aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--doc/tutorial.cpp4
-rw-r--r--src/Manip3
-rw-r--r--src/internal/Matrix.h10
-rw-r--r--src/internal/Object.h26
-rw-r--r--src/internal/Row.h (renamed from src/internal/RowAndCol.h)82
-rw-r--r--src/internal/ScalarOps.h4
6 files changed, 45 insertions, 84 deletions
diff --git a/doc/tutorial.cpp b/doc/tutorial.cpp
index 03495dbcb..a5b019531 100644
--- a/doc/tutorial.cpp
+++ b/doc/tutorial.cpp
@@ -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;
}
diff --git a/src/Manip b/src/Manip
index ca450ddf7..db4607091 100644
--- a/src/Manip
+++ b/src/Manip
@@ -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"
diff --git a/src/internal/Matrix.h b/src/internal/Matrix.h
index e5481df2f..19e3b313d 100644
--- a/src/internal/Matrix.h
+++ b/src/internal/Matrix.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
diff --git a/src/internal/Object.h b/src/internal/Object.h
index 3f27e6c0e..de33c84c0 100644
--- a/src/internal/Object.h
+++ b/src/internal/Object.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
diff --git a/src/internal/RowAndCol.h b/src/internal/Row.h
index 62a9d56da..39efc0b2b 100644
--- a/src/internal/RowAndCol.h
+++ b/src/internal/Row.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
diff --git a/src/internal/ScalarOps.h b/src/internal/ScalarOps.h
index e2acfb5d9..903f2751b 100644
--- a/src/internal/ScalarOps.h
+++ b/src/internal/ScalarOps.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)