mirror of
https://gitlab.com/libeigen/eigen.git
synced 2024-12-15 07:10:37 +08:00
Split Row and Column into separate files.
Introduce a notion of RowVector (typedef for Matriw with 1 row) Make row() return a row vector instead of a "column vector" Introduce operator[] to access elements of row/column vectors uniformly Remove default arguments in operator(), these were for vectors, now use operator[] instead
This commit is contained in:
parent
3cf6caba1a
commit
96524fc573
@ -26,8 +26,10 @@ int main(int, char **)
|
||||
cout << "Now the 4x4 matrix m2 is:" << endl << m2 << endl;
|
||||
|
||||
cout << "The central 2x2 block of m2 is:" << endl << m2.block(1,2,1,2) << endl;
|
||||
cout << "Row 0 of m2, written as a column vector, is:" << endl << m2.row(0) << endl;
|
||||
cout << "Row 0 of m2 is:" << endl << m2.row(0) << endl;
|
||||
cout << "The third element in that row is " << m2.row(0)[2] << endl;
|
||||
cout << "Column 1 of m2 is:" << endl << m2.col(1) << endl;
|
||||
cout << "The matrix m2 with row 0 and column 1 removed is:" << endl << m2.minor(0,1) << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -26,7 +26,8 @@
|
||||
#ifndef EI_MANIP_H
|
||||
#define EI_MANIP_H
|
||||
|
||||
#include "internal/RowAndCol.h"
|
||||
#include "internal/Row.h"
|
||||
#include "internal/Column.h"
|
||||
#include "internal/Block.h"
|
||||
#include "internal/Minor.h"
|
||||
|
||||
|
@ -33,7 +33,7 @@
|
||||
|
||||
template<typename _Scalar, int _Rows, int _Cols>
|
||||
class EiMatrix : public EiObject<_Scalar, EiMatrix<_Scalar, _Rows, _Cols> >,
|
||||
public EiMatrixStorage<_Scalar, _Rows, _Cols>
|
||||
public EiMatrixStorage<_Scalar, _Rows, _Cols>
|
||||
{
|
||||
public:
|
||||
friend class EiObject<_Scalar, EiMatrix>;
|
||||
@ -57,13 +57,13 @@ class EiMatrix : public EiObject<_Scalar, EiMatrix<_Scalar, _Rows, _Cols> >,
|
||||
Ref _ref() { return Ref(*this); }
|
||||
ConstRef _constRef() const { return ConstRef(*this); }
|
||||
|
||||
const Scalar& _read(int row, int col = 0) const
|
||||
const Scalar& _read(int row, int col) const
|
||||
{
|
||||
EI_CHECK_RANGES(*this, row, col);
|
||||
return array()[row + col * Storage::_rows()];
|
||||
}
|
||||
|
||||
Scalar& _write(int row, int col = 0)
|
||||
Scalar& _write(int row, int col)
|
||||
{
|
||||
EI_CHECK_RANGES(*this, row, col);
|
||||
return array()[row + col * Storage::_rows()];
|
||||
@ -103,7 +103,8 @@ class EiMatrix : public EiObject<_Scalar, EiMatrix<_Scalar, _Rows, _Cols> >,
|
||||
|
||||
#define EI_MAKE_TYPEDEFS(Type, TypeSuffix, Size, SizeSuffix) \
|
||||
typedef EiMatrix<Type, Size, Size> EiMatrix##SizeSuffix##TypeSuffix; \
|
||||
typedef EiMatrix<Type, Size, 1> EiVector##SizeSuffix##TypeSuffix;
|
||||
typedef EiMatrix<Type, Size, 1> EiVector##SizeSuffix##TypeSuffix; \
|
||||
typedef EiMatrix<Type, 1, Size> EiRowVector##SizeSuffix##TypeSuffix;
|
||||
|
||||
#define EI_MAKE_TYPEDEFS_ALL_SIZES(Type, TypeSuffix) \
|
||||
EI_MAKE_TYPEDEFS(Type, TypeSuffix, 2, 2) \
|
||||
@ -124,6 +125,5 @@ EI_MAKE_TYPEDEFS_ALL_SIZES(std::complex<double>, cd)
|
||||
#include "Eval.h"
|
||||
#include "MatrixOps.h"
|
||||
#include "ScalarOps.h"
|
||||
#include "RowAndCol.h"
|
||||
|
||||
#endif // EI_MATRIX_H
|
||||
|
@ -24,8 +24,8 @@
|
||||
// License. This exception does not invalidate any other reasons why a work
|
||||
// based on this file might be covered by the GNU General Public License.
|
||||
|
||||
#ifndef EI_EIGENBASE_H
|
||||
#define EI_EIGENBASE_H
|
||||
#ifndef EI_OBJECT_H
|
||||
#define EI_OBJECT_H
|
||||
|
||||
#include "Util.h"
|
||||
|
||||
@ -118,7 +118,7 @@ template<typename Scalar, typename Derived> class EiObject
|
||||
EiRow<Derived> row(int i);
|
||||
EiColumn<Derived> col(int i);
|
||||
EiMinor<Derived> minor(int row, int col);
|
||||
EiBlock<Derived> block(int startRow, int endRow, int startCol= 0, int endCol = 0);
|
||||
EiBlock<Derived> block(int startRow, int endRow, int startCol, int endCol);
|
||||
|
||||
template<typename OtherDerived>
|
||||
EiMatrixProduct<Derived, OtherDerived>
|
||||
@ -145,12 +145,26 @@ template<typename Scalar, typename Derived> class EiObject
|
||||
Derived& operator/=(const std::complex<float>& other);
|
||||
Derived& operator/=(const std::complex<double>& other);
|
||||
|
||||
Scalar operator()(int row, int col = 0) const
|
||||
Scalar operator()(int row, int col) const
|
||||
{ return read(row, col); }
|
||||
|
||||
Scalar& operator()(int row, int col = 0)
|
||||
Scalar& operator()(int row, int col)
|
||||
{ return write(row, col); }
|
||||
|
||||
Scalar operator[](int index) const
|
||||
{
|
||||
assert(RowsAtCompileTime == 1 || ColsAtCompileTime == 1);
|
||||
if(RowsAtCompileTime == 1) return read(0, index);
|
||||
else return read(index, 0);
|
||||
}
|
||||
|
||||
Scalar& operator[](int index)
|
||||
{
|
||||
assert(RowsAtCompileTime == 1 || ColsAtCompileTime == 1);
|
||||
if(RowsAtCompileTime == 1) return write(0, index);
|
||||
else return write(index, 0);
|
||||
}
|
||||
|
||||
EiEval<Derived> eval() const EI_ALWAYS_INLINE;
|
||||
};
|
||||
|
||||
@ -170,4 +184,4 @@ std::ostream & operator <<
|
||||
return s;
|
||||
}
|
||||
|
||||
#endif // EI_EIGENBASE_H
|
||||
#endif // EI_OBJECT_H
|
||||
|
@ -23,8 +23,8 @@
|
||||
// License. This exception does not invalidate any other reasons why a work
|
||||
// based on this file might be covered by the GNU General Public License.
|
||||
|
||||
#ifndef EI_ROWANDCOL_H
|
||||
#define EI_ROWANDCOL_H
|
||||
#ifndef EI_ROW_H
|
||||
#define EI_ROW_H
|
||||
|
||||
template<typename MatrixType> class EiRow
|
||||
: public EiObject<typename MatrixType::Scalar, EiRow<MatrixType> >
|
||||
@ -34,8 +34,8 @@ template<typename MatrixType> class EiRow
|
||||
typedef typename MatrixType::Ref MatRef;
|
||||
friend class EiObject<Scalar, EiRow<MatrixType> >;
|
||||
|
||||
static const int RowsAtCompileTime = MatrixType::ColsAtCompileTime,
|
||||
ColsAtCompileTime = 1;
|
||||
static const int RowsAtCompileTime = 1,
|
||||
ColsAtCompileTime = MatrixType::ColsAtCompileTime;
|
||||
|
||||
EiRow(const MatRef& matrix, int row)
|
||||
: m_matrix(matrix), m_row(row)
|
||||
@ -58,21 +58,19 @@ template<typename MatrixType> class EiRow
|
||||
EiRow& _ref() { return *this; }
|
||||
const EiRow& _constRef() const { return *this; }
|
||||
|
||||
int _rows() const { return m_matrix.cols(); }
|
||||
int _cols() const { return 1; }
|
||||
int _rows() const { return 1; }
|
||||
int _cols() const { return m_matrix.cols(); }
|
||||
|
||||
Scalar& _write(int row, int col=0)
|
||||
Scalar& _write(int row, int col)
|
||||
{
|
||||
EI_UNUSED(col);
|
||||
EI_CHECK_ROW_RANGE(*this, row);
|
||||
return m_matrix.write(m_row, row);
|
||||
EI_UNUSED(row);
|
||||
return m_matrix.write(m_row, col);
|
||||
}
|
||||
|
||||
Scalar _read(int row, int col=0) const
|
||||
Scalar _read(int row, int col) const
|
||||
{
|
||||
EI_UNUSED(col);
|
||||
EI_CHECK_ROW_RANGE(*this, row);
|
||||
return m_matrix.read(m_row, row);
|
||||
EI_UNUSED(row);
|
||||
return m_matrix.read(m_row, col);
|
||||
}
|
||||
|
||||
protected:
|
||||
@ -80,53 +78,6 @@ template<typename MatrixType> class EiRow
|
||||
const int m_row;
|
||||
};
|
||||
|
||||
template<typename MatrixType> class EiColumn
|
||||
: public EiObject<typename MatrixType::Scalar, EiColumn<MatrixType> >
|
||||
{
|
||||
public:
|
||||
typedef typename MatrixType::Scalar Scalar;
|
||||
typedef typename MatrixType::Ref MatRef;
|
||||
friend class EiObject<Scalar, EiColumn<MatrixType> >;
|
||||
|
||||
static const int RowsAtCompileTime = MatrixType::RowsAtCompileTime,
|
||||
ColsAtCompileTime = 1;
|
||||
|
||||
EiColumn(const MatRef& matrix, int col)
|
||||
: m_matrix(matrix), m_col(col)
|
||||
{
|
||||
EI_CHECK_COL_RANGE(matrix, col);
|
||||
}
|
||||
|
||||
EiColumn(const EiColumn& other)
|
||||
: m_matrix(other.m_matrix), m_col(other.m_col) {}
|
||||
|
||||
EI_INHERIT_ASSIGNMENT_OPERATORS(EiColumn)
|
||||
|
||||
private:
|
||||
EiColumn& _ref() { return *this; }
|
||||
const EiColumn& _constRef() const { return *this; }
|
||||
int _rows() const { return m_matrix.rows(); }
|
||||
int _cols() const { return 1; }
|
||||
|
||||
Scalar& _write(int row, int col=0)
|
||||
{
|
||||
EI_UNUSED(col);
|
||||
EI_CHECK_ROW_RANGE(*this, row);
|
||||
return m_matrix.write(row, m_col);
|
||||
}
|
||||
|
||||
Scalar _read(int row, int col=0) const
|
||||
{
|
||||
EI_UNUSED(col);
|
||||
EI_CHECK_ROW_RANGE(*this, row);
|
||||
return m_matrix.read(row, m_col);
|
||||
}
|
||||
|
||||
protected:
|
||||
MatRef m_matrix;
|
||||
const int m_col;
|
||||
};
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
EiRow<Derived>
|
||||
EiObject<Scalar, Derived>::row(int i)
|
||||
@ -134,11 +85,4 @@ EiObject<Scalar, Derived>::row(int i)
|
||||
return EiRow<Derived>(static_cast<Derived*>(this)->ref(), i);
|
||||
}
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
EiColumn<Derived>
|
||||
EiObject<Scalar, Derived>::col(int i)
|
||||
{
|
||||
return EiColumn<Derived>(static_cast<Derived*>(this)->ref(), i);
|
||||
}
|
||||
|
||||
#endif // EI_ROWANDCOL_H
|
||||
#endif // EI_ROW_H
|
@ -90,14 +90,14 @@ template<typename Scalar, typename Derived> \
|
||||
Derived & \
|
||||
EiObject<Scalar, Derived>::operator*=(const OtherScalar &other) \
|
||||
{ \
|
||||
return *this = *this * other; \
|
||||
return *this = *this * other; \
|
||||
} \
|
||||
\
|
||||
template<typename Scalar, typename Derived> \
|
||||
Derived & \
|
||||
EiObject<Scalar, Derived>::operator/=(const OtherScalar &other) \
|
||||
{ \
|
||||
return *this = *this / other; \
|
||||
return *this = *this / other; \
|
||||
}
|
||||
|
||||
EI_MAKE_SCALAR_OPS(int)
|
||||
|
Loading…
Reference in New Issue
Block a user