5#include <tatooine/real.h>
13template <arithmetic_or_complex ValueType, std::
size_t M, std::
size_t N>
30 using parent_type::operator();
48 template <
typename RandEng = std::mt19937_64>
49 static auto constexpr randu(ValueType
min = 0, ValueType
max = 1,
50 RandEng&& eng = RandEng{std::random_device{}()}) {
54 template <
typename RandEng = std::mt19937_64>
55 static auto constexpr randn(ValueType mean = 0, ValueType stddev = 1,
56 RandEng&& eng = RandEng{std::random_device{}()}) {
62 auto factor_up_row = [
row = std::size_t(0), &V](
auto x)
mutable {
64 for (std::size_t
col = 1;
col < N; ++
col) {
69 for (std::size_t i = 0; i < N; ++i) {
78 auto factor_up_row = [
row = std::size_t(0), &V](
auto x)
mutable {
80 for (std::size_t
col = 1;
col < N; ++
col) {
85 (factor_up_row(xs), ...);
92 constexpr mat() =
default;
96 constexpr mat(
mat&& other)
noexcept =
default;
99 template <static_tensor Other>
100 requires(same_dimensions<this_type, Other>())
explicit constexpr mat(
104 template <
typename... Rows>
106 static_assert(((is_arithmetic<Rows> || is_complex<Rows>)&&...));
109 "number of given rows does not match specified number of rows");
112 auto insert_row = [r = std::size_t(0),
this](
auto const&
row)
mutable {
114 at(r, c) =
static_cast<ValueType
>(
row[c]);
124 for (std::size_t i = 0; i < std::min(M, N); ++i) {
129 template <convertible_to<ValueType> Fill>
133 template <
typename RandomReal,
typename Engine>
134 requires is_arithmetic<ValueType>
138 template <arithmetic RandomReal,
typename Engine>
142 template <arithmetic RandomReal,
typename Engine>
143 requires is_arithmetic<ValueType>
147 template <arithmetic RandomReal,
typename Engine>
148 requires is_arithmetic<ValueType>
159 template <static_tensor Other>
160 requires(same_dimensions<this_type, Other>())
161 auto constexpr operator=(Other
const& other)
noexcept ->
mat& {
172 auto constexpr row(std::size_t i) {
return this->
template slice<0>(i); }
173 auto constexpr row(std::size_t i)
const {
return this->
template slice<0>(i); }
175 auto constexpr col(std::size_t i) {
return this->
template slice<1>(i); }
176 auto constexpr col(std::size_t i)
const {
return this->
template slice<1>(i); }
181template <std::size_t C,
typename... Rows>
184template <
typename Mat,
typename ValueType, std::
size_t M, std::
size_t N>
Definition: concepts.h:39
Definition: tensor_concepts.h:33
Definition: concepts.h:30
static constexpr eye_t eye
Definition: tags.h:85
Definition: algorithm.h:6
typename common_type_impl< Ts... >::type common_type
Definition: common_type.h:23
constexpr auto max(A &&a, B &&b)
Definition: math.h:20
constexpr auto min(A &&a, B &&b)
Definition: math.h:15
constexpr void for_each(F &&f, Ts &&... ts)
Definition: utility.h:39
Definition: base_tensor.h:23
auto constexpr dimension() const
Definition: contracted_dynamic_tensor.h:36
static auto constexpr randn(ValueType mean=0, ValueType stddev=1, RandEng &&eng=RandEng{std::random_device{}()})
Definition: mat.h:55
mat< ValueType, M, N > this_type
Definition: mat.h:24
constexpr mat(tag::eye_t)
Constructs an identity matrix.
Definition: mat.h:123
static auto constexpr num_columns()
Definition: mat.h:19
static auto constexpr num_rows()
Definition: mat.h:18
auto constexpr operator=(mat const &) -> mat &=default
auto constexpr row(std::size_t i)
Definition: mat.h:172
static auto constexpr fill(ValueType const &v)
Definition: mat.h:40
auto constexpr col(std::size_t i) const
Definition: mat.h:176
constexpr mat(random::normal< RandomReal, Engine > &rand)
Definition: mat.h:149
static auto constexpr vander(fixed_size_vec< N > auto const &v)
Definition: mat.h:60
auto constexpr col(std::size_t i)
Definition: mat.h:175
static auto constexpr randu(ValueType min=0, ValueType max=1, RandEng &&eng=RandEng{std::random_device{}()})
Definition: mat.h:49
static auto constexpr ones()
Definition: mat.h:38
constexpr mat(Rows(&&... rows)[parent_type::dimension(1)])
Definition: mat.h:105
constexpr mat(Other &&other)
Copies any other tensor with same dimensions.
Definition: mat.h:100
constexpr mat(mat &&other) noexcept=default
constexpr mat(random::uniform< RandomReal, Engine > &&rand)
Definition: mat.h:135
static auto constexpr vander(convertible_to< ValueType > auto &&... xs)
Definition: mat.h:75
constexpr mat(tag::fill< Fill > const f)
Definition: mat.h:130
static auto constexpr zeros()
Definition: mat.h:36
constexpr mat(random::uniform< RandomReal, Engine > &rand)
Definition: mat.h:139
auto constexpr operator=(mat &&other) noexcept -> mat &=default
constexpr mat(random::normal< RandomReal, Engine > &&rand)
Definition: mat.h:144
constexpr mat(tag::zeros_t const zeros)
Definition: mat.h:132
constexpr mat(tag::ones_t const ones)
Definition: mat.h:131
static auto constexpr nans()
Definition: mat.h:42
static auto constexpr eye()
Definition: mat.h:46
auto constexpr row(std::size_t i) const
Definition: mat.h:173
constexpr mat(mat const &)=default
constexpr auto operator=(tensor const &) -> tensor &=default
auto constexpr at(integral auto const ... is) -> decltype(auto)
Definition: tensor.h:38
type_list_at< this_type, I > at
Definition: type_list.h:269