aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/internal
diff options
context:
space:
mode:
authorGravatar Benoit Jacob <jacob.benoit.1@gmail.com>2007-09-09 09:41:15 +0000
committerGravatar Benoit Jacob <jacob.benoit.1@gmail.com>2007-09-09 09:41:15 +0000
commit1af61c6ff078e6f9f9cd1298374811cfc73d4488 (patch)
tree5121727066ffa461b6575acd9689cc87af150ba6 /src/internal
parent3b727ef939f5888a8931b231edcf31c00de8bf69 (diff)
reorganize header files, split MatrixBase into smaller files.
expose only a few meta-headers to the user, the rest moves to a internal/ subdirectory
Diffstat (limited to 'src/internal')
-rw-r--r--src/internal/Block.h99
-rw-r--r--src/internal/CMakeLists.txt6
-rw-r--r--src/internal/Matrix.h179
-rw-r--r--src/internal/MatrixAlias.h116
-rw-r--r--src/internal/MatrixBase.h201
-rw-r--r--src/internal/MatrixOps.h218
-rw-r--r--src/internal/MatrixRef.h76
-rw-r--r--src/internal/MatrixXpr.h108
-rw-r--r--src/internal/Minor.h95
-rw-r--r--src/internal/RowAndCol.h141
-rw-r--r--src/internal/ScalarOps.h145
-rw-r--r--src/internal/Util.h83
-rw-r--r--src/internal/Vector.h190
13 files changed, 1657 insertions, 0 deletions
diff --git a/src/internal/Block.h b/src/internal/Block.h
new file mode 100644
index 000000000..68c4439cd
--- /dev/null
+++ b/src/internal/Block.h
@@ -0,0 +1,99 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra. Eigen itself is part of the KDE project.
+//
+// Copyright (C) 2006-2007 Benoit Jacob <jacob@math.jussieu.fr>
+//
+// Eigen is free software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the Free Software
+// Foundation; either version 2 or (at your option) any later version.
+//
+// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+// details.
+//
+// You should have received a copy of the GNU General Public License along
+// with Eigen; if not, write to the Free Software Foundation, Inc., 51
+// Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+// As a special exception, if other files instantiate templates or use macros
+// or functions from this file, or you compile this file and link it
+// with other works to produce a work based on this file, this file does not
+// by itself cause the resulting work to be covered by the GNU General Public
+// 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 EIGEN_BLOCK_H
+#define EIGEN_BLOCK_H
+
+namespace Eigen {
+
+template<typename MatrixType> class MatrixBlock
+{
+ public:
+ typedef typename MatrixType::Scalar Scalar;
+
+ MatrixBlock(const MatrixType& matrix, int startRow, int endRow,
+ int startCol = 0, int endCol = 0)
+ : m_matrix(matrix), m_startRow(startRow), m_endRow(endRow),
+ m_startCol(startCol), m_endCol(endCol)
+ {
+ assert(startRow >= 0 && startRow <= endRow && endRow < matrix.rows()
+ && startCol >= 0 && startCol <= endCol && endCol < matrix.cols());
+ }
+
+ MatrixBlock(const MatrixBlock& other)
+ : m_matrix(other.m_matrix), m_startRow(other.m_startRow), m_endRow(other.m_endRow),
+ m_startCol(other.m_startCol), m_endCol(other.m_endCol) {}
+
+ int rows() const { return m_endRow - m_startRow + 1; }
+ int cols() const { return m_endCol - m_startCol + 1; }
+
+ Scalar& write(int row, int col=0)
+ {
+ return m_matrix.write(row + m_startRow, col + m_startCol);
+ }
+
+ Scalar read(int row, int col=0) const
+ {
+ return m_matrix.read(row + m_startRow, col + m_startCol);
+ }
+
+ protected:
+ MatrixType m_matrix;
+ const int m_startRow, m_endRow, m_startCol, m_endCol;
+};
+
+template<typename Derived>
+MatrixXpr<
+ MatrixBlock<
+ MatrixRef<
+ MatrixBase<Derived>
+ >
+ >
+>
+MatrixBase<Derived>::block(int startRow, int endRow, int startCol, int endCol)
+{
+ typedef MatrixBlock<Ref> ProductType;
+ typedef MatrixXpr<ProductType> XprType;
+ return XprType(ProductType(ref(), startRow, endRow, startCol, endCol));
+}
+
+template<typename Content>
+MatrixXpr<
+ MatrixBlock<
+ MatrixXpr<Content>
+ >
+>
+MatrixXpr<Content>::block(int startRow, int endRow, int startCol, int endCol)
+{
+ typedef MatrixBlock<
+ MatrixXpr<Content>
+ > ProductType;
+ typedef MatrixXpr<ProductType> XprType;
+ return XprType(ProductType(*this, startRow, endRow, startCol, endCol));
+}
+
+}
+
+#endif // EIGEN_BLOCK_H
diff --git a/src/internal/CMakeLists.txt b/src/internal/CMakeLists.txt
new file mode 100644
index 000000000..c3643b916
--- /dev/null
+++ b/src/internal/CMakeLists.txt
@@ -0,0 +1,6 @@
+FILE(GLOB Eigen_internal_SRCS "*.h")
+
+INSTALL(FILES
+ ${Eigen_internal_SRCS}
+ DESTINATION ${INCLUDE_INSTALL_DIR}/internal
+ )
diff --git a/src/internal/Matrix.h b/src/internal/Matrix.h
new file mode 100644
index 000000000..be7c22bc3
--- /dev/null
+++ b/src/internal/Matrix.h
@@ -0,0 +1,179 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra. Eigen itself is part of the KDE project.
+//
+// Copyright (C) 2006-2007 Benoit Jacob <jacob@math.jussieu.fr>
+//
+// Eigen is free software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the Free Software
+// Foundation; either version 2 or (at your option) any later version.
+//
+// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+// details.
+//
+// You should have received a copy of the GNU General Public License along
+// with Eigen; if not, write to the Free Software Foundation, Inc., 51
+// Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+// As a special exception, if other files instantiate templates or use macros
+// or functions from this file, or you compile this file and link it
+// with other works to produce a work based on this file, this file does not
+// by itself cause the resulting work to be covered by the GNU General Public
+// 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.
+
+/** \file Matrix.h
+ * \brief Matrix and MatrixX class templates
+ */
+
+#ifndef EIGEN_MATRIX_H
+#define EIGEN_MATRIX_H
+
+#include "MatrixBase.h"
+
+namespace Eigen
+{
+
+template<typename T, int Rows, int Cols>
+class Matrix: public MatrixBase< Matrix<T, Rows, Cols> >
+{
+ friend class MatrixBase<Matrix<T, Rows, Cols> >;
+ typedef class MatrixBase<Matrix<T, Rows, Cols> > Base;
+
+ public:
+ typedef T Scalar;
+
+ private:
+
+ static bool _hasDynamicNumRows()
+ { return false; }
+
+ static bool _hasDynamicNumCols()
+ { return false; }
+
+ int _rows() const
+ { return Rows; }
+
+ int _cols() const
+ { return Cols; }
+
+ void _resize( int rows, int cols ) const
+ {
+ assert(rows == Rows && cols == Cols);
+ }
+
+ public:
+
+ Matrix()
+ {
+ assert(Rows > 0 && Cols > 0);
+ }
+
+ Matrix(const Matrix& other) : Base()
+ {
+ *this = other;
+ }
+
+ Matrix(int rows, int cols)
+ {
+ assert(Rows > 0 && Cols > 0 && rows == Rows && cols == Cols);
+ }
+
+ void operator=(const Matrix & other)
+ { Base::operator=(other); }
+
+ template<typename XprContent>
+ void operator=(const MatrixXpr<XprContent> &xpr)
+ { Base::operator=(xpr); }
+
+ template<typename XprContent>
+ explicit Matrix(const MatrixXpr<XprContent>& xpr)
+ {
+ *this = xpr;
+ }
+
+ protected:
+
+ T m_array[ Rows * Cols ];
+
+};
+
+template<typename T>
+class MatrixX : public MatrixBase< MatrixX<T> >
+{
+ friend class MatrixBase<MatrixX<T> >;
+ typedef class MatrixBase<MatrixX<T> > Base;
+
+ public:
+
+ typedef T Scalar;
+
+ MatrixX(int rows, int cols)
+ { _init(rows, cols); }
+
+ MatrixX(const MatrixX& other) : Base()
+ {
+ _init(other.rows(), other.cols());
+ *this = other;
+ }
+
+ ~MatrixX()
+ { delete[] m_array; }
+
+ void operator=(const MatrixX& other)
+ { Base::operator=(other); }
+
+ template<typename XprContent>
+ void operator=(const MatrixXpr<XprContent> &xpr)
+ { Base::operator=(xpr); }
+
+ template<typename XprContent>
+ explicit MatrixX(const MatrixXpr<XprContent>& xpr)
+ {
+ _init(xpr.rows(), xpr.cols());
+ *this = xpr;
+ }
+
+ protected:
+
+ int m_rows, m_cols;
+
+ T *m_array;
+
+ private:
+
+ int _rows() const { return m_rows; }
+ int _cols() const { return m_cols; }
+
+ static bool _hasDynamicNumRows()
+ { return true; }
+
+ static bool _hasDynamicNumCols()
+ { return true; }
+
+ void _resize( int rows, int cols )
+ {
+ assert(rows > 0 && cols > 0);
+ if(rows * cols > m_rows * m_cols)
+ {
+ delete[] m_array;
+ m_array = new T[rows * cols];
+ }
+ m_rows = rows;
+ m_cols = cols;
+ }
+
+ void _init( int rows, int cols )
+ {
+ assert(rows > 0 && cols > 0);
+ m_rows = rows;
+ m_cols = cols;
+ m_array = new T[m_rows * m_cols];
+ }
+
+};
+
+} // namespace Eigen
+
+#endif // EIGEN_MATRIX_H
diff --git a/src/internal/MatrixAlias.h b/src/internal/MatrixAlias.h
new file mode 100644
index 000000000..868011321
--- /dev/null
+++ b/src/internal/MatrixAlias.h
@@ -0,0 +1,116 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra. Eigen itself is part of the KDE project.
+//
+// Copyright (C) 2006-2007 Benoit Jacob <jacob@math.jussieu.fr>
+//
+// Eigen is free software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the Free Software
+// Foundation; either version 2 or (at your option) any later version.
+//
+// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+// details.
+//
+// You should have received a copy of the GNU General Public License along
+// with Eigen; if not, write to the Free Software Foundation, Inc., 51
+// Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+// As a special exception, if other files instantiate templates or use macros
+// or functions from this file, or you compile this file and link it
+// with other works to produce a work based on this file, this file does not
+// by itself cause the resulting work to be covered by the GNU General Public
+// 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 EIGEN_MATRIXALIAS_H
+#define EIGEN_MATRIXALIAS_H
+
+namespace Eigen
+{
+
+template<typename Derived> class MatrixAlias
+{
+ public:
+ typedef typename Derived::Scalar Scalar;
+ typedef MatrixRef<MatrixAlias<Derived> > Ref;
+ typedef MatrixXpr<Ref> Xpr;
+
+ MatrixAlias(Derived& matrix) : m_aliased(matrix), m_tmp(matrix) {}
+ MatrixAlias(const MatrixAlias& other) : m_aliased(other.m_aliased), m_tmp(other.m_tmp) {}
+
+ ~MatrixAlias()
+ {
+ m_aliased.xpr() = m_tmp;
+ }
+
+ Ref ref()
+ {
+ return Ref(*this);
+ }
+
+ Xpr xpr()
+ {
+ return Xpr(ref());
+ }
+
+ static bool hasDynamicNumRows()
+ {
+ return MatrixBase<Derived>::hasDynamicNumRows();
+ }
+
+ static bool hasDynamicNumCols()
+ {
+ return MatrixBase<Derived>::hasDynamicNumCols();
+ }
+
+ int rows() const { return m_tmp.rows(); }
+ int cols() const { return m_tmp.cols(); }
+
+ Scalar& write(int row, int col)
+ {
+ return m_tmp.write(row, col);
+ }
+
+ MatrixXpr<MatrixRow<Xpr> > row(int i) { return xpr().row(i); };
+ MatrixXpr<MatrixCol<Xpr> > col(int i) { return xpr().col(i); };
+ MatrixXpr<MatrixMinor<Xpr> > minor(int row, int col) { return xpr().minor(row, col); };
+ MatrixXpr<MatrixBlock<Xpr> >
+ block(int startRow, int endRow, int startCol = 0, int endCol = 0)
+ {
+ return xpr().block(startRow, endRow, startCol, endCol);
+ }
+
+ template<typename XprContent>
+ void operator=(const MatrixXpr<XprContent> &other)
+ {
+ xpr() = other;
+ }
+
+ template<typename XprContent>
+ void operator+=(const MatrixXpr<XprContent> &other)
+ {
+ xpr() += other;
+ }
+
+ template<typename XprContent>
+ void operator-=(const MatrixXpr<XprContent> &other)
+ {
+ xpr() -= other;
+ }
+
+ protected:
+ MatrixRef<MatrixBase<Derived> > m_aliased;
+ Derived m_tmp;
+};
+
+template<typename Derived>
+typename MatrixBase<Derived>::Alias
+MatrixBase<Derived>::alias()
+{
+ return Alias(*static_cast<Derived*>(this));
+}
+
+} // namespace Eigen
+
+#endif // EIGEN_MATRIXALIAS_H
diff --git a/src/internal/MatrixBase.h b/src/internal/MatrixBase.h
new file mode 100644
index 000000000..910cc4ac0
--- /dev/null
+++ b/src/internal/MatrixBase.h
@@ -0,0 +1,201 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra. Eigen itself is part of the KDE project.
+//
+// Copyright (C) 2006-2007 Benoit Jacob <jacob@math.jussieu.fr>
+//
+// Eigen is free software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the Free Software
+// Foundation; either version 2 or (at your option) any later version.
+//
+// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+// details.
+//
+// You should have received a copy of the GNU General Public License along
+// with Eigen; if not, write to the Free Software Foundation, Inc., 51
+// Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+// As a special exception, if other files instantiate templates or use macros
+// or functions from this file, or you compile this file and link it
+// with other works to produce a work based on this file, this file does not
+// by itself cause the resulting work to be covered by the GNU General Public
+// 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 EIGEN_MATRIXBASE_H
+#define EIGEN_MATRIXBASE_H
+
+#include "Util.h"
+#include "MatrixXpr.h"
+#include "MatrixRef.h"
+
+namespace Eigen
+{
+
+template<typename Derived>
+class MatrixBase
+{
+ public:
+
+ typedef typename ForwardDecl<Derived>::Scalar Scalar;
+ typedef MatrixRef<MatrixBase<Derived> > Ref;
+ typedef MatrixXpr<Ref> Xpr;
+ typedef MatrixAlias<Derived> Alias;
+
+ Ref ref()
+ {
+ return Ref(*this);
+ }
+
+ Xpr xpr()
+ {
+ return Xpr(ref());
+ }
+
+ Alias alias();
+
+ static bool hasDynamicNumRows()
+ {
+ return Derived::_hasDynamicNumRows();
+ }
+
+ static bool hasDynamicNumCols()
+ {
+ return Derived::_hasDynamicNumCols();
+ }
+
+ int rows() const
+ {
+ return static_cast<const Derived*>(this)->_rows();
+ }
+
+ int cols() const
+ {
+ return static_cast<const Derived*>(this)->_cols();
+ }
+
+ void resize(int rows, int cols)
+ {
+ static_cast<Derived*>(this)->_resize(rows, cols);
+ }
+
+ const Scalar* array() const
+ {
+ return static_cast<const Derived*>(this)->m_array;
+ }
+
+ Scalar* array()
+ {
+ return static_cast<Derived*>(this)->m_array;
+ }
+
+ const Scalar& read(int row, int col = 0) const
+ {
+ EIGEN_CHECK_RANGES(*this, row, col);
+ return array()[row + col * rows()];
+ }
+
+ const Scalar& operator()(int row, int col = 0) const
+ {
+ return read(row, col);
+ }
+
+ Scalar& write(int row, int col = 0)
+ {
+ EIGEN_CHECK_RANGES(*this, row, col);
+ return array()[row + col * rows()];
+ }
+
+ Scalar& operator()(int row, int col = 0)
+ {
+ return write(row, col);
+ }
+
+ template<typename XprContent>
+ MatrixBase& operator=(const MatrixXpr<XprContent> &otherXpr)
+ {
+ resize(otherXpr.rows(), otherXpr.cols());
+ xpr() = otherXpr;
+ return *this;
+ }
+
+ MatrixBase& operator=(const MatrixBase &other)
+ {
+ resize(other.rows(), other.cols());
+ for(int i = 0; i < rows(); i++)
+ for(int j = 0; j < cols(); j++)
+ this->operator()(i, j) = other(i, j);
+ return *this;
+ }
+
+ MatrixXpr<MatrixRow<Ref> > row(int i);
+ MatrixXpr<MatrixCol<Ref> > col(int i);
+ MatrixXpr<MatrixMinor<Ref> > minor(int row, int col);
+ MatrixXpr<MatrixBlock<Ref> >
+ block(int startRow, int endRow, int startCol = 0, int endCol = 0);
+
+ template<typename Content>
+ MatrixBase& operator+=(const MatrixXpr<Content> &xpr);
+ template<typename Content>
+ MatrixBase& operator-=(const MatrixXpr<Content> &xpr);
+ template<typename Derived2>
+ MatrixBase& operator+=(MatrixBase<Derived2> &other);
+ template<typename Derived2>
+ MatrixBase& operator-=(MatrixBase<Derived2> &other);
+
+ protected:
+
+ MatrixBase() {};
+};
+
+template<typename Content>
+template<typename Derived>
+MatrixXpr<Content>& MatrixXpr<Content>::operator=(const MatrixBase<Derived>& matrix)
+{
+ assert(rows() == matrix.rows() && cols() == matrix.cols());
+ for(int i = 0; i < rows(); i++)
+ for(int j = 0; j < cols(); j++)
+ write(i, j) = matrix(i, j);
+ return *this;
+}
+
+template<typename Derived>
+std::ostream & operator <<
+( std::ostream & s,
+ const MatrixBase<Derived> & m )
+{
+ for( int i = 0; i < m.rows(); i++ )
+ {
+ s << m( i, 0 );
+ for (int j = 1; j < m.cols(); j++ )
+ s << " " << m( i, j );
+ if( i < m.rows() - 1)
+ s << std::endl;
+ }
+ return s;
+}
+
+template<typename Content>
+std::ostream & operator << (std::ostream & s,
+ const MatrixXpr<Content>& xpr)
+{
+ for( int i = 0; i < xpr.rows(); i++ )
+ {
+ s << xpr.read(i, 0);
+ for (int j = 1; j < xpr.cols(); j++ )
+ s << " " << xpr.read(i, j);
+ if( i < xpr.rows() - 1)
+ s << std::endl;
+ }
+ return s;
+}
+
+} // namespace Eigen
+
+#include "MatrixAlias.h"
+#include "MatrixOps.h"
+#include "ScalarOps.h"
+#include "RowAndCol.h"
+
+#endif // EIGEN_MATRIXBASE_H
diff --git a/src/internal/MatrixOps.h b/src/internal/MatrixOps.h
new file mode 100644
index 000000000..e76e64c85
--- /dev/null
+++ b/src/internal/MatrixOps.h
@@ -0,0 +1,218 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra. Eigen itself is part of the KDE project.
+//
+// Copyright (C) 2006-2007 Benoit Jacob <jacob@math.jussieu.fr>
+//
+// Eigen is free software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the Free Software
+// Foundation; either version 2 or (at your option) any later version.
+//
+// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+// details.
+//
+// You should have received a copy of the GNU General Public License along
+// with Eigen; if not, write to the Free Software Foundation, Inc., 51
+// Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+// As a special exception, if other files instantiate templates or use macros
+// or functions from this file, or you compile this file and link it
+// with other works to produce a work based on this file, this file does not
+// by itself cause the resulting work to be covered by the GNU General Public
+// 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 EIGEN_MATRIXOPS_H
+#define EIGEN_MATRIXOPS_H
+
+namespace Eigen {
+
+#define EIGEN_MAKE_MATRIX_OP_XPR(NAME, SYMBOL) \
+template<typename Lhs, typename Rhs> class Matrix##NAME \
+{ \
+ public: \
+ typedef typename Lhs::Scalar Scalar; \
+\
+ Matrix##NAME(const Lhs& lhs, const Rhs& rhs) \
+ : m_lhs(lhs), m_rhs(rhs) \
+ { \
+ assert(lhs.rows() == rhs.rows() && lhs.cols() == rhs.cols()); \
+ } \
+\
+ Matrix##NAME(const Matrix##NAME& other) \
+ : m_lhs(other.m_lhs), m_rhs(other.m_rhs) {} \
+\
+ int rows() const { return m_lhs.rows(); } \
+ int cols() const { return m_lhs.cols(); } \
+\
+ Scalar read(int row, int col) const \
+ { \
+ return m_lhs.read(row, col) SYMBOL m_rhs.read(row, col); \
+ } \
+\
+ protected: \
+ const Lhs m_lhs; \
+ const Rhs m_rhs; \
+};
+
+EIGEN_MAKE_MATRIX_OP_XPR(Sum, +)
+EIGEN_MAKE_MATRIX_OP_XPR(Difference, -)
+
+#undef EIGEN_MAKE_MATRIX_OP_XPR
+
+template<typename Lhs, typename Rhs> class MatrixProduct
+{
+ public:
+ typedef typename Lhs::Scalar Scalar;
+
+ MatrixProduct(const Lhs& lhs, const Rhs& rhs)
+ : m_lhs(lhs), m_rhs(rhs)
+ {
+ assert(lhs.cols() == rhs.rows());
+ }
+
+ MatrixProduct(const MatrixProduct& other)
+ : m_lhs(other.m_lhs), m_rhs(other.m_rhs) {}
+
+ int rows() const { return m_lhs.rows(); }
+ int cols() const { return m_rhs.cols(); }
+
+ Scalar read(int row, int col) const
+ {
+ Scalar x = static_cast<Scalar>(0);
+ for(int i = 0; i < m_lhs.cols(); i++)
+ x += m_lhs.read(row, i) * m_rhs.read(i, col);
+ return x;
+ }
+
+ protected:
+ const Lhs m_lhs;
+ const Rhs m_rhs;
+};
+
+#define EIGEN_MAKE_MATRIX_OP(NAME, SYMBOL) \
+template<typename Content1, typename Content2> \
+MatrixXpr< \
+ Matrix##NAME< \
+ MatrixXpr<Content1>, \
+ MatrixXpr<Content2> \
+ > \
+> \
+operator SYMBOL(const MatrixXpr<Content1> &xpr1, const MatrixXpr<Content2> &xpr2) \
+{ \
+ typedef Matrix##NAME< \
+ MatrixXpr<Content1>, \
+ MatrixXpr<Content2> \
+ > ProductType; \
+ typedef MatrixXpr<ProductType> XprType; \
+ return XprType(ProductType(xpr1, xpr2)); \
+} \
+\
+template<typename Derived, typename Content> \
+MatrixXpr< \
+ Matrix##NAME< \
+ MatrixRef<MatrixBase<Derived> >, \
+ MatrixXpr<Content> \
+ > \
+> \
+operator SYMBOL(MatrixBase<Derived> &mat, const MatrixXpr<Content> &xpr) \
+{ \
+ typedef Matrix##NAME< \
+ MatrixRef<MatrixBase<Derived> >, \
+ MatrixXpr<Content> \
+ > ProductType; \
+ typedef MatrixXpr<ProductType> XprType; \
+ return XprType(ProductType(mat.ref(), xpr)); \
+} \
+\
+template<typename Content, typename Derived> \
+MatrixXpr< \
+ Matrix##NAME< \
+ MatrixXpr<Content>, \
+ MatrixRef<MatrixBase<Derived> > \
+ > \
+> \
+operator SYMBOL(const MatrixXpr<Content> &xpr, MatrixBase<Derived> &mat) \
+{ \
+ typedef Matrix##NAME< \
+ MatrixXpr<Content>, \
+ MatrixRef<MatrixBase<Derived> > \
+ > ProductType; \
+ typedef MatrixXpr<ProductType> XprType; \
+ return XprType(ProductType(xpr, mat.ref())); \
+} \
+\
+template<typename Derived1, typename Derived2> \
+MatrixXpr< \
+ Matrix##NAME< \
+ MatrixRef<MatrixBase<Derived1> >, \
+ MatrixRef<MatrixBase<Derived2> > \
+ > \
+> \
+operator SYMBOL(MatrixBase<Derived1> &mat1, MatrixBase<Derived2> &mat2) \
+{ \
+ typedef Matrix##NAME< \
+ MatrixRef<MatrixBase<Derived1> >, \
+ MatrixRef<MatrixBase<Derived2> > \
+ > ProductType; \
+ typedef MatrixXpr<ProductType> XprType; \
+ return XprType(ProductType(mat1.ref(), \
+ mat2.ref())); \
+}
+
+EIGEN_MAKE_MATRIX_OP(Sum, +)
+EIGEN_MAKE_MATRIX_OP(Difference, -)
+EIGEN_MAKE_MATRIX_OP(Product, *)
+
+#undef EIGEN_MAKE_MATRIX_OP
+
+#define EIGEN_MAKE_MATRIX_OP_EQ(SYMBOL) \
+template<typename Derived1> \
+template<typename Derived2> \
+MatrixBase<Derived1> & \
+MatrixBase<Derived1>::operator SYMBOL##=(MatrixBase<Derived2> &mat2) \
+{ \
+ return *this = *this SYMBOL mat2; \
+} \
+\
+template<typename Derived> \
+template<typename Content> \
+MatrixBase<Derived> & \
+MatrixBase<Derived>::operator SYMBOL##=(const MatrixXpr<Content> &xpr) \
+{ \
+ return *this = *this SYMBOL xpr; \
+} \
+\
+template<typename Content> \
+template<typename Derived> \
+MatrixXpr<Content> & \
+MatrixXpr<Content>::operator SYMBOL##=(MatrixBase<Derived> &mat) \
+{ \
+ assert(rows() == mat.rows() && cols() == mat.cols()); \
+ for(int i = 0; i < rows(); i++) \
+ for(int j = 0; j < cols(); j++) \
+ write(i, j) SYMBOL##= mat.read(i, j); \
+ return *this; \
+} \
+\
+template<typename Content1> \
+template<typename Content2> \
+MatrixXpr<Content1> & \
+MatrixXpr<Content1>::operator SYMBOL##=(const MatrixXpr<Content2> &other) \
+{ \
+ assert(rows() == other.rows() && cols() == other.cols()); \
+ for(int i = 0; i < rows(); i++) \
+ for(int j = 0; j < cols(); j++) \
+ write(i, j) SYMBOL##= other.read(i, j); \
+ return *this; \
+}
+
+EIGEN_MAKE_MATRIX_OP_EQ(+)
+EIGEN_MAKE_MATRIX_OP_EQ(-)
+
+#undef EIGEN_MAKE_MATRIX_OP_EQ
+
+} // namespace Eigen
+
+#endif // EIGEN_MATRIXOPS_H
diff --git a/src/internal/MatrixRef.h b/src/internal/MatrixRef.h
new file mode 100644
index 000000000..0123c535c
--- /dev/null
+++ b/src/internal/MatrixRef.h
@@ -0,0 +1,76 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra. Eigen itself is part of the KDE project.
+//
+// Copyright (C) 2006-2007 Benoit Jacob <jacob@math.jussieu.fr>
+//
+// Eigen is free software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the Free Software
+// Foundation; either version 2 or (at your option) any later version.
+//
+// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+// details.
+//
+// You should have received a copy of the GNU General Public License along
+// with Eigen; if not, write to the Free Software Foundation, Inc., 51
+// Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+// As a special exception, if other files instantiate templates or use macros
+// or functions from this file, or you compile this file and link it
+// with other works to produce a work based on this file, this file does not
+// by itself cause the resulting work to be covered by the GNU General Public
+// 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 EIGEN_MATRIXREF_H
+#define EIGEN_MATRIXREF_H
+
+namespace Eigen
+{
+
+template<typename MatrixType> class MatrixRef
+{
+ public:
+ typedef typename ForwardDecl<MatrixType>::Scalar Scalar;
+ typedef MatrixXpr<MatrixRef<MatrixType> > Xpr;
+
+ MatrixRef(MatrixType& matrix) : m_matrix(matrix) {}
+ MatrixRef(const MatrixRef& other) : m_matrix(other.m_matrix) {}
+ ~MatrixRef() {}
+
+ static bool hasDynamicNumRows()
+ {
+ return MatrixType::hasDynamicNumRows();
+ }
+
+ static bool hasDynamicNumCols()
+ {
+ return MatrixType::hasDynamicNumCols();
+ }
+
+ int rows() const { return m_matrix.rows(); }
+ int cols() const { return m_matrix.cols(); }
+
+ const Scalar& read(int row, int col) const
+ {
+ return m_matrix.read(row, col);
+ }
+
+ Scalar& write(int row, int col)
+ {
+ return m_matrix.write(row, col);
+ }
+
+ Xpr xpr()
+ {
+ return Xpr(*this);
+ }
+
+ protected:
+ MatrixType& m_matrix;
+};
+
+} // namespace Eigen
+
+#endif // EIGEN_MATRIXREF_H
diff --git a/src/internal/MatrixXpr.h b/src/internal/MatrixXpr.h
new file mode 100644
index 000000000..fe890d16c
--- /dev/null
+++ b/src/internal/MatrixXpr.h
@@ -0,0 +1,108 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra. Eigen itself is part of the KDE project.
+//
+// Copyright (C) 2006-2007 Benoit Jacob <jacob@math.jussieu.fr>
+//
+// Eigen is free software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the Free Software
+// Foundation; either version 2 or (at your option) any later version.
+//
+// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+// details.
+//
+// You should have received a copy of the GNU General Public License along
+// with Eigen; if not, write to the Free Software Foundation, Inc., 51
+// Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+// As a special exception, if other files instantiate templates or use macros
+// or functions from this file, or you compile this file and link it
+// with other works to produce a work based on this file, this file does not
+// by itself cause the resulting work to be covered by the GNU General Public
+// 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 EIGEN_MATRIXXPR_H
+#define EIGEN_MATRIXXPR_H
+
+namespace Eigen {
+
+//forward declarations
+template<typename MatrixType> class MatrixRow;
+template<typename MatrixType> class MatrixCol;
+template<typename MatrixType> class MatrixMinor;
+template<typename MatrixType> class MatrixBlock;
+
+template<typename Content> class MatrixXpr
+{
+ public:
+ typedef typename Content::Scalar Scalar;
+
+ MatrixXpr(const Content& content)
+ : m_content(content) {}
+
+ MatrixXpr(const MatrixXpr& other)
+ : m_content(other.m_content) {}
+
+ ~MatrixXpr() {}
+
+ int rows() const { return m_content.rows(); }
+ int cols() const { return m_content.cols(); }
+
+ Scalar& write(int row, int col)
+ {
+ return m_content.write(row, col);
+ }
+
+ Scalar read(int row, int col) const
+ {
+ return m_content.read(row, col);
+ }
+
+ template<typename OtherContent>
+ MatrixXpr& operator=(const MatrixXpr<OtherContent>& other)
+ {
+ assert(rows() == other.rows() && cols() == other.cols());
+ for(int i = 0; i < rows(); i++)
+ for(int j = 0; j < cols(); j++)
+ write(i, j) = other.read(i, j);
+ return *this;
+ }
+
+ //special case of the above template operator=. Strangely, g++ 4.1 failed to use
+ //that template when OtherContent == Content
+ MatrixXpr& operator=(const MatrixXpr& other)
+ {
+ assert(rows() == other.rows() && cols() == other.cols());
+ for(int i = 0; i < rows(); i++)
+ for(int j = 0; j < cols(); j++)
+ write(i, j) = other.read(i, j);
+ return *this;
+ }
+
+ template<typename Derived>
+ MatrixXpr& operator=(const MatrixBase<Derived>& matrix);
+
+ MatrixXpr<MatrixRow<MatrixXpr<Content> > > row(int i);
+ MatrixXpr<MatrixCol<MatrixXpr<Content> > > col(int i);
+ MatrixXpr<MatrixMinor<MatrixXpr<Content> > > minor(int row, int col);
+ MatrixXpr<MatrixBlock<MatrixXpr<Content> > >
+ block(int startRow, int endRow, int startCol= 0, int endCol = 0);
+
+ template<typename Content2>
+ MatrixXpr& operator+=(const MatrixXpr<Content2> &other);
+ template<typename Content2>
+ MatrixXpr& operator-=(const MatrixXpr<Content2> &other);
+ template<typename Derived>
+ MatrixXpr& operator+=(MatrixBase<Derived> &matrix);
+ template<typename Derived>
+ MatrixXpr& operator-=(MatrixBase<Derived> &matrix);
+
+ protected:
+ Content m_content;
+};
+
+} // namespace Eigen
+
+#endif // EIGEN_MATRIXXPR_H
diff --git a/src/internal/Minor.h b/src/internal/Minor.h
new file mode 100644
index 000000000..da0d759de
--- /dev/null
+++ b/src/internal/Minor.h
@@ -0,0 +1,95 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra. Eigen itself is part of the KDE project.
+//
+// Copyright (C) 2006-2007 Benoit Jacob <jacob@math.jussieu.fr>
+//
+// Eigen is free software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the Free Software
+// Foundation; either version 2 or (at your option) any later version.
+//
+// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+// details.
+//
+// You should have received a copy of the GNU General Public License along
+// with Eigen; if not, write to the Free Software Foundation, Inc., 51
+// Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+// As a special exception, if other files instantiate templates or use macros
+// or functions from this file, or you compile this file and link it
+// with other works to produce a work based on this file, this file does not
+// by itself cause the resulting work to be covered by the GNU General Public
+// 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 EIGEN_MINOR_H
+#define EIGEN_MINOR_H
+
+namespace Eigen {
+
+template<typename MatrixType> class MatrixMinor
+{
+ public:
+ typedef typename MatrixType::Scalar Scalar;
+
+ MatrixMinor(const MatrixType& matrix, int row, int col = 0)
+ : m_matrix(matrix), m_row(row), m_col(col)
+ {
+ EIGEN_CHECK_RANGES(matrix, row, col);
+ }
+
+ MatrixMinor(const MatrixMinor& other)
+ : m_matrix(other.m_matrix), m_row(other.m_row), m_col(other.m_col) {}
+
+ int rows() const { return m_matrix.rows() - 1; }
+ int cols() const { return m_matrix.cols() - 1; }
+
+ Scalar& write(int row, int col=0)
+ {
+ return m_matrix.write(row + (row >= m_row), col + (col >= m_col));
+ }
+
+ Scalar read(int row, int col=0) const
+ {
+ return m_matrix.read(row + (row >= m_row), col + (col >= m_col));
+ }
+
+ protected:
+ MatrixType m_matrix;
+ const int m_row, m_col;
+};
+
+template<typename Derived>
+MatrixXpr<
+ MatrixMinor<
+ MatrixRef<
+ MatrixBase<Derived>
+ >
+ >
+>
+MatrixBase<Derived>::minor(int row, int col)
+{
+ typedef MatrixMinor<Ref> ProductType;
+ typedef MatrixXpr<ProductType> XprType;
+ return XprType(ProductType(ref(), row, col));
+}
+
+template<typename Content>
+MatrixXpr<
+ MatrixMinor<
+ MatrixXpr<Content>
+ >
+>
+MatrixXpr<Content>::minor(int row, int col)
+{
+ typedef MatrixMinor<
+ MatrixXpr<Content>
+ > ProductType;
+ typedef MatrixXpr<ProductType> XprType;
+ return XprType(ProductType(*this, row, col));
+}
+
+}
+
+#endif // EIGEN_MINOR_H
diff --git a/src/internal/RowAndCol.h b/src/internal/RowAndCol.h
new file mode 100644
index 000000000..5da3cfa23
--- /dev/null
+++ b/src/internal/RowAndCol.h
@@ -0,0 +1,141 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra. Eigen itself is part of the KDE project.
+//
+// Copyright (C) 2006-2007 Benoit Jacob <jacob@math.jussieu.fr>
+//
+// Eigen is free software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the Free Software
+// Foundation; either version 2 or (at your option) any later version.
+//
+// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+// details.
+//
+// You should have received a copy of the GNU General Public License along
+// with Eigen; if not, write to the Free Software Foundation, Inc., 51
+// Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+// As a special exception, if other files instantiate templates or use macros
+// or functions from this file, or you compile this file and link it
+// with other works to produce a work based on this file, this file does not
+// by itself cause the resulting work to be covered by the GNU General Public
+// 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 EIGEN_ROWANDCOL_H
+#define EIGEN_ROWANDCOL_H
+
+namespace Eigen {
+
+template<typename MatrixType> class MatrixRow
+{
+ public:
+ typedef typename MatrixType::Scalar Scalar;
+
+ MatrixRow(const MatrixType& matrix, int row)
+ : m_matrix(matrix), m_row(row)
+ {
+ EIGEN_CHECK_ROW_RANGE(matrix, row);
+ }
+
+ MatrixRow(const MatrixRow& other)
+ : m_matrix(other.m_matrix), m_row(other.m_row) {}
+
+ int rows() const { return m_matrix.cols(); }
+ int cols() const { return 1; }
+
+ Scalar& write(int row, int col=0)
+ {
+ EIGEN_UNUSED(col);
+ EIGEN_CHECK_ROW_RANGE(*this, row);
+ return m_matrix.write(m_row, row);
+ }
+
+ Scalar read(int row, int col=0) const
+ {
+ EIGEN_UNUSED(col);
+ EIGEN_CHECK_ROW_RANGE(*this, row);
+ return m_matrix.read(m_row, row);
+ }
+
+ protected:
+ MatrixType m_matrix;
+ const int m_row;
+};
+
+template<typename MatrixType> class MatrixCol
+{
+ public:
+ typedef typename MatrixType::Scalar Scalar;
+
+ MatrixCol(const MatrixType& matrix, int col)
+ : m_matrix(matrix), m_col(col)
+ {
+ EIGEN_CHECK_COL_RANGE(matrix, col);
+ }
+
+ MatrixCol(const MatrixCol& other)
+ : m_matrix(other.m_matrix), m_col(other.m_col) {}
+
+ int rows() const { return m_matrix.rows(); }
+ int cols() const { return 1; }
+
+ Scalar& write(int row, int col=0)
+ {
+ EIGEN_UNUSED(col);
+ EIGEN_CHECK_ROW_RANGE(*this, row);
+ return m_matrix.write(row, m_col);
+ }
+
+ Scalar read(int row, int col=0) const
+ {
+ EIGEN_UNUSED(col);
+ EIGEN_CHECK_ROW_RANGE(*this, row);
+ return m_matrix.read(row, m_col);
+ }
+
+ protected:
+ MatrixType m_matrix;
+ const int m_col;
+};
+
+#define EIGEN_MAKE_ROW_COL_FUNCTIONS(func, Func) \
+template<typename Derived> \
+MatrixXpr< \
+ Matrix##Func< \
+ MatrixRef< \
+ MatrixBase<Derived> \
+ > \
+ > \
+> \
+MatrixBase<Derived>::func(int i)\
+{ \
+ typedef Matrix##Func<Ref> ProductType; \
+ typedef MatrixXpr<ProductType> XprType; \
+ return XprType(ProductType(ref(), i)); \
+} \
+\
+template<typename Content> \
+MatrixXpr< \
+ Matrix##Func< \
+ MatrixXpr<Content> \
+ > \
+> \
+MatrixXpr<Content>::func(int i)\
+{ \
+ typedef Matrix##Func< \
+ MatrixXpr<Content> \
+ > ProductType; \
+ typedef MatrixXpr<ProductType> XprType; \
+ return XprType(ProductType(*this, i)); \
+}
+
+EIGEN_MAKE_ROW_COL_FUNCTIONS(row, Row)
+EIGEN_MAKE_ROW_COL_FUNCTIONS(col, Col)
+
+#undef EIGEN_MAKE_ROW_COL_FUNCTIONS
+
+}
+
+#endif // EIGEN_ROWANDCOL_H
diff --git a/src/internal/ScalarOps.h b/src/internal/ScalarOps.h
new file mode 100644
index 000000000..01772569a
--- /dev/null
+++ b/src/internal/ScalarOps.h
@@ -0,0 +1,145 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra. Eigen itself is part of the KDE project.
+//
+// Copyright (C) 2006-2007 Benoit Jacob <jacob@math.jussieu.fr>
+//
+// Eigen is free software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the Free Software
+// Foundation; either version 2 or (at your option) any later version.
+//
+// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+// details.
+//
+// You should have received a copy of the GNU General Public License along
+// with Eigen; if not, write to the Free Software Foundation, Inc., 51
+// Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+// As a special exception, if other files instantiate templates or use macros
+// or functions from this file, or you compile this file and link it
+// with other works to produce a work based on this file, this file does not
+// by itself cause the resulting work to be covered by the GNU General Public
+// 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 EIGEN_SCALAROPS_H
+#define EIGEN_SCALAROPS_H
+
+namespace Eigen {
+
+template<typename MatrixType> class ScalarProduct
+{
+ public:
+ typedef typename MatrixType::Scalar Scalar;
+
+ ScalarProduct(const MatrixType& 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(); }
+
+ Scalar read(int row, int col) const
+ {
+ return m_matrix.read(row, col) * m_scalar;
+ }
+
+ protected:
+ const MatrixType m_matrix;
+ const Scalar m_scalar;
+};
+
+template<typename Content>
+MatrixXpr<
+ ScalarProduct<
+ MatrixXpr<Content>
+ >
+>
+operator *(const MatrixXpr<Content>& xpr,
+ typename Content::Scalar scalar)
+{
+ typedef ScalarProduct<
+ MatrixXpr<Content>
+ > ProductType;
+ typedef MatrixXpr<ProductType> XprType;
+ return XprType(ProductType(xpr, scalar));
+}
+
+template<typename Content>
+MatrixXpr<
+ ScalarProduct<
+ MatrixXpr<Content>
+ >
+>
+operator *(typename Content::Scalar scalar,
+ const MatrixXpr<Content>& xpr)
+{
+ typedef ScalarProduct<
+ MatrixXpr<Content>
+ > ProductType;
+ typedef MatrixXpr<ProductType> XprType;
+ return XprType(ProductType(xpr, 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)
+{
+ return matrix * (static_cast<typename Derived::Scalar>(1) / scalar);
+}
+
+} // namespace Eigen
+
+#endif // EIGEN_SCALAROPS_H
diff --git a/src/internal/Util.h b/src/internal/Util.h
new file mode 100644
index 000000000..31b94b421
--- /dev/null
+++ b/src/internal/Util.h
@@ -0,0 +1,83 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra. Eigen itself is part of the KDE project.
+//
+// Copyright (C) 2006-2007 Benoit Jacob <jacob@math.jussieu.fr>
+//
+// Eigen is free software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the Free Software
+// Foundation; either version 2 or (at your option) any later version.
+//
+// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+// details.
+//
+// You should have received a copy of the GNU General Public License along
+// with Eigen; if not, write to the Free Software Foundation, Inc., 51
+// Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+// As a special exception, if other files instantiate templates or use macros
+// or functions from this file, or you compile this file and link it
+// with other works to produce a work based on this file, this file does not
+// by itself cause the resulting work to be covered by the GNU General Public
+// 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 EIGEN_UTIL_H
+#define EIGEN_UTIL_H
+
+#include <iostream>
+#include <cassert>
+
+#undef minor
+
+#define EIGEN_UNUSED(x) (void)x
+#define EIGEN_CHECK_RANGES(matrix, row, col) \
+ assert(row >= 0 && row < (matrix).rows() && col >= 0 && col < (matrix).cols())
+#define EIGEN_CHECK_ROW_RANGE(matrix, row) \
+ assert(row >= 0 && row < (matrix).rows())
+#define EIGEN_CHECK_COL_RANGE(matrix, col) \
+ assert(col >= 0 && col < (matrix).cols())
+
+namespace Eigen
+{
+
+//forward declarations
+template<typename T, int Rows, int Cols> class Matrix;
+template<typename T> class MatrixX;
+template<typename T, int Size> class Vector;
+template<typename T> class VectorX;
+template<typename Derived> class MatrixBase;
+template<typename Derived> class MatrixAlias;
+
+template<typename T> struct ForwardDecl;
+template<typename T, int Rows, int Cols> struct ForwardDecl< Matrix<T, Rows, Cols> >
+{ typedef T Scalar; };
+template<typename T> struct ForwardDecl< MatrixX<T> >
+{ typedef T Scalar; };
+template<typename T, int Size> struct ForwardDecl< Vector<T, Size> >
+{ typedef T Scalar; };
+template<typename T> struct ForwardDecl< VectorX<T> >
+{ typedef T Scalar; };
+template<typename T, int Rows, int Cols> struct ForwardDecl< MatrixBase<Matrix<T, Rows, Cols> > >
+{ typedef T Scalar; };
+template<typename T, int Rows, int Cols> struct ForwardDecl< MatrixAlias<Matrix<T, Rows, Cols> > >
+{ typedef T Scalar; };
+template<typename T> struct ForwardDecl< MatrixBase<MatrixX<T> > >
+{ typedef T Scalar; };
+template<typename T> struct ForwardDecl< MatrixAlias<MatrixX<T> > >
+{ typedef T Scalar; };
+template<typename T, int Size> struct ForwardDecl< MatrixBase<Vector<T, Size> > >
+{ typedef T Scalar; };
+template<typename T, int Size> struct ForwardDecl< MatrixAlias<Vector<T, Size> > >
+{ typedef T Scalar; };
+template<typename T> struct ForwardDecl< MatrixBase<VectorX<T> > >
+{ typedef T Scalar; };
+template<typename T> struct ForwardDecl< MatrixAlias<VectorX<T> > >
+{ typedef T Scalar; };
+
+template<typename MatrixType> class MatrixRef;
+
+} // namespace Eigen
+
+#endif // EIGEN_UTIL_H
diff --git a/src/internal/Vector.h b/src/internal/Vector.h
new file mode 100644
index 000000000..0d1c719c5
--- /dev/null
+++ b/src/internal/Vector.h
@@ -0,0 +1,190 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra. Eigen itself is part of the KDE project.
+//
+// Copyright (C) 2006-2007 Benoit Jacob <jacob@math.jussieu.fr>
+//
+// Eigen is free software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the Free Software
+// Foundation; either version 2 or (at your option) any later version.
+//
+// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+// details.
+//
+// You should have received a copy of the GNU General Public License along
+// with Eigen; if not, write to the Free Software Foundation, Inc., 51
+// Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+// As a special exception, if other files instantiate templates or use macros
+// or functions from this file, or you compile this file and link it
+// with other works to produce a work based on this file, this file does not
+// by itself cause the resulting work to be covered by the GNU General Public
+// 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.
+
+/** \file Matrix.h
+ * \brief Matrix and MatrixX class templates
+ */
+
+#ifndef EIGEN_VECTOR_H
+#define EIGEN_VECTOR_H
+
+#include "MatrixBase.h"
+
+namespace Eigen
+{
+
+template<typename T, int Size>
+class Vector: public MatrixBase<Vector<T, Size> >
+{
+ friend class MatrixBase<Vector<T, Size> >;
+ typedef class MatrixBase<Vector<T, Size> > Base;
+
+ public:
+ typedef T Scalar;
+
+ private:
+
+ static bool _hasDynamicNumRows()
+ { return false; }
+
+ static bool _hasDynamicNumCols()
+ { return false; }
+
+ int _rows() const
+ { return Size; }
+
+ int _cols() const
+ { return 1; }
+
+ void _resize( int rows, int cols ) const
+ {
+ assert( rows == Size && cols == 1 );
+ }
+
+ public:
+
+ Vector()
+ {
+ assert(Size > 0);
+ }
+
+ explicit Vector(int rows, int cols = 1)
+ {
+ assert(Size > 0 && rows == Size && cols == 1);
+ }
+
+ Vector(const Vector& other) : Base()
+ {
+ *this = other;
+ }
+
+ void operator=(const Vector & other)
+ { Base::operator=(other); }
+
+ template<typename XprContent>
+ void operator=(const MatrixXpr<XprContent> &xpr)
+ {
+ Base::operator=(xpr);
+ }
+
+ template<typename XprContent>
+ explicit Vector(const MatrixXpr<XprContent>& xpr)
+ {
+ *this = xpr;
+ }
+
+ int size() const { return _rows(); }
+
+ protected:
+
+ T m_array[Size];
+
+};
+
+template<typename T>
+class VectorX : public MatrixBase<VectorX<T> >
+{
+ friend class MatrixBase<VectorX<T> >;
+ typedef class MatrixBase<VectorX<T> > Base;
+
+ public:
+
+ typedef T Scalar;
+
+ explicit VectorX(int rows, int cols = 1)
+ {
+ assert(cols == 1);
+ _init(rows);
+ }
+
+ VectorX(const VectorX& other) : Base()
+ {
+ _init(other.size());
+ *this = other;
+ }
+
+ void operator=(const VectorX& other)
+ {
+ Base::operator=(other);
+ }
+
+ template<typename XprContent>
+ void operator=(const MatrixXpr<XprContent> &xpr)
+ {
+ Base::operator=(xpr);
+ }
+
+ template<typename XprContent>
+ explicit VectorX(const MatrixXpr<XprContent>& xpr)
+ {
+ _init(xpr.rows());
+ *this = xpr;
+ }
+
+ ~VectorX()
+ {
+ delete[] m_array; }
+
+ int size() const { return _rows(); }
+
+ protected:
+
+ int m_size;
+ T *m_array;
+
+ private:
+
+ int _rows() const { return m_size; }
+ int _cols() const { return 1; }
+
+ static bool _hasDynamicNumRows()
+ { return true; }
+
+ static bool _hasDynamicNumCols()
+ { return false; }
+
+ void _resize(int rows, int cols)
+ {
+ assert(rows > 0 && cols == 1);
+ if(rows > m_size)
+ {
+ delete[] m_array;
+ m_array = new T[rows];
+ }
+ m_size = rows;
+ }
+
+ void _init(int size)
+ {
+ assert(size > 0);
+ m_size = size;
+ m_array = new T[m_size];
+ }
+
+};
+
+} // namespace Eigen
+
+#endif // EIGEN_VECTOR_H