Feat/block implementation

See merge request oss/rotgen!10
This commit is contained in:
Karen Kaspar 2025-06-23 15:22:11 +02:00 committed by Joel Falcou
parent b868398a77
commit 3d23a07e90
6 changed files with 406 additions and 287 deletions

View file

@ -35,163 +35,183 @@ namespace rotgen
block(parent const& base) : parent(base) {}
/*
block transpose() const
{
return block(static_cast<parent const&>(*this).transpose());
}
concrete_type transpose() const
{
return concrete_type(static_cast<parent const &>(*this).transpose());
}
block conjugate() const
{
return block(static_cast<parent const&>(*this).conjugate());
}
concrete_type conjugate() const
{
return concrete_type(static_cast<parent const &>(*this).conjugate());
}
block adjoint() const
{
return block(static_cast<parent const&>(*this).adjoint());
}
*/
concrete_type adjoint() const
{
return concrete_type(static_cast<parent const &>(*this).adjoint());
}
friend bool operator==(block const& lhs, block const& rhs)
void transposeInPlace() { parent::transposeInPlace(); }
void adjointInPlace() { parent::adjointInPlace(); }
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-());
}
concrete_type matrix_addition(block const& rhs) const
{
return concrete_type(static_cast<parent const&>(*this).matrix_addition(rhs));
}
concrete_type matrix_subtraction(block const& rhs) const
{
return concrete_type(static_cast<parent const&>(*this).matrix_subtraction(rhs));
}
concrete_type matrix_multiplication(block const& rhs) const
{
return concrete_type(static_cast<parent const&>(*this).matrix_multiplication(rhs));
}
concrete_type matrix_multiplication(scalar_type rhs) const
{
return concrete_type(static_cast<parent const&>(*this).matrix_multiplication(rhs));
}
concrete_type matrix_division(scalar_type rhs) const
{
return concrete_type(static_cast<parent const&>(*this).matrix_division(rhs));
}
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 Ref, int R, int C, bool I, int F>
typename block<Ref, R, C, I, F>::concrete_type operator+(block<Ref, R, C, I, F> const& lhs, block<Ref, R, C, I, F> const& rhs)
{
return static_cast<parent const&>(lhs) == static_cast<parent const&>(rhs);
return lhs.matrix_addition(rhs);
}
block& operator+=(block const& rhs)
template<typename Ref, int R, int C, bool I, int F>
typename block<Ref, R, C, I, F>::concrete_type operator-(block<Ref, R, C, I, F> const& lhs, block<Ref, R, C, I, F> const& rhs)
{
static_cast<parent&>(*this) += static_cast<parent const&>(rhs);
return *this;
return lhs.matrix_subtraction(rhs);
}
block& operator-=(block const& rhs)
template<typename Ref, int R, int C, bool I, int F>
typename block<Ref, R, C, I, F>::concrete_type operator*(block<Ref, R, C, I, F> const& lhs, block<Ref, R, C, I, F> const& rhs)
{
static_cast<parent&>(*this) -= static_cast<parent const&>(rhs);
return *this;
return lhs.matrix_multiplication(rhs);
}
concrete_type operator-() const
template<typename Ref, int R, int C, bool I, int F>
typename block<Ref, R, C, I, F>::concrete_type operator*(block<Ref, R, C, I, F> const& lhs, double rhs)
{
return concrete_type(static_cast<parent const&>(*this).operator-());
return lhs.matrix_multiplication(rhs);
}
block& operator*=(block const& rhs)
template<typename Ref, int R, int C, bool I, int F>
typename block<Ref, R, C, I, F>::concrete_type operator*(double lhs, block<Ref, R, C, I, F> const& rhs)
{
static_cast<parent&>(*this) *= static_cast<parent const&>(rhs);
return *this;
return rhs.matrix_multiplication(lhs);
}
block& operator*=(scalar_type rhs)
template<typename Ref, int R, int C, bool I, int F>
typename block<Ref, R, C, I, F>::concrete_type operator/(block<Ref, R, C, I, F> const& lhs, double rhs)
{
static_cast<parent&>(*this) *= rhs;
return *this;
return lhs.matrix_division(rhs);
}
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;
}
*/
}

View file

@ -28,12 +28,12 @@ class CLASSNAME
std::size_t cols() const;
std::size_t size() const;
// CLASSNAME transpose() const;
// CLASSNAME conjugate() const;
// CLASSNAME adjoint() const;
SOURCENAME transpose() const;
SOURCENAME conjugate() const;
SOURCENAME adjoint() const;
// void transposeInPlace();
// void adjointInPlace();
void transposeInPlace();
void adjointInPlace();
TYPE sum() const;
TYPE prod() const;
@ -61,6 +61,12 @@ class CLASSNAME
CLASSNAME& operator*=(TYPE d);
CLASSNAME& operator/=(TYPE d);
SOURCENAME matrix_addition(CLASSNAME const& rhs) const;
SOURCENAME matrix_subtraction(CLASSNAME const& rhs) const;
SOURCENAME matrix_multiplication(CLASSNAME const& rhs) const;
SOURCENAME matrix_multiplication(TYPE s) const;
SOURCENAME matrix_division(TYPE s) const;
friend std::ostream& operator<<(std::ostream&,CLASSNAME const&);
friend bool operator==(CLASSNAME const& lhs, CLASSNAME const& rhs);

View file

@ -27,6 +27,8 @@ namespace rotgen
payload(data_type&& matrix) : data(std::move(matrix)) {}
void assign(Eigen::Block<data_type> ref) { data = ref; }
void assign(data_type const& mat) { data = mat; }
void assign(data_type&& mat) { data = std::move(mat); }
};
struct matrix_impl64_row::payload
@ -39,6 +41,8 @@ namespace rotgen
payload(data_type&& matrix) : data(std::move(matrix)) {}
void assign(Eigen::Block<data_type> ref) { data = ref; }
void assign(data_type const& mat) { data = mat; }
void assign(data_type&& mat) { data = std::move(mat); }
};
struct matrix_impl32_col::payload
@ -51,6 +55,8 @@ namespace rotgen
payload(data_type&& matrix) : data(std::move(matrix)) {}
void assign(Eigen::Block<data_type> ref) { data = ref; }
void assign(data_type const& mat) { data = mat; }
void assign(data_type&& mat) { data = std::move(mat); }
};
struct matrix_impl32_row::payload
@ -63,5 +69,7 @@ namespace rotgen
payload(data_type&& matrix) : data(std::move(matrix)) {}
void assign(Eigen::Block<data_type> ref) { data = ref; }
void assign(data_type const& mat) { data = mat; }
void assign(data_type&& mat) { data = std::move(mat); }
};
}