Added more operators + tests
This commit is contained in:
parent
5f1d070547
commit
682202825e
4 changed files with 68 additions and 10 deletions
|
|
@ -35,6 +35,7 @@ namespace rotgen
|
|||
matrix_impl64& operator*=(double d);
|
||||
|
||||
friend std::ostream& operator<<(std::ostream&,matrix_impl64 const&);
|
||||
friend bool operator==(matrix_impl64 const& lhs, matrix_impl64 const& rhs);
|
||||
|
||||
private:
|
||||
struct payload;
|
||||
|
|
|
|||
|
|
@ -11,14 +11,21 @@
|
|||
|
||||
namespace rotgen
|
||||
{
|
||||
template<typename Scalar, int Rows = -1, int Cols = -1>
|
||||
template< typename Scalar, int Rows = -1 , int Cols = -1
|
||||
, int Options = 0, int MaxRows = Rows, int MaxCols = Cols
|
||||
>
|
||||
class matrix : public matrix_impl64
|
||||
{
|
||||
using parent = matrix_impl64;
|
||||
|
||||
public:
|
||||
matrix() : parent(Rows==-1?0:Rows,Cols==-1?0:Cols) {}
|
||||
matrix(std::size_t r, std::size_t c) : parent(r,c) {}
|
||||
matrix() : parent(Rows==-1?0:Rows,Cols==-1?0:Cols) {}
|
||||
matrix(std::size_t r, std::size_t c) : parent(r,c) {}
|
||||
|
||||
friend bool operator==(matrix const& lhs, matrix const& rhs)
|
||||
{
|
||||
return static_cast<parent const&>(lhs) == static_cast<parent const&>(rhs);
|
||||
}
|
||||
|
||||
matrix& operator+=(matrix const& rhs)
|
||||
{
|
||||
|
|
@ -31,19 +38,38 @@ namespace rotgen
|
|||
static_cast<parent&>(*this) *= static_cast<parent const&>(rhs);
|
||||
return *this;
|
||||
}
|
||||
|
||||
matrix& operator*=(double rhs)
|
||||
{
|
||||
static_cast<parent&>(*this) *= rhs;
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename S, int R, int C>
|
||||
matrix<S,R,C> operator+(matrix<S,R,C> const& lhs, matrix<S,R,C> const& 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> that(lhs);
|
||||
matrix<S,R,C,O,MR,MC> that(lhs);
|
||||
return that += rhs;
|
||||
}
|
||||
|
||||
template<typename S, int R, int C>
|
||||
matrix<S,R,C> operator*(matrix<S,R,C> const& lhs, matrix<S,R,C> const& 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> that(lhs);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
@ -21,6 +21,6 @@ TTS_CASE("Sample test")
|
|||
"0 0 0 0 0\n"
|
||||
"0 0 0 0 0\n"
|
||||
"0 0 0 0 0";
|
||||
|
||||
|
||||
TTS_EQUAL(os.str(), ref);
|
||||
};
|
||||
31
test/basic/operators.cpp
Normal file
31
test/basic/operators.cpp
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
//==================================================================================================
|
||||
/*
|
||||
ROTGEN - Runtime Overlay for Eigen
|
||||
Copyright : CODE RECKONS
|
||||
SPDX-License-Identifier: BSL-1.0
|
||||
*/
|
||||
//==================================================================================================
|
||||
#define TTS_MAIN
|
||||
#include <rotgen/matrix.hpp>
|
||||
#include "tts.hpp"
|
||||
|
||||
TTS_CASE("Check operator*")
|
||||
{
|
||||
rotgen::matrix<double> a(2,2);
|
||||
rotgen::matrix<double> ref(2,2);
|
||||
|
||||
for(int r=0;r<a.rows();r++)
|
||||
{
|
||||
for(int c=0;c<a.cols();c++)
|
||||
{
|
||||
a(r,c) = (1+c) + 10*(1+r);
|
||||
ref(r,c) = ((1+c) + 10*(1+r)) * 10.5;
|
||||
}
|
||||
}
|
||||
|
||||
TTS_EQUAL(a * 10.5, ref);
|
||||
TTS_EQUAL(10.5 * a, ref);
|
||||
|
||||
a *= 10.5;
|
||||
TTS_EQUAL(a, ref);
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue