Implements block typs and related functions - First part
Co-authored-by: Karen <kkaspar@codereckons.com> Co-authored-by: Joel FALCOU <jfalcou@codereckons.com> See merge request oss/rotgen!9
This commit is contained in:
parent
09be3b4b15
commit
c6b864f247
28 changed files with 1814 additions and 114 deletions
197
include/rotgen/block.hpp
Normal file
197
include/rotgen/block.hpp
Normal file
|
|
@ -0,0 +1,197 @@
|
|||
//==================================================================================================
|
||||
/*
|
||||
ROTGEN - Runtime Overlay for Eigen
|
||||
Copyright : CODE RECKONS
|
||||
SPDX-License-Identifier: BSL-1.0
|
||||
*/
|
||||
//==================================================================================================
|
||||
#pragma once
|
||||
|
||||
#include <rotgen/impl/block.hpp>
|
||||
#include <rotgen/matrix.hpp>
|
||||
#include <initializer_list>
|
||||
#include <cassert>
|
||||
|
||||
namespace rotgen
|
||||
{
|
||||
template<typename Ref, int Rows = Dynamic, int Cols = Dynamic, bool Inner = false, int ForceStorageOrder = -1>
|
||||
class block : public find_block<Ref>
|
||||
{
|
||||
using parent = find_block<Ref>;
|
||||
public:
|
||||
using scalar_type = typename Ref::scalar_type;
|
||||
static constexpr int storage_order = (ForceStorageOrder == -1) ? Ref::storage_order : ForceStorageOrder;
|
||||
using concrete_type = matrix<scalar_type,Rows,Cols,storage_order>;
|
||||
|
||||
static constexpr int RowsAtCompileTime = Rows;
|
||||
static constexpr int ColsAtCompileTime = Cols;
|
||||
|
||||
block(Ref& r, std::size_t i0, std::size_t j0, std::size_t ni, std::size_t nj) : parent(r,i0,j0,ni,nj)
|
||||
{}
|
||||
|
||||
block(Ref& r, std::size_t i0, std::size_t j0) requires(Rows != -1 && Cols != -1)
|
||||
: parent(r,i0,j0,Rows,Cols)
|
||||
{}
|
||||
|
||||
block(parent const& base) : parent(base) {}
|
||||
|
||||
/*
|
||||
block transpose() const
|
||||
{
|
||||
return block(static_cast<parent const&>(*this).transpose());
|
||||
}
|
||||
|
||||
block conjugate() const
|
||||
{
|
||||
return block(static_cast<parent const&>(*this).conjugate());
|
||||
}
|
||||
|
||||
block adjoint() const
|
||||
{
|
||||
return block(static_cast<parent const&>(*this).adjoint());
|
||||
}
|
||||
*/
|
||||
|
||||
friend bool operator==(block const& lhs, block const& rhs)
|
||||
{
|
||||
return static_cast<parent const&>(lhs) == static_cast<parent const&>(rhs);
|
||||
}
|
||||
|
||||
block& operator+=(block const& rhs)
|
||||
{
|
||||
static_cast<parent&>(*this) += static_cast<parent const&>(rhs);
|
||||
return *this;
|
||||
}
|
||||
|
||||
block& operator-=(block const& rhs)
|
||||
{
|
||||
static_cast<parent&>(*this) -= static_cast<parent const&>(rhs);
|
||||
return *this;
|
||||
}
|
||||
|
||||
concrete_type operator-() const
|
||||
{
|
||||
return concrete_type(static_cast<parent const&>(*this).operator-());
|
||||
}
|
||||
|
||||
block& operator*=(block const& rhs)
|
||||
{
|
||||
static_cast<parent&>(*this) *= static_cast<parent const&>(rhs);
|
||||
return *this;
|
||||
}
|
||||
|
||||
block& operator*=(scalar_type rhs)
|
||||
{
|
||||
static_cast<parent&>(*this) *= rhs;
|
||||
return *this;
|
||||
}
|
||||
|
||||
block& operator/=(scalar_type rhs)
|
||||
{
|
||||
static_cast<parent&>(*this) /= rhs;
|
||||
return *this;
|
||||
}
|
||||
|
||||
static concrete_type Zero()
|
||||
requires (Rows != -1 && Cols != -1)
|
||||
{
|
||||
return parent::Zero(Rows, Cols);
|
||||
}
|
||||
|
||||
static concrete_type Zero(int rows, int cols)
|
||||
{
|
||||
if constexpr(Rows != -1) assert(rows == Rows && "Mismatched between dynamic and static row size");
|
||||
if constexpr(Cols != -1) assert(cols == Cols && "Mismatched between dynamic and static column size");
|
||||
return parent::Zero(rows, cols);
|
||||
}
|
||||
|
||||
static concrete_type Constant(scalar_type value)
|
||||
requires (Rows != -1 && Cols != -1)
|
||||
{
|
||||
return parent::Constant(Rows, Cols, static_cast<double>(value));
|
||||
}
|
||||
|
||||
static concrete_type Constant(int rows, int cols, scalar_type value)
|
||||
{
|
||||
if constexpr(Rows != -1) assert(rows == Rows && "Mismatched between dynamic and static row size");
|
||||
if constexpr(Cols != -1) assert(cols == Cols && "Mismatched between dynamic and static column size");
|
||||
return parent::Constant(rows, cols, static_cast<double>(value));
|
||||
}
|
||||
|
||||
static concrete_type Random()
|
||||
requires (Rows != -1 && Cols != -1)
|
||||
{
|
||||
return parent::Random(Rows, Cols);
|
||||
}
|
||||
|
||||
static concrete_type Random(int rows, int cols)
|
||||
{
|
||||
if constexpr(Rows != -1) assert(rows == Rows && "Mismatched between dynamic and static row size");
|
||||
if constexpr(Cols != -1) assert(cols == Cols && "Mismatched between dynamic and static column size");
|
||||
return parent::Random(rows, cols);
|
||||
}
|
||||
|
||||
static concrete_type Identity()
|
||||
requires (Rows != -1 && Cols != -1)
|
||||
{
|
||||
return parent::Identity(Rows, Cols);
|
||||
}
|
||||
|
||||
static concrete_type Identity(int rows, int cols)
|
||||
{
|
||||
if constexpr(Rows != -1) assert(rows == Rows && "Mismatched between dynamic and static row size");
|
||||
if constexpr(Cols != -1) assert(cols == Cols && "Mismatched between dynamic and static column size");
|
||||
return parent::Identity(rows, cols);
|
||||
}
|
||||
|
||||
template<int P>
|
||||
double lpNorm() const
|
||||
{
|
||||
assert(P == 1 || P == 2 || P == Infinity);
|
||||
return parent::lpNorm(P);
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
template<typename S, int R, int C, int O, int MR, int MC>
|
||||
block<S,R,C,O,MR,MC> operator+(block<S,R,C,O,MR,MC> const& lhs, block<S,R,C,O,MR,MC> const& rhs)
|
||||
{
|
||||
block<S,R,C,O,MR,MC> that(lhs);
|
||||
return that += rhs;
|
||||
}
|
||||
|
||||
template<typename S, int R, int C, int O, int MR, int MC>
|
||||
block<S,R,C,O,MR,MC> operator-(block<S,R,C,O,MR,MC> const& lhs, block<S,R,C,O,MR,MC> const& rhs)
|
||||
{
|
||||
block<S,R,C,O,MR,MC> that(lhs);
|
||||
return that -= rhs;
|
||||
}
|
||||
|
||||
template<typename S, int R, int C, int O, int MR, int MC>
|
||||
block<S,R,C,O,MR,MC> operator*(block<S,R,C,O,MR,MC> const& lhs, block<S,R,C,O,MR,MC> const& rhs)
|
||||
{
|
||||
block<S,R,C,O,MR,MC> that(lhs);
|
||||
return that *= rhs;
|
||||
}
|
||||
|
||||
template<typename S, int R, int C, int O, int MR, int MC>
|
||||
block<S,R,C,O,MR,MC> operator*(block<S,R,C,O,MR,MC> const& lhs, double rhs)
|
||||
{
|
||||
block<S,R,C,O,MR,MC> that(lhs);
|
||||
return that *= rhs;
|
||||
}
|
||||
|
||||
template<typename S, int R, int C, int O, int MR, int MC>
|
||||
block<S,R,C,O,MR,MC> operator*(double lhs, block<S,R,C,O,MR,MC> const& rhs)
|
||||
{
|
||||
return rhs * lhs;
|
||||
}
|
||||
|
||||
template<typename S, int R, int C, int O, int MR, int MC>
|
||||
block<S,R,C,O,MR,MC> operator/(block<S,R,C,O,MR,MC> const& lhs, double rhs)
|
||||
{
|
||||
block<S,R,C,O,MR,MC> that(lhs);
|
||||
return that /= rhs;
|
||||
}
|
||||
*/
|
||||
}
|
||||
235
include/rotgen/extract.hpp
Normal file
235
include/rotgen/extract.hpp
Normal file
|
|
@ -0,0 +1,235 @@
|
|||
//==================================================================================================
|
||||
/*
|
||||
ROTGEN - Runtime Overlay for Eigen
|
||||
Copyright : CODE RECKONS
|
||||
SPDX-License-Identifier: BSL-1.0
|
||||
*/
|
||||
//==================================================================================================
|
||||
#pragma once
|
||||
|
||||
#include <rotgen/matrix.hpp>
|
||||
#include <rotgen/block.hpp>
|
||||
|
||||
namespace rotgen
|
||||
{
|
||||
template< typename S, int R , int C
|
||||
, int Opts , int MaxR, int MaxC
|
||||
>
|
||||
auto extract(matrix<S,R,C,Opts,MaxR,MaxC>& m, int i0, int j0,int ni, int nj)
|
||||
{
|
||||
using base = matrix<S,R,C,Opts,MaxR,MaxC>;
|
||||
return block<base>(m, i0,j0,ni,nj);
|
||||
}
|
||||
|
||||
template< int NI, int NJ
|
||||
, typename S, int R , int C
|
||||
, int Opts , int MaxR, int MaxC
|
||||
>
|
||||
auto extract(matrix<S,R,C,Opts,MaxR,MaxC>& m, int i0, int j0)
|
||||
{
|
||||
using base = matrix<S,R,C,Opts,MaxR,MaxC>;
|
||||
return block<base,NI,NJ>(m,i0,j0);
|
||||
}
|
||||
|
||||
template< typename S, int R , int C
|
||||
, int Opts , int MaxR, int MaxC
|
||||
>
|
||||
auto topLeftCorner(matrix<S,R,C,Opts,MaxR,MaxC>& m, int ni, int nj)
|
||||
{
|
||||
using base = matrix<S,R,C,Opts,MaxR,MaxC>;
|
||||
return block<base>(m,0,0,ni,nj);
|
||||
}
|
||||
|
||||
template< typename S, int R , int C
|
||||
, int Opts , int MaxR, int MaxC
|
||||
>
|
||||
auto topRightCorner(matrix<S,R,C,Opts,MaxR,MaxC>& m, int ni, int nj)
|
||||
{
|
||||
using base = matrix<S,R,C,Opts,MaxR,MaxC>;
|
||||
return block<base>(m,0,m.cols()-nj,ni,nj);
|
||||
}
|
||||
|
||||
template< typename S, int R , int C
|
||||
, int Opts , int MaxR, int MaxC
|
||||
>
|
||||
auto bottomLeftCorner(matrix<S,R,C,Opts,MaxR,MaxC>& m, int ni, int nj)
|
||||
{
|
||||
using base = matrix<S,R,C,Opts,MaxR,MaxC>;
|
||||
return block<base>(m,m.rows()-ni,0,ni,nj);
|
||||
}
|
||||
|
||||
template< typename S, int R , int C
|
||||
, int Opts , int MaxR, int MaxC
|
||||
>
|
||||
auto bottomRightCorner(matrix<S,R,C,Opts,MaxR,MaxC>& m, int ni, int nj)
|
||||
{
|
||||
using base = matrix<S,R,C,Opts,MaxR,MaxC>;
|
||||
return block<base>(m,m.rows()-ni,m.cols()-nj,ni,nj);
|
||||
}
|
||||
|
||||
template< typename S, int R , int C
|
||||
, int Opts , int MaxR, int MaxC
|
||||
>
|
||||
auto topRows(matrix<S,R,C,Opts,MaxR,MaxC>& m, int ni)
|
||||
{
|
||||
using base = matrix<S,R,C,Opts,MaxR,MaxC>;
|
||||
return block<base>(m,0,0,ni,m.cols());
|
||||
}
|
||||
|
||||
template< typename S, int R , int C,
|
||||
int Opts , int MaxR, int MaxC
|
||||
>
|
||||
auto middleRows(matrix<S,R,C,Opts,MaxR,MaxC>& m, int i0, int ni)
|
||||
{
|
||||
using base = matrix<S,R,C,Opts,MaxR,MaxC>;
|
||||
return block<base>(m,i0,0,ni,m.cols());
|
||||
}
|
||||
|
||||
template< typename S, int R , int C
|
||||
, int Opts , int MaxR, int MaxC
|
||||
>
|
||||
auto bottomRows(matrix<S,R,C,Opts,MaxR,MaxC>& m, int ni)
|
||||
{
|
||||
using base = matrix<S,R,C,Opts,MaxR,MaxC>;
|
||||
return block<base>(m,m.rows()-ni,0,ni,m.cols());
|
||||
}
|
||||
|
||||
template< typename S, int R , int C
|
||||
, int Opts , int MaxR, int MaxC
|
||||
>
|
||||
auto leftCols(matrix<S,R,C,Opts,MaxR,MaxC>& m, int nj)
|
||||
{
|
||||
using base = matrix<S,R,C,Opts,MaxR,MaxC>;
|
||||
return block<base>(m,0,0,m.rows(),nj);
|
||||
}
|
||||
|
||||
template< typename S, int R , int C,
|
||||
int Opts , int MaxR, int MaxC
|
||||
>
|
||||
auto middleCols(matrix<S,R,C,Opts,MaxR,MaxC>& m, int j0, int nj)
|
||||
{
|
||||
using base = matrix<S,R,C,Opts,MaxR,MaxC>;
|
||||
return block<base>(m,0,j0,m.rows(),nj);
|
||||
}
|
||||
|
||||
template< typename S, int R , int C
|
||||
, int Opts , int MaxR, int MaxC
|
||||
>
|
||||
auto rightCols(matrix<S,R,C,Opts,MaxR,MaxC>& m, int nj)
|
||||
{
|
||||
using base = matrix<S,R,C,Opts,MaxR,MaxC>;
|
||||
return block<base>(m,0,m.cols()-nj,m.rows(),nj);
|
||||
}
|
||||
|
||||
template< typename S, int R, int C
|
||||
, int Opts , int MaxR, int MaxC
|
||||
>
|
||||
auto row(matrix<S,R,C,Opts,MaxR,MaxC>& m, int i0)
|
||||
{
|
||||
using base = matrix<S,R,C,Opts,MaxR,MaxC>;
|
||||
return block<base,1, -1, false, 1>(m,i0,0, 1, m.cols());
|
||||
}
|
||||
|
||||
template< typename S, int R, int C
|
||||
, int Opts , int MaxR, int MaxC
|
||||
>
|
||||
auto col(matrix<S,R,C,Opts,MaxR,MaxC>& m, int j0)
|
||||
{
|
||||
using base = matrix<S,R,C,Opts,MaxR,MaxC>;
|
||||
return block<base,-1,1, false, 0>(m,0,j0, m.rows(), 1);
|
||||
}
|
||||
|
||||
template< int NI, typename S, int R, int C,
|
||||
int Opts, int MaxR, int MaxC
|
||||
>
|
||||
auto topRows(matrix<S,R,C,Opts,MaxR,MaxC>& m)
|
||||
{
|
||||
using base = matrix<S,R,C,Opts,MaxR,MaxC>;
|
||||
return block<base,NI,-1>(m,0,0, NI, m.cols());
|
||||
}
|
||||
|
||||
template< int NI, typename S, int R, int C,
|
||||
int Opts, int MaxR, int MaxC
|
||||
>
|
||||
auto bottomRows(matrix<S,R,C,Opts,MaxR,MaxC>& m)
|
||||
{
|
||||
using base = matrix<S,R,C,Opts,MaxR,MaxC>;
|
||||
return block<base,NI,-1>(m,m.rows()-NI,0, NI, m.cols());
|
||||
}
|
||||
|
||||
template< int NI, typename S, int R, int C,
|
||||
int Opts , int MaxR, int MaxC
|
||||
>
|
||||
auto middleRows(matrix<S,R,C,Opts,MaxR,MaxC>& m, int i0)
|
||||
{
|
||||
using base = matrix<S,R,C,Opts,MaxR,MaxC>;
|
||||
return block<base,NI,-1>(m,i0,0, NI, m.cols());
|
||||
}
|
||||
|
||||
template< int NJ, typename S, int R, int C,
|
||||
int Opts, int MaxR, int MaxC
|
||||
>
|
||||
auto leftCols(matrix<S,R,C,Opts,MaxR,MaxC>& m)
|
||||
{
|
||||
using base = matrix<S,R,C,Opts,MaxR,MaxC>;
|
||||
return block<base,-1,NJ>(m,0,0, m.rows(), NJ);
|
||||
}
|
||||
|
||||
template< int NJ, typename S, int R, int C,
|
||||
int Opts, int MaxR, int MaxC
|
||||
>
|
||||
auto rightCols(matrix<S,R,C,Opts,MaxR,MaxC>& m)
|
||||
{
|
||||
using base = matrix<S,R,C,Opts,MaxR,MaxC>;
|
||||
return block<base,-1,NJ>(m,0,m.cols()-NJ, m.rows(), NJ);
|
||||
}
|
||||
|
||||
template< int NJ, typename S, int R, int C,
|
||||
int Opts , int MaxR, int MaxC
|
||||
>
|
||||
auto middleCols(matrix<S,R,C,Opts,MaxR,MaxC>& m, int j0)
|
||||
{
|
||||
using base = matrix<S,R,C,Opts,MaxR,MaxC>;
|
||||
return block<base,-1,NJ>(m,0,j0, m.rows(), NJ);
|
||||
}
|
||||
|
||||
template< int NI, int NJ
|
||||
, typename S, int R , int C
|
||||
, int Opts , int MaxR, int MaxC
|
||||
>
|
||||
auto topLeftCorner(matrix<S,R,C,Opts,MaxR,MaxC>& m)
|
||||
{
|
||||
using base = matrix<S,R,C,Opts,MaxR,MaxC>;
|
||||
return block<base,NI,NJ>(m,0,0);
|
||||
}
|
||||
|
||||
template< int NI, int NJ
|
||||
, typename S, int R , int C
|
||||
, int Opts , int MaxR, int MaxC
|
||||
>
|
||||
auto topRightCorner(matrix<S,R,C,Opts,MaxR,MaxC>& m)
|
||||
{
|
||||
using base = matrix<S,R,C,Opts,MaxR,MaxC>;
|
||||
return block<base,NI,NJ>(m,0,m.cols()-NJ);
|
||||
}
|
||||
|
||||
template< int NI, int NJ
|
||||
, typename S, int R , int C
|
||||
, int Opts , int MaxR, int MaxC
|
||||
>
|
||||
auto bottomLeftCorner(matrix<S,R,C,Opts,MaxR,MaxC>& m)
|
||||
{
|
||||
using base = matrix<S,R,C,Opts,MaxR,MaxC>;
|
||||
return block<base,NI,NJ>(m,m.rows()-NI,0);
|
||||
}
|
||||
|
||||
template< int NI, int NJ
|
||||
, typename S, int R , int C
|
||||
, int Opts , int MaxR, int MaxC
|
||||
>
|
||||
auto bottomRightCorner(matrix<S,R,C,Opts,MaxR,MaxC>& m)
|
||||
{
|
||||
using base = matrix<S,R,C,Opts,MaxR,MaxC>;
|
||||
return block<base,NI,NJ>(m,m.rows()-NI,m.cols()-NJ);
|
||||
}
|
||||
}
|
||||
64
include/rotgen/impl/block.hpp
Normal file
64
include/rotgen/impl/block.hpp
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
//==================================================================================================
|
||||
/*
|
||||
ROTGEN - Runtime Overlay for Eigen
|
||||
Copyright : CODE RECKONS
|
||||
SPDX-License-Identifier: BSL-1.0
|
||||
*/
|
||||
//==================================================================================================
|
||||
#pragma once
|
||||
|
||||
#include <rotgen/detail/generators.hpp>
|
||||
#include <rotgen/detail/static_info.hpp>
|
||||
#include <rotgen/impl/matrix.hpp>
|
||||
#include <initializer_list>
|
||||
#include <cstddef>
|
||||
#include <memory>
|
||||
|
||||
namespace rotgen
|
||||
{
|
||||
#define SIZE 64
|
||||
#define TYPE double
|
||||
|
||||
#define CLASSNAME ROTGEN_MATRIX_NAME(block_impl,SIZE,_col)
|
||||
#define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_col)
|
||||
#include <rotgen/impl/block_model.hpp>
|
||||
#undef CLASSNAME
|
||||
#undef SOURCENAME
|
||||
|
||||
#define CLASSNAME ROTGEN_MATRIX_NAME(block_impl,SIZE,_row)
|
||||
#define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_row)
|
||||
#include <rotgen/impl/block_model.hpp>
|
||||
#undef CLASSNAME
|
||||
#undef SOURCENAME
|
||||
|
||||
#undef SIZE
|
||||
#undef TYPE
|
||||
|
||||
#define SIZE 32
|
||||
#define TYPE float
|
||||
|
||||
#define CLASSNAME ROTGEN_MATRIX_NAME(block_impl,SIZE,_col)
|
||||
#define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_col)
|
||||
#include <rotgen/impl/block_model.hpp>
|
||||
#undef CLASSNAME
|
||||
#undef SOURCENAME
|
||||
|
||||
#define CLASSNAME ROTGEN_MATRIX_NAME(block_impl,SIZE,_row)
|
||||
#define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_row)
|
||||
#include <rotgen/impl/block_model.hpp>
|
||||
#undef CLASSNAME
|
||||
#undef SOURCENAME
|
||||
|
||||
#undef SIZE
|
||||
#undef TYPE
|
||||
|
||||
template<typename Scalar,int Options> struct find_block_impl;
|
||||
|
||||
template<> struct find_block_impl<float , ColMajor> { using type = block_impl32_col; };
|
||||
template<> struct find_block_impl<float , RowMajor> { using type = block_impl32_row; };
|
||||
template<> struct find_block_impl<double, ColMajor> { using type = block_impl64_col; };
|
||||
template<> struct find_block_impl<double, RowMajor> { using type = block_impl64_row; };
|
||||
|
||||
template<typename Ref>
|
||||
using find_block = typename find_block_impl<typename Ref::scalar_type, Ref::storage_order>::type;
|
||||
}
|
||||
81
include/rotgen/impl/block_model.hpp
Normal file
81
include/rotgen/impl/block_model.hpp
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
//==================================================================================================
|
||||
/*
|
||||
ROTGEN - Runtime Overlay for Eigen
|
||||
Copyright : CODE RECKONS
|
||||
SPDX-License-Identifier: BSL-1.0
|
||||
*/
|
||||
//==================================================================================================
|
||||
|
||||
//==================================================================================================
|
||||
/*
|
||||
This file is a X-File to generate various block_impl_* declarations variant
|
||||
*/
|
||||
//==================================================================================================
|
||||
class CLASSNAME
|
||||
{
|
||||
public:
|
||||
CLASSNAME(SOURCENAME& r, std::size_t i0, std::size_t j0, std::size_t ni, std::size_t nj);
|
||||
|
||||
CLASSNAME(CLASSNAME const& other);
|
||||
CLASSNAME(CLASSNAME&&) noexcept;
|
||||
|
||||
CLASSNAME& operator=(CLASSNAME const& other);
|
||||
CLASSNAME& operator=(CLASSNAME&&) noexcept;
|
||||
|
||||
~CLASSNAME();
|
||||
|
||||
std::size_t rows() const;
|
||||
std::size_t cols() const;
|
||||
std::size_t size() const;
|
||||
|
||||
// CLASSNAME transpose() const;
|
||||
// CLASSNAME conjugate() const;
|
||||
// CLASSNAME adjoint() const;
|
||||
|
||||
// void transposeInPlace();
|
||||
// void adjointInPlace();
|
||||
|
||||
TYPE sum() const;
|
||||
TYPE prod() const;
|
||||
TYPE mean() const;
|
||||
TYPE trace() const;
|
||||
TYPE maxCoeff() const;
|
||||
TYPE minCoeff() const;
|
||||
TYPE maxCoeff(std::ptrdiff_t* row, std::ptrdiff_t* col) const;
|
||||
TYPE minCoeff(std::ptrdiff_t* row, std::ptrdiff_t* col) const;
|
||||
|
||||
TYPE squaredNorm() const;
|
||||
TYPE norm() const;
|
||||
TYPE lpNorm(int p) const;
|
||||
|
||||
TYPE& operator()(std::size_t i, std::size_t j);
|
||||
TYPE const& operator()(std::size_t i, std::size_t j) const;
|
||||
|
||||
// TYPE& operator()(std::size_t index);
|
||||
// TYPE const& operator()(std::size_t index) const;
|
||||
|
||||
CLASSNAME& operator+=(CLASSNAME const& rhs);
|
||||
CLASSNAME& operator-=(CLASSNAME const& rhs);
|
||||
SOURCENAME operator-() const;
|
||||
CLASSNAME& operator*=(CLASSNAME const& rhs);
|
||||
CLASSNAME& operator*=(TYPE d);
|
||||
CLASSNAME& operator/=(TYPE d);
|
||||
|
||||
friend std::ostream& operator<<(std::ostream&,CLASSNAME const&);
|
||||
friend bool operator==(CLASSNAME const& lhs, CLASSNAME const& rhs);
|
||||
|
||||
const TYPE* data() const;
|
||||
|
||||
static SOURCENAME Zero(std::size_t r, std::size_t c) { return SOURCENAME::Zero(r,c); }
|
||||
static SOURCENAME Constant(std::size_t r, std::size_t c, TYPE v) { return SOURCENAME::Constant(r,c,v); }
|
||||
static SOURCENAME Random(std::size_t r, std::size_t c) { return SOURCENAME::Random(r,c); }
|
||||
static SOURCENAME Identity(std::size_t r, std::size_t c) { return SOURCENAME::Identity(r,c); }
|
||||
|
||||
private:
|
||||
struct payload;
|
||||
std::unique_ptr<payload> storage_;
|
||||
|
||||
public:
|
||||
std::unique_ptr<payload>& storage() { return storage_; }
|
||||
std::unique_ptr<payload> const& storage() const { return storage_; }
|
||||
};
|
||||
|
|
@ -18,13 +18,13 @@ namespace rotgen
|
|||
#define SIZE 64
|
||||
#define TYPE double
|
||||
|
||||
#define MATRIX ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_col)
|
||||
#define CLASSNAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_col)
|
||||
#include <rotgen/impl/matrix_model.hpp>
|
||||
#undef MATRIX
|
||||
#undef CLASSNAME
|
||||
|
||||
#define MATRIX ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_row)
|
||||
#define CLASSNAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_row)
|
||||
#include <rotgen/impl/matrix_model.hpp>
|
||||
#undef MATRIX
|
||||
#undef CLASSNAME
|
||||
|
||||
#undef SIZE
|
||||
#undef TYPE
|
||||
|
|
@ -32,13 +32,13 @@ namespace rotgen
|
|||
#define SIZE 32
|
||||
#define TYPE float
|
||||
|
||||
#define MATRIX ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_col)
|
||||
#define CLASSNAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_col)
|
||||
#include <rotgen/impl/matrix_model.hpp>
|
||||
#undef MATRIX
|
||||
#undef CLASSNAME
|
||||
|
||||
#define MATRIX ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_row)
|
||||
#define CLASSNAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_row)
|
||||
#include <rotgen/impl/matrix_model.hpp>
|
||||
#undef MATRIX
|
||||
#undef CLASSNAME
|
||||
|
||||
#undef SIZE
|
||||
#undef TYPE
|
||||
|
|
|
|||
|
|
@ -8,24 +8,24 @@
|
|||
|
||||
//==================================================================================================
|
||||
/*
|
||||
This file is a X-File to generate various matrix_impl_* definitions variant
|
||||
This file is a X-File to generate various matrix_impl_* declarations variant
|
||||
*/
|
||||
//==================================================================================================
|
||||
class MATRIX
|
||||
class CLASSNAME
|
||||
{
|
||||
public:
|
||||
MATRIX(std::size_t rows = 0, std::size_t cols = 0);
|
||||
MATRIX(std::size_t rows, std::size_t cols,std::initializer_list<TYPE> init);
|
||||
CLASSNAME(std::size_t rows = 0, std::size_t cols = 0);
|
||||
CLASSNAME(std::size_t rows, std::size_t cols,std::initializer_list<TYPE> init);
|
||||
|
||||
MATRIX(std::initializer_list<std::initializer_list<TYPE>> init);
|
||||
CLASSNAME(std::initializer_list<std::initializer_list<TYPE>> init);
|
||||
|
||||
MATRIX(MATRIX const& other);
|
||||
MATRIX(MATRIX&&) noexcept;
|
||||
CLASSNAME(CLASSNAME const& other);
|
||||
CLASSNAME(CLASSNAME&&) noexcept;
|
||||
|
||||
MATRIX& operator=(MATRIX const& other);
|
||||
MATRIX& operator=(MATRIX&&) noexcept;
|
||||
CLASSNAME& operator=(CLASSNAME const& other);
|
||||
CLASSNAME& operator=(CLASSNAME&&) noexcept;
|
||||
|
||||
~MATRIX();
|
||||
~CLASSNAME();
|
||||
|
||||
std::size_t rows() const;
|
||||
std::size_t cols() const;
|
||||
|
|
@ -34,9 +34,9 @@ class MATRIX
|
|||
void resize(std::size_t new_rows, std::size_t new_cols);
|
||||
void conservativeResize(std::size_t new_rows, std::size_t new_cols);
|
||||
|
||||
MATRIX transpose() const;
|
||||
MATRIX conjugate() const;
|
||||
MATRIX adjoint() const;
|
||||
CLASSNAME transpose() const;
|
||||
CLASSNAME conjugate() const;
|
||||
CLASSNAME adjoint() const;
|
||||
|
||||
void transposeInPlace();
|
||||
void adjointInPlace();
|
||||
|
|
@ -60,24 +60,28 @@ class MATRIX
|
|||
TYPE& operator()(std::size_t index);
|
||||
TYPE const& operator()(std::size_t index) const;
|
||||
|
||||
MATRIX& operator+=(MATRIX const& rhs);
|
||||
MATRIX& operator-=(MATRIX const& rhs);
|
||||
MATRIX operator-() const;
|
||||
MATRIX& operator*=(MATRIX const& rhs);
|
||||
MATRIX& operator*=(TYPE d);
|
||||
MATRIX& operator/=(TYPE d);
|
||||
CLASSNAME& operator+=(CLASSNAME const& rhs);
|
||||
CLASSNAME& operator-=(CLASSNAME const& rhs);
|
||||
CLASSNAME operator-() const;
|
||||
CLASSNAME& operator*=(CLASSNAME const& rhs);
|
||||
CLASSNAME& operator*=(TYPE d);
|
||||
CLASSNAME& operator/=(TYPE d);
|
||||
|
||||
friend std::ostream& operator<<(std::ostream&,MATRIX const&);
|
||||
friend bool operator==(MATRIX const& lhs, MATRIX const& rhs);
|
||||
friend std::ostream& operator<<(std::ostream&,CLASSNAME const&);
|
||||
friend bool operator==(CLASSNAME const& lhs, CLASSNAME const& rhs);
|
||||
|
||||
const TYPE* data() const;
|
||||
|
||||
static MATRIX Zero(std::size_t rows, std::size_t cols);
|
||||
static MATRIX Constant(std::size_t rows, std::size_t cols, TYPE value);
|
||||
static MATRIX Random(std::size_t rows, std::size_t cols);
|
||||
static MATRIX Identity(std::size_t rows, std::size_t cols);
|
||||
static CLASSNAME Zero(std::size_t rows, std::size_t cols);
|
||||
static CLASSNAME Constant(std::size_t rows, std::size_t cols, TYPE value);
|
||||
static CLASSNAME Random(std::size_t rows, std::size_t cols);
|
||||
static CLASSNAME Identity(std::size_t rows, std::size_t cols);
|
||||
|
||||
private:
|
||||
struct payload;
|
||||
std::unique_ptr<payload> storage_;
|
||||
|
||||
public:
|
||||
std::unique_ptr<payload>& storage() { return storage_; }
|
||||
std::unique_ptr<payload> const& storage() const { return storage_; }
|
||||
};
|
||||
67
include/rotgen/impl/payload.hpp
Normal file
67
include/rotgen/impl/payload.hpp
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
//==================================================================================================
|
||||
/*
|
||||
ROTGEN - Runtime Overlay for Eigen
|
||||
Copyright : CODE RECKONS
|
||||
SPDX-License-Identifier: BSL-1.0
|
||||
*/
|
||||
//==================================================================================================
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <memory>
|
||||
#include <rotgen/impl/matrix.hpp>
|
||||
#include <Eigen/Dense>
|
||||
|
||||
namespace rotgen
|
||||
{
|
||||
//==================================================================================================
|
||||
// Internal payload - Requried for cross-referencing from block_impl*
|
||||
//==================================================================================================
|
||||
struct matrix_impl64_col::payload
|
||||
{
|
||||
using data_type = Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic,Eigen::ColMajor>;
|
||||
|
||||
data_type data;
|
||||
payload(std::size_t r=0, std::size_t c=0) : data(r, c) {}
|
||||
payload(std::initializer_list<std::initializer_list<double>> init) : data(init) {}
|
||||
payload(data_type&& matrix) : data(std::move(matrix)) {}
|
||||
|
||||
void assign(Eigen::Block<data_type> ref) { data = ref; }
|
||||
};
|
||||
|
||||
struct matrix_impl64_row::payload
|
||||
{
|
||||
using data_type = Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic,Eigen::RowMajor>;
|
||||
|
||||
data_type data;
|
||||
payload(std::size_t r=0, std::size_t c=0) : data(r, c) {}
|
||||
payload(std::initializer_list<std::initializer_list<double>> init) : data(init) {}
|
||||
payload(data_type&& matrix) : data(std::move(matrix)) {}
|
||||
|
||||
void assign(Eigen::Block<data_type> ref) { data = ref; }
|
||||
};
|
||||
|
||||
struct matrix_impl32_col::payload
|
||||
{
|
||||
using data_type = Eigen::Matrix<float,Eigen::Dynamic,Eigen::Dynamic,Eigen::ColMajor>;
|
||||
|
||||
data_type data;
|
||||
payload(std::size_t r=0, std::size_t c=0) : data(r, c) {}
|
||||
payload(std::initializer_list<std::initializer_list<float>> init) : data(init) {}
|
||||
payload(data_type&& matrix) : data(std::move(matrix)) {}
|
||||
|
||||
void assign(Eigen::Block<data_type> ref) { data = ref; }
|
||||
};
|
||||
|
||||
struct matrix_impl32_row::payload
|
||||
{
|
||||
using data_type = Eigen::Matrix<float,Eigen::Dynamic,Eigen::Dynamic,Eigen::RowMajor>;
|
||||
|
||||
data_type data;
|
||||
payload(std::size_t r=0, std::size_t c=0) : data(r, c) {}
|
||||
payload(std::initializer_list<std::initializer_list<float>> init) : data(init) {}
|
||||
payload(data_type&& matrix) : data(std::move(matrix)) {}
|
||||
|
||||
void assign(Eigen::Block<data_type> ref) { data = ref; }
|
||||
};
|
||||
}
|
||||
|
|
@ -20,10 +20,11 @@ namespace rotgen
|
|||
>
|
||||
class matrix : public find_matrix<Scalar,Options>
|
||||
{
|
||||
using parent = find_matrix<Scalar,Options>;
|
||||
using parent = find_matrix<Scalar,Options>;
|
||||
|
||||
public:
|
||||
using value_type = Scalar;
|
||||
using scalar_type = Scalar;
|
||||
static constexpr auto storage_order = Options & 1;
|
||||
|
||||
matrix() : parent(Rows==-1?0:Rows,Cols==-1?0:Cols) {}
|
||||
|
||||
|
|
|
|||
12
include/rotgen/rotgen.hpp
Normal file
12
include/rotgen/rotgen.hpp
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
//==================================================================================================
|
||||
/*
|
||||
ROTGEN - Runtime Overlay for Eigen
|
||||
Copyright : CODE RECKONS
|
||||
SPDX-License-Identifier: BSL-1.0
|
||||
*/
|
||||
//==================================================================================================
|
||||
#pragma once
|
||||
|
||||
#include <rotgen/matrix.hpp>
|
||||
#include <rotgen/block.hpp>
|
||||
#include <rotgen/extract.hpp>
|
||||
Loading…
Add table
Add a link
Reference in a new issue