25 template <
typename T, order SO,
size_t D>
30 iterable<dyn_matrix_impl<T, SO, D>, SO == order::RowMajor>,
44 using iterator = std::conditional_t<SO == order::RowMajor, value_type*, etl::iterator<this_type>>;
45 using const_iterator = std::conditional_t<SO == order::RowMajor, const value_type*, etl::iterator<const this_type>>;
50 template <
typename V = default_vec>
54 using base_type::_dimensions;
56 using base_type::_size;
59 using base_type::check_invariants;
60 using base_type::release;
64 using base_type::memory_end;
65 using base_type::memory_start;
92 if (rhs.is_cpu_up_to_date()) {
93 direct_copy(rhs.memory_start(), rhs.memory_end(), memory_start());
96 cpp_assert(rhs.is_cpu_up_to_date() == this->
is_cpu_up_to_date(),
"dyn_matrix_impl(&) must preserve CPU status");
97 cpp_assert(rhs.is_gpu_up_to_date() == this->
is_gpu_up_to_date(),
"dyn_matrix_impl(&) must preserve GPU status");
108 rhs._memory =
nullptr;
118 std::copy(list.begin(), list.end(),
begin());
128 template <size_c... S>
137 template <
typename... S>
139 :
base_type(util::size(std::make_index_sequence<(
sizeof...(S) - 1)>(), sizes...),
140 dyn_detail::sizes(std::make_index_sequence<(
sizeof...(S) - 1)>(), sizes...)) {
143 static_assert(
sizeof...(S) ==
D + 1,
"Invalid number of dimensions");
145 auto list = cpp::last_value(sizes...);
146 std::copy(list.begin(), list.end(),
begin());
153 template <
typename... S>
154 explicit dyn_matrix_impl(
size_t s1, S... sizes) noexcept
requires((
sizeof...(S) ==
D) && cpp::specialization_of<
values_t,
typename cpp::last_type<size_t, S...>::type>)
155 :
base_type(util::size(std::make_index_sequence<(
sizeof...(S))>(), s1, sizes...),
156 dyn_detail::sizes(std::make_index_sequence<(
sizeof...(S))>(), s1, sizes...)) {
159 auto list = cpp::last_value(sizes...).template list<value_type>();
160 std::copy(list.begin(), list.end(),
begin());
169 template <
typename... S>
170 explicit dyn_matrix_impl(
size_t s1, S... sizes) noexcept
requires((
sizeof...(S) ==
D) && !cpp::specialization_of<
values_t,
typename cpp::last_type<size_t, S...>::type>)
171 :
base_type(util::size(std::make_index_sequence<(
sizeof...(S))>(), s1, sizes...),
172 dyn_detail::sizes(std::make_index_sequence<(
sizeof...(S))>(), s1, sizes...)) {
175 decltype(
auto) value = cpp::last_value(s1, sizes...);
185 template <std_container Container>
186 explicit dyn_matrix_impl(
const Container& container)
requires(
D == 1 && std::convertible_to<typename Container::value_type, value_type>) :
187 base_type(container.size(), {{container.size()}}) {
191 std::copy_n(container.begin(), _size,
_memory);
205 cpp_assert(!
_memory,
"_size and _memory are not properly synced");
208 _dimensions = rhs._dimensions;
216 validate_assign(*
this, rhs);
225 cpp_assert(rhs.is_cpu_up_to_date() == this->
is_cpu_up_to_date(),
"dyn_matrix_impl::operator= must preserve CPU status");
226 cpp_assert(rhs.is_gpu_up_to_date() == this->
is_gpu_up_to_date(),
"dyn_matrix_impl::operator= must preserve GPU status");
242 release(
_memory, alloc_size_mat<T>(_size,
dim(n_dimensions - 1)));
246 _dimensions = std::move(rhs._dimensions);
263 auto new_size = std::accumulate(dimensions.begin(), dimensions.end(), size_t(1), std::multiplies<size_t>());
266 auto new_memory =
allocate(alloc_size_mat<T>(new_size, (dimensions.back())));
268 for (
size_t i = 0; i <
std::min(_size, new_size); ++i) {
272 release(
_memory, alloc_size_mat<T>(_size,
dim(n_dimensions - 1)));
280 _dimensions = dimensions;
287 template <
typename... Sizes>
288 void resize(Sizes... sizes)
requires(
sizeof...(Sizes) == n_dimensions) {
289 static_assert(
sizeof...(Sizes),
"Cannot change number of dimensions");
291 auto new_size = util::size(sizes...);
294 auto new_memory =
allocate(alloc_size_mat<T>(new_size, cpp::last_value(sizes...)));
296 for (
size_t i = 0; i <
std::min(_size, new_size); ++i) {
300 release(
_memory, alloc_size_mat<T>(_size,
dim(n_dimensions - 1)));
304 _memory =
allocate(alloc_size_mat<T>(new_size, cpp::last_value(sizes...)));
308 _dimensions = dyn_detail::sizes(std::make_index_sequence<D>(), sizes...);
316 template <etl_expr E>
324 validate_assign(*
this, e);
329 if (e.alias(*
this)) {
359 template <std_container Container>
360 dyn_matrix_impl& operator=(
const Container& vec)
requires(std::convertible_to<typename Container::value_type, value_type>) {
365 _dimensions[0] = vec.size();
370 validate_assign(*
this, vec);
373 std::copy(vec.begin(), vec.end(),
begin());
401 release(
_memory, alloc_size_mat<T>(_size,
dim(n_dimensions - 1)));
412 release(
_memory, alloc_size_mat<T>(_size,
dim(n_dimensions - 1)));
423 template <
typename Y>
433 template <
typename Y>
445 swap(_size, other._size);
446 swap(_dimensions, other._dimensions);
460 template <
typename V = default_vec>
461 ETL_STRONG_INLINE(
void)
472 template <
typename V = default_vec>
473 ETL_STRONG_INLINE(
void)
484 template <
typename V = default_vec>
485 ETL_STRONG_INLINE(
void)
496 template <
typename V = default_vec>
498 load(
size_t i)
const noexcept {
508 template <
typename V = default_vec>
510 loadu(
size_t i)
const noexcept {
521 size_t& unsafe_dimension_access(
size_t i) {
522 cpp_assert(i < n_dimensions,
"Out of bounds");
523 return _dimensions[i];
531 template <exact_dimensions<D> E>
532 void inherit_if_null(
const E& e) {
544 template <
typename L>
553 template <
typename L>
562 template <
typename L>
571 template <
typename L>
580 template <
typename L>
589 template <
typename L>
608 template <
typename E>
609 void inherit([[maybe_unused]]
const E& e) {
611 cpp_unreachable(
"Impossible to inherit dimensions from generators");
613 cpp_assert(n_dimensions ==
etl::dimensions(e),
"Invalid number of dimensions");
619 _size *= _dimensions[d];
635 return os <<
"V[" << mat.size() <<
"]";
638 os <<
"M[" << mat.dim(0);
640 for (
size_t i = 1; i <
D; ++i) {
641 os <<
"," << mat.dim(i);
648 #ifndef CPP_UTILS_ASSERT_EXCEPTION 649 static_assert(std::is_nothrow_default_constructible_v<
dyn_vector<double>>,
"dyn_vector should be nothrow default constructible");
650 static_assert(std::is_nothrow_copy_constructible_v<
dyn_vector<double>>,
"dyn_vector should be nothrow copy constructible");
651 static_assert(std::is_nothrow_move_constructible_v<
dyn_vector<double>>,
"dyn_vector should be nothrow move constructible");
652 static_assert(std::is_nothrow_copy_assignable_v<
dyn_vector<double>>,
"dyn_vector should be nothrow copy assignable");
653 static_assert(std::is_nothrow_move_assignable_v<
dyn_vector<double>>,
"dyn_vector should be nothrow move assignable");
654 static_assert(std::is_nothrow_destructible_v<
dyn_vector<double>>,
"dyn_vector should be nothrow destructible");
667 template <
typename T,
typename... Sizes>
677 template <
typename T, order SO,
size_t D>
687 template <
typename Stream,
typename T, order SO,
size_t D>
693 for (
const auto& value : matrix) {
703 template <
typename Stream,
typename T, order SO,
size_t D>
705 typename std::decay_t<decltype(matrix)>::dimension_storage_impl new_dimensions;
707 for (
auto& value : new_dimensions) {
711 matrix.resize_arr(new_dimensions);
713 for (
auto& value : matrix) {
Simple collection of values to initialize a dyn matrix.
Definition: dyn_base.hpp:36
A deserializer for ETL expressions.
Definition: deserializer.hpp:16
CRTP class to inject iterators functions.
Definition: iterable.hpp:23
void swap(dyn_matrix_impl< T, SO, D > &lhs, dyn_matrix_impl< T, SO, D > &rhs)
Swap two dyn matrix.
Definition: dyn.hpp:678
void assign_add_to(L &&lhs) const
Add to the given left-hand-side expression.
Definition: dyn_matrix_view.hpp:217
static constexpr size_t alignment
The memory alignment.
Definition: dyn.hpp:34
Dense Matrix with run-time fixed dimensions. The matrix support an arbitrary number of dimensions...
Definition: dyn_base.hpp:294
void std_assign_evaluate(Expr &&expr, Result &&result)
Evaluation of the expr into result.
Definition: evaluator.hpp:1176
void assign_div_to(L &&lhs) const
Divide the given left-hand-side expression.
Definition: dyn_matrix_view.hpp:244
void assign_mul_to(L &&lhs) const
Multiply the given left-hand-side expression.
Definition: dyn_matrix_view.hpp:235
static constexpr order storage_order
The storage order.
Definition: dyn.hpp:33
std::conditional_t< SO==order::RowMajor, value_type *, etl::iterator< this_type > > iterator
The iterator type.
Definition: dyn.hpp:44
dyn_matrix_impl() noexcept
Construct an empty matrix.
Definition: dyn.hpp:77
void assign_to(L &&lhs) const
Assign to the given left-hand-side expression.
Definition: dyn_matrix_view.hpp:208
D D
The number of dimensions.
Definition: dyn_matrix_view.hpp:24
Standard memory utilities.
Define traits to get vectorization information for types when no vector mode is available.
Definition: no_vectorization.hpp:16
order
Storage order of a matrix.
Definition: order.hpp:15
dyn_matrix_impl(const dyn_matrix_impl &rhs) noexcept(assert_nothrow)
Copy construct a matrix.
Definition: dyn.hpp:85
void direct_copy(const S *first, const S *last, T *target)
Performs a direct memory copy.
Definition: memory.hpp:24
constexpr size_t dimensions() noexcept
Return the number of dimensions of the given ETL type.
Definition: helpers.hpp:28
void serialize(serializer< Stream > &os, const dyn_matrix_impl< T, SO, D > &matrix)
Serialize the given matrix using the given serializer.
Definition: dyn.hpp:688
bool is_cpu_up_to_date() const noexcept
Indicates if the CPU memory is up to date.
Definition: sub_view.hpp:777
CRTP class to inject functions testing values of the expressions.
Definition: value_testable.hpp:26
auto end() noexcept
Return an iterator to the past-the-end element of the matrix.
Definition: iterable.hpp:59
A serializer for ETL expressions.
Definition: serializer.hpp:16
auto load(size_t x) const noexcept
Load several elements of the expression at once.
Definition: dyn_matrix_view.hpp:143
Traits to get information about ETL types.
Definition: tmp.hpp:68
Root namespace for the ETL library.
Definition: adapter.hpp:15
value_type * memory_type
The memory type.
Definition: dyn.hpp:41
void invalidate_gpu() const noexcept
Invalidates the GPU memory.
Definition: sub_view.hpp:695
auto dim(E &&value, size_t i) -> detail::identity_helper< E, dim_view< detail::build_identity_type< E >, D >>
Return a view representing the ith Dth dimension.
Definition: view_expression_builder.hpp:25
CRTP class to inject functions creating new expressions.
Definition: expression_able.hpp:23
void store(vec_type< V > in, size_t i) noexcept
Store several elements in the matrix at once.
Definition: dyn_matrix_view.hpp:176
void stream(vec_type< V > in, size_t i) noexcept
Store several elements in the matrix at once, using non-temporal store.
Definition: dyn_matrix_view.hpp:165
std::ostream & operator<<(std::ostream &os, const etl::complex< T > &c)
Outputs a textual representation of the complex number in the given stream.
Definition: complex.hpp:576
etl::dyn_matrix< T, sizeof...(Sizes)> make_dyn_matrix(Sizes... sizes)
Helper to create a dyn matrix using the dimensions.
Definition: dyn.hpp:668
void deserialize(deserializer< Stream > &is, dyn_matrix_impl< T, SO, D > &matrix)
Deserialize the given matrix using the given serializer.
Definition: dyn.hpp:704
Visitor to perform local evaluation when necessary.
Definition: eval_visitors.hpp:23
T value_type
The value type.
Definition: dyn.hpp:39
void storeu(vec_type< V > in, size_t i) noexcept
Store several elements in the matrix at once.
Definition: dyn_matrix_view.hpp:187
CRTP class to inject inplace operations to matrix and vector structures.
Definition: inplace_assignable.hpp:26
void std_mod_evaluate(Expr &&expr, Result &&result)
Compound modulo evaluation of the expr into result.
Definition: evaluator.hpp:1271
auto begin() noexcept
Return an iterator to the first element of the matrix.
Definition: iterable.hpp:46
Matrix with run-time fixed dimensions.
Definition: dyn.hpp:26
void direct_fill(E &&mat, V value)
Fill the given ETL value class with the given value.
Definition: direct_fill.hpp:25
void std_mul_evaluate(Expr &&expr, Result &&result)
Compound multiply evaluation of the expr into result.
Definition: evaluator.hpp:1233
void swap(custom_dyn_matrix_impl< T, SO, D > &lhs, custom_dyn_matrix_impl< T, SO, D > &rhs)
Swap two dyn matrix.
Definition: custom_dyn.hpp:403
auto loadu(size_t x) const noexcept
Load several elements of the expression at once.
Definition: dyn_matrix_view.hpp:154
auto min(L &&lhs, R &&rhs)
Create an expression with the min value of lhs or rhs.
Definition: expression_builder.hpp:77
Base class and utilities for dyn matrix implementations.
std::array< size_t, n_dimensions > dimension_storage_impl
The type used to store the dimensions.
Definition: dyn.hpp:40
void visit(detail::evaluator_visitor &visitor) const
Apply the given visitor to this expression and its descendants.
Definition: dyn_matrix_view.hpp:263
std::conditional_t< SO==order::RowMajor, const value_type *, etl::iterator< const this_type > > const_iterator
The const iterator type.
Definition: dyn.hpp:45
requires(D > 0) struct dyn_base
Matrix with run-time fixed dimensions.
Definition: dyn_base.hpp:113
bool is_gpu_up_to_date() const noexcept
Indicates if the GPU memory is up to date.
Definition: sub_view.hpp:785
void ensure_gpu_up_to_date() const
Copy back from the GPU to the expression memory if necessary.
Definition: dyn_matrix_view.hpp:280
const value_type * const_memory_type
The const memory type.
Definition: dyn.hpp:42
dyn_matrix_impl(dyn_matrix_impl &&rhs) noexcept
Move construct a matrix.
Definition: dyn.hpp:104
dense_dyn_base< this_type, T, SO, D > base_type
The base type.
Definition: dyn.hpp:37
void std_sub_evaluate(Expr &&expr, Result &&result)
Compound subtract evaluation of the expr into result.
Definition: evaluator.hpp:1214
void assign_mod_to(L &&lhs) const
Modulo the given left-hand-side expression.
Definition: dyn_matrix_view.hpp:253
auto allocate(size_t size, mangling_faker< S >=mangling_faker< S >())
Allocate an array of the given size for the given type.
Definition: allocator.hpp:80
Traits to test if the constructor is an initializer list constructor.
Definition: dyn_base.hpp:89
typename V::template vec_type< T > vec_type
The vectorization type for V.
Definition: dyn.hpp:51
const auto & gpu_compute_hint([[maybe_unused]] Y &y) const
Return a GPU computed version of this expression.
Definition: sub_view.hpp:653
typename decay_traits< E >::value_type value_t
Traits to extract the value type out of an ETL type.
Definition: tmp.hpp:81
void std_div_evaluate(Expr &&expr, Result &&result)
Compound divide evaluation of the expr into result.
Definition: evaluator.hpp:1252
void validate_cpu() const noexcept
Validates the CPU memory.
Definition: sub_view.hpp:702
static constexpr size_t n_dimensions
The number of dimensions.
Definition: dyn.hpp:32
void std_add_evaluate(Expr &&expr, Result &&result)
Compound add evaluation of the expr into result.
Definition: evaluator.hpp:1195
value_type *ETL_RESTRICT _memory
Pointer to the allocated memory.
Definition: dyn_base.hpp:312
CRTP class to inject functions testing the dimensions.
Definition: dim_testable.hpp:45
void assign_sub_to(L &&lhs) const
Sub from the given left-hand-side expression.
Definition: dyn_matrix_view.hpp:226