batmat 0.0.16
Batched linear algebra routines
Loading...
Searching...
No Matches
triangular.hpp
Go to the documentation of this file.
1#pragma once
2
4#include <utility>
5
6namespace batmat::linalg {
7
8/// @addtogroup topic-linalg
9/// @{
10
11/// Light-weight wrapper class used for overload resolution of triangular and symmetric matrices.
12template <class M, MatrixStructure S = MatrixStructure::General>
13struct Structured {
14 static constexpr MatrixStructure structure = S;
15 explicit(S != MatrixStructure::General) Structured(M &&m) : value{std::forward<M>(m)} {}
16 Structured(const Structured &) = default;
17 Structured(Structured &&) = default;
19 [[nodiscard]] constexpr auto transposed() const &
20 requires requires { value.transposed(); }
21 {
22 return Structured<decltype(value.transposed()), transpose(S)>{value.transposed()};
23 }
24 [[nodiscard]] constexpr auto transposed() &&
25 requires requires { std::forward<M>(value).transposed(); }
26 {
27 return Structured<decltype(std::forward<M>(value).transposed()), transpose(S)>{
28 std::forward<M>(value).transposed()};
29 }
30 [[nodiscard]] constexpr auto ref() { return Structured<M &, S>{value}; } // TODO: const version
31};
32
33template <class M>
35
36/// @name Triangular views of batches of matrices
37/// @{
38
39/// Lower-triangular view.
40template <class M>
41[[nodiscard]] constexpr auto tril(M &&m) {
42 return Structured<M, MatrixStructure::LowerTriangular>{std::forward<M>(m)};
43}
44
45/// Upper-triangular view.
46template <class M>
47[[nodiscard]] constexpr auto triu(M &&m) {
48 return Structured<M, MatrixStructure::UpperTriangular>{std::forward<M>(m)};
49}
50
51/// View with the given structure.
52template <MatrixStructure S, class M>
53[[nodiscard]] constexpr auto make_structured(M &&m) {
54 return Structured<M, S>{std::forward<M>(m)};
55}
56
57/// @}
58
59/// @}
60
61template <class M, MatrixStructure S>
62void simdify(const Structured<M, S> &) = delete;
63
64} // namespace batmat::linalg
constexpr MatrixStructure transpose(MatrixStructure s)
Definition structure.hpp:11
constexpr auto make_structured(M &&m)
View with the given structure.
Structured(M &&) -> Structured< M >
constexpr auto triu(M &&m)
Upper-triangular view.
constexpr auto tril(M &&m)
Lower-triangular view.
constexpr auto simdify(simdifiable auto &&a) -> simdified_view_t< decltype(a)>
Definition simdify.hpp:214
Light-weight wrapper class used for overload resolution of triangular and symmetric matrices.
constexpr auto transposed() const &
Structured(Structured &&)=default
constexpr auto transposed() &&
Structured(const Structured &)=default
static constexpr MatrixStructure structure