mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Deep refactoring.
1) Kill MatrixXpr class, instead let all class inherit a common EigenBase class 2) Kill MatrixBase/Matrix/Vector classes, instead introduce a single Matrix class, a MatrixStorage class, and typedefs to emulate vectors 3) Huge code cleanup, remove large preprocessor macros, sloccount drop to ~750 down from 1100. 4) Introduce compile-time-known sizes
This commit is contained in:
@@ -29,113 +29,57 @@
|
||||
namespace Eigen {
|
||||
|
||||
template<typename MatrixType> class ScalarProduct
|
||||
: public EigenBase<typename MatrixType::Scalar, ScalarProduct<MatrixType> >
|
||||
{
|
||||
public:
|
||||
typedef typename MatrixType::Scalar Scalar;
|
||||
typedef typename MatrixType::Ref MatRef;
|
||||
typedef ScalarProduct Ref;
|
||||
friend class EigenBase<typename MatrixType::Scalar, ScalarProduct<MatrixType> >;
|
||||
|
||||
ScalarProduct(const MatrixType& matrix, Scalar scalar)
|
||||
ScalarProduct(const MatRef& matrix, Scalar scalar)
|
||||
: m_matrix(matrix), m_scalar(scalar) {}
|
||||
|
||||
ScalarProduct(const ScalarProduct& other)
|
||||
: m_matrix(other.m_matrix), m_scalar(other.m_scalar) {}
|
||||
|
||||
int rows() const { return m_matrix.rows(); }
|
||||
int cols() const { return m_matrix.cols(); }
|
||||
INHERIT_ASSIGNMENT_OPERATORS(ScalarProduct)
|
||||
|
||||
Scalar read(int row, int col) const
|
||||
private:
|
||||
const Ref& _ref() const { return *this; }
|
||||
int _rows() const { return m_matrix.rows(); }
|
||||
int _cols() const { return m_matrix.cols(); }
|
||||
|
||||
Scalar _read(int row, int col) const
|
||||
{
|
||||
return m_matrix.read(row, col) * m_scalar;
|
||||
}
|
||||
|
||||
protected:
|
||||
const MatrixType m_matrix;
|
||||
const Scalar m_scalar;
|
||||
const MatRef m_matrix;
|
||||
const Scalar m_scalar;
|
||||
};
|
||||
|
||||
template<typename Content>
|
||||
MatrixXpr<
|
||||
ScalarProduct<
|
||||
MatrixXpr<Content>
|
||||
>
|
||||
>
|
||||
operator *(const MatrixXpr<Content>& xpr,
|
||||
typename Content::Scalar scalar)
|
||||
template<typename Scalar, typename Derived>
|
||||
ScalarProduct<Derived>
|
||||
operator*(const EigenBase<Scalar, Derived>& matrix,
|
||||
Scalar scalar)
|
||||
{
|
||||
typedef ScalarProduct<
|
||||
MatrixXpr<Content>
|
||||
> ProductType;
|
||||
typedef MatrixXpr<ProductType> XprType;
|
||||
return XprType(ProductType(xpr, scalar));
|
||||
return ScalarProduct<Derived>(matrix.ref(), scalar);
|
||||
}
|
||||
|
||||
template<typename Content>
|
||||
MatrixXpr<
|
||||
ScalarProduct<
|
||||
MatrixXpr<Content>
|
||||
>
|
||||
>
|
||||
operator *(typename Content::Scalar scalar,
|
||||
const MatrixXpr<Content>& xpr)
|
||||
template<typename Scalar, typename Derived>
|
||||
ScalarProduct<Derived>
|
||||
operator*(Scalar scalar,
|
||||
const EigenBase<Scalar, Derived>& matrix)
|
||||
{
|
||||
typedef ScalarProduct<
|
||||
MatrixXpr<Content>
|
||||
> ProductType;
|
||||
typedef MatrixXpr<ProductType> XprType;
|
||||
return XprType(ProductType(xpr, scalar));
|
||||
return ScalarProduct<Derived>(matrix.ref(), scalar);
|
||||
}
|
||||
|
||||
template<typename Derived>
|
||||
MatrixXpr<
|
||||
ScalarProduct<
|
||||
MatrixRef<MatrixBase<Derived> >
|
||||
>
|
||||
>
|
||||
operator *(MatrixBase<Derived>& matrix,
|
||||
typename Derived::Scalar scalar)
|
||||
{
|
||||
typedef ScalarProduct<
|
||||
MatrixRef<MatrixBase<Derived> >
|
||||
> ProductType;
|
||||
typedef MatrixXpr<ProductType> XprType;
|
||||
return XprType(ProductType(matrix.ref(), scalar));
|
||||
}
|
||||
|
||||
template<typename Derived>
|
||||
MatrixXpr<
|
||||
ScalarProduct<
|
||||
MatrixRef<MatrixBase<Derived> >
|
||||
>
|
||||
>
|
||||
operator *(typename Derived::Scalar scalar,
|
||||
MatrixBase<Derived>& matrix)
|
||||
{
|
||||
typedef ScalarProduct<
|
||||
MatrixRef<MatrixBase<Derived> >
|
||||
> ProductType;
|
||||
typedef MatrixXpr<ProductType> XprType;
|
||||
return XprType(ProductType(matrix.ref(), scalar));
|
||||
}
|
||||
|
||||
template<typename Content>
|
||||
MatrixXpr<
|
||||
ScalarProduct<
|
||||
MatrixXpr<Content>
|
||||
>
|
||||
>
|
||||
operator /(MatrixXpr<Content>& xpr,
|
||||
typename Content::Scalar scalar)
|
||||
{
|
||||
return xpr * (static_cast<typename Content::Scalar>(1) / scalar);
|
||||
}
|
||||
|
||||
template<typename Derived>
|
||||
MatrixXpr<
|
||||
ScalarProduct<
|
||||
MatrixRef<MatrixBase<Derived> >
|
||||
>
|
||||
>
|
||||
operator /(MatrixBase<Derived>& matrix,
|
||||
typename Derived::Scalar scalar)
|
||||
template<typename Scalar, typename Derived>
|
||||
ScalarProduct<Derived>
|
||||
operator/(const EigenBase<Scalar, Derived>& matrix,
|
||||
Scalar scalar)
|
||||
{
|
||||
return matrix * (static_cast<typename Derived::Scalar>(1) / scalar);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user