3 #include <funcy/concepts.h> 4 #include <funcy/linalg/at.h> 5 #include <funcy/linalg/concepts.h> 6 #include <funcy/linalg/rows_and_cols.h> 7 #include <funcy/linalg/type_traits.h> 8 #include <funcy/util/chainer.h> 9 #include <funcy/util/macros.h> 12 #include <type_traits> 25 template < ConstantSize M >
26 struct WrappedMatrix< M >
28 using type =
typename GetTransposed< M >::type;
31 template < ConstantSize Mat >
32 [[nodiscard]] Transposed_t< Mat >
33 transpose( Mat A ) requires std::same_as< Mat, Transposed_t< Mat > >
35 auto a =
at( A, 0, 0 );
36 for (
int i = 0; i < rows< Mat >(); ++i )
37 for (
int j = i + 1; j < cols< Mat >(); ++j )
40 at( A, i, j ) =
at( A, j, i );
48 template < ConstantSize Mat >
49 [[nodiscard]] Transposed_t< Mat >
50 transpose(
const Mat& A ) requires( !std::same_as< Mat, Transposed_t< Mat > > )
52 auto B = zero< Transposed_t< Mat > >();
53 for (
int i = 0; i < rows< Mat >(); ++i )
54 for (
int j = 0; j < cols< Mat >(); ++j )
55 at( B, j, i ) = A( i, j );
60 template <
class Mat >
61 [[nodiscard]] Mat
transpose( Mat A ) requires( !ConstantSize< Mat > )
63 FUNCY_ASSERT(
rows( A ) ==
cols( A ) );
64 using Index = decltype(
rows( std::declval< Mat >() ) );
65 auto a = std::decay_t< decltype( at( A, 0, 0 ) ) >( 0. );
66 for ( Index i = 0; i <
rows( A ); ++i )
67 for ( Index j = i + 1; j <
cols( A ); ++j )
70 at( A, i, j ) =
at( A, j, i );
81 template < ConstantSize Mat >
82 [[nodiscard]] Mat& add_transposed( Mat& A )
85 using Index = decltype( dim< Mat >() );
86 for ( Index i = 0; i < dim< Mat >(); ++i )
87 for ( Index j = i + 1; j < dim< Mat >(); ++j )
88 at( A, j, i ) =
at( A, i, j ) =
at( A, i, j ) +
at( A, j, i );
89 for ( Index i = 0; i < dim< Mat >(); ++i )
98 template <
class Mat >
99 [[nodiscard]] Mat& add_transposed( Mat& A )
103 FUNCY_ASSERT(
rows( A ) ==
cols( A ) );
104 using Index = decltype(
rows( std::declval< Mat >() ) );
105 for ( Index i = 0; i <
rows( A ); ++i )
106 for ( Index j = i + 1; j <
cols( A ); ++j )
107 at( A, j, i ) =
at( A, i, j ) =
at( A, i, j ) +
at( A, j, i );
108 for ( Index i = 0; i <
rows( A ); ++i )
117 template <
class Mat >
126 void update(
const Mat& A )
131 [[nodiscard]]
const auto& d0()
const noexcept
136 [[nodiscard]]
auto d1(
const Mat& dA )
const 142 typename detail::WrappedMatrix< Mat >::type AT_;
150 template <
class Mat >
161 template < Function F >
auto transpose(const F &f)
Generate , where .
Definition: transpose.h:162
auto cols(const Mat &A) requires(!ConstantSize< Mat > &&static_check
Number of columns of a dynamic size matrix.
Definition: rows_and_cols.h:36
constexpr int dim()
Dimension of a fixed size matrix in .
Definition: dimension.h:19
auto rows(const Mat &A) requires(!ConstantSize< Mat > &&static_check
Number of rows of a dynamic size matrix.
Definition: rows_and_cols.h:13
Functionality from linear algebra such as (modified) principal and mixed matrix invariants.
decltype(auto) FUNCY_ALWAYS_INLINE at(M &&A, Index i, Index j) requires requires(std
Access matrix entry.
Definition: at.h:17
auto transpose(const Mat &A)
Generate .
Definition: transpose.h:151
Definition: transpose.h:118