Compare commits

..

No commits in common. "8e4359d7e69bf3d0571be2c287b47e3a0208d364" and "083ada097ea797c8506033fb5430c495e80ee28f" have entirely different histories.

67 changed files with 1891 additions and 3236 deletions

10
.clangd
View file

@ -1,10 +0,0 @@
CompileFlags:
CompilationDatabase: build/debug/ # Use this to change build type for LSP
Diagnostics:
UnusedIncludes: Strict
ClangTidy:
Add:
- 'bugprone-*'
- 'readability-*'
- 'clang-analyzer-core.*'
- 'clang-analyzer-security.*'

1
.gitignore vendored
View file

@ -12,4 +12,3 @@ _deps
build/* build/*
.idea .idea
.vscode/* .vscode/*
.clangd

View file

@ -39,11 +39,11 @@ test-native-debug:
CXX: clang++ CXX: clang++
CMAKE_PRESET: debug CMAKE_PRESET: debug
test-native-debug-fixed: test-native-debug-static:
<<: *test-native <<: *test-native
variables: variables:
CXX: clang++ CXX: clang++
CMAKE_PRESET: debug-fixed CMAKE_PRESET: debug-static
test-native-debug-et: test-native-debug-et:
<<: *test-native <<: *test-native
@ -57,11 +57,11 @@ test-native-release:
CXX: clang++ CXX: clang++
CMAKE_PRESET: release CMAKE_PRESET: release
test-native-release-fixed: test-native-release-static:
<<: *test-native <<: *test-native
variables: variables:
CXX: clang++ CXX: clang++
CMAKE_PRESET: release-fixed CMAKE_PRESET: release-static
test-native-release-et: test-native-release-et:
<<: *test-native <<: *test-native
@ -78,12 +78,12 @@ test-ubuntu-clang14-debug:
CXXFLAGS: --stdlib=libc++ CXXFLAGS: --stdlib=libc++
CMAKE_PRESET: debug CMAKE_PRESET: debug
test-ubuntu-clang14-debug-fixed: test-ubuntu-clang14-debug-static:
<<: *test-ubuntu2404 <<: *test-ubuntu2404
variables: variables:
CXX: clang++-14 CXX: clang++-14
CXXFLAGS: --stdlib=libc++ CXXFLAGS: --stdlib=libc++
CMAKE_PRESET: debug-fixed CMAKE_PRESET: debug-static
test-ubuntu-clang14-debug-et: test-ubuntu-clang14-debug-et:
<<: *test-ubuntu2404 <<: *test-ubuntu2404
@ -99,12 +99,12 @@ test-ubuntu-clang14-release:
CXXFLAGS: --stdlib=libc++ CXXFLAGS: --stdlib=libc++
CMAKE_PRESET: release CMAKE_PRESET: release
test-ubuntu-clang14-release-fixed: test-ubuntu-clang14-release-static:
<<: *test-ubuntu2404 <<: *test-ubuntu2404
variables: variables:
CXX: clang++-14 CXX: clang++-14
CXXFLAGS: --stdlib=libc++ CXXFLAGS: --stdlib=libc++
CMAKE_PRESET: release-fixed CMAKE_PRESET: release-static
test-ubuntu-clang14-release-et: test-ubuntu-clang14-release-et:
<<: *test-ubuntu2404 <<: *test-ubuntu2404
@ -121,11 +121,11 @@ test-ubuntu-gcc-debug:
CXX: g++ CXX: g++
CMAKE_PRESET: debug CMAKE_PRESET: debug
test-ubuntu-gcc-debug-fixed: test-ubuntu-gcc-debug-static:
<<: *test-ubuntu2404 <<: *test-ubuntu2404
variables: variables:
CXX: g++ CXX: g++
CMAKE_PRESET: debug-fixed CMAKE_PRESET: debug-static
test-ubuntu-gcc-debug-et: test-ubuntu-gcc-debug-et:
<<: *test-ubuntu2404 <<: *test-ubuntu2404
@ -139,11 +139,11 @@ test-ubuntu-gcc-release:
CXX: g++ CXX: g++
CMAKE_PRESET: release CMAKE_PRESET: release
test-ubuntu-gcc-release-fixed: test-ubuntu-gcc-release-static:
<<: *test-ubuntu2404 <<: *test-ubuntu2404
variables: variables:
CXX: g++ CXX: g++
CMAKE_PRESET: release-fixed CMAKE_PRESET: release-static
test-ubuntu-gcc-release-et: test-ubuntu-gcc-release-et:
<<: *test-ubuntu2404 <<: *test-ubuntu2404

View file

@ -96,8 +96,3 @@ include(${ROTGEN_SOURCE_DIR}/cmake/config/rotgen-install.cmake)
## Setup the library's Tests ## Setup the library's Tests
##============================================================================== ##==============================================================================
add_subdirectory(test) add_subdirectory(test)
##==============================================================================
## Setup the library's documentation
##==============================================================================
include(${ROTGEN_SOURCE_DIR}/cmake/docs.cmake)

View file

@ -42,21 +42,21 @@
} }
}, },
{ {
"name": "release-fixed", "name": "release-static",
"displayName": "Release (Fixed size)", "displayName": "Release (Static size)",
"description": "Release (Fixed size) build", "description": "Release (Static size) build",
"generator": "Ninja", "generator": "Ninja",
"binaryDir": "${sourceDir}/build/release-fixed", "binaryDir": "${sourceDir}/build/release-static",
"cacheVariables": { "cacheVariables": {
"ROTGEN_MAX_SIZE": "16" "ROTGEN_MAX_SIZE": "16"
} }
}, },
{ {
"name": "debug-fixed", "name": "debug-static",
"displayName": "Debug (Fixed size)", "displayName": "Debug (Static size)",
"description": "Debug (Fixed size) build", "description": "Debug (Static size) build",
"generator": "Ninja", "generator": "Ninja",
"binaryDir": "${sourceDir}/build/debug-fixed", "binaryDir": "${sourceDir}/build/debug-static",
"cacheVariables": { "cacheVariables": {
"ROTGEN_MAX_SIZE": "16" "ROTGEN_MAX_SIZE": "16"
} }
@ -90,8 +90,8 @@
"configurePreset": "release" "configurePreset": "release"
}, },
{ {
"name": "release-fixed", "name": "release-static",
"configurePreset": "release-fixed" "configurePreset": "release-static"
}, },
{ {
"name": "release-et", "name": "release-et",
@ -102,8 +102,8 @@
"configurePreset": "debug" "configurePreset": "debug"
}, },
{ {
"name": "debug-fixed", "name": "debug-static",
"configurePreset": "debug-fixed" "configurePreset": "debug-static"
}, },
{ {
"name": "debug-et", "name": "debug-et",

View file

@ -1,41 +0,0 @@
##==============================================================================
## ROTGEN - Runtime Overlay for Eigen
## Copyright : CODE RECKONS
## SPDX-License-Identifier: BSL-1.0
##==============================================================================
find_package(Doxygen COMPONENTS dot OPTIONAL_COMPONENTS mscgen dia)
if(Doxygen_FOUND)
# Documentation options
set(DOXYGEN_EXTRACT_ALL YES)
set(DOXYGEN_GENERATE_TREEVIEW YES)
set(DOXYGEN_EXCLUDE_PATTERNS */build/* */test/*)
set(DOXYGEN_USE_MDFILE_AS_MAINPAGE ${CMAKE_SOURCE_DIR}/README.md)
set(DOXYGEN_EXAMPLE_PATH ${CMAKE_SOURCE_DIR})
set(DOXYGEN_DOT_TRANSPARENT YES)
set(DOXYGEN_IMAGE_PATH ${CMAKE_SOURCE_DIR})
# ============================================================================
# Doxygen Awesome CSS
include(FetchContent)
FetchContent_Declare(
doxygen_awesome_content
GIT_REPOSITORY https://github.com/jothepro/doxygen-awesome-css.git
GIT_TAG v2.4.1
GIT_SHALLOW)
FetchContent_GetProperties(doxygen_awesome_content)
if(NOT doxygen_awesome_content_POPULATED)
FetchContent_Populate(doxygen_awesome_content)
endif()
set(DOXYGEN_HTML_EXTRA_STYLESHEET
${doxygen_awesome_content_SOURCE_DIR}/doxygen-awesome.css)
doxygen_add_docs(docs)
endif()

View file

@ -58,10 +58,10 @@ function(print_configuration_summary FORCE_DYNAMIC_VAR FORCE_CONFIG_REASON MAX_S
if(${FORCE_DYNAMIC_VAR}) if(${FORCE_DYNAMIC_VAR})
message(STATUS " Configuration mode: DYNAMIC") message(STATUS " Configuration mode: DYNAMIC")
if(${FORCE_CONFIG_REASON}) if(${FORCE_CONFIG_REASON})
message(STATUS " Reason : No fixed size options were provided") message(STATUS " Reason : No static size options were provided")
endif() endif()
else() else()
message(STATUS " Configuration mode: FIXED SIZE") message(STATUS " Configuration mode: STATIC")
message(STATUS " Expression Templates: ${ROTGEN_ENABLE_EXPRESSION_TEMPLATES}") message(STATUS " Expression Templates: ${ROTGEN_ENABLE_EXPRESSION_TEMPLATES}")
endif() endif()

View file

@ -25,20 +25,20 @@ namespace rotgen
int rank() const { return parent::rank(); } int rank() const { return parent::rank(); }
m_type matrixU() const { return parent::U(); } m_type U() const { return parent::U(); }
m_type matrixD() const { return parent::D(); } m_type D() const { return parent::D(); }
m_type matrixV() const { return parent::V(); } m_type V() const { return parent::V(); }
d_type singularValues() const { return parent::singular_values(); } d_type singular_values() const { return parent::singular_values(); }
m_type matrixU(int r) const { return parent::U(r); } m_type U(int r) const { return parent::U(r); }
m_type matrixD(int r) const { return parent::D(r); } m_type D(int r) const { return parent::D(r); }
m_type matrixV(int r) const { return parent::V(r); } m_type V(int r) const { return parent::V(r); }
m_type singularValues(int r) const { return parent::singular_values(r); } m_type singular_values(int r) const { return parent::singular_values(r); }
}; };
} }

View file

@ -31,28 +31,28 @@ namespace rotgen
int rank() const { return svd_.rank(); } int rank() const { return svd_.rank(); }
auto singularValues() const auto singular_values() const
{ {
if constexpr (!use_expression_templates) if constexpr (!use_expression_templates)
return detail::as_concrete_t<d_type, matrix>{svd_.singularValues()}; return detail::as_concrete_t<d_type, matrix>{svd_.singularValues()};
else return svd_.singularValues(); else return svd_.singularValues();
} }
auto matrixU() const auto U() const
{ {
if constexpr (!use_expression_templates) if constexpr (!use_expression_templates)
return detail::as_concrete_t<u_type, matrix>{svd_.matrixU()}; return detail::as_concrete_t<u_type, matrix>{svd_.matrixU()};
else return svd_.matrixU(); else return svd_.matrixU();
} }
auto matrixV() const auto V() const
{ {
if constexpr (!use_expression_templates) if constexpr (!use_expression_templates)
return detail::as_concrete_t<v_type, matrix>{svd_.matrixV()}; return detail::as_concrete_t<v_type, matrix>{svd_.matrixV()};
else return svd_.matrixV(); else return svd_.matrixV();
} }
auto matrixD() const auto D() const
{ {
auto d = svd_.singularValues().asDiagonal(); auto d = svd_.singularValues().asDiagonal();
if constexpr (!use_expression_templates) if constexpr (!use_expression_templates)
@ -61,7 +61,7 @@ namespace rotgen
else return d; else return d;
} }
auto singularValues(int r) const auto singular_values(int r) const
{ {
auto that = svd_.singularValues().head(r); auto that = svd_.singularValues().head(r);
if constexpr (!use_expression_templates) if constexpr (!use_expression_templates)
@ -69,7 +69,7 @@ namespace rotgen
else return svd_.singularValues(); else return svd_.singularValues();
} }
auto matrixU(int r) const auto U(int r) const
{ {
auto that = svd_.matrixU().leftCols(r); auto that = svd_.matrixU().leftCols(r);
if constexpr (!use_expression_templates) if constexpr (!use_expression_templates)
@ -77,7 +77,7 @@ namespace rotgen
else return that; else return that;
} }
auto matrixV(int r) const auto V(int r) const
{ {
auto that = svd_.matrixV().leftCols(r); auto that = svd_.matrixV().leftCols(r);
if constexpr (!use_expression_templates) if constexpr (!use_expression_templates)
@ -85,7 +85,7 @@ namespace rotgen
else return that; else return that;
} }
auto matrixD(int r) const auto D(int r) const
{ {
auto d = svd_.singularValues().head(r).asDiagonal(); auto d = svd_.singularValues().head(r).asDiagonal();
if constexpr (!use_expression_templates) if constexpr (!use_expression_templates)

View file

@ -12,26 +12,6 @@
namespace rotgen::concepts namespace rotgen::concepts
{ {
//================================================================================================
//! @brief Check if a type is a Rotgen block.
//================================================================================================
template<typename T>
concept block =
requires { typename std::remove_cvref_t<T>::rotgen_block_tag; };
//================================================================================================
//! @brief Check if a type is a Rotgen matrix.
//================================================================================================
template<typename T>
concept matrix =
requires { typename std::remove_cvref_t<T>::rotgen_matrix_tag; };
//================================================================================================
//! @brief Check if a type is a Rotgen map.
//================================================================================================
template<typename T>
concept map = requires { typename std::remove_cvref_t<T>::rotgen_map_tag; };
//================================================================================================ //================================================================================================
//! @brief Check if a type is a Rotgen reference. //! @brief Check if a type is a Rotgen reference.
//================================================================================================ //================================================================================================
@ -56,8 +36,10 @@ namespace rotgen::concepts
//! @brief Check if a type is a ROTGEN type. //! @brief Check if a type is a ROTGEN type.
//================================================================================================ //================================================================================================
template<typename T> template<typename T>
concept entity = concept entity = requires(T const&) {
requires(T const&) { typename std::remove_cvref_t<T>::rotgen_tag; }; typename std::remove_cvref_t<T>::rotgen_tag;
typename std::remove_cvref_t<T>::parent;
};
//================================================================================================ //================================================================================================
//! @brief Check if a type is an EIGEN type. //! @brief Check if a type is an EIGEN type.

View file

@ -7,12 +7,11 @@
//================================================================================================== //==================================================================================================
#pragma once #pragma once
#include <rotgen/detail/assert.hpp>
#include <rotgen/concepts.hpp> #include <rotgen/concepts.hpp>
#include <rotgen/container/block/dynamic/impl.hpp> #include <rotgen/container/block/dynamic/impl.hpp>
#include <rotgen/container/matrix/dynamic.hpp> #include <rotgen/container/matrix/dynamic.hpp>
#include <cassert>
#include <initializer_list> #include <initializer_list>
namespace rotgen namespace rotgen
@ -77,37 +76,14 @@ namespace rotgen
using parent::operator=; using parent::operator=;
template<concepts::entity Src> block& operator=(concepts::entity auto const& other)
block& operator=(Src const& other)
requires(!is_immutable) requires(!is_immutable)
{ {
if constexpr (IsVectorAtCompileTime && Src::IsVectorAtCompileTime) assert(parent::rows() == other.rows() && parent::cols() == other.cols());
{ for (rotgen::Index r = 0; r < parent::rows(); ++r)
ROTGEN_ASSERT(parent::size() == other.size(), for (rotgen::Index c = 0; c < parent::cols(); ++c)
"Block assignment from 1D source doesn't match size");
for (rotgen::Index i = 0; i < parent::size(); ++i)
(*this)[i] = other[i];
}
else if constexpr (IsVectorAtCompileTime && !Src::IsVectorAtCompileTime)
{
auto r = other._rows();
auto c = other._cols();
ROTGEN_ASSERT(r == 1 || c == 1, "Block assignment from dynamic sized "
"source doesn't match static size");
for (rotgen::Index i = 0; i < parent::size(); ++i)
(*this)[i] = other(r == 1 ? 0 : i, c == 1 ? 0 : i);
}
else
{
ROTGEN_ASSERT(parent::_rows() == other._rows() &&
parent::_cols() == other._cols(),
"Block assignment size mismatch");
for (rotgen::Index r = 0; r < parent::_rows(); ++r)
for (rotgen::Index c = 0; c < parent::_cols(); ++c)
(*this)(r, c) = other(r, c); (*this)(r, c) = other(r, c);
}
return *this; return *this;
} }
@ -191,6 +167,13 @@ namespace rotgen
block(parent const& base) : parent(base) {} block(parent const& base) : parent(base) {}
bool is_contiguous_linear() const
{
if (parent::innerStride() != 1) return false;
if constexpr (IsRowMajor) return parent::outerStride() == parent::cols();
else return parent::outerStride() == parent::rows();
}
value_type& operator()(Index i, Index j) value_type& operator()(Index i, Index j)
requires(!is_immutable) requires(!is_immutable)
{ {
@ -200,6 +183,7 @@ namespace rotgen
value_type& operator()(Index i) value_type& operator()(Index i)
requires(!is_immutable && IsVectorAtCompileTime) requires(!is_immutable && IsVectorAtCompileTime)
{ {
assert(is_contiguous_linear());
return parent::operator()(i); return parent::operator()(i);
} }
@ -217,6 +201,7 @@ namespace rotgen
value_type operator()(Index i) const value_type operator()(Index i) const
requires(IsVectorAtCompileTime) requires(IsVectorAtCompileTime)
{ {
assert(is_contiguous_linear());
return parent::operator()(i); return parent::operator()(i);
} }
@ -226,69 +211,66 @@ namespace rotgen
return (*this)(i); return (*this)(i);
} }
concrete_type _evaluate() const { return concrete_type{*this}; } auto evaluate() const { return *this; }
decltype(auto) _noalias() const { return *this; } decltype(auto) noalias() const { return *this; }
decltype(auto) _noalias() { return *this; } decltype(auto) noalias() { return *this; }
concrete_type _normalized() const concrete_type normalized() const
requires(IsVectorAtCompileTime) requires(IsVectorAtCompileTime)
{ {
return concrete_type(base()._normalized()); return concrete_type(base().normalized());
} }
transposed_type _transpose() const transposed_type transpose() const
{ {
return transposed_type(base()._transpose()); return transposed_type(base().transpose());
} }
concrete_type _conjugate() const concrete_type conjugate() const
{ {
return concrete_type(base()._conjugate()); return concrete_type(base().conjugate());
} }
transposed_type _adjoint() const transposed_type adjoint() const
{ {
return transposed_type(base()._adjoint()); return transposed_type(base().adjoint());
} }
concrete_type _cwiseAbs() const concrete_type cwiseAbs() const { return concrete_type(base().cwiseAbs()); }
concrete_type cwiseAbs2() const
{ {
return concrete_type(base()._cwiseAbs()); return concrete_type(base().cwiseAbs2());
} }
concrete_type _cwiseAbs2() const concrete_type cwiseInverse() const
{ {
return concrete_type(base()._cwiseAbs2()); return concrete_type(base().cwiseInverse());
} }
concrete_type _cwiseInverse() const concrete_type cwiseSqrt() const
{ {
return concrete_type(base()._cwiseInverse()); return concrete_type(base().cwiseSqrt());
} }
concrete_type _cwiseSqrt() const void normalize()
{
return concrete_type(base()._cwiseSqrt());
}
void _normalize()
requires(!is_immutable && IsVectorAtCompileTime) requires(!is_immutable && IsVectorAtCompileTime)
{ {
parent::_normalize(); parent::normalize();
} }
void _transposeInPlace() void transposeInPlace()
requires(!is_immutable) requires(!is_immutable)
{ {
parent::_transposeInPlace(); parent::transposeInPlace();
} }
void _adjointInPlace() void adjointInPlace()
requires(!is_immutable) requires(!is_immutable)
{ {
parent::_adjointInPlace(); parent::adjointInPlace();
} }
friend bool operator==(block const& lhs, block const& rhs) friend bool operator==(block const& lhs, block const& rhs)
@ -296,19 +278,17 @@ namespace rotgen
return static_cast<parent const&>(lhs) == static_cast<parent const&>(rhs); return static_cast<parent const&>(lhs) == static_cast<parent const&>(rhs);
} }
template<concepts::entity E> block& operator+=(block const& rhs)
block& operator+=(E const& rhs)
requires(!is_immutable) requires(!is_immutable)
{ {
base() += rhs.base(); base() += static_cast<parent const&>(rhs);
return *this; return *this;
} }
template<concepts::entity E> block& operator-=(block const& rhs)
block& operator-=(E const& rhs)
requires(!is_immutable) requires(!is_immutable)
{ {
base() -= rhs.base(); base() -= static_cast<parent const&>(rhs);
return *this; return *this;
} }
@ -317,11 +297,10 @@ namespace rotgen
return concrete_type(static_cast<parent const&>(*this).operator-()); return concrete_type(static_cast<parent const&>(*this).operator-());
} }
template<concepts::entity E> block& operator*=(block const& rhs)
block& operator*=(E const& rhs)
requires(!is_immutable) requires(!is_immutable)
{ {
base() *= rhs.base(); base() *= static_cast<parent const&>(rhs);
return *this; return *this;
} }
@ -339,155 +318,154 @@ namespace rotgen
return *this; return *this;
} }
auto _minCoeff() const { return parent::_minCoeff(); } auto minCoeff() const { return parent::minCoeff(); }
auto _maxCoeff() const { return parent::_maxCoeff(); } auto maxCoeff() const { return parent::maxCoeff(); }
template<std::integral IndexType> template<std::integral IndexType>
auto _minCoeff(IndexType* row, IndexType* col) const auto minCoeff(IndexType* row, IndexType* col) const
{ {
Index r, c; Index r, c;
auto result = parent::_minCoeff(&r, &c); auto result = parent::minCoeff(&r, &c);
*row = r; *row = r;
*col = c; *col = c;
return result; return result;
} }
template<std::integral IndexType> template<std::integral IndexType>
auto _maxCoeff(IndexType* row, IndexType* col) const auto maxCoeff(IndexType* row, IndexType* col) const
{ {
Index r, c; Index r, c;
auto result = parent::_maxCoeff(&r, &c); auto result = parent::maxCoeff(&r, &c);
*row = r; *row = r;
*col = c; *col = c;
return result; return result;
} }
static concrete_type _Zero() static concrete_type Zero()
requires(Rows != -1 && Cols != -1) requires(Rows != -1 && Cols != -1)
{ {
return parent::_Zero(Rows, Cols); return parent::Zero(Rows, Cols);
} }
static concrete_type _Zero(int rows, int cols) static concrete_type Zero(int rows, int cols)
{ {
if constexpr (Rows != -1) if constexpr (Rows != -1)
ROTGEN_ASSERT(rows == Rows, assert(rows == Rows &&
"Mismatched between dynamic and static row size"); "Mismatched between dynamic and static row size");
if constexpr (Cols != -1) if constexpr (Cols != -1)
ROTGEN_ASSERT(cols == Cols, assert(cols == Cols &&
"Mismatched between dynamic and static column size"); "Mismatched between dynamic and static column size");
return parent::_Zero(rows, cols); return parent::Zero(rows, cols);
} }
static concrete_type _Ones() static concrete_type Ones()
requires(Rows != -1 && Cols != -1) requires(Rows != -1 && Cols != -1)
{ {
return parent::_Ones(Rows, Cols); return parent::Ones(Rows, Cols);
} }
static concrete_type _Ones(int rows, int cols) static concrete_type Ones(int rows, int cols)
{ {
if constexpr (Rows != -1) if constexpr (Rows != -1)
ROTGEN_ASSERT(rows == Rows, assert(rows == Rows &&
"Mismatched between dynamic and static row size"); "Mismatched between dynamic and static row size");
if constexpr (Cols != -1) if constexpr (Cols != -1)
ROTGEN_ASSERT(cols == Cols, assert(cols == Cols &&
"Mismatched between dynamic and static column size"); "Mismatched between dynamic and static column size");
return parent::_Ones(rows, cols); return parent::Ones(rows, cols);
} }
static concrete_type _Constant(value_type value) static concrete_type Constant(value_type value)
requires(Rows != -1 && Cols != -1) requires(Rows != -1 && Cols != -1)
{ {
return parent::_Constant(Rows, Cols, static_cast<double>(value)); return parent::Constant(Rows, Cols, static_cast<double>(value));
} }
static concrete_type _Constant(int rows, int cols, value_type value) static concrete_type Constant(int rows, int cols, value_type value)
{ {
if constexpr (Rows != -1) if constexpr (Rows != -1)
ROTGEN_ASSERT(rows == Rows, assert(rows == Rows &&
"Mismatched between dynamic and static row size"); "Mismatched between dynamic and static row size");
if constexpr (Cols != -1) if constexpr (Cols != -1)
ROTGEN_ASSERT(cols == Cols, assert(cols == Cols &&
"Mismatched between dynamic and static column size"); "Mismatched between dynamic and static column size");
return parent::_Constant(rows, cols, static_cast<double>(value)); return parent::Constant(rows, cols, static_cast<double>(value));
} }
static concrete_type _Random() static concrete_type Random()
requires(Rows != -1 && Cols != -1) requires(Rows != -1 && Cols != -1)
{ {
return parent::_Random(Rows, Cols); return parent::Random(Rows, Cols);
} }
static concrete_type _Random(int rows, int cols) static concrete_type Random(int rows, int cols)
{ {
if constexpr (Rows != -1) if constexpr (Rows != -1)
ROTGEN_ASSERT(rows == Rows, assert(rows == Rows &&
"Mismatched between dynamic and static row size"); "Mismatched between dynamic and static row size");
if constexpr (Cols != -1) if constexpr (Cols != -1)
ROTGEN_ASSERT(cols == Cols, assert(cols == Cols &&
"Mismatched between dynamic and static column size"); "Mismatched between dynamic and static column size");
return parent::_Random(rows, cols); return parent::Random(rows, cols);
} }
static concrete_type _Identity() static concrete_type Identity()
requires(Rows != -1 && Cols != -1) requires(Rows != -1 && Cols != -1)
{ {
return parent::_Identity(Rows, Cols); return parent::Identity(Rows, Cols);
} }
static concrete_type _Identity(int rows, int cols) static concrete_type Identity(int rows, int cols)
{ {
if constexpr (Rows != -1) if constexpr (Rows != -1)
ROTGEN_ASSERT(rows == Rows, assert(rows == Rows &&
"Mismatched between dynamic and static row size"); "Mismatched between dynamic and static row size");
if constexpr (Cols != -1) if constexpr (Cols != -1)
ROTGEN_ASSERT(cols == Cols, assert(cols == Cols &&
"Mismatched between dynamic and static column size"); "Mismatched between dynamic and static column size");
return parent::_Identity(rows, cols); return parent::Identity(rows, cols);
} }
block& _setOnes() block& setOnes()
requires(!is_immutable) requires(!is_immutable)
{ {
parent::assign(parent::_Ones(parent::_rows(), parent::_cols())); parent::assign(parent::Ones(parent::rows(), parent::cols()));
return *this; return *this;
} }
block& _setZero() block& setZero()
requires(!is_immutable) requires(!is_immutable)
{ {
parent::assign(parent::_Zero(parent::_rows(), parent::_cols())); parent::assign(parent::Zero(parent::rows(), parent::cols()));
return *this; return *this;
} }
block& _setConstant(value_type value) block& setConstant(value_type value)
requires(!is_immutable) requires(!is_immutable)
{ {
parent::assign( parent::assign(parent::Constant(parent::rows(), parent::cols(), value));
parent::_Constant(parent::_rows(), parent::_cols(), value));
return *this; return *this;
} }
block& _setRandom() block& setRandom()
requires(!is_immutable) requires(!is_immutable)
{ {
parent::assign(parent::_Random(parent::_rows(), parent::_cols())); parent::assign(parent::Random(parent::rows(), parent::cols()));
return *this; return *this;
} }
block& _setIdentity() block& setIdentity()
requires(!is_immutable) requires(!is_immutable)
{ {
parent::assign(parent::_Identity(parent::_rows(), parent::_cols())); parent::assign(parent::Identity(parent::rows(), parent::cols()));
return *this; return *this;
} }
template<int P> value_type _lpNorm() const template<int P> value_type lpNorm() const
{ {
static_assert(P == 1 || P == 2 || P == Infinity); assert(P == 1 || P == 2 || P == Infinity);
return parent::_lpNorm(P); return parent::lpNorm(P);
} }
parent& base() { return static_cast<parent&>(*this); } parent& base() { return static_cast<parent&>(*this); }
@ -499,41 +477,41 @@ namespace rotgen
auto operator+(block<Ref, R, C, I> const& lhs, block<Ref, R, C, I> const& rhs) auto operator+(block<Ref, R, C, I> const& lhs, block<Ref, R, C, I> const& rhs)
{ {
using concrete_type = typename block<Ref, R, C, I>::concrete_type; using concrete_type = typename block<Ref, R, C, I>::concrete_type;
return concrete_type(lhs.base()._add(rhs)); return concrete_type(lhs.base().add(rhs));
} }
template<typename Ref, int R, int C, bool I> template<typename Ref, int R, int C, bool I>
auto operator-(block<Ref, R, C, I> const& lhs, block<Ref, R, C, I> const& rhs) auto operator-(block<Ref, R, C, I> const& lhs, block<Ref, R, C, I> const& rhs)
{ {
using concrete_type = typename block<Ref, R, C, I>::concrete_type; using concrete_type = typename block<Ref, R, C, I>::concrete_type;
return concrete_type(lhs.base()._sub(rhs)); return concrete_type(lhs.base().sub(rhs));
} }
template<typename Ref, int R, int C, bool I> template<typename Ref, int R, int C, bool I>
auto operator*(block<Ref, R, C, I> const& lhs, block<Ref, R, C, I> const& rhs) auto operator*(block<Ref, R, C, I> const& lhs, block<Ref, R, C, I> const& rhs)
{ {
using concrete_type = typename block<Ref, R, C, I>::concrete_type; using concrete_type = typename block<Ref, R, C, I>::concrete_type;
return concrete_type(lhs.base()._mul(rhs)); return concrete_type(lhs.base().mul(rhs));
} }
template<typename Ref, int R, int C, bool I> template<typename Ref, int R, int C, bool I>
auto operator*(block<Ref, R, C, I> const& lhs, double rhs) auto operator*(block<Ref, R, C, I> const& lhs, double rhs)
{ {
using concrete_type = typename block<Ref, R, C, I>::concrete_type; using concrete_type = typename block<Ref, R, C, I>::concrete_type;
return concrete_type(lhs.base()._mul(rhs)); return concrete_type(lhs.base().mul(rhs));
} }
template<typename Ref, int R, int C, bool I> template<typename Ref, int R, int C, bool I>
auto operator*(double lhs, block<Ref, R, C, I> const& rhs) auto operator*(double lhs, block<Ref, R, C, I> const& rhs)
{ {
using concrete_type = typename block<Ref, R, C, I>::concrete_type; using concrete_type = typename block<Ref, R, C, I>::concrete_type;
return concrete_type(rhs.base()._mul(lhs)); return concrete_type(rhs.base().mul(lhs));
} }
template<typename Ref, int R, int C, bool I> template<typename Ref, int R, int C, bool I>
auto operator/(block<Ref, R, C, I> const& lhs, double rhs) auto operator/(block<Ref, R, C, I> const& lhs, double rhs)
{ {
using concrete_type = typename block<Ref, R, C, I>::concrete_type; using concrete_type = typename block<Ref, R, C, I>::concrete_type;
return concrete_type(lhs.base()._div(rhs)); return concrete_type(lhs.base().div(rhs));
} }
} }

View file

@ -2,36 +2,28 @@
#define TYPE double #define TYPE double
#define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _col) #define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _col)
#define CLASSCONSTNAME ROTGEN_MATRIX_NAME(block_const_impl, SIZE, _col)
#define TRANSCLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _row) #define TRANSCLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _row)
#define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _col) #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _col)
#define TRANSNAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _row) #define TRANSNAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _row)
#define MAPNAME ROTGEN_MATRIX_NAME(BASEMAP, SIZE, _col) #define MAPNAME ROTGEN_MATRIX_NAME(BASEMAP, SIZE, _col)
#define TRANSMAPNAME ROTGEN_MATRIX_NAME(BASEMAP, SIZE, _row)
#include <rotgen/container/block/dynamic/model.hpp> #include <rotgen/container/block/dynamic/model.hpp>
#undef CLASSNAME #undef CLASSNAME
#undef CLASSCONSTNAME
#undef TRANSCLASSNAME #undef TRANSCLASSNAME
#undef TRANSNAME #undef TRANSNAME
#undef SOURCENAME #undef SOURCENAME
#undef MAPNAME #undef MAPNAME
#undef TRANSMAPNAME
#define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _row) #define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _row)
#define CLASSCONSTNAME ROTGEN_MATRIX_NAME(block_const_impl, SIZE, _row)
#define TRANSCLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _col) #define TRANSCLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _col)
#define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _row) #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _row)
#define TRANSNAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _col) #define TRANSNAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _col)
#define MAPNAME ROTGEN_MATRIX_NAME(BASEMAP, SIZE, _row) #define MAPNAME ROTGEN_MATRIX_NAME(BASEMAP, SIZE, _row)
#define TRANSMAPNAME ROTGEN_MATRIX_NAME(BASEMAP, SIZE, _col)
#include <rotgen/container/block/dynamic/model.hpp> #include <rotgen/container/block/dynamic/model.hpp>
#undef CLASSNAME #undef CLASSNAME
#undef CLASSCONSTNAME
#undef TRANSCLASSNAME #undef TRANSCLASSNAME
#undef TRANSNAME #undef TRANSNAME
#undef SOURCENAME #undef SOURCENAME
#undef MAPNAME #undef MAPNAME
#undef TRANSMAPNAME
#undef SIZE #undef SIZE
#undef TYPE #undef TYPE
@ -40,36 +32,28 @@
#define TYPE float #define TYPE float
#define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _col) #define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _col)
#define CLASSCONSTNAME ROTGEN_MATRIX_NAME(block_const_impl, SIZE, _col)
#define TRANSCLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _row) #define TRANSCLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _row)
#define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _col) #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _col)
#define TRANSNAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _row) #define TRANSNAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _row)
#define MAPNAME ROTGEN_MATRIX_NAME(BASEMAP, SIZE, _col) #define MAPNAME ROTGEN_MATRIX_NAME(BASEMAP, SIZE, _col)
#define TRANSMAPNAME ROTGEN_MATRIX_NAME(BASEMAP, SIZE, _row)
#include <rotgen/container/block/dynamic/model.hpp> #include <rotgen/container/block/dynamic/model.hpp>
#undef CLASSNAME #undef CLASSNAME
#undef CLASSCONSTNAME
#undef TRANSCLASSNAME #undef TRANSCLASSNAME
#undef TRANSNAME #undef TRANSNAME
#undef SOURCENAME #undef SOURCENAME
#undef MAPNAME #undef MAPNAME
#undef TRANSMAPNAME
#define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _row) #define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _row)
#define CLASSCONSTNAME ROTGEN_MATRIX_NAME(block_const_impl, SIZE, _row)
#define TRANSCLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _col) #define TRANSCLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _col)
#define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _row) #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _row)
#define TRANSNAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _col) #define TRANSNAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _col)
#define MAPNAME ROTGEN_MATRIX_NAME(BASEMAP, SIZE, _row) #define MAPNAME ROTGEN_MATRIX_NAME(BASEMAP, SIZE, _row)
#define TRANSMAPNAME ROTGEN_MATRIX_NAME(BASEMAP, SIZE, _col)
#include <rotgen/container/block/dynamic/model.hpp> #include <rotgen/container/block/dynamic/model.hpp>
#undef CLASSNAME #undef CLASSNAME
#undef CLASSCONSTNAME
#undef TRANSCLASSNAME #undef TRANSCLASSNAME
#undef TRANSNAME #undef TRANSNAME
#undef SOURCENAME #undef SOURCENAME
#undef MAPNAME #undef MAPNAME
#undef TRANSMAPNAME
#undef SIZE #undef SIZE
#undef TYPE #undef TYPE

View file

@ -23,7 +23,6 @@ public:
CLASSNAME(MAPNAME CONST& r, Index i0, Index j0, Index ni, Index nj); CLASSNAME(MAPNAME CONST& r, Index i0, Index j0, Index ni, Index nj);
CLASSNAME(CLASSNAME CONST& r, Index i0, Index j0, Index ni, Index nj); CLASSNAME(CLASSNAME CONST& r, Index i0, Index j0, Index ni, Index nj);
CLASSNAME(TRANSCLASSNAME CONST& r, Index i0, Index j0, Index ni, Index nj); CLASSNAME(TRANSCLASSNAME CONST& r, Index i0, Index j0, Index ni, Index nj);
CLASSNAME(TRANSMAPNAME CONST& r, Index i0, Index j0, Index ni, Index nj);
CLASSNAME(CLASSNAME const& other); CLASSNAME(CLASSNAME const& other);
CLASSNAME(CLASSNAME&&) noexcept; CLASSNAME(CLASSNAME&&) noexcept;
@ -39,61 +38,51 @@ public:
void assign(SOURCENAME const&); void assign(SOURCENAME const&);
#endif #endif
Index rows() const;
Index cols() const;
Index size() const; Index size() const;
Index _rows() const; Index innerStride() const;
Index _cols() const; Index outerStride() const;
Index _innerStride() const; Index startRow() const;
Index _outerStride() const; Index startCol() const;
Index _startRow() const; SOURCENAME normalized() const;
Index _startCol() const; SOURCENAME transpose() const;
SOURCENAME conjugate() const;
SOURCENAME adjoint() const;
SOURCENAME _normalized() const; SOURCENAME cwiseAbs() const;
SOURCENAME _transpose() const; SOURCENAME cwiseAbs2() const;
SOURCENAME _conjugate() const; SOURCENAME cwiseInverse() const;
SOURCENAME _adjoint() const; SOURCENAME cwiseSqrt() const;
SOURCENAME _cwiseAbs() const;
SOURCENAME _cwiseAbs2() const;
SOURCENAME _cwiseInverse() const;
SOURCENAME _cwiseSqrt() const;
#if !defined(USE_CONST) #if !defined(USE_CONST)
void _normalize(); void normalize();
void _transposeInPlace(); void transposeInPlace();
void _adjointInPlace(); void adjointInPlace();
#endif #endif
TYPE _sum() const; TYPE sum() const;
TYPE _prod() const; TYPE prod() const;
TYPE _mean() const; TYPE mean() const;
TYPE _trace() const; TYPE trace() const;
TYPE _maxCoeff() const; TYPE maxCoeff() const;
TYPE _minCoeff() const; TYPE minCoeff() const;
TYPE _maxCoeff(Index* row, Index* col) const; TYPE maxCoeff(Index* row, Index* col) const;
TYPE _minCoeff(Index* row, Index* col) const; TYPE minCoeff(Index* row, Index* col) const;
TYPE _squaredNorm() const; TYPE squaredNorm() const;
TYPE _norm() const; TYPE norm() const;
TYPE _lpNorm(int p) const; TYPE lpNorm(int p) const;
#if !defined(USE_CONST) #if !defined(USE_CONST)
TYPE& operator()(Index i, Index j); TYPE& operator()(Index i, Index j);
TYPE& operator()(Index index); TYPE& operator()(Index index);
CLASSNAME& operator+=(CLASSNAME const& rhs); CLASSNAME& operator+=(CLASSNAME const& rhs);
CLASSNAME& operator+=(CLASSCONSTNAME const& rhs);
CLASSNAME& operator+=(SOURCENAME const& rhs);
CLASSNAME& operator+=(TRANSNAME const& rhs);
CLASSNAME& operator-=(CLASSNAME const& rhs); CLASSNAME& operator-=(CLASSNAME const& rhs);
CLASSNAME& operator-=(CLASSCONSTNAME const& rhs);
CLASSNAME& operator-=(SOURCENAME const& rhs);
CLASSNAME& operator-=(TRANSNAME const& rhs);
CLASSNAME& operator*=(CLASSNAME const& rhs); CLASSNAME& operator*=(CLASSNAME const& rhs);
CLASSNAME& operator*=(CLASSCONSTNAME const& rhs);
CLASSNAME& operator*=(SOURCENAME const& rhs);
CLASSNAME& operator*=(TRANSNAME const& rhs);
CLASSNAME& operator*=(TYPE d); CLASSNAME& operator*=(TYPE d);
CLASSNAME& operator/=(TYPE d); CLASSNAME& operator/=(TYPE d);
#endif #endif
@ -102,11 +91,11 @@ public:
TYPE operator()(Index index) const; TYPE operator()(Index index) const;
SOURCENAME operator-() const; SOURCENAME operator-() const;
SOURCENAME _add(CLASSNAME const& rhs) const; SOURCENAME add(CLASSNAME const& rhs) const;
SOURCENAME _sub(CLASSNAME const& rhs) const; SOURCENAME sub(CLASSNAME const& rhs) const;
SOURCENAME _mul(CLASSNAME const& rhs) const; SOURCENAME mul(CLASSNAME const& rhs) const;
SOURCENAME _mul(TYPE s) const; SOURCENAME mul(TYPE s) const;
SOURCENAME _div(TYPE s) const; SOURCENAME div(TYPE s) const;
friend ROTGEN_EXPORT std::ostream& operator<<(std::ostream&, friend ROTGEN_EXPORT std::ostream& operator<<(std::ostream&,
CLASSNAME const&); CLASSNAME const&);
@ -122,23 +111,23 @@ public:
#endif #endif
const TYPE* data() const; const TYPE* data() const;
static SOURCENAME _Zero(Index r, Index c) { return SOURCENAME::_Zero(r, c); } static SOURCENAME Zero(Index r, Index c) { return SOURCENAME::Zero(r, c); }
static SOURCENAME _Ones(Index r, Index c) { return SOURCENAME::_Ones(r, c); } static SOURCENAME Ones(Index r, Index c) { return SOURCENAME::Ones(r, c); }
static SOURCENAME _Constant(Index r, Index c, TYPE v) static SOURCENAME Constant(Index r, Index c, TYPE v)
{ {
return SOURCENAME::_Constant(r, c, v); return SOURCENAME::Constant(r, c, v);
} }
static SOURCENAME _Random(Index r, Index c) static SOURCENAME Random(Index r, Index c)
{ {
return SOURCENAME::_Random(r, c); return SOURCENAME::Random(r, c);
} }
static SOURCENAME _Identity(Index r, Index c) static SOURCENAME Identity(Index r, Index c)
{ {
return SOURCENAME::_Identity(r, c); return SOURCENAME::Identity(r, c);
} }
public: public:

View file

@ -193,21 +193,25 @@ namespace rotgen
parent const& base() const { return static_cast<parent const&>(*this); } parent const& base() const { return static_cast<parent const&>(*this); }
auto _evaluate() const { return concrete_type(base().eval()); } auto evaluate() const
{
auto res = base().eval();
return as_concrete_type<decltype(res)>(res);
}
decltype(auto) _noalias() const decltype(auto) noalias() const
{ {
if constexpr (use_expression_templates) return base().noalias(); if constexpr (use_expression_templates) return base().noalias();
else return *this; else return *this;
} }
decltype(auto) _noalias() decltype(auto) noalias()
{ {
if constexpr (use_expression_templates) return base().noalias(); if constexpr (use_expression_templates) return base().noalias();
else return *this; else return *this;
} }
auto _normalized() const auto normalized() const
requires(IsVectorAtCompileTime) requires(IsVectorAtCompileTime)
{ {
if constexpr (use_expression_templates) return base().normalized(); if constexpr (use_expression_templates) return base().normalized();
@ -216,7 +220,7 @@ namespace rotgen
base().normalized()); base().normalized());
} }
auto _transpose() const auto transpose() const
{ {
if constexpr (use_expression_templates) return base().transpose(); if constexpr (use_expression_templates) return base().transpose();
else else
@ -224,14 +228,14 @@ namespace rotgen
base().transpose()); base().transpose());
} }
auto _adjoint() const auto adjoint() const
{ {
if constexpr (use_expression_templates) return base().adjoint(); if constexpr (use_expression_templates) return base().adjoint();
else else
return as_concrete_type<decltype(base().adjoint())>(base().adjoint()); return as_concrete_type<decltype(base().adjoint())>(base().adjoint());
} }
auto _conjugate() const auto conjugate() const
{ {
if constexpr (use_expression_templates) return base().conjugate(); if constexpr (use_expression_templates) return base().conjugate();
else else
@ -239,208 +243,208 @@ namespace rotgen
base().conjugate()); base().conjugate());
} }
void _normalize() void normalize()
requires(!is_immutable && IsVectorAtCompileTime) requires(!is_immutable && IsVectorAtCompileTime)
{ {
parent::normalize(); parent::normalize();
} }
void _transposeInPlace() void transposeInPlace()
requires(!is_immutable) requires(!is_immutable)
{ {
parent::transposeInPlace(); parent::transposeInPlace();
} }
void _adjointInPlace() void adjointInPlace()
requires(!is_immutable) requires(!is_immutable)
{ {
parent::adjointInPlace(); parent::adjointInPlace();
} }
auto _cwiseAbs() const auto cwiseAbs() const
{ {
if constexpr (!use_expression_templates) if constexpr (!use_expression_templates)
return concrete_type{parent::cwiseAbs()}; return concrete_type{parent::cwiseAbs()};
else return base().cwiseAbs(); else return base().cwiseAbs();
} }
auto _cwiseAbs2() const auto cwiseAbs2() const
{ {
if constexpr (!use_expression_templates) if constexpr (!use_expression_templates)
return concrete_type{parent::cwiseAbs2()}; return concrete_type{parent::cwiseAbs2()};
else return base().cwiseAbs2(); else return base().cwiseAbs2();
} }
auto _cwiseInverse() const auto cwiseInverse() const
{ {
if constexpr (!use_expression_templates) if constexpr (!use_expression_templates)
return concrete_type{parent::cwiseInverse()}; return concrete_type{parent::cwiseInverse()};
else return base().cwiseInverse(); else return base().cwiseInverse();
} }
auto _cwiseSqrt() const auto cwiseSqrt() const
{ {
if constexpr (!use_expression_templates) if constexpr (!use_expression_templates)
return concrete_type{parent::cwiseSqrt()}; return concrete_type{parent::cwiseSqrt()};
else return base().cwiseSqrt(); else return base().cwiseSqrt();
} }
static concrete_type _Constant(value_type value) static concrete_type Constant(value_type value)
requires(Rows != -1 && Cols != -1) requires(Rows != -1 && Cols != -1)
{ {
return parent::Constant(Rows, Cols, static_cast<value_type>(value)); return parent::Constant(Rows, Cols, static_cast<value_type>(value));
} }
static concrete_type _Constant(int rows, int cols, value_type value) static concrete_type Constant(int rows, int cols, value_type value)
{ {
if constexpr (Rows != -1) if constexpr (Rows != -1)
ROTGEN_ASSERT(rows == Rows, assert(rows == Rows &&
"Mismatched between dynamic and static row size"); "Mismatched between dynamic and static row size");
if constexpr (Cols != -1) if constexpr (Cols != -1)
ROTGEN_ASSERT(cols == Cols, assert(cols == Cols &&
"Mismatched between dynamic and static column size"); "Mismatched between dynamic and static column size");
return parent::Constant(rows, cols, static_cast<value_type>(value)); return parent::Constant(rows, cols, static_cast<value_type>(value));
} }
static concrete_type _Identity() static concrete_type Identity()
requires(Rows != -1 && Cols != -1) requires(Rows != -1 && Cols != -1)
{ {
return parent::Identity(Rows, Cols); return parent::Identity(Rows, Cols);
} }
static concrete_type _Identity(int rows, int cols) static concrete_type Identity(int rows, int cols)
{ {
if constexpr (Rows != -1) if constexpr (Rows != -1)
ROTGEN_ASSERT(rows == Rows, assert(rows == Rows &&
"Mismatched between dynamic and static row size"); "Mismatched between dynamic and static row size");
if constexpr (Cols != -1) if constexpr (Cols != -1)
ROTGEN_ASSERT(cols == Cols, assert(cols == Cols &&
"Mismatched between dynamic and static column size"); "Mismatched between dynamic and static column size");
return parent::Identity(rows, cols); return parent::Identity(rows, cols);
} }
static concrete_type _Zero() static concrete_type Zero()
requires(Rows != -1 && Cols != -1) requires(Rows != -1 && Cols != -1)
{ {
return parent::Zero(Rows, Cols); return parent::Zero(Rows, Cols);
} }
static concrete_type _Zero(int rows, int cols) static concrete_type Zero(int rows, int cols)
{ {
if constexpr (Rows != -1) if constexpr (Rows != -1)
ROTGEN_ASSERT(rows == Rows, assert(rows == Rows &&
"Mismatched between dynamic and static row size"); "Mismatched between dynamic and static row size");
if constexpr (Cols != -1) if constexpr (Cols != -1)
ROTGEN_ASSERT(cols == Cols, assert(cols == Cols &&
"Mismatched between dynamic and static column size"); "Mismatched between dynamic and static column size");
return parent::Zero(rows, cols); return parent::Zero(rows, cols);
} }
static concrete_type _Ones() static concrete_type Ones()
requires(Rows != -1 && Cols != -1) requires(Rows != -1 && Cols != -1)
{ {
return parent::Ones(Rows, Cols); return parent::Ones(Rows, Cols);
} }
static concrete_type _Ones(int rows, int cols) static concrete_type Ones(int rows, int cols)
{ {
if constexpr (Rows != -1) if constexpr (Rows != -1)
ROTGEN_ASSERT(rows == Rows, assert(rows == Rows &&
"Mismatched between dynamic and static row size"); "Mismatched between dynamic and static row size");
if constexpr (Cols != -1) if constexpr (Cols != -1)
ROTGEN_ASSERT(cols == Cols, assert(cols == Cols &&
"Mismatched between dynamic and static column size"); "Mismatched between dynamic and static column size");
return parent::Ones(rows, cols); return parent::Ones(rows, cols);
} }
static concrete_type _Random() static concrete_type Random()
requires(Rows != -1 && Cols != -1) requires(Rows != -1 && Cols != -1)
{ {
return parent::Random(Rows, Cols); return parent::Random(Rows, Cols);
} }
static concrete_type _Random(int rows, int cols) static concrete_type Random(int rows, int cols)
{ {
if constexpr (Rows != -1) if constexpr (Rows != -1)
ROTGEN_ASSERT(rows == Rows, assert(rows == Rows &&
"Mismatched between dynamic and static row size"); "Mismatched between dynamic and static row size");
if constexpr (Cols != -1) if constexpr (Cols != -1)
ROTGEN_ASSERT(cols == Cols, assert(cols == Cols &&
"Mismatched between dynamic and static column size"); "Mismatched between dynamic and static column size");
return parent::Random(rows, cols); return parent::Random(rows, cols);
} }
block& _setOnes() block& setOnes()
requires(!is_immutable) requires(!is_immutable)
{ {
*this = parent::Ones(_rows(), _cols()); *this = parent::Ones(rows(), cols());
return *this; return *this;
} }
block& _setOnes(int r, int c) block& setOnes(int r, int c)
requires(!is_immutable) requires(!is_immutable)
{ {
*this = parent::Ones(r, c); *this = parent::Ones(r, c);
return *this; return *this;
} }
block& _setZero() block& setZero()
requires(!is_immutable) requires(!is_immutable)
{ {
*this = parent::Zero(_rows(), _cols()); *this = parent::Zero(rows(), cols());
return *this; return *this;
} }
block& _setZero(int r, int c) block& setZero(int r, int c)
requires(!is_immutable) requires(!is_immutable)
{ {
*this = parent::Zero(r, c); *this = parent::Zero(r, c);
return *this; return *this;
} }
block& _setConstant(value_type value) block& setConstant(value_type value)
requires(!is_immutable) requires(!is_immutable)
{ {
*this = parent::Constant(_rows(), _cols(), value); *this = parent::Constant(rows(), cols(), value);
return *this; return *this;
} }
block& _setConstant(int r, int c, value_type value) block& setConstant(int r, int c, value_type value)
requires(!is_immutable) requires(!is_immutable)
{ {
*this = parent::Constant(r, c, value); *this = parent::Constant(r, c, value);
return *this; return *this;
} }
block& _setRandom() block& setRandom()
requires(!is_immutable) requires(!is_immutable)
{ {
*this = parent::Random(_rows(), _cols()); *this = parent::Random(rows(), cols());
return *this; return *this;
} }
block& _setRandom(int r, int c) block& setRandom(int r, int c)
requires(!is_immutable) requires(!is_immutable)
{ {
*this = parent::Random(r, c); *this = parent::Random(r, c);
return *this; return *this;
} }
block& _setIdentity() block& setIdentity()
requires(!is_immutable) requires(!is_immutable)
{ {
*this = parent::Identity(_rows(), _cols()); *this = parent::Identity(rows(), cols());
return *this; return *this;
} }
block& _setIdentity(int r, int c) block& setIdentity(int r, int c)
requires(!is_immutable) requires(!is_immutable)
{ {
*this = parent::Identity(r, c); *this = parent::Identity(r, c);
return *this; return *this;
} }
template<int P> value_type _lpNorm() const template<int P> value_type lpNorm() const
{ {
static_assert(P == 1 || P == 2 || P == Infinity); static_assert(P == 1 || P == 2 || P == Infinity);
return parent::template lpNorm<P>(); return parent::template lpNorm<P>();
@ -478,35 +482,25 @@ namespace rotgen
return (*this)(i); return (*this)(i);
} }
using parent::cols;
using parent::data; using parent::data;
using parent::innerStride;
using parent::mean;
using parent::norm;
using parent::outerStride;
using parent::prod;
using parent::rows;
using parent::size; using parent::size;
using parent::squaredNorm;
using parent::sum;
using parent::trace;
Index _cols() const { return parent::cols(); } auto minCoeff() const { return parent::minCoeff(); }
Index _rows() const { return parent::rows(); } auto maxCoeff() const { return parent::maxCoeff(); }
value_type _mean() const { return parent::mean(); }
value_type _norm() const { return parent::norm(); }
value_type _squaredNorm() const { return parent::squaredNorm(); }
value_type _sum() const { return parent::sum(); }
value_type _prod() const { return parent::prod(); }
value_type _trace() const { return parent::trace(); }
Index _innerStride() const noexcept { return parent::innerStride(); };
Index _outerStride() const noexcept { return parent::outerStride(); };
auto _minCoeff() const { return parent::minCoeff(); }
auto _maxCoeff() const { return parent::maxCoeff(); }
template<std::integral IndexType> template<std::integral IndexType>
auto _minCoeff(IndexType* row, IndexType* col) const auto minCoeff(IndexType* row, IndexType* col) const
{ {
Index r, c; Index r, c;
auto result = parent::minCoeff(&r, &c); auto result = parent::minCoeff(&r, &c);
@ -516,7 +510,7 @@ namespace rotgen
} }
template<std::integral IndexType> template<std::integral IndexType>
auto _maxCoeff(IndexType* row, IndexType* col) const auto maxCoeff(IndexType* row, IndexType* col) const
{ {
Index r, c; Index r, c;
auto result = parent::maxCoeff(&r, &c); auto result = parent::maxCoeff(&r, &c);
@ -525,23 +519,21 @@ namespace rotgen
return result; return result;
} }
Index _startRow() const { return base().startRow(); } Index startRow() const { return base().startRow(); }
Index _startCol() const { return base().startCol(); } Index startCol() const { return base().startCol(); }
template<concepts::entity E> block& operator+=(block const& rhs)
block& operator+=(E const& rhs)
requires(!is_immutable) requires(!is_immutable)
{ {
base() += rhs.base(); static_cast<parent&>(*this) += static_cast<parent const&>(rhs);
return *this; return *this;
} }
template<concepts::entity E> block& operator-=(block const& rhs)
block& operator-=(E const& rhs)
requires(!is_immutable) requires(!is_immutable)
{ {
base() -= rhs.base(); static_cast<parent&>(*this) -= static_cast<parent const&>(rhs);
return *this; return *this;
} }
@ -550,11 +542,10 @@ namespace rotgen
return concrete_type(static_cast<parent const&>(*this).operator-()); return concrete_type(static_cast<parent const&>(*this).operator-());
} }
template<concepts::entity E> block& operator*=(block const& rhs)
block& operator*=(E const& rhs)
requires(!is_immutable) requires(!is_immutable)
{ {
base() *= rhs.base(); static_cast<parent&>(*this) *= static_cast<parent const&>(rhs);
return *this; return *this;
} }

View file

@ -7,14 +7,14 @@
//================================================================================================== //==================================================================================================
#pragma once #pragma once
#include <rotgen/detail/assert.hpp>
#include <rotgen/detail/helpers.hpp> #include <rotgen/detail/helpers.hpp>
#include <rotgen/detail/product.hpp>
#include <rotgen/concepts.hpp> #include <rotgen/concepts.hpp>
#include <rotgen/container/map/dynamic/impl.hpp> #include <rotgen/container/map/dynamic/impl.hpp>
#include <rotgen/container/matrix.hpp> #include <rotgen/container/matrix.hpp>
#include <cassert>
namespace rotgen namespace rotgen
{ {
namespace detail namespace detail
@ -35,7 +35,6 @@ namespace rotgen
using parent = find_map<Ref>; using parent = find_map<Ref>;
using rotgen_tag = void; using rotgen_tag = void;
using rotgen_map_tag = void;
using value_type = typename std::remove_const_t<Ref>::value_type; using value_type = typename std::remove_const_t<Ref>::value_type;
using concrete_type = typename std::remove_const_t<Ref>::concrete_type; using concrete_type = typename std::remove_const_t<Ref>::concrete_type;
@ -53,7 +52,6 @@ namespace rotgen
static constexpr int ColsAtCompileTime = Ref::ColsAtCompileTime; static constexpr int ColsAtCompileTime = Ref::ColsAtCompileTime;
static constexpr int MaxRowsAtCompileTime = Ref::MaxRowsAtCompileTime; static constexpr int MaxRowsAtCompileTime = Ref::MaxRowsAtCompileTime;
static constexpr int MaxColsAtCompileTime = Ref::MaxColsAtCompileTime; static constexpr int MaxColsAtCompileTime = Ref::MaxColsAtCompileTime;
static constexpr int SizeAtCompileTime = Ref::SizeAtCompileTime;
static constexpr bool IsVectorAtCompileTime = Ref::IsVectorAtCompileTime; static constexpr bool IsVectorAtCompileTime = Ref::IsVectorAtCompileTime;
static constexpr bool is_defined_static = static constexpr bool is_defined_static =
RowsAtCompileTime != -1 && ColsAtCompileTime != -1; RowsAtCompileTime != -1 && ColsAtCompileTime != -1;
@ -77,11 +75,11 @@ namespace rotgen
: parent(ptr, r, c, strides<storage_order>(s, r, c)) : parent(ptr, r, c, strides<storage_order>(s, r, c))
{ {
if constexpr (RowsAtCompileTime != -1) if constexpr (RowsAtCompileTime != -1)
ROTGEN_ASSERT(r == RowsAtCompileTime, assert(r == RowsAtCompileTime &&
"Mismatched between dynamic and static row size"); "Mismatched between dynamic and static row size");
if constexpr (ColsAtCompileTime != -1) if constexpr (ColsAtCompileTime != -1)
ROTGEN_ASSERT(c == ColsAtCompileTime, assert(c == ColsAtCompileTime &&
"Mismatched between dynamic and static column size"); "Mismatched between dynamic and static column size");
} }
@ -97,13 +95,8 @@ namespace rotgen
map(ptr_type ptr, Index r, Index c) map(ptr_type ptr, Index r, Index c)
: parent(ptr, r, c, [&]() { : parent(ptr, r, c, [&]() {
if constexpr (!std::same_as<Stride, stride<0, 0>>) if constexpr (!std::same_as<Stride, stride<0, 0>>)
{
return strides<storage_order>(Stride{}, r, c); return strides<storage_order>(Stride{}, r, c);
} else return strides<storage_order>(r, c);
else
{
return strides<storage_order>(r, c);
}
}()) }())
{ {
} }
@ -132,9 +125,9 @@ namespace rotgen
template<typename R2, int O2, typename S2> template<typename R2, int O2, typename S2>
map(map<R2, O2, S2> const& other) map(map<R2, O2, S2> const& other)
: map(other.data(), : map(other.data(),
other._rows(), other.rows(),
other._cols(), other.cols(),
dynamic_stride{other._outerStride(), other._innerStride()}) dynamic_stride{other.outerStride(), other.innerStride()})
{ {
} }
@ -142,52 +135,26 @@ namespace rotgen
map(map const& other) : parent(other) {} map(map const& other) : parent(other) {}
map(map&& other) : parent(std::move(other)) {}
map& operator=(map const& other) map& operator=(map const& other)
requires(!is_immutable) requires(!is_immutable)
{ {
base() = other.base(); base() = static_cast<parent const&>(other);
return *this; return *this;
} }
map& operator=(map&& other) map& operator=(concepts::entity auto const& other)
requires(!is_immutable) requires(!is_immutable)
{ {
base() = std::move(other.base()); assert(parent::rows() == other.rows() && parent::cols() == other.cols());
return *this; if constexpr (IsVectorAtCompileTime)
}
template<concepts::entity Src>
map& operator=(Src const& other)
requires(!is_immutable)
{ {
if constexpr (IsVectorAtCompileTime && Src::IsVectorAtCompileTime)
{
ROTGEN_ASSERT(parent::size() == other.size(),
"Map assignment from 1D source doesn't match size");
for (rotgen::Index i = 0; i < parent::size(); ++i) for (rotgen::Index i = 0; i < parent::size(); ++i)
(*this)[i] = other[i]; (*this)(i) = other(i);
}
else if constexpr (IsVectorAtCompileTime && !Src::IsVectorAtCompileTime)
{
auto r = other._rows();
auto c = other._cols();
ROTGEN_ASSERT(
r == 1 || c == 1,
"Map assignment from dynamic sized source doesn't match static size");
for (rotgen::Index i = 0; i < parent::size(); ++i)
(*this)[i] = other(r == 1 ? 0 : i, c == 1 ? 0 : i);
} }
else else
{ {
ROTGEN_ASSERT(parent::_rows() == other._rows() && for (rotgen::Index r = 0; r < parent::rows(); ++r)
parent::_cols() == other._cols(), for (rotgen::Index c = 0; c < parent::cols(); ++c)
"Map assignment size mismatch");
for (rotgen::Index r = 0; r < parent::_rows(); ++r)
for (rotgen::Index c = 0; c < parent::_cols(); ++c)
(*this)(r, c) = other(r, c); (*this)(r, c) = other(r, c);
} }
@ -229,89 +196,86 @@ namespace rotgen
return (*this)(i); return (*this)(i);
} }
concrete_type _evaluate() const { return concrete_type{*this}; } auto evaluate() const { return *this; }
decltype(auto) _noalias() const { return *this; } decltype(auto) noalias() const { return *this; }
decltype(auto) _noalias() { return *this; } decltype(auto) noalias() { return *this; }
concrete_type _normalized() const concrete_type normalized() const
requires(IsVectorAtCompileTime) requires(IsVectorAtCompileTime)
{ {
return concrete_type(base()._normalized()); return concrete_type(base().normalized());
} }
transposed_type _transpose() const transposed_type transpose() const
{ {
return transposed_type(base()._transpose()); return transposed_type(base().transpose());
} }
concrete_type _conjugate() const concrete_type conjugate() const
{ {
return concrete_type(base()._conjugate()); return concrete_type(base().conjugate());
} }
transposed_type _adjoint() const transposed_type adjoint() const
{ {
return transposed_type(base()._adjoint()); return transposed_type(base().adjoint());
} }
concrete_type _cwiseAbs() const concrete_type cwiseAbs() const { return concrete_type(base().cwiseAbs()); }
concrete_type cwiseAbs2() const
{ {
return concrete_type(base()._cwiseAbs()); return concrete_type(base().cwiseAbs2());
} }
concrete_type _cwiseAbs2() const concrete_type cwiseInverse() const
{ {
return concrete_type(base()._cwiseAbs2()); return concrete_type(base().cwiseInverse());
} }
concrete_type _cwiseInverse() const concrete_type cwiseSqrt() const
{ {
return concrete_type(base()._cwiseInverse()); return concrete_type(base().cwiseSqrt());
} }
concrete_type _cwiseSqrt() const concrete_type cwiseMin(map const& rhs) const
{ {
return concrete_type(base()._cwiseSqrt()); return concrete_type(base().cwiseMin(rhs.base()));
} }
concrete_type _cwiseMin(map const& rhs) const concrete_type cwiseMax(map const& rhs) const
{ {
return concrete_type(base()._cwiseMin(rhs.base())); return concrete_type(base().cwiseMax(rhs.base()));
} }
concrete_type _cwiseMax(map const& rhs) const concrete_type cwiseQuotient(map const& rhs) const
{ {
return concrete_type(base()._cwiseMax(rhs.base())); return concrete_type(base().cwiseQuotient(rhs.base()));
} }
concrete_type _cwiseQuotient(map const& rhs) const concrete_type cwiseProduct(map const& rhs) const
{ {
return concrete_type(base()._cwiseQuotient(rhs.base())); return concrete_type(base().cwiseProduct(rhs.base()));
} }
concrete_type _cwiseProduct(map const& rhs) const concrete_type cwiseMin(value_type s) const
{ {
return concrete_type(base()._cwiseProduct(rhs.base())); return concrete_type(base().cwiseMin(s));
} }
concrete_type _cwiseMin(value_type s) const concrete_type cwiseMax(value_type s) const
{ {
return concrete_type(base()._cwiseMin(s)); return concrete_type(base().cwiseMax(s));
} }
concrete_type _cwiseMax(value_type s) const concrete_type inverse() const { return concrete_type(base().inverse()); }
{
return concrete_type(base()._cwiseMax(s));
}
concrete_type _inverse() const { return concrete_type(base()._inverse()); } concrete_type cross(map const& other) const
concrete_type _cross(map const& other) const
{ {
concrete_type that; concrete_type that;
if constexpr (ColsAtCompileTime == 1) if constexpr (RowsAtCompileTime == -1)
{ {
that(0, 0) = (*this)(1, 0) * other(2, 0) - (*this)(2, 0) * other(1, 0); that(0, 0) = (*this)(1, 0) * other(2, 0) - (*this)(2, 0) * other(1, 0);
that(1, 0) = (*this)(2, 0) * other(0, 0) - (*this)(0, 0) * other(2, 0); that(1, 0) = (*this)(2, 0) * other(0, 0) - (*this)(0, 0) * other(2, 0);
@ -326,29 +290,28 @@ namespace rotgen
return that; return that;
} }
void _normalize() void normalize()
requires(!is_immutable && IsVectorAtCompileTime) requires(!is_immutable && IsVectorAtCompileTime)
{ {
parent::_normalize(); parent::normalize();
} }
void _transposeInPlace() void transposeInPlace()
requires(!is_immutable) requires(!is_immutable)
{ {
parent::_transposeInPlace(); parent::transposeInPlace();
} }
void _adjointInPlace() void adjointInPlace()
requires(!is_immutable) requires(!is_immutable)
{ {
parent::_adjointInPlace(); parent::adjointInPlace();
} }
template<typename R2, int O2, typename S2> template<typename R2, int O2, typename S2>
map& operator+=(map<R2, O2, S2> const& rhs) map& operator+=(map<R2, O2, S2> const& rhs)
requires(!is_immutable) requires(!is_immutable)
{ {
validate_compound_operator(rhs);
base() += rhs.base(); base() += rhs.base();
return *this; return *this;
} }
@ -357,7 +320,6 @@ namespace rotgen
map& operator-=(map<R2, O2, S2> const& rhs) map& operator-=(map<R2, O2, S2> const& rhs)
requires(!is_immutable) requires(!is_immutable)
{ {
validate_compound_operator(rhs);
base() -= rhs.base(); base() -= rhs.base();
return *this; return *this;
} }
@ -371,9 +333,6 @@ namespace rotgen
map& operator*=(map<R2, O2, S2> const& rhs) map& operator*=(map<R2, O2, S2> const& rhs)
requires(!is_immutable) requires(!is_immutable)
{ {
ROTGEN_ASSERT(parent::_cols() == rhs._rows() &&
parent::_cols() == rhs._cols(),
"Incompatible dimensions for compound matrix-product");
base() *= rhs.base(); base() *= rhs.base();
return *this; return *this;
} }
@ -392,121 +351,121 @@ namespace rotgen
return *this; return *this;
} }
auto _minCoeff() const { return parent::_minCoeff(); } auto minCoeff() const { return parent::minCoeff(); }
auto _maxCoeff() const { return parent::_maxCoeff(); } auto maxCoeff() const { return parent::maxCoeff(); }
template<std::integral IndexType> template<std::integral IndexType>
auto _minCoeff(IndexType* row, IndexType* col) const auto minCoeff(IndexType* row, IndexType* col) const
{ {
Index r, c; Index r, c;
auto result = parent::_minCoeff(&r, &c); auto result = parent::minCoeff(&r, &c);
*row = r; *row = r;
*col = c; *col = c;
return result; return result;
} }
template<std::integral IndexType> template<std::integral IndexType>
auto _maxCoeff(IndexType* row, IndexType* col) const auto maxCoeff(IndexType* row, IndexType* col) const
{ {
Index r, c; Index r, c;
auto result = parent::_maxCoeff(&r, &c); auto result = parent::maxCoeff(&r, &c);
*row = r; *row = r;
*col = c; *col = c;
return result; return result;
} }
static auto _Zero() static auto Zero()
requires(requires { Ref::_Zero(); }) requires(requires { Ref::Zero(); })
{ {
return Ref::_Zero(); return Ref::Zero();
} }
static auto _Ones() static auto Ones()
requires(requires { Ref::_Ones(); }) requires(requires { Ref::Ones(); })
{ {
return Ref::_Ones(); return Ref::Ones();
} }
static auto _Zero(int rows, int cols) { return Ref::_Zero(rows, cols); } static auto Zero(int rows, int cols) { return Ref::Zero(rows, cols); }
static auto _Ones(int rows, int cols) { return Ref::_Ones(rows, cols); } static auto Ones(int rows, int cols) { return Ref::Ones(rows, cols); }
static auto _Constant(value_type value) static auto Constant(value_type value)
requires(requires { Ref::_Constant(value); }) requires(requires { Ref::Constant(value); })
{ {
return Ref::_Constant(value); return Ref::Constant(value);
} }
static auto _Constant(int rows, int cols, value_type value) static auto Constant(int rows, int cols, value_type value)
{ {
return Ref::_Constant(rows, cols, value); return Ref::Constant(rows, cols, value);
} }
static auto _Random() static auto Random()
requires(requires { Ref::_Random(); }) requires(requires { Ref::Random(); })
{ {
return Ref::_Random(); return Ref::Random();
} }
static auto _Random(int rows, int cols) { return Ref::_Random(rows, cols); } static auto Random(int rows, int cols) { return Ref::Random(rows, cols); }
static auto _Identity() static auto Identity()
requires(requires { Ref::_Identity(); }) requires(requires { Ref::Identity(); })
{ {
return Ref::_Identity(); return Ref::Identity();
} }
static auto _Identity(int rows, int cols) static auto Identity(int rows, int cols)
{ {
return Ref::_Identity(rows, cols); return Ref::Identity(rows, cols);
} }
map& _setZero() map& setZero()
requires(!is_immutable) requires(!is_immutable)
{ {
parent::_setZero(); parent::setZero();
return *this; return *this;
} }
map& _setOnes() map& setOnes()
requires(!is_immutable) requires(!is_immutable)
{ {
parent::_setOnes(); parent::setOnes();
return *this; return *this;
} }
map& _setIdentity() map& setIdentity()
requires(!is_immutable) requires(!is_immutable)
{ {
parent::_setIdentity(); parent::setIdentity();
return *this; return *this;
} }
map& _setRandom() map& setRandom()
requires(!is_immutable) requires(!is_immutable)
{ {
parent::_setRandom(); parent::setRandom();
return *this; return *this;
} }
map& _setConstant(value_type scalar) map& setConstant(value_type s)
requires(!is_immutable) requires(!is_immutable)
{ {
parent::_setConstant(scalar); parent::setConstant(s);
return *this; return *this;
} }
template<typename R2, int O2, typename S2> template<typename R2, int O2, typename S2>
value_type _dot(map<R2, O2, S2> const& rhs) const value_type dot(map<R2, O2, S2> const& rhs) const
{ {
return base()._dot(rhs.base()); return base().dot(rhs.base());
} }
template<int P> value_type _lpNorm() const template<int P> value_type lpNorm() const
{ {
static_assert(P == 1 || P == 2 || P == Infinity); assert(P == 1 || P == 2 || P == Infinity);
return parent::_lpNorm(P); return parent::lpNorm(P);
} }
parent& base() { return static_cast<parent&>(*this); } parent& base() { return static_cast<parent&>(*this); }
@ -517,32 +476,6 @@ namespace rotgen
{ {
return concrete_type(base().qr_solve(rhs.base())); return concrete_type(base().qr_solve(rhs.base()));
}; };
template<typename R2, int O2, typename S2>
void validate_compound_operator(map<R2, O2, S2> const& rhs)
{
if constexpr (IsVectorAtCompileTime && R2::IsVectorAtCompileTime)
{
if constexpr (is_defined_static && R2::is_defined_static)
{
static_assert(
SizeAtCompileTime == R2::SizeAtCompileTime,
"Compile-time size mismatch in compound assignment operator");
}
else
{
ROTGEN_ASSERT(parent::size() == rhs.size(),
"Size mismatch in compound assignment operator");
}
}
else
{
ROTGEN_ASSERT(parent::_rows() == rhs._rows(),
"Mismatched rows count in compound assignment operator");
ROTGEN_ASSERT(parent::_cols() == rhs._cols(),
"Mismatched cols count in compound assignment operator");
}
}
}; };
template<typename R1, typename R2, int O1, typename S1, int O2, typename S2> template<typename R1, typename R2, int O1, typename S1, int O2, typename S2>
@ -552,7 +485,7 @@ namespace rotgen
using map1_type = map<R1 const, O1, S1>; using map1_type = map<R1 const, O1, S1>;
using map2_type = map<R2 const, O2, S2>; using map2_type = map<R2 const, O2, S2>;
using concrete_type = detail::composite_type<R1, R2, matrix>; using concrete_type = detail::composite_type<R1, R2, matrix>;
return concrete_type(map1_type(lhs).base()._add(map2_type(rhs))); return concrete_type(map1_type(lhs).base().add(map2_type(rhs)));
} }
template<typename R1, typename R2, int O1, typename S1, int O2, typename S2> template<typename R1, typename R2, int O1, typename S1, int O2, typename S2>
@ -562,34 +495,22 @@ namespace rotgen
using map1_type = map<R1 const, O1, S1>; using map1_type = map<R1 const, O1, S1>;
using map2_type = map<R2 const, O2, S2>; using map2_type = map<R2 const, O2, S2>;
using concrete_type = detail::composite_type<R1, R2, matrix>; using concrete_type = detail::composite_type<R1, R2, matrix>;
return concrete_type(map1_type(lhs).base()._sub(map2_type(rhs))); return concrete_type(map1_type(lhs).base().sub(map2_type(rhs)));
} }
template<typename R1, typename R2, int O1, typename S1, int O2, typename S2> template<typename R1, typename R2, int O1, typename S1, int O2, typename S2>
auto operator*(map<R1, O1, S1> const& lhs, map<R2, O2, S2> const& rhs) matrix<typename R1::value_type,
R1::RowsAtCompileTime,
R2::ColsAtCompileTime,
R1::storage_order>
operator*(map<R1, O1, S1> const& lhs, map<R2, O2, S2> const& rhs)
{ {
using map1_type = map<R1 const, O1, S1>; using map1_type = map<R1 const, O1, S1>;
using map2_type = map<R2 const, O2, S2>; using map2_type = map<R2 const, O2, S2>;
using concrete_type = matrix<typename R1::value_type, R1::RowsAtCompileTime, using concrete_type = matrix<typename R1::value_type, R1::RowsAtCompileTime,
R2::ColsAtCompileTime, R1::storage_order>; R2::ColsAtCompileTime, R1::storage_order>;
if constexpr (concrete_type::SizeAtCompileTime == 0) return concrete_type(map1_type(lhs).base().mul(map2_type(rhs).base()));
{
return concrete_type{};
}
else
{
auto product_result =
concrete_type(map1_type(lhs).base()._mul(map2_type(rhs).base()));
if constexpr (concrete_type::SizeAtCompileTime == 1)
{
return product{product_result};
}
else
{
return product_result;
}
}
} }
template<typename R, int O, typename S> template<typename R, int O, typename S>
@ -597,7 +518,7 @@ namespace rotgen
map<R, O, S> const& lhs, std::convertible_to<typename R::value_type> auto s) map<R, O, S> const& lhs, std::convertible_to<typename R::value_type> auto s)
{ {
using concrete_type = typename map<R, O, S>::concrete_type; using concrete_type = typename map<R, O, S>::concrete_type;
return concrete_type(lhs.base()._mul(s)); return concrete_type(lhs.base().mul(s));
} }
template<typename R, int O, typename S> template<typename R, int O, typename S>
@ -605,7 +526,7 @@ namespace rotgen
std::convertible_to<typename R::value_type> auto s, map<R, O, S> const& rhs) std::convertible_to<typename R::value_type> auto s, map<R, O, S> const& rhs)
{ {
using concrete_type = typename map<R, O, S>::concrete_type; using concrete_type = typename map<R, O, S>::concrete_type;
return concrete_type(rhs.base()._mul(s)); return concrete_type(rhs.base().mul(s));
} }
template<typename R, int O, typename S> template<typename R, int O, typename S>
@ -613,7 +534,7 @@ namespace rotgen
map<R, O, S> const& lhs, std::convertible_to<typename R::value_type> auto s) map<R, O, S> const& lhs, std::convertible_to<typename R::value_type> auto s)
{ {
using concrete_type = typename map<R, O, S>::concrete_type; using concrete_type = typename map<R, O, S>::concrete_type;
return concrete_type(lhs.base()._div(s)); return concrete_type(lhs.base().div(s));
} }
template<typename R1, int O1, typename S1, typename R2, int O2, typename S2> template<typename R1, int O1, typename S1, typename R2, int O2, typename S2>

View file

@ -3,39 +3,27 @@
#define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _col) #define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _col)
#define TRANSCLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _row) #define TRANSCLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _row)
#define TRANSCLASSCONSTNAME ROTGEN_MATRIX_NAME(map_const_impl, SIZE, _row)
#define TRANSCLASSNONCONSTNAME ROTGEN_MATRIX_NAME(map_impl, SIZE, _row)
#define CLASSCONSTNAME ROTGEN_MATRIX_NAME(map_const_impl, SIZE, _col) #define CLASSCONSTNAME ROTGEN_MATRIX_NAME(map_const_impl, SIZE, _col)
#define CLASSNONCONSTNAME ROTGEN_MATRIX_NAME(map_impl, SIZE, _col)
#define TRANSSOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _row) #define TRANSSOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _row)
#define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _col) #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _col)
#include <rotgen/container/map/dynamic/model.hpp> #include <rotgen/container/map/dynamic/model.hpp>
#undef CLASSNAME #undef CLASSNAME
#undef TRANSCLASSNAME #undef TRANSCLASSNAME
#undef TRANSCLASSCONSTNAME
#undef TRANSCLASSNONCONSTNAME
#undef TRANSSOURCENAME #undef TRANSSOURCENAME
#undef SOURCENAME #undef SOURCENAME
#undef CLASSCONSTNAME #undef CLASSCONSTNAME
#undef CLASSNONCONSTNAME
#define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _row) #define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _row)
#define TRANSCLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _col) #define TRANSCLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _col)
#define TRANSCLASSCONSTNAME ROTGEN_MATRIX_NAME(map_const_impl, SIZE, _col)
#define TRANSCLASSNONCONSTNAME ROTGEN_MATRIX_NAME(map_impl, SIZE, _col)
#define CLASSCONSTNAME ROTGEN_MATRIX_NAME(map_const_impl, SIZE, _row) #define CLASSCONSTNAME ROTGEN_MATRIX_NAME(map_const_impl, SIZE, _row)
#define CLASSNONCONSTNAME ROTGEN_MATRIX_NAME(map_impl, SIZE, _row)
#define TRANSSOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _col) #define TRANSSOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _col)
#define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _row) #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _row)
#include <rotgen/container/map/dynamic/model.hpp> #include <rotgen/container/map/dynamic/model.hpp>
#undef CLASSNAME #undef CLASSNAME
#undef TRANSCLASSNAME #undef TRANSCLASSNAME
#undef TRANSCLASSCONSTNAME
#undef TRANSCLASSNONCONSTNAME
#undef TRANSSOURCENAME #undef TRANSSOURCENAME
#undef SOURCENAME #undef SOURCENAME
#undef CLASSCONSTNAME #undef CLASSCONSTNAME
#undef CLASSNONCONSTNAME
#undef SIZE #undef SIZE
#undef TYPE #undef TYPE
@ -45,39 +33,27 @@
#define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _col) #define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _col)
#define TRANSCLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _row) #define TRANSCLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _row)
#define TRANSCLASSCONSTNAME ROTGEN_MATRIX_NAME(map_const_impl, SIZE, _row)
#define TRANSCLASSNONCONSTNAME ROTGEN_MATRIX_NAME(map_impl, SIZE, _row)
#define CLASSCONSTNAME ROTGEN_MATRIX_NAME(map_const_impl, SIZE, _col) #define CLASSCONSTNAME ROTGEN_MATRIX_NAME(map_const_impl, SIZE, _col)
#define CLASSNONCONSTNAME ROTGEN_MATRIX_NAME(map_impl, SIZE, _col)
#define TRANSSOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _row) #define TRANSSOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _row)
#define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _col) #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _col)
#include <rotgen/container/map/dynamic/model.hpp> #include <rotgen/container/map/dynamic/model.hpp>
#undef CLASSNAME #undef CLASSNAME
#undef TRANSCLASSNAME #undef TRANSCLASSNAME
#undef TRANSCLASSCONSTNAME
#undef TRANSCLASSNONCONSTNAME
#undef TRANSSOURCENAME #undef TRANSSOURCENAME
#undef SOURCENAME #undef SOURCENAME
#undef CLASSCONSTNAME #undef CLASSCONSTNAME
#undef CLASSNONCONSTNAME
#define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _row) #define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _row)
#define TRANSCLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _col) #define TRANSCLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _col)
#define TRANSCLASSCONSTNAME ROTGEN_MATRIX_NAME(map_const_impl, SIZE, _col)
#define TRANSCLASSNONCONSTNAME ROTGEN_MATRIX_NAME(map_impl, SIZE, _col)
#define CLASSCONSTNAME ROTGEN_MATRIX_NAME(map_const_impl, SIZE, _row) #define CLASSCONSTNAME ROTGEN_MATRIX_NAME(map_const_impl, SIZE, _row)
#define CLASSNONCONSTNAME ROTGEN_MATRIX_NAME(map_impl, SIZE, _row)
#define TRANSSOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _col) #define TRANSSOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _col)
#define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _row) #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _row)
#include <rotgen/container/map/dynamic/model.hpp> #include <rotgen/container/map/dynamic/model.hpp>
#undef CLASSNAME #undef CLASSNAME
#undef TRANSCLASSNAME #undef TRANSCLASSNAME
#undef TRANSCLASSCONSTNAME
#undef TRANSCLASSNONCONSTNAME
#undef TRANSSOURCENAME #undef TRANSSOURCENAME
#undef SOURCENAME #undef SOURCENAME
#undef CLASSCONSTNAME #undef CLASSCONSTNAME
#undef CLASSNONCONSTNAME
#undef SIZE #undef SIZE
#undef TYPE #undef TYPE

View file

@ -28,53 +28,50 @@ public:
~CLASSNAME(); ~CLASSNAME();
Index rows() const;
Index cols() const;
Index size() const; Index size() const;
Index _rows() const; Index innerStride() const;
Index _cols() const; Index outerStride() const;
Index _innerStride() const; SOURCENAME normalized() const;
Index _outerStride() const; SOURCENAME transpose() const;
SOURCENAME conjugate() const;
SOURCENAME adjoint() const;
SOURCENAME _normalized() const; SOURCENAME cwiseAbs() const;
SOURCENAME _transpose() const; SOURCENAME cwiseAbs2() const;
SOURCENAME _conjugate() const; SOURCENAME cwiseInverse() const;
SOURCENAME _adjoint() const; SOURCENAME cwiseSqrt() const;
SOURCENAME _cwiseAbs() const; SOURCENAME cwiseMax(CLASSNAME const&) const;
SOURCENAME _cwiseAbs2() const; SOURCENAME cwiseMin(CLASSNAME const&) const;
SOURCENAME _cwiseInverse() const; SOURCENAME cwiseProduct(CLASSNAME const&) const;
SOURCENAME _cwiseSqrt() const; SOURCENAME cwiseQuotient(CLASSNAME const&) const;
SOURCENAME cwiseMax(TYPE) const;
SOURCENAME _cwiseMax(CLASSNAME const&) const; SOURCENAME cwiseMin(TYPE) const;
SOURCENAME _cwiseMin(CLASSNAME const&) const;
SOURCENAME _cwiseProduct(CLASSNAME const&) const;
SOURCENAME _cwiseQuotient(CLASSNAME const&) const;
SOURCENAME _cwiseMax(TYPE) const;
SOURCENAME _cwiseMin(TYPE) const;
#if !defined(USE_CONST) #if !defined(USE_CONST)
void _normalize(); void normalize();
void _transposeInPlace(); void transposeInPlace();
void _adjointInPlace(); void adjointInPlace();
#endif #endif
TYPE _sum() const; TYPE sum() const;
TYPE _prod() const; TYPE prod() const;
TYPE _mean() const; TYPE mean() const;
TYPE _trace() const; TYPE trace() const;
TYPE _maxCoeff() const; TYPE maxCoeff() const;
TYPE _minCoeff() const; TYPE minCoeff() const;
TYPE _maxCoeff(Index*, Index*) const; TYPE maxCoeff(Index*, Index*) const;
TYPE _minCoeff(Index*, Index*) const; TYPE minCoeff(Index*, Index*) const;
TYPE _dot(CLASSNONCONSTNAME const&) const; TYPE dot(CLASSNAME const&) const;
TYPE _dot(CLASSCONSTNAME const&) const; TYPE dot(TRANSCLASSNAME const&) const;
TYPE _dot(TRANSCLASSCONSTNAME const&) const;
TYPE _dot(TRANSCLASSNONCONSTNAME const&) const;
TYPE _squaredNorm() const; TYPE squaredNorm() const;
TYPE _norm() const; TYPE norm() const;
TYPE _lpNorm(int p) const; TYPE lpNorm(int p) const;
SOURCENAME qr_solve(CLASSNAME const& rhs) const; SOURCENAME qr_solve(CLASSNAME const& rhs) const;
@ -89,31 +86,25 @@ public:
#if !defined(USE_CONST) #if !defined(USE_CONST)
CLASSNAME& operator+=(CLASSNAME const& rhs); CLASSNAME& operator+=(CLASSNAME const& rhs);
CLASSNAME& operator+=(CLASSCONSTNAME const& rhs); CLASSNAME& operator+=(CLASSCONSTNAME const& rhs);
CLASSNAME& operator+=(TRANSCLASSCONSTNAME const& rhs);
CLASSNAME& operator+=(TRANSCLASSNONCONSTNAME const& rhs);
CLASSNAME& operator-=(CLASSNAME const& rhs); CLASSNAME& operator-=(CLASSNAME const& rhs);
CLASSNAME& operator-=(CLASSCONSTNAME const& rhs); CLASSNAME& operator-=(CLASSCONSTNAME const& rhs);
CLASSNAME& operator-=(TRANSCLASSCONSTNAME const& rhs);
CLASSNAME& operator-=(TRANSCLASSNONCONSTNAME const& rhs);
CLASSNAME& operator*=(CLASSNAME const& rhs); CLASSNAME& operator*=(CLASSNAME const& rhs);
CLASSNAME& operator*=(CLASSCONSTNAME const& rhs); CLASSNAME& operator*=(CLASSCONSTNAME const& rhs);
CLASSNAME& operator*=(TRANSCLASSCONSTNAME const& rhs);
CLASSNAME& operator*=(TRANSCLASSNONCONSTNAME const& rhs);
CLASSNAME& operator*=(TYPE d); CLASSNAME& operator*=(TYPE d);
CLASSNAME& operator/=(TYPE d); CLASSNAME& operator/=(TYPE d);
#endif #endif
SOURCENAME operator-() const; SOURCENAME operator-() const;
SOURCENAME _add(CLASSNAME const& rhs) const; SOURCENAME add(CLASSNAME const& rhs) const;
SOURCENAME _add(TRANSCLASSNAME const& rhs) const; SOURCENAME add(TRANSCLASSNAME const& rhs) const;
SOURCENAME _sub(CLASSNAME const& rhs) const; SOURCENAME sub(CLASSNAME const& rhs) const;
SOURCENAME _sub(TRANSCLASSNAME const& rhs) const; SOURCENAME sub(TRANSCLASSNAME const& rhs) const;
SOURCENAME _mul(CLASSNAME const& rhs) const; SOURCENAME mul(CLASSNAME const& rhs) const;
SOURCENAME _mul(TRANSCLASSNAME const& rhs) const; SOURCENAME mul(TRANSCLASSNAME const& rhs) const;
SOURCENAME _mul(TYPE s) const; SOURCENAME mul(TYPE s) const;
SOURCENAME _div(TYPE s) const; SOURCENAME div(TYPE s) const;
SOURCENAME _inverse() const; SOURCENAME inverse() const;
friend ROTGEN_EXPORT std::ostream& operator<<(std::ostream&, friend ROTGEN_EXPORT std::ostream& operator<<(std::ostream&,
CLASSNAME const&); CLASSNAME const&);
@ -123,11 +114,11 @@ public:
#if !defined(USE_CONST) #if !defined(USE_CONST)
TYPE* data(); TYPE* data();
void _setZero(); void setZero();
void _setOnes(); void setOnes();
void _setRandom(); void setRandom();
void _setIdentity(); void setIdentity();
void _setConstant(TYPE); void setConstant(TYPE);
#endif #endif
friend ROTGEN_EXPORT bool operator==(CLASSNAME const& lhs, friend ROTGEN_EXPORT bool operator==(CLASSNAME const& lhs,

View file

@ -7,8 +7,6 @@
//================================================================================================== //==================================================================================================
#pragma once #pragma once
#include <rotgen/detail/product.hpp>
#include <Eigen/Dense> #include <Eigen/Dense>
#include <iostream> #include <iostream>
@ -43,7 +41,6 @@ namespace rotgen
{ {
public: public:
using rotgen_tag = void; using rotgen_tag = void;
using rotgen_map_tag = void;
using parent = detail:: using parent = detail::
map_type<std::remove_const_t<Ref>, Options, std::is_const_v<Ref>, Stride>; map_type<std::remove_const_t<Ref>, Options, std::is_const_v<Ref>, Stride>;
using value_type = typename std::remove_const_t<Ref>::value_type; using value_type = typename std::remove_const_t<Ref>::value_type;
@ -53,7 +50,6 @@ namespace rotgen
static constexpr int ColsAtCompileTime = Ref::ColsAtCompileTime; static constexpr int ColsAtCompileTime = Ref::ColsAtCompileTime;
static constexpr int MaxRowsAtCompileTime = Ref::MaxRowsAtCompileTime; static constexpr int MaxRowsAtCompileTime = Ref::MaxRowsAtCompileTime;
static constexpr int MaxColsAtCompileTime = Ref::MaxColsAtCompileTime; static constexpr int MaxColsAtCompileTime = Ref::MaxColsAtCompileTime;
static constexpr int SizeAtCompileTime = Ref::SizeAtCompileTime;
static constexpr bool IsVectorAtCompileTime = Ref::IsVectorAtCompileTime; static constexpr bool IsVectorAtCompileTime = Ref::IsVectorAtCompileTime;
static constexpr bool has_static_storage = Ref::has_static_storage; static constexpr bool has_static_storage = Ref::has_static_storage;
static constexpr bool IsRowMajor = Ref::IsRowMajor; static constexpr bool IsRowMajor = Ref::IsRowMajor;
@ -116,33 +112,29 @@ namespace rotgen
return *this; return *this;
} }
template<typename OtherDerived>
map& operator=(Eigen::MatrixBase<OtherDerived> const& other)
{
parent::operator=(other);
return *this;
}
template<typename OtherDerived>
map& operator=(Eigen::EigenBase<OtherDerived> const& other)
{
parent::operator=(other);
return *this;
}
parent& base() { return static_cast<parent&>(*this); } parent& base() { return static_cast<parent&>(*this); }
parent const& base() const { return static_cast<parent const&>(*this); } parent const& base() const { return static_cast<parent const&>(*this); }
auto _evaluate() const { return concrete_type(base().eval()); } auto evaluate() const
{
auto res = static_cast<parent const&>(*this).eval();
return as_concrete_type<decltype(res)>(res);
}
decltype(auto) _noalias() const auto evaluate()
{
auto res = static_cast<parent&>(*this).eval();
return as_concrete_type<decltype(res)>(res);
}
decltype(auto) noalias() const
{ {
if constexpr (use_expression_templates) return base().noalias(); if constexpr (use_expression_templates) return base().noalias();
else return *this; else return *this;
} }
decltype(auto) _noalias() decltype(auto) noalias()
{ {
if constexpr (use_expression_templates) return base().noalias(); if constexpr (use_expression_templates) return base().noalias();
else return *this; else return *this;
@ -184,7 +176,6 @@ namespace rotgen
map& operator+=(map<R2, O2, S2> const& rhs) map& operator+=(map<R2, O2, S2> const& rhs)
requires(!is_immutable) requires(!is_immutable)
{ {
validate_compound_operator(rhs);
base() += rhs.base(); base() += rhs.base();
return *this; return *this;
} }
@ -193,7 +184,6 @@ namespace rotgen
map& operator-=(map<R2, O2, S2> const& rhs) map& operator-=(map<R2, O2, S2> const& rhs)
requires(!is_immutable) requires(!is_immutable)
{ {
validate_compound_operator(rhs);
base() -= rhs.base(); base() -= rhs.base();
return *this; return *this;
} }
@ -202,9 +192,6 @@ namespace rotgen
map& operator*=(map<R2, O2, S2> const& rhs) map& operator*=(map<R2, O2, S2> const& rhs)
requires(!is_immutable) requires(!is_immutable)
{ {
ROTGEN_ASSERT(parent::cols() == rhs.rows() &&
parent::cols() == rhs.cols(),
"Incompatible dimensions for compound matrix-product");
base() *= rhs.base(); base() *= rhs.base();
return *this; return *this;
} }
@ -221,91 +208,91 @@ namespace rotgen
return *this; return *this;
} }
auto _cwiseMin(map const& rhs) const auto cwiseMin(map const& rhs) const
{ {
if constexpr (!use_expression_templates) if constexpr (!use_expression_templates)
return concrete_type{parent::cwiseMin(rhs.base())}; return concrete_type{parent::cwiseMin(rhs.base())};
else return base().cwiseMin(rhs.base()); else return base().cwiseMin(rhs.base());
} }
auto _cwiseMin(value_type rhs) const auto cwiseMin(value_type rhs) const
{ {
if constexpr (!use_expression_templates) if constexpr (!use_expression_templates)
return concrete_type{parent::cwiseMin(rhs)}; return concrete_type{parent::cwiseMin(rhs)};
else return base().cwiseMin(rhs); else return base().cwiseMin(rhs);
} }
auto _cwiseMax(map const& rhs) const auto cwiseMax(map const& rhs) const
{ {
if constexpr (!use_expression_templates) if constexpr (!use_expression_templates)
return concrete_type{parent::cwiseMax(rhs.base())}; return concrete_type{parent::cwiseMax(rhs.base())};
else return base().cwiseMax(rhs.base()); else return base().cwiseMax(rhs.base());
} }
auto _cwiseMax(value_type rhs) const auto cwiseMax(value_type rhs) const
{ {
if constexpr (!use_expression_templates) if constexpr (!use_expression_templates)
return concrete_type{parent::cwiseMax(rhs)}; return concrete_type{parent::cwiseMax(rhs)};
else return base().cwiseMax(rhs); else return base().cwiseMax(rhs);
} }
auto _cwiseProduct(map const& rhs) const auto cwiseProduct(map const& rhs) const
{ {
if constexpr (!use_expression_templates) if constexpr (!use_expression_templates)
return concrete_type{parent::cwiseProduct(rhs.base())}; return concrete_type{parent::cwiseProduct(rhs.base())};
else return base().cwiseProduct(rhs.base()); else return base().cwiseProduct(rhs.base());
} }
auto _cwiseQuotient(map const& rhs) const auto cwiseQuotient(map const& rhs) const
{ {
if constexpr (!use_expression_templates) if constexpr (!use_expression_templates)
return concrete_type{parent::cwiseQuotient(rhs.base())}; return concrete_type{parent::cwiseQuotient(rhs.base())};
else return base().cwiseQuotient(rhs.base()); else return base().cwiseQuotient(rhs.base());
} }
auto _cwiseAbs() const auto cwiseAbs() const
{ {
if constexpr (!use_expression_templates) if constexpr (!use_expression_templates)
return concrete_type{parent::cwiseAbs()}; return concrete_type{parent::cwiseAbs()};
else return base().cwiseAbs(); else return base().cwiseAbs();
} }
auto _cwiseAbs2() const auto cwiseAbs2() const
{ {
if constexpr (!use_expression_templates) if constexpr (!use_expression_templates)
return concrete_type{parent::cwiseAbs2()}; return concrete_type{parent::cwiseAbs2()};
else return base().cwiseAbs2(); else return base().cwiseAbs2();
} }
auto _cwiseInverse() const auto cwiseInverse() const
{ {
if constexpr (!use_expression_templates) if constexpr (!use_expression_templates)
return concrete_type{parent::cwiseInverse()}; return concrete_type{parent::cwiseInverse()};
else return base().cwiseInverse(); else return base().cwiseInverse();
} }
auto _cwiseSqrt() const auto cwiseSqrt() const
{ {
if constexpr (!use_expression_templates) if constexpr (!use_expression_templates)
return concrete_type{parent::cwiseSqrt()}; return concrete_type{parent::cwiseSqrt()};
else return base().cwiseSqrt(); else return base().cwiseSqrt();
} }
auto _cross(map const& rhs) const auto cross(map const& rhs) const
{ {
if constexpr (!use_expression_templates) if constexpr (!use_expression_templates)
return concrete_type{parent::cross(rhs.base())}; return concrete_type{parent::cross(rhs.base())};
else return base().cross(rhs.base()); else return base().cross(rhs.base());
} }
auto _inverse() const auto inverse() const
{ {
if constexpr (use_expression_templates) return base().inverse(); if constexpr (use_expression_templates) return base().inverse();
else else
return as_concrete_type<decltype(base().inverse())>(base().inverse()); return as_concrete_type<decltype(base().inverse())>(base().inverse());
} }
auto _normalized() const auto normalized() const
requires(IsVectorAtCompileTime) requires(IsVectorAtCompileTime)
{ {
if constexpr (use_expression_templates) return base().normalized(); if constexpr (use_expression_templates) return base().normalized();
@ -314,7 +301,7 @@ namespace rotgen
base().normalized()); base().normalized());
} }
auto _transpose() const auto transpose() const
{ {
if constexpr (use_expression_templates) return base().transpose(); if constexpr (use_expression_templates) return base().transpose();
else else
@ -322,14 +309,14 @@ namespace rotgen
base().transpose()); base().transpose());
} }
auto _adjoint() const auto adjoint() const
{ {
if constexpr (use_expression_templates) return base().adjoint(); if constexpr (use_expression_templates) return base().adjoint();
else else
return as_concrete_type<decltype(base().adjoint())>(base().adjoint()); return as_concrete_type<decltype(base().adjoint())>(base().adjoint());
} }
auto _conjugate() const auto conjugate() const
{ {
if constexpr (use_expression_templates) return base().conjugate(); if constexpr (use_expression_templates) return base().conjugate();
else else
@ -337,126 +324,116 @@ namespace rotgen
base().conjugate()); base().conjugate());
} }
void _normalize() void normalize()
requires(IsVectorAtCompileTime) requires(IsVectorAtCompileTime)
{ {
base().normalize(); base().normalize();
} }
void _transposeInPlace() { base().transposeInPlace(); } void transposeInPlace() { base().transposeInPlace(); }
void _adjointInPlace() { base().adjointInPlace(); } void adjointInPlace() { base().adjointInPlace(); }
auto qr_solve(auto const& rhs) const auto qr_solve(auto const& rhs) const
{ {
return concrete_type(base().colPivHouseholderQr().solve(rhs.base())); return concrete_type(base().colPivHouseholderQr().solve(rhs.base()));
}; };
static auto _Zero() static auto Zero()
requires(requires { Ref::Zero(); }) requires(requires { Ref::Zero(); })
{ {
return Ref::Zero(); return Ref::Zero();
} }
static auto _Zero(int rows, int cols) { return Ref::Zero(rows, cols); } static auto Zero(int rows, int cols) { return Ref::Zero(rows, cols); }
static auto _Ones() static auto Ones()
requires(requires { Ref::Ones(); }) requires(requires { Ref::Ones(); })
{ {
return Ref::Ones(); return Ref::Ones();
} }
static auto _Ones(int rows, int cols) { return Ref::Ones(rows, cols); } static auto Ones(int rows, int cols) { return Ref::Ones(rows, cols); }
static auto _Constant(value_type value) static auto Constant(value_type value)
requires(requires { Ref::Constant(value); }) requires(requires { Ref::Constant(value); })
{ {
return Ref::Constant(value); return Ref::Constant(value);
} }
static auto _Constant(int rows, int cols, value_type value) static auto Constant(int rows, int cols, value_type value)
{ {
return Ref::Constant(rows, cols, value); return Ref::Constant(rows, cols, value);
} }
static auto _Random() static auto Random()
requires(requires { Ref::Random(); }) requires(requires { Ref::Random(); })
{ {
return Ref::Random(); return Ref::Random();
} }
static auto _Random(int rows, int cols) { return Ref::Random(rows, cols); } static auto Random(int rows, int cols) { return Ref::Random(rows, cols); }
static auto _Identity() static auto Identity()
requires(requires { Ref::Identity(); }) requires(requires { Ref::Identity(); })
{ {
return Ref::Identity(); return Ref::Identity();
} }
static auto _Identity(int rows, int cols) static auto Identity(int rows, int cols)
{ {
return Ref::Identity(rows, cols); return Ref::Identity(rows, cols);
} }
map& _setOnes() map& setOnes()
{ {
base() = parent::Ones(base().rows(), base().cols()); base() = parent::Ones(base().rows(), base().cols());
return *this; return *this;
} }
map& _setZero() map& setZero()
{ {
base() = parent::Zero(base().rows(), base().cols()); base() = parent::Zero(base().rows(), base().cols());
return *this; return *this;
} }
map& _setConstant(value_type value) map& setConstant(value_type value)
{ {
base() = parent::Constant(base().rows(), base().cols(), value); base() = parent::Constant(base().rows(), base().cols(), value);
return *this; return *this;
} }
map& _setRandom() map& setRandom()
{ {
base() = parent::Random(base().rows(), base().cols()); base() = parent::Random(base().rows(), base().cols());
return *this; return *this;
} }
map& _setIdentity() map& setIdentity()
{ {
base() = parent::Identity(base().rows(), base().cols()); base() = parent::Identity(base().rows(), base().cols());
return *this; return *this;
} }
using parent::cols;
using parent::data; using parent::data;
using parent::innerStride;
using parent::mean;
using parent::norm;
using parent::outerStride;
using parent::prod;
using parent::rows;
using parent::size; using parent::size;
using parent::squaredNorm;
using parent::sum;
using parent::trace;
Index _cols() const { return parent::cols(); } auto minCoeff() const { return parent::minCoeff(); }
Index _rows() const { return parent::rows(); } auto maxCoeff() const { return parent::maxCoeff(); }
value_type _mean() const { return parent::mean(); }
value_type _norm() const { return parent::norm(); }
value_type _squaredNorm() const { return parent::squaredNorm(); }
value_type _sum() const { return parent::sum(); }
value_type _prod() const { return parent::prod(); }
value_type _trace() const { return parent::trace(); }
Index _innerStride() const noexcept { return parent::innerStride(); };
Index _outerStride() const noexcept { return parent::outerStride(); };
auto _minCoeff() const { return parent::minCoeff(); }
auto _maxCoeff() const { return parent::maxCoeff(); }
template<std::integral IndexType> template<std::integral IndexType>
auto _minCoeff(IndexType* row, IndexType* col) const auto minCoeff(IndexType* row, IndexType* col) const
{ {
Index r, c; Index r, c;
auto result = parent::minCoeff(&r, &c); auto result = parent::minCoeff(&r, &c);
@ -466,7 +443,7 @@ namespace rotgen
} }
template<std::integral IndexType> template<std::integral IndexType>
auto _maxCoeff(IndexType* row, IndexType* col) const auto maxCoeff(IndexType* row, IndexType* col) const
{ {
Index r, c; Index r, c;
auto result = parent::maxCoeff(&r, &c); auto result = parent::maxCoeff(&r, &c);
@ -476,42 +453,16 @@ namespace rotgen
} }
template<typename R2, int O2, typename S2> template<typename R2, int O2, typename S2>
value_type _dot(map<R2, O2, S2> const& rhs) const value_type dot(map<R2, O2, S2> const& rhs) const
{ {
return base().dot(rhs.base()); return base().dot(rhs.base());
} }
template<int P> value_type _lpNorm() const template<int P> value_type lpNorm() const
{ {
static_assert(P == 1 || P == 2 || P == Infinity); static_assert(P == 1 || P == 2 || P == Infinity);
return parent::template lpNorm<P>(); return parent::template lpNorm<P>();
} }
template<typename R2, int O2, typename S2>
void validate_compound_operator(map<R2, O2, S2> const& rhs)
{
if constexpr (IsVectorAtCompileTime && R2::IsVectorAtCompileTime)
{
if constexpr (is_defined_static && R2::is_defined_static)
{
static_assert(
SizeAtCompileTime == R2::SizeAtCompileTime,
"Compile-time size mismatch in compound assignment operator");
}
else
{
ROTGEN_ASSERT(parent::size() == rhs.size(),
"Size mismatch in compound assignment operator");
}
}
else
{
ROTGEN_ASSERT(parent::rows() == rhs.rows(),
"Mismatched rows count in compound assignment operator");
ROTGEN_ASSERT(parent::cols() == rhs.cols(),
"Mismatched cols count in compound assignment operator");
}
}
}; };
template<typename R1, typename R2, int O1, typename S1, int O2, typename S2> template<typename R1, typename R2, int O1, typename S1, int O2, typename S2>
@ -583,14 +534,13 @@ namespace rotgen
} }
template<typename R1, typename R2, int O1, typename S1, int O2, typename S2> template<typename R1, typename R2, int O1, typename S1, int O2, typename S2>
auto operator*(map<R1, O1, S1> const& lhs, map<R2, O2, S2> const& rhs) matrix<typename R1::value_type, R1::RowsAtCompileTime, R2::ColsAtCompileTime>
operator*(map<R1, O1, S1> const& lhs, map<R2, O2, S2> const& rhs)
{ {
auto p = lhs.base() * rhs.base(); using concrete_type = matrix<typename R1::value_type, R1::RowsAtCompileTime,
using concrete_type = detail::as_concrete_t<decltype(p), matrix>; R2::ColsAtCompileTime>;
if constexpr (concrete_type::SizeAtCompileTime == 1) return concrete_type(lhs.base() * rhs.base());
return product{concrete_type{p}};
else return concrete_type{p};
} }
template<typename R, int O, typename S> template<typename R, int O, typename S>

View file

@ -7,12 +7,11 @@
//================================================================================================== //==================================================================================================
#pragma once #pragma once
#include <rotgen/detail/assert.hpp>
#include <rotgen/detail/helpers.hpp> #include <rotgen/detail/helpers.hpp>
#include <rotgen/concepts.hpp> #include <rotgen/concepts.hpp>
#include <rotgen/container/matrix/dynamic/impl.hpp> #include <rotgen/container/matrix/dynamic/impl.hpp>
#include <cassert>
#include <initializer_list> #include <initializer_list>
namespace rotgen namespace rotgen
@ -28,7 +27,6 @@ namespace rotgen
public: public:
using parent = find_matrix<Scalar, Opts>; using parent = find_matrix<Scalar, Opts>;
using rotgen_tag = void; using rotgen_tag = void;
using rotgen_matrix_tag = void;
using concrete_type = matrix; using concrete_type = matrix;
using value_type = Scalar; using value_type = Scalar;
@ -50,40 +48,29 @@ namespace rotgen
static constexpr bool has_static_storage = false; static constexpr bool has_static_storage = false;
static constexpr bool is_immutable = false; static constexpr bool is_immutable = false;
static constexpr int InnerStrideAtCompileTime = 1; static constexpr int InnerStrideAtCompileTime = 1;
static constexpr int OuterStrideAtCompileTime = IsRowMajor ? Cols : Rows; static constexpr int OuterStrideAtCompileTime =
IsRowMajor ? ColsAtCompileTime : RowsAtCompileTime;
using transposed_type = matrix<value_type, Cols, Rows, storage_order>; using transposed_type = matrix<value_type, Cols, Rows, storage_order>;
static constexpr int AllocatedRows = matrix() : parent(Rows == -1 ? 0 : Rows, Cols == -1 ? 0 : Cols) {}
Rows == -1 ? (MaxRows == -1 ? 0 : MaxRows) : Rows;
static constexpr int AllocatedCols =
Cols == -1 ? (MaxCols == -1 ? 0 : MaxCols) : Cols;
matrix() : parent(AllocatedRows, AllocatedCols) {}
matrix(Index r, Index c) : parent(r, c) matrix(Index r, Index c) : parent(r, c)
{ {
if constexpr (Rows != -1) if constexpr (Rows != -1)
ROTGEN_ASSERT(r == Rows, assert(r == Rows && "Mismatched between dynamic and static row size");
"Mismatched between dynamic and static row size");
if constexpr (Cols != -1) if constexpr (Cols != -1)
ROTGEN_ASSERT(c == Cols, assert(c == Cols &&
"Mismatched between dynamic and static column size"); "Mismatched between dynamic and static column size");
} }
matrix(Index n) matrix(Index n)
requires(IsVectorAtCompileTime && (Rows != 1 || Cols != 1)) requires(IsVectorAtCompileTime && (Rows != 1 || Cols != 1))
: parent(Rows != 1 ? n : 1, Cols != 1 ? n : 1) : parent(Rows != -1 ? 1 : n, Cols != -1 ? 1 : n)
{ {
if constexpr (Rows == 1 && Cols != -1)
ROTGEN_ASSERT(Cols == n,
"Mismatched between dynamic and static col size");
if constexpr (Cols == 1 && Rows != -1)
ROTGEN_ASSERT(Rows == n,
"Mismatched between dynamic and static row size");
} }
explicit matrix(Scalar v) matrix(Scalar v)
requires(Rows == 1 && Cols == 1) requires(Rows == 1 && Cols == 1)
: parent(1, 1, {v}) : parent(1, 1, {v})
{ {
@ -102,13 +89,13 @@ namespace rotgen
: parent(init) : parent(init)
{ {
if constexpr (Rows != -1) if constexpr (Rows != -1)
ROTGEN_ASSERT(init.size() == Rows, assert(init.size() == Rows &&
"Mismatched between dynamic and static row size"); "Mismatched between dynamic and static row size");
if constexpr (Cols != -1) if constexpr (Cols != -1)
{ {
[[maybe_unused]] Index c = 0; [[maybe_unused]] Index c = 0;
if (init.size()) c = init.begin()->size(); if (init.size()) c = init.begin()->size();
ROTGEN_ASSERT(c == Cols, assert(c == Cols &&
"Mismatched between dynamic and static column size"); "Mismatched between dynamic and static column size");
} }
} }
@ -119,28 +106,31 @@ namespace rotgen
{ {
} }
template<concepts::entity Src> matrix(Src const& other) : parent() matrix(concepts::entity auto const& e) : parent(e.rows(), e.cols())
{ {
if constexpr (IsVectorAtCompileTime && Src::IsVectorAtCompileTime) if constexpr (Rows != -1)
{ assert(e.rows() == Rows &&
resize(other.size()); "Mismatched between dynamic and static row size");
for (rotgen::Index i = 0; i < parent::size(); ++i) if constexpr (Cols != -1)
(*this)[i] = other[i]; assert(e.cols() == Cols &&
} "Mismatched between dynamic and static col size");
else for (rotgen::Index r = 0; r < e.rows(); ++r)
{ for (rotgen::Index c = 0; c < e.cols(); ++c) (*this)(r, c) = e(r, c);
resize(other._rows(), other._cols());
for (rotgen::Index r = 0; r < parent::_rows(); ++r)
for (rotgen::Index c = 0; c < parent::_cols(); ++c)
(*this)(r, c) = other(r, c);
}
} }
matrix& operator=(concepts::entity auto const& other) matrix& operator=(concepts::entity auto const& e)
{ {
matrix local(other); if constexpr (Rows != -1)
swap(local); assert(e.rows() == Rows &&
"Mismatched between dynamic and static row size");
if constexpr (Cols != -1)
assert(e.cols() == Cols &&
"Mismatched between dynamic and static col size");
resize(e.rows(), e.cols());
for (rotgen::Index r = 0; r < e.rows(); ++r)
for (rotgen::Index c = 0; c < e.cols(); ++c) (*this)(r, c) = e(r, c);
return *this; return *this;
} }
@ -156,39 +146,27 @@ namespace rotgen
return (*this)(i); return (*this)(i);
} }
void swap(matrix& other) auto evaluate() const { return *this; }
decltype(auto) noalias() const { return *this; }
decltype(auto) noalias() { return *this; }
Index innerStride() const noexcept { return 1; }
Index outerStride() const noexcept
{ {
// TODO: Swap elements per elements if statically defined to preserve return IsVectorAtCompileTime ? this->size()
// data location in memory as with actual statically defines matrix : IsRowMajor ? this->cols()
base().swap(other.base()); : this->rows();
}
auto _evaluate() const { return *this; }
decltype(auto) _noalias() const { return *this; }
decltype(auto) _noalias() { return *this; }
Index _innerStride() const noexcept { return 1; }
Index _outerStride() const noexcept
{
if constexpr (IsVectorAtCompileTime) return this->size();
else
{
if constexpr (IsRowMajor) return this->_cols();
else return this->_rows();
}
} }
void resize(int r, int c) void resize(int r, int c)
{ {
if constexpr (Cols != -1) if constexpr (Rows == 1)
ROTGEN_ASSERT(c == Cols, assert(c == Cols && "Mismatched between dynamic and static col size");
"Mismatched between dynamic and static col size"); if constexpr (Cols == 1)
if constexpr (Rows != -1) assert(r == Rows && "Mismatched between dynamic and static row size");
ROTGEN_ASSERT(r == Rows,
"Mismatched between dynamic and static row size");
parent::resize(r, c); parent::resize(r, c);
} }
@ -199,82 +177,80 @@ namespace rotgen
else parent::resize(s, 1); else parent::resize(s, 1);
} }
void _conservativeResize(int r, int c) void conservativeResize(int r, int c)
{ {
if constexpr (Cols != -1) if constexpr (Rows == 1)
ROTGEN_ASSERT(c == Cols, assert(c == Cols && "Mismatched between dynamic and static col size");
"Mismatched between dynamic and static col size"); if constexpr (Cols == 1)
if constexpr (Rows != -1) assert(r == Rows && "Mismatched between dynamic and static row size");
ROTGEN_ASSERT(r == Rows, parent::conservativeResize(r, c);
"Mismatched between dynamic and static row size");
parent::_conservativeResize(r, c);
} }
void _conservativeResize(int s) void conservativeResize(int s)
requires(IsVectorAtCompileTime) requires(IsVectorAtCompileTime)
{ {
if constexpr (Rows == 1) parent::_conservativeResize(1, s); if constexpr (Rows == 1) parent::conservativeResize(1, s);
else parent::_conservativeResize(s, 1); else parent::conservativeResize(s, 1);
} }
matrix _normalized() const matrix normalized() const
requires(IsVectorAtCompileTime) requires(IsVectorAtCompileTime)
{ {
return matrix(base()._normalized()); return matrix(base().normalized());
} }
transposed_type _transpose() const transposed_type transpose() const
{ {
return transposed_type(base()._transpose()); return transposed_type(base().transpose());
} }
matrix _conjugate() const { return matrix(base()._conjugate()); } matrix conjugate() const { return matrix(base().conjugate()); }
transposed_type _adjoint() const transposed_type adjoint() const
{ {
return transposed_type(base()._adjoint()); return transposed_type(base().adjoint());
} }
void _normalize() void normalize()
requires(IsVectorAtCompileTime) requires(IsVectorAtCompileTime)
{ {
parent::_normalize(); parent::normalize();
} }
void _transposeInPlace() { parent::_transposeInPlace(); } void transposeInPlace() { parent::transposeInPlace(); }
void _adjointInPlace() { parent::_adjointInPlace(); } void adjointInPlace() { parent::adjointInPlace(); }
matrix _cwiseAbs() const { return matrix(base()._cwiseAbs()); } matrix cwiseAbs() const { return matrix(base().cwiseAbs()); }
matrix _cwiseAbs2() const { return matrix(base()._cwiseAbs2()); } matrix cwiseAbs2() const { return matrix(base().cwiseAbs2()); }
matrix _cwiseInverse() const { return matrix(base()._cwiseInverse()); } matrix cwiseInverse() const { return matrix(base().cwiseInverse()); }
matrix _cwiseSqrt() const { return matrix(base()._cwiseSqrt()); } matrix cwiseSqrt() const { return matrix(base().cwiseSqrt()); }
friend bool operator==(matrix const& lhs, matrix const& rhs) friend bool operator==(matrix const& lhs, matrix const& rhs)
{ {
return lhs.base() == rhs.base(); return static_cast<parent const&>(lhs) == static_cast<parent const&>(rhs);
} }
matrix& operator+=(matrix const& rhs) matrix& operator+=(matrix const& rhs)
{ {
base() += rhs.base(); base() += static_cast<parent const&>(rhs);
return *this; return *this;
} }
matrix& operator-=(matrix const& rhs) matrix& operator-=(matrix const& rhs)
{ {
base() -= rhs.base(); base() -= static_cast<parent const&>(rhs);
return *this; return *this;
} }
matrix operator-() const { return -base(); } matrix operator-() const { return matrix(base().operator-()); }
matrix& operator*=(matrix const& rhs) matrix& operator*=(matrix const& rhs)
{ {
base() *= rhs.base(); base() *= static_cast<parent const&>(rhs);
return *this; return *this;
} }
@ -290,184 +266,231 @@ namespace rotgen
return *this; return *this;
} }
auto _minCoeff() const { return parent::_minCoeff(); } auto minCoeff() const { return parent::minCoeff(); }
auto _maxCoeff() const { return parent::_maxCoeff(); } auto maxCoeff() const { return parent::maxCoeff(); }
template<std::integral IndexType> template<std::integral IndexType>
auto _minCoeff(IndexType* row, IndexType* col) const auto minCoeff(IndexType* row, IndexType* col) const
{ {
Index r, c; Index r, c;
auto result = parent::_minCoeff(&r, &c); auto result = parent::minCoeff(&r, &c);
*row = r; *row = r;
*col = c; *col = c;
return result; return result;
} }
template<std::integral IndexType> template<std::integral IndexType>
auto _maxCoeff(IndexType* row, IndexType* col) const auto maxCoeff(IndexType* row, IndexType* col) const
{ {
Index r, c; Index r, c;
auto result = parent::_maxCoeff(&r, &c); auto result = parent::maxCoeff(&r, &c);
*row = r; *row = r;
*col = c; *col = c;
return result; return result;
} }
static matrix _Ones() static matrix Ones()
requires(Rows != -1 && Cols != -1) requires(Rows != -1 && Cols != -1)
{ {
return parent::_Ones(Rows, Cols); return parent::Ones(Rows, Cols);
} }
static matrix _Ones(int rows, int cols) static matrix Ones(int rows, int cols)
{ {
if constexpr (Rows != -1) if constexpr (Rows != -1)
ROTGEN_ASSERT(rows == Rows, assert(rows == Rows &&
"Mismatched between dynamic and static row size"); "Mismatched between dynamic and static row size");
if constexpr (Cols != -1) if constexpr (Cols != -1)
ROTGEN_ASSERT(cols == Cols, assert(cols == Cols &&
"Mismatched between dynamic and static column size"); "Mismatched between dynamic and static column size");
return parent::_Ones(rows, cols); return parent::Ones(rows, cols);
} }
static matrix _Zero() static matrix Zero()
requires(Rows != -1 && Cols != -1) requires(Rows != -1 && Cols != -1)
{ {
return parent::_Zero(Rows, Cols); return parent::Zero(Rows, Cols);
} }
static matrix _Zero(int rows, int cols) static matrix Zero(int rows, int cols)
{ {
if constexpr (Rows != -1) if constexpr (Rows != -1)
ROTGEN_ASSERT(rows == Rows, assert(rows == Rows &&
"Mismatched between dynamic and static row size"); "Mismatched between dynamic and static row size");
if constexpr (Cols != -1) if constexpr (Cols != -1)
ROTGEN_ASSERT(cols == Cols, assert(cols == Cols &&
"Mismatched between dynamic and static column size"); "Mismatched between dynamic and static column size");
return parent::_Zero(rows, cols); return parent::Zero(rows, cols);
} }
static matrix _Constant(Scalar value) static matrix Constant(Scalar value)
requires(Rows != -1 && Cols != -1) requires(Rows != -1 && Cols != -1)
{ {
return parent::_Constant(Rows, Cols, static_cast<Scalar>(value)); return parent::Constant(Rows, Cols, static_cast<Scalar>(value));
} }
static matrix _Constant(int rows, int cols, Scalar value) static matrix Constant(int rows, int cols, Scalar value)
{ {
if constexpr (Rows != -1) if constexpr (Rows != -1)
ROTGEN_ASSERT(rows == Rows, assert(rows == Rows &&
"Mismatched between dynamic and static row size"); "Mismatched between dynamic and static row size");
if constexpr (Cols != -1) if constexpr (Cols != -1)
ROTGEN_ASSERT(cols == Cols, assert(cols == Cols &&
"Mismatched between dynamic and static column size"); "Mismatched between dynamic and static column size");
return parent::_Constant(rows, cols, static_cast<Scalar>(value)); return parent::Constant(rows, cols, static_cast<Scalar>(value));
} }
static matrix _Random() static matrix Random()
requires(Rows != -1 && Cols != -1) requires(Rows != -1 && Cols != -1)
{ {
return parent::_Random(Rows, Cols); return parent::Random(Rows, Cols);
} }
static matrix _Random(int rows, int cols) static matrix Random(int rows, int cols)
{ {
if constexpr (Rows != -1) if constexpr (Rows != -1)
ROTGEN_ASSERT(rows == Rows, assert(rows == Rows &&
"Mismatched between dynamic and static row size"); "Mismatched between dynamic and static row size");
if constexpr (Cols != -1) if constexpr (Cols != -1)
ROTGEN_ASSERT(cols == Cols, assert(cols == Cols &&
"Mismatched between dynamic and static column size"); "Mismatched between dynamic and static column size");
return parent::_Random(rows, cols); return parent::Random(rows, cols);
} }
static matrix _Identity() static matrix Identity()
requires(Rows != -1 && Cols != -1) requires(Rows != -1 && Cols != -1)
{ {
return parent::_Identity(Rows, Cols); return parent::Identity(Rows, Cols);
} }
static matrix _Identity(int rows, int cols) static matrix Identity(int rows, int cols)
{ {
if constexpr (Rows != -1) if constexpr (Rows != -1)
ROTGEN_ASSERT(rows == Rows, assert(rows == Rows &&
"Mismatched between dynamic and static row size"); "Mismatched between dynamic and static row size");
if constexpr (Cols != -1) if constexpr (Cols != -1)
ROTGEN_ASSERT(cols == Cols, assert(cols == Cols &&
"Mismatched between dynamic and static column size"); "Mismatched between dynamic and static column size");
return parent::_Identity(rows, cols); return parent::Identity(rows, cols);
} }
matrix& _setOnes() matrix& setOnes()
{ {
parent::_setOnes(parent::_rows(), parent::_cols()); parent::setOnes(parent::rows(), parent::cols());
return *this; return *this;
} }
matrix& _setOnes(int rows, int cols) matrix& setOnes(int rows, int cols)
{ {
parent::_setOnes(rows, cols); parent::setOnes(rows, cols);
return *this; return *this;
} }
matrix& _setZero() matrix& setZero()
{ {
parent::_setZero(parent::_rows(), parent::_cols()); parent::setZero(parent::rows(), parent::cols());
return *this; return *this;
} }
matrix& _setZero(int rows, int cols) matrix& setZero(int rows, int cols)
{ {
parent::_setZero(rows, cols); parent::setZero(rows, cols);
return *this; return *this;
} }
matrix& _setConstant(Scalar v) matrix& setConstant(Scalar v)
{ {
parent::_setConstant(parent::_rows(), parent::_cols(), parent::setConstant(parent::rows(), parent::cols(),
static_cast<Scalar>(v)); static_cast<Scalar>(v));
return *this; return *this;
} }
matrix& _setConstant(int rows, int cols, Scalar v) matrix& setConstant(int rows, int cols, Scalar v)
{ {
parent::_setConstant(rows, cols, static_cast<Scalar>(v)); parent::setConstant(rows, cols, static_cast<Scalar>(v));
return *this; return *this;
} }
matrix& _setRandom() matrix& setRandom()
{ {
parent::_setRandom(parent::_rows(), parent::_cols()); parent::setRandom(parent::rows(), parent::cols());
return *this; return *this;
} }
matrix& _setRandom(int rows, int cols) matrix& setRandom(int rows, int cols)
{ {
parent::_setRandom(rows, cols); parent::setRandom(rows, cols);
return *this; return *this;
} }
matrix& _setIdentity() matrix& setIdentity()
{ {
parent::_setIdentity(parent::_rows(), parent::_cols()); parent::setIdentity(parent::rows(), parent::cols());
return *this; return *this;
} }
matrix& _setIdentity(int rows, int cols) matrix& setIdentity(int rows, int cols)
{ {
parent::_setIdentity(rows, cols); parent::setIdentity(rows, cols);
return *this; return *this;
} }
template<int P> Scalar _lpNorm() const template<int P> Scalar lpNorm() const
{ {
static_assert(P == 1 || P == 2 || P == Infinity); static_assert(P == 1 || P == 2 || P == Infinity);
return parent::_lp_norm(P); return parent::lp_norm(P);
} }
parent& base() { return static_cast<parent&>(*this); } parent& base() { return static_cast<parent&>(*this); }
parent const& base() const { return static_cast<parent const&>(*this); } parent const& base() const { return static_cast<parent const&>(*this); }
}; };
template<typename S, int R, int C, int O, int MR, int MC>
matrix<S, R, C, O, MR, MC> operator+(matrix<S, R, C, O, MR, MC> const& lhs,
matrix<S, R, C, O, MR, MC> const& rhs)
{
matrix<S, R, C, O, MR, MC> that(lhs);
return that += rhs;
}
template<typename S, int R, int C, int O, int MR, int MC>
matrix<S, R, C, O, MR, MC> operator-(matrix<S, R, C, O, MR, MC> const& lhs,
matrix<S, R, C, O, MR, MC> const& rhs)
{
matrix<S, R, C, O, MR, MC> that(lhs);
return that -= rhs;
}
template<typename S, int R, int C, int O, int MR, int MC>
matrix<S, R, C, O, MR, MC> operator*(matrix<S, R, C, O, MR, MC> const& lhs,
matrix<S, R, C, O, MR, MC> const& rhs)
{
matrix<S, R, C, O, MR, MC> that(lhs);
return that *= rhs;
}
template<typename S, int R, int C, int O, int MR, int MC>
matrix<S, R, C, O, MR, MC> operator*(matrix<S, R, C, O, MR, MC> const& lhs,
double rhs)
{
matrix<S, R, C, O, MR, MC> that(lhs);
return that *= rhs;
}
template<typename S, int R, int C, int O, int MR, int MC>
matrix<S, R, C, O, MR, MC> operator*(double lhs,
matrix<S, R, C, O, MR, MC> const& rhs)
{
return rhs * lhs;
}
template<typename S, int R, int C, int O, int MR, int MC>
matrix<S, R, C, O, MR, MC> operator/(matrix<S, R, C, O, MR, MC> const& lhs,
double rhs)
{
matrix<S, R, C, O, MR, MC> that(lhs);
return that /= rhs;
}
} }

View file

@ -28,40 +28,39 @@ public:
~CLASSNAME(); ~CLASSNAME();
Index rows() const;
Index cols() const;
Index size() const; Index size() const;
Index _rows() const;
Index _cols() const;
void resize(Index new_rows, Index new_cols); void resize(Index new_rows, Index new_cols);
void _conservativeResize(Index new_rows, Index new_cols); void conservativeResize(Index new_rows, Index new_cols);
CLASSNAME _normalized() const; CLASSNAME normalized() const;
CLASSNAME _transpose() const; CLASSNAME transpose() const;
CLASSNAME _conjugate() const; CLASSNAME conjugate() const;
CLASSNAME _adjoint() const; CLASSNAME adjoint() const;
CLASSNAME _cwiseAbs() const; CLASSNAME cwiseAbs() const;
CLASSNAME _cwiseAbs2() const; CLASSNAME cwiseAbs2() const;
CLASSNAME _cwiseInverse() const; CLASSNAME cwiseInverse() const;
CLASSNAME _cwiseSqrt() const; CLASSNAME cwiseSqrt() const;
void _normalize(); void normalize();
void _transposeInPlace(); void transposeInPlace();
void _adjointInPlace(); void adjointInPlace();
TYPE _sum() const; TYPE sum() const;
TYPE _prod() const; TYPE prod() const;
TYPE _mean() const; TYPE mean() const;
TYPE _trace() const; TYPE trace() const;
TYPE _maxCoeff() const; TYPE maxCoeff() const;
TYPE _minCoeff() const; TYPE minCoeff() const;
TYPE _maxCoeff(Index* row, Index* col) const; TYPE maxCoeff(Index* row, Index* col) const;
TYPE _minCoeff(Index* row, Index* col) const; TYPE minCoeff(Index* row, Index* col) const;
TYPE _squaredNorm() const; TYPE squaredNorm() const;
TYPE _norm() const; TYPE norm() const;
TYPE _lp_norm(int p) const; TYPE lp_norm(int p) const;
TYPE& operator()(Index i, Index j); TYPE& operator()(Index i, Index j);
TYPE const& operator()(Index i, Index j) const; TYPE const& operator()(Index i, Index j) const;
@ -88,19 +87,17 @@ public:
const TYPE* data() const; const TYPE* data() const;
TYPE* data(); TYPE* data();
static CLASSNAME _Zero(Index rows, Index cols); static CLASSNAME Zero(Index rows, Index cols);
static CLASSNAME _Ones(Index rows, Index cols); static CLASSNAME Ones(Index rows, Index cols);
static CLASSNAME _Constant(Index rows, Index cols, TYPE value); static CLASSNAME Constant(Index rows, Index cols, TYPE value);
static CLASSNAME _Random(Index rows, Index cols); static CLASSNAME Random(Index rows, Index cols);
static CLASSNAME _Identity(Index rows, Index cols); static CLASSNAME Identity(Index rows, Index cols);
void _setOnes(Index rows, Index cols); void setOnes(Index rows, Index cols);
void _setZero(Index rows, Index cols); void setZero(Index rows, Index cols);
void _setConstant(Index rows, Index cols, TYPE value); void setConstant(Index rows, Index cols, TYPE value);
void _setRandom(Index rows, Index cols); void setRandom(Index rows, Index cols);
void _setIdentity(Index rows, Index cols); void setIdentity(Index rows, Index cols);
void swap(CLASSNAME& other) { storage_.swap(other.storage_); }
private: private:
struct payload; struct payload;

View file

@ -7,7 +7,6 @@
//================================================================================================== //==================================================================================================
#pragma once #pragma once
#include <rotgen/detail/assert.hpp>
#include <rotgen/detail/helpers.hpp> #include <rotgen/detail/helpers.hpp>
#include <rotgen/concepts.hpp> #include <rotgen/concepts.hpp>
@ -41,7 +40,6 @@ namespace rotgen
{ {
public: public:
using rotgen_tag = void; using rotgen_tag = void;
using rotgen_matrix_tag = void;
using parent = using parent =
detail::storage_type<Scalar, Rows, Cols, Opts, MaxRows, MaxCols>; detail::storage_type<Scalar, Rows, Cols, Opts, MaxRows, MaxCols>;
using value_type = Scalar; using value_type = Scalar;
@ -51,9 +49,6 @@ namespace rotgen
using concrete_type = matrix; using concrete_type = matrix;
using concrete_dynamic_type = matrix<value_type>; using concrete_dynamic_type = matrix<value_type>;
using exact_base =
Eigen::Matrix<Scalar, Rows, Cols, Opts, MaxRows, MaxCols>;
static constexpr int RowsAtCompileTime = Rows; static constexpr int RowsAtCompileTime = Rows;
static constexpr int ColsAtCompileTime = Cols; static constexpr int ColsAtCompileTime = Cols;
static constexpr int SizeAtCompileTime = detail::static_size<matrix>(); static constexpr int SizeAtCompileTime = detail::static_size<matrix>();
@ -80,11 +75,6 @@ namespace rotgen
static constexpr bool has_static_storage = static constexpr bool has_static_storage =
storage_status<Rows, Cols, MaxRows, MaxCols>; storage_status<Rows, Cols, MaxRows, MaxCols>;
static constexpr int AllocatedRows =
Rows == -1 ? (MaxRows == -1 ? 0 : MaxRows) : Rows;
static constexpr int AllocatedCols =
Cols == -1 ? (MaxCols == -1 ? 0 : MaxCols) : Cols;
public: public:
matrix() matrix()
requires(has_static_storage) requires(has_static_storage)
@ -93,24 +83,20 @@ namespace rotgen
matrix() matrix()
requires(!has_static_storage) requires(!has_static_storage)
: parent(AllocatedRows, AllocatedCols) : parent(Rows > 0 ? Rows : 0, Cols > 0 ? Cols : 0)
{ {
} }
matrix(Index r, Index c) : parent(r, c) matrix(Index r, Index c) : parent(r, c)
{ {
if constexpr (RowsAtCompileTime != -1) if constexpr (RowsAtCompileTime != -1)
{ assert(r == RowsAtCompileTime &&
ROTGEN_ASSERT(r == RowsAtCompileTime,
"Mismatched between dynamic and static row size"); "Mismatched between dynamic and static row size");
}
if constexpr (ColsAtCompileTime != -1) if constexpr (ColsAtCompileTime != -1)
{ assert(c == ColsAtCompileTime &&
ROTGEN_ASSERT(c == ColsAtCompileTime,
"Mismatched between dynamic and static column size"); "Mismatched between dynamic and static column size");
} }
}
matrix(matrix const& other) = default; matrix(matrix const& other) = default;
matrix(matrix&& other) = default; matrix(matrix&& other) = default;
@ -131,11 +117,8 @@ namespace rotgen
explicit matrix(Scalar v) explicit matrix(Scalar v)
requires(Rows == 1 && Cols == 1) requires(Rows == 1 && Cols == 1)
: parent([&]() { : parent([&]() {
if constexpr (has_static_storage) { return parent(v); } if constexpr (has_static_storage) return parent(v);
else else return parent{1, 1};
{
return parent{1, 1};
}
}()) }())
{ {
if constexpr (!has_static_storage) (*this)(0) = v; if constexpr (!has_static_storage) (*this)(0) = v;
@ -144,18 +127,12 @@ namespace rotgen
matrix(std::initializer_list<Scalar> init) matrix(std::initializer_list<Scalar> init)
requires(IsVectorAtCompileTime) requires(IsVectorAtCompileTime)
: parent([&]() { : parent([&]() {
if constexpr (has_static_storage) { return parent{}; } if constexpr (has_static_storage) return parent{};
else else return parent{Rows, Cols};
{
return parent{Rows, Cols};
}
}()) }())
{ {
auto first = init.begin(); auto first = init.begin();
for (rotgen::Index i = 0; i < parent::size(); i++) for (rotgen::Index i = 0; i < parent::size(); i++) (*this)(i) = first[i];
{
(*this)(i) = first[i];
}
} }
matrix(Scalar v0, Scalar v1, auto... vs) matrix(Scalar v0, Scalar v1, auto... vs)
@ -197,34 +174,35 @@ namespace rotgen
return *this; return *this;
} }
using parent::innerStride;
using parent::outerStride;
parent& base() { return static_cast<parent&>(*this); } parent& base() { return static_cast<parent&>(*this); }
parent const& base() const { return static_cast<parent const&>(*this); } parent const& base() const { return static_cast<parent const&>(*this); }
auto _evaluate() const { return *this; } auto evaluate() const
decltype(auto) _noalias() const
{ {
if constexpr (use_expression_templates) { return base().noalias(); } auto res = base().eval();
else return as_concrete_type<decltype(res)>(res);
{
return *this;
}
} }
decltype(auto) _noalias() decltype(auto) noalias() const
{ {
if constexpr (use_expression_templates) { return base().noalias(); } if constexpr (use_expression_templates) return base().noalias();
else else return *this;
{
return *this;
}
} }
auto _normalized() const decltype(auto) noalias()
{
if constexpr (use_expression_templates) return base().noalias();
else return *this;
}
auto normalized() const
requires(IsVectorAtCompileTime) requires(IsVectorAtCompileTime)
{ {
if constexpr (use_expression_templates) { return base().normalized(); } if constexpr (use_expression_templates) return base().normalized();
else else
{ {
auto res = base().normalized(); auto res = base().normalized();
@ -232,9 +210,9 @@ namespace rotgen
} }
} }
auto _transpose() const auto transpose() const
{ {
if constexpr (use_expression_templates) { return base().transpose(); } if constexpr (use_expression_templates) return base().transpose();
else else
{ {
auto res = base().transpose(); auto res = base().transpose();
@ -242,232 +220,180 @@ namespace rotgen
} }
} }
auto _conjugate() const auto conjugate() const
{ {
auto res = base().conjugate(); auto res = base().conjugate();
return as_concrete_type<decltype(res)>(res); return as_concrete_type<decltype(res)>(res);
} }
auto _adjoint() const auto adjoint() const
{ {
auto res = base().adjoint(); auto res = base().adjoint();
return as_concrete_type<decltype(res)>(res); return as_concrete_type<decltype(res)>(res);
} }
void _normalize() void normalize()
requires(IsVectorAtCompileTime) requires(IsVectorAtCompileTime)
{ {
parent::normalize(); parent::normalize();
} }
void _transposeInPlace() { parent::transposeInPlace(); } void transposeInPlace() { parent::transposeInPlace(); }
void _adjointInPlace() { parent::adjointInPlace(); } void adjointInPlace() { parent::adjointInPlace(); }
auto _cwiseAbs() const auto cwiseAbs() const
{ {
if constexpr (!use_expression_templates) if constexpr (!use_expression_templates)
{
return matrix{parent::cwiseAbs()}; return matrix{parent::cwiseAbs()};
} else return base().cwiseAbs();
else
{
return base().cwiseAbs();
}
} }
auto _cwiseAbs2() const auto cwiseAbs2() const
{ {
if constexpr (!use_expression_templates) if constexpr (!use_expression_templates)
{
return matrix{parent::cwiseAbs2()}; return matrix{parent::cwiseAbs2()};
} else return base().cwiseAbs2();
else
{
return base().cwiseAbs2();
}
} }
auto _cwiseInverse() const auto cwiseInverse() const
{ {
if constexpr (!use_expression_templates) if constexpr (!use_expression_templates)
{
return matrix{parent::cwiseInverse()}; return matrix{parent::cwiseInverse()};
} else return base().cwiseInverse();
else
{
return base().cwiseInverse();
}
} }
auto _cwiseSqrt() const auto cwiseSqrt() const
{ {
if constexpr (!use_expression_templates) if constexpr (!use_expression_templates)
{
return matrix{parent::cwiseSqrt()}; return matrix{parent::cwiseSqrt()};
} else return base().cwiseSqrt();
else
{
return base().cwiseSqrt();
}
} }
void resize(int new_size) void resize(int s)
requires(IsVectorAtCompileTime) requires(IsVectorAtCompileTime)
{ {
if constexpr (Rows == 1) { parent::resize(1, new_size); } if constexpr (Rows == 1)
else assert(s == Cols && "Mismatched between dynamic and static col size");
{ if constexpr (Cols == 1)
parent::resize(new_size, 1); assert(s == Rows && "Mismatched between dynamic and static row size");
} parent::resize(s);
} }
void resize(int new_row_count, int new_col_count) void resize(int r, int c)
{ {
if constexpr (Cols != -1) if constexpr (Rows == 1)
{ assert(c == Cols && "Mismatched between dynamic and static col size");
ROTGEN_ASSERT(new_col_count == Cols, if constexpr (Cols == 1)
"Mismatched between dynamic and static col size"); assert(r == Rows && "Mismatched between dynamic and static row size");
} parent::resize(r, c);
if constexpr (Rows != -1)
{
ROTGEN_ASSERT(new_row_count == Rows,
"Mismatched between dynamic and static row size");
}
parent::resize(new_row_count, new_col_count);
} }
void _conservativeResize(int new_size) void conservativeResize(int s)
requires(IsVectorAtCompileTime) requires(IsVectorAtCompileTime)
{ {
if constexpr (Rows == 1) { parent::conservativeResize(1, new_size); } if constexpr (Rows == 1)
else assert(s == Cols && "Mismatched between dynamic and static col size");
{ if constexpr (Cols == 1)
parent::conservativeResize(new_size, 1); assert(s == Rows && "Mismatched between dynamic and static row size");
} parent::conservativeResize(s);
} }
void _conservativeResize(int new_row_count, int new_col_count) void conservativeResize(int r, int c)
{ {
if constexpr (Cols != -1) if constexpr (Rows == 1)
{ assert(c == Cols && "Mismatched between dynamic and static col size");
ROTGEN_ASSERT(new_col_count == Cols, if constexpr (Cols == 1)
"Mismatched between dynamic and static col size"); assert(r == Rows && "Mismatched between dynamic and static row size");
} parent::conservativeResize(r, c);
if constexpr (Rows != -1)
{
ROTGEN_ASSERT(new_row_count == Rows,
"Mismatched between dynamic and static row size");
}
parent::conservativeResize(new_row_count, new_col_count);
} }
static matrix _Constant(Scalar value) static matrix Constant(Scalar value)
requires(Rows != -1 && Cols != -1) requires(Rows != -1 && Cols != -1)
{ {
return parent::Constant(Rows, Cols, value); return parent::Constant(Rows, Cols, static_cast<Scalar>(value));
} }
static matrix _Constant(int rows, int cols, Scalar value) static matrix Constant(int rows, int cols, Scalar value)
{ {
if constexpr (Rows != -1) if constexpr (Rows != -1)
{ assert(rows == Rows &&
ROTGEN_ASSERT(rows == Rows,
"Mismatched between dynamic and static row size"); "Mismatched between dynamic and static row size");
}
if constexpr (Cols != -1) if constexpr (Cols != -1)
{ assert(cols == Cols &&
ROTGEN_ASSERT(cols == Cols,
"Mismatched between dynamic and static column size"); "Mismatched between dynamic and static column size");
} return parent::Constant(rows, cols, static_cast<Scalar>(value));
return parent::Constant(rows, cols, value);
} }
static matrix _Identity() static matrix Identity()
requires(Rows != -1 && Cols != -1) requires(Rows != -1 && Cols != -1)
{ {
return parent::Identity(Rows, Cols); return parent::Identity(Rows, Cols);
} }
static matrix _Identity(int rows, int cols) static matrix Identity(int rows, int cols)
{ {
if constexpr (Rows != -1) if constexpr (Rows != -1)
{ assert(rows == Rows &&
ROTGEN_ASSERT(rows == Rows,
"Mismatched between dynamic and static row size"); "Mismatched between dynamic and static row size");
}
if constexpr (Cols != -1) if constexpr (Cols != -1)
{ assert(cols == Cols &&
ROTGEN_ASSERT(cols == Cols,
"Mismatched between dynamic and static column size"); "Mismatched between dynamic and static column size");
}
return parent::Identity(rows, cols); return parent::Identity(rows, cols);
} }
static matrix _Ones() static matrix Ones()
requires(Rows != -1 && Cols != -1) requires(Rows != -1 && Cols != -1)
{ {
return parent::Ones(Rows, Cols); return parent::Ones(Rows, Cols);
} }
static matrix _Ones(int rows, int cols) static matrix Ones(int rows, int cols)
{ {
if constexpr (Rows != -1) if constexpr (Rows != -1)
{ assert(rows == Rows &&
ROTGEN_ASSERT(rows == Rows,
"Mismatched between dynamic and static row size"); "Mismatched between dynamic and static row size");
}
if constexpr (Cols != -1) if constexpr (Cols != -1)
{ assert(cols == Cols &&
ROTGEN_ASSERT(cols == Cols,
"Mismatched between dynamic and static column size"); "Mismatched between dynamic and static column size");
}
return parent::Ones(rows, cols); return parent::Ones(rows, cols);
} }
static matrix _Zero() static matrix Zero()
requires(Rows != -1 && Cols != -1) requires(Rows != -1 && Cols != -1)
{ {
return parent::Zero(Rows, Cols); return parent::Zero(Rows, Cols);
} }
static matrix _Zero(int rows, int cols) static matrix Zero(int rows, int cols)
{ {
if constexpr (Rows != -1) if constexpr (Rows != -1)
{ assert(rows == Rows &&
ROTGEN_ASSERT(rows == Rows,
"Mismatched between dynamic and static row size"); "Mismatched between dynamic and static row size");
}
if constexpr (Cols != -1) if constexpr (Cols != -1)
{ assert(cols == Cols &&
ROTGEN_ASSERT(cols == Cols,
"Mismatched between dynamic and static column size"); "Mismatched between dynamic and static column size");
}
return parent::Zero(rows, cols); return parent::Zero(rows, cols);
} }
static matrix _Random() static matrix Random()
requires(Rows != -1 && Cols != -1) requires(Rows != -1 && Cols != -1)
{ {
return parent::Random(Rows, Cols); return parent::Random(Rows, Cols);
} }
static matrix _Random(int rows, int cols) static matrix Random(int rows, int cols)
{ {
if constexpr (Rows != -1) if constexpr (Rows != -1)
{ assert(rows == Rows &&
ROTGEN_ASSERT(rows == Rows,
"Mismatched between dynamic and static row size"); "Mismatched between dynamic and static row size");
}
if constexpr (Cols != -1) if constexpr (Cols != -1)
{ assert(cols == Cols &&
ROTGEN_ASSERT(cols == Cols,
"Mismatched between dynamic and static column size"); "Mismatched between dynamic and static column size");
}
return parent::Random(rows, cols); return parent::Random(rows, cols);
} }
template<int P> value_type _lpNorm() const template<int P> value_type lpNorm() const
{ {
static_assert(P == 1 || P == 2 || P == Infinity); static_assert(P == 1 || P == 2 || P == Infinity);
return parent::template lpNorm<P>(); return parent::template lpNorm<P>();
@ -486,111 +412,96 @@ namespace rotgen
} }
using parent::operator(); using parent::operator();
using parent::cols;
using parent::data; using parent::data;
using parent::mean;
using parent::norm;
using parent::prod;
using parent::rows;
using parent::size; using parent::size;
using parent::squaredNorm;
using parent::sum;
using parent::trace;
Index _cols() const { return parent::cols(); } auto minCoeff() const { return parent::minCoeff(); }
Index _rows() const { return parent::rows(); } auto maxCoeff() const { return parent::maxCoeff(); }
// Reductions
value_type _mean() const { return parent::mean(); }
value_type _norm() const { return parent::norm(); }
value_type _squaredNorm() const { return parent::squaredNorm(); }
value_type _sum() const { return parent::sum(); }
value_type _prod() const { return parent::prod(); }
value_type _trace() const { return parent::trace(); }
Index _innerStride() const noexcept { return parent::innerStride(); };
Index _outerStride() const noexcept { return parent::outerStride(); };
auto _minCoeff() const { return parent::minCoeff(); }
auto _maxCoeff() const { return parent::maxCoeff(); }
template<std::integral IndexType> template<std::integral IndexType>
auto _minCoeff(IndexType* row, IndexType* col) const auto minCoeff(IndexType* row, IndexType* col) const
{ {
Index result_row, result_col; Index r, c;
auto result = parent::minCoeff(&result_row, &result_col); auto result = parent::minCoeff(&r, &c);
*row = result_row; *row = r;
*col = result_col; *col = c;
return result; return result;
} }
template<std::integral IndexType> template<std::integral IndexType>
auto _maxCoeff(IndexType* row, IndexType* col) const auto maxCoeff(IndexType* row, IndexType* col) const
{ {
Index result_row, result_col; Index r, c;
auto result = parent::maxCoeff(&result_row, &result_col); auto result = parent::maxCoeff(&r, &c);
*row = result_row; *row = r;
*col = result_col; *col = c;
return result; return result;
} }
matrix& _setOnes() matrix& setOnes()
{ {
*this = parent::Ones(_rows(), _cols()); *this = parent::Ones(rows(), cols());
return *this; return *this;
} }
matrix& _setOnes(int r, int c) matrix& setOnes(int r, int c)
{ {
*this = parent::Ones(r, c); *this = parent::Ones(r, c);
return *this; return *this;
} }
matrix& _setZero() matrix& setZero()
{ {
*this = parent::Zero(_rows(), _cols()); *this = parent::Zero(rows(), cols());
return *this; return *this;
} }
matrix& _setZero(int r, int c) matrix& setZero(int r, int c)
{ {
*this = parent::Zero(r, c); *this = parent::Zero(r, c);
return *this; return *this;
} }
matrix& _setConstant(Scalar value) matrix& setConstant(Scalar value)
{ {
*this = parent::Constant(_rows(), _cols(), value); *this = parent::Constant(rows(), cols(), static_cast<Scalar>(value));
return *this; return *this;
} }
matrix& _setConstant(int r, int c, Scalar value) matrix& setConstant(int r, int c, Scalar value)
{ {
*this = parent::Constant(r, c, value); *this = parent::Constant(r, c, static_cast<Scalar>(value));
return *this; return *this;
} }
matrix& _setRandom() matrix& setRandom()
{ {
*this = parent::Random(_rows(), _cols()); *this = parent::Random(rows(), cols());
return *this; return *this;
} }
matrix& _setRandom(int r, int c) matrix& setRandom(int r, int c)
{ {
*this = parent::Random(r, c); *this = parent::Random(r, c);
return *this; return *this;
} }
matrix& _setIdentity() matrix& setIdentity()
{ {
*this = parent::Identity(_rows(), _cols()); *this = parent::Identity(rows(), cols());
return *this; return *this;
} }
matrix& _setIdentity(int r, int c) matrix& setIdentity(int r, int c)
{ {
*this = parent::Identity(r, c); *this = parent::Identity(r, c);
return *this; return *this;
@ -608,7 +519,7 @@ namespace rotgen
return *this; return *this;
} }
matrix operator-() const { return -base(); } matrix operator-() const { return matrix(base()(*this).operator-()); }
matrix& operator*=(matrix const& rhs) matrix& operator*=(matrix const& rhs)
{ {

View file

@ -7,13 +7,12 @@
//================================================================================================== //==================================================================================================
#pragma once #pragma once
#include <rotgen/detail/assert.hpp>
#include <rotgen/config.hpp> #include <rotgen/config.hpp>
#include <rotgen/container/block.hpp> #include <rotgen/container/block.hpp>
#include <rotgen/container/map.hpp> #include <rotgen/container/map.hpp>
#include <rotgen/format.hpp> #include <rotgen/format.hpp>
#include <cassert>
#include <iostream> #include <iostream>
#include <type_traits> #include <type_traits>

View file

@ -7,8 +7,7 @@
//================================================================================================== //==================================================================================================
#pragma once #pragma once
#include <rotgen/detail/assert.hpp> #include <cassert>
#include <type_traits> #include <type_traits>
#if !defined(ROTGEN_FORCE_DYNAMIC) #if !defined(ROTGEN_FORCE_DYNAMIC)
@ -16,7 +15,6 @@
#endif #endif
#include <rotgen/detail/accept_as_ref.hpp> #include <rotgen/detail/accept_as_ref.hpp>
#include <rotgen/detail/product.hpp>
namespace rotgen namespace rotgen
{ {
@ -60,33 +58,33 @@ namespace rotgen
using parent::operator[]; using parent::operator[];
// Size related functions // Size related functions
using parent::cols;
using parent::data; using parent::data;
using parent::innerStride;
using parent::outerStride;
using parent::rows;
using parent::size; using parent::size;
using parent::_cols;
using parent::_innerStride;
using parent::_outerStride;
using parent::_rows;
// Aliasing handling // Aliasing handling
using parent::_evaluate; using parent::evaluate;
using parent::_noalias; using parent::noalias;
// Reductions // Reductions
using parent::_lpNorm; using parent::lpNorm;
using parent::_maxCoeff; using parent::maxCoeff;
using parent::_mean; using parent::mean;
using parent::_minCoeff; using parent::minCoeff;
using parent::_norm; using parent::norm;
using parent::_prod; using parent::prod;
using parent::_squaredNorm; using parent::squaredNorm;
using parent::_sum; using parent::sum;
using parent::_trace; using parent::trace;
// Arithmetic // Arithmetic
using parent::_cwiseAbs; using parent::cwiseAbs;
using parent::_cwiseAbs2; using parent::cwiseAbs2;
using parent::_cwiseInverse; using parent::cwiseInverse;
using parent::_cwiseSqrt; using parent::cwiseSqrt;
// Compound Operators // Compound Operators
template<typename A, int O, typename S> template<typename A, int O, typename S>
@ -128,30 +126,29 @@ namespace rotgen
} }
// Shape modifications // Shape modifications
using parent::_adjoint; using parent::adjoint;
using parent::_conjugate; using parent::conjugate;
using parent::_normalized; using parent::normalized;
using parent::_transpose; using parent::transpose;
// In-place Shape modifications // In-place Shape modifications
using parent::_adjointInPlace; using parent::adjointInPlace;
using parent::_normalize; using parent::normalize;
using parent::_transposeInPlace; using parent::transposeInPlace;
// Generators // Generators
using parent::_Constant; using parent::Constant;
using parent::_Identity; using parent::Identity;
using parent::_Ones; using parent::Ones;
using parent::_Random; using parent::Random;
using parent::_setConstant; using parent::setConstant;
using parent::_setIdentity; using parent::setIdentity;
using parent::_setOnes; using parent::setOnes;
using parent::_setRandom; using parent::setRandom;
using parent::_setZero; using parent::setZero;
using parent::_Zero; using parent::Zero;
using parent::operator=; using parent::operator=;
using parent::operator-;
template<typename RO, int OO, typename SO> template<typename RO, int OO, typename SO>
auto qr_solve(ref<RO, OO, SO> rhs) const auto qr_solve(ref<RO, OO, SO> rhs) const
@ -169,18 +166,12 @@ namespace rotgen
parent& as_map() { return base(); } parent& as_map() { return base(); }
template<typename M>
requires(is_immutable)
ref(product<M> const& m) : ref(m.storage_)
{
}
template<typename S, int R, int C, int O, int MR, int MC> template<typename S, int R, int C, int O, int MR, int MC>
requires(detail::accept_as_ref<ref, matrix<S, R, C, O, MR, MC>>) requires(detail::accept_as_ref<ref, matrix<S, R, C, O, MR, MC>>)
ref(matrix<S, R, C, O, MR, MC>& m) : parent(detail::postpone{}) ref(matrix<S, R, C, O, MR, MC>& m) : parent(detail::postpone{})
{ {
[[maybe_unused]] bool correct_ref_setup = detail::validate_ref(*this, m); [[maybe_unused]] bool correct_ref_setup = detail::validate_ref(*this, m);
ROTGEN_ASSERT(correct_ref_setup, "Invalid reference binding"); assert(correct_ref_setup);
} }
template<typename S, int R, int C, int O, int MR, int MC> template<typename S, int R, int C, int O, int MR, int MC>
@ -211,7 +202,7 @@ namespace rotgen
ref(block<Ref, R, C, I>&& b) : parent(detail::postpone{}) ref(block<Ref, R, C, I>&& b) : parent(detail::postpone{})
{ {
[[maybe_unused]] bool correct_ref_setup = detail::validate_ref(*this, b); [[maybe_unused]] bool correct_ref_setup = detail::validate_ref(*this, b);
ROTGEN_ASSERT(correct_ref_setup, "Invalid reference binding"); assert(correct_ref_setup);
} }
template<typename Ref, int R, int C, bool I> template<typename Ref, int R, int C, bool I>
@ -219,7 +210,7 @@ namespace rotgen
ref(block<Ref, R, C, I>& b) : parent(detail::postpone{}) ref(block<Ref, R, C, I>& b) : parent(detail::postpone{})
{ {
[[maybe_unused]] bool correct_ref_setup = detail::validate_ref(*this, b); [[maybe_unused]] bool correct_ref_setup = detail::validate_ref(*this, b);
ROTGEN_ASSERT(correct_ref_setup, "Invalid reference binding"); assert(correct_ref_setup);
} }
template<typename Ref, int R, int C, bool I> template<typename Ref, int R, int C, bool I>
@ -238,7 +229,7 @@ namespace rotgen
ref(map<Ref, O, S>& b) : parent(detail::postpone{}) ref(map<Ref, O, S>& b) : parent(detail::postpone{})
{ {
[[maybe_unused]] bool correct_ref_setup = detail::validate_ref(*this, b); [[maybe_unused]] bool correct_ref_setup = detail::validate_ref(*this, b);
ROTGEN_ASSERT(correct_ref_setup, "Invalid reference binding"); assert(correct_ref_setup);
} }
template<typename Ref, int O, typename S> template<typename Ref, int O, typename S>
@ -268,15 +259,15 @@ namespace rotgen
ref(ref<TT, OO, SS>& b) : parent(detail::postpone{}) ref(ref<TT, OO, SS>& b) : parent(detail::postpone{})
{ {
[[maybe_unused]] bool correct_ref_setup = detail::validate_ref(*this, b); [[maybe_unused]] bool correct_ref_setup = detail::validate_ref(*this, b);
ROTGEN_ASSERT(correct_ref_setup, "Invalid reference binding"); assert(correct_ref_setup);
} }
template<typename TT, int OO, typename SS> template<typename TT, int OO, typename SS>
requires(detail::accept_as_ref<ref, ref<TT, OO, SS>>) requires(detail::same_scalar<ref, ref<TT, OO, SS>>)
ref(ref<TT, OO, SS> const& b) : parent(detail::postpone{}) ref(ref<TT, OO, SS> const& b) : parent(detail::postpone{})
{ {
[[maybe_unused]] bool correct_ref_setup = detail::validate_ref(*this, b); [[maybe_unused]] bool correct_ref_setup = detail::validate_ref(*this, b);
ROTGEN_ASSERT(correct_ref_setup, "Invalid reference binding"); assert(correct_ref_setup);
} }
ref(parent& m) : parent(m.data(), m.rows(), m.cols()) {} ref(parent& m) : parent(m.data(), m.rows(), m.cols()) {}
@ -348,70 +339,70 @@ namespace rotgen
template<typename A, int O, typename S, typename B, int P, typename T> template<typename A, int O, typename S, typename B, int P, typename T>
auto min(ref<A, O, S> lhs, ref<B, P, T> rhs) auto min(ref<A, O, S> lhs, ref<B, P, T> rhs)
-> decltype(lhs.base()._cwiseMin(rhs.base())) -> decltype(lhs.base().cwiseMin(rhs.base()))
{ {
return lhs.base()._cwiseMin(rhs.base()); return lhs.base().cwiseMin(rhs.base());
} }
template<typename A, int O, typename S> template<typename A, int O, typename S>
auto min(ref<A, O, S> lhs, std::convertible_to<typename A::value_type> auto s) auto min(ref<A, O, S> lhs, std::convertible_to<typename A::value_type> auto s)
-> decltype(lhs.base()._cwiseMin(s)) -> decltype(lhs.base().cwiseMin(s))
{ {
return lhs.base()._cwiseMin(s); return lhs.base().cwiseMin(s);
} }
template<typename A, int O, typename S> template<typename A, int O, typename S>
auto min(std::convertible_to<typename A::value_type> auto s, ref<A, O, S> rhs) auto min(std::convertible_to<typename A::value_type> auto s, ref<A, O, S> rhs)
-> decltype(rhs.base()._cwiseMin(s)) -> decltype(rhs.base().cwiseMin(s))
{ {
return rhs.base()._cwiseMin(s); return rhs.base().cwiseMin(s);
} }
template<typename A, int O, typename S, typename B, int P, typename T> template<typename A, int O, typename S, typename B, int P, typename T>
auto max(ref<A, O, S> lhs, ref<B, P, T> rhs) auto max(ref<A, O, S> lhs, ref<B, P, T> rhs)
-> decltype(lhs.base()._cwiseMax(rhs.base())) -> decltype(lhs.base().cwiseMax(rhs.base()))
{ {
return lhs.base()._cwiseMax(rhs.base()); return lhs.base().cwiseMax(rhs.base());
} }
template<typename A, int O, typename S> template<typename A, int O, typename S>
auto max(ref<A, O, S> lhs, std::convertible_to<typename A::value_type> auto s) auto max(ref<A, O, S> lhs, std::convertible_to<typename A::value_type> auto s)
-> decltype(lhs.base()._cwiseMax(s)) -> decltype(lhs.base().cwiseMax(s))
{ {
return lhs.base()._cwiseMax(s); return lhs.base().cwiseMax(s);
} }
template<typename A, int O, typename S> template<typename A, int O, typename S>
auto max(std::convertible_to<typename A::value_type> auto s, ref<A, O, S> rhs) auto max(std::convertible_to<typename A::value_type> auto s, ref<A, O, S> rhs)
-> decltype(rhs.base()._cwiseMax(s)) -> decltype(rhs.base().cwiseMax(s))
{ {
return rhs.base()._cwiseMax(s); return rhs.base().cwiseMax(s);
} }
template<typename A, int O, typename S, typename B, int P, typename T> template<typename A, int O, typename S, typename B, int P, typename T>
auto mul(ref<A, O, S> lhs, ref<B, P, T> rhs) auto mul(ref<A, O, S> lhs, ref<B, P, T> rhs)
-> decltype(lhs.base()._cwiseProduct(rhs.base())) -> decltype(lhs.base().cwiseProduct(rhs.base()))
{ {
return lhs.base()._cwiseProduct(rhs.base()); return lhs.base().cwiseProduct(rhs.base());
} }
template<typename A, int O, typename S, typename B, int P, typename T> template<typename A, int O, typename S, typename B, int P, typename T>
auto div(ref<A, O, S> lhs, ref<B, P, T> rhs) auto div(ref<A, O, S> lhs, ref<B, P, T> rhs)
-> decltype(lhs.base()._cwiseQuotient(rhs.base())) -> decltype(lhs.base().cwiseQuotient(rhs.base()))
{ {
return lhs.base()._cwiseQuotient(rhs.base()); return lhs.base().cwiseQuotient(rhs.base());
} }
template<typename A, int O, typename S> template<typename A, int O, typename S>
auto inverse(ref<A, O, S> lhs) -> decltype(lhs.base()._inverse()) auto inverse(ref<A, O, S> lhs) -> decltype(lhs.base().inverse())
{ {
return lhs.base()._inverse(); return lhs.base().inverse();
} }
template<typename A, int O, typename S, typename B, int P, typename T> template<typename A, int O, typename S, typename B, int P, typename T>
auto cross(ref<A, O, S> lhs, ref<B, P, T> rhs) auto cross(ref<A, O, S> lhs, ref<B, P, T> rhs)
-> decltype(lhs.base()._cross(rhs.base())) -> decltype(lhs.base().cross(rhs.base()))
{ {
return lhs.base()._cross(rhs.base()); return lhs.base().cross(rhs.base());
} }
} }

View file

@ -8,7 +8,6 @@
#pragma once #pragma once
#include <rotgen/detail/helpers.hpp> #include <rotgen/detail/helpers.hpp>
#include <rotgen/detail/product.hpp>
#include <Eigen/Dense> #include <Eigen/Dense>
#include <type_traits> #include <type_traits>
@ -53,9 +52,6 @@ namespace rotgen
template<typename T, int Options, typename Stride> template<typename T, int Options, typename Stride>
using compile_ref_t = typename compile_ref<T, Options, Stride>::type; using compile_ref_t = typename compile_ref<T, Options, Stride>::type;
template<typename T, int Options, typename Stride>
using compile_base_t = typename compile_ref<T, Options, Stride>::base;
} }
template<typename T, int Options, typename Stride> template<typename T, int Options, typename Stride>
@ -63,7 +59,6 @@ namespace rotgen
{ {
public: public:
using parent = detail::compile_ref_t<T, Options, Stride>; using parent = detail::compile_ref_t<T, Options, Stride>;
using exact_base = detail::compile_base_t<T, Options, Stride>;
using referee = std::remove_const_t<T>; using referee = std::remove_const_t<T>;
using value_type = typename referee::value_type; using value_type = typename referee::value_type;
using rotgen_tag = void; using rotgen_tag = void;
@ -86,99 +81,56 @@ namespace rotgen
// Access to values // Access to values
using parent::operator(); using parent::operator();
using parent::operator[]; using parent::operator[];
using parent::data;
using parent::size;
// Size related functions // Size related functions
using parent::cols;
Index _cols() const { return parent::cols(); } using parent::data;
using parent::innerStride;
Index _rows() const { return parent::rows(); } using parent::outerStride;
using parent::rows;
Index _innerStride() const noexcept { return parent::innerStride(); }; using parent::size;
Index _outerStride() const noexcept { return parent::outerStride(); };
// Aliasing handling // Aliasing handling
auto evaluate() const
{
auto res = static_cast<parent const&>(*this).eval();
return as_concrete_type<decltype(res)>(res);
}
auto _evaluate() const { return T(base().eval()); } auto evaluate()
{
auto res = static_cast<parent&>(*this).eval();
return as_concrete_type<decltype(res)>(res);
}
decltype(auto) _noalias() const decltype(auto) noalias() const
{ {
if constexpr (use_expression_templates) return base().noalias(); if constexpr (use_expression_templates) return base().noalias();
else return *this; else return *this;
} }
decltype(auto) _noalias() decltype(auto) noalias()
{ {
if constexpr (use_expression_templates) return base().noalias(); if constexpr (use_expression_templates) return base().noalias();
else return *this; else return *this;
} }
// Numeric functions // Numeric functions
auto operator-() const { return detail::concretize<matrix>(-base()); } using parent::cwiseAbs;
using parent::cwiseAbs2;
auto _cwiseAbs() const using parent::cwiseInverse;
{ using parent::cwiseSqrt;
return detail::concretize<matrix>(base().cwiseAbs());
}
auto _cwiseAbs2() const
{
return detail::concretize<matrix>(base().cwiseAbs2());
}
auto _cwiseInverse() const
{
return detail::concretize<matrix>(base().cwiseInverse());
}
auto _cwiseSqrt() const
{
return detail::concretize<matrix>(base().cwiseSqrt());
}
// Reductions // Reductions
value_type _mean() const { return parent::mean(); } using parent::lpNorm;
using parent::maxCoeff;
value_type _norm() const { return parent::norm(); } using parent::mean;
using parent::minCoeff;
template<int P> value_type _lpNorm() const using parent::norm;
{ using parent::prod;
return parent::template lpNorm<P>(); using parent::squaredNorm;
} using parent::sum;
using parent::trace;
value_type _squaredNorm() const { return parent::squaredNorm(); }
value_type _sum() const { return parent::sum(); }
value_type _prod() const { return parent::prod(); }
value_type _trace() const { return parent::trace(); }
auto _minCoeff() const { return parent::minCoeff(); }
auto _maxCoeff() const { return parent::maxCoeff(); }
template<std::integral IndexType>
auto _minCoeff(IndexType* row, IndexType* col) const
{
Index result_row, result_col;
auto result = parent::minCoeff(&result_row, &result_col);
*row = result_row;
*col = result_col;
return result;
}
template<std::integral IndexType>
auto _maxCoeff(IndexType* row, IndexType* col) const
{
Index result_row, result_col;
auto result = parent::maxCoeff(&result_row, &result_col);
*row = result_row;
*col = result_col;
return result;
}
// Compound Operators // Compound Operators
template<typename A, int O, typename S> template<typename A, int O, typename S>
@ -220,113 +172,27 @@ namespace rotgen
} }
// Shape modifications // Shape modifications
auto _normalized() const using parent::adjoint;
requires(IsVectorAtCompileTime) using parent::conjugate;
{ using parent::normalized;
return detail::concretize<matrix>(base().normalized()); using parent::transpose;
}
auto _transpose() const
{
return detail::concretize<matrix>(base().transpose());
}
auto _adjoint() const
{
return detail::concretize<matrix>(base().adjoint());
}
auto _conjugate() const
{
return detail::concretize<matrix>(base().conjugate());
}
// In-place Shape modifications // In-place Shape modifications
using parent::adjointInPlace;
void _adjointInPlace() { parent::adjointInPlace(); } using parent::normalize;
using parent::transposeInPlace;
void _normalize()
requires(IsVectorAtCompileTime)
{
parent::normalize();
}
void _transposeInPlace() { parent::transposeInPlace(); }
// Generators // Generators
static auto _Zero() { return detail::concretize<matrix>(parent::Zero()); } using parent::Constant;
using parent::Identity;
static auto _Zero(int rows, int cols) using parent::Ones;
{ using parent::Random;
return detail::concretize<matrix>(parent::Zero(rows, cols)); using parent::setConstant;
} using parent::setIdentity;
using parent::setOnes;
static auto _Ones() { return detail::concretize<matrix>(parent::Ones()); } using parent::setRandom;
using parent::setZero;
static auto _Ones(int rows, int cols) using parent::Zero;
{
return detail::concretize<matrix>(parent::Ones(rows, cols));
}
static auto _Constant(value_type value)
{
return detail::concretize<matrix>(parent::Constant(value));
}
static auto _Constant(int rows, int cols, value_type value)
{
return detail::concretize<matrix>(parent::Constant(rows, cols, value));
}
static auto _Random()
{
return detail::concretize<matrix>(parent::Random());
}
static auto _Random(int rows, int cols)
{
return detail::concretize<matrix>(parent::Random(rows, cols));
}
static auto _Identity()
{
return detail::concretize<matrix>(parent::Identity());
}
static auto _Identity(int rows, int cols)
{
return detail::concretize<matrix>(parent::Identity(rows, cols));
}
ref& _setOnes()
{
base() = parent::Ones(base().rows(), base().cols());
return *this;
}
ref& _setZero()
{
base() = parent::Zero(base().rows(), base().cols());
return *this;
}
ref& _setConstant(value_type value)
{
base() = parent::Constant(base().rows(), base().cols(), value);
return *this;
}
ref& _setRandom()
{
base() = parent::Random(base().rows(), base().cols());
return *this;
}
ref& _setIdentity()
{
base() = parent::Identity(base().rows(), base().cols());
return *this;
}
auto qr_solve(auto const& rhs) const auto qr_solve(auto const& rhs) const
{ {
@ -346,12 +212,6 @@ namespace rotgen
parent& base() { return static_cast<parent&>(*this); } parent& base() { return static_cast<parent&>(*this); }
template<typename M>
requires(is_immutable)
ref(product<M> const& m) : ref(m.storage_)
{
}
template<typename S, int R, int C, int O, int MR, int MC> template<typename S, int R, int C, int O, int MR, int MC>
ref(matrix<S, R, C, O, MR, MC>& m) ref(matrix<S, R, C, O, MR, MC>& m)
requires(requires { parent(m.base()); }) requires(requires { parent(m.base()); })
@ -447,14 +307,13 @@ namespace rotgen
// Deduction Guides // Deduction Guides
//============================================================================ //============================================================================
template<typename S, int R, int C, int O, int MR, int MC> template<typename S, int R, int C, int O, int MR, int MC>
ref(matrix<S, R, C, O, MR, MC>&) -> ref<matrix<S, R, C, O, MR, MC>>; ref(matrix<S, R, C, O, MR, MC>&) -> ref<matrix<S>>;
template<typename Ref, int R, int C, bool I> template<typename Ref, int R, int C, bool I>
ref(block<Ref, R, C, I>& b) -> ref<Ref>; ref(block<Ref, R, C, I>& b) -> ref<Ref>;
template<typename S, int R, int C, int O, int MR, int MC> template<typename S, int R, int C, int O, int MR, int MC>
ref(matrix<S, R, C, O, MR, MC> const&) ref(matrix<S, R, C, O, MR, MC> const&) -> ref<matrix<S> const>;
-> ref<matrix<S, R, C, O, MR, MC> const>;
template<typename Ref, int R, int C, bool I> template<typename Ref, int R, int C, bool I>
ref(block<Ref, R, C, I> const& b) -> ref<Ref const>; ref(block<Ref, R, C, I> const& b) -> ref<Ref const>;
@ -477,14 +336,7 @@ namespace rotgen
template<typename A, int O, typename S, typename B, int P, typename T> template<typename A, int O, typename S, typename B, int P, typename T>
auto operator*(ref<A, O, S> lhs, ref<B, P, T> rhs) auto operator*(ref<A, O, S> lhs, ref<B, P, T> rhs)
{ {
auto p = lhs.base() * rhs.base(); return detail::concretize<matrix>(lhs.base() * rhs.base());
using concrete_type = detail::as_concrete_t<decltype(p), matrix>;
if constexpr (concrete_type::SizeAtCompileTime == 1)
return product{concrete_type{p}};
else if constexpr (concrete_type::SizeAtCompileTime == 0)
return concrete_type{};
else return concrete_type{p};
} }
template<typename A, int O, typename S> template<typename A, int O, typename S>
@ -559,6 +411,7 @@ namespace rotgen
template<typename A, int O, typename S, typename B, int P, typename T> template<typename A, int O, typename S, typename B, int P, typename T>
auto cross(ref<A, O, S> lhs, ref<B, P, T> rhs) auto cross(ref<A, O, S> lhs, ref<B, P, T> rhs)
-> decltype(lhs.base().cross(rhs.base()))
{ {
return detail::concretize<matrix>(lhs.base().cross(rhs.base())); return detail::concretize<matrix>(lhs.base().cross(rhs.base()));
} }
@ -579,8 +432,13 @@ namespace rotgen
using type = std::conditional_t<is_const, ref<base const>, ref<base>>; using type = std::conditional_t<is_const, ref<base const>, ref<base>>;
}; };
template<concepts::eigen_compatible T> decltype(auto) base_of(T&& a) template<concepts::eigen_compatible T> auto const& base_of(T const& a)
{ {
return ROTGEN_FWD(a); return a;
}
template<concepts::eigen_compatible T> auto& base_of(T& a)
{
return a;
} }
} }

View file

@ -7,67 +7,51 @@
//================================================================================================== //==================================================================================================
#pragma once #pragma once
#include <rotgen/detail/helpers.hpp>
#include <type_traits> #include <type_traits>
namespace rotgen namespace rotgen
{ {
template<typename A, int O, typename S, typename B, int P, typename T> template<typename A, int O, typename S, typename B, int P, typename T>
bool operator==(ref<A, O, S> const& lhs, ref<B, P, T> const& rhs) bool operator==(ref<A, O, S> lhs, ref<B, P, T> rhs)
{ {
return lhs.base() == rhs.base(); return lhs.base() == rhs.base();
} }
template<typename A, int O, typename S, typename B, int P, typename T> template<typename A, int O, typename S, typename B, int P, typename T>
bool operator!=(ref<A, O, S> const& lhs, ref<B, P, T> const& rhs) bool operator!=(ref<A, O, S> lhs, ref<B, P, T> rhs)
{ {
return lhs.base() != rhs.base(); return lhs.base() != rhs.base();
} }
template<typename A, int O, typename S> template<typename A, int O, typename S>
auto operator*(std::convertible_to<typename A::value_type> auto s, auto operator*(std::convertible_to<typename A::value_type> auto s,
ref<A, O, S> const& rhs) ref<A, O, S> rhs)
{ {
// void* _ = rhs;
return rhs * s; return rhs * s;
} }
template<typename A, int O, typename S, typename B, int P, typename T> template<typename A, int O, typename S, typename B, int P, typename T>
auto dot(ref<A, O, S> const& lhs, ref<B, P, T> const& rhs) auto dot(ref<A, O, S> lhs, ref<B, P, T> rhs)
{
if constexpr (requires { lhs.base().dot(rhs.base()); })
{ {
return lhs.base().dot(rhs.base()); return lhs.base().dot(rhs.base());
} }
else if constexpr (requires { lhs.base()._dot(rhs.base()); })
{
return lhs.base()._dot(rhs.base());
}
else
{
return detail::unsupported_parameters<T>();
}
}
template<typename A, int O, typename S> template<typename A, int O, typename S>
auto mul(ref<A, O, S> const& lhs, auto mul(ref<A, O, S> lhs, std::convertible_to<typename A::value_type> auto s)
std::convertible_to<typename A::value_type> auto s)
-> decltype(lhs * s) -> decltype(lhs * s)
{ {
return lhs * s; return lhs * s;
} }
template<typename A, int O, typename S> template<typename A, int O, typename S>
auto mul(std::convertible_to<typename A::value_type> auto s, auto mul(std::convertible_to<typename A::value_type> auto s, ref<A, O, S> rhs)
ref<A, O, S> const& rhs) -> decltype(s * rhs) -> decltype(s * rhs)
{ {
return s * rhs; return s * rhs;
} }
template<typename A, int O, typename S> template<typename A, int O, typename S>
auto div(ref<A, O, S> const& lhs, auto div(ref<A, O, S> lhs, std::convertible_to<typename A::value_type> auto s)
std::convertible_to<typename A::value_type> auto s)
-> decltype(lhs / s) -> decltype(lhs / s)
{ {
return lhs / s; return lhs / s;

View file

@ -1,16 +1,13 @@
//============================================================================== //==================================================================================================
/* /*
ROTGEN - Runtime Overlay for Eigen ROTGEN - Runtime Overlay for Eigen
Copyright : CODE RECKONS Copyright : CODE RECKONS
SPDX-License-Identifier: BSL-1.0 SPDX-License-Identifier: BSL-1.0
*/ */
//============================================================================== //==================================================================================================
#pragma once #pragma once
#include <rotgen/concepts.hpp>
#include <rotgen/config.hpp> #include <rotgen/config.hpp>
#include <rotgen/container/matrix.hpp>
#include <rotgen/container/ref.hpp>
#include <type_traits> #include <type_traits>
@ -18,7 +15,7 @@ namespace rotgen
{ {
template<typename Scalar, int Options = AutoAlign> class quaternion; template<typename Scalar, int Options = AutoAlign> class quaternion;
//---------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------
// Convert entity/eigen types to a proper ref so we can write less function // Convert entity/eigen types to a proper ref so we can write less function
// overloads // overloads
@ -35,12 +32,11 @@ namespace rotgen
template<concepts::entity T> struct generalize<T> template<concepts::entity T> struct generalize<T>
{ {
static constexpr bool is_const = static constexpr bool is_const = std::is_const_v<T>;
std::is_const_v<std::remove_reference_t<T>>; using base = matrix<typename T::value_type,
using base = matrix<typename std::remove_cvref_t<T>::value_type, T::RowsAtCompileTime,
std::remove_cvref_t<T>::RowsAtCompileTime, T::ColsAtCompileTime,
std::remove_cvref_t<T>::ColsAtCompileTime, T::storage_order>;
std::remove_cvref_t<T>::storage_order>;
using type = std::conditional_t<is_const, ref<base const>, ref<base>>; using type = std::conditional_t<is_const, ref<base const>, ref<base>>;
}; };

View file

@ -7,10 +7,7 @@
//================================================================================================== //==================================================================================================
#pragma once #pragma once
#include <rotgen/detail/assert.hpp> #include <cassert>
#include <rotgen/functions/functions.hpp>
#include <concepts> #include <concepts>
namespace rotgen::detail namespace rotgen::detail
@ -75,34 +72,30 @@ namespace rotgen::detail
using parent = typename Ref::parent; using parent = typename Ref::parent;
using map_base = typename parent::parent; using map_base = typename parent::parent;
auto r = rows(in); auto rows = in.rows();
auto c = cols(in); auto cols = in.cols();
if (Ref::RowsAtCompileTime == 1) if (Ref::RowsAtCompileTime == 1)
{ {
ROTGEN_ASSERT(rows(in) == 1 || cols(in) == 1, assert(in.rows() == 1 || in.cols() == 1);
"Incompatible rows/cols in ref binding"); rows = 1;
r = 1; cols = in.size();
c = in.size();
} }
else if (Ref::ColsAtCompileTime == 1) else if (Ref::ColsAtCompileTime == 1)
{ {
ROTGEN_ASSERT(rows(in) == 1 || cols(in) == 1, assert(in.rows() == 1 || in.cols() == 1);
"Incompatible rows/cols in ref binding"); rows = in.size();
r = in.size(); cols = 1;
c = 1;
} }
// Verify that the sizes are valid. // Verify that the sizes are valid.
ROTGEN_ASSERT((Ref::RowsAtCompileTime == Dynamic) || assert((Ref::RowsAtCompileTime == Dynamic) ||
(Ref::RowsAtCompileTime == r), (Ref::RowsAtCompileTime == rows));
"Incompatible static rows/cols in ref binding"); assert((Ref::ColsAtCompileTime == Dynamic) ||
ROTGEN_ASSERT((Ref::ColsAtCompileTime == Dynamic) || (Ref::ColsAtCompileTime == cols));
(Ref::ColsAtCompileTime == c),
"Incompatible static rows/cols in ref binding");
// Swap stride if we are a vector and we changed rows as such // Swap stride if we are a vector and we changed rows as such
bool transpose = Ref::IsVectorAtCompileTime && (r != rows(in)); bool transpose = Ref::IsVectorAtCompileTime && (rows != in.rows());
// Swap stride if storage ordder doesn't match // Swap stride if storage ordder doesn't match
constexpr bool row_major = Ref::IsRowMajor; constexpr bool row_major = Ref::IsRowMajor;
@ -112,13 +105,13 @@ namespace rotgen::detail
bool swap_stride = (transpose != storage_differs); bool swap_stride = (transpose != storage_differs);
// Determine expr's actual strides, resolving any defaults if zero. // Determine expr's actual strides, resolving any defaults if zero.
Index inner_actual = proper_inner_stride(innerStride(in)); Index inner_actual = proper_inner_stride(in.innerStride());
Index outer_actual = Index outer_actual =
proper_outer_stride(inner_actual, outerStride(in), rows(in), cols(in), proper_outer_stride(inner_actual, in.outerStride(), in.rows(), in.cols(),
Input::IsVectorAtCompileTime, input_row_major); Input::IsVectorAtCompileTime, input_row_major);
bool row_vector = (r == 1); bool row_vector = (rows == 1);
bool col_vector = (c == 1); bool col_vector = (cols == 1);
// Adapt inner stride based on row/col vector status // Adapt inner stride based on row/col vector status
Index inner_stride = Index inner_stride =
@ -134,7 +127,7 @@ namespace rotgen::detail
((!row_major && col_vector) || (row_major && row_vector)) ((!row_major && col_vector) || (row_major && row_vector))
? (stride_type::OuterStrideAtCompileTime > 0 ? (stride_type::OuterStrideAtCompileTime > 0
? stride_type::OuterStrideAtCompileTime ? stride_type::OuterStrideAtCompileTime
: r * c * inner_stride) : rows * cols * inner_stride)
: swap_stride ? inner_actual : swap_stride ? inner_actual
: outer_actual; : outer_actual;
@ -149,7 +142,7 @@ namespace rotgen::detail
bool outer_valid = bool outer_valid =
(stride_type::OuterStrideAtCompileTime == Dynamic) || (stride_type::OuterStrideAtCompileTime == Dynamic) ||
(proper_outer_stride( (proper_outer_stride(
inner_stride, Index(stride_type::OuterStrideAtCompileTime), r, c, inner_stride, Index(stride_type::OuterStrideAtCompileTime), rows, cols,
Ref::IsVectorAtCompileTime != 0, row_major) == outer_stride); Ref::IsVectorAtCompileTime != 0, row_major) == outer_stride);
if (!outer_valid) return false; if (!outer_valid) return false;
@ -158,7 +151,7 @@ namespace rotgen::detail
stride_type::OuterStrideAtCompileTime == 0 ? 1 : outer_stride, stride_type::OuterStrideAtCompileTime == 0 ? 1 : outer_stride,
stride_type::InnerStrideAtCompileTime == 0 ? 1 : inner_stride); stride_type::InnerStrideAtCompileTime == 0 ? 1 : inner_stride);
auto actual = map_base(in.data(), r, c, proper_stride); auto actual = map_base(in.data(), rows, cols, proper_stride);
ref.base().base().storage().swap(actual.storage()); ref.base().base().storage().swap(actual.storage());

View file

@ -1,22 +0,0 @@
//==================================================================================================
/*
ROTGEN - Runtime Overlay for Eigen
Copyright : CODE RECKONS
SPDX-License-Identifier: BSL-1.0
*/
//==================================================================================================
#pragma once
#if defined(ROTGEN_USE_LIBASSERT)
#include <libassert/assert.hpp>
#define ROTGEN_ASSERT(COND, ...) DEBUG_ASSERT(COND, __VA_ARGS__)
#else
#include <cassert>
#if !defined(NDEBUG)
#define ROTGEN_ASSERT(COND, MSG, ...) assert((COND) && (MSG))
#else
#define ROTGEN_ASSERT(COND, ...) (void)(COND)
#endif
#endif

View file

@ -1,10 +1,10 @@
//============================================================================== //==================================================================================================
/* /*
ROTGEN - Runtime Overlay for Eigen ROTGEN - Runtime Overlay for Eigen
Copyright : CODE RECKONS Copyright : CODE RECKONS
SPDX-License-Identifier: BSL-1.0 SPDX-License-Identifier: BSL-1.0
*/ */
//============================================================================== //==================================================================================================
#pragma once #pragma once
#include <rotgen/config.hpp> #include <rotgen/config.hpp>
@ -15,15 +15,6 @@
namespace rotgen::detail namespace rotgen::detail
{ {
/// Returned when a function is called with unsupported parameters,
/// effectively triggering a compile error to avoid undefined behaviors in
/// cases where return directives are missing.
template<typename T> auto unsupported_parameters()
{
static_assert(sizeof(T) == 0,
"Function was called with unsupported parameters.");
};
template<typename T> constexpr int static_size() template<typename T> constexpr int static_size()
{ {
auto rows = T::RowsAtCompileTime; auto rows = T::RowsAtCompileTime;
@ -40,7 +31,7 @@ namespace rotgen::detail
using type = Wrapper<typename EigenType::value_type, using type = Wrapper<typename EigenType::value_type,
EigenType::RowsAtCompileTime, EigenType::RowsAtCompileTime,
EigenType::ColsAtCompileTime, EigenType::ColsAtCompileTime,
EigenType::IsRowMajor ? RowMajor : ColMajor, EigenType::Flags & 1,
EigenType::MaxRowsAtCompileTime, EigenType::MaxRowsAtCompileTime,
EigenType::MaxColsAtCompileTime>; EigenType::MaxColsAtCompileTime>;
}; };

View file

@ -1,57 +0,0 @@
//==================================================================================================
/*
ROTGEN - Runtime Overlay for Eigen
Copyright : CODE RECKONS
SPDX-License-Identifier: BSL-1.0
*/
//==================================================================================================
#pragma once
#include <rotgen/detail/helpers.hpp>
#include <rotgen/container/matrix.hpp>
namespace rotgen
{
// Emulate EIGEN 1x1 pseudo product type
template<typename M> struct product
{
using rotgen_tag = void;
using value_type = typename M::value_type;
using concrete_type = matrix<value_type, 1, 1>;
static constexpr auto storage_order = concrete_type::storage_order;
static constexpr int RowsAtCompileTime = 1;
static constexpr int ColsAtCompileTime = 1;
static constexpr int SizeAtCompileTime = 1;
static constexpr int MaxRowsAtCompileTime = 1;
static constexpr int MaxColsAtCompileTime = 1;
static constexpr bool IsVectorAtCompileTime =
concrete_type::IsVectorAtCompileTime;
product(M const& m) : storage_(m) {}
auto size() const { return storage_.size(); }
auto _rows() const { return storage_._rows(); }
auto _cols() const { return storage_._cols(); }
auto operator()(int i) const { return storage_(i); }
auto operator[](int i) const { return storage_(i); }
auto operator()(int r, int c) const { return storage_(r, c); }
auto _sum() const { return storage_._sum(); }
auto const& base() const { return storage_.base(); }
operator value_type const() const { return storage_(0); }
operator concrete_type() const { return storage_; }
concrete_type storage_;
};
}

View file

@ -1,17 +1,13 @@
//============================================================================== //==================================================================================================
/* /*
ROTGEN - Runtime Overlay for Eigen ROTGEN - Runtime Overlay for Eigen
Copyright : CODE RECKONS Copyright : CODE RECKONS
SPDX-License-Identifier: BSL-1.0 SPDX-License-Identifier: BSL-1.0
*/ */
//============================================================================== //==================================================================================================
#pragma once #pragma once
#include <rotgen/detail/assert.hpp>
#include <rotgen/detail/helpers.hpp> #include <rotgen/detail/helpers.hpp>
#include <rotgen/concepts.hpp>
#include <type_traits> #include <type_traits>
namespace rotgen namespace rotgen
@ -25,12 +21,10 @@ namespace rotgen
[[maybe_unused]] Index ni, [[maybe_unused]] Index ni,
[[maybe_unused]] Index nj) [[maybe_unused]] Index nj)
{ {
ROTGEN_ASSERT(i0 >= 0, "block extraction uses negative row index."); assert(i0 >= 0 && "block extraction uses negative row index.");
ROTGEN_ASSERT(j0 >= 0, "block extraction uses negative col index."); assert(j0 >= 0 && "block extraction uses negative col index.");
ROTGEN_ASSERT(i0 + ni <= rows(e), assert(i0 + ni <= e.rows() && "block extraction rows is out of range.");
"block extraction rows is out of range."); assert(j0 + nj <= e.cols() && "block extraction cols is out of range.");
ROTGEN_ASSERT(j0 + nj <= cols(e),
"block extraction cols is out of range.");
} }
} }
@ -87,55 +81,55 @@ namespace rotgen
template<concepts::entity Entity> template<concepts::entity Entity>
auto topRightCorner(Entity&& e, Index ni, Index nj) auto topRightCorner(Entity&& e, Index ni, Index nj)
{ {
return extract(ROTGEN_FWD(e), 0, cols(e) - nj, ni, nj); return extract(ROTGEN_FWD(e), 0, e.cols() - nj, ni, nj);
} }
template<Index NI, Index NJ, concepts::entity Entity> template<Index NI, Index NJ, concepts::entity Entity>
auto topRightCorner(Entity&& e) auto topRightCorner(Entity&& e)
{ {
return extract<NI, NJ>(ROTGEN_FWD(e), 0, cols(e) - NJ); return extract<NI, NJ>(ROTGEN_FWD(e), 0, e.cols() - NJ);
} }
//======================== BOTTOM LEFT CORNER ======================== //======================== BOTTOM LEFT CORNER ========================
template<concepts::entity Entity> template<concepts::entity Entity>
auto bottomLeftCorner(Entity&& e, Index ni, Index nj) auto bottomLeftCorner(Entity&& e, Index ni, Index nj)
{ {
return extract(ROTGEN_FWD(e), rows(e) - ni, 0, ni, nj); return extract(ROTGEN_FWD(e), e.rows() - ni, 0, ni, nj);
} }
template<Index NI, Index NJ, concepts::entity Entity> template<Index NI, Index NJ, concepts::entity Entity>
auto bottomLeftCorner(Entity&& e) auto bottomLeftCorner(Entity&& e)
{ {
return extract<NI, NJ>(ROTGEN_FWD(e), rows(e) - NI, 0); return extract<NI, NJ>(ROTGEN_FWD(e), e.rows() - NI, 0);
} }
//======================== BOTTOM RIGHT CORNER ======================== //======================== BOTTOM RIGHT CORNER ========================
template<concepts::entity Entity> template<concepts::entity Entity>
auto bottomRightCorner(Entity&& e, Index ni, Index nj) auto bottomRightCorner(Entity&& e, Index ni, Index nj)
{ {
return extract(ROTGEN_FWD(e), rows(e) - ni, cols(e) - nj, ni, nj); return extract(ROTGEN_FWD(e), e.rows() - ni, e.cols() - nj, ni, nj);
} }
template<Index NI, Index NJ, concepts::entity Entity> template<Index NI, Index NJ, concepts::entity Entity>
auto bottomRightCorner(Entity&& e) auto bottomRightCorner(Entity&& e)
{ {
return extract<NI, NJ>(ROTGEN_FWD(e), rows(e) - NI, cols(e) - NJ); return extract<NI, NJ>(ROTGEN_FWD(e), e.rows() - NI, e.cols() - NJ);
} }
//======================== TOP ROWS ======================== //======================== TOP ROWS ========================
template<concepts::entity Entity> auto topRows(Entity&& e, Index ni) template<concepts::entity Entity> auto topRows(Entity&& e, Index ni)
{ {
if constexpr (std::remove_cvref_t<Entity>::ColsAtCompileTime == -1) if constexpr (std::remove_cvref_t<Entity>::ColsAtCompileTime == -1)
return extract(ROTGEN_FWD(e), 0, 0, ni, cols(e)); return extract(ROTGEN_FWD(e), 0, 0, ni, e.cols());
else else
return extract<-1, std::remove_cvref_t<Entity>::ColsAtCompileTime>( return extract<-1, std::remove_cvref_t<Entity>::ColsAtCompileTime>(
ROTGEN_FWD(e), 0, 0, ni, cols(e)); ROTGEN_FWD(e), 0, 0, ni, e.cols());
} }
template<Index NI, concepts::entity Entity> auto topRows(Entity&& e) template<Index NI, concepts::entity Entity> auto topRows(Entity&& e)
{ {
if constexpr (std::remove_cvref_t<Entity>::ColsAtCompileTime == -1) if constexpr (std::remove_cvref_t<Entity>::ColsAtCompileTime == -1)
return extract<NI, -1>(ROTGEN_FWD(e), 0, 0, NI, cols(e)); return extract<NI, -1>(ROTGEN_FWD(e), 0, 0, NI, e.cols());
else else
return extract<NI, std::remove_cvref_t<Entity>::ColsAtCompileTime>( return extract<NI, std::remove_cvref_t<Entity>::ColsAtCompileTime>(
ROTGEN_FWD(e), 0, 0); ROTGEN_FWD(e), 0, 0);
@ -146,17 +140,17 @@ namespace rotgen
auto middleRows(Entity&& e, Index i0, Index ni) auto middleRows(Entity&& e, Index i0, Index ni)
{ {
if constexpr (std::remove_cvref_t<Entity>::ColsAtCompileTime == -1) if constexpr (std::remove_cvref_t<Entity>::ColsAtCompileTime == -1)
return extract(ROTGEN_FWD(e), i0, 0, ni, cols(e)); return extract(ROTGEN_FWD(e), i0, 0, ni, e.cols());
else else
return extract<-1, std::remove_cvref_t<Entity>::ColsAtCompileTime>( return extract<-1, std::remove_cvref_t<Entity>::ColsAtCompileTime>(
ROTGEN_FWD(e), i0, 0, ni, cols(e)); ROTGEN_FWD(e), i0, 0, ni, e.cols());
} }
template<Index NI, concepts::entity Entity> template<Index NI, concepts::entity Entity>
auto middleRows(Entity&& e, Index i0) auto middleRows(Entity&& e, Index i0)
{ {
if constexpr (std::remove_cvref_t<Entity>::ColsAtCompileTime == -1) if constexpr (std::remove_cvref_t<Entity>::ColsAtCompileTime == -1)
return extract<NI, -1>(ROTGEN_FWD(e), i0, 0, NI, cols(e)); return extract<NI, -1>(ROTGEN_FWD(e), i0, 0, NI, e.cols());
else else
return extract<NI, std::remove_cvref_t<Entity>::ColsAtCompileTime>( return extract<NI, std::remove_cvref_t<Entity>::ColsAtCompileTime>(
ROTGEN_FWD(e), i0, 0); ROTGEN_FWD(e), i0, 0);
@ -166,35 +160,35 @@ namespace rotgen
template<concepts::entity Entity> auto bottomRows(Entity&& e, Index ni) template<concepts::entity Entity> auto bottomRows(Entity&& e, Index ni)
{ {
if constexpr (std::remove_cvref_t<Entity>::ColsAtCompileTime == -1) if constexpr (std::remove_cvref_t<Entity>::ColsAtCompileTime == -1)
return extract(ROTGEN_FWD(e), rows(e) - ni, 0, ni, cols(e)); return extract(ROTGEN_FWD(e), e.rows() - ni, 0, ni, e.cols());
else else
return extract<-1, std::remove_cvref_t<Entity>::ColsAtCompileTime>( return extract<-1, std::remove_cvref_t<Entity>::ColsAtCompileTime>(
ROTGEN_FWD(e), rows(e) - ni, 0, ni, cols(e)); ROTGEN_FWD(e), e.rows() - ni, 0, ni, e.cols());
} }
template<Index NI, concepts::entity Entity> auto bottomRows(Entity&& e) template<Index NI, concepts::entity Entity> auto bottomRows(Entity&& e)
{ {
if constexpr (std::remove_cvref_t<Entity>::ColsAtCompileTime == -1) if constexpr (std::remove_cvref_t<Entity>::ColsAtCompileTime == -1)
return extract<NI, -1>(ROTGEN_FWD(e), rows(e) - NI, 0, NI, cols(e)); return extract<NI, -1>(ROTGEN_FWD(e), e.rows() - NI, 0, NI, e.cols());
else else
return extract<NI, std::remove_cvref_t<Entity>::ColsAtCompileTime>( return extract<NI, std::remove_cvref_t<Entity>::ColsAtCompileTime>(
ROTGEN_FWD(e), rows(e) - NI, 0); ROTGEN_FWD(e), e.rows() - NI, 0);
} }
//======================== LEFT COLS ======================== //======================== LEFT COLS ========================
template<concepts::entity Entity> auto leftCols(Entity&& e, Index nj) template<concepts::entity Entity> auto leftCols(Entity&& e, Index nj)
{ {
if constexpr (std::remove_cvref_t<Entity>::RowsAtCompileTime == -1) if constexpr (std::remove_cvref_t<Entity>::RowsAtCompileTime == -1)
return extract(ROTGEN_FWD(e), 0, 0, rows(e), nj); return extract(ROTGEN_FWD(e), 0, 0, e.rows(), nj);
else else
return extract<std::remove_cvref_t<Entity>::RowsAtCompileTime, -1>( return extract<std::remove_cvref_t<Entity>::RowsAtCompileTime, -1>(
ROTGEN_FWD(e), 0, 0, rows(e), nj); ROTGEN_FWD(e), 0, 0, e.rows(), nj);
} }
template<Index NJ, concepts::entity Entity> auto leftCols(Entity&& e) template<Index NJ, concepts::entity Entity> auto leftCols(Entity&& e)
{ {
if constexpr (std::remove_cvref_t<Entity>::RowsAtCompileTime == -1) if constexpr (std::remove_cvref_t<Entity>::RowsAtCompileTime == -1)
return extract<-1, NJ>(ROTGEN_FWD(e), 0, 0, rows(e), NJ); return extract<-1, NJ>(ROTGEN_FWD(e), 0, 0, e.rows(), NJ);
else else
return extract<std::remove_cvref_t<Entity>::RowsAtCompileTime, NJ>( return extract<std::remove_cvref_t<Entity>::RowsAtCompileTime, NJ>(
ROTGEN_FWD(e), 0, 0); ROTGEN_FWD(e), 0, 0);
@ -205,17 +199,17 @@ namespace rotgen
auto middleCols(Entity&& e, Index j0, Index nj) auto middleCols(Entity&& e, Index j0, Index nj)
{ {
if constexpr (std::remove_cvref_t<Entity>::RowsAtCompileTime == -1) if constexpr (std::remove_cvref_t<Entity>::RowsAtCompileTime == -1)
return extract(ROTGEN_FWD(e), 0, j0, rows(e), nj); return extract(ROTGEN_FWD(e), 0, j0, e.rows(), nj);
else else
return extract<std::remove_cvref_t<Entity>::RowsAtCompileTime, -1>( return extract<std::remove_cvref_t<Entity>::RowsAtCompileTime, -1>(
ROTGEN_FWD(e), 0, j0, rows(e), nj); ROTGEN_FWD(e), 0, j0, e.rows(), nj);
} }
template<Index NJ, concepts::entity Entity> template<Index NJ, concepts::entity Entity>
auto middleCols(Entity&& e, Index j0) auto middleCols(Entity&& e, Index j0)
{ {
if constexpr (std::remove_cvref_t<Entity>::RowsAtCompileTime == -1) if constexpr (std::remove_cvref_t<Entity>::RowsAtCompileTime == -1)
return extract<-1, NJ>(ROTGEN_FWD(e), 0, j0, rows(e), NJ); return extract<-1, NJ>(ROTGEN_FWD(e), 0, j0, e.rows(), NJ);
else else
return extract<std::remove_cvref_t<Entity>::RowsAtCompileTime, NJ>( return extract<std::remove_cvref_t<Entity>::RowsAtCompileTime, NJ>(
ROTGEN_FWD(e), 0, j0); ROTGEN_FWD(e), 0, j0);
@ -225,27 +219,27 @@ namespace rotgen
template<concepts::entity Entity> auto rightCols(Entity&& e, Index nj) template<concepts::entity Entity> auto rightCols(Entity&& e, Index nj)
{ {
if constexpr (std::remove_cvref_t<Entity>::RowsAtCompileTime == -1) if constexpr (std::remove_cvref_t<Entity>::RowsAtCompileTime == -1)
return extract(ROTGEN_FWD(e), 0, cols(e) - nj, rows(e), nj); return extract(ROTGEN_FWD(e), 0, e.cols() - nj, e.rows(), nj);
else else
return extract<std::remove_cvref_t<Entity>::RowsAtCompileTime, -1>( return extract<std::remove_cvref_t<Entity>::RowsAtCompileTime, -1>(
ROTGEN_FWD(e), 0, cols(e) - nj, rows(e), nj); ROTGEN_FWD(e), 0, e.cols() - nj, e.rows(), nj);
; ;
} }
template<Index NJ, concepts::entity Entity> auto rightCols(Entity&& e) template<Index NJ, concepts::entity Entity> auto rightCols(Entity&& e)
{ {
if constexpr (std::remove_cvref_t<Entity>::RowsAtCompileTime == -1) if constexpr (std::remove_cvref_t<Entity>::RowsAtCompileTime == -1)
return extract<-1, NJ>(ROTGEN_FWD(e), 0, cols(e) - NJ, rows(e), NJ); return extract<-1, NJ>(ROTGEN_FWD(e), 0, e.cols() - NJ, e.rows(), NJ);
else else
return extract<std::remove_cvref_t<Entity>::RowsAtCompileTime, NJ>( return extract<std::remove_cvref_t<Entity>::RowsAtCompileTime, NJ>(
ROTGEN_FWD(e), 0, cols(e) - NJ); ROTGEN_FWD(e), 0, e.cols() - NJ);
} }
//======================== ROW ======================== //======================== ROW ========================
template<concepts::entity Entity> auto row(Entity&& e, Index i0) template<concepts::entity Entity> auto row(Entity&& e, Index i0)
{ {
if constexpr (std::remove_cvref_t<Entity>::ColsAtCompileTime == -1) if constexpr (std::remove_cvref_t<Entity>::ColsAtCompileTime == -1)
return extract<1, -1>(ROTGEN_FWD(e), i0, 0, 1, cols(e)); return extract<1, -1>(ROTGEN_FWD(e), i0, 0, 1, e.cols());
else else
return extract<1, std::remove_cvref_t<Entity>::ColsAtCompileTime>( return extract<1, std::remove_cvref_t<Entity>::ColsAtCompileTime>(
ROTGEN_FWD(e), i0, 0); ROTGEN_FWD(e), i0, 0);
@ -255,7 +249,7 @@ namespace rotgen
template<concepts::entity Entity> auto col(Entity&& e, Index j0) template<concepts::entity Entity> auto col(Entity&& e, Index j0)
{ {
if constexpr (std::remove_cvref_t<Entity>::RowsAtCompileTime == -1) if constexpr (std::remove_cvref_t<Entity>::RowsAtCompileTime == -1)
return extract<-1, 1>(ROTGEN_FWD(e), 0, j0, rows(e), 1); return extract<-1, 1>(ROTGEN_FWD(e), 0, j0, e.rows(), 1);
else else
return extract<std::remove_cvref_t<Entity>::RowsAtCompileTime, 1>( return extract<std::remove_cvref_t<Entity>::RowsAtCompileTime, 1>(
ROTGEN_FWD(e), 0, j0); ROTGEN_FWD(e), 0, j0);
@ -291,9 +285,9 @@ namespace rotgen
std::remove_cvref_t<Entity>::ColsAtCompileTime == 1) std::remove_cvref_t<Entity>::ColsAtCompileTime == 1)
{ {
if constexpr (std::remove_cvref_t<Entity>::RowsAtCompileTime == 1) if constexpr (std::remove_cvref_t<Entity>::RowsAtCompileTime == 1)
return extract<1, Dynamic>(ROTGEN_FWD(e), 0, cols(e) - n, 1, n); return extract<1, Dynamic>(ROTGEN_FWD(e), 0, e.cols() - n, 1, n);
else if constexpr (std::remove_cvref_t<Entity>::ColsAtCompileTime == 1) else if constexpr (std::remove_cvref_t<Entity>::ColsAtCompileTime == 1)
return extract<Dynamic, 1>(ROTGEN_FWD(e), rows(e) - n, 0, n, 1); return extract<Dynamic, 1>(ROTGEN_FWD(e), e.rows() - n, 0, n, 1);
} }
template<Index N, concepts::entity Entity> template<Index N, concepts::entity Entity>
@ -302,9 +296,9 @@ namespace rotgen
std::remove_cvref_t<Entity>::ColsAtCompileTime == 1) std::remove_cvref_t<Entity>::ColsAtCompileTime == 1)
{ {
if constexpr (std::remove_cvref_t<Entity>::RowsAtCompileTime == 1) if constexpr (std::remove_cvref_t<Entity>::RowsAtCompileTime == 1)
return extract<1, N>(ROTGEN_FWD(e), 0, cols(e) - N); return extract<1, N>(ROTGEN_FWD(e), 0, e.cols() - N);
else if constexpr (std::remove_cvref_t<Entity>::ColsAtCompileTime == 1) else if constexpr (std::remove_cvref_t<Entity>::ColsAtCompileTime == 1)
return extract<N, 1>(ROTGEN_FWD(e), rows(e) - N, 0); return extract<N, 1>(ROTGEN_FWD(e), e.rows() - N, 0);
} }
//======================== VECTOR SEGMENT ======================== //======================== VECTOR SEGMENT ========================

View file

@ -1,308 +1,187 @@
//============================================================================== //==================================================================================================
/* /*
ROTGEN - Runtime Overlay for Eigen ROTGEN - Runtime Overlay for Eigen
Copyright : CODE RECKONS Copyright : CODE RECKONS
SPDX-License-Identifier: BSL-1.0 SPDX-License-Identifier: BSL-1.0
*/ */
//============================================================================== //==================================================================================================
#pragma once #pragma once
#include <rotgen/detail/helpers.hpp> #include <rotgen/detail/helpers.hpp>
#include <rotgen/concepts.hpp>
#include <rotgen/container/ref/generalize.hpp>
namespace rotgen namespace rotgen
{ {
//---------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------------
// Infos & Shape // Infos & Shape
//---------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------------
/// Returns the row count of a matrix.
Index rows(auto const& m) Index rows(auto const& m)
requires(requires { m.rows(); })
{ {
if constexpr (requires { m.rows(); }) { return m.rows(); } return m.rows();
else if constexpr (requires { m._rows(); }) { return m._rows(); }
else { return detail::unsupported_parameters<decltype(m)>(); }
} }
/// Returns the column count of a matrix.
Index cols(auto const& m) Index cols(auto const& m)
requires(requires { m.cols(); })
{ {
return m.cols();
if constexpr (requires { m.cols(); }) { return m.cols(); }
else if constexpr (requires { m._cols(); }) { return m._cols(); }
else { return detail::unsupported_parameters<decltype(m)>(); }
} }
Index startRow(auto const& m)
{
if constexpr (requires { m.startRow(); }) { return m.startRow(); }
else if constexpr (requires { m._startRow(); }) { return m._startRow(); }
else { return detail::unsupported_parameters<decltype(m)>(); }
}
Index startCol(auto const& m)
{
if constexpr (requires { m.startCol(); }) { return m.startCol(); }
else if constexpr (requires { m._startCol(); }) { return m._startCol(); }
else { return detail::unsupported_parameters<decltype(m)>(); }
}
/// Returns the size of a matrix.
Index size(auto const& m) Index size(auto const& m)
requires(requires { m.size(); }) requires(requires { m.size(); })
{ {
return m.size(); return m.size();
} }
/// Resizes a matrix into a vector of size s. void resize(auto& a, int s)
void resize(auto& m, int s) requires requires { a.resize(s); }
requires requires { m.resize(s); }
{ {
m.resize(s); a.resize(s);
} }
/// Resizes a matrix into with a given number of rows and columns. void resize(auto& a, int r, int c)
void resize(auto& m, int r, int c) requires requires { a.resize(r, c); }
requires requires { m.resize(r, c); }
{ {
m.resize(r, c); a.resize(r, c);
} }
void conservativeResize(auto& a, int s) void conservativeResize(auto& a, int s)
{ requires requires { a.conservativeResize(s); }
if constexpr (requires { a.conservativeResize(s); })
{ {
a.conservativeResize(s); a.conservativeResize(s);
} }
else if constexpr (requires { a._conservativeResize(s); })
{
a._conservativeResize(s);
}
else { return detail::unsupported_parameters<decltype(a)>(); }
}
void conservativeResize(auto& a, int r, int c) void conservativeResize(auto& a, int r, int c)
{ requires requires { a.conservativeResize(r, c); }
if constexpr (requires { a.conservativeResize(r, c); })
{ {
a.conservativeResize(r, c); a.conservativeResize(r, c);
} }
else if constexpr (requires { a._conservativeResize(r, c); })
{
a._conservativeResize(r, c);
}
else { return detail::unsupported_parameters<decltype(a)>(); }
}
Index innerStride(auto const& m) //-----------------------------------------------------------------------------------------------
{
if constexpr (requires { m.innerStride(); }) { return m.innerStride(); }
else if constexpr (requires { m._innerStride(); })
{
return m._innerStride();
}
else { return detail::unsupported_parameters<decltype(m)>(); }
}
Index outerStride(auto const& m)
{
if constexpr (requires { m.outerStride(); }) { return m.outerStride(); }
else if constexpr (requires { m._outerStride(); })
{
return m._outerStride();
}
else { return detail::unsupported_parameters<decltype(m)>(); }
}
//----------------------------------------------------------------------------
// Global operations // Global operations
//---------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------------
decltype(auto) normalized(auto const& m) decltype(auto) normalized(auto const& m)
requires(requires { m.normalized(); })
{ {
if constexpr (requires { m.normalized(); }) { return m.normalized(); } return m.normalized();
else if constexpr (requires { m._normalized(); })
{
return m._normalized();
}
else { return detail::unsupported_parameters<decltype(m)>(); }
} }
decltype(auto) transpose(auto const& m) decltype(auto) transpose(auto const& m)
requires(requires { m.transpose(); })
{ {
if constexpr (requires { m.transpose(); }) { return m.transpose(); } return m.transpose();
else if constexpr (requires { m._transpose(); }) { return m._transpose(); }
else { return detail::unsupported_parameters<decltype(m)>(); }
} }
decltype(auto) conjugate(auto const& m) decltype(auto) conjugate(auto const& m)
requires(requires { m.conjugate(); })
{ {
if constexpr (requires { m.conjugate(); }) { return m.conjugate(); } return m.conjugate();
else if constexpr (requires { m._conjugate(); }) { return m._conjugate(); }
} }
decltype(auto) adjoint(auto const& m) decltype(auto) adjoint(auto const& m)
requires(requires { m.adjoint(); })
{ {
if constexpr (requires { m.adjoint(); }) { return m.adjoint(); } return m.adjoint();
else if constexpr (requires { m._adjoint(); }) { return m._adjoint(); }
else { return detail::unsupported_parameters<decltype(m)>(); }
} }
template<typename C> void normalize(C&& a) void normalize(auto& a)
requires(requires { a.normalize(); })
{ {
if constexpr (requires { std::forward<C>(a).normalize(); }) a.normalize();
{
std::forward<C>(a).normalize();
}
else if constexpr (requires { std::forward<C>(a)._normalize(); })
{
std::forward<C>(a)._normalize();
}
else { return detail::unsupported_parameters<decltype(a)>(); }
} }
template<typename C> void transposeInPlace(C&& a) void transposeInPlace(auto& a)
requires(requires { a.transposeInPlace(); })
{ {
if constexpr (requires { std::forward<C>(a).transposeInPlace(); }) a.transposeInPlace();
{
std::forward<C>(a).transposeInPlace();
}
else if constexpr (requires { std::forward<C>(a)._transposeInPlace(); })
{
std::forward<C>(a)._transposeInPlace();
}
else { return detail::unsupported_parameters<decltype(a)>(); }
} }
template<typename C> void adjointInPlace(C&& a) void adjointInPlace(auto& a)
requires(requires { a.adjointInPlace(); })
{ {
if constexpr (requires { std::forward<C>(a).adjointInPlace(); }) a.adjointInPlace();
{
std::forward<C>(a).adjointInPlace();
}
else if constexpr (requires { std::forward<C>(a)._adjointInPlace(); })
{
std::forward<C>(a)._adjointInPlace();
}
else { return detail::unsupported_parameters<decltype(a)>(); }
} }
//---------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------------
// Component-wise functions // Component-wise functions
//---------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------------
auto abs(auto const& arg) auto abs(auto const& arg)
requires(requires { arg.cwiseAbs(); })
{ {
if constexpr (requires { arg.cwiseAbs(); }) { return arg.cwiseAbs(); } return arg.cwiseAbs();
else if constexpr (requires { arg._cwiseAbs(); })
{
return arg._cwiseAbs();
}
else { return detail::unsupported_parameters<decltype(arg)>(); }
} }
auto abs2(auto const& arg) auto abs2(auto const& arg)
requires(requires { arg.cwiseAbs2(); })
{ {
if constexpr (requires { arg.cwiseAbs2(); }) { return arg.cwiseAbs2(); } return arg.cwiseAbs2();
else if constexpr (requires { arg._cwiseAbs2(); })
{
return arg._cwiseAbs2();
}
else { return detail::unsupported_parameters<decltype(arg)>(); }
} }
auto rec(auto const& arg) auto rec(auto const& arg)
{ requires(requires { arg.cwiseInverse(); })
if constexpr (requires { arg.cwiseInverse(); })
{ {
return arg.cwiseInverse(); return arg.cwiseInverse();
} }
else if constexpr (requires { arg._cwiseInverse(); })
{
return arg._cwiseInverse();
}
else { return detail::unsupported_parameters<decltype(arg)>(); }
}
auto sqrt(auto const& arg) auto sqrt(auto const& arg)
requires(requires { arg.cwiseSqrt(); })
{ {
if constexpr (requires { arg.cwiseSqrt(); }) { return arg.cwiseSqrt(); } return arg.cwiseSqrt();
else if constexpr (requires { arg._cwiseSqrt(); })
{
return arg._cwiseSqrt();
}
} }
template<concepts::entity A, concepts::entity B> template<concepts::entity A, concepts::entity B>
auto min(A const& a, B const& b) auto min(A const& a, B const& b)
{ {
if constexpr (!use_expression_templates) if constexpr (!use_expression_templates)
{
return min(generalize_t<A const>(a), generalize_t<B const>(b)); return min(generalize_t<A const>(a), generalize_t<B const>(b));
} else return base_of(a).cwiseMin(base_of(b));
else { return base_of(a).cwiseMin(base_of(b)); }
} }
template<concepts::entity A> template<concepts::entity A>
auto min(A const& a, std::convertible_to<typename A::value_type> auto b) auto min(A const& a, std::convertible_to<typename A::value_type> auto b)
{ {
if constexpr (!use_expression_templates) if constexpr (!use_expression_templates)
{
return min(generalize_t<A const>(a), b); return min(generalize_t<A const>(a), b);
} else return base_of(a).cwiseMin(b);
else { return base_of(a).cwiseMin(b); }
} }
template<concepts::entity B> template<concepts::entity B>
auto min(std::convertible_to<typename B::value_type> auto a, B const& b) auto min(std::convertible_to<typename B::value_type> auto a, B const& b)
{ {
if constexpr (!use_expression_templates) if constexpr (!use_expression_templates)
{
return min(a, generalize_t<B const>(b)); return min(a, generalize_t<B const>(b));
} else return base_of(b).cwiseMin(a);
else { return base_of(b).cwiseMin(a); }
} }
template<concepts::entity A, concepts::entity B> template<concepts::entity A, concepts::entity B>
auto max(A const& a, B const& b) auto max(A const& a, B const& b)
{ {
if constexpr (!use_expression_templates) if constexpr (!use_expression_templates)
{
return max(generalize_t<A const>(a), generalize_t<B const>(b)); return max(generalize_t<A const>(a), generalize_t<B const>(b));
} else return base_of(a).cwiseMax(base_of(b));
else { return base_of(a).cwiseMax(base_of(b)); }
} }
template<concepts::entity A> template<concepts::entity A>
auto max(A const& a, std::convertible_to<typename A::value_type> auto b) auto max(A const& a, std::convertible_to<typename A::value_type> auto b)
{ {
if constexpr (!use_expression_templates) if constexpr (!use_expression_templates)
{
return max(generalize_t<A const>(a), b); return max(generalize_t<A const>(a), b);
} else return base_of(a).cwiseMax(b);
else { return base_of(a).cwiseMax(b); }
} }
template<concepts::entity B> template<concepts::entity B>
auto max(std::convertible_to<typename B::value_type> auto a, B const& b) auto max(std::convertible_to<typename B::value_type> auto a, B const& b)
{ {
if constexpr (!use_expression_templates) if constexpr (!use_expression_templates)
{
return max(a, generalize_t<B const>(b)); return max(a, generalize_t<B const>(b));
} else return base_of(b).cwiseMax(a);
else { return base_of(b).cwiseMax(a); }
} }
template<concepts::entity A, concepts::entity B> template<concepts::entity A, concepts::entity B>
auto mul(A const& a, B const& b) auto mul(A const& a, B const& b)
{ {
if constexpr (!use_expression_templates) if constexpr (!use_expression_templates)
{
return mul(generalize_t<A const>(a), generalize_t<B const>(b)); return mul(generalize_t<A const>(a), generalize_t<B const>(b));
} else return base_of(a).cwiseProduct(base_of(b));
else { return base_of(a).cwiseProduct(base_of(b)); }
} }
template<concepts::entity A> template<concepts::entity A>
@ -321,10 +200,8 @@ namespace rotgen
auto div(A const& a, B const& b) auto div(A const& a, B const& b)
{ {
if constexpr (!use_expression_templates) if constexpr (!use_expression_templates)
{
return div(generalize_t<A const>(a), generalize_t<B const>(b)); return div(generalize_t<A const>(a), generalize_t<B const>(b));
} else return base_of(a).array() / base_of(b).array();
else { return base_of(a).array() / base_of(b).array(); }
} }
template<concepts::entity A> template<concepts::entity A>
@ -338,54 +215,43 @@ namespace rotgen
return mul(a, a); return mul(a, a);
} }
//---------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------------
// Reductions // Reductions
//---------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------------
auto trace(auto const& arg) auto trace(auto const& arg)
requires requires { arg.trace(); }
{ {
if constexpr (requires { arg.trace(); }) { return arg.trace(); } return arg.trace();
else if constexpr (requires { arg._trace(); }) { return arg._trace(); }
else { return detail::unsupported_parameters<decltype(arg)>(); }
} }
auto squaredNorm(auto const& arg) auto squaredNorm(auto const& arg)
requires requires { arg.squaredNorm(); }
{ {
if constexpr (requires { arg.squaredNorm(); }) { return arg.squaredNorm(); } return arg.squaredNorm();
else if constexpr (requires { arg._squaredNorm(); })
{
return arg._squaredNorm();
}
else { return detail::unsupported_parameters<decltype(arg)>(); }
} }
auto norm(auto const& arg) auto norm(auto const& arg)
requires requires { arg.norm(); }
{ {
if constexpr (requires { arg.norm(); }) { return arg.norm(); } return arg.norm();
else if constexpr (requires { arg._norm(); }) { return arg._norm(); }
else { return detail::unsupported_parameters<decltype(arg)>(); }
} }
auto sum(auto const& arg) auto sum(auto const& arg)
requires(requires { arg.sum(); } || requires { arg._sum(); }) requires requires { arg.sum(); }
{ {
if constexpr (requires { arg.sum(); }) { return arg.sum(); } return arg.sum();
else if constexpr (requires { arg._sum(); }) { return arg._sum(); }
else { return detail::unsupported_parameters<decltype(arg)>(); }
} }
auto prod(auto const& arg) auto prod(auto const& arg)
requires requires { arg.prod(); }
{ {
if constexpr (requires { arg.prod(); }) { return arg.prod(); } return arg.prod();
else if constexpr (requires { arg._prod(); }) { return arg._prod(); }
else { return detail::unsupported_parameters<decltype(arg)>(); }
} }
auto mean(auto const& arg) auto mean(auto const& arg)
requires requires { arg.mean(); }
{ {
if constexpr (requires { arg.mean(); }) { return arg.mean(); } return arg.mean();
else if constexpr (requires { arg._mean(); }) { return arg._mean(); }
else { return detail::unsupported_parameters<decltype(arg)>(); }
} }
template<concepts::entity A, concepts::entity B> template<concepts::entity A, concepts::entity B>
@ -394,135 +260,89 @@ namespace rotgen
std::same_as<typename A::value_type, typename B::value_type>) std::same_as<typename A::value_type, typename B::value_type>)
{ {
if constexpr (!use_expression_templates) if constexpr (!use_expression_templates)
{
return dot(generalize_t<A const>(a), generalize_t<B const>(b)); return dot(generalize_t<A const>(a), generalize_t<B const>(b));
} else return base_of(a).dot(base_of(b));
else { return base_of(a).dot(base_of(b)); }
} }
auto maxCoeff(auto const& arg) auto maxCoeff(auto const& arg)
requires(requires { arg.maxCoeff(); })
{ {
if constexpr (requires { arg.maxCoeff(); }) { return arg.maxCoeff(); } return arg.maxCoeff();
else if constexpr (requires { arg._maxCoeff(); })
{
return arg._maxCoeff();
}
else { return detail::unsupported_parameters<decltype(arg)>(); }
} }
auto minCoeff(auto const& arg) auto minCoeff(auto const& arg)
requires(requires { arg.minCoeff(); })
{ {
if constexpr (requires { arg.minCoeff(); }) { return arg.minCoeff(); } return arg.minCoeff();
else if constexpr (requires { arg._minCoeff(); })
{
return arg._minCoeff();
}
else { return detail::unsupported_parameters<decltype(arg)>(); }
} }
template<std::integral IndexType> template<std::integral IndexType>
auto maxCoeff(auto const& arg, IndexType* row, IndexType* col) auto maxCoeff(auto const& arg, IndexType* row, IndexType* col)
{ requires(requires { arg.maxCoeff(row, col); })
if constexpr (requires { arg.maxCoeff(row, col); })
{ {
return arg.maxCoeff(row, col); return arg.maxCoeff(row, col);
} }
else if constexpr (requires { arg._maxCoeff(row, col); })
{
return arg._maxCoeff(row, col);
}
else { return detail::unsupported_parameters<decltype(arg)>(); }
}
template<std::integral IndexType> template<std::integral IndexType>
auto minCoeff(auto const& arg, IndexType* row, IndexType* col) auto minCoeff(auto const& arg, IndexType* row, IndexType* col)
{ requires(requires { arg.minCoeff(row, col); })
if constexpr (requires { arg.minCoeff(row, col); })
{ {
return arg.minCoeff(row, col); return arg.minCoeff(row, col);
} }
else if constexpr (requires { arg._minCoeff(row, col); })
{
return arg._minCoeff(row, col);
}
else { return detail::unsupported_parameters<decltype(arg)>(); }
}
template<int P, typename T> auto lpNorm(T const& arg) template<int P, typename T>
{ auto lpNorm(T const& arg)
if constexpr (requires { arg.template lpNorm<P>(); }) requires(requires { arg.template lpNorm<P>(); })
{ {
static_assert(P == 1 || P == 2 || P == Infinity); static_assert(P == 1 || P == 2 || P == Infinity);
return arg.template lpNorm<P>(); return arg.template lpNorm<P>();
} }
else if constexpr (requires { arg.template _lpNorm<P>(); })
{
static_assert(P == 1 || P == 2 || P == Infinity);
return arg.template _lpNorm<P>();
}
else { return detail::unsupported_parameters<decltype(arg)>(); }
}
//---------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------------
// Expression handling // Expression handling
//---------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------------
template<typename T> decltype(auto) noalias(T&& t) template<typename T>
{ decltype(auto) noalias(T&& t)
if constexpr (requires { std::forward<T>(t).noalias(); }) requires(requires { std::forward<T>(t).noalias(); })
{ {
return std::forward<T>(t).noalias(); return std::forward<T>(t).noalias();
} }
else if constexpr (requires { std::forward<T>(t)._noalias(); })
{
return std::forward<T>(t)._noalias();
}
else { return detail::unsupported_parameters<decltype(t)>(); }
}
template<typename T> auto evaluate(T&& t) template<typename T>
{ auto evaluate(T&& t)
if constexpr (requires { std::forward<T>(t).evaluate(); }) requires(requires { std::forward<T>(t).evaluate(); })
{ {
return std::forward<T>(t).evaluate(); return std::forward<T>(t).evaluate();
} }
else if constexpr (requires { std::forward<T>(t)._evaluate(); })
{ template<typename T>
return std::forward<T>(t)._evaluate(); auto evaluate(T&& t)
} requires(requires { std::forward<T>(t).eval(); })
else if constexpr (requires { std::forward<T>(t).eval(); })
{ {
return std::forward<T>(t).eval(); return std::forward<T>(t).eval();
} }
else { return detail::unsupported_parameters<decltype(t)>(); }
}
//---------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------------
// Others // Others
// TODO: Adapt other functions ot behave as inverse and limit code in // TODO: Adapt other functions ot behave as inverse and limit code in
// non-ref/non-map containers // non-ref/non-map containers
//---------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------------
template<typename A> auto inverse(A const& a) template<typename A> auto inverse(A const& a)
{ {
if constexpr (!use_expression_templates) if constexpr (!use_expression_templates)
{
return inverse(generalize_t<A const>(a)); return inverse(generalize_t<A const>(a));
} else return base_of(a).inverse();
else { return base_of(a).inverse(); }
} }
template<concepts::vectorND<3> L, concepts::vectorND<3> R> template<concepts::vectorND<3> L, concepts::vectorND<3> R>
auto cross(L const& l, R const& r) auto cross(L const& l, R const& r)
{ {
if constexpr (!use_expression_templates) if constexpr (!use_expression_templates)
{
return cross(generalize_t<R const>(l), generalize_t<R const>(r)); return cross(generalize_t<R const>(l), generalize_t<R const>(r));
}
else if constexpr ( else if constexpr (
requires { typename L::rotgen_tag; } || requires { typename L::rotgen_tag; } ||
requires { typename R::rotgen_tag; }) requires { typename R::rotgen_tag; })
{ return base_of(l).cross(base_of(r));
return base_of(l)._cross(base_of(r)); else return l.cross(r);
}
else { return l._cross(r); }
} }
} }

View file

@ -1,288 +1,156 @@
//============================================================================== //==================================================================================================
/* /*
ROTGEN - Runtime Overlay for Eigen ROTGEN - Runtime Overlay for Eigen
Copyright : CODE RECKONS Copyright : CODE RECKONS
SPDX-License-Identifier: BSL-1.0 SPDX-License-Identifier: BSL-1.0
*/ */
//============================================================================== //==================================================================================================
#pragma once #pragma once
#include <rotgen/detail/assert.hpp>
#include <rotgen/detail/helpers.hpp> #include <rotgen/detail/helpers.hpp>
#include <rotgen/container/map.hpp>
namespace rotgen namespace rotgen
{ {
//---------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------
template<typename T, typename... Args> void initialize_with(T&& m, Args... v)
{
using type = typename std::remove_cvref_t<T>::value_type;
using map_t = rotgen::map<rotgen::matrix<type, -1, -1, rotgen::RowMajor>>;
ROTGEN_ASSERT(sizeof...(v) == m.size(),
"Incorrect quantity of coefficients for initialization");
type data[] = {static_cast<type>(v)...};
m = map_t(data, rows(m), cols(m));
}
//----------------------------------------------------------------------------
// Generators // Generators
//---------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------------
template<typename T>
template<typename T> auto setZero(T&& t) auto setZero(T&& t)
{ requires(requires { std::forward<T>(t).setZero(); })
if constexpr (requires { std::forward<T>(t).setZero(); })
{ {
return std::forward<T>(t).setZero(); return std::forward<T>(t).setZero();
} }
else if constexpr (requires { std::forward<T>(t)._setZero(); })
template<typename T>
auto setZero()
requires(requires { T::Zero(); })
{ {
return std::forward<T>(t)._setZero(); return T::Zero();
}
else
{
return detail::unsupported_parameters<T>();
}
} }
template<typename T> auto setZero() template<typename T>
auto setZero(std::integral auto n)
requires(requires { T::Zero(n); })
{ {
if constexpr (requires { T::Zero(); }) { return T::Zero(); } return T::Zero(n);
else if constexpr (requires { T::_Zero(); }) { return T::_Zero(); }
else
{
return detail::unsupported_parameters<T>();
}
} }
template<typename T> auto setZero(std::integral auto n) template<typename T>
auto setZero(std::integral auto r, std::integral auto c)
requires(requires { T::Zero(r, c); })
{ {
if constexpr (requires { T::Zero(n); }) { return T::Zero(n); } return T::Zero(r, c);
else if constexpr (requires { T::_Zero(n); }) { return T::_Zero(n); }
else
{
return detail::unsupported_parameters<T>();
}
} }
template<typename T> auto setZero(std::integral auto r, std::integral auto c) template<typename T>
{ auto setOnes(T&& t)
if constexpr (requires { T::Zero(r, c); }) { return T::Zero(r, c); } requires(requires { std::forward<T>(t).setOnes(); })
else if constexpr (requires { T::_Zero(r, c); }) { return T::_Zero(r, c); }
else
{
return detail::unsupported_parameters<T>();
}
}
template<typename T> auto setOnes(T&& t)
{
if constexpr (requires { std::forward<T>(t).setOnes(); })
{ {
return std::forward<T>(t).setOnes(); return std::forward<T>(t).setOnes();
} }
else if constexpr (requires { std::forward<T>(t)._setOnes(); })
template<typename T>
auto setOnes()
requires(requires { T::Ones(); })
{ {
return std::forward<T>(t)._setOnes(); return T::Ones();
}
else
{
return detail::unsupported_parameters<T>();
}
} }
template<typename T> auto setOnes() template<typename T>
auto setOnes(std::integral auto n)
requires(requires { T::Ones(n); })
{ {
if constexpr (requires { T::Ones(); }) { return T::Ones(); } return T::Ones(n);
else if constexpr (requires { T::_Ones(); }) { return T::_Ones(); }
else
{
return detail::unsupported_parameters<T>();
}
} }
template<typename T> auto setOnes(std::integral auto n) template<typename T>
auto setOnes(std::integral auto r, std::integral auto c)
requires(requires { T::Ones(r, c); })
{ {
if constexpr (requires { T::Ones(n); }) { return T::Ones(n); } return T::Ones(r, c);
else if constexpr (requires { T::_Ones(n); }) { return T::_Ones(n); }
else
{
return detail::unsupported_parameters<T>();
}
} }
template<typename T> auto setOnes(std::integral auto r, std::integral auto c) template<typename T>
{ auto setIdentity(T&& t)
if constexpr (requires { T::Ones(r, c); }) { return T::Ones(r, c); } requires(requires { std::forward<T>(t).setIdentity(); })
else if constexpr (requires { T::_Ones(r, c); }) { return T::_Ones(r, c); }
else
{
return detail::unsupported_parameters<T>();
}
}
template<typename T> auto setIdentity(T&& t)
{
if constexpr (requires { std::forward<T>(t).setIdentity(); })
{ {
return std::forward<T>(t).setIdentity(); return std::forward<T>(t).setIdentity();
} }
else if constexpr (requires { std::forward<T>(t)._setIdentity(); })
template<typename T>
auto setIdentity()
requires(requires { T::Identity(); })
{ {
return std::forward<T>(t)._setIdentity(); return T::Identity();
}
else
{
return detail::unsupported_parameters<T>();
}
} }
template<typename T> auto setIdentity() template<typename T>
auto setIdentity(std::integral auto n)
requires(requires { T::Identity(n); })
{ {
if constexpr (requires { T::Identity(); }) { return T::Identity(); } return T::Identity(n);
else if constexpr (requires { T::_Identity(); }) { return T::_Identity(); }
else
{
return detail::unsupported_parameters<T>();
}
}
template<typename T> auto setIdentity(std::integral auto n)
{
if constexpr (requires { T::Identity(n); }) { return T::Identity(n); }
else if constexpr (requires { T::_Identity(n); })
{
return T::_Identity(n);
}
else
{
return detail::unsupported_parameters<T>();
}
} }
template<typename T> template<typename T>
auto setIdentity(std::integral auto r, std::integral auto c) auto setIdentity(std::integral auto r, std::integral auto c)
requires(requires { T::Identity(r, c); })
{ {
if constexpr (requires { T::Identity(r, c); }) { return T::Identity(r, c); } return T::Identity(r, c);
else if constexpr (requires { T::_Identity(r, c); })
{
return T::_Identity(r, c);
}
else
{
return detail::unsupported_parameters<T>();
}
} }
template<typename T> auto setRandom(T&& t) template<typename T>
{ auto setRandom(T&& t)
if constexpr (requires { std::forward<T>(t).setRandom(); }) requires(requires { std::forward<T>(t).setRandom(); })
{ {
return std::forward<T>(t).setRandom(); return std::forward<T>(t).setRandom();
} }
else if constexpr (requires { std::forward<T>(t)._setRandom(); })
template<typename T>
auto setRandom()
requires(requires { T::Random(); })
{ {
return std::forward<T>(t)._setRandom(); return T::Random();
}
else
{
return detail::unsupported_parameters<T>();
}
} }
template<typename T> auto setRandom() template<typename T>
auto setRandom(std::integral auto n)
requires(requires { T::Random(n); })
{ {
if constexpr (requires { T::Random(); }) { return T::Random(); } return T::Random(n);
else if constexpr (requires { T::_Random(); }) { return T::_Random(); }
else
{
return detail::unsupported_parameters<T>();
}
}
template<typename T> auto setRandom(std::integral auto n)
{
if constexpr (requires { T::Random(n); }) { return T::Random(n); }
else if constexpr (requires { T::_Random(n); }) { return T::_Random(n); }
else
{
return detail::unsupported_parameters<T>();
}
} }
template<typename T> template<typename T>
auto setRandom(std::integral auto r, std::integral auto c) auto setRandom(std::integral auto r, std::integral auto c)
requires(requires { T::Random(r, c); })
{ {
if constexpr (requires { T::Random(r, c); }) { return T::Random(r, c); } return T::Random(r, c);
else if constexpr (requires { T::_Random(r, c); })
{
return T::_Random(r, c);
}
else
{
return detail::unsupported_parameters<T>();
}
} }
template<typename T> auto setConstant(T&& t, auto v) template<typename T>
{ auto setConstant(T&& t, auto v)
if constexpr (requires { std::forward<T>(t).setConstant(v); }) requires(requires { std::forward<T>(t).setConstant(v); })
{ {
return std::forward<T>(t).setConstant(v); return std::forward<T>(t).setConstant(v);
} }
else if constexpr (requires { std::forward<T>(t)._setConstant(v); })
template<typename T>
auto setConstant(auto v)
requires(requires { T::Constant(v); })
{ {
return std::forward<T>(t)._setConstant(v); return T::Constant(v);
}
else
{
return detail::unsupported_parameters<T>();
}
} }
template<typename T> auto setConstant(auto v) template<typename T>
auto setConstant(std::integral auto n, auto v)
requires(requires { T::Constant(n, v); })
{ {
if constexpr (requires { T::Constant(v); }) { return T::Constant(v); } return T::Constant(n, v);
else if constexpr (requires { T::_Constant(v); })
{
return T::_Constant(v);
}
else
{
return detail::unsupported_parameters<T>();
}
}
template<typename T> auto setConstant(std::integral auto n, auto v)
{
if constexpr (requires { T::Constant(n, v); }) { return T::Constant(n, v); }
else if constexpr (requires { T::_Constant(n, v); })
{
return T::_Constant(n, v);
}
else
{
return detail::unsupported_parameters<T>();
}
} }
template<typename T> template<typename T>
auto setConstant(std::integral auto r, std::integral auto c, auto v) auto setConstant(std::integral auto r, std::integral auto c, auto v)
{ requires(requires { T::Constant(r, c, v); })
if constexpr (requires { T::Constant(r, c, v); })
{ {
return T::Constant(r, c, v); return T::Constant(r, c, v);
} }
else if constexpr (requires { T::_Constant(r, c, v); })
{
return T::_Constant(r, c, v);
}
else
{
return detail::unsupported_parameters<T>();
}
}
} }

View file

@ -7,10 +7,9 @@
//================================================================================================== //==================================================================================================
#pragma once #pragma once
#include <rotgen/detail/product.hpp>
#include <rotgen/concepts.hpp> #include <rotgen/concepts.hpp>
#include <cassert>
#include <iosfwd> #include <iosfwd>
namespace rotgen namespace rotgen
@ -81,27 +80,30 @@ namespace rotgen
//------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------
// Compounds operators across types // Compounds operators across types
template<concepts::entity A, concepts::entity B> template<typename A, typename B>
decltype(auto) operator+=(A&& a, B const& b) auto operator+=(A& a, B const& b)
requires(!concepts::block<A>) requires(concepts::entity<A> && concepts::entity<B>)
{ {
generalize_t<A>(ROTGEN_FWD(a)) += generalize_t<B const>(b); if constexpr (!use_expression_templates)
return ROTGEN_FWD(a); return generalize_t<A>(a) += generalize_t<B const>(b);
else return base_of(a) += base_of(b);
} }
template<concepts::entity A, concepts::entity B> template<typename A, typename B>
decltype(auto) operator-=(A&& a, B const& b) auto operator-=(A& a, B const& b)
requires(!concepts::block<A>) requires(concepts::entity<A> && concepts::entity<B>)
{ {
generalize_t<A>(ROTGEN_FWD(a)) -= generalize_t<B const>(b); if constexpr (!use_expression_templates)
return ROTGEN_FWD(a); return generalize_t<A>(a) -= generalize_t<B const>(b);
else return base_of(a) -= base_of(b);
} }
template<concepts::entity A, concepts::entity B> template<typename A, typename B>
decltype(auto) operator*=(A&& a, B const& b) auto operator*=(A& a, B const& b)
requires(!concepts::block<A>) requires(concepts::entity<A> && concepts::entity<B>)
{ {
generalize_t<A>(ROTGEN_FWD(a)) *= generalize_t<B const>(b); if constexpr (!use_expression_templates)
return ROTGEN_FWD(a); return generalize_t<A>(a) *= generalize_t<B const>(b);
else return base_of(a) *= base_of(b);
} }
} }

View file

@ -7,11 +7,6 @@
//================================================================================================== //==================================================================================================
#pragma once #pragma once
#include <rotgen/config.hpp>
#include <rotgen/functions/functions.hpp>
#include <type_traits>
namespace rotgen namespace rotgen
{ {
template<typename Ref> struct rowwise_adaptor template<typename Ref> struct rowwise_adaptor
@ -19,64 +14,64 @@ namespace rotgen
using concrete_type = typename std::remove_cvref_t<Ref>::concrete_type; using concrete_type = typename std::remove_cvref_t<Ref>::concrete_type;
Ref& target_; Ref& target_;
concrete_type _sum() const concrete_type sum() const
{ {
concrete_type res(rows(target_), 1); concrete_type res(target_.rows(), 1);
apply([&](auto r, auto i) { res(i) = rotgen::sum(r); }); apply([&](auto r, auto i) { res(i) = r.sum(); });
return res; return res;
} }
concrete_type _mean() const concrete_type mean() const
{ {
concrete_type res(rows(target_), 1); concrete_type res(target_.rows(), 1);
apply([&](auto r, auto i) { res(i) = rotgen::mean(r); }); apply([&](auto r, auto i) { res(i) = r.mean(); });
return res; return res;
} }
concrete_type _prod() const concrete_type prod() const
{ {
concrete_type res(rows(target_), 1); concrete_type res(target_.rows(), 1);
apply([&](auto r, auto i) { res(i) = rotgen::prod(r); }); apply([&](auto r, auto i) { res(i) = r.prod(); });
return res; return res;
} }
concrete_type _maxCoeff() const concrete_type maxCoeff() const
{ {
concrete_type res(rows(target_), 1); concrete_type res(target_.rows(), 1);
apply([&](auto r, auto i) { res(i) = rotgen::maxCoeff(r); }); apply([&](auto r, auto i) { res(i) = r.maxCoeff(); });
return res; return res;
} }
concrete_type _minCoeff() const concrete_type minCoeff() const
{ {
concrete_type res(rows(target_), 1); concrete_type res(target_.rows(), 1);
apply([&](auto r, auto i) { res(i) = rotgen::minCoeff(r); }); apply([&](auto r, auto i) { res(i) = r.minCoeff(); });
return res; return res;
} }
concrete_type _squaredNorm() const concrete_type squaredNorm() const
{ {
concrete_type res(rows(target_), 1); concrete_type res(target_.rows(), 1);
apply([&](auto r, auto i) { res(i) = rotgen::squaredNorm(r); }); apply([&](auto r, auto i) { res(i) = r.squaredNorm(); });
return res; return res;
} }
concrete_type _norm() const concrete_type norm() const
{ {
concrete_type res(rows(target_), 1); concrete_type res(target_.rows(), 1);
apply([&](auto r, auto i) { res(i) = rotgen::norm(r); }); apply([&](auto r, auto i) { res(i) = r.norm(); });
return res; return res;
} }
private: private:
template<typename Func> void apply(Func f) template<typename Func> void apply(Func f)
{ {
for (Index i = 0; i < rows(target_); ++i) { f(row(target_, i), i); } for (Index i = 0; i < target_.rows(); ++i) f(row(target_, i), i);
} }
template<typename Func> void apply(Func f) const template<typename Func> void apply(Func f) const
{ {
for (Index i = 0; i < rows(target_); ++i) { f(row(target_, i), i); } for (Index i = 0; i < target_.rows(); ++i) f(row(target_, i), i);
} }
}; };
@ -85,82 +80,76 @@ namespace rotgen
using concrete_type = typename std::remove_cvref_t<Ref>::concrete_type; using concrete_type = typename std::remove_cvref_t<Ref>::concrete_type;
Ref& target_; Ref& target_;
concrete_type _sum() const concrete_type sum() const
{ {
concrete_type res(1, cols(target_)); concrete_type res(1, target_.cols());
apply([&](auto r, auto i) { res(i) = rotgen::sum(r); }); apply([&](auto r, auto i) { res(i) = r.sum(); });
return res; return res;
} }
concrete_type _mean() const concrete_type mean() const
{ {
concrete_type res(1, cols(target_)); concrete_type res(1, target_.cols());
apply([&](auto r, auto i) { res(i) = rotgen::mean(r); }); apply([&](auto r, auto i) { res(i) = r.mean(); });
return res; return res;
} }
concrete_type _prod() const concrete_type prod() const
{ {
concrete_type res(1, cols(target_)); concrete_type res(1, target_.cols());
apply([&](auto r, auto i) { res(i) = rotgen::prod(r); }); apply([&](auto r, auto i) { res(i) = r.prod(); });
return res; return res;
} }
concrete_type _maxCoeff() const concrete_type maxCoeff() const
{ {
concrete_type res(1, cols(target_)); concrete_type res(1, target_.cols());
apply([&](auto r, auto i) { res(i) = rotgen::maxCoeff(r); }); apply([&](auto r, auto i) { res(i) = r.maxCoeff(); });
return res; return res;
} }
concrete_type _minCoeff() const concrete_type minCoeff() const
{ {
concrete_type res(1, cols(target_)); concrete_type res(1, target_.cols());
apply([&](auto r, auto i) { res(i) = rotgen::minCoeff(r); }); apply([&](auto r, auto i) { res(i) = r.minCoeff(); });
return res; return res;
} }
concrete_type _squaredNorm() const concrete_type squaredNorm() const
{ {
concrete_type res(1, cols(target_)); concrete_type res(1, target_.cols());
apply([&](auto r, auto i) { res(i) = rotgen::squaredNorm(r); }); apply([&](auto r, auto i) { res(i) = r.squaredNorm(); });
return res; return res;
} }
concrete_type _norm() const concrete_type norm() const
{ {
concrete_type res(1, cols(target_)); concrete_type res(1, target_.cols());
apply([&](auto r, auto i) { res(i) = rotgen::norm(r); }); apply([&](auto r, auto i) { res(i) = r.norm(); });
return res; return res;
} }
private: private:
template<typename Func> void apply(Func f) template<typename Func> void apply(Func f)
{ {
for (Index i = 0; i < cols(target_); ++i) { f(col(target_, i), i); } for (Index i = 0; i < target_.cols(); ++i) f(col(target_, i), i);
} }
template<typename Func> void apply(Func f) const template<typename Func> void apply(Func f) const
{ {
for (Index i = 0; i < cols(target_); ++i) { f(col(target_, i), i); } for (Index i = 0; i < target_.cols(); ++i) f(col(target_, i), i);
} }
}; };
template<typename T> auto rowwise(T&& t) template<typename T> auto rowwise(T&& t)
{ {
if constexpr (use_expression_templates) { return t.base().rowwise(); } if constexpr (use_expression_templates) return t.base().rowwise();
else else return rowwise_adaptor<T>{t};
{
return rowwise_adaptor<T>{t};
}
} }
template<typename T> auto colwise(T&& t) template<typename T> auto colwise(T&& t)
{ {
if constexpr (use_expression_templates) { return t.base().colwise(); } if constexpr (use_expression_templates) return t.base().colwise();
else else return colwise_adaptor<T>{t};
{
return colwise_adaptor<T>{t};
}
} }
} }

View file

@ -10,38 +10,30 @@
#define STORAGE_ORDER Eigen::ColMajor #define STORAGE_ORDER Eigen::ColMajor
#define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _col) #define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _col)
#define CLASSCONSTNAME ROTGEN_MATRIX_NAME(block_const_impl, SIZE, _col)
#define TRANSCLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _row) #define TRANSCLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _row)
#define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _col) #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _col)
#define TRANSNAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _row) #define TRANSNAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _row)
#define MAPNAME ROTGEN_MATRIX_NAME(BASEMAP, SIZE, _col) #define MAPNAME ROTGEN_MATRIX_NAME(BASEMAP, SIZE, _col)
#define TRANSMAPNAME ROTGEN_MATRIX_NAME(BASEMAP, SIZE, _row)
#include "model.cpp" #include "model.cpp"
#undef CLASSNAME #undef CLASSNAME
#undef CLASSCONSTNAME
#undef TRANSNAME #undef TRANSNAME
#undef TRANSCLASSNAME #undef TRANSCLASSNAME
#undef SOURCENAME #undef SOURCENAME
#undef MAPNAME #undef MAPNAME
#undef TRANSMAPNAME
#undef STORAGE_ORDER #undef STORAGE_ORDER
#define STORAGE_ORDER Eigen::RowMajor #define STORAGE_ORDER Eigen::RowMajor
#define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _row) #define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _row)
#define CLASSCONSTNAME ROTGEN_MATRIX_NAME(block_const_impl, SIZE, _row)
#define TRANSCLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _col) #define TRANSCLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _col)
#define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _row) #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _row)
#define TRANSNAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _col) #define TRANSNAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _col)
#define MAPNAME ROTGEN_MATRIX_NAME(BASEMAP, SIZE, _row) #define MAPNAME ROTGEN_MATRIX_NAME(BASEMAP, SIZE, _row)
#define TRANSMAPNAME ROTGEN_MATRIX_NAME(BASEMAP, SIZE, _col)
#include "model.cpp" #include "model.cpp"
#undef CLASSNAME #undef CLASSNAME
#undef CLASSCONSTNAME
#undef TRANSNAME #undef TRANSNAME
#undef TRANSCLASSNAME #undef TRANSCLASSNAME
#undef SOURCENAME #undef SOURCENAME
#undef MAPNAME #undef MAPNAME
#undef TRANSMAPNAME
#undef STORAGE_ORDER #undef STORAGE_ORDER
#undef SIZE #undef SIZE
@ -52,38 +44,30 @@
#define STORAGE_ORDER Eigen::ColMajor #define STORAGE_ORDER Eigen::ColMajor
#define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _col) #define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _col)
#define CLASSCONSTNAME ROTGEN_MATRIX_NAME(block_const_impl, SIZE, _col)
#define TRANSCLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _row) #define TRANSCLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _row)
#define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _col) #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _col)
#define TRANSNAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _row) #define TRANSNAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _row)
#define MAPNAME ROTGEN_MATRIX_NAME(BASEMAP, SIZE, _col) #define MAPNAME ROTGEN_MATRIX_NAME(BASEMAP, SIZE, _col)
#define TRANSMAPNAME ROTGEN_MATRIX_NAME(BASEMAP, SIZE, _row)
#include "model.cpp" #include "model.cpp"
#undef CLASSNAME #undef CLASSNAME
#undef CLASSCONSTNAME
#undef TRANSNAME #undef TRANSNAME
#undef TRANSCLASSNAME #undef TRANSCLASSNAME
#undef SOURCENAME #undef SOURCENAME
#undef MAPNAME #undef MAPNAME
#undef TRANSMAPNAME
#undef STORAGE_ORDER #undef STORAGE_ORDER
#define STORAGE_ORDER Eigen::RowMajor #define STORAGE_ORDER Eigen::RowMajor
#define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _row) #define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _row)
#define CLASSCONSTNAME ROTGEN_MATRIX_NAME(block_const_impl, SIZE, _row)
#define TRANSCLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _col) #define TRANSCLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _col)
#define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _row) #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _row)
#define TRANSNAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _col) #define TRANSNAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _col)
#define MAPNAME ROTGEN_MATRIX_NAME(BASEMAP, SIZE, _row) #define MAPNAME ROTGEN_MATRIX_NAME(BASEMAP, SIZE, _row)
#define TRANSMAPNAME ROTGEN_MATRIX_NAME(BASEMAP, SIZE, _col)
#include "model.cpp" #include "model.cpp"
#undef CLASSNAME #undef CLASSNAME
#undef CLASSCONSTNAME
#undef TRANSNAME #undef TRANSNAME
#undef TRANSCLASSNAME #undef TRANSCLASSNAME
#undef SOURCENAME #undef SOURCENAME
#undef MAPNAME #undef MAPNAME
#undef TRANSMAPNAME
#undef STORAGE_ORDER #undef STORAGE_ORDER
#undef SIZE #undef SIZE

View file

@ -1,20 +1,20 @@
//============================================================================== //==================================================================================================
/* /*
ROTGEN - Runtime Overlay for Eigen ROTGEN - Runtime Overlay for Eigen
Copyright : CODE RECKONS Copyright : CODE RECKONS
SPDX-License-Identifier: BSL-1.0 SPDX-License-Identifier: BSL-1.0
*/ */
//============================================================================== //==================================================================================================
//============================================================================== //==================================================================================================
/* /*
This file is a X-File to generate various block_impl_* definitions variant This file is a X-File to generate various block_impl_* definitions variant
*/ */
//============================================================================== //==================================================================================================
//============================================================================== //==================================================================================================
// Constructors & Special Members // Constructors & Special Members
//============================================================================== //==================================================================================================
CLASSNAME::CLASSNAME( CLASSNAME::CLASSNAME(
SOURCENAME CONST& r, Index i0, Index j0, Index ni, Index nj) SOURCENAME CONST& r, Index i0, Index j0, Index ni, Index nj)
: storage_( : storage_(
@ -33,12 +33,6 @@ CLASSNAME::CLASSNAME(MAPNAME CONST& r, Index i0, Index j0, Index ni, Index nj)
{ {
} }
CLASSNAME::CLASSNAME(
TRANSMAPNAME CONST& r, Index i0, Index j0, Index ni, Index nj)
: storage_(std::make_unique<payload>(r, i0, j0, ni, nj, map_t{}, trans_t{}))
{
}
// We're building a block from a block - So we have to dig around the internals // We're building a block from a block - So we have to dig around the internals
CLASSNAME::CLASSNAME( CLASSNAME::CLASSNAME(
TRANSCLASSNAME CONST& p, Index i0, Index j0, Index ni, Index nj) TRANSCLASSNAME CONST& p, Index i0, Index j0, Index ni, Index nj)
@ -134,9 +128,22 @@ void CLASSNAME::assign(SOURCENAME const& m)
} }
#endif #endif
//============================================================================== //==================================================================================================
// Matrix API // Matrix API
//============================================================================== //==================================================================================================
rotgen::Index CLASSNAME::rows() const
{
rotgen::Index that;
storage_->apply([&](auto const& blk) { that = blk.rows(); });
return that;
}
rotgen::Index CLASSNAME::cols() const
{
rotgen::Index that;
storage_->apply([&](auto const& blk) { that = blk.cols(); });
return that;
}
rotgen::Index CLASSNAME::size() const rotgen::Index CLASSNAME::size() const
{ {
@ -145,40 +152,26 @@ rotgen::Index CLASSNAME::size() const
return that; return that;
} }
rotgen::Index CLASSNAME::_rows() const rotgen::Index CLASSNAME::innerStride() const
{
rotgen::Index that;
storage_->apply([&](auto const& blk) { that = blk.rows(); });
return that;
}
rotgen::Index CLASSNAME::_cols() const
{
rotgen::Index that;
storage_->apply([&](auto const& blk) { that = blk.cols(); });
return that;
}
rotgen::Index CLASSNAME::_innerStride() const
{ {
rotgen::Index that; rotgen::Index that;
storage_->apply([&](auto const& blk) { that = blk.innerStride(); }); storage_->apply([&](auto const& blk) { that = blk.innerStride(); });
return that; return that;
} }
rotgen::Index CLASSNAME::_outerStride() const rotgen::Index CLASSNAME::outerStride() const
{ {
rotgen::Index that; rotgen::Index that;
storage_->apply([&](auto const& blk) { that = blk.outerStride(); }); storage_->apply([&](auto const& blk) { that = blk.outerStride(); });
return that; return that;
} }
rotgen::Index CLASSNAME::_startRow() const rotgen::Index CLASSNAME::startRow() const
{ {
return storage_->rel_i0; return storage_->rel_i0;
} }
rotgen::Index CLASSNAME::_startCol() const rotgen::Index CLASSNAME::startCol() const
{ {
return storage_->rel_j0; return storage_->rel_j0;
} }
@ -204,17 +197,17 @@ TYPE CLASSNAME::operator()(Index i, Index j) const
#if !defined(USE_CONST) #if !defined(USE_CONST)
TYPE& CLASSNAME::operator()(Index index) TYPE& CLASSNAME::operator()(Index index)
{ {
auto r = _rows() == 1 ? 0 : index; TYPE* ptr = nullptr;
auto c = _cols() == 1 ? 0 : index; storage_->apply([&](auto& blk) { ptr = blk.data() + index; });
return (*this)(r, c); return *ptr;
} }
#endif #endif
TYPE CLASSNAME::operator()(Index index) const TYPE CLASSNAME::operator()(Index index) const
{ {
auto r = _rows() == 1 ? 0 : index; TYPE ptr;
auto c = _cols() == 1 ? 0 : index; storage_->apply([&](auto const& blk) { ptr = *(blk.data() + index); });
return (*this)(r, c); return ptr;
} }
// Raw pointer access // Raw pointer access
@ -234,10 +227,10 @@ TYPE const* CLASSNAME::data() const
return ptr; return ptr;
} }
//============================================================================== //==================================================================================================
// Matrix operations // Matrix operations
//============================================================================== //==================================================================================================
SOURCENAME CLASSNAME::_normalized() const SOURCENAME CLASSNAME::normalized() const
{ {
SOURCENAME result; SOURCENAME result;
storage_->apply([&](auto const& blk) { storage_->apply([&](auto const& blk) {
@ -246,7 +239,7 @@ SOURCENAME CLASSNAME::_normalized() const
return result; return result;
} }
SOURCENAME CLASSNAME::_transpose() const SOURCENAME CLASSNAME::transpose() const
{ {
SOURCENAME result; SOURCENAME result;
storage_->apply( storage_->apply(
@ -254,7 +247,7 @@ SOURCENAME CLASSNAME::_transpose() const
return result; return result;
} }
SOURCENAME CLASSNAME::_conjugate() const SOURCENAME CLASSNAME::conjugate() const
{ {
SOURCENAME result; SOURCENAME result;
storage_->apply( storage_->apply(
@ -262,7 +255,7 @@ SOURCENAME CLASSNAME::_conjugate() const
return result; return result;
} }
SOURCENAME CLASSNAME::_adjoint() const SOURCENAME CLASSNAME::adjoint() const
{ {
SOURCENAME result; SOURCENAME result;
storage_->apply( storage_->apply(
@ -270,7 +263,7 @@ SOURCENAME CLASSNAME::_adjoint() const
return result; return result;
} }
SOURCENAME CLASSNAME::_cwiseAbs() const SOURCENAME CLASSNAME::cwiseAbs() const
{ {
SOURCENAME result; SOURCENAME result;
storage_->apply( storage_->apply(
@ -278,7 +271,7 @@ SOURCENAME CLASSNAME::_cwiseAbs() const
return result; return result;
} }
SOURCENAME CLASSNAME::_cwiseAbs2() const SOURCENAME CLASSNAME::cwiseAbs2() const
{ {
SOURCENAME result; SOURCENAME result;
storage_->apply( storage_->apply(
@ -286,7 +279,7 @@ SOURCENAME CLASSNAME::_cwiseAbs2() const
return result; return result;
} }
SOURCENAME CLASSNAME::_cwiseInverse() const SOURCENAME CLASSNAME::cwiseInverse() const
{ {
SOURCENAME result; SOURCENAME result;
storage_->apply([&](auto const& blk) { storage_->apply([&](auto const& blk) {
@ -295,7 +288,7 @@ SOURCENAME CLASSNAME::_cwiseInverse() const
return result; return result;
} }
SOURCENAME CLASSNAME::_cwiseSqrt() const SOURCENAME CLASSNAME::cwiseSqrt() const
{ {
SOURCENAME result; SOURCENAME result;
storage_->apply( storage_->apply(
@ -304,96 +297,96 @@ SOURCENAME CLASSNAME::_cwiseSqrt() const
} }
#if !defined(USE_CONST) #if !defined(USE_CONST)
void CLASSNAME::_normalize() void CLASSNAME::normalize()
{ {
storage_->apply([](auto& blk) { blk.normalize(); }); storage_->apply([](auto& blk) { blk.normalize(); });
} }
void CLASSNAME::_transposeInPlace() void CLASSNAME::transposeInPlace()
{ {
storage_->apply([](auto& blk) { blk.transposeInPlace(); }); storage_->apply([](auto& blk) { blk.transposeInPlace(); });
} }
void CLASSNAME::_adjointInPlace() void CLASSNAME::adjointInPlace()
{ {
storage_->apply([](auto& blk) { blk.adjointInPlace(); }); storage_->apply([](auto& blk) { blk.adjointInPlace(); });
} }
#endif #endif
//============================================================================== //==================================================================================================
// Reductions // Reductions
//============================================================================== //==================================================================================================
TYPE CLASSNAME::_sum() const TYPE CLASSNAME::sum() const
{ {
TYPE val{}; TYPE val{};
storage_->apply([&](auto const& blk) { val = blk.sum(); }); storage_->apply([&](auto const& blk) { val = blk.sum(); });
return val; return val;
} }
TYPE CLASSNAME::_prod() const TYPE CLASSNAME::prod() const
{ {
TYPE val{}; TYPE val{};
storage_->apply([&](auto const& blk) { val = blk.prod(); }); storage_->apply([&](auto const& blk) { val = blk.prod(); });
return val; return val;
} }
TYPE CLASSNAME::_mean() const TYPE CLASSNAME::mean() const
{ {
TYPE val{}; TYPE val{};
storage_->apply([&](auto const& blk) { val = blk.mean(); }); storage_->apply([&](auto const& blk) { val = blk.mean(); });
return val; return val;
} }
TYPE CLASSNAME::_trace() const TYPE CLASSNAME::trace() const
{ {
TYPE val{}; TYPE val{};
storage_->apply([&](auto const& blk) { val = blk.trace(); }); storage_->apply([&](auto const& blk) { val = blk.trace(); });
return val; return val;
} }
TYPE CLASSNAME::_minCoeff() const TYPE CLASSNAME::minCoeff() const
{ {
TYPE val{}; TYPE val{};
storage_->apply([&](auto const& blk) { val = blk.minCoeff(); }); storage_->apply([&](auto const& blk) { val = blk.minCoeff(); });
return val; return val;
} }
TYPE CLASSNAME::_maxCoeff() const TYPE CLASSNAME::maxCoeff() const
{ {
TYPE val{}; TYPE val{};
storage_->apply([&](auto const& blk) { val = blk.maxCoeff(); }); storage_->apply([&](auto const& blk) { val = blk.maxCoeff(); });
return val; return val;
} }
TYPE CLASSNAME::_minCoeff(Index* row, Index* col) const TYPE CLASSNAME::minCoeff(Index* row, Index* col) const
{ {
TYPE val{}; TYPE val{};
storage_->apply([&](auto const& blk) { val = blk.minCoeff(row, col); }); storage_->apply([&](auto const& blk) { val = blk.minCoeff(row, col); });
return val; return val;
} }
TYPE CLASSNAME::_maxCoeff(Index* row, Index* col) const TYPE CLASSNAME::maxCoeff(Index* row, Index* col) const
{ {
TYPE val{}; TYPE val{};
storage_->apply([&](auto const& blk) { val = blk.maxCoeff(row, col); }); storage_->apply([&](auto const& blk) { val = blk.maxCoeff(row, col); });
return val; return val;
} }
TYPE CLASSNAME::_squaredNorm() const TYPE CLASSNAME::squaredNorm() const
{ {
TYPE val{}; TYPE val{};
storage_->apply([&](auto const& blk) { val = blk.squaredNorm(); }); storage_->apply([&](auto const& blk) { val = blk.squaredNorm(); });
return val; return val;
} }
TYPE CLASSNAME::_norm() const TYPE CLASSNAME::norm() const
{ {
TYPE val{}; TYPE val{};
storage_->apply([&](auto const& blk) { val = blk.norm(); }); storage_->apply([&](auto const& blk) { val = blk.norm(); });
return val; return val;
} }
TYPE CLASSNAME::_lpNorm(int p) const TYPE CLASSNAME::lpNorm(int p) const
{ {
TYPE val{}; TYPE val{};
storage_->apply([&](auto const& blk) { storage_->apply([&](auto const& blk) {
@ -404,9 +397,9 @@ TYPE CLASSNAME::_lpNorm(int p) const
return val; return val;
} }
//============================================================================== //==================================================================================================
// Operators // Operators
//============================================================================== //==================================================================================================
ROTGEN_EXPORT std::ostream& operator<<(std::ostream& os, CLASSNAME const& m) ROTGEN_EXPORT std::ostream& operator<<(std::ostream& os, CLASSNAME const& m)
{ {
m.storage_->apply([&](auto const& blk) { os << blk; }); m.storage_->apply([&](auto const& blk) { os << blk; });
@ -455,28 +448,6 @@ CLASSNAME& CLASSNAME::operator+=(CLASSNAME const& rhs)
return *this; return *this;
} }
CLASSNAME& CLASSNAME::operator+=(CLASSCONSTNAME const& rhs)
{
std::visit(
[](auto& lhs_blk, auto const& rhs_blk) { lhs_blk.first += rhs_blk.first; },
storage_->data, rhs.storage()->data);
return *this;
}
CLASSNAME& CLASSNAME::operator+=(SOURCENAME const& rhs)
{
std::visit([&](auto& lhs_blk) { lhs_blk.first += rhs.storage()->data; },
storage_->data);
return *this;
}
CLASSNAME& CLASSNAME::operator+=(TRANSNAME const& rhs)
{
std::visit([&](auto& lhs_blk) { lhs_blk.first += rhs.storage()->data; },
storage_->data);
return *this;
}
CLASSNAME& CLASSNAME::operator-=(CLASSNAME const& rhs) CLASSNAME& CLASSNAME::operator-=(CLASSNAME const& rhs)
{ {
std::visit( std::visit(
@ -485,28 +456,6 @@ CLASSNAME& CLASSNAME::operator-=(CLASSNAME const& rhs)
return *this; return *this;
} }
CLASSNAME& CLASSNAME::operator-=(CLASSCONSTNAME const& rhs)
{
std::visit(
[](auto& lhs_blk, auto const& rhs_blk) { lhs_blk.first -= rhs_blk.first; },
storage_->data, rhs.storage()->data);
return *this;
}
CLASSNAME& CLASSNAME::operator-=(SOURCENAME const& rhs)
{
std::visit([&](auto& lhs_blk) { lhs_blk.first -= rhs.storage()->data; },
storage_->data);
return *this;
}
CLASSNAME& CLASSNAME::operator-=(TRANSNAME const& rhs)
{
std::visit([&](auto& lhs_blk) { lhs_blk.first -= rhs.storage()->data; },
storage_->data);
return *this;
}
CLASSNAME& CLASSNAME::operator*=(CLASSNAME const& rhs) CLASSNAME& CLASSNAME::operator*=(CLASSNAME const& rhs)
{ {
std::visit( std::visit(
@ -515,28 +464,6 @@ CLASSNAME& CLASSNAME::operator*=(CLASSNAME const& rhs)
return *this; return *this;
} }
CLASSNAME& CLASSNAME::operator*=(CLASSCONSTNAME const& rhs)
{
std::visit(
[](auto& lhs_blk, auto const& rhs_blk) { lhs_blk.first *= rhs_blk.first; },
storage_->data, rhs.storage()->data);
return *this;
}
CLASSNAME& CLASSNAME::operator*=(SOURCENAME const& rhs)
{
std::visit([&](auto& lhs_blk) { lhs_blk.first *= rhs.storage()->data; },
storage_->data);
return *this;
}
CLASSNAME& CLASSNAME::operator*=(TRANSNAME const& rhs)
{
std::visit([&](auto& lhs_blk) { lhs_blk.first *= rhs.storage()->data; },
storage_->data);
return *this;
}
CLASSNAME& CLASSNAME::operator*=(TYPE s) CLASSNAME& CLASSNAME::operator*=(TYPE s)
{ {
storage_->apply([&](auto& blk) { blk *= s; }); storage_->apply([&](auto& blk) { blk *= s; });
@ -550,7 +477,7 @@ CLASSNAME& CLASSNAME::operator/=(TYPE s)
} }
#endif #endif
SOURCENAME CLASSNAME::_add(CLASSNAME const& rhs) const SOURCENAME CLASSNAME::add(CLASSNAME const& rhs) const
{ {
SOURCENAME result; SOURCENAME result;
std::visit( std::visit(
@ -561,7 +488,7 @@ SOURCENAME CLASSNAME::_add(CLASSNAME const& rhs) const
return result; return result;
} }
SOURCENAME CLASSNAME::_sub(CLASSNAME const& rhs) const SOURCENAME CLASSNAME::sub(CLASSNAME const& rhs) const
{ {
SOURCENAME result; SOURCENAME result;
std::visit( std::visit(
@ -572,7 +499,7 @@ SOURCENAME CLASSNAME::_sub(CLASSNAME const& rhs) const
return result; return result;
} }
SOURCENAME CLASSNAME::_mul(CLASSNAME const& rhs) const SOURCENAME CLASSNAME::mul(CLASSNAME const& rhs) const
{ {
SOURCENAME result; SOURCENAME result;
std::visit( std::visit(
@ -583,7 +510,7 @@ SOURCENAME CLASSNAME::_mul(CLASSNAME const& rhs) const
return result; return result;
} }
SOURCENAME CLASSNAME::_mul(TYPE s) const SOURCENAME CLASSNAME::mul(TYPE s) const
{ {
SOURCENAME result; SOURCENAME result;
std::visit( std::visit(
@ -594,7 +521,7 @@ SOURCENAME CLASSNAME::_mul(TYPE s) const
return result; return result;
} }
SOURCENAME CLASSNAME::_div(TYPE s) const SOURCENAME CLASSNAME::div(TYPE s) const
{ {
SOURCENAME result; SOURCENAME result;
std::visit( std::visit(

View file

@ -11,41 +11,29 @@
#define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _col) #define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _col)
#define TRANSCLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _row) #define TRANSCLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _row)
#define TRANSCLASSCONSTNAME ROTGEN_MATRIX_NAME(map_const_impl, SIZE, _row)
#define TRANSCLASSNONCONSTNAME ROTGEN_MATRIX_NAME(map_impl, SIZE, _row)
#define TRANSSOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _row) #define TRANSSOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _row)
#define CLASSCONSTNAME ROTGEN_MATRIX_NAME(map_const_impl, SIZE, _col) #define CLASSCONSTNAME ROTGEN_MATRIX_NAME(map_const_impl, SIZE, _col)
#define CLASSNONCONSTNAME ROTGEN_MATRIX_NAME(map_impl, SIZE, _col)
#define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _col) #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _col)
#include "model.cpp" #include "model.cpp"
#undef CLASSNAME #undef CLASSNAME
#undef TRANSCLASSNAME #undef TRANSCLASSNAME
#undef TRANSCLASSCONSTNAME
#undef TRANSCLASSNONCONSTNAME
#undef TRANSSOURCENAME #undef TRANSSOURCENAME
#undef CLASSCONSTNAME #undef CLASSCONSTNAME
#undef CLASSNONCONSTNAME
#undef SOURCENAME #undef SOURCENAME
#undef STORAGE_ORDER #undef STORAGE_ORDER
#define STORAGE_ORDER Eigen::RowMajor #define STORAGE_ORDER Eigen::RowMajor
#define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _row) #define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _row)
#define TRANSCLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _col) #define TRANSCLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _col)
#define TRANSCLASSCONSTNAME ROTGEN_MATRIX_NAME(map_const_impl, SIZE, _col)
#define TRANSCLASSNONCONSTNAME ROTGEN_MATRIX_NAME(map_impl, SIZE, _col)
#define TRANSSOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _col) #define TRANSSOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _col)
#define CLASSCONSTNAME ROTGEN_MATRIX_NAME(map_const_impl, SIZE, _row) #define CLASSCONSTNAME ROTGEN_MATRIX_NAME(map_const_impl, SIZE, _row)
#define CLASSNONCONSTNAME ROTGEN_MATRIX_NAME(map_impl, SIZE, _row)
#define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _row) #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _row)
#include "model.cpp" #include "model.cpp"
#undef CLASSNAME #undef CLASSNAME
#undef TRANSCLASSNAME #undef TRANSCLASSNAME
#undef TRANSCLASSCONSTNAME
#undef TRANSCLASSNONCONSTNAME
#undef TRANSSOURCENAME #undef TRANSSOURCENAME
#undef SOURCENAME #undef SOURCENAME
#undef CLASSCONSTNAME #undef CLASSCONSTNAME
#undef CLASSNONCONSTNAME
#undef STORAGE_ORDER #undef STORAGE_ORDER
#undef SIZE #undef SIZE
@ -57,40 +45,28 @@
#define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _col) #define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _col)
#define TRANSCLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _row) #define TRANSCLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _row)
#define TRANSCLASSCONSTNAME ROTGEN_MATRIX_NAME(map_const_impl, SIZE, _row)
#define TRANSCLASSNONCONSTNAME ROTGEN_MATRIX_NAME(map_impl, SIZE, _row)
#define TRANSSOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _row) #define TRANSSOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _row)
#define CLASSCONSTNAME ROTGEN_MATRIX_NAME(map_const_impl, SIZE, _col) #define CLASSCONSTNAME ROTGEN_MATRIX_NAME(map_const_impl, SIZE, _col)
#define CLASSNONCONSTNAME ROTGEN_MATRIX_NAME(map_impl, SIZE, _col)
#define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _col) #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _col)
#include "model.cpp" #include "model.cpp"
#undef CLASSNAME #undef CLASSNAME
#undef TRANSCLASSNAME #undef TRANSCLASSNAME
#undef TRANSCLASSCONSTNAME
#undef TRANSCLASSNONCONSTNAME
#undef TRANSSOURCENAME #undef TRANSSOURCENAME
#undef CLASSCONSTNAME #undef CLASSCONSTNAME
#undef CLASSNONCONSTNAME
#undef SOURCENAME #undef SOURCENAME
#undef STORAGE_ORDER #undef STORAGE_ORDER
#define STORAGE_ORDER Eigen::RowMajor #define STORAGE_ORDER Eigen::RowMajor
#define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _row) #define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _row)
#define TRANSCLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _col) #define TRANSCLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _col)
#define TRANSCLASSCONSTNAME ROTGEN_MATRIX_NAME(map_const_impl, SIZE, _col)
#define TRANSCLASSNONCONSTNAME ROTGEN_MATRIX_NAME(map_impl, SIZE, _col)
#define TRANSSOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _col) #define TRANSSOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _col)
#define CLASSCONSTNAME ROTGEN_MATRIX_NAME(map_const_impl, SIZE, _row) #define CLASSCONSTNAME ROTGEN_MATRIX_NAME(map_const_impl, SIZE, _row)
#define CLASSNONCONSTNAME ROTGEN_MATRIX_NAME(map_impl, SIZE, _row)
#define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _row) #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _row)
#include "model.cpp" #include "model.cpp"
#undef CLASSNAME #undef CLASSNAME
#undef TRANSCLASSNAME #undef TRANSCLASSNAME
#undef TRANSCLASSCONSTNAME
#undef TRANSCLASSNONCONSTNAME
#undef TRANSSOURCENAME #undef TRANSSOURCENAME
#undef CLASSCONSTNAME #undef CLASSCONSTNAME
#undef CLASSNONCONSTNAME
#undef SOURCENAME #undef SOURCENAME
#undef STORAGE_ORDER #undef STORAGE_ORDER

View file

@ -58,12 +58,12 @@ CLASSNAME::~CLASSNAME() = default;
//================================================================================================== //==================================================================================================
// Matrix API // Matrix API
//================================================================================================== //==================================================================================================
rotgen::Index CLASSNAME::_rows() const rotgen::Index CLASSNAME::rows() const
{ {
return storage_->data.rows(); return storage_->data.rows();
} }
rotgen::Index CLASSNAME::_cols() const rotgen::Index CLASSNAME::cols() const
{ {
return storage_->data.cols(); return storage_->data.cols();
} }
@ -73,12 +73,12 @@ rotgen::Index CLASSNAME::size() const
return storage_->data.size(); return storage_->data.size();
} }
rotgen::Index CLASSNAME::_innerStride() const rotgen::Index CLASSNAME::innerStride() const
{ {
return storage_->data.innerStride(); return storage_->data.innerStride();
} }
rotgen::Index CLASSNAME::_outerStride() const rotgen::Index CLASSNAME::outerStride() const
{ {
return storage_->data.outerStride(); return storage_->data.outerStride();
} }
@ -115,77 +115,77 @@ TYPE CLASSNAME::operator()(Index i) const
return storage_->data.data()[i]; return storage_->data.data()[i];
} }
SOURCENAME CLASSNAME::_normalized() const SOURCENAME CLASSNAME::normalized() const
{ {
SOURCENAME result; SOURCENAME result;
result.storage()->assign(storage_->data.normalized().eval()); result.storage()->assign(storage_->data.normalized().eval());
return result; return result;
} }
SOURCENAME CLASSNAME::_transpose() const SOURCENAME CLASSNAME::transpose() const
{ {
SOURCENAME result; SOURCENAME result;
result.storage()->assign(storage_->data.transpose().eval()); result.storage()->assign(storage_->data.transpose().eval());
return result; return result;
} }
SOURCENAME CLASSNAME::_conjugate() const SOURCENAME CLASSNAME::conjugate() const
{ {
SOURCENAME result; SOURCENAME result;
result.storage()->assign(storage_->data.conjugate().eval()); result.storage()->assign(storage_->data.conjugate().eval());
return result; return result;
} }
SOURCENAME CLASSNAME::_adjoint() const SOURCENAME CLASSNAME::adjoint() const
{ {
SOURCENAME result; SOURCENAME result;
result.storage()->assign(storage_->data.adjoint().eval()); result.storage()->assign(storage_->data.adjoint().eval());
return result; return result;
} }
SOURCENAME CLASSNAME::_cwiseAbs() const SOURCENAME CLASSNAME::cwiseAbs() const
{ {
SOURCENAME result; SOURCENAME result;
result.storage()->assign(storage_->data.cwiseAbs().eval()); result.storage()->assign(storage_->data.cwiseAbs().eval());
return result; return result;
} }
SOURCENAME CLASSNAME::_cwiseAbs2() const SOURCENAME CLASSNAME::cwiseAbs2() const
{ {
SOURCENAME result; SOURCENAME result;
result.storage()->assign(storage_->data.cwiseAbs2().eval()); result.storage()->assign(storage_->data.cwiseAbs2().eval());
return result; return result;
} }
SOURCENAME CLASSNAME::_cwiseInverse() const SOURCENAME CLASSNAME::cwiseInverse() const
{ {
SOURCENAME result; SOURCENAME result;
result.storage()->assign(storage_->data.cwiseInverse().eval()); result.storage()->assign(storage_->data.cwiseInverse().eval());
return result; return result;
} }
SOURCENAME CLASSNAME::_cwiseSqrt() const SOURCENAME CLASSNAME::cwiseSqrt() const
{ {
SOURCENAME result; SOURCENAME result;
result.storage()->assign(storage_->data.cwiseSqrt().eval()); result.storage()->assign(storage_->data.cwiseSqrt().eval());
return result; return result;
} }
SOURCENAME CLASSNAME::_cwiseMin(CLASSNAME const& rhs) const SOURCENAME CLASSNAME::cwiseMin(CLASSNAME const& rhs) const
{ {
SOURCENAME result; SOURCENAME result;
result.storage()->assign(storage_->data.cwiseMin(rhs.storage()->data).eval()); result.storage()->assign(storage_->data.cwiseMin(rhs.storage()->data).eval());
return result; return result;
} }
SOURCENAME CLASSNAME::_cwiseMax(CLASSNAME const& rhs) const SOURCENAME CLASSNAME::cwiseMax(CLASSNAME const& rhs) const
{ {
SOURCENAME result; SOURCENAME result;
result.storage()->assign(storage_->data.cwiseMax(rhs.storage()->data).eval()); result.storage()->assign(storage_->data.cwiseMax(rhs.storage()->data).eval());
return result; return result;
} }
SOURCENAME CLASSNAME::_cwiseProduct(CLASSNAME const& rhs) const SOURCENAME CLASSNAME::cwiseProduct(CLASSNAME const& rhs) const
{ {
SOURCENAME result; SOURCENAME result;
result.storage()->assign( result.storage()->assign(
@ -193,7 +193,7 @@ SOURCENAME CLASSNAME::_cwiseProduct(CLASSNAME const& rhs) const
return result; return result;
} }
SOURCENAME CLASSNAME::_cwiseQuotient(CLASSNAME const& rhs) const SOURCENAME CLASSNAME::cwiseQuotient(CLASSNAME const& rhs) const
{ {
SOURCENAME result; SOURCENAME result;
result.storage()->assign( result.storage()->assign(
@ -201,21 +201,21 @@ SOURCENAME CLASSNAME::_cwiseQuotient(CLASSNAME const& rhs) const
return result; return result;
} }
SOURCENAME CLASSNAME::_cwiseMin(TYPE rhs) const SOURCENAME CLASSNAME::cwiseMin(TYPE rhs) const
{ {
SOURCENAME result; SOURCENAME result;
result.storage()->assign(storage_->data.cwiseMin(rhs).eval()); result.storage()->assign(storage_->data.cwiseMin(rhs).eval());
return result; return result;
} }
SOURCENAME CLASSNAME::_cwiseMax(TYPE rhs) const SOURCENAME CLASSNAME::cwiseMax(TYPE rhs) const
{ {
SOURCENAME result; SOURCENAME result;
result.storage()->assign(storage_->data.cwiseMax(rhs).eval()); result.storage()->assign(storage_->data.cwiseMax(rhs).eval());
return result; return result;
} }
SOURCENAME CLASSNAME::_inverse() const SOURCENAME CLASSNAME::inverse() const
{ {
SOURCENAME result; SOURCENAME result;
result.storage()->assign(storage_->data.inverse().eval()); result.storage()->assign(storage_->data.inverse().eval());
@ -223,93 +223,83 @@ SOURCENAME CLASSNAME::_inverse() const
} }
#if !defined(USE_CONST) #if !defined(USE_CONST)
void CLASSNAME::_normalize() void CLASSNAME::normalize()
{ {
storage_->data.normalize(); storage_->data.normalize();
} }
void CLASSNAME::_transposeInPlace() void CLASSNAME::transposeInPlace()
{ {
storage_->data.transposeInPlace(); storage_->data.transposeInPlace();
} }
void CLASSNAME::_adjointInPlace() void CLASSNAME::adjointInPlace()
{ {
storage_->data.adjointInPlace(); storage_->data.adjointInPlace();
} }
#endif #endif
TYPE CLASSNAME::_dot(CLASSNONCONSTNAME const& rhs) const TYPE CLASSNAME::dot(CLASSNAME const& rhs) const
{ {
return storage_->data.reshaped().dot(rhs.storage()->data.reshaped()); return storage_->data.reshaped().dot(rhs.storage()->data.reshaped());
} }
TYPE CLASSNAME::_dot(CLASSCONSTNAME const& rhs) const TYPE CLASSNAME::dot(TRANSCLASSNAME const& rhs) const
{ {
return storage_->data.reshaped().dot(rhs.storage()->data.reshaped()); return storage_->data.reshaped().dot(rhs.storage()->data.reshaped());
} }
TYPE CLASSNAME::_dot(TRANSCLASSNONCONSTNAME const& rhs) const TYPE CLASSNAME::sum() const
{
return storage_->data.reshaped().dot(rhs.storage()->data.reshaped());
}
TYPE CLASSNAME::_dot(TRANSCLASSCONSTNAME const& rhs) const
{
return storage_->data.reshaped().dot(rhs.storage()->data.reshaped());
}
TYPE CLASSNAME::_sum() const
{ {
return storage_->data.sum(); return storage_->data.sum();
} }
TYPE CLASSNAME::_prod() const TYPE CLASSNAME::prod() const
{ {
return storage_->data.prod(); return storage_->data.prod();
} }
TYPE CLASSNAME::_mean() const TYPE CLASSNAME::mean() const
{ {
return storage_->data.mean(); return storage_->data.mean();
} }
TYPE CLASSNAME::_trace() const TYPE CLASSNAME::trace() const
{ {
return storage_->data.trace(); return storage_->data.trace();
} }
TYPE CLASSNAME::_minCoeff() const TYPE CLASSNAME::minCoeff() const
{ {
return storage_->data.minCoeff(); return storage_->data.minCoeff();
} }
TYPE CLASSNAME::_maxCoeff() const TYPE CLASSNAME::maxCoeff() const
{ {
return storage_->data.maxCoeff(); return storage_->data.maxCoeff();
} }
TYPE CLASSNAME::_minCoeff(Index* row, Index* col) const TYPE CLASSNAME::minCoeff(Index* row, Index* col) const
{ {
return storage_->data.minCoeff(row, col); return storage_->data.minCoeff(row, col);
} }
TYPE CLASSNAME::_maxCoeff(Index* row, Index* col) const TYPE CLASSNAME::maxCoeff(Index* row, Index* col) const
{ {
return storage_->data.maxCoeff(row, col); return storage_->data.maxCoeff(row, col);
} }
TYPE CLASSNAME::_squaredNorm() const TYPE CLASSNAME::squaredNorm() const
{ {
return storage_->data.squaredNorm(); return storage_->data.squaredNorm();
} }
TYPE CLASSNAME::_norm() const TYPE CLASSNAME::norm() const
{ {
return storage_->data.norm(); return storage_->data.norm();
} }
TYPE CLASSNAME::_lpNorm(int p) const TYPE CLASSNAME::lpNorm(int p) const
{ {
if (p == 1) return storage_->data.lpNorm<1>(); if (p == 1) return storage_->data.lpNorm<1>();
else if (p == 2) return storage_->data.lpNorm<2>(); else if (p == 2) return storage_->data.lpNorm<2>();
@ -317,27 +307,27 @@ TYPE CLASSNAME::_lpNorm(int p) const
} }
#if !defined(USE_CONST) #if !defined(USE_CONST)
void CLASSNAME::_setZero() void CLASSNAME::setZero()
{ {
storage_->data.setZero(); storage_->data.setZero();
} }
void CLASSNAME::_setOnes() void CLASSNAME::setOnes()
{ {
storage_->data.setOnes(); storage_->data.setOnes();
} }
void CLASSNAME::_setIdentity() void CLASSNAME::setIdentity()
{ {
storage_->data.setIdentity(); storage_->data.setIdentity();
} }
void CLASSNAME::_setRandom() void CLASSNAME::setRandom()
{ {
storage_->data.setRandom(); storage_->data.setRandom();
} }
void CLASSNAME::_setConstant(TYPE s) void CLASSNAME::setConstant(TYPE s)
{ {
storage_->data.setConstant(s); storage_->data.setConstant(s);
} }
@ -388,7 +378,7 @@ SOURCENAME CLASSNAME::operator-() const
#if !defined(USE_CONST) #if !defined(USE_CONST)
CLASSNAME& CLASSNAME::operator+=(CLASSNAME const& rhs) CLASSNAME& CLASSNAME::operator+=(CLASSNAME const& rhs)
{ {
storage_->data += rhs.storage()->data; storage_->data += rhs.storage_->data;
return *this; return *this;
} }
@ -398,21 +388,9 @@ CLASSNAME& CLASSNAME::operator+=(CLASSCONSTNAME const& rhs)
return *this; return *this;
} }
CLASSNAME& CLASSNAME::operator+=(TRANSCLASSNONCONSTNAME const& rhs)
{
storage_->data.reshaped() += rhs.storage()->data.reshaped();
return *this;
}
CLASSNAME& CLASSNAME::operator+=(TRANSCLASSCONSTNAME const& rhs)
{
storage_->data.reshaped() += rhs.storage()->data.reshaped();
return *this;
}
CLASSNAME& CLASSNAME::operator-=(CLASSNAME const& rhs) CLASSNAME& CLASSNAME::operator-=(CLASSNAME const& rhs)
{ {
storage_->data -= rhs.storage()->data; storage_->data -= rhs.storage_->data;
return *this; return *this;
} }
@ -422,21 +400,9 @@ CLASSNAME& CLASSNAME::operator-=(CLASSCONSTNAME const& rhs)
return *this; return *this;
} }
CLASSNAME& CLASSNAME::operator-=(TRANSCLASSNONCONSTNAME const& rhs)
{
storage_->data.reshaped() -= rhs.storage()->data.reshaped();
return *this;
}
CLASSNAME& CLASSNAME::operator-=(TRANSCLASSCONSTNAME const& rhs)
{
storage_->data.reshaped() -= rhs.storage()->data.reshaped();
return *this;
}
CLASSNAME& CLASSNAME::operator*=(CLASSNAME const& rhs) CLASSNAME& CLASSNAME::operator*=(CLASSNAME const& rhs)
{ {
storage_->data *= rhs.storage()->data; storage_->data *= rhs.storage_->data;
return *this; return *this;
} }
@ -446,18 +412,6 @@ CLASSNAME& CLASSNAME::operator*=(CLASSCONSTNAME const& rhs)
return *this; return *this;
} }
CLASSNAME& CLASSNAME::operator*=(TRANSCLASSNONCONSTNAME const& rhs)
{
storage_->data *= rhs.storage()->data;
return *this;
}
CLASSNAME& CLASSNAME::operator*=(TRANSCLASSCONSTNAME const& rhs)
{
storage_->data *= rhs.storage()->data;
return *this;
}
CLASSNAME& CLASSNAME::operator*=(TYPE s) CLASSNAME& CLASSNAME::operator*=(TYPE s)
{ {
storage_->data *= s; storage_->data *= s;
@ -471,56 +425,56 @@ CLASSNAME& CLASSNAME::operator/=(TYPE s)
} }
#endif #endif
SOURCENAME CLASSNAME::_add(CLASSNAME const& rhs) const SOURCENAME CLASSNAME::add(CLASSNAME const& rhs) const
{ {
SOURCENAME result; SOURCENAME result;
result.storage()->assign(storage_->data + rhs.storage_->data); result.storage()->assign(storage_->data + rhs.storage_->data);
return result; return result;
} }
SOURCENAME CLASSNAME::_add(TRANSCLASSNAME const& rhs) const SOURCENAME CLASSNAME::add(TRANSCLASSNAME const& rhs) const
{ {
SOURCENAME result; SOURCENAME result;
result.storage()->assign(storage_->data + rhs.storage()->data); result.storage()->assign(storage_->data + rhs.storage()->data);
return result; return result;
} }
SOURCENAME CLASSNAME::_sub(CLASSNAME const& rhs) const SOURCENAME CLASSNAME::sub(CLASSNAME const& rhs) const
{ {
SOURCENAME result; SOURCENAME result;
result.storage()->assign(storage_->data - rhs.storage_->data); result.storage()->assign(storage_->data - rhs.storage_->data);
return result; return result;
} }
SOURCENAME CLASSNAME::_sub(TRANSCLASSNAME const& rhs) const SOURCENAME CLASSNAME::sub(TRANSCLASSNAME const& rhs) const
{ {
SOURCENAME result; SOURCENAME result;
result.storage()->assign(storage_->data - rhs.storage()->data); result.storage()->assign(storage_->data - rhs.storage()->data);
return result; return result;
} }
SOURCENAME CLASSNAME::_mul(CLASSNAME const& rhs) const SOURCENAME CLASSNAME::mul(CLASSNAME const& rhs) const
{ {
SOURCENAME result; SOURCENAME result;
result.storage()->assign(storage_->data * rhs.storage_->data); result.storage()->assign(storage_->data * rhs.storage_->data);
return result; return result;
} }
SOURCENAME CLASSNAME::_mul(TRANSCLASSNAME const& rhs) const SOURCENAME CLASSNAME::mul(TRANSCLASSNAME const& rhs) const
{ {
SOURCENAME result; SOURCENAME result;
result.storage()->assign(storage_->data * rhs.storage()->data); result.storage()->assign(storage_->data * rhs.storage()->data);
return result; return result;
} }
SOURCENAME CLASSNAME::_mul(TYPE s) const SOURCENAME CLASSNAME::mul(TYPE s) const
{ {
SOURCENAME result; SOURCENAME result;
result.storage()->assign(storage_->data * s); result.storage()->assign(storage_->data * s);
return result; return result;
} }
SOURCENAME CLASSNAME::_div(TYPE s) const SOURCENAME CLASSNAME::div(TYPE s) const
{ {
SOURCENAME result; SOURCENAME result;
result.storage()->assign(storage_->data / s); result.storage()->assign(storage_->data / s);

View file

@ -34,7 +34,7 @@ CLASSNAME::CLASSNAME(Index r, Index c, std::initializer_list<TYPE> init)
for (std::size_t i = 0; i < init.size(); i++) (*this)(i) = first[i]; for (std::size_t i = 0; i < init.size(); i++) (*this)(i) = first[i];
} }
CLASSNAME::CLASSNAME(CLASSNAME const& o) : CLASSNAME(o._rows(), o._cols()) CLASSNAME::CLASSNAME(CLASSNAME const& o) : CLASSNAME(o.rows(), o.cols())
{ {
storage_->data = o.storage_->data; storage_->data = o.storage_->data;
} }
@ -54,27 +54,27 @@ CLASSNAME::~CLASSNAME() = default;
//================================================================================================== //==================================================================================================
// Matrix API // Matrix API
//================================================================================================== //==================================================================================================
rotgen::Index CLASSNAME::size() const rotgen::Index CLASSNAME::rows() const
{
return storage_->data.size();
}
rotgen::Index CLASSNAME::_rows() const
{ {
return storage_->data.rows(); return storage_->data.rows();
} }
rotgen::Index CLASSNAME::_cols() const rotgen::Index CLASSNAME::cols() const
{ {
return storage_->data.cols(); return storage_->data.cols();
} }
rotgen::Index CLASSNAME::size() const
{
return storage_->data.size();
}
void CLASSNAME::resize(Index new_rows, Index new_cols) void CLASSNAME::resize(Index new_rows, Index new_cols)
{ {
storage_->data.resize(new_rows, new_cols); storage_->data.resize(new_rows, new_cols);
} }
void CLASSNAME::_conservativeResize(Index new_rows, Index new_cols) void CLASSNAME::conservativeResize(Index new_rows, Index new_cols)
{ {
storage_->data.conservativeResize(new_rows, new_cols); storage_->data.conservativeResize(new_rows, new_cols);
} }
@ -109,128 +109,128 @@ TYPE* CLASSNAME::data()
return storage_->data.data(); return storage_->data.data();
} }
CLASSNAME CLASSNAME::_normalized() const CLASSNAME CLASSNAME::normalized() const
{ {
CLASSNAME result(*this); CLASSNAME result(*this);
result.storage_->data.normalize(); result.storage_->data.normalize();
return result; return result;
} }
CLASSNAME CLASSNAME::_transpose() const CLASSNAME CLASSNAME::transpose() const
{ {
CLASSNAME result; CLASSNAME result;
result.storage()->data = storage_->data.transpose(); result.storage()->data = storage_->data.transpose();
return result; return result;
} }
CLASSNAME CLASSNAME::_conjugate() const CLASSNAME CLASSNAME::conjugate() const
{ {
CLASSNAME result(*this); CLASSNAME result(*this);
result.storage_->data = storage_->data.conjugate(); result.storage_->data = storage_->data.conjugate();
return result; return result;
} }
CLASSNAME CLASSNAME::_adjoint() const CLASSNAME CLASSNAME::adjoint() const
{ {
CLASSNAME result; CLASSNAME result;
result.storage()->data = storage_->data.adjoint(); result.storage()->data = storage_->data.adjoint();
return result; return result;
} }
void CLASSNAME::_normalize() void CLASSNAME::normalize()
{ {
storage_->data.normalize(); storage_->data.normalize();
} }
void CLASSNAME::_transposeInPlace() void CLASSNAME::transposeInPlace()
{ {
storage_->data.transposeInPlace(); storage_->data.transposeInPlace();
} }
void CLASSNAME::_adjointInPlace() void CLASSNAME::adjointInPlace()
{ {
storage_->data.adjointInPlace(); storage_->data.adjointInPlace();
} }
CLASSNAME CLASSNAME::_cwiseAbs() const CLASSNAME CLASSNAME::cwiseAbs() const
{ {
CLASSNAME result(*this); CLASSNAME result(*this);
result.storage_->data = storage_->data.cwiseAbs(); result.storage_->data = storage_->data.cwiseAbs();
return result; return result;
} }
CLASSNAME CLASSNAME::_cwiseAbs2() const CLASSNAME CLASSNAME::cwiseAbs2() const
{ {
CLASSNAME result(*this); CLASSNAME result(*this);
result.storage_->data = storage_->data.cwiseAbs2(); result.storage_->data = storage_->data.cwiseAbs2();
return result; return result;
} }
CLASSNAME CLASSNAME::_cwiseInverse() const CLASSNAME CLASSNAME::cwiseInverse() const
{ {
CLASSNAME result(*this); CLASSNAME result(*this);
result.storage_->data = storage_->data.cwiseInverse(); result.storage_->data = storage_->data.cwiseInverse();
return result; return result;
} }
CLASSNAME CLASSNAME::_cwiseSqrt() const CLASSNAME CLASSNAME::cwiseSqrt() const
{ {
CLASSNAME result(*this); CLASSNAME result(*this);
result.storage_->data = storage_->data.cwiseSqrt(); result.storage_->data = storage_->data.cwiseSqrt();
return result; return result;
} }
TYPE CLASSNAME::_sum() const TYPE CLASSNAME::sum() const
{ {
return storage_->data.sum(); return storage_->data.sum();
} }
TYPE CLASSNAME::_prod() const TYPE CLASSNAME::prod() const
{ {
return storage_->data.prod(); return storage_->data.prod();
} }
TYPE CLASSNAME::_mean() const TYPE CLASSNAME::mean() const
{ {
return storage_->data.mean(); return storage_->data.mean();
} }
TYPE CLASSNAME::_trace() const TYPE CLASSNAME::trace() const
{ {
return storage_->data.trace(); return storage_->data.trace();
} }
TYPE CLASSNAME::_minCoeff() const TYPE CLASSNAME::minCoeff() const
{ {
return storage_->data.minCoeff(); return storage_->data.minCoeff();
} }
TYPE CLASSNAME::_maxCoeff() const TYPE CLASSNAME::maxCoeff() const
{ {
return storage_->data.maxCoeff(); return storage_->data.maxCoeff();
} }
TYPE CLASSNAME::_minCoeff(Index* row, Index* col) const TYPE CLASSNAME::minCoeff(Index* row, Index* col) const
{ {
return storage_->data.minCoeff(row, col); return storage_->data.minCoeff(row, col);
} }
TYPE CLASSNAME::_maxCoeff(Index* row, Index* col) const TYPE CLASSNAME::maxCoeff(Index* row, Index* col) const
{ {
return storage_->data.maxCoeff(row, col); return storage_->data.maxCoeff(row, col);
} }
TYPE CLASSNAME::_squaredNorm() const TYPE CLASSNAME::squaredNorm() const
{ {
return storage_->data.squaredNorm(); return storage_->data.squaredNorm();
} }
TYPE CLASSNAME::_norm() const TYPE CLASSNAME::norm() const
{ {
return storage_->data.norm(); return storage_->data.norm();
} }
TYPE CLASSNAME::_lp_norm(int p) const TYPE CLASSNAME::lp_norm(int p) const
{ {
if (p == 1) return storage_->data.lpNorm<1>(); if (p == 1) return storage_->data.lpNorm<1>();
else if (p == 2) return storage_->data.lpNorm<2>(); else if (p == 2) return storage_->data.lpNorm<2>();
@ -301,27 +301,27 @@ CLASSNAME& CLASSNAME::operator/=(TYPE s)
//============================================================================== //==============================================================================
// Generators functions // Generators functions
//============================================================================== //==============================================================================
void CLASSNAME::_setOnes(Index rows, Index cols) void CLASSNAME::setOnes(Index rows, Index cols)
{ {
storage_->assign(payload::data_type::Ones(rows, cols).eval()); storage_->assign(payload::data_type::Ones(rows, cols).eval());
} }
void CLASSNAME::_setZero(Index rows, Index cols) void CLASSNAME::setZero(Index rows, Index cols)
{ {
storage_->assign(payload::data_type::Zero(rows, cols).eval()); storage_->assign(payload::data_type::Zero(rows, cols).eval());
} }
void CLASSNAME::_setConstant(Index rows, Index cols, TYPE value) void CLASSNAME::setConstant(Index rows, Index cols, TYPE value)
{ {
storage_->assign(payload::data_type::Constant(rows, cols, value).eval()); storage_->assign(payload::data_type::Constant(rows, cols, value).eval());
} }
void CLASSNAME::_setRandom(Index rows, Index cols) void CLASSNAME::setRandom(Index rows, Index cols)
{ {
storage_->assign(payload::data_type::Random(rows, cols).eval()); storage_->assign(payload::data_type::Random(rows, cols).eval());
} }
void CLASSNAME::_setIdentity(Index rows, Index cols) void CLASSNAME::setIdentity(Index rows, Index cols)
{ {
storage_->assign(payload::data_type::Identity(rows, cols).eval()); storage_->assign(payload::data_type::Identity(rows, cols).eval());
} }
@ -329,21 +329,21 @@ void CLASSNAME::_setIdentity(Index rows, Index cols)
//============================================================================== //==============================================================================
// Static functions // Static functions
//============================================================================== //==============================================================================
CLASSNAME CLASSNAME::_Ones(Index rows, Index cols) CLASSNAME CLASSNAME::Ones(Index rows, Index cols)
{ {
CLASSNAME m; CLASSNAME m;
m.storage_ = std::make_unique<payload>(payload::data_type::Ones(rows, cols)); m.storage_ = std::make_unique<payload>(payload::data_type::Ones(rows, cols));
return m; return m;
} }
CLASSNAME CLASSNAME::_Zero(Index rows, Index cols) CLASSNAME CLASSNAME::Zero(Index rows, Index cols)
{ {
CLASSNAME m; CLASSNAME m;
m.storage_ = std::make_unique<payload>(payload::data_type::Zero(rows, cols)); m.storage_ = std::make_unique<payload>(payload::data_type::Zero(rows, cols));
return m; return m;
} }
CLASSNAME CLASSNAME::_Constant(Index rows, Index cols, TYPE value) CLASSNAME CLASSNAME::Constant(Index rows, Index cols, TYPE value)
{ {
CLASSNAME m; CLASSNAME m;
m.storage_ = m.storage_ =
@ -351,7 +351,7 @@ CLASSNAME CLASSNAME::_Constant(Index rows, Index cols, TYPE value)
return m; return m;
} }
CLASSNAME CLASSNAME::_Random(Index rows, Index cols) CLASSNAME CLASSNAME::Random(Index rows, Index cols)
{ {
CLASSNAME m; CLASSNAME m;
m.storage_ = m.storage_ =
@ -359,7 +359,7 @@ CLASSNAME CLASSNAME::_Random(Index rows, Index cols)
return m; return m;
} }
CLASSNAME CLASSNAME::_Identity(Index rows, Index cols) CLASSNAME CLASSNAME::Identity(Index rows, Index cols)
{ {
CLASSNAME m; CLASSNAME m;
m.storage_ = m.storage_ =

View file

@ -14,34 +14,34 @@ TTS_CASE_TPL("Chains of extraction", rotgen::tests::types)
<typename T, typename O>(tts::type<tts::types<T, O>>) <typename T, typename O>(tts::type<tts::types<T, O>>)
{ {
constexpr int N = 8; constexpr int N = 8;
auto a = rotgen::setRandom<rotgen::matrix<T, N, N, O::value>>(); auto a = rotgen::matrix<T, N, N, O::value>::Random();
auto b = topLeftCorner(a, 5, 5); auto b = topLeftCorner(a, 5, 5);
TTS_EQUAL(startRow(b), 0); TTS_EQUAL(b.startRow(), 0);
TTS_EQUAL(startCol(b), 0); TTS_EQUAL(b.startCol(), 0);
setConstant(b, -7); setConstant(b, -7);
for (rotgen::Index r = 0; r < 5; r++) for (rotgen::Index r = 0; r < 5; r++)
for (rotgen::Index c = 0; c < 5; c++) TTS_EQUAL(a(r, c), -7); for (rotgen::Index c = 0; c < 5; c++) TTS_EQUAL(a(r, c), -7);
auto bb = bottomRightCorner(b, 3, 3); auto bb = bottomRightCorner(b, 3, 3);
TTS_EQUAL(startRow(bb), 2); TTS_EQUAL(bb.startRow(), 2);
TTS_EQUAL(startCol(bb), 2); TTS_EQUAL(bb.startCol(), 2);
setConstant(bb, 42); setConstant(bb, 42);
for (rotgen::Index r = 2; r < 5; r++) for (rotgen::Index r = 2; r < 5; r++)
for (rotgen::Index c = 2; c < 5; c++) TTS_EQUAL(a(r, c), 42); for (rotgen::Index c = 2; c < 5; c++) TTS_EQUAL(a(r, c), 42);
auto bbb = row(bb, 1); auto bbb = row(bb, 1);
TTS_EQUAL(startRow(bbb), 1); TTS_EQUAL(bbb.startRow(), 1);
TTS_EQUAL(startCol(bbb), 0); TTS_EQUAL(bbb.startCol(), 0);
setConstant(bbb, 99.5); setConstant(bbb, 99.5);
for (rotgen::Index c = 3; c < 5; c++) TTS_EQUAL(a(3, c), 99.5); for (rotgen::Index c = 3; c < 5; c++) TTS_EQUAL(a(3, c), 99.5);
auto bbbb = col(bbb, 1); auto bbbb = col(bbb, 1);
TTS_EQUAL(startRow(bbbb), 0); TTS_EQUAL(bbbb.startRow(), 0);
TTS_EQUAL(startCol(bbbb), 1); TTS_EQUAL(bbbb.startCol(), 1);
setConstant(bbbb, 0.125); setConstant(bbbb, 0.125);
TTS_EQUAL(a(3, 3), 0.125); TTS_EQUAL(a(3, 3), 0.125);
@ -77,39 +77,3 @@ TTS_CASE("Extraction of ref/ref const")
for (rotgen::Index r = 0; r < 4; r++) for (rotgen::Index r = 0; r < 4; r++)
for (rotgen::Index c = 0; c < 3; c++) TTS_EQUAL(sliced(r, c), 5.f); for (rotgen::Index c = 0; c < 3; c++) TTS_EQUAL(sliced(r, c), 5.f);
}; };
void process_col(rotgen::matrix<float, 3, 4>& m,
rotgen::matrix<float, 3, 1> const& n,
int c)
{
col(m, c) += n;
}
TTS_CASE("Compound operators on extractions")
{
rotgen::matrix<float, 3, 4> m;
rotgen::matrix<float, 3, 4> reference;
rotgen::matrix<float, 3, 1> n;
setZero(m);
setConstant(n, 10);
setConstant(reference, 10);
for (int i = 0; i < cols(m); i++) process_col(m, n, i);
TTS_EQUAL(m, reference);
};
TTS_CASE("Compatibility of 1D blocks")
{
rotgen::matrix<float, 4, 2> V;
setConstant(V, 99);
rotgen::matrix<float, 3, 1> C{12, 34, 56};
extract<1, 2>(V, 0, 0) = segment<2>(C, 0);
extract<2, 1>(V, 1, 0) = segment<2>(C, 1);
TTS_EQUAL(V(0, 0), C(0));
TTS_EQUAL(V(0, 1), C(1));
TTS_EQUAL(V(1, 0), C(1));
TTS_EQUAL(V(2, 0), C(2));
};

View file

@ -1,123 +0,0 @@
//==================================================================================================
/*
ROTGEN - Runtime Overlay for Eigen
Copyright : CODE RECKONS
SPDX-License-Identifier: BSL-1.0
*/
//==================================================================================================
#include <rotgen/rotgen.hpp>
#include "unit/tests.hpp"
#include <Eigen/Core>
TTS_CASE_TPL("Initialize a matrix with a list of scalars", rotgen::tests::types)
<typename T, typename O>(tts::type<tts::types<T, O>>)
{
using eigen_t = Eigen::Matrix<T, -1, -1, O::value>;
using rotgen_t = rotgen::matrix<T, -1, -1, O::value>;
eigen_t reference(3, 3);
reference << 1, 2, 3, 4, 5, 6, 7, 8, 9;
rotgen_t values(3, 3);
initialize_with(values, 1, 2, 3, 4, 5, 6, 7, 8, 9);
for (int r = 0; r < 3; r++)
for (int c = 0; c < 3; c++) TTS_EQUAL(values(r, c), reference(r, c));
};
TTS_CASE_TPL("Initialize a sub-matrix with a list of scalars",
rotgen::tests::types)
<typename T, typename O>(tts::type<tts::types<T, O>>)
{
using eigen_t = Eigen::Matrix<T, -1, -1, O::value>;
using rotgen_t = rotgen::matrix<T, -1, -1, O::value>;
eigen_t reference(6, 6);
reference.block(1, 1, 3, 3) << 1, 2, 3, 4, 5, 6, 7, 8, 9;
rotgen_t values(6, 6);
initialize_with(extract(values, 1, 1, 3, 3), 1, 2, 3, 4, 5, 6, 7, 8, 9);
for (int r = 0; r < 3; r++)
for (int c = 0; c < 3; c++)
TTS_EQUAL(values(r + 1, c + 1), reference(r + 1, c + 1));
};
TTS_CASE_TPL("Initialize a map with a list of scalars", rotgen::tests::types)
<typename T, typename O>(tts::type<tts::types<T, O>>)
{
using eigen_t = Eigen::Matrix<T, -1, -1, O::value>;
using rotgen_t = rotgen::matrix<T, -1, -1, O::value>;
T eigen_data[9] = {};
T rotgen_data[9] = {};
Eigen::Map<eigen_t> reference(eigen_data, 3, 3);
reference << 1, 2, 3, 4, 5, 6, 7, 8, 9;
rotgen::map<rotgen_t> values(rotgen_data, 3, 3);
initialize_with(values, 1, 2, 3, 4, 5, 6, 7, 8, 9);
for (int i = 0; i < 9; i++) TTS_EQUAL(eigen_data[i], rotgen_data[i]);
};
TTS_CASE_TPL("Initialize a sub-map with a list of scalars",
rotgen::tests::types)
<typename T, typename O>(tts::type<tts::types<T, O>>)
{
using eigen_t = Eigen::Matrix<T, -1, -1, O::value>;
using rotgen_t = rotgen::matrix<T, -1, -1, O::value>;
T eigen_data[36] = {};
T rotgen_data[36] = {};
Eigen::Map<eigen_t> reference(eigen_data, 6, 6);
reference.block(1, 1, 3, 3) << 1, 2, 3, 4, 5, 6, 7, 8, 9;
rotgen::map<rotgen_t> values(rotgen_data, 6, 6);
initialize_with(extract(values, 1, 1, 3, 3), 1, 2, 3, 4, 5, 6, 7, 8, 9);
for (int i = 0; i < 9; i++) TTS_EQUAL(eigen_data[i], rotgen_data[i]);
};
void process(rotgen::ref<rotgen::matrixXf> r)
{
rotgen::initialize_with(r, 1, 2, 3, 4, 5, 6, 7, 8, 9);
}
void process(rotgen::ref<rotgen::matrixXd> r)
{
rotgen::initialize_with(r, 1, 2, 3, 4, 5, 6, 7, 8, 9);
}
void process(rotgen::ref<rotgen::matrix<float, -1, -1, rotgen::RowMajor>> r)
{
rotgen::initialize_with(r, 1, 2, 3, 4, 5, 6, 7, 8, 9);
}
void process(rotgen::ref<rotgen::matrix<double, -1, -1, rotgen::RowMajor>> r)
{
rotgen::initialize_with(r, 1, 2, 3, 4, 5, 6, 7, 8, 9);
}
TTS_CASE_TPL("Initialize a ref with a list of scalars", rotgen::tests::types)
<typename T, typename O>(tts::type<tts::types<T, O>>)
{
using eigen_t = Eigen::Matrix<T, -1, -1, O::value>;
using rotgen_t = rotgen::matrix<T, -1, -1, O::value>;
eigen_t reference(3, 3);
reference << 1, 2, 3, 4, 5, 6, 7, 8, 9;
rotgen_t values(3, 3);
process(values);
for (int r = 0; r < 3; r++)
for (int c = 0; c < 3; c++) TTS_EQUAL(values(r, c), reference(r, c));
};

View file

@ -10,29 +10,29 @@
#include "unit/tests.hpp" #include "unit/tests.hpp"
#include <iostream> #include <iostream>
TTS_CASE_TPL("outer_stride<0> interactions", rotgen::tests::types) TTS_CASE_TPL("outer_stride<0> interactions",
rotgen::tests::types)<typename T, typename O>(
<typename T, typename O>(tts::type<tts::types<T, O>>) tts::type<tts::types<T, O>>)
{ {
using mat_t = rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value>; using mat_t = rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value>;
T contiguous[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; T contiguous[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
rotgen::map<mat_t, 0, rotgen::outer_stride<0>> m(&contiguous[0], 4, 3); rotgen::map<mat_t, 0, rotgen::outer_stride<0>> m(&contiguous[0], 4, 3);
TTS_EQUAL(innerStride(m), 1); TTS_EQUAL(m.innerStride(), 1);
TTS_EQUAL(outerStride(m), O::value == rotgen::ColMajor ? 4 : 3); TTS_EQUAL(m.outerStride(), O::value == rotgen::ColMajor ? 4 : 3);
if constexpr (O::value == rotgen::ColMajor) if constexpr (O::value == rotgen::ColMajor)
{ {
T padded[] = {1, 2, 3, 4, 99, 5, 6, 7, 8, 99, 9, 10, 11, 12}; T padded[] = {1, 2, 3, 4, 99, 5, 6, 7, 8, 99, 9, 10, 11, 12};
rotgen::map<mat_t, 0, rotgen::outer_stride<5>> sp(&padded[0], 4, 3); rotgen::map<mat_t, 0, rotgen::outer_stride<5>> sp(&padded[0], 4, 3);
TTS_EQUAL(innerStride(sp), 1); TTS_EQUAL(sp.innerStride(), 1);
TTS_EQUAL(outerStride(sp), 5); TTS_EQUAL(sp.outerStride(), 5);
rotgen::map<mat_t, 0, rotgen::outer_stride<>> dp(&padded[0], 4, 3, rotgen::map<mat_t, 0, rotgen::outer_stride<>> dp(&padded[0], 4, 3,
rotgen::outer_stride(5)); rotgen::outer_stride(5));
TTS_EQUAL(innerStride(dp), 1); TTS_EQUAL(dp.innerStride(), 1);
TTS_EQUAL(outerStride(dp), 5); TTS_EQUAL(dp.outerStride(), 5);
TTS_EQUAL(m, sp); TTS_EQUAL(m, sp);
TTS_EQUAL(m, dp); TTS_EQUAL(m, dp);
@ -42,13 +42,13 @@ TTS_CASE_TPL("outer_stride<0> interactions", rotgen::tests::types)
{ {
T padded[] = {1, 2, 3, 99, 4, 5, 6, 99, 7, 8, 9, 99, 10, 11, 12}; T padded[] = {1, 2, 3, 99, 4, 5, 6, 99, 7, 8, 9, 99, 10, 11, 12};
rotgen::map<mat_t, 0, rotgen::outer_stride<4>> sp(&padded[0], 4, 3); rotgen::map<mat_t, 0, rotgen::outer_stride<4>> sp(&padded[0], 4, 3);
TTS_EQUAL(innerStride(sp), 1); TTS_EQUAL(sp.innerStride(), 1);
TTS_EQUAL(outerStride(sp), 4); TTS_EQUAL(sp.outerStride(), 4);
rotgen::map<mat_t, 0, rotgen::outer_stride<>> dp(&padded[0], 4, 3, rotgen::map<mat_t, 0, rotgen::outer_stride<>> dp(&padded[0], 4, 3,
rotgen::outer_stride(4)); rotgen::outer_stride(4));
TTS_EQUAL(innerStride(dp), 1); TTS_EQUAL(dp.innerStride(), 1);
TTS_EQUAL(outerStride(dp), 4); TTS_EQUAL(dp.outerStride(), 4);
TTS_EQUAL(m, sp); TTS_EQUAL(m, sp);
TTS_EQUAL(m, dp); TTS_EQUAL(m, dp);

View file

@ -48,9 +48,9 @@ auto process(column_ref<> v)
TTS_CASE("Reference of reference check") TTS_CASE("Reference of reference check")
{ {
auto v1 = rotgen::setOnes<rotgen::matrix<float, 1, 1>>(); auto v1 = rotgen::matrix<float, 1, 1>::Ones();
auto v2 = rotgen::setRandom<rotgen::matrix<float, 2, 1>>(); auto v2 = rotgen::matrix<float, 2, 1>::Random();
auto v3 = rotgen::setConstant<rotgen::matrix<float, 3, 1>>(6.66); auto v3 = rotgen::matrix<float, 3, 1>::Constant(6.66);
auto sum1 = v1(0); auto sum1 = v1(0);
auto sum2 = v2(0) + v2(1); auto sum2 = v2(0) + v2(1);

View file

@ -1,50 +0,0 @@
//==================================================================================================
/*
ROTGEN - Runtime Overlay for Eigen
Copyright : CODE RECKONS
SPDX-License-Identifier: BSL-1.0
*/
//==================================================================================================
#include <rotgen/rotgen.hpp>
#include "unit/tests.hpp"
bool categorize_as_scalar(double)
{
return true;
}
bool categorize_as_scalar(rotgen::ref<rotgen::matrix<double, 1, 1>>)
{
return false;
}
TTS_CASE("Matrix product of 1xN by Nx1 yields a scalar-convertible object")
{
rotgen::matrix<double, 1, 2> a = {1, 2};
rotgen::matrix<double, 2, 1> b = {10, 20};
double n = a * b;
TTS_EQUAL(n, 50);
TTS_EXPECT(categorize_as_scalar(a * b));
};
TTS_CASE_TPL("Static 1x1 matrix-like objects can be assigned as-if",
rotgen::tests::types)
<typename T, typename O>(tts::type<tts::types<T, O>>)
{
rotgen::matrix<T, 1, 2> a = {1, 2};
rotgen::matrix<T, 2, 1> b = {10, 20};
rotgen::matrix<T, -1, -1, O::value> big(10, 10);
auto bk = extract<1, 1>(big, 2, 2);
bk = a * b;
TTS_EQUAL(big(2, 2), 50);
rotgen::map<rotgen::matrix<T, 1, 1, O::value>> big_map(big.data(), 1, 1);
big_map = a * b;
TTS_EQUAL(big(0, 0), 50);
};

View file

@ -18,9 +18,8 @@ void fill(auto& m, int r, int c, auto data[])
for (int k = 0; k < r * c; ++k) m.data()[k] = data[k]; for (int k = 0; k < r * c; ++k) m.data()[k] = data[k];
} }
TTS_CASE_TPL("Function size", rotgen::tests::types) TTS_CASE_TPL("Function size", rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
<typename T, typename O>(tts::type<tts::types<T, O>>)
{ {
T data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; T data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
@ -29,44 +28,44 @@ TTS_CASE_TPL("Function size", rotgen::tests::types)
fill(dm, 1, 12, data); fill(dm, 1, 12, data);
auto b1 = rotgen::block<decltype(dm), rotgen::Dynamic, rotgen::Dynamic>( auto b1 = rotgen::block<decltype(dm), rotgen::Dynamic, rotgen::Dynamic>(
dm, 0, 0, 1, 12); dm, 0, 0, 1, 12);
TTS_EQUAL(rows(b1), rotgen::Index{1}); TTS_EQUAL(b1.rows(), rotgen::Index{1});
TTS_EQUAL(cols(b1), rotgen::Index{12}); TTS_EQUAL(b1.cols(), rotgen::Index{12});
// 1x5 dynamic block at (0,2) // 1x5 dynamic block at (0,2)
auto b2 = rotgen::block<decltype(dm), rotgen::Dynamic, rotgen::Dynamic>( auto b2 = rotgen::block<decltype(dm), rotgen::Dynamic, rotgen::Dynamic>(
dm, 0, 2, 1, 5); dm, 0, 2, 1, 5);
TTS_EQUAL(rows(b2), rotgen::Index{1}); TTS_EQUAL(b2.rows(), rotgen::Index{1});
TTS_EQUAL(cols(b2), rotgen::Index{5}); TTS_EQUAL(b2.cols(), rotgen::Index{5});
// 3x2 dynamic block at (1,4) in 4x6 // 3x2 dynamic block at (1,4) in 4x6
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> dm2(4, 6); rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> dm2(4, 6);
fill(dm2, 4, 6, data); fill(dm2, 4, 6, data);
auto b3 = rotgen::block<decltype(dm2), rotgen::Dynamic, rotgen::Dynamic>( auto b3 = rotgen::block<decltype(dm2), rotgen::Dynamic, rotgen::Dynamic>(
dm2, 1, 4, 3, 2); dm2, 1, 4, 3, 2);
TTS_EQUAL(rows(b3), rotgen::Index{3}); TTS_EQUAL(b3.rows(), rotgen::Index{3});
TTS_EQUAL(cols(b3), rotgen::Index{2}); TTS_EQUAL(b3.cols(), rotgen::Index{2});
TTS_EQUAL(b3.size(), rotgen::Index{6}); TTS_EQUAL(b3.size(), rotgen::Index{6});
// 3x4 static block // 3x4 static block
rotgen::matrix<T, 3, 4, O::value> sm; rotgen::matrix<T, 3, 4, O::value> sm;
fill(sm, 3, 4, data); fill(sm, 3, 4, data);
auto b4 = rotgen::block<decltype(sm), 3, 4>(sm, 0, 0); auto b4 = rotgen::block<decltype(sm), 3, 4>(sm, 0, 0);
TTS_EQUAL(rows(b4), rotgen::Index{3}); TTS_EQUAL(b4.rows(), rotgen::Index{3});
TTS_EQUAL(cols(b4), rotgen::Index{4}); TTS_EQUAL(b4.cols(), rotgen::Index{4});
TTS_EQUAL(b4.size(), rotgen::Index{12}); TTS_EQUAL(b4.size(), rotgen::Index{12});
// 6x2 static block // 6x2 static block
rotgen::matrix<T, 6, 2, O::value> sm2; rotgen::matrix<T, 6, 2, O::value> sm2;
fill(sm2, 6, 2, data); fill(sm2, 6, 2, data);
auto b5 = rotgen::block<decltype(sm2), 6, 2>(sm2, 0, 0); auto b5 = rotgen::block<decltype(sm2), 6, 2>(sm2, 0, 0);
TTS_EQUAL(rows(b5), rotgen::Index{6}); TTS_EQUAL(b5.rows(), rotgen::Index{6});
TTS_EQUAL(cols(b5), rotgen::Index{2}); TTS_EQUAL(b5.cols(), rotgen::Index{2});
TTS_EQUAL(b5.size(), rotgen::Index{12}); TTS_EQUAL(b5.size(), rotgen::Index{12});
}; };
TTS_CASE_TPL("Test coefficient accessors", rotgen::tests::types) TTS_CASE_TPL("Test coefficient accessors",
rotgen::tests::types)<typename T, typename O>(
<typename T, typename O>(tts::type<tts::types<T, O>>) tts::type<tts::types<T, O>>)
{ {
using base = rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value>; using base = rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value>;
@ -93,9 +92,9 @@ TTS_CASE_TPL("Test coefficient accessors", rotgen::tests::types)
TTS_EQUAL(b(2, 2), 17); TTS_EQUAL(b(2, 2), 17);
}; };
TTS_CASE_TPL("Test one index coefficient accessors", rotgen::tests::types) TTS_CASE_TPL("Test one index coefficient accessors",
rotgen::tests::types)<typename T, typename O>(
<typename T, typename O>(tts::type<tts::types<T, O>>) tts::type<tts::types<T, O>>)
{ {
auto vs = [&]() { auto vs = [&]() {
if constexpr (O::value == rotgen::ColMajor) if constexpr (O::value == rotgen::ColMajor)

View file

@ -13,15 +13,15 @@
template<typename EigenType, typename F> template<typename EigenType, typename F>
void for_each_element(EigenType const& m, F&& f) void for_each_element(EigenType const& m, F&& f)
{ {
for (rotgen::Index i = 0; i < rows(m); ++i) for (rotgen::Index i = 0; i < m.rows(); ++i)
for (rotgen::Index j = 0; j < cols(m); ++j) f(i, j, m(i, j)); for (rotgen::Index j = 0; j < m.cols(); ++j) f(i, j, m(i, j));
} }
template<typename EigenType, typename F> template<typename EigenType, typename F>
void for_each_element(EigenType& m, F&& f) void for_each_element(EigenType& m, F&& f)
{ {
for (rotgen::Index i = 0; i < rows(m); ++i) for (rotgen::Index i = 0; i < m.rows(); ++i)
for (rotgen::Index j = 0; j < cols(m); ++j) f(i, j, m(i, j)); for (rotgen::Index j = 0; j < m.cols(); ++j) f(i, j, m(i, j));
} }
template<typename MatrixType, typename T> template<typename MatrixType, typename T>
@ -53,8 +53,8 @@ void validate_block_behavior(MatrixType& matrix,
rotgen::Index block_n) rotgen::Index block_n)
{ {
using T = typename MatrixType::value_type; using T = typename MatrixType::value_type;
TTS_EQUAL(rows(block), block_m); TTS_EQUAL(block.rows(), block_m);
TTS_EQUAL(cols(block), block_n); TTS_EQUAL(block.cols(), block_n);
TTS_EQUAL(block.size(), block_m * block_n); TTS_EQUAL(block.size(), block_m * block_n);
// test block values // test block values
@ -144,31 +144,31 @@ void test_dynamic_block_extraction(
std::make_tuple(c_block_top_left_corner, 0, 0, matrix_construct.ni, std::make_tuple(c_block_top_left_corner, 0, 0, matrix_construct.ni,
matrix_construct.nj, rotgen::Dynamic, rotgen::Dynamic), matrix_construct.nj, rotgen::Dynamic, rotgen::Dynamic),
std::make_tuple(c_block_top_right_corner, 0, std::make_tuple(c_block_top_right_corner, 0,
cols(matrix) - matrix_construct.nj, matrix_construct.ni, matrix.cols() - matrix_construct.nj, matrix_construct.ni,
matrix_construct.nj, rotgen::Dynamic, rotgen::Dynamic), matrix_construct.nj, rotgen::Dynamic, rotgen::Dynamic),
std::make_tuple(c_block_bottom_left_corner, std::make_tuple(c_block_bottom_left_corner,
rows(matrix) - matrix_construct.ni, 0, matrix_construct.ni, matrix.rows() - matrix_construct.ni, 0, matrix_construct.ni,
matrix_construct.nj, rotgen::Dynamic, rotgen::Dynamic), matrix_construct.nj, rotgen::Dynamic, rotgen::Dynamic),
std::make_tuple(c_block_bottom_right_corner, std::make_tuple(c_block_bottom_right_corner,
rows(matrix) - matrix_construct.ni, matrix.rows() - matrix_construct.ni,
cols(matrix) - matrix_construct.nj, matrix_construct.ni, matrix.cols() - matrix_construct.nj, matrix_construct.ni,
matrix_construct.nj, rotgen::Dynamic, rotgen::Dynamic), matrix_construct.nj, rotgen::Dynamic, rotgen::Dynamic),
std::make_tuple(c_block_top_rows, 0, 0, matrix_construct.ni, cols(matrix), std::make_tuple(c_block_top_rows, 0, 0, matrix_construct.ni, matrix.cols(),
rotgen::Dynamic, MatrixType::ColsAtCompileTime), rotgen::Dynamic, MatrixType::ColsAtCompileTime),
std::make_tuple(c_block_middle_rows, matrix_construct.i0, 0, std::make_tuple(c_block_middle_rows, matrix_construct.i0, 0,
matrix_construct.ni, cols(matrix), rotgen::Dynamic, matrix_construct.ni, matrix.cols(), rotgen::Dynamic,
MatrixType::ColsAtCompileTime), MatrixType::ColsAtCompileTime),
std::make_tuple(c_block_bottom_rows, rows(matrix) - matrix_construct.ni, 0, std::make_tuple(c_block_bottom_rows, matrix.rows() - matrix_construct.ni, 0,
matrix_construct.ni, cols(matrix), rotgen::Dynamic, matrix_construct.ni, matrix.cols(), rotgen::Dynamic,
MatrixType::ColsAtCompileTime), MatrixType::ColsAtCompileTime),
std::make_tuple(c_block_left_cols, 0, 0, rows(matrix), matrix_construct.nj, std::make_tuple(c_block_left_cols, 0, 0, matrix.rows(), matrix_construct.nj,
MatrixType::RowsAtCompileTime, rotgen::Dynamic), MatrixType::RowsAtCompileTime, rotgen::Dynamic),
std::make_tuple(c_block_middle_cols, 0, matrix_construct.j0, rows(matrix), std::make_tuple(c_block_middle_cols, 0, matrix_construct.j0, matrix.rows(),
matrix_construct.nj, MatrixType::RowsAtCompileTime, matrix_construct.nj, MatrixType::RowsAtCompileTime,
rotgen::Dynamic), rotgen::Dynamic),
std::make_tuple(c_block_right_cols, 0, cols(matrix) - matrix_construct.nj, std::make_tuple(c_block_right_cols, 0, matrix.cols() - matrix_construct.nj,
rows(matrix), matrix_construct.nj, matrix.rows(), matrix_construct.nj,
MatrixType::RowsAtCompileTime, rotgen::Dynamic), MatrixType::RowsAtCompileTime, rotgen::Dynamic),
// --- REGULAR TESTS // --- REGULAR TESTS
@ -178,31 +178,31 @@ void test_dynamic_block_extraction(
std::make_tuple(block_top_left_corner, 0, 0, matrix_construct.ni, std::make_tuple(block_top_left_corner, 0, 0, matrix_construct.ni,
matrix_construct.nj, rotgen::Dynamic, rotgen::Dynamic), matrix_construct.nj, rotgen::Dynamic, rotgen::Dynamic),
std::make_tuple(block_top_right_corner, 0, std::make_tuple(block_top_right_corner, 0,
cols(matrix) - matrix_construct.nj, matrix_construct.ni, matrix.cols() - matrix_construct.nj, matrix_construct.ni,
matrix_construct.nj, rotgen::Dynamic, rotgen::Dynamic), matrix_construct.nj, rotgen::Dynamic, rotgen::Dynamic),
std::make_tuple(block_bottom_left_corner, std::make_tuple(block_bottom_left_corner,
rows(matrix) - matrix_construct.ni, 0, matrix_construct.ni, matrix.rows() - matrix_construct.ni, 0, matrix_construct.ni,
matrix_construct.nj, rotgen::Dynamic, rotgen::Dynamic), matrix_construct.nj, rotgen::Dynamic, rotgen::Dynamic),
std::make_tuple(block_bottom_right_corner, std::make_tuple(block_bottom_right_corner,
rows(matrix) - matrix_construct.ni, matrix.rows() - matrix_construct.ni,
cols(matrix) - matrix_construct.nj, matrix_construct.ni, matrix.cols() - matrix_construct.nj, matrix_construct.ni,
matrix_construct.nj, rotgen::Dynamic, rotgen::Dynamic), matrix_construct.nj, rotgen::Dynamic, rotgen::Dynamic),
std::make_tuple(block_top_rows, 0, 0, matrix_construct.ni, cols(matrix), std::make_tuple(block_top_rows, 0, 0, matrix_construct.ni, matrix.cols(),
rotgen::Dynamic, MatrixType::ColsAtCompileTime), rotgen::Dynamic, MatrixType::ColsAtCompileTime),
std::make_tuple(block_middle_rows, matrix_construct.i0, 0, std::make_tuple(block_middle_rows, matrix_construct.i0, 0,
matrix_construct.ni, cols(matrix), rotgen::Dynamic, matrix_construct.ni, matrix.cols(), rotgen::Dynamic,
MatrixType::ColsAtCompileTime), MatrixType::ColsAtCompileTime),
std::make_tuple(block_bottom_rows, rows(matrix) - matrix_construct.ni, 0, std::make_tuple(block_bottom_rows, matrix.rows() - matrix_construct.ni, 0,
matrix_construct.ni, cols(matrix), rotgen::Dynamic, matrix_construct.ni, matrix.cols(), rotgen::Dynamic,
MatrixType::ColsAtCompileTime), MatrixType::ColsAtCompileTime),
std::make_tuple(block_left_cols, 0, 0, rows(matrix), matrix_construct.nj, std::make_tuple(block_left_cols, 0, 0, matrix.rows(), matrix_construct.nj,
MatrixType::RowsAtCompileTime, rotgen::Dynamic), MatrixType::RowsAtCompileTime, rotgen::Dynamic),
std::make_tuple(block_middle_cols, 0, matrix_construct.j0, rows(matrix), std::make_tuple(block_middle_cols, 0, matrix_construct.j0, matrix.rows(),
matrix_construct.nj, MatrixType::RowsAtCompileTime, matrix_construct.nj, MatrixType::RowsAtCompileTime,
rotgen::Dynamic), rotgen::Dynamic),
std::make_tuple(block_right_cols, 0, cols(matrix) - matrix_construct.nj, std::make_tuple(block_right_cols, 0, matrix.cols() - matrix_construct.nj,
rows(matrix), matrix_construct.nj, matrix.rows(), matrix_construct.nj,
MatrixType::RowsAtCompileTime, rotgen::Dynamic)); MatrixType::RowsAtCompileTime, rotgen::Dynamic));
std::apply( std::apply(
@ -276,68 +276,68 @@ void test_static_block_extraction(
std::make_tuple(c_block_top_left_corner, 0, 0, matrix_construct.ni, std::make_tuple(c_block_top_left_corner, 0, 0, matrix_construct.ni,
matrix_construct.nj, int(NI), int(NJ)), matrix_construct.nj, int(NI), int(NJ)),
std::make_tuple(c_block_top_right_corner, 0, std::make_tuple(c_block_top_right_corner, 0,
cols(matrix) - matrix_construct.nj, matrix_construct.ni, matrix.cols() - matrix_construct.nj, matrix_construct.ni,
matrix_construct.nj, int(NI), int(NJ)), matrix_construct.nj, int(NI), int(NJ)),
std::make_tuple(c_block_bottom_left_corner, std::make_tuple(c_block_bottom_left_corner,
rows(matrix) - matrix_construct.ni, 0, matrix_construct.ni, matrix.rows() - matrix_construct.ni, 0, matrix_construct.ni,
matrix_construct.nj, int(NI), int(NJ)), matrix_construct.nj, int(NI), int(NJ)),
std::make_tuple(c_block_bottom_right_corner, std::make_tuple(c_block_bottom_right_corner,
rows(matrix) - matrix_construct.ni, matrix.rows() - matrix_construct.ni,
cols(matrix) - matrix_construct.nj, matrix_construct.ni, matrix.cols() - matrix_construct.nj, matrix_construct.ni,
matrix_construct.nj, int(NI), int(NJ)), matrix_construct.nj, int(NI), int(NJ)),
std::make_tuple(c_block_top_rows, 0, 0, matrix_construct.ni, cols(matrix), std::make_tuple(c_block_top_rows, 0, 0, matrix_construct.ni, matrix.cols(),
int(NI), rotgen::Dynamic), int(NI), rotgen::Dynamic),
std::make_tuple(c_block_middle_rows, i0, 0, matrix_construct.ni, std::make_tuple(c_block_middle_rows, i0, 0, matrix_construct.ni,
cols(matrix), int(NI), rotgen::Dynamic), matrix.cols(), int(NI), rotgen::Dynamic),
std::make_tuple(c_block_bottom_rows, rows(matrix) - matrix_construct.ni, 0, std::make_tuple(c_block_bottom_rows, matrix.rows() - matrix_construct.ni, 0,
matrix_construct.ni, cols(matrix), int(NI), matrix_construct.ni, matrix.cols(), int(NI),
rotgen::Dynamic), rotgen::Dynamic),
std::make_tuple(c_block_left_cols, 0, 0, rows(matrix), matrix_construct.nj, std::make_tuple(c_block_left_cols, 0, 0, matrix.rows(), matrix_construct.nj,
rotgen::Dynamic, int(NJ)), rotgen::Dynamic, int(NJ)),
std::make_tuple(c_block_middle_cols, 0, j0, rows(matrix), std::make_tuple(c_block_middle_cols, 0, j0, matrix.rows(),
matrix_construct.nj, rotgen::Dynamic, int(NJ)), matrix_construct.nj, rotgen::Dynamic, int(NJ)),
std::make_tuple(c_block_right_cols, 0, cols(matrix) - matrix_construct.nj, std::make_tuple(c_block_right_cols, 0, matrix.cols() - matrix_construct.nj,
rows(matrix), matrix_construct.nj, rotgen::Dynamic, matrix.rows(), matrix_construct.nj, rotgen::Dynamic,
int(NJ)), int(NJ)),
std::make_tuple(c_block_row, i0, 0, 1, cols(matrix), 1, rotgen::Dynamic), std::make_tuple(c_block_row, i0, 0, 1, matrix.cols(), 1, rotgen::Dynamic),
std::make_tuple(c_block_col, 0, j0, rows(matrix), 1, rotgen::Dynamic, 1), std::make_tuple(c_block_col, 0, j0, matrix.rows(), 1, rotgen::Dynamic, 1),
// -- Block to NON CONST // -- Block to NON CONST
std::make_tuple(block_main, i0, j0, matrix_construct.ni, std::make_tuple(block_main, i0, j0, matrix_construct.ni,
matrix_construct.nj, int(NI), int(NJ)), matrix_construct.nj, int(NI), int(NJ)),
std::make_tuple(block_top_left_corner, 0, 0, matrix_construct.ni, std::make_tuple(block_top_left_corner, 0, 0, matrix_construct.ni,
matrix_construct.nj, int(NI), int(NJ)), matrix_construct.nj, int(NI), int(NJ)),
std::make_tuple(block_top_right_corner, 0, std::make_tuple(block_top_right_corner, 0,
cols(matrix) - matrix_construct.nj, matrix_construct.ni, matrix.cols() - matrix_construct.nj, matrix_construct.ni,
matrix_construct.nj, int(NI), int(NJ)), matrix_construct.nj, int(NI), int(NJ)),
std::make_tuple(block_bottom_left_corner, std::make_tuple(block_bottom_left_corner,
rows(matrix) - matrix_construct.ni, 0, matrix_construct.ni, matrix.rows() - matrix_construct.ni, 0, matrix_construct.ni,
matrix_construct.nj, int(NI), int(NJ)), matrix_construct.nj, int(NI), int(NJ)),
std::make_tuple(block_bottom_right_corner, std::make_tuple(block_bottom_right_corner,
rows(matrix) - matrix_construct.ni, matrix.rows() - matrix_construct.ni,
cols(matrix) - matrix_construct.nj, matrix_construct.ni, matrix.cols() - matrix_construct.nj, matrix_construct.ni,
matrix_construct.nj, int(NI), int(NJ)), matrix_construct.nj, int(NI), int(NJ)),
std::make_tuple(block_top_rows, 0, 0, matrix_construct.ni, cols(matrix), std::make_tuple(block_top_rows, 0, 0, matrix_construct.ni, matrix.cols(),
int(NI), rotgen::Dynamic), int(NI), rotgen::Dynamic),
std::make_tuple(block_middle_rows, i0, 0, matrix_construct.ni, cols(matrix), std::make_tuple(block_middle_rows, i0, 0, matrix_construct.ni,
int(NI), rotgen::Dynamic), matrix.cols(), int(NI), rotgen::Dynamic),
std::make_tuple(block_bottom_rows, rows(matrix) - matrix_construct.ni, 0, std::make_tuple(block_bottom_rows, matrix.rows() - matrix_construct.ni, 0,
matrix_construct.ni, cols(matrix), int(NI), matrix_construct.ni, matrix.cols(), int(NI),
rotgen::Dynamic), rotgen::Dynamic),
std::make_tuple(block_left_cols, 0, 0, rows(matrix), matrix_construct.nj, std::make_tuple(block_left_cols, 0, 0, matrix.rows(), matrix_construct.nj,
rotgen::Dynamic, int(NJ)), rotgen::Dynamic, int(NJ)),
std::make_tuple(block_middle_cols, 0, j0, rows(matrix), matrix_construct.nj, std::make_tuple(block_middle_cols, 0, j0, matrix.rows(),
rotgen::Dynamic, int(NJ)), matrix_construct.nj, rotgen::Dynamic, int(NJ)),
std::make_tuple(block_right_cols, 0, cols(matrix) - matrix_construct.nj, std::make_tuple(block_right_cols, 0, matrix.cols() - matrix_construct.nj,
rows(matrix), matrix_construct.nj, rotgen::Dynamic, matrix.rows(), matrix_construct.nj, rotgen::Dynamic,
int(NJ)), int(NJ)),
std::make_tuple(block_row, i0, 0, 1, cols(matrix), 1, rotgen::Dynamic), std::make_tuple(block_row, i0, 0, 1, matrix.cols(), 1, rotgen::Dynamic),
std::make_tuple(block_col, 0, j0, rows(matrix), 1, rotgen::Dynamic, 1)); std::make_tuple(block_col, 0, j0, matrix.rows(), 1, rotgen::Dynamic, 1));
std::apply( std::apply(
[&](auto&&... block_entries) { [&](auto&&... block_entries) {
@ -358,9 +358,7 @@ void test_static_block_extraction(
TTS_CASE_TPL( TTS_CASE_TPL(
"Check all dynamic block extractions on a dynamic row-major matrix", "Check all dynamic block extractions on a dynamic row-major matrix",
rotgen::tests::types) rotgen::tests::types)<typename T, typename O>(tts::type<tts::types<T, O>>)
<typename T, typename O>(tts::type<tts::types<T, O>>)
{ {
using mat_t = using mat_t =
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, rotgen::RowMajor>; rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, rotgen::RowMajor>;
@ -396,9 +394,7 @@ TTS_CASE_TPL(
TTS_CASE_TPL( TTS_CASE_TPL(
"Check all dynamic block extractions on a static column-major matrix", "Check all dynamic block extractions on a static column-major matrix",
rotgen::tests::types) rotgen::tests::types)<typename T, typename O>(tts::type<tts::types<T, O>>)
<typename T, typename O>(tts::type<tts::types<T, O>>)
{ {
using mat_t = rotgen::matrix<T, 4, 5, rotgen::ColMajor>; using mat_t = rotgen::matrix<T, 4, 5, rotgen::ColMajor>;
@ -421,9 +417,9 @@ TTS_CASE_TPL(
} }
}; };
TTS_CASE_TPL("Check all static block extractions", rotgen::tests::types) TTS_CASE_TPL("Check all static block extractions",
rotgen::tests::types)<typename T, typename O>(
<typename T, typename O>(tts::type<tts::types<T, O>>) tts::type<tts::types<T, O>>)
{ {
using mat_t = rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value>; using mat_t = rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value>;
@ -450,9 +446,9 @@ TTS_CASE_TPL("Check all static block extractions", rotgen::tests::types)
0}); 0});
}; };
TTS_CASE_TPL("Check vector-only extractions", rotgen::tests::types) TTS_CASE_TPL("Check vector-only extractions",
rotgen::tests::types)<typename T, typename O>(
<typename T, typename O>(tts::type<tts::types<T, O>>) tts::type<tts::types<T, O>>)
{ {
auto run_case = [](auto&& matrix, auto&& block, int i_offset, int j_offset, auto run_case = [](auto&& matrix, auto&& block, int i_offset, int j_offset,
int ni, int nj, auto const& rows_ct, auto const& cols_ct) { int ni, int nj, auto const& rows_ct, auto const& cols_ct) {

View file

@ -48,9 +48,9 @@ void test_random(auto const& matrix,
} }
} }
TTS_CASE_TPL("Test dynamic block::setZero", rotgen::tests::types) TTS_CASE_TPL("Test dynamic block::setZero",
rotgen::tests::types)<typename T, typename O>(
<typename T, typename O>(tts::type<tts::types<T, O>>) tts::type<tts::types<T, O>>)
{ {
auto const cases = rotgen::tests::generate_block_references<T, O>(); auto const cases = rotgen::tests::generate_block_references<T, O>();
for (auto const& [matrix_desc, i0, j0, ni, nj] : cases) for (auto const& [matrix_desc, i0, j0, ni, nj] : cases)
@ -64,14 +64,14 @@ TTS_CASE_TPL("Test dynamic block::setZero", rotgen::tests::types)
test_value(m, T{0}, i0, j0, ni, nj); test_value(m, T{0}, i0, j0, ni, nj);
using input_type = decltype(rotgen::extract(m, i0, j0, ni, nj)); using input_type = decltype(rotgen::extract(m, i0, j0, ni, nj));
auto values = rotgen::setZero<input_type>(ni, nj); auto values = input_type::Zero(ni, nj);
test_value(values, T{0}, 0, 0, ni, nj); test_value(values, T{0}, 0, 0, ni, nj);
} }
}; };
TTS_CASE_TPL("Test static block::setZero", rotgen::tests::types) TTS_CASE_TPL("Test static block::setZero",
rotgen::tests::types)<typename T, typename O>(
<typename T, typename O>(tts::type<tts::types<T, O>>) tts::type<tts::types<T, O>>)
{ {
auto const cases = rotgen::tests::generate_static_block_references<T, O>(); auto const cases = rotgen::tests::generate_static_block_references<T, O>();
@ -87,16 +87,16 @@ TTS_CASE_TPL("Test static block::setZero", rotgen::tests::types)
test_value(m, T{0}, i0, j0, D::ni, D::nj); test_value(m, T{0}, i0, j0, D::ni, D::nj);
using input_type = decltype(rotgen::extract<D::ni, D::nj>(m, i0, j0)); using input_type = decltype(rotgen::extract<D::ni, D::nj>(m, i0, j0));
auto values = rotgen::setZero<input_type>(); auto values = input_type::Zero();
test_value(values, T{0}, 0, 0, D::ni, D::nj); test_value(values, T{0}, 0, 0, D::ni, D::nj);
}; };
std::apply([&](auto const&... d) { (process(d), ...); }, cases); std::apply([&](auto const&... d) { (process(d), ...); }, cases);
}; };
TTS_CASE_TPL("Test dynamic block::setOnes", rotgen::tests::types) TTS_CASE_TPL("Test dynamic block::setOnes",
rotgen::tests::types)<typename T, typename O>(
<typename T, typename O>(tts::type<tts::types<T, O>>) tts::type<tts::types<T, O>>)
{ {
auto const cases = rotgen::tests::generate_block_references<T, O>(); auto const cases = rotgen::tests::generate_block_references<T, O>();
for (auto const& [matrix_desc, i0, j0, ni, nj] : cases) for (auto const& [matrix_desc, i0, j0, ni, nj] : cases)
@ -110,14 +110,14 @@ TTS_CASE_TPL("Test dynamic block::setOnes", rotgen::tests::types)
test_value(m, T{1}, i0, j0, ni, nj); test_value(m, T{1}, i0, j0, ni, nj);
using input_type = decltype(rotgen::extract(m, i0, j0, ni, nj)); using input_type = decltype(rotgen::extract(m, i0, j0, ni, nj));
auto values = rotgen::setOnes<input_type>(ni, nj); auto values = input_type::Ones(ni, nj);
test_value(values, T{1}, 0, 0, ni, nj); test_value(values, T{1}, 0, 0, ni, nj);
} }
}; };
TTS_CASE_TPL("Test static block::setOnes", rotgen::tests::types) TTS_CASE_TPL("Test static block::setOnes",
rotgen::tests::types)<typename T, typename O>(
<typename T, typename O>(tts::type<tts::types<T, O>>) tts::type<tts::types<T, O>>)
{ {
auto const cases = rotgen::tests::generate_static_block_references<T, O>(); auto const cases = rotgen::tests::generate_static_block_references<T, O>();
@ -133,16 +133,16 @@ TTS_CASE_TPL("Test static block::setOnes", rotgen::tests::types)
test_value(m, T{1}, i0, j0, D::ni, D::nj); test_value(m, T{1}, i0, j0, D::ni, D::nj);
using input_type = decltype(rotgen::extract<D::ni, D::nj>(m, i0, j0)); using input_type = decltype(rotgen::extract<D::ni, D::nj>(m, i0, j0));
auto values = rotgen::setOnes<input_type>(); auto values = input_type::Ones();
test_value(values, T{1}, 0, 0, D::ni, D::nj); test_value(values, T{1}, 0, 0, D::ni, D::nj);
}; };
std::apply([&](auto const&... d) { (process(d), ...); }, cases); std::apply([&](auto const&... d) { (process(d), ...); }, cases);
}; };
TTS_CASE_TPL("Test dynamic block::setConstant", rotgen::tests::types) TTS_CASE_TPL("Test dynamic block::setConstant",
rotgen::tests::types)<typename T, typename O>(
<typename T, typename O>(tts::type<tts::types<T, O>>) tts::type<tts::types<T, O>>)
{ {
auto const cases = rotgen::tests::generate_block_references<T, O>(); auto const cases = rotgen::tests::generate_block_references<T, O>();
for (auto const& [matrix_desc, i0, j0, ni, nj] : cases) for (auto const& [matrix_desc, i0, j0, ni, nj] : cases)
@ -156,14 +156,14 @@ TTS_CASE_TPL("Test dynamic block::setConstant", rotgen::tests::types)
test_value(m, T{13.37f}, i0, j0, ni, nj); test_value(m, T{13.37f}, i0, j0, ni, nj);
using input_type = decltype(rotgen::extract(m, i0, j0, ni, nj)); using input_type = decltype(rotgen::extract(m, i0, j0, ni, nj));
auto values = rotgen::setConstant<input_type>(ni, nj, T{13.37f}); auto values = input_type::Constant(ni, nj, T{13.37f});
test_value(values, T{13.37f}, 0, 0, ni, nj); test_value(values, T{13.37f}, 0, 0, ni, nj);
} }
}; };
TTS_CASE_TPL("Test static block::setConstant", rotgen::tests::types) TTS_CASE_TPL("Test static block::setConstant",
rotgen::tests::types)<typename T, typename O>(
<typename T, typename O>(tts::type<tts::types<T, O>>) tts::type<tts::types<T, O>>)
{ {
auto const cases = rotgen::tests::generate_static_block_references<T, O>(); auto const cases = rotgen::tests::generate_static_block_references<T, O>();
@ -179,16 +179,16 @@ TTS_CASE_TPL("Test static block::setConstant", rotgen::tests::types)
test_value(m, T{13.37f}, i0, j0, D::ni, D::nj); test_value(m, T{13.37f}, i0, j0, D::ni, D::nj);
using input_type = decltype(rotgen::extract<D::ni, D::nj>(m, i0, j0)); using input_type = decltype(rotgen::extract<D::ni, D::nj>(m, i0, j0));
auto values = rotgen::setConstant<input_type>(T{13.37f}); auto values = input_type::Constant(T{13.37f});
test_value(values, T{13.37f}, 0, 0, D::ni, D::nj); test_value(values, T{13.37f}, 0, 0, D::ni, D::nj);
}; };
std::apply([&](auto const&... d) { (process(d), ...); }, cases); std::apply([&](auto const&... d) { (process(d), ...); }, cases);
}; };
TTS_CASE_TPL("Test dynamic block::setIdentity", rotgen::tests::types) TTS_CASE_TPL("Test dynamic block::setIdentity",
rotgen::tests::types)<typename T, typename O>(
<typename T, typename O>(tts::type<tts::types<T, O>>) tts::type<tts::types<T, O>>)
{ {
auto const cases = rotgen::tests::generate_block_references<T, O>(); auto const cases = rotgen::tests::generate_block_references<T, O>();
for (auto const& [matrix_desc, i0, j0, ni, nj] : cases) for (auto const& [matrix_desc, i0, j0, ni, nj] : cases)
@ -202,14 +202,14 @@ TTS_CASE_TPL("Test dynamic block::setIdentity", rotgen::tests::types)
test_identity(m, i0, j0, ni, nj); test_identity(m, i0, j0, ni, nj);
using input_type = decltype(rotgen::extract(m, i0, j0, ni, nj)); using input_type = decltype(rotgen::extract(m, i0, j0, ni, nj));
auto values = rotgen::setIdentity<input_type>(ni, nj); auto values = input_type::Identity(ni, nj);
test_identity(values, 0, 0, ni, nj); test_identity(values, 0, 0, ni, nj);
} }
}; };
TTS_CASE_TPL("Test static block::setIdentity", rotgen::tests::types) TTS_CASE_TPL("Test static block::setIdentity",
rotgen::tests::types)<typename T, typename O>(
<typename T, typename O>(tts::type<tts::types<T, O>>) tts::type<tts::types<T, O>>)
{ {
auto const cases = rotgen::tests::generate_static_block_references<T, O>(); auto const cases = rotgen::tests::generate_static_block_references<T, O>();
@ -225,16 +225,16 @@ TTS_CASE_TPL("Test static block::setIdentity", rotgen::tests::types)
test_identity(m, i0, j0, D::ni, D::nj); test_identity(m, i0, j0, D::ni, D::nj);
using input_type = decltype(rotgen::extract<D::ni, D::nj>(m, i0, j0)); using input_type = decltype(rotgen::extract<D::ni, D::nj>(m, i0, j0));
auto values = rotgen::setIdentity<input_type>(); auto values = input_type::Identity();
test_identity(values, 0, 0, D::ni, D::nj); test_identity(values, 0, 0, D::ni, D::nj);
}; };
std::apply([&](auto const&... d) { (process(d), ...); }, cases); std::apply([&](auto const&... d) { (process(d), ...); }, cases);
}; };
TTS_CASE_TPL("Test dynamic block::setRandom", rotgen::tests::types) TTS_CASE_TPL("Test dynamic block::setRandom",
rotgen::tests::types)<typename T, typename O>(
<typename T, typename O>(tts::type<tts::types<T, O>>) tts::type<tts::types<T, O>>)
{ {
auto const cases = rotgen::tests::generate_block_references<T, O>(); auto const cases = rotgen::tests::generate_block_references<T, O>();
for (auto const& [matrix_desc, i0, j0, ni, nj] : cases) for (auto const& [matrix_desc, i0, j0, ni, nj] : cases)
@ -248,14 +248,14 @@ TTS_CASE_TPL("Test dynamic block::setRandom", rotgen::tests::types)
test_random(m, i0, j0, ni, nj); test_random(m, i0, j0, ni, nj);
using input_type = decltype(rotgen::extract(m, i0, j0, ni, nj)); using input_type = decltype(rotgen::extract(m, i0, j0, ni, nj));
auto values = rotgen::setRandom<input_type>(ni, nj); auto values = input_type::Random(ni, nj);
test_random(values, 0, 0, ni, nj); test_random(values, 0, 0, ni, nj);
} }
}; };
TTS_CASE_TPL("Test static block::setRandom", rotgen::tests::types) TTS_CASE_TPL("Test static block::setRandom",
rotgen::tests::types)<typename T, typename O>(
<typename T, typename O>(tts::type<tts::types<T, O>>) tts::type<tts::types<T, O>>)
{ {
auto const cases = rotgen::tests::generate_static_block_references<T, O>(); auto const cases = rotgen::tests::generate_static_block_references<T, O>();
@ -271,7 +271,7 @@ TTS_CASE_TPL("Test static block::setRandom", rotgen::tests::types)
test_random(m, i0, j0, D::ni, D::nj); test_random(m, i0, j0, D::ni, D::nj);
using input_type = decltype(rotgen::extract<D::ni, D::nj>(m, i0, j0)); using input_type = decltype(rotgen::extract<D::ni, D::nj>(m, i0, j0));
auto values = rotgen::setRandom<input_type>(); auto values = input_type::Random();
test_random(values, 0, 0, D::ni, D::nj); test_random(values, 0, 0, D::ni, D::nj);
}; };

View file

@ -21,7 +21,7 @@ namespace rotgen::tests
using eigen_mat_t = using eigen_mat_t =
matrix<typename T::value_type, Dynamic, Dynamic, T::storage_order>; matrix<typename T::value_type, Dynamic, Dynamic, T::storage_order>;
eigen_mat_t eigen_result(cols(rotgen_input), rows(rotgen_input)); eigen_mat_t eigen_result(rotgen_input.cols(), rotgen_input.rows());
prepare([&](auto r, auto c) { return rotgen_input(c, r); }, eigen_result); prepare([&](auto r, auto c) { return rotgen_input(c, r); }, eigen_result);
TTS_EQUAL(transpose(rotgen_input), eigen_result); TTS_EQUAL(transpose(rotgen_input), eigen_result);
@ -42,7 +42,7 @@ namespace rotgen::tests
} }
else else
{ {
if (rows(rotgen_input) == cols(rotgen_input)) if (rotgen_input.rows() == rotgen_input.cols())
{ {
eigen_mat_t eigen_ref = rotgen_input; eigen_mat_t eigen_ref = rotgen_input;
transposeInPlace(rotgen_input); transposeInPlace(rotgen_input);
@ -66,7 +66,7 @@ namespace rotgen::tests
using eigen_mat_t = using eigen_mat_t =
Eigen::Matrix<typename T::value_type, Eigen::Dynamic, Eigen::Dynamic>; Eigen::Matrix<typename T::value_type, Eigen::Dynamic, Eigen::Dynamic>;
eigen_mat_t eigen_ref(rows(rotgen_input), cols(rotgen_input)); eigen_mat_t eigen_ref(rotgen_input.rows(), rotgen_input.cols());
prepare([&](auto r, auto c) { return rotgen_input(r, c); }, eigen_ref); prepare([&](auto r, auto c) { return rotgen_input(r, c); }, eigen_ref);
TTS_ULP_EQUAL(sum(rotgen_input), eigen_ref.sum(), 2); TTS_ULP_EQUAL(sum(rotgen_input), eigen_ref.sum(), 2);

View file

@ -25,10 +25,10 @@ namespace rotgen::tests
TTS_WHEN("Unary Cwise operations") TTS_WHEN("Unary Cwise operations")
{ {
eigen_mat_t eigen_ref(rows(rotgen_input), cols(rotgen_input)); eigen_mat_t eigen_ref(rotgen_input.rows(), rotgen_input.cols());
prepare([&](auto r, auto c) { return rotgen_input(r, c); }, eigen_ref); prepare([&](auto r, auto c) { return rotgen_input(r, c); }, eigen_ref);
rotgen_mat_t rotgen_ref(rows(rotgen_input), cols(rotgen_input)); rotgen_mat_t rotgen_ref(rotgen_input.rows(), rotgen_input.cols());
TTS_AND_THEN("abs()") TTS_AND_THEN("abs()")
{ {
@ -57,8 +57,8 @@ namespace rotgen::tests
auto mat = rotgen::abs(rotgen_input); auto mat = rotgen::abs(rotgen_input);
auto proper_input = rotgen::sqrt(mat); auto proper_input = rotgen::sqrt(mat);
for (rotgen::Index r = 0; r < rows(rotgen_input); ++r) for (rotgen::Index r = 0; r < rotgen_input.rows(); ++r)
for (rotgen::Index c = 0; c < cols(rotgen_input); ++c) for (rotgen::Index c = 0; c < rotgen_input.cols(); ++c)
TTS_ULP_EQUAL(proper_input(r, c), eigen_ref(r, c), 1); TTS_ULP_EQUAL(proper_input(r, c), eigen_ref(r, c), 1);
} }
} }

View file

@ -20,7 +20,7 @@ namespace rotgen::tests
using eigen_mat_t = using eigen_mat_t =
Eigen::Matrix<typename T::value_type, Eigen::Dynamic, Eigen::Dynamic>; Eigen::Matrix<typename T::value_type, Eigen::Dynamic, Eigen::Dynamic>;
eigen_mat_t eigen_ref(rows(rotgen_input), cols(rotgen_input)); eigen_mat_t eigen_ref(rotgen_input.rows(), rotgen_input.cols());
prepare([&](auto row, auto col) { return rotgen_input(row, col); }, prepare([&](auto row, auto col) { return rotgen_input(row, col); },
eigen_ref); eigen_ref);
@ -38,7 +38,7 @@ namespace rotgen::tests
using rotgen_mat_t = using rotgen_mat_t =
rotgen::matrix<typename T::value_type, rotgen::Dynamic, rotgen::Dynamic, rotgen::matrix<typename T::value_type, rotgen::Dynamic, rotgen::Dynamic,
T::storage_order>; T::storage_order>;
rotgen_mat_t rotgen_norm_ref(rows(rotgen_input), cols(rotgen_input)); rotgen_mat_t rotgen_norm_ref(rotgen_input.rows(), rotgen_input.cols());
prepare([&](auto row, auto col) { return eigen_normalized(row, col); }, prepare([&](auto row, auto col) { return eigen_normalized(row, col); },
rotgen_norm_ref); rotgen_norm_ref);

View file

@ -55,13 +55,8 @@ namespace rotgen::tests
void prepare(auto fn, auto& output) void prepare(auto fn, auto& output)
{ {
for (rotgen::Index r = 0; r < rows(output); ++r) for (rotgen::Index r = 0; r < output.rows(); ++r)
{ for (rotgen::Index c = 0; c < output.cols(); ++c) output(r, c) = fn(r, c);
for (rotgen::Index c = 0; c < cols(output); ++c)
{
output(r, c) = fn(r, c);
}
}
} }
auto default_init_function = [](auto row, auto col) { auto default_init_function = [](auto row, auto col) {

View file

@ -10,9 +10,8 @@
#include "unit/common/references.hpp" #include "unit/common/references.hpp"
#include "unit/tests.hpp" #include "unit/tests.hpp"
TTS_CASE_TPL("rowwise API", rotgen::tests::types) TTS_CASE_TPL("rowwise API", rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
<typename T, typename O>(tts::type<tts::types<T, O>>)
{ {
using eigen_mat_t = using eigen_mat_t =
Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic, O::value>; Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic, O::value>;
@ -26,25 +25,24 @@ TTS_CASE_TPL("rowwise API", rotgen::tests::types)
auto rotgen_rw = rotgen::rowwise(rotgen_mat); auto rotgen_rw = rotgen::rowwise(rotgen_mat);
for (rotgen::Index i = 0; i < rows(rotgen_mat); ++i) for (rotgen::Index i = 0; i < rotgen_mat.rows(); ++i)
TTS_EQUAL(rotgen::sum(rotgen_rw)(i), eigen_ref_rw.sum()(i)); TTS_EQUAL(rotgen::sum(rotgen_rw)(i), eigen_ref_rw.sum()(i));
for (rotgen::Index i = 0; i < rows(rotgen_mat); ++i) for (rotgen::Index i = 0; i < rotgen_mat.rows(); ++i)
TTS_EQUAL(rotgen::mean(rotgen_rw)(i), eigen_ref_rw.mean()(i)); TTS_EQUAL(rotgen::mean(rotgen_rw)(i), eigen_ref_rw.mean()(i));
for (rotgen::Index i = 0; i < rows(rotgen_mat); ++i) for (rotgen::Index i = 0; i < rotgen_mat.rows(); ++i)
TTS_EQUAL(rotgen::prod(rotgen_rw)(i), eigen_ref_rw.prod()(i)); TTS_EQUAL(rotgen::prod(rotgen_rw)(i), eigen_ref_rw.prod()(i));
for (rotgen::Index i = 0; i < rows(rotgen_mat); ++i) for (rotgen::Index i = 0; i < rotgen_mat.rows(); ++i)
TTS_EQUAL(rotgen::maxCoeff(rotgen_rw)(i), eigen_ref_rw.maxCoeff()(i)); TTS_EQUAL(rotgen::maxCoeff(rotgen_rw)(i), eigen_ref_rw.maxCoeff()(i));
for (rotgen::Index i = 0; i < rows(rotgen_mat); ++i) for (rotgen::Index i = 0; i < rotgen_mat.rows(); ++i)
TTS_EQUAL(rotgen::minCoeff(rotgen_rw)(i), eigen_ref_rw.minCoeff()(i)); TTS_EQUAL(rotgen::minCoeff(rotgen_rw)(i), eigen_ref_rw.minCoeff()(i));
for (rotgen::Index i = 0; i < rows(rotgen_mat); ++i) for (rotgen::Index i = 0; i < rotgen_mat.rows(); ++i)
TTS_EQUAL(rotgen::squaredNorm(rotgen_rw)(i), eigen_ref_rw.squaredNorm()(i)); TTS_EQUAL(rotgen::squaredNorm(rotgen_rw)(i), eigen_ref_rw.squaredNorm()(i));
for (rotgen::Index i = 0; i < rows(rotgen_mat); ++i) for (rotgen::Index i = 0; i < rotgen_mat.rows(); ++i)
TTS_EQUAL(rotgen::norm(rotgen_rw)(i), eigen_ref_rw.norm()(i)); TTS_EQUAL(rotgen::norm(rotgen_rw)(i), eigen_ref_rw.norm()(i));
}; };
TTS_CASE_TPL("colwise API", rotgen::tests::types) TTS_CASE_TPL("colwise API", rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
<typename T, typename O>(tts::type<tts::types<T, O>>)
{ {
using eigen_mat_t = using eigen_mat_t =
Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic, O::value>; Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic, O::value>;
@ -58,18 +56,18 @@ TTS_CASE_TPL("colwise API", rotgen::tests::types)
auto rotgen_rw = rotgen::colwise(rotgen_mat); auto rotgen_rw = rotgen::colwise(rotgen_mat);
for (rotgen::Index i = 0; i < cols(rotgen_mat); ++i) for (rotgen::Index i = 0; i < rotgen_mat.cols(); ++i)
TTS_EQUAL(rotgen::sum(rotgen_rw)(i), eigen_ref_rw.sum()(i)); TTS_EQUAL(rotgen::sum(rotgen_rw)(i), eigen_ref_rw.sum()(i));
for (rotgen::Index i = 0; i < cols(rotgen_mat); ++i) for (rotgen::Index i = 0; i < rotgen_mat.cols(); ++i)
TTS_EQUAL(rotgen::mean(rotgen_rw)(i), eigen_ref_rw.mean()(i)); TTS_EQUAL(rotgen::mean(rotgen_rw)(i), eigen_ref_rw.mean()(i));
for (rotgen::Index i = 0; i < cols(rotgen_mat); ++i) for (rotgen::Index i = 0; i < rotgen_mat.cols(); ++i)
TTS_EQUAL(rotgen::prod(rotgen_rw)(i), eigen_ref_rw.prod()(i)); TTS_EQUAL(rotgen::prod(rotgen_rw)(i), eigen_ref_rw.prod()(i));
for (rotgen::Index i = 0; i < cols(rotgen_mat); ++i) for (rotgen::Index i = 0; i < rotgen_mat.cols(); ++i)
TTS_EQUAL(rotgen::maxCoeff(rotgen_rw)(i), eigen_ref_rw.maxCoeff()(i)); TTS_EQUAL(rotgen::maxCoeff(rotgen_rw)(i), eigen_ref_rw.maxCoeff()(i));
for (rotgen::Index i = 0; i < cols(rotgen_mat); ++i) for (rotgen::Index i = 0; i < rotgen_mat.cols(); ++i)
TTS_EQUAL(rotgen::minCoeff(rotgen_rw)(i), eigen_ref_rw.minCoeff()(i)); TTS_EQUAL(rotgen::minCoeff(rotgen_rw)(i), eigen_ref_rw.minCoeff()(i));
for (rotgen::Index i = 0; i < cols(rotgen_mat); ++i) for (rotgen::Index i = 0; i < rotgen_mat.cols(); ++i)
TTS_EQUAL(rotgen::squaredNorm(rotgen_rw)(i), eigen_ref_rw.squaredNorm()(i)); TTS_EQUAL(rotgen::squaredNorm(rotgen_rw)(i), eigen_ref_rw.squaredNorm()(i));
for (rotgen::Index i = 0; i < cols(rotgen_mat); ++i) for (rotgen::Index i = 0; i < rotgen_mat.cols(); ++i)
TTS_EQUAL(rotgen::norm(rotgen_rw)(i), eigen_ref_rw.norm()(i)); TTS_EQUAL(rotgen::norm(rotgen_rw)(i), eigen_ref_rw.norm()(i));
}; };

View file

@ -9,25 +9,25 @@
#include "unit/tests.hpp" #include "unit/tests.hpp"
TTS_CASE_TPL("SVD decomposition - Dynamic case", rotgen::tests::types) TTS_CASE_TPL("SVD decomposition - Dynamic case",
rotgen::tests::types)<typename T, typename O>(
<typename T, typename O>(tts::type<tts::types<T, O>>) tts::type<tts::types<T, O>>)
{ {
int rank, i = 5; int rank, i = 5;
auto eps = std::numeric_limits<T>::epsilon(); auto eps = std::numeric_limits<T>::epsilon();
auto m = rotgen::setRandom< auto m =
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value>>(5, 5); rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value>::Random(5, 5);
auto decomp = rotgen::svd(m); auto decomp = rotgen::svd(m);
do do
{ {
rank = decomp.rank(); rank = decomp.rank();
auto u = decomp.matrixU(rank); auto u = decomp.U(rank);
auto d = decomp.singularValues(rank); auto d = decomp.singular_values(rank);
auto dd = decomp.matrixD(rank); auto dd = decomp.D(rank);
auto v = decomp.matrixV(rank); auto v = decomp.V(rank);
TTS_EQUAL(rank, i); TTS_EQUAL(rank, i);
@ -48,24 +48,24 @@ TTS_CASE_TPL("SVD decomposition - Dynamic case", rotgen::tests::types)
} while (rank != 1); } while (rank != 1);
}; };
TTS_CASE_TPL("SVD decomposition - Static case", rotgen::tests::types) TTS_CASE_TPL("SVD decomposition - Static case",
rotgen::tests::types)<typename T, typename O>(
<typename T, typename O>(tts::type<tts::types<T, O>>) tts::type<tts::types<T, O>>)
{ {
int rank, i = 5; int rank, i = 5;
auto eps = std::numeric_limits<T>::epsilon(); auto eps = std::numeric_limits<T>::epsilon();
auto m = rotgen::setRandom<rotgen::matrix<T, 5, 5, O::value>>(); auto m = rotgen::matrix<T, 5, 5, O::value>::Random();
auto decomp = rotgen::svd(m); auto decomp = rotgen::svd(m);
do do
{ {
rank = decomp.rank(); rank = decomp.rank();
auto u = decomp.matrixU(rank); auto u = decomp.U(rank);
auto d = decomp.singularValues(rank); auto d = decomp.singular_values(rank);
auto dd = decomp.matrixD(rank); auto dd = decomp.D(rank);
auto v = decomp.matrixV(rank); auto v = decomp.V(rank);
TTS_EQUAL(rank, i); TTS_EQUAL(rank, i);

View file

@ -36,7 +36,7 @@ TTS_CASE_TPL("Test static map transposition-like operations",
auto process = []<typename D>(D const& desc) { auto process = []<typename D>(D const& desc) {
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> base(D::rows, rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> base(D::rows,
D::cols); D::cols);
rotgen::tests::prepare(rows(base), cols(base), desc.init_fn, base); rotgen::tests::prepare(base.rows(), base.cols(), desc.init_fn, base);
rotgen::map<rotgen::matrix<T, D::rows, D::cols, O::value>> input( rotgen::map<rotgen::matrix<T, D::rows, D::cols, O::value>> input(
base.data()); base.data());
@ -72,7 +72,7 @@ TTS_CASE_TPL("Test static map reduction-like operations",
auto process = []<typename D>(D const& desc) { auto process = []<typename D>(D const& desc) {
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> base(D::rows, rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> base(D::rows,
D::cols); D::cols);
rotgen::tests::prepare(rows(base), cols(base), desc.init_fn, base); rotgen::tests::prepare(base.rows(), base.cols(), desc.init_fn, base);
rotgen::map<rotgen::matrix<T, D::rows, D::cols, O::value>> input( rotgen::map<rotgen::matrix<T, D::rows, D::cols, O::value>> input(
base.data()); base.data());

View file

@ -9,41 +9,40 @@
#include "unit/tests.hpp" #include "unit/tests.hpp"
TTS_CASE_TPL("Function size", rotgen::tests::types) TTS_CASE_TPL("Function size", rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
<typename T, typename O>(tts::type<tts::types<T, O>>)
{ {
T data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; T data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
rotgen::map<rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value>> rotgen::map<rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value>>
dyn_map(data, 1, 12); dyn_map(data, 1, 12);
TTS_EQUAL(rows(dyn_map), rotgen::Index{1}); TTS_EQUAL(dyn_map.rows(), rotgen::Index{1});
TTS_EQUAL(cols(dyn_map), rotgen::Index{12}); TTS_EQUAL(dyn_map.cols(), rotgen::Index{12});
rotgen::map<rotgen::matrix<T, 1, 12, rotgen::RowMajor>> s112_map(data); rotgen::map<rotgen::matrix<T, 1, 12, rotgen::RowMajor>> s112_map(data);
TTS_EQUAL(rows(s112_map), rotgen::Index{1}); TTS_EQUAL(s112_map.rows(), rotgen::Index{1});
TTS_EQUAL(cols(s112_map), rotgen::Index{12}); TTS_EQUAL(s112_map.cols(), rotgen::Index{12});
TTS_EQUAL(s112_map.size(), rotgen::Index{12}); TTS_EQUAL(s112_map.size(), rotgen::Index{12});
rotgen::map<rotgen::matrix<T, 12, 1, rotgen::ColMajor>> s121_map(data); rotgen::map<rotgen::matrix<T, 12, 1, rotgen::ColMajor>> s121_map(data);
TTS_EQUAL(rows(s121_map), rotgen::Index{12}); TTS_EQUAL(s121_map.rows(), rotgen::Index{12});
TTS_EQUAL(cols(s121_map), rotgen::Index{1}); TTS_EQUAL(s121_map.cols(), rotgen::Index{1});
TTS_EQUAL(s121_map.size(), rotgen::Index{12}); TTS_EQUAL(s121_map.size(), rotgen::Index{12});
rotgen::map<rotgen::matrix<T, 3, 4, O::value>> s34_map(data); rotgen::map<rotgen::matrix<T, 3, 4, O::value>> s34_map(data);
TTS_EQUAL(rows(s34_map), rotgen::Index{3}); TTS_EQUAL(s34_map.rows(), rotgen::Index{3});
TTS_EQUAL(cols(s34_map), rotgen::Index{4}); TTS_EQUAL(s34_map.cols(), rotgen::Index{4});
TTS_EQUAL(s34_map.size(), rotgen::Index{12}); TTS_EQUAL(s34_map.size(), rotgen::Index{12});
rotgen::map<rotgen::matrix<T, 6, 2, O::value>> s62_map(data); rotgen::map<rotgen::matrix<T, 6, 2, O::value>> s62_map(data);
TTS_EQUAL(rows(s62_map), rotgen::Index{6}); TTS_EQUAL(s62_map.rows(), rotgen::Index{6});
TTS_EQUAL(cols(s62_map), rotgen::Index{2}); TTS_EQUAL(s62_map.cols(), rotgen::Index{2});
TTS_EQUAL(s62_map.size(), rotgen::Index{12}); TTS_EQUAL(s62_map.size(), rotgen::Index{12});
}; };
TTS_CASE_TPL("Test coefficient accessors", rotgen::tests::types) TTS_CASE_TPL("Test coefficient accessors",
rotgen::tests::types)<typename T, typename O>(
<typename T, typename O>(tts::type<tts::types<T, O>>) tts::type<tts::types<T, O>>)
{ {
using base = rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value>; using base = rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value>;
@ -67,9 +66,9 @@ TTS_CASE_TPL("Test coefficient accessors", rotgen::tests::types)
TTS_EQUAL(a(2, 2), 17); TTS_EQUAL(a(2, 2), 17);
}; };
TTS_CASE_TPL("Test one index coefficient accessors", rotgen::tests::types) TTS_CASE_TPL("Test one index coefficient accessors",
rotgen::tests::types)<typename T, typename O>(
<typename T, typename O>(tts::type<tts::types<T, O>>) tts::type<tts::types<T, O>>)
{ {
T data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; T data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};

View file

@ -11,9 +11,9 @@
#include "unit/common/references.hpp" #include "unit/common/references.hpp"
#include "unit/tests.hpp" #include "unit/tests.hpp"
TTS_CASE_TPL("Test dynamic map cwise operations", rotgen::tests::types) TTS_CASE_TPL("Test dynamic map cwise operations",
rotgen::tests::types)<typename T, typename O>(
<typename T, typename O>(tts::type<tts::types<T, O>>) tts::type<tts::types<T, O>>)
{ {
auto const cases = rotgen::tests::generate_matrix_references(); auto const cases = rotgen::tests::generate_matrix_references();
for (auto const& [rows, cols, fn] : cases) for (auto const& [rows, cols, fn] : cases)
@ -28,16 +28,16 @@ TTS_CASE_TPL("Test dynamic map cwise operations", rotgen::tests::types)
} }
}; };
TTS_CASE_TPL("Test static map cwise operations", rotgen::tests::types) TTS_CASE_TPL("Test static map cwise operations",
rotgen::tests::types)<typename T, typename O>(
<typename T, typename O>(tts::type<tts::types<T, O>>) tts::type<tts::types<T, O>>)
{ {
auto const cases = rotgen::tests::generate_static_matrix_references(); auto const cases = rotgen::tests::generate_static_matrix_references();
auto process = []<typename D>(D const& desc) { auto process = []<typename D>(D const& desc) {
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> base(D::rows, rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> base(D::rows,
D::cols); D::cols);
rotgen::tests::prepare(rows(base), cols(base), desc.init_fn, base); rotgen::tests::prepare(base.rows(), base.cols(), desc.init_fn, base);
rotgen::map<rotgen::matrix<T, D::rows, D::cols, O::value>> input( rotgen::map<rotgen::matrix<T, D::rows, D::cols, O::value>> input(
base.data()); base.data());

View file

@ -11,9 +11,9 @@
#include "unit/common/references.hpp" #include "unit/common/references.hpp"
#include "unit/tests.hpp" #include "unit/tests.hpp"
TTS_CASE_TPL("Test dynamic map norm operations", rotgen::tests::types) TTS_CASE_TPL("Test dynamic map norm operations",
rotgen::tests::types)<typename T, typename O>(
<typename T, typename O>(tts::type<tts::types<T, O>>) tts::type<tts::types<T, O>>)
{ {
auto const cases = rotgen::tests::generate_matrix_references(); auto const cases = rotgen::tests::generate_matrix_references();
for (auto const& [rows, cols, fn] : cases) for (auto const& [rows, cols, fn] : cases)
@ -28,16 +28,16 @@ TTS_CASE_TPL("Test dynamic map norm operations", rotgen::tests::types)
} }
}; };
TTS_CASE_TPL("Test static map norm operations", rotgen::tests::types) TTS_CASE_TPL("Test static map norm operations",
rotgen::tests::types)<typename T, typename O>(
<typename T, typename O>(tts::type<tts::types<T, O>>) tts::type<tts::types<T, O>>)
{ {
auto const cases = rotgen::tests::generate_static_matrix_references(); auto const cases = rotgen::tests::generate_static_matrix_references();
auto process = []<typename D>(D const& desc) { auto process = []<typename D>(D const& desc) {
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> base(D::rows, rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> base(D::rows,
D::cols); D::cols);
rotgen::tests::prepare(rows(base), cols(base), desc.init_fn, base); rotgen::tests::prepare(base.rows(), base.cols(), desc.init_fn, base);
rotgen::map<rotgen::matrix<T, D::rows, D::cols, O::value>> input( rotgen::map<rotgen::matrix<T, D::rows, D::cols, O::value>> input(
base.data()); base.data());

View file

@ -40,8 +40,8 @@ TTS_CASE("Validate Column Major Map with regular stride behavior")
r_map_t<r_mat_t<rotgen::ColMajor>> r_map(buffer.data(), rows, cols); r_map_t<r_mat_t<rotgen::ColMajor>> r_map(buffer.data(), rows, cols);
TTS_EQUAL(innerStride(r_map), 1); TTS_EQUAL(r_map.innerStride(), 1);
TTS_EQUAL(outerStride(r_map), 3); TTS_EQUAL(r_map.outerStride(), 3);
e_map_t<e_mat_t<Eigen::ColMajor>> e_map(buffer.data(), rows, cols); e_map_t<e_mat_t<Eigen::ColMajor>> e_map(buffer.data(), rows, cols);
@ -59,8 +59,8 @@ TTS_CASE("Validate Column Major Map with specific outer stride behavior")
r_map_t<r_mat_t<rotgen::ColMajor>, rotgen::outer_stride<>> r_map( r_map_t<r_mat_t<rotgen::ColMajor>, rotgen::outer_stride<>> r_map(
buffer.data(), rows, cols, rotgen::outer_stride<>(rows + 1)); buffer.data(), rows, cols, rotgen::outer_stride<>(rows + 1));
TTS_EQUAL(innerStride(r_map), 1); TTS_EQUAL(r_map.innerStride(), 1);
TTS_EQUAL(outerStride(r_map), 4); TTS_EQUAL(r_map.outerStride(), 4);
e_map_t<e_mat_t<Eigen::ColMajor>, Eigen::OuterStride<>> e_map( e_map_t<e_mat_t<Eigen::ColMajor>, Eigen::OuterStride<>> e_map(
buffer.data(), rows, cols, Eigen::OuterStride<>(rows + 1)); buffer.data(), rows, cols, Eigen::OuterStride<>(rows + 1));
@ -79,8 +79,8 @@ TTS_CASE("Validate Column Major Map with specific inner stride behavior")
r_map_t<r_mat_t<rotgen::ColMajor>, rotgen::dynamic_stride> r_map( r_map_t<r_mat_t<rotgen::ColMajor>, rotgen::dynamic_stride> r_map(
buffer.data(), rows, cols, rotgen::dynamic_stride(rows, 2)); buffer.data(), rows, cols, rotgen::dynamic_stride(rows, 2));
TTS_EQUAL(innerStride(r_map), 2); TTS_EQUAL(r_map.innerStride(), 2);
TTS_EQUAL(outerStride(r_map), 3); TTS_EQUAL(r_map.outerStride(), 3);
e_map_t<e_mat_t<Eigen::ColMajor>, e_map_t<e_mat_t<Eigen::ColMajor>,
Eigen::Stride<Eigen::Dynamic, Eigen::Dynamic>> Eigen::Stride<Eigen::Dynamic, Eigen::Dynamic>>
@ -100,8 +100,8 @@ TTS_CASE("Validate Row Major Map with regular stride behavior")
r_map_t<r_mat_t<rotgen::RowMajor>> r_map(buffer.data(), rows, cols); r_map_t<r_mat_t<rotgen::RowMajor>> r_map(buffer.data(), rows, cols);
TTS_EQUAL(innerStride(r_map), 1); TTS_EQUAL(r_map.innerStride(), 1);
TTS_EQUAL(outerStride(r_map), 4); TTS_EQUAL(r_map.outerStride(), 4);
e_map_t<e_mat_t<Eigen::RowMajor>> e_map(buffer.data(), rows, cols); e_map_t<e_mat_t<Eigen::RowMajor>> e_map(buffer.data(), rows, cols);
@ -119,8 +119,8 @@ TTS_CASE("Validate Row Major Map with specific outer stride behavior")
r_map_t<r_mat_t<rotgen::RowMajor>, rotgen::outer_stride<>> r_map( r_map_t<r_mat_t<rotgen::RowMajor>, rotgen::outer_stride<>> r_map(
buffer.data(), rows, cols, rotgen::outer_stride<>(cols + 1)); buffer.data(), rows, cols, rotgen::outer_stride<>(cols + 1));
TTS_EQUAL(innerStride(r_map), 1); TTS_EQUAL(r_map.innerStride(), 1);
TTS_EQUAL(outerStride(r_map), 5); TTS_EQUAL(r_map.outerStride(), 5);
e_map_t<e_mat_t<Eigen::RowMajor>, Eigen::OuterStride<>> e_map( e_map_t<e_mat_t<Eigen::RowMajor>, Eigen::OuterStride<>> e_map(
buffer.data(), rows, cols, Eigen::OuterStride<>(cols + 1)); buffer.data(), rows, cols, Eigen::OuterStride<>(cols + 1));
@ -139,8 +139,8 @@ TTS_CASE("Validate Row Major Map with specific inner stride behavior")
r_map_t<r_mat_t<rotgen::RowMajor>, rotgen::dynamic_stride> r_map( r_map_t<r_mat_t<rotgen::RowMajor>, rotgen::dynamic_stride> r_map(
buffer.data(), rows, cols, rotgen::dynamic_stride(2, cols)); buffer.data(), rows, cols, rotgen::dynamic_stride(2, cols));
TTS_EQUAL(innerStride(r_map), 4); TTS_EQUAL(r_map.innerStride(), 4);
TTS_EQUAL(outerStride(r_map), 2); TTS_EQUAL(r_map.outerStride(), 2);
e_map_t<e_mat_t<Eigen::RowMajor>, e_map_t<e_mat_t<Eigen::RowMajor>,
Eigen::Stride<Eigen::Dynamic, Eigen::Dynamic>> Eigen::Stride<Eigen::Dynamic, Eigen::Dynamic>>

View file

@ -13,9 +13,8 @@
#include "unit/tests.hpp" #include "unit/tests.hpp"
TTS_CASE_TPL("Test dynamic matrix transposition-like operations", TTS_CASE_TPL("Test dynamic matrix transposition-like operations",
rotgen::tests::types) rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
<typename T, typename O>(tts::type<tts::types<T, O>>)
{ {
auto const cases = rotgen::tests::generate_matrix_references(); auto const cases = rotgen::tests::generate_matrix_references();
for (auto const& [rows, cols, fn] : cases) for (auto const& [rows, cols, fn] : cases)
@ -28,15 +27,14 @@ TTS_CASE_TPL("Test dynamic matrix transposition-like operations",
}; };
TTS_CASE_TPL("Test static matrix transposition-like operations", TTS_CASE_TPL("Test static matrix transposition-like operations",
rotgen::tests::types) rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
<typename T, typename O>(tts::type<tts::types<T, O>>)
{ {
auto const cases = rotgen::tests::generate_static_matrix_references(); auto const cases = rotgen::tests::generate_static_matrix_references();
auto process = []<typename D>(D const& desc) { auto process = []<typename D>(D const& desc) {
rotgen::matrix<T, D::rows, D::cols, O::value> input; rotgen::matrix<T, D::rows, D::cols, O::value> input;
rotgen::tests::prepare(rows(input), cols(input), desc.init_fn, input); rotgen::tests::prepare(input.rows(), input.cols(), desc.init_fn, input);
rotgen::tests::check_shape_functions(input); rotgen::tests::check_shape_functions(input);
}; };
@ -44,9 +42,8 @@ TTS_CASE_TPL("Test static matrix transposition-like operations",
}; };
TTS_CASE_TPL("Test dynamic matrix reduction-like operations", TTS_CASE_TPL("Test dynamic matrix reduction-like operations",
rotgen::tests::types) rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
<typename T, typename O>(tts::type<tts::types<T, O>>)
{ {
auto const cases = rotgen::tests::generate_matrix_references(); auto const cases = rotgen::tests::generate_matrix_references();
for (auto const& [rows, cols, fn] : cases) for (auto const& [rows, cols, fn] : cases)
@ -59,23 +56,21 @@ TTS_CASE_TPL("Test dynamic matrix reduction-like operations",
}; };
TTS_CASE_TPL("Test static matrix reduction-like operations", TTS_CASE_TPL("Test static matrix reduction-like operations",
rotgen::tests::types) rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
<typename T, typename O>(tts::type<tts::types<T, O>>)
{ {
auto const cases = rotgen::tests::generate_static_matrix_references(); auto const cases = rotgen::tests::generate_static_matrix_references();
auto process = []<typename D>(D const& desc) { auto process = []<typename D>(D const& desc) {
rotgen::matrix<T, D::rows, D::cols, O::value> input; rotgen::matrix<T, D::rows, D::cols, O::value> input;
rotgen::tests::prepare(rows(input), cols(input), desc.init_fn, input); rotgen::tests::prepare(input.rows(), input.cols(), desc.init_fn, input);
rotgen::tests::check_reduction_functions(input); rotgen::tests::check_reduction_functions(input);
}; };
std::apply([&](auto const&... d) { (process(d), ...); }, cases); std::apply([&](auto const&... d) { (process(d), ...); }, cases);
}; };
TTS_CASE_TPL("Test dot product", float, double) TTS_CASE_TPL("Test dot product", float, double)<typename T>(tts::type<T>){
<typename T>(tts::type<T>){
{auto a = rotgen::setConstant<rotgen::matrix<T, 1, rotgen::Dynamic>>(1, 8, 2); {auto a = rotgen::setConstant<rotgen::matrix<T, 1, rotgen::Dynamic>>(1, 8, 2);
auto b = rotgen::setConstant<rotgen::matrix<T, 1, rotgen::Dynamic>>(1, 8, 2); auto b = rotgen::setConstant<rotgen::matrix<T, 1, rotgen::Dynamic>>(1, 8, 2);

View file

@ -9,9 +9,8 @@
#include "unit/tests.hpp" #include "unit/tests.hpp"
TTS_CASE_TPL("Function size", rotgen::tests::types) TTS_CASE_TPL("Function size", rotgen::tests::types)<typename T, typename O>(
tts::type<tts::types<T, O>>)
<typename T, typename O>(tts::type<tts::types<T, O>>)
{ {
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> empty_matrix; rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> empty_matrix;
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> matrix(3, 4); rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> matrix(3, 4);
@ -26,87 +25,87 @@ TTS_CASE_TPL("Function size", rotgen::tests::types)
TTS_EQUAL(column_vector.size(), rotgen::Index{5}); TTS_EQUAL(column_vector.size(), rotgen::Index{5});
}; };
TTS_CASE_TPL("Resizing dynamic matrix", rotgen::tests::types) TTS_CASE_TPL("Resizing dynamic matrix",
rotgen::tests::types)<typename T, typename O>(
<typename T, typename O>(tts::type<tts::types<T, O>>) tts::type<tts::types<T, O>>)
{ {
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> a(2, 3); rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> a(2, 3);
for (rotgen::Index r = 0; r < rows(a); ++r) for (rotgen::Index r = 0; r < a.rows(); ++r)
for (rotgen::Index c = 0; c < cols(a); ++c) a(r, c) = 42 + 2 * c + r; for (rotgen::Index c = 0; c < a.cols(); ++c) a(r, c) = 42 + 2 * c + r;
rotgen::resize(a, 3, 2); rotgen::resize(a, 3, 2);
TTS_EQUAL(rows(a), rotgen::Index(3)); TTS_EQUAL(a.rows(), rotgen::Index(3));
TTS_EQUAL(cols(a), rotgen::Index(2)); TTS_EQUAL(a.cols(), rotgen::Index(2));
for (rotgen::Index r = 0; r < rows(a); ++r) for (rotgen::Index r = 0; r < a.rows(); ++r)
for (rotgen::Index c = 0; c < cols(a); ++c) TTS_GREATER(a(r, c), 0); for (rotgen::Index c = 0; c < a.cols(); ++c) TTS_GREATER(a(r, c), 0);
rotgen::resize(a, 2, 2); rotgen::resize(a, 2, 2);
TTS_EQUAL(rows(a), rotgen::Index(2)); TTS_EQUAL(a.rows(), rotgen::Index(2));
TTS_EQUAL(cols(a), rotgen::Index(2)); TTS_EQUAL(a.cols(), rotgen::Index(2));
}; };
TTS_CASE_TPL("Dynamix matrix conservative resizing", rotgen::tests::types) TTS_CASE_TPL("Dynamix matrix conservative resizing",
rotgen::tests::types)<typename T, typename O>(
<typename T, typename O>(tts::type<tts::types<T, O>>) tts::type<tts::types<T, O>>)
{ {
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> a(2, 3); rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> a(2, 3);
int i = 1; int i = 1;
for (rotgen::Index r = 0; r < rows(a); ++r) for (rotgen::Index r = 0; r < a.rows(); ++r)
for (rotgen::Index c = 0; c < cols(a); ++c) a(r, c) = i++; for (rotgen::Index c = 0; c < a.cols(); ++c) a(r, c) = i++;
rotgen::conservativeResize(a, 2, 3); rotgen::conservativeResize(a, 2, 3);
TTS_EQUAL(rows(a), rotgen::Index(2)); TTS_EQUAL(a.rows(), rotgen::Index(2));
TTS_EQUAL(cols(a), rotgen::Index(3)); TTS_EQUAL(a.cols(), rotgen::Index(3));
i = 1; i = 1;
for (rotgen::Index r = 0; r < rows(a); ++r) for (rotgen::Index r = 0; r < a.rows(); ++r)
for (rotgen::Index c = 0; c < cols(a); ++c) TTS_EQUAL(a(r, c), i++); for (rotgen::Index c = 0; c < a.cols(); ++c) TTS_EQUAL(a(r, c), i++);
rotgen::conservativeResize(a, 3, 2); rotgen::conservativeResize(a, 3, 2);
TTS_EQUAL(rows(a), rotgen::Index(3)); TTS_EQUAL(a.rows(), rotgen::Index(3));
TTS_EQUAL(cols(a), rotgen::Index(2)); TTS_EQUAL(a.cols(), rotgen::Index(2));
int expected[3][2] = {{1, 2}, {4, 5}}; int expected[3][2] = {{1, 2}, {4, 5}};
for (rotgen::Index r = 0; r < 2; ++r) for (rotgen::Index r = 0; r < 2; ++r)
for (rotgen::Index c = 0; c < 2; ++c) TTS_EQUAL(a(r, c), expected[r][c]); for (rotgen::Index c = 0; c < 2; ++c) TTS_EQUAL(a(r, c), expected[r][c]);
rotgen::conservativeResize(a, 4, 4); rotgen::conservativeResize(a, 4, 4);
TTS_EQUAL(rows(a), rotgen::Index(4)); TTS_EQUAL(a.rows(), rotgen::Index(4));
TTS_EQUAL(cols(a), rotgen::Index(4)); TTS_EQUAL(a.cols(), rotgen::Index(4));
TTS_EQUAL(a(0, 0), 1); TTS_EQUAL(a(0, 0), 1);
TTS_EQUAL(a(3, 3), 0); TTS_EQUAL(a(3, 3), 0);
rotgen::conservativeResize(a, 2, 2); rotgen::conservativeResize(a, 2, 2);
TTS_EQUAL(rows(a), rotgen::Index(2)); TTS_EQUAL(a.rows(), rotgen::Index(2));
TTS_EQUAL(cols(a), rotgen::Index(2)); TTS_EQUAL(a.cols(), rotgen::Index(2));
TTS_EQUAL(a(0, 0), 1); TTS_EQUAL(a(0, 0), 1);
TTS_EQUAL(a(1, 1), 5); TTS_EQUAL(a(1, 1), 5);
rotgen::conservativeResize(a, 1, 2); rotgen::conservativeResize(a, 1, 2);
TTS_EQUAL(rows(a), rotgen::Index(1)); TTS_EQUAL(a.rows(), rotgen::Index(1));
TTS_EQUAL(cols(a), rotgen::Index(2)); TTS_EQUAL(a.cols(), rotgen::Index(2));
TTS_EQUAL(a(0, 0), 1); TTS_EQUAL(a(0, 0), 1);
TTS_EQUAL(a(0, 1), 2); TTS_EQUAL(a(0, 1), 2);
rotgen::conservativeResize(a, 0, 0); rotgen::conservativeResize(a, 0, 0);
TTS_EQUAL(rows(a), rotgen::Index(0)); TTS_EQUAL(a.rows(), rotgen::Index(0));
TTS_EQUAL(cols(a), rotgen::Index(0)); TTS_EQUAL(a.cols(), rotgen::Index(0));
rotgen::conservativeResize(a, 3, 3); rotgen::conservativeResize(a, 3, 3);
TTS_EQUAL(rows(a), rotgen::Index(3)); TTS_EQUAL(a.rows(), rotgen::Index(3));
TTS_EQUAL(cols(a), rotgen::Index(3)); TTS_EQUAL(a.cols(), rotgen::Index(3));
}; };
TTS_CASE_TPL("Test coefficient accessors", rotgen::tests::types) TTS_CASE_TPL("Test coefficient accessors",
rotgen::tests::types)<typename T, typename O>(
<typename T, typename O>(tts::type<tts::types<T, O>>) tts::type<tts::types<T, O>>)
{ {
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> a(3, 5); rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> a(3, 5);
for (rotgen::Index r = 0; r < rows(a); ++r) for (rotgen::Index r = 0; r < a.rows(); ++r)
for (rotgen::Index c = 0; c < cols(a); ++c) a(r, c) = r + 2 * c + 3; for (rotgen::Index c = 0; c < a.cols(); ++c) a(r, c) = r + 2 * c + 3;
TTS_EQUAL(a(0, 0), 3); TTS_EQUAL(a(0, 0), 3);
TTS_EQUAL(a(1, 1), 6); TTS_EQUAL(a(1, 1), 6);
@ -122,9 +121,9 @@ TTS_CASE_TPL("Test coefficient accessors", rotgen::tests::types)
TTS_EQUAL(a(2, 2), 17); TTS_EQUAL(a(2, 2), 17);
}; };
TTS_CASE_TPL("Test one index coefficient accessors", rotgen::tests::types) TTS_CASE_TPL("Test one index coefficient accessors",
rotgen::tests::types)<typename T, typename O>(
<typename T, typename O>(tts::type<tts::types<T, O>>) tts::type<tts::types<T, O>>)
{ {
auto a = [&]() { auto a = [&]() {
if constexpr (O::value == rotgen::ColMajor) if constexpr (O::value == rotgen::ColMajor)

View file

@ -15,8 +15,8 @@ TTS_CASE_TPL("Default matrix dynamic constructor", rotgen::tests::types)
{ {
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> matrix; rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> matrix;
TTS_EQUAL(rows(matrix), rotgen::Index{0}); TTS_EQUAL(matrix.rows(), rotgen::Index{0});
TTS_EQUAL(cols(matrix), rotgen::Index{0}); TTS_EQUAL(matrix.cols(), rotgen::Index{0});
}; };
TTS_CASE_TPL("Default matrix static constructor", rotgen::tests::types) TTS_CASE_TPL("Default matrix static constructor", rotgen::tests::types)
@ -25,8 +25,8 @@ TTS_CASE_TPL("Default matrix static constructor", rotgen::tests::types)
{ {
rotgen::matrix<T, 4, 9, O::value> matrix; rotgen::matrix<T, 4, 9, O::value> matrix;
TTS_EQUAL(rows(matrix), rotgen::Index{4}); TTS_EQUAL(matrix.rows(), rotgen::Index{4});
TTS_EQUAL(cols(matrix), rotgen::Index{9}); TTS_EQUAL(matrix.cols(), rotgen::Index{9});
}; };
TTS_CASE_TPL("Dynamic matrix constructor with row and columns", TTS_CASE_TPL("Dynamic matrix constructor with row and columns",
@ -36,8 +36,8 @@ TTS_CASE_TPL("Dynamic matrix constructor with row and columns",
{ {
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> matrix(10, 5); rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> matrix(10, 5);
TTS_EQUAL(rows(matrix), rotgen::Index{10}); TTS_EQUAL(matrix.rows(), rotgen::Index{10});
TTS_EQUAL(cols(matrix), rotgen::Index{5}); TTS_EQUAL(matrix.cols(), rotgen::Index{5});
}; };
TTS_CASE_TPL("Static matrix constructor with row and columns", float, double) TTS_CASE_TPL("Static matrix constructor with row and columns", float, double)
@ -72,16 +72,16 @@ TTS_CASE_TPL("Copy constructor produces identical but independent matrix",
{ {
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> a(3, 3); rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> a(3, 3);
for (rotgen::Index r = 0; r < rows(a); r++) for (rotgen::Index r = 0; r < a.rows(); r++)
for (rotgen::Index c = 0; c < cols(a); c++) a(r, c) = r + c; for (rotgen::Index c = 0; c < a.cols(); c++) a(r, c) = r + c;
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> b = a; rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> b = a;
TTS_EQUAL(rows(b), rows(a)); TTS_EQUAL(b.rows(), a.rows());
TTS_EQUAL(cols(b), cols(a)); TTS_EQUAL(b.cols(), a.cols());
for (rotgen::Index r = 0; r < rows(a); r++) for (rotgen::Index r = 0; r < a.rows(); r++)
for (rotgen::Index c = 0; c < cols(a); c++) TTS_EQUAL(b(r, c), a(r, c)); for (rotgen::Index c = 0; c < a.cols(); c++) TTS_EQUAL(b(r, c), a(r, c));
TTS_EQUAL(b(0, 0), 0.0); TTS_EQUAL(b(0, 0), 0.0);
TTS_EQUAL(b(1, 0), 1.0); TTS_EQUAL(b(1, 0), 1.0);
@ -97,8 +97,8 @@ TTS_CASE_TPL("Copy constructor on default matrix", rotgen::tests::types)
{ {
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> a; rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> a;
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> b = a; rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> b = a;
TTS_EQUAL(rows(b), rotgen::Index{0}); TTS_EQUAL(b.rows(), rotgen::Index{0});
TTS_EQUAL(cols(b), rotgen::Index{0}); TTS_EQUAL(b.cols(), rotgen::Index{0});
}; };
TTS_CASE_TPL("Copy constructor from const matrix", rotgen::tests::types) TTS_CASE_TPL("Copy constructor from const matrix", rotgen::tests::types)
@ -107,8 +107,8 @@ TTS_CASE_TPL("Copy constructor from const matrix", rotgen::tests::types)
{ {
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> const a(2, 2); rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> const a(2, 2);
auto b = a; auto b = a;
TTS_EQUAL(rows(b), rotgen::Index{2}); TTS_EQUAL(b.rows(), rotgen::Index{2});
TTS_EQUAL(cols(b), rotgen::Index{2}); TTS_EQUAL(b.cols(), rotgen::Index{2});
}; };
TTS_CASE_TPL("Copy constructor on static matrix", rotgen::tests::types) TTS_CASE_TPL("Copy constructor on static matrix", rotgen::tests::types)
@ -117,8 +117,8 @@ TTS_CASE_TPL("Copy constructor on static matrix", rotgen::tests::types)
{ {
rotgen::matrix<T, 2, 5> a; rotgen::matrix<T, 2, 5> a;
rotgen::matrix<T, 2, 5> b = a; rotgen::matrix<T, 2, 5> b = a;
TTS_EQUAL(rows(b), rotgen::Index{2}); TTS_EQUAL(b.rows(), rotgen::Index{2});
TTS_EQUAL(cols(b), rotgen::Index{5}); TTS_EQUAL(b.cols(), rotgen::Index{5});
}; };
TTS_CASE_TPL("Copy constructor on static/dynamic matrix", rotgen::tests::types) TTS_CASE_TPL("Copy constructor on static/dynamic matrix", rotgen::tests::types)
@ -127,8 +127,8 @@ TTS_CASE_TPL("Copy constructor on static/dynamic matrix", rotgen::tests::types)
{ {
rotgen::matrix<T, 11, 4, O::value> a; rotgen::matrix<T, 11, 4, O::value> a;
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> b = a; rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> b = a;
TTS_EQUAL(rows(b), 11); TTS_EQUAL(b.rows(), 11);
TTS_EQUAL(cols(b), 4); TTS_EQUAL(b.cols(), 4);
}; };
TTS_CASE_TPL("Copy constructor on dynamic/static matrix", rotgen::tests::types) TTS_CASE_TPL("Copy constructor on dynamic/static matrix", rotgen::tests::types)
@ -137,8 +137,8 @@ TTS_CASE_TPL("Copy constructor on dynamic/static matrix", rotgen::tests::types)
{ {
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> a(5, 7); rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> a(5, 7);
rotgen::matrix<T, 5, 7, O::value> b = a; rotgen::matrix<T, 5, 7, O::value> b = a;
TTS_EQUAL(rows(b), 5); TTS_EQUAL(b.rows(), 5);
TTS_EQUAL(cols(b), 7); TTS_EQUAL(b.cols(), 7);
}; };
TTS_CASE_TPL("Move constructor transfers contents", rotgen::tests::types) TTS_CASE_TPL("Move constructor transfers contents", rotgen::tests::types)
@ -153,8 +153,8 @@ TTS_CASE_TPL("Move constructor transfers contents", rotgen::tests::types)
std::move(a); std::move(a);
TTS_EQUAL(b(1, 1), 7); TTS_EQUAL(b(1, 1), 7);
TTS_EQUAL(rows(b), rotgen::Index{3}); TTS_EQUAL(b.rows(), rotgen::Index{3});
TTS_EQUAL(cols(b), rotgen::Index{3}); TTS_EQUAL(b.cols(), rotgen::Index{3});
TTS_EXPECT(b.data() == ptr); TTS_EXPECT(b.data() == ptr);
}; };
@ -164,8 +164,8 @@ TTS_CASE_TPL("Move constructor from Rvalue", rotgen::tests::types)
{ {
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> b = rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> b =
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value>(2, 2); rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value>(2, 2);
TTS_EQUAL(rows(b), rotgen::Index{2}); TTS_EQUAL(b.rows(), rotgen::Index{2});
TTS_EQUAL(cols(b), rotgen::Index{2}); TTS_EQUAL(b.cols(), rotgen::Index{2});
}; };
TTS_CASE_TPL("Constructor from Initializer list", rotgen::tests::types) TTS_CASE_TPL("Constructor from Initializer list", rotgen::tests::types)
@ -173,24 +173,24 @@ TTS_CASE_TPL("Constructor from Initializer list", rotgen::tests::types)
<typename T, typename O>(tts::type<tts::types<T, O>>) <typename T, typename O>(tts::type<tts::types<T, O>>)
{ {
rotgen::matrix<T, 1, 1, O::value> b1{3.5}; rotgen::matrix<T, 1, 1, O::value> b1{3.5};
TTS_EQUAL(rows(b1), rotgen::Index{1}); TTS_EQUAL(b1.rows(), rotgen::Index{1});
TTS_EQUAL(cols(b1), rotgen::Index{1}); TTS_EQUAL(b1.cols(), rotgen::Index{1});
TTS_EQUAL(b1(0), 3.5); TTS_EQUAL(b1(0), 3.5);
rotgen::matrix<T, 5, 1, rotgen::ColMajor> b9{0.25, 0.5, 1, 2, 4}; rotgen::matrix<T, 5, 1, rotgen::ColMajor> b9{0.25, 0.5, 1, 2, 4};
TTS_EQUAL(rows(b9), rotgen::Index{5}); TTS_EQUAL(b9.rows(), rotgen::Index{5});
TTS_EQUAL(cols(b9), rotgen::Index{1}); TTS_EQUAL(b9.cols(), rotgen::Index{1});
T i = 0.25; T i = 0.25;
for (rotgen::Index r = 0; r < rows(b9); ++r) for (rotgen::Index r = 0; r < b9.rows(); ++r)
{ {
TTS_EQUAL(b9(r, 0), i); TTS_EQUAL(b9(r, 0), i);
i *= 2; i *= 2;
} }
rotgen::matrix<T, 1, 3, rotgen::RowMajor> b13{1.2, 2.3, 3.4}; rotgen::matrix<T, 1, 3, rotgen::RowMajor> b13{1.2, 2.3, 3.4};
TTS_EQUAL(rows(b13), rotgen::Index{1}); TTS_EQUAL(b13.rows(), rotgen::Index{1});
TTS_EQUAL(cols(b13), rotgen::Index{3}); TTS_EQUAL(b13.cols(), rotgen::Index{3});
TTS_EQUAL(b13(0), T(1.2)); TTS_EQUAL(b13(0), T(1.2));
TTS_EQUAL(b13(1), T(2.3)); TTS_EQUAL(b13(1), T(2.3));
TTS_EQUAL(b13(2), T(3.4)); TTS_EQUAL(b13(2), T(3.4));
@ -201,16 +201,16 @@ TTS_CASE_TPL("Constructor from Initializer list of rows", rotgen::tests::types)
<typename T, typename O>(tts::type<tts::types<T, O>>) <typename T, typename O>(tts::type<tts::types<T, O>>)
{ {
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> b1{{3.5}}; rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> b1{{3.5}};
TTS_EQUAL(rows(b1), rotgen::Index{1}); TTS_EQUAL(b1.rows(), rotgen::Index{1});
TTS_EQUAL(cols(b1), rotgen::Index{1}); TTS_EQUAL(b1.cols(), rotgen::Index{1});
TTS_EQUAL(b1(0, 0), T(3.5)); TTS_EQUAL(b1(0, 0), T(3.5));
rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> b23{ rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value> b23{
{1.2, 2.3, 3.4}, {1.2, 2.3, 3.4},
{10, 200, 3000}}; {10, 200, 3000}};
TTS_EQUAL(rows(b23), rotgen::Index{2}); TTS_EQUAL(b23.rows(), rotgen::Index{2});
TTS_EQUAL(cols(b23), rotgen::Index{3}); TTS_EQUAL(b23.cols(), rotgen::Index{3});
TTS_EQUAL(b23(0, 0), T(1.2)); TTS_EQUAL(b23(0, 0), T(1.2));
TTS_EQUAL(b23(0, 1), T(2.3)); TTS_EQUAL(b23(0, 1), T(2.3));
TTS_EQUAL(b23(0, 2), T(3.4)); TTS_EQUAL(b23(0, 2), T(3.4));

View file

@ -11,9 +11,9 @@
#include "unit/common/references.hpp" #include "unit/common/references.hpp"
#include "unit/tests.hpp" #include "unit/tests.hpp"
TTS_CASE_TPL("Test dynamic matrix cwise operations", rotgen::tests::types) TTS_CASE_TPL("Test dynamic matrix cwise operations",
rotgen::tests::types)<typename T, typename O>(
<typename T, typename O>(tts::type<tts::types<T, O>>) tts::type<tts::types<T, O>>)
{ {
auto const cases = rotgen::tests::generate_matrix_references(); auto const cases = rotgen::tests::generate_matrix_references();
for (auto const& [rows, cols, fn] : cases) for (auto const& [rows, cols, fn] : cases)
@ -25,15 +25,15 @@ TTS_CASE_TPL("Test dynamic matrix cwise operations", rotgen::tests::types)
} }
}; };
TTS_CASE_TPL("Test static matrix cwise operations", rotgen::tests::types) TTS_CASE_TPL("Test static matrix cwise operations",
rotgen::tests::types)<typename T, typename O>(
<typename T, typename O>(tts::type<tts::types<T, O>>) tts::type<tts::types<T, O>>)
{ {
auto const cases = rotgen::tests::generate_static_matrix_references(); auto const cases = rotgen::tests::generate_static_matrix_references();
auto process = []<typename D>(D const& desc) { auto process = []<typename D>(D const& desc) {
rotgen::matrix<T, D::rows, D::cols, O::value> input; rotgen::matrix<T, D::rows, D::cols, O::value> input;
rotgen::tests::prepare(rows(input), cols(input), desc.init_fn, input); rotgen::tests::prepare(input.rows(), input.cols(), desc.init_fn, input);
rotgen::tests::check_cwise_functions(input); rotgen::tests::check_cwise_functions(input);
}; };

View file

@ -10,9 +10,9 @@
#include "unit/common/references.hpp" #include "unit/common/references.hpp"
#include "unit/tests.hpp" #include "unit/tests.hpp"
TTS_CASE_TPL("Test dynamic matrix inverse", rotgen::tests::types) TTS_CASE_TPL("Test dynamic matrix inverse",
rotgen::tests::types)<typename T, typename O>(
<typename T, typename O>(tts::type<tts::types<T, O>>) tts::type<tts::types<T, O>>)
{ {
using mat_t = rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value>; using mat_t = rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value>;
auto eps = std::numeric_limits<T>::epsilon(); auto eps = std::numeric_limits<T>::epsilon();
@ -23,7 +23,7 @@ TTS_CASE_TPL("Test dynamic matrix inverse", rotgen::tests::types)
auto inv = rotgen::inverse(input); auto inv = rotgen::inverse(input);
auto rec = input * inv; auto rec = input * inv;
auto id = rotgen::setIdentity<mat_t>(rotgen::rows(rec), rotgen::cols(rec)); auto id = mat_t::Identity(rotgen::rows(rec), rotgen::cols(rec));
auto error = rec - id; auto error = rec - id;
TTS_LESS_EQUAL(rotgen::maxCoeff(rotgen::abs(error)) / eps, 256.) TTS_LESS_EQUAL(rotgen::maxCoeff(rotgen::abs(error)) / eps, 256.)
@ -43,7 +43,7 @@ template<typename T, typename O, int N> void check_static_inverse()
auto inv = rotgen::inverse(input); auto inv = rotgen::inverse(input);
auto rec = input * inv; auto rec = input * inv;
auto id = rotgen::setIdentity<mat_t>(rotgen::rows(rec), rotgen::cols(rec)); auto id = mat_t::Identity(rotgen::rows(rec), rotgen::cols(rec));
auto error = rec - id; auto error = rec - id;
TTS_LESS_EQUAL(rotgen::maxCoeff(rotgen::abs(error)) / eps, 256.) TTS_LESS_EQUAL(rotgen::maxCoeff(rotgen::abs(error)) / eps, 256.)
@ -53,9 +53,9 @@ template<typename T, typename O, int N> void check_static_inverse()
<< error << "\n"; << error << "\n";
} }
TTS_CASE_TPL("Test static matrix inverse", rotgen::tests::types) TTS_CASE_TPL("Test static matrix inverse",
rotgen::tests::types)<typename T, typename O>(
<typename T, typename O>(tts::type<tts::types<T, O>>) tts::type<tts::types<T, O>>)
{ {
check_static_inverse<T, O, 2>(); check_static_inverse<T, O, 2>();
check_static_inverse<T, O, 3>(); check_static_inverse<T, O, 3>();

View file

@ -11,9 +11,9 @@
#include "unit/common/references.hpp" #include "unit/common/references.hpp"
#include "unit/tests.hpp" #include "unit/tests.hpp"
TTS_CASE_TPL("Test dynamic matrix norm operations", rotgen::tests::types) TTS_CASE_TPL("Test dynamic matrix norm operations",
rotgen::tests::types)<typename T, typename O>(
<typename T, typename O>(tts::type<tts::types<T, O>>) tts::type<tts::types<T, O>>)
{ {
auto const cases = rotgen::tests::generate_matrix_references(); auto const cases = rotgen::tests::generate_matrix_references();
for (auto const& [rows, cols, fn] : cases) for (auto const& [rows, cols, fn] : cases)
@ -25,15 +25,15 @@ TTS_CASE_TPL("Test dynamic matrix norm operations", rotgen::tests::types)
} }
}; };
TTS_CASE_TPL("Test static matrix norm operations", rotgen::tests::types) TTS_CASE_TPL("Test static matrix norm operations",
rotgen::tests::types)<typename T, typename O>(
<typename T, typename O>(tts::type<tts::types<T, O>>) tts::type<tts::types<T, O>>)
{ {
auto const cases = rotgen::tests::generate_static_matrix_references(); auto const cases = rotgen::tests::generate_static_matrix_references();
auto process = []<typename D>(D const& desc) { auto process = []<typename D>(D const& desc) {
rotgen::matrix<T, D::rows, D::cols, O::value> input; rotgen::matrix<T, D::rows, D::cols, O::value> input;
rotgen::tests::prepare(rows(input), cols(input), desc.init_fn, input); rotgen::tests::prepare(input.rows(), input.cols(), desc.init_fn, input);
rotgen::tests::check_norms_functions(input); rotgen::tests::check_norms_functions(input);
}; };

View file

@ -10,20 +10,20 @@
#include "unit/tests.hpp" #include "unit/tests.hpp"
template<typename MatrixType> template<typename MatrixType>
void test_matrix_operations(rotgen::Index rr, void test_matrix_operations(rotgen::Index rows,
rotgen::Index cc, rotgen::Index cols,
auto a_init_fn, auto a_init_fn,
auto b_init_fn, auto b_init_fn,
auto ops, auto ops,
auto self_ops) auto self_ops)
{ {
MatrixType a(rr, cc); MatrixType a(rows, cols);
MatrixType b(rr, cc); MatrixType b(rows, cols);
MatrixType ref(rr, cc); MatrixType ref(rows, cols);
for (rotgen::Index r = 0; r < rr; ++r) for (rotgen::Index r = 0; r < rows; ++r)
{ {
for (rotgen::Index c = 0; c < cc; ++c) for (rotgen::Index c = 0; c < cols; ++c)
{ {
a(r, c) = a_init_fn(r, c); a(r, c) = a_init_fn(r, c);
b(r, c) = b_init_fn(r, c); b(r, c) = b_init_fn(r, c);
@ -40,19 +40,19 @@ void test_matrix_operations(rotgen::Index rr,
} }
template<typename MatrixType> template<typename MatrixType>
void test_scalar_operations(rotgen::Index rr, void test_scalar_operations(rotgen::Index rows,
rotgen::Index cc, rotgen::Index cols,
auto a_init_fn, auto a_init_fn,
auto s, auto s,
auto ops, auto ops,
auto self_ops) auto self_ops)
{ {
MatrixType a(rr, cc); MatrixType a(rows, cols);
MatrixType ref(rr, cc); MatrixType ref(rows, cols);
for (rotgen::Index r = 0; r < rr; ++r) for (rotgen::Index r = 0; r < rows; ++r)
{ {
for (rotgen::Index c = 0; c < cc; ++c) for (rotgen::Index c = 0; c < cols; ++c)
{ {
a(r, c) = a_init_fn(r, c); a(r, c) = a_init_fn(r, c);
ref(r, c) = ops(a(r, c), s); ref(r, c) = ops(a(r, c), s);
@ -68,17 +68,17 @@ void test_scalar_operations(rotgen::Index rr,
} }
template<typename MatrixType> template<typename MatrixType>
void test_scalar_multiplications(rotgen::Index rr, void test_scalar_multiplications(rotgen::Index rows,
rotgen::Index cc, rotgen::Index cols,
auto fn, auto fn,
auto s) auto s)
{ {
MatrixType a(rr, cc); MatrixType a(rows, cols);
MatrixType ref(rr, cc); MatrixType ref(rows, cols);
for (rotgen::Index r = 0; r < rr; ++r) for (rotgen::Index r = 0; r < rows; ++r)
{ {
for (rotgen::Index c = 0; c < cc; ++c) for (rotgen::Index c = 0; c < cols; ++c)
{ {
a(r, c) = fn(r, c); a(r, c) = fn(r, c);
ref(r, c) = a(r, c) * s; ref(r, c) = a(r, c) * s;
@ -96,27 +96,27 @@ void test_scalar_multiplications(rotgen::Index rr,
} }
template<typename MatrixType> template<typename MatrixType>
void test_matrix_multiplication(rotgen::Index rr, void test_matrix_multiplication(rotgen::Index rows,
rotgen::Index cc, rotgen::Index cols,
auto a_init_fn, auto a_init_fn,
auto b_init_fn) auto b_init_fn)
{ {
MatrixType a(rr, cc); MatrixType a(rows, cols);
MatrixType b(cc, rr); MatrixType b(cols, rows);
MatrixType ref(rr, rr); MatrixType ref(rows, rows);
for (rotgen::Index r = 0; r < rows(a); ++r) for (rotgen::Index r = 0; r < a.rows(); ++r)
for (rotgen::Index c = 0; c < cols(a); ++c) a(r, c) = a_init_fn(r, c); for (rotgen::Index c = 0; c < a.cols(); ++c) a(r, c) = a_init_fn(r, c);
for (rotgen::Index r = 0; r < rows(b); ++r) for (rotgen::Index r = 0; r < b.rows(); ++r)
for (rotgen::Index c = 0; c < cols(b); ++c) b(r, c) = b_init_fn(r, c); for (rotgen::Index c = 0; c < b.cols(); ++c) b(r, c) = b_init_fn(r, c);
for (rotgen::Index i = 0; i < rows(a); ++i) for (rotgen::Index i = 0; i < a.rows(); ++i)
{ {
for (rotgen::Index j = 0; j < cols(b); ++j) for (rotgen::Index j = 0; j < b.cols(); ++j)
{ {
ref(i, j) = 0; ref(i, j) = 0;
for (rotgen::Index k = 0; k < cols(a); ++k) for (rotgen::Index k = 0; k < a.cols(); ++k)
ref(i, j) += a(i, k) * b(k, j); ref(i, j) += a(i, k) * b(k, j);
} }
} }
@ -134,9 +134,9 @@ inline constexpr auto init_b = [](auto r, auto c) {
}; };
inline constexpr auto init_0 = [](auto, auto) { return 0; }; inline constexpr auto init_0 = [](auto, auto) { return 0; };
TTS_CASE_TPL("Check matrix addition", rotgen::tests::types) TTS_CASE_TPL("Check matrix addition",
rotgen::tests::types)<typename T, typename O>(
<typename T, typename O>(tts::type<tts::types<T, O>>) tts::type<tts::types<T, O>>)
{ {
using mat_t = rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value>; using mat_t = rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value>;
auto op = [](auto a, auto b) { return a + b; }; auto op = [](auto a, auto b) { return a + b; };
@ -153,9 +153,9 @@ TTS_CASE_TPL("Check matrix addition", rotgen::tests::types)
test_matrix_operations<mat_t>(5, 5, init_a, init_0, op, s_op); test_matrix_operations<mat_t>(5, 5, init_a, init_0, op, s_op);
}; };
TTS_CASE_TPL("Check matrix substraction", rotgen::tests::types) TTS_CASE_TPL("Check matrix substraction",
rotgen::tests::types)<typename T, typename O>(
<typename T, typename O>(tts::type<tts::types<T, O>>) tts::type<tts::types<T, O>>)
{ {
using mat_t = rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value>; using mat_t = rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value>;
auto op = [](auto a, auto b) { return a - b; }; auto op = [](auto a, auto b) { return a - b; };
@ -172,9 +172,9 @@ TTS_CASE_TPL("Check matrix substraction", rotgen::tests::types)
test_matrix_operations<mat_t>(5, 5, init_a, init_0, op, s_op); test_matrix_operations<mat_t>(5, 5, init_a, init_0, op, s_op);
}; };
TTS_CASE_TPL("Check matrix multiplications", rotgen::tests::types) TTS_CASE_TPL("Check matrix multiplications",
rotgen::tests::types)<typename T, typename O>(
<typename T, typename O>(tts::type<tts::types<T, O>>) tts::type<tts::types<T, O>>)
{ {
using mat_t = rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value>; using mat_t = rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value>;
auto init_id = [](auto r, auto c) { return r == c ? 1 : 0; }; auto init_id = [](auto r, auto c) { return r == c ? 1 : 0; };
@ -193,9 +193,9 @@ TTS_CASE_TPL("Check matrix multiplications", rotgen::tests::types)
test_matrix_multiplication<mat_t>(5, 5, init_a, init_0); test_matrix_multiplication<mat_t>(5, 5, init_a, init_0);
}; };
TTS_CASE_TPL("Check matrix multiplication with scalar", rotgen::tests::types) TTS_CASE_TPL("Check matrix multiplication with scalar",
rotgen::tests::types)<typename T, typename O>(
<typename T, typename O>(tts::type<tts::types<T, O>>) tts::type<tts::types<T, O>>)
{ {
using mat_t = rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value>; using mat_t = rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value>;
@ -209,9 +209,9 @@ TTS_CASE_TPL("Check matrix multiplication with scalar", rotgen::tests::types)
test_scalar_multiplications<mat_t>(1, 10, init_a, T{-0.5}); test_scalar_multiplications<mat_t>(1, 10, init_a, T{-0.5});
}; };
TTS_CASE_TPL("Check matrix division with scalar", rotgen::tests::types) TTS_CASE_TPL("Check matrix division with scalar",
rotgen::tests::types)<typename T, typename O>(
<typename T, typename O>(tts::type<tts::types<T, O>>) tts::type<tts::types<T, O>>)
{ {
using mat_t = rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value>; using mat_t = rotgen::matrix<T, rotgen::Dynamic, rotgen::Dynamic, O::value>;
auto op = [](auto a, auto b) { return a / b; }; auto op = [](auto a, auto b) { return a / b; };

View file

@ -22,7 +22,7 @@ template<typename Ref, typename Generator> void check_acceptance(Generator f)
TTS_EQUAL(v.data(), ptr); TTS_EQUAL(v.data(), ptr);
// Setup the data correctly // Setup the data correctly
data.resize(rows(v), cols(v)); data.resize(v.rows(), v.cols());
rotgen::setRandom(data); rotgen::setRandom(data);
// Assign through the ref // Assign through the ref
@ -34,7 +34,7 @@ template<typename Ref, typename Generator> void check_acceptance(Generator f)
}; };
acceptor(in, in.data()); acceptor(in, in.data());
data.resize(rows(in), cols(in)); data.resize(in.rows(), in.cols());
TTS_EQUAL(in, data); TTS_EQUAL(in, data);
TTS_EQUAL(constant_acceptor(in), minCoeff(data)) << in << "\n" TTS_EQUAL(constant_acceptor(in), minCoeff(data)) << in << "\n"