10#ifndef TLAPACK_STARPU_HH
11#define TLAPACK_STARPU_HH
19constexpr real_type<T>
real(
const starpu::MatrixEntry<T>& x)
noexcept
21 if constexpr (is_complex<T>)
24 return real_type<T>(T(x));
28constexpr real_type<T>
imag(
const starpu::MatrixEntry<T>& x)
noexcept
30 if constexpr (is_complex<T>)
33 return real_type<T>(0);
37constexpr T
conj(
const starpu::MatrixEntry<T>& x)
noexcept
39 if constexpr (is_complex<T>)
63constexpr auto nrows(
const starpu::Matrix<T>& A)
noexcept
69constexpr auto ncols(
const starpu::Matrix<T>& A)
noexcept
75constexpr auto size(
const starpu::Matrix<T>& A)
noexcept
77 return A.nrows() * A.ncols();
83#define isSlice(SliceSpec) \
84 std::is_convertible<SliceSpec, \
85 std::tuple<starpu::idx_t, starpu::idx_t>>::value
91 typename std::enable_if<isSlice(SliceSpecRow) && isSlice(SliceSpecCol),
93constexpr auto slice(
const starpu::Matrix<T>& A,
95 SliceSpecCol&& cols)
noexcept
99 const idx_t row0 = std::get<0>(rows);
100 const idx_t col0 = std::get<0>(cols);
101 const idx_t row1 = std::get<1>(rows);
102 const idx_t col1 = std::get<1>(cols);
104 return A.map_to_const_tiles(row0, row1, col0, col1);
110 typename std::enable_if<isSlice(SliceSpecRow) && isSlice(SliceSpecCol),
112constexpr auto slice(starpu::Matrix<T>& A,
114 SliceSpecCol&& cols)
noexcept
118 const idx_t row0 = std::get<0>(rows);
119 const idx_t col0 = std::get<0>(cols);
120 const idx_t row1 = std::get<1>(rows);
121 const idx_t col1 = std::get<1>(cols);
123 return A.map_to_tiles(row0, row1, col0, col1);
128template <
class T,
class SliceSpec>
129constexpr auto slice(
const starpu::Matrix<T>& v,
131 starpu::idx_t colIdx)
noexcept
133 return slice(v, std::forward<SliceSpec>(range),
134 std::make_tuple(colIdx, colIdx + 1));
136template <
class T,
class SliceSpec>
137constexpr auto slice(starpu::Matrix<T>& v,
139 starpu::idx_t colIdx)
noexcept
141 return slice(v, std::forward<SliceSpec>(range),
142 std::make_tuple(colIdx, colIdx + 1));
145template <
class T,
class SliceSpec>
146constexpr auto slice(
const starpu::Matrix<T>& v,
147 starpu::idx_t rowIdx,
148 SliceSpec&& range)
noexcept
150 return slice(v, std::make_tuple(rowIdx, rowIdx + 1),
151 std::forward<SliceSpec>(range));
153template <
class T,
class SliceSpec>
154constexpr auto slice(starpu::Matrix<T>& v,
155 starpu::idx_t rowIdx,
156 SliceSpec&& range)
noexcept
158 return slice(v, std::make_tuple(rowIdx, rowIdx + 1),
159 std::forward<SliceSpec>(range));
162template <
class T,
class SliceSpec>
163constexpr auto slice(
const starpu::Matrix<T>& v, SliceSpec&& range)
noexcept
165 assert((v.nrows() <= 1 || v.ncols() <= 1) &&
"Matrix is not a vector");
168 return slice(v, std::forward<SliceSpec>(range), std::make_tuple(0, 1));
170 return slice(v, std::make_tuple(0, 1), std::forward<SliceSpec>(range));
172template <
class T,
class SliceSpec>
173constexpr auto slice(starpu::Matrix<T>& v, SliceSpec&& range)
noexcept
175 assert((v.nrows() <= 1 || v.ncols() <= 1) &&
"Matrix is not a vector");
178 return slice(v, std::forward<SliceSpec>(range), std::make_tuple(0, 1));
180 return slice(v, std::make_tuple(0, 1), std::forward<SliceSpec>(range));
184constexpr auto col(
const starpu::Matrix<T>& A, starpu::idx_t colIdx)
noexcept
186 return slice(A, std::make_tuple(0, A.nrows()),
187 std::make_tuple(colIdx, colIdx + 1));
190constexpr auto col(starpu::Matrix<T>& A, starpu::idx_t colIdx)
noexcept
192 return slice(A, std::make_tuple(0, A.nrows()),
193 std::make_tuple(colIdx, colIdx + 1));
196template <
class T,
class SliceSpec>
197constexpr auto cols(
const starpu::Matrix<T>& A, SliceSpec&& cols)
noexcept
199 return slice(A, std::make_tuple(0, A.nrows()),
200 std::forward<SliceSpec>(cols));
202template <
class T,
class SliceSpec>
203constexpr auto cols(starpu::Matrix<T>& A, SliceSpec&& cols)
noexcept
205 return slice(A, std::make_tuple(0, A.nrows()),
206 std::forward<SliceSpec>(cols));
210constexpr auto row(
const starpu::Matrix<T>& A, starpu::idx_t rowIdx)
noexcept
212 return slice(A, std::make_tuple(rowIdx, rowIdx + 1),
213 std::make_tuple(0, A.ncols()));
216constexpr auto row(starpu::Matrix<T>& A, starpu::idx_t rowIdx)
noexcept
218 return slice(A, std::make_tuple(rowIdx, rowIdx + 1),
219 std::make_tuple(0, A.ncols()));
222template <
class T,
class SliceSpec>
223constexpr auto rows(
const starpu::Matrix<T>& A, SliceSpec&& rows)
noexcept
225 return slice(A, std::forward<SliceSpec>(rows),
226 std::make_tuple(0, A.ncols()));
228template <
class T,
class SliceSpec>
229constexpr auto rows(starpu::Matrix<T>& A, SliceSpec&& rows)
noexcept
231 return slice(A, std::forward<SliceSpec>(rows),
232 std::make_tuple(0, A.ncols()));
236constexpr auto diag(
const starpu::Matrix<T>& A,
int diagIdx = 0)
238 throw std::runtime_error(
"Not implemented");
242constexpr auto diag(starpu::Matrix<T>& A,
int diagIdx = 0)
244 throw std::runtime_error(
"Not implemented");
250 template <
class TA,
class TB>
256 template <
class TA,
class TB>
268 starpu::idx_t n = 1)
const
278 template <
class U,
int m,
int n>
280 static_assert(m >= 0 && n >= -1);
285 constexpr int Cols_ = (n == -1) ? 1 : n;
constexpr real_type< T > real(const T &x) noexcept
Extends std::real() to real datatypes.
Definition utils.hpp:71
constexpr T conj(const T &x) noexcept
Extends std::conj() to real datatypes.
Definition utils.hpp:100
constexpr real_type< T > imag(const T &x) noexcept
Extends std::imag() to real datatypes.
Definition utils.hpp:86
Class for representing a matrix in StarPU that is split into tiles.
Definition Matrix.hpp:134
constexpr auto diag(T &A, int diagIdx=0) noexcept
Get the Diagonal of an Eigen Matrix.
Definition eigen.hpp:576
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
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
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