26 #ifndef TILEDARRAY_MATH_LINALG_UTIL_H__INCLUDED
27 #define TILEDARRAY_MATH_LINALG_UTIL_H__INCLUDED
29 #include <TiledArray/config.h>
39 static const bool complex = !std::is_same_v<scalar_type, numeric_type>;
40 static_assert(std::is_same_v<numeric_type, typename A::element_type>,
41 "TA::linalg is only usable with a DistArray of scalar types");
45 template <
typename Tile,
typename Policy>
49 return array_to_eigen<Tile, Policy, Eigen::ColMajor>(A_repl);
52 template <
typename ContiguousTensor,
53 typename = std::enable_if_t<
54 TiledArray::detail::is_contiguous_tensor_v<ContiguousTensor>>>
58 std::is_same_v<numeric_type, typename ContiguousTensor::value_type>,
59 "TA::lapack::{cholesky*} are only usable with a ContiguousTensor of "
61 TA_ASSERT(A.range().rank() == 1 || A.range().rank() == 2);
62 using colmajor_matrix_type =
Eigen::Matrix<numeric_type, Eigen::Dynamic,
63 Eigen::Dynamic, Eigen::ColMajor>;
64 colmajor_matrix_type result(A.range().extent(0),
65 A.range().rank() == 2 ? A.range().extent(1) : 1);
66 constexpr
const auto layout =
68 if (layout == TiledArray::OrdinalType::RowMajor) {
69 using rowmajor_matrix_type =
Eigen::Matrix<numeric_type, Eigen::Dynamic,
70 Eigen::Dynamic, Eigen::RowMajor>;
71 auto result_map = Eigen::Map<const rowmajor_matrix_type>(
72 A.data(), result.rows(), result.cols());
74 }
else if constexpr (layout == TiledArray::OrdinalType::ColMajor) {
75 using rowmajor_matrix_type =
Eigen::Matrix<numeric_type, Eigen::Dynamic,
76 Eigen::Dynamic, Eigen::ColMajor>;
77 auto result_map = Eigen::Map<const rowmajor_matrix_type>(
78 A.data(), result.rows(), result.cols());
85 template <
typename ContiguousTensor,
typename Scalar,
int ... Options,
86 typename = std::enable_if_t<
87 TiledArray::detail::is_contiguous_tensor_v<ContiguousTensor>>>
88 auto make_array(
const Eigen::Matrix<Scalar, Options...>& A,
89 typename ContiguousTensor::range_type range = {}) {
92 std::is_same_v<numeric_type, typename ContiguousTensor::value_type>,
93 "TA::math::linalg is only usable with a ContiguousTensor of scalar types"
95 using range_type =
typename ContiguousTensor::range_type;
96 if (range.rank() == 0)
97 range = range_type(A.rows(), A.cols());
99 TA_ASSERT(A.rows() * A.cols() == range.volume());
100 ContiguousTensor result(range);
101 auto result_map =
eigen_map(result, A.rows(), A.cols());
106 template <
typename Derived>
108 A.template triangularView<Eigen::StrictlyUpper>().setZero();
113 #endif // TILEDARRAY_MATH_LINALG_UTIL_H__INCLUDED