diff --git a/include/rotgen/container/block/dynamic.hpp b/include/rotgen/container/block/dynamic.hpp index f452f46..9ed70b2 100644 --- a/include/rotgen/container/block/dynamic.hpp +++ b/include/rotgen/container/block/dynamic.hpp @@ -87,62 +87,52 @@ namespace rotgen return *this; } - block(Ref const& r, - std::size_t i0, - std::size_t j0, - std::size_t ni, - std::size_t nj) + block(Ref const& r, Index i0, Index j0, Index ni, Index nj) requires(!requires { typename Ref::rotgen_block_tag; } && is_immutable) : parent(r.base(), i0, j0, ni, nj) { } - block(Ref const& r, - std::size_t i0, - std::size_t j0, - std::size_t ni, - std::size_t nj) + block(Ref const& r, Index i0, Index j0, Index ni, Index nj) requires(requires { typename Ref::rotgen_block_tag; } && is_immutable) : parent(r.base(), i0, j0, ni, nj) { } - block(Ref const& r, std::size_t i0, std::size_t j0) + block(Ref const& r, Index i0, Index j0) requires(!requires { typename Ref::rotgen_block_tag; } && Rows != -1 && Cols != -1 && is_immutable) : parent(r.base(), i0, j0, Rows, Cols) { } - block(Ref const& r, std::size_t i0, std::size_t j0) + block(Ref const& r, Index i0, Index j0) requires(requires { typename Ref::rotgen_block_tag; } && Rows != -1 && Cols != -1 && is_immutable) : parent(r.base(), i0, j0, Rows, Cols) { } - block( - Ref& r, std::size_t i0, std::size_t j0, std::size_t ni, std::size_t nj) + block(Ref& r, Index i0, Index j0, Index ni, Index nj) requires(!requires { typename Ref::rotgen_block_tag; } && !is_immutable) : parent(r.base(), i0, j0, ni, nj) { } - block( - Ref& r, std::size_t i0, std::size_t j0, std::size_t ni, std::size_t nj) + block(Ref& r, Index i0, Index j0, Index ni, Index nj) requires(requires { typename Ref::rotgen_block_tag; } && !is_immutable) : parent(r.base(), i0, j0, ni, nj) { } - block(Ref& r, std::size_t i0, std::size_t j0) + block(Ref& r, Index i0, Index j0) requires(!requires { typename Ref::rotgen_block_tag; } && Rows != -1 && Cols != -1 && !is_immutable) : parent(r.base(), i0, j0, Rows, Cols) { } - block(Ref& r, std::size_t i0, std::size_t j0) + block(Ref& r, Index i0, Index j0) requires(requires { typename Ref::rotgen_block_tag; } && Rows != -1 && Cols != -1 && !is_immutable) : parent(r.base(), i0, j0, Rows, Cols) diff --git a/include/rotgen/container/block/fixed.hpp b/include/rotgen/container/block/fixed.hpp index e9ab4a2..df4d148 100644 --- a/include/rotgen/container/block/fixed.hpp +++ b/include/rotgen/container/block/fixed.hpp @@ -109,30 +109,25 @@ namespace rotgen block& operator=(block const&) = default; block& operator=(block&&) = default; - block(Ref const& r, - std::size_t i0, - std::size_t j0, - std::size_t ni, - std::size_t nj) + block(Ref const& r, Index i0, Index j0, Index ni, Index nj) requires(is_immutable) : parent(r.base(), i0, j0, ni, nj) { } - block(Ref const& r, std::size_t i0, std::size_t j0) + block(Ref const& r, Index i0, Index j0) requires(Rows != -1 && Cols != -1 && is_immutable) : parent(r.base(), i0, j0, Rows, Cols) { } - block( - Ref& r, std::size_t i0, std::size_t j0, std::size_t ni, std::size_t nj) + block(Ref& r, Index i0, Index j0, Index ni, Index nj) requires(!is_immutable) : parent(r.base(), i0, j0, ni, nj) { } - block(Ref& r, std::size_t i0, std::size_t j0) + block(Ref& r, Index i0, Index j0) requires(Rows != -1 && Cols != -1 && !is_immutable) : parent(r.base(), i0, j0, Rows, Cols) { diff --git a/include/rotgen/container/matrix/dynamic.hpp b/include/rotgen/container/matrix/dynamic.hpp index 697d177..8c96261 100644 --- a/include/rotgen/container/matrix/dynamic.hpp +++ b/include/rotgen/container/matrix/dynamic.hpp @@ -94,7 +94,7 @@ namespace rotgen "Mismatched between dynamic and static row size"); if constexpr (Cols != -1) { - [[maybe_unused]] std::size_t c = 0; + [[maybe_unused]] Index c = 0; if (init.size()) c = init.begin()->size(); assert(c == Cols && "Mismatched between dynamic and static column size"); diff --git a/include/rotgen/container/matrix/dynamic/model.hpp b/include/rotgen/container/matrix/dynamic/model.hpp index 6e1f153..2520239 100644 --- a/include/rotgen/container/matrix/dynamic/model.hpp +++ b/include/rotgen/container/matrix/dynamic/model.hpp @@ -15,10 +15,8 @@ class ROTGEN_EXPORT CLASSNAME { public: CLASSNAME(); - CLASSNAME(std::size_t rows, std::size_t cols); - CLASSNAME(std::size_t rows, - std::size_t cols, - std::initializer_list init); + CLASSNAME(Index rows, Index cols); + CLASSNAME(Index rows, Index cols, std::initializer_list init); CLASSNAME(std::initializer_list> init); @@ -34,8 +32,8 @@ public: Index cols() const; Index size() const; - void resize(std::size_t new_rows, std::size_t new_cols); - void conservativeResize(std::size_t new_rows, std::size_t new_cols); + void resize(Index new_rows, Index new_cols); + void conservativeResize(Index new_rows, Index new_cols); CLASSNAME normalized() const; CLASSNAME transpose() const; @@ -64,11 +62,11 @@ public: TYPE norm() const; TYPE lp_norm(int p) const; - TYPE& operator()(std::size_t i, std::size_t j); - TYPE const& operator()(std::size_t i, std::size_t j) const; + TYPE& operator()(Index i, Index j); + TYPE const& operator()(Index i, Index j) const; - TYPE& operator()(std::size_t index); - TYPE const& operator()(std::size_t index) const; + TYPE& operator()(Index index); + TYPE const& operator()(Index index) const; CLASSNAME& operator+=(CLASSNAME const& rhs); CLASSNAME& operator-=(CLASSNAME const& rhs); @@ -89,17 +87,17 @@ public: const TYPE* data() const; TYPE* data(); - static CLASSNAME Zero(std::size_t rows, std::size_t cols); - static CLASSNAME Ones(std::size_t rows, std::size_t cols); - static CLASSNAME Constant(std::size_t rows, std::size_t cols, TYPE value); - static CLASSNAME Random(std::size_t rows, std::size_t cols); - static CLASSNAME Identity(std::size_t rows, std::size_t cols); + static CLASSNAME Zero(Index rows, Index cols); + static CLASSNAME Ones(Index rows, Index cols); + static CLASSNAME Constant(Index rows, Index cols, TYPE value); + static CLASSNAME Random(Index rows, Index cols); + static CLASSNAME Identity(Index rows, Index cols); - void setOnes(std::size_t rows, std::size_t cols); - void setZero(std::size_t rows, std::size_t cols); - void setConstant(std::size_t rows, std::size_t cols, TYPE value); - void setRandom(std::size_t rows, std::size_t cols); - void setIdentity(std::size_t rows, std::size_t cols); + void setOnes(Index rows, Index cols); + void setZero(Index rows, Index cols); + void setConstant(Index rows, Index cols, TYPE value); + void setRandom(Index rows, Index cols); + void setIdentity(Index rows, Index cols); private: struct payload; diff --git a/include/rotgen/container/ref/dynamic.hpp b/include/rotgen/container/ref/dynamic.hpp index fcd3d17..015e587 100644 --- a/include/rotgen/container/ref/dynamic.hpp +++ b/include/rotgen/container/ref/dynamic.hpp @@ -86,6 +86,45 @@ namespace rotgen using parent::cwiseInverse; using parent::cwiseSqrt; + // Compound Operators + template + ref& operator+=(ref rhs) + requires(!is_immutable) + { + base() += rhs.base(); + return *this; + } + + template + ref& operator-=(ref rhs) + requires(!is_immutable) + { + base() -= rhs.base(); + return *this; + } + + template + ref& operator*=(ref rhs) + requires(!is_immutable) + { + base() *= rhs.base(); + return *this; + } + + ref& operator*=(std::convertible_to auto s) + requires(!is_immutable) + { + base() *= s; + return *this; + } + + ref& operator/=(std::convertible_to auto s) + requires(!is_immutable) + { + base() /= s; + return *this; + } + // Shape modifications using parent::adjoint; using parent::conjugate; diff --git a/include/rotgen/container/ref/fixed.hpp b/include/rotgen/container/ref/fixed.hpp index 039e700..3d5521d 100644 --- a/include/rotgen/container/ref/fixed.hpp +++ b/include/rotgen/container/ref/fixed.hpp @@ -132,6 +132,45 @@ namespace rotgen using parent::sum; using parent::trace; + // Compound Operators + template + ref& operator+=(ref rhs) + requires(!is_immutable) + { + base() += rhs.base(); + return *this; + } + + template + ref& operator-=(ref rhs) + requires(!is_immutable) + { + base() -= rhs.base(); + return *this; + } + + template + ref& operator*=(ref rhs) + requires(!is_immutable) + { + base() *= rhs.base(); + return *this; + } + + ref& operator*=(std::convertible_to auto s) + requires(!is_immutable) + { + base() *= s; + return *this; + } + + ref& operator/=(std::convertible_to auto s) + requires(!is_immutable) + { + base() /= s; + return *this; + } + // Shape modifications using parent::adjoint; using parent::conjugate; diff --git a/include/rotgen/container/ref/functions.hpp b/include/rotgen/container/ref/functions.hpp index 732b95c..4fa278d 100644 --- a/include/rotgen/container/ref/functions.hpp +++ b/include/rotgen/container/ref/functions.hpp @@ -23,35 +23,6 @@ namespace rotgen return lhs.base() != rhs.base(); } - template - auto operator+=(ref lhs, ref rhs) - { - lhs.base() += rhs.base(); - return lhs; - } - - template - auto operator-=(ref lhs, ref rhs) - { - lhs.base() -= rhs.base(); - return lhs; - } - - template - auto operator*=(ref lhs, ref rhs) - { - lhs.base() *= rhs.base(); - return lhs; - } - - template - auto operator/=(ref lhs, - std::convertible_to auto s) - { - lhs.base() /= s; - return lhs; - } - template auto operator*(std::convertible_to auto s, ref rhs) diff --git a/include/rotgen/detail/payload/matrix.hpp b/include/rotgen/detail/payload/matrix.hpp index d10f755..b7d7a9d 100644 --- a/include/rotgen/detail/payload/matrix.hpp +++ b/include/rotgen/detail/payload/matrix.hpp @@ -26,7 +26,7 @@ namespace rotgen data_type data; - payload(std::size_t r = 0, std::size_t c = 0) : data(r, c) {} + payload(Index r = 0, Index c = 0) : data(r, c) {} payload(std::initializer_list> init) : data(init) @@ -49,7 +49,7 @@ namespace rotgen data_type data; - payload(std::size_t r = 0, std::size_t c = 0) : data(r, c) {} + payload(Index r = 0, Index c = 0) : data(r, c) {} payload(std::initializer_list> init) : data(init) @@ -72,7 +72,7 @@ namespace rotgen data_type data; - payload(std::size_t r = 0, std::size_t c = 0) : data(r, c) {} + payload(Index r = 0, Index c = 0) : data(r, c) {} payload(std::initializer_list> init) : data(init) @@ -95,7 +95,7 @@ namespace rotgen data_type data; - payload(std::size_t r = 0, std::size_t c = 0) : data(r, c) {} + payload(Index r = 0, Index c = 0) : data(r, c) {} payload(std::initializer_list> init) : data(init) diff --git a/include/rotgen/functions/functions.hpp b/include/rotgen/functions/functions.hpp index 6ec88d4..7733f2d 100644 --- a/include/rotgen/functions/functions.hpp +++ b/include/rotgen/functions/functions.hpp @@ -14,19 +14,19 @@ namespace rotgen //----------------------------------------------------------------------------------------------- // Infos & Shape //----------------------------------------------------------------------------------------------- - std::size_t rows(auto const& m) + Index rows(auto const& m) requires(requires { m.rows(); }) { return m.rows(); } - std::size_t cols(auto const& m) + Index cols(auto const& m) requires(requires { m.cols(); }) { return m.cols(); } - std::size_t size(auto const& m) + Index size(auto const& m) requires(requires { m.size(); }) { return m.size(); diff --git a/include/rotgen/functions/operators.hpp b/include/rotgen/functions/operators.hpp index 7147e5d..e56fb82 100644 --- a/include/rotgen/functions/operators.hpp +++ b/include/rotgen/functions/operators.hpp @@ -8,6 +8,7 @@ #pragma once #include + #include #include @@ -81,7 +82,7 @@ namespace rotgen // Compounds operators across types template auto operator+=(A& a, B const& b) - requires(concepts::entity || concepts::entity) + requires(concepts::entity && concepts::entity) { if constexpr (!use_expression_templates) return generalize_t(a) += generalize_t(b); @@ -90,7 +91,7 @@ namespace rotgen template auto operator-=(A& a, B const& b) - requires(concepts::entity || concepts::entity) + requires(concepts::entity && concepts::entity) { if constexpr (!use_expression_templates) return generalize_t(a) -= generalize_t(b); @@ -99,7 +100,7 @@ namespace rotgen template auto operator*=(A& a, B const& b) - requires(concepts::entity || concepts::entity) + requires(concepts::entity && concepts::entity) { if constexpr (!use_expression_templates) return generalize_t(a) *= generalize_t(b); diff --git a/src/matrix/model.cpp b/src/matrix/model.cpp index dcd0267..937e6d9 100644 --- a/src/matrix/model.cpp +++ b/src/matrix/model.cpp @@ -17,7 +17,7 @@ //================================================================================================== CLASSNAME::CLASSNAME() : storage_(std::make_unique(0, 0)) {} -CLASSNAME::CLASSNAME(std::size_t r, std::size_t c) +CLASSNAME::CLASSNAME(Index r, Index c) : storage_(std::make_unique(r, c)) { } @@ -27,9 +27,7 @@ CLASSNAME::CLASSNAME(std::initializer_list> init) { } -CLASSNAME::CLASSNAME(std::size_t r, - std::size_t c, - std::initializer_list init) +CLASSNAME::CLASSNAME(Index r, Index c, std::initializer_list init) : CLASSNAME(r, c) { auto first = init.begin(); @@ -71,32 +69,32 @@ rotgen::Index CLASSNAME::size() const return storage_->data.size(); } -void CLASSNAME::resize(std::size_t new_rows, std::size_t new_cols) +void CLASSNAME::resize(Index new_rows, Index new_cols) { storage_->data.resize(new_rows, new_cols); } -void CLASSNAME::conservativeResize(std::size_t new_rows, std::size_t new_cols) +void CLASSNAME::conservativeResize(Index new_rows, Index new_cols) { storage_->data.conservativeResize(new_rows, new_cols); } -TYPE& CLASSNAME::operator()(std::size_t i, std::size_t j) +TYPE& CLASSNAME::operator()(Index i, Index j) { return storage_->data(i, j); } -TYPE const& CLASSNAME::operator()(std::size_t i, std::size_t j) const +TYPE const& CLASSNAME::operator()(Index i, Index j) const { return storage_->data(i, j); } -TYPE& CLASSNAME::operator()(std::size_t index) +TYPE& CLASSNAME::operator()(Index index) { return storage_->data(index); } -TYPE const& CLASSNAME::operator()(std::size_t index) const +TYPE const& CLASSNAME::operator()(Index index) const { return storage_->data(index); } @@ -303,27 +301,27 @@ CLASSNAME& CLASSNAME::operator/=(TYPE s) //============================================================================== // Generators functions //============================================================================== -void CLASSNAME::setOnes(std::size_t rows, std::size_t cols) +void CLASSNAME::setOnes(Index rows, Index cols) { storage_->assign(payload::data_type::Ones(rows, cols).eval()); } -void CLASSNAME::setZero(std::size_t rows, std::size_t cols) +void CLASSNAME::setZero(Index rows, Index cols) { storage_->assign(payload::data_type::Zero(rows, cols).eval()); } -void CLASSNAME::setConstant(std::size_t rows, std::size_t cols, TYPE value) +void CLASSNAME::setConstant(Index rows, Index cols, TYPE value) { storage_->assign(payload::data_type::Constant(rows, cols, value).eval()); } -void CLASSNAME::setRandom(std::size_t rows, std::size_t cols) +void CLASSNAME::setRandom(Index rows, Index cols) { storage_->assign(payload::data_type::Random(rows, cols).eval()); } -void CLASSNAME::setIdentity(std::size_t rows, std::size_t cols) +void CLASSNAME::setIdentity(Index rows, Index cols) { storage_->assign(payload::data_type::Identity(rows, cols).eval()); } @@ -331,21 +329,21 @@ void CLASSNAME::setIdentity(std::size_t rows, std::size_t cols) //============================================================================== // Static functions //============================================================================== -CLASSNAME CLASSNAME::Ones(std::size_t rows, std::size_t cols) +CLASSNAME CLASSNAME::Ones(Index rows, Index cols) { CLASSNAME m; m.storage_ = std::make_unique(payload::data_type::Ones(rows, cols)); return m; } -CLASSNAME CLASSNAME::Zero(std::size_t rows, std::size_t cols) +CLASSNAME CLASSNAME::Zero(Index rows, Index cols) { CLASSNAME m; m.storage_ = std::make_unique(payload::data_type::Zero(rows, cols)); return m; } -CLASSNAME CLASSNAME::Constant(std::size_t rows, std::size_t cols, TYPE value) +CLASSNAME CLASSNAME::Constant(Index rows, Index cols, TYPE value) { CLASSNAME m; m.storage_ = @@ -353,7 +351,7 @@ CLASSNAME CLASSNAME::Constant(std::size_t rows, std::size_t cols, TYPE value) return m; } -CLASSNAME CLASSNAME::Random(std::size_t rows, std::size_t cols) +CLASSNAME CLASSNAME::Random(Index rows, Index cols) { CLASSNAME m; m.storage_ = @@ -361,7 +359,7 @@ CLASSNAME CLASSNAME::Random(std::size_t rows, std::size_t cols) return m; } -CLASSNAME CLASSNAME::Identity(std::size_t rows, std::size_t cols) +CLASSNAME CLASSNAME::Identity(Index rows, Index cols) { CLASSNAME m; m.storage_ = diff --git a/test/unit/functions/size_related.cpp b/test/unit/functions/size_related.cpp index 3fb4f6e..7d87f5b 100644 --- a/test/unit/functions/size_related.cpp +++ b/test/unit/functions/size_related.cpp @@ -5,10 +5,11 @@ SPDX-License-Identifier: BSL-1.0 */ //================================================================================================== -#include "unit/tests.hpp" #include -#include + +#include "unit/tests.hpp" #include +#include template struct MatrixDescriptor { @@ -18,15 +19,15 @@ template struct MatrixDescriptor template void test_matrix_sizes( - std::size_t rows, - std::size_t cols, + rotgen::Index rows, + rotgen::Index cols, std::function const& init_fn, std::array, N> const& resize_dimensions) { MatrixType matrix(rows, cols); - for (std::size_t r = 0; r < rows; ++r) - for (std::size_t c = 0; c < cols; ++c) init_fn(matrix, r, c); + for (rotgen::Index r = 0; r < rows; ++r) + for (rotgen::Index c = 0; c < cols; ++c) init_fn(matrix, r, c); TTS_EQUAL(rotgen::size(matrix), rows * cols); @@ -37,24 +38,24 @@ void test_matrix_sizes( rotgen::resize(matrix, r, c); - TTS_EQUAL(rotgen::rows(matrix), static_cast(r)); - TTS_EQUAL(rotgen::cols(matrix), static_cast(c)); - TTS_EQUAL(rotgen::size(matrix), static_cast(r * c)); + TTS_EQUAL(rotgen::rows(matrix), r); + TTS_EQUAL(rotgen::cols(matrix), c); + TTS_EQUAL(rotgen::size(matrix), r * c); } rotgen::conservativeResize(matrix, rows, cols); TTS_EQUAL(rotgen::size(matrix), rows * cols); int i = 1; - for (std::size_t r = 0; r < rows; ++r) - for (std::size_t c = 0; c < cols; ++c) matrix(r, c) = i++; + for (rotgen::Index r = 0; r < rows; ++r) + for (rotgen::Index c = 0; c < cols; ++c) matrix(r, c) = i++; rotgen::conservativeResize(matrix, rows + 3, cols + 2); TTS_EQUAL(rotgen::size(matrix), (rows + 3) * (cols + 2)); i = 1; - for (std::size_t r = 0; r < rows; ++r) - for (std::size_t c = 0; c < cols; ++c) TTS_EQUAL(matrix(r, c), i++); + for (rotgen::Index r = 0; r < rows; ++r) + for (rotgen::Index c = 0; c < cols; ++c) TTS_EQUAL(matrix(r, c), i++); } TTS_CASE("Matrix size-related operations")