10#ifndef TLAPACK_LEGACYARRAY_HH
11#define TLAPACK_LEGACYARRAY_HH
28 template <
typename T,
class idx_t, Layout L>
31 template <
typename T,
class idx_t,
class int_t, Direction D>
32 std::true_type is_legacy_type_f(
35 std::false_type is_legacy_type_f(
const void*);
42 decltype(internal::is_legacy_type_f(std::declval<T*>()))::value;
50 template <
typename T,
class idx_t, Layout L>
52 static constexpr Layout value = L;
56 template <
typename T,
class idx_t,
typename int_t, Direction D>
61 template <
class T,
class idx_t,
typename int_t, Direction D>
66 template <
typename T,
class idx_t, Layout layout>
71 template <
class T,
class idx_t,
typename int_t, Direction D>
76 template <
typename T,
class idx_t, Layout layout>
82 template <
class U,
class idx_t, Layout layout>
85 constexpr auto operator()(std::vector<T>&
v, idx_t m, idx_t n)
const
94 template <
class U,
class idx_t, Layout layout,
int m,
int n>
96 static_assert(m >= 0 && n >= 0);
106 template <
class U,
class idx_t,
typename int_t, Direction D>
109 constexpr auto operator()(std::vector<T>&
v, idx_t n)
const
118 template <
class U,
class idx_t,
typename int_t, Direction D,
int n>
120 static_assert(n >= 0);
122 template <
typename T>
134template <
typename T,
class idx_t, Layout layout>
141template <
typename T,
class idx_t, Layout layout>
148template <
typename T,
class idx_t, Layout layout>
155template <
typename T,
class idx_t,
typename int_t, Direction direction>
162template <
typename T,
class idx_t>
169template <
typename T,
class idx_t>
176template <
typename T,
class idx_t>
183template <
typename T,
class idx_t>
190template <
typename T,
class idx_t>
199#define isSlice(SliceSpec) !std::is_convertible<SliceSpec, idx_t>::value
214 assert((rows.first >= 0
and (idx_t) rows.first < nrows(
A)) ||
215 rows.first == rows.second);
216 assert(rows.second >= 0
and (idx_t) rows.second <= nrows(
A));
217 assert(rows.first <= rows.second);
218 assert((cols.first >= 0
and (idx_t) cols.first < ncols(
A)) ||
219 cols.first == cols.second);
220 assert(cols.second >= 0
and (idx_t) cols.second <= ncols(
A));
221 assert(cols.first <= cols.second);
223 rows.second - rows.first, cols.second - cols.first,
232template <
typename T,
class idx_t, Layout layout,
class SliceSpecCol>
237 assert((cols.first >= 0
and (idx_t) cols.first < ncols(
A)) ||
238 cols.first == cols.second);
239 assert(cols.second >= 0
and (idx_t) cols.second <= ncols(
A));
240 assert(cols.first <= cols.second);
243 cols.second - cols.first,
250template <
typename T,
class idx_t, Layout layout,
class SliceSpecRow>
255 assert((rows.first >= 0
and (idx_t) rows.first < nrows(
A)) ||
256 rows.first == rows.second);
257 assert(rows.second >= 0
and (idx_t) rows.second <= nrows(
A));
258 assert(rows.first <= rows.second);
261 rows.second - rows.first,
268template <
typename T,
class idx_t, Layout layout,
class SliceSpec>
272 assert((rows.first >= 0
and (idx_t) rows.first < nrows(
A)) ||
273 rows.first == rows.second);
274 assert(rows.second >= 0
and (idx_t) rows.second <= nrows(
A));
275 assert(rows.first <= rows.second);
277 rows.second - rows.first,
A.n,
284template <
typename T,
class idx_t>
293template <
typename T,
class idx_t>
303template <
typename T,
class idx_t, Layout layout,
class SliceSpec>
307 assert((cols.first >= 0
and (idx_t) cols.first < ncols(
A)) ||
308 cols.first == cols.second);
309 assert(cols.second >= 0
and (idx_t) cols.second <= ncols(
A));
310 assert(cols.first <= cols.second);
312 A.m, cols.second - cols.first,
319template <
typename T,
class idx_t>
328template <
typename T,
class idx_t>
338template <
typename T,
class idx_t, Layout layout>
355template <
typename T,
class idx_t>
356constexpr auto transpose_view(
362template <
typename T,
class idx_t>
363constexpr auto transpose_view(
379 assert((rows.first >= 0
and (idx_t) rows.first < size(
v)) ||
380 rows.first == rows.second);
381 assert(rows.second >= 0
and (idx_t) rows.second <= size(
v));
382 assert(rows.first <= rows.second);
384 rows.second - rows.first, &
v.ptr[rows.first *
v.inc],
v.inc);
390#define isSlice(SliceSpec) !std::is_convertible<SliceSpec, idx_t>::value
405 assert((rows.first >= 0
and (idx_t) rows.first < nrows(
A)) ||
406 rows.first == rows.second);
407 assert(rows.second >= 0
and (idx_t) rows.second <= nrows(
A));
408 assert(rows.first <= rows.second);
409 assert((cols.first >= 0
and (idx_t) cols.first < ncols(
A)) ||
410 cols.first == cols.second);
411 assert(cols.second >= 0
and (idx_t) cols.second <= ncols(
A));
412 assert(cols.first <= cols.second);
414 rows.second - rows.first, cols.second - cols.first,
423template <
typename T,
class idx_t, Layout layout,
class SliceSpecCol>
428 assert((cols.first >= 0
and (idx_t) cols.first < ncols(
A)) ||
429 cols.first == cols.second);
430 assert(cols.second >= 0
and (idx_t) cols.second <= ncols(
A));
431 assert(cols.first <= cols.second);
434 cols.second - cols.first,
441template <
typename T,
class idx_t, Layout layout,
class SliceSpecRow>
446 assert((rows.first >= 0
and (idx_t) rows.first < nrows(
A)) ||
447 rows.first == rows.second);
448 assert(rows.second >= 0
and (idx_t) rows.second <= nrows(
A));
449 assert(rows.first <= rows.second);
452 rows.second - rows.first,
459template <
typename T,
class idx_t, Layout layout,
class SliceSpec>
463 assert((rows.first >= 0
and (idx_t) rows.first < nrows(
A)) ||
464 rows.first == rows.second);
465 assert(rows.second >= 0
and (idx_t) rows.second <= nrows(
A));
466 assert(rows.first <= rows.second);
475template <
typename T,
class idx_t>
484template <
typename T,
class idx_t>
494template <
typename T,
class idx_t, Layout layout,
class SliceSpec>
498 assert((cols.first >= 0
and (idx_t) cols.first < ncols(
A)) ||
499 cols.first == cols.second);
500 assert(cols.second >= 0
and (idx_t) cols.second <= ncols(
A));
501 assert(cols.first <= cols.second);
504 ? &
A.ptr[cols.first *
A.ldim]
510template <
typename T,
class idx_t>
519template <
typename T,
class idx_t>
529template <
typename T,
class idx_t, Layout layout>
545template <
typename T,
class idx_t>
546constexpr auto transpose_view(
551template <
typename T,
class idx_t>
552constexpr auto transpose_view(
567 assert((rows.first >= 0
and (idx_t) rows.first < size(
v)) ||
568 rows.first == rows.second);
569 assert(rows.second >= 0
and (idx_t) rows.second <= size(
v));
570 assert(rows.first <= rows.second);
572 rows.second - rows.first, &
v.ptr[rows.first *
v.inc],
v.inc);
576template <
typename T,
class idx_t, Layout layout>
584 const idx_t size =
A.m *
A.n;
593 throw std::domain_error(
"New size is larger than current size");
596 return std::make_pair(
603 if (m ==
A.m || n == 0)
604 return std::make_pair(cols(
A, std::pair{(idx_t)0, n}),
605 cols(
A, std::pair{n,
A.n}));
606 else if (n ==
A.n || m == 0)
607 return std::make_pair(rows(
A, std::pair{(idx_t)0, m}),
608 rows(
A, std::pair{m,
A.m}));
610 throw std::domain_error(
611 "Cannot reshape to non-contiguous matrix into a matrix if both "
612 "the number of rows and columns are different from the new "
616template <
typename T,
class idx_t, Layout layout>
624 const idx_t size =
A.m *
A.n;
632 throw std::domain_error(
"New size is larger than current size");
635 return std::make_pair(
vector_t(n, &
A.ptr[0]),
642 return std::make_pair(
vector_t(0, &
A.ptr[0]),
A);
646 return std::make_pair(
650 return std::make_pair(
656 return std::make_pair(
660 return std::make_pair(
665 throw std::domain_error(
666 "Cannot reshape to non-contiguous matrix into a vector if the "
667 "new size is different from the number of rows and columns.");
673template <
typename T,
class idx_t,
typename int_t, Direction direction>
688 throw std::domain_error(
"New size is larger than current size");
690 throw std::domain_error(
691 "New sizes are not compatible with the current vector.");
694 return std::make_pair(
matrix_t(m, n, &
v.ptr[0]),
698 return std::make_pair(
matrix_t(m, n, &
v.ptr[0],
v.inc),
702template <
typename T,
class idx_t,
typename int_t, Direction direction>
708 throw std::domain_error(
"New size is larger than current size");
710 return std::make_pair(slice(
v, std::pair{(idx_t)0, n}),
711 slice(
v, std::pair{n,
v.n}));
719 template <
typename T>
720 constexpr bool cast_to_legacy_type =
722#ifdef TLAPACK_EIGEN_HH
725#ifdef TLAPACK_MDSPAN_HH
732 template <
class matrixA_t,
typename matrixB_t>
737 ((is_legacy_type<matrixA_t> ||
738 is_legacy_type<matrixB_t>)&&cast_to_legacy_type<matrixA_t> &&
739 cast_to_legacy_type<matrixB_t>),
746 static constexpr Layout L =
756 template <
typename vecA_t,
typename vecB_t>
761 ((is_legacy_type<vecA_t> ||
762 is_legacy_type<vecB_t>)&&cast_to_legacy_type<vecA_t> &&
763 cast_to_legacy_type<vecB_t>),
771#if !defined(TLAPACK_EIGEN_HH) && !defined(TLAPACK_MDSPAN_HH)
772 template <
class vecA_t,
class vecB_t>
776 std::enable_if_t<traits::is_stdvector_type<vecA_t> &&
777 traits::is_stdvector_type<vecB_t>,
783 template <
class vecA_t,
class vecB_t>
784 struct vector_type_traits<
787 std::enable_if_t<traits::is_stdvector_type<vecA_t> &&
788 traits::is_stdvector_type<vecB_t>,
800template <
typename T,
class idx_t, Layout layout>
803 return legacy::Matrix<T, idx_t>{
layout,
A.m,
A.n,
A.ptr,
A.ldim};
806template <
class T,
class idx_t,
class int_t, Direction direction>
807constexpr auto legacy_matrix(
814template <
typename T,
class idx_t,
typename int_t, Direction direction>
815constexpr auto legacy_vector(
821 return legacy::Vector<T, idx_t>{
Concept for types that represent tlapack::Direction.
Concept for matrices that can be converted to a legacy matrix.
Concept for vectors that can be converted to a legacy vector.
Sort the numbers in D in increasing order (if ID = 'I') or in decreasing order (if ID = 'D' ).
Definition arrayTraits.hpp:15
typename traits::real_type_traits< Types..., int >::type real_type
The common real type of the list of types.
Definition scalar_type_traits.hpp:113
@ Forward
Forward direction.
typename traits::size_type_trait< T, int >::type size_type
Size type of a matrix or vector.
Definition arrayTraits.hpp:228
constexpr auto diag(T &A, int diagIdx=0) noexcept
Get the Diagonal of an Eigen Matrix.
Definition eigen.hpp:576
constexpr Layout layout
Layout of a matrix or vector.
Definition arrayTraits.hpp:232
Layout
Definition types.hpp:29
@ ColMajor
Column-major layout.
@ RowMajor
Row-major layout.
constexpr bool is_legacy_type
True if T is a legacy array.
Definition legacyArray.hpp:41
Legacy matrix.
Definition LegacyMatrix.hpp:34
Legacy vector.
Definition LegacyVector.hpp:42
Functor for data creation.
Definition arrayTraits.hpp:89
constexpr auto operator()(std::vector< T > &v, idx_t m, idx_t n=1) const
Creates a m-by-n matrix with entries of type T.
Definition arrayTraits.hpp:105
Functor for data creation with static size.
Definition arrayTraits.hpp:141
constexpr auto operator()(T *v) const
Creates a m-by-n matrix or, if n == -1, a vector of size m.
Definition arrayTraits.hpp:157
Complex type traits for the list of types Types.
Definition scalar_type_traits.hpp:145
Trait to determine the layout of a given data structure.
Definition arrayTraits.hpp:75
Matrix type deduction.
Definition arrayTraits.hpp:176
Real type traits for the list of types Types.
Definition scalar_type_traits.hpp:71
Vector type deduction.
Definition arrayTraits.hpp:203