diff --git a/src/Core.h b/src/Core.h index 5a14c5bdf..6d2424f13 100644 --- a/src/Core.h +++ b/src/Core.h @@ -36,5 +36,6 @@ namespace Eigen { #include "Core/Identity.h" #include "Core/Fuzzy.h" #include "Core/Map.h" +#include "Core/IO.h" } // namespace Eigen diff --git a/src/Core/Block.h b/src/Core/Block.h index c5ab18884..55ba7830f 100644 --- a/src/Core/Block.h +++ b/src/Core/Block.h @@ -56,14 +56,14 @@ template class Block int _rows() const { return BlockRows; } int _cols() const { return BlockCols; } - Scalar& _write(int row, int col) + Scalar& _coeffRef(int row, int col) { - return m_matrix.write(row + m_startRow, col + m_startCol); + return m_matrix.coeffRef(row + m_startRow, col + m_startCol); } - Scalar _read(int row, int col) const + Scalar _coeff(int row, int col) const { - return m_matrix.read(row + m_startRow, col + m_startCol); + return m_matrix.coeff(row + m_startRow, col + m_startCol); } protected: diff --git a/src/Core/Cast.h b/src/Core/Cast.h index 6ef4e77b0..58a731522 100644 --- a/src/Core/Cast.h +++ b/src/Core/Cast.h @@ -47,9 +47,9 @@ template class Cast : NoOperatorEquals, int _rows() const { return m_matrix.rows(); } int _cols() const { return m_matrix.cols(); } - Scalar _read(int row, int col) const + Scalar _coeff(int row, int col) const { - return static_cast(m_matrix.read(row, col)); + return static_cast(m_matrix.coeff(row, col)); } protected: diff --git a/src/Core/Column.h b/src/Core/Column.h index 942b8aaf9..fc24fb484 100644 --- a/src/Core/Column.h +++ b/src/Core/Column.h @@ -53,14 +53,14 @@ template class Column int _rows() const { return m_matrix.rows(); } int _cols() const { return 1; } - Scalar& _write(int row, int) + Scalar& _coeffRef(int row, int) { - return m_matrix.write(row, m_col); + return m_matrix.coeffRef(row, m_col); } - Scalar _read(int row, int) const + Scalar _coeff(int row, int) const { - return m_matrix.read(row, m_col); + return m_matrix.coeff(row, m_col); } protected: diff --git a/src/Core/Conjugate.h b/src/Core/Conjugate.h index 515c49e6a..87054efa8 100644 --- a/src/Core/Conjugate.h +++ b/src/Core/Conjugate.h @@ -47,9 +47,9 @@ template class Conjugate : NoOperatorEquals, int _rows() const { return m_matrix.rows(); } int _cols() const { return m_matrix.cols(); } - Scalar _read(int row, int col) const + Scalar _coeff(int row, int col) const { - return conj(m_matrix.read(row, col)); + return conj(m_matrix.coeff(row, col)); } protected: @@ -63,4 +63,11 @@ MatrixBase::conjugate() const return Conjugate(static_cast(this)->ref()); } +template +const Transpose > +MatrixBase::adjoint() const +{ + return conjugate().transpose(); +} + #endif // EIGEN_CONJUGATE_H diff --git a/src/Core/DiagonalCoeffs.h b/src/Core/DiagonalCoeffs.h index a54db4938..8b788feea 100644 --- a/src/Core/DiagonalCoeffs.h +++ b/src/Core/DiagonalCoeffs.h @@ -48,14 +48,14 @@ template class DiagonalCoeffs int _rows() const { return std::min(m_matrix.rows(), m_matrix.cols()); } int _cols() const { return 1; } - Scalar& _write(int row, int) + Scalar& _coeffRef(int row, int) { - return m_matrix.write(row, row); + return m_matrix.coeffRef(row, row); } - Scalar _read(int row, int) const + Scalar _coeff(int row, int) const { - return m_matrix.read(row, row); + return m_matrix.coeff(row, row); } protected: diff --git a/src/Core/DiagonalMatrix.h b/src/Core/DiagonalMatrix.h index e7db09fc7..624eec353 100644 --- a/src/Core/DiagonalMatrix.h +++ b/src/Core/DiagonalMatrix.h @@ -52,9 +52,9 @@ class DiagonalMatrix : NoOperatorEquals, int _rows() const { return m_coeffs.size(); } int _cols() const { return m_coeffs.size(); } - Scalar _read(int row, int col) const + Scalar _coeff(int row, int col) const { - return row == col ? m_coeffs.read(row) : static_cast(0); + return row == col ? m_coeffs.coeff(row) : static_cast(0); } protected: diff --git a/src/Core/Difference.h b/src/Core/Difference.h index 7f962b4f8..525741bc2 100644 --- a/src/Core/Difference.h +++ b/src/Core/Difference.h @@ -52,9 +52,9 @@ template class Difference : NoOperatorEquals, int _rows() const { return m_lhs.rows(); } int _cols() const { return m_lhs.cols(); } - Scalar _read(int row, int col) const + Scalar _coeff(int row, int col) const { - return m_lhs.read(row, col) - m_rhs.read(row, col); + return m_lhs.coeff(row, col) - m_rhs.coeff(row, col); } protected: diff --git a/src/Core/Dot.h b/src/Core/Dot.h index cc603f4ac..1c0573a9a 100644 --- a/src/Core/Dot.h +++ b/src/Core/Dot.h @@ -32,7 +32,7 @@ struct DotUnroller static void run(const Derived1 &v1, const Derived2& v2, typename Derived1::Scalar &dot) { DotUnroller::run(v1, v2, dot); - dot += v1.read(Index) * conj(v2.read(Index)); + dot += v1.coeff(Index) * conj(v2.coeff(Index)); } }; @@ -41,7 +41,7 @@ struct DotUnroller<0, Size, Derived1, Derived2> { static void run(const Derived1 &v1, const Derived2& v2, typename Derived1::Scalar &dot) { - dot = v1.read(0) * conj(v2.read(0)); + dot = v1.coeff(0) * conj(v2.coeff(0)); } }; @@ -69,9 +69,9 @@ Scalar MatrixBase::dot(const OtherDerived& other) const ::run(*static_cast(this), other, res); else { - res = (*this).read(0) * conj(other.read(0)); + res = (*this).coeff(0) * conj(other.coeff(0)); for(int i = 1; i < size(); i++) - res += (*this).read(i)* conj(other.read(i)); + res += (*this).coeff(i)* conj(other.coeff(i)); } return res; } diff --git a/src/Core/DynBlock.h b/src/Core/DynBlock.h index efe16abc4..024a0c030 100644 --- a/src/Core/DynBlock.h +++ b/src/Core/DynBlock.h @@ -60,14 +60,14 @@ template class DynBlock int _rows() const { return m_blockRows; } int _cols() const { return m_blockCols; } - Scalar& _write(int row, int col) + Scalar& _coeffRef(int row, int col) { - return m_matrix.write(row + m_startRow, col + m_startCol); + return m_matrix.coeffRef(row + m_startRow, col + m_startCol); } - Scalar _read(int row, int col) const + Scalar _coeff(int row, int col) const { - return m_matrix.read(row + m_startRow, col + m_startCol); + return m_matrix.coeff(row + m_startRow, col + m_startCol); } protected: diff --git a/src/Core/IO.h b/src/Core/IO.h new file mode 100644 index 000000000..0aa8f22f7 --- /dev/null +++ b/src/Core/IO.h @@ -0,0 +1,45 @@ +// 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 +// +// 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_IO_H +#define EIGEN_IO_H + +template +std::ostream & operator << +( std::ostream & s, + const MatrixBase & 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; +} + +#endif // EIGEN_IO_H diff --git a/src/Core/Identity.h b/src/Core/Identity.h index cf74fdeb7..ca785f3e4 100644 --- a/src/Core/Identity.h +++ b/src/Core/Identity.h @@ -46,7 +46,7 @@ template class Identity : NoOperatorEquals, int _rows() const { return m_rows; } int _cols() const { return m_rows; } - Scalar _read(int row, int col) const + Scalar _coeff(int row, int col) const { return row == col ? static_cast(1) : static_cast(0); } diff --git a/src/Core/Map.h b/src/Core/Map.h index 420d318cb..e62603195 100644 --- a/src/Core/Map.h +++ b/src/Core/Map.h @@ -48,12 +48,12 @@ template class Map int _rows() const { return m_rows; } int _cols() const { return m_cols; } - const Scalar& _read(int row, int col) const + const Scalar& _coeff(int row, int col) const { return m_data[row + col * m_rows]; } - Scalar& _write(int row, int col) + Scalar& _coeffRef(int row, int col) { return m_data[row + col * m_rows]; } diff --git a/src/Core/Matrix.h b/src/Core/Matrix.h index a06cfe335..cd71b50c5 100644 --- a/src/Core/Matrix.h +++ b/src/Core/Matrix.h @@ -49,12 +49,12 @@ class Matrix : public MatrixBase<_Scalar, Matrix<_Scalar, _Rows, _Cols> >, private: Ref _ref() const { return Ref(*this); } - const Scalar& _read(int row, int col) const + const Scalar& _coeff(int row, int col) const { return data()[row + col * Storage::_rows()]; } - Scalar& _write(int row, int col) + Scalar& _coeffRef(int row, int col) { return data()[row + col * Storage::_rows()]; } diff --git a/src/Core/MatrixBase.h b/src/Core/MatrixBase.h index e53cbad45..cf4b31be2 100644 --- a/src/Core/MatrixBase.h +++ b/src/Core/MatrixBase.h @@ -70,8 +70,7 @@ template class MatrixBase Transpose transpose() const; const Conjugate conjugate() const; - const Transpose > adjoint() const - { return conjugate().transpose(); } + const Transpose > adjoint() const; Scalar trace() const; template @@ -139,71 +138,55 @@ template class MatrixBase Derived& operator/=(const std::complex& other); Derived& operator/=(const std::complex& other); - Scalar read(int row, int col, AssertLevel assertLevel = InternalDebugging) const + Scalar coeff(int row, int col, AssertLevel assertLevel = InternalDebugging) const { eigen_assert(assertLevel, row >= 0 && row < rows() && col >= 0 && col < cols()); - return static_cast(this)->_read(row, col); + return static_cast(this)->_coeff(row, col); } - Scalar operator()(int row, int col) const { return read(row, col, UserDebugging); } + Scalar operator()(int row, int col) const { return coeff(row, col, UserDebugging); } - Scalar& write(int row, int col, AssertLevel assertLevel = InternalDebugging) + Scalar& coeffRef(int row, int col, AssertLevel assertLevel = InternalDebugging) { eigen_assert(assertLevel, row >= 0 && row < rows() && col >= 0 && col < cols()); - return static_cast(this)->_write(row, col); + return static_cast(this)->_coeffRef(row, col); } - Scalar& operator()(int row, int col) { return write(row, col, UserDebugging); } + Scalar& operator()(int row, int col) { return coeffRef(row, col, UserDebugging); } - Scalar read(int index, AssertLevel assertLevel = InternalDebugging) const + Scalar coeff(int index, AssertLevel assertLevel = InternalDebugging) const { eigen_assert(assertLevel, IsVector); if(RowsAtCompileTime == 1) { eigen_assert(assertLevel, index >= 0 && index < cols()); - return read(0, index); + return coeff(0, index); } else { eigen_assert(assertLevel, index >= 0 && index < rows()); - return read(index, 0); + return coeff(index, 0); } } - Scalar operator[](int index) const { return read(index, UserDebugging); } + Scalar operator[](int index) const { return coeff(index, UserDebugging); } - Scalar& write(int index, AssertLevel assertLevel = InternalDebugging) + Scalar& coeffRef(int index, AssertLevel assertLevel = InternalDebugging) { eigen_assert(assertLevel, IsVector); if(RowsAtCompileTime == 1) { eigen_assert(assertLevel, index >= 0 && index < cols()); - return write(0, index); + return coeffRef(0, index); } else { eigen_assert(assertLevel, index >= 0 && index < rows()); - return write(index, 0); + return coeffRef(index, 0); } } - Scalar& operator[](int index) { return write(index, UserDebugging); } + Scalar& operator[](int index) { return coeffRef(index, UserDebugging); } Eval eval() const EIGEN_ALWAYS_INLINE; }; -template -std::ostream & operator << -( std::ostream & s, - const MatrixBase & 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; -} - #endif // EIGEN_MATRIXBASE_H diff --git a/src/Core/MatrixRef.h b/src/Core/MatrixRef.h index e79c32a08..b5f0a1eef 100644 --- a/src/Core/MatrixRef.h +++ b/src/Core/MatrixRef.h @@ -46,14 +46,14 @@ template class MatrixRef int _rows() const { return m_matrix.rows(); } int _cols() const { return m_matrix.cols(); } - const Scalar& _read(int row, int col) const + const Scalar& _coeff(int row, int col) const { - return m_matrix._read(row, col); + return m_matrix._coeff(row, col); } - Scalar& _write(int row, int col) + Scalar& _coeffRef(int row, int col) { - return m_matrix.write(row, col); + return m_matrix.coeffRef(row, col); } protected: diff --git a/src/Core/Minor.h b/src/Core/Minor.h index 93789183f..d238d5084 100644 --- a/src/Core/Minor.h +++ b/src/Core/Minor.h @@ -58,14 +58,14 @@ template class Minor int _rows() const { return m_matrix.rows() - 1; } int _cols() const { return m_matrix.cols() - 1; } - Scalar& _write(int row, int col) + Scalar& _coeffRef(int row, int col) { - return m_matrix.write(row + (row >= m_row), col + (col >= m_col)); + return m_matrix.coeffRef(row + (row >= m_row), col + (col >= m_col)); } - Scalar _read(int row, int col) const + Scalar _coeff(int row, int col) const { - return m_matrix.read(row + (row >= m_row), col + (col >= m_col)); + return m_matrix.coeff(row + (row >= m_row), col + (col >= m_col)); } protected: diff --git a/src/Core/Ones.h b/src/Core/Ones.h index 01a8250ef..020e5031f 100644 --- a/src/Core/Ones.h +++ b/src/Core/Ones.h @@ -46,7 +46,7 @@ template class Ones : NoOperatorEquals, int _rows() const { return m_rows; } int _cols() const { return m_cols; } - Scalar _read(int, int) const + Scalar _coeff(int, int) const { return static_cast(1); } diff --git a/src/Core/OperatorEquals.h b/src/Core/OperatorEquals.h index bbf55b8f1..8206d280f 100644 --- a/src/Core/OperatorEquals.h +++ b/src/Core/OperatorEquals.h @@ -36,7 +36,7 @@ struct OperatorEqualsUnroller static void run(Derived1 &dst, const Derived2 &src) { OperatorEqualsUnroller::run(dst, src); - dst.write(row, col) = src.read(row, col); + dst.coeffRef(row, col) = src.coeff(row, col); } }; @@ -52,7 +52,7 @@ struct OperatorEqualsUnroller { static void run(Derived1 &dst, const Derived2 &src) { - dst.write(0, 0) = src.read(0, 0); + dst.coeffRef(0, 0) = src.coeff(0, 0); } }; @@ -75,7 +75,7 @@ Derived& MatrixBase else for(int j = 0; j < cols(); j++) //traverse in column-dominant order for(int i = 0; i < rows(); i++) - write(i, j) = other.read(i, j); + coeffRef(i, j) = other.coeff(i, j); return *static_cast(this); } diff --git a/src/Core/Opposite.h b/src/Core/Opposite.h index 0a0bcc24a..627b0c0b5 100644 --- a/src/Core/Opposite.h +++ b/src/Core/Opposite.h @@ -47,9 +47,9 @@ template class Opposite : NoOperatorEquals, int _rows() const { return m_matrix.rows(); } int _cols() const { return m_matrix.cols(); } - Scalar _read(int row, int col) const + Scalar _coeff(int row, int col) const { - return -(m_matrix.read(row, col)); + return -(m_matrix.coeff(row, col)); } protected: diff --git a/src/Core/Product.h b/src/Core/Product.h index 39ceeaf90..8403cb3ba 100644 --- a/src/Core/Product.h +++ b/src/Core/Product.h @@ -33,7 +33,7 @@ struct ProductUnroller typename Lhs::Scalar &res) { ProductUnroller::run(row, col, lhs, rhs, res); - res += lhs.read(row, Index) * rhs.read(Index, col); + res += lhs.coeff(row, Index) * rhs.coeff(Index, col); } }; @@ -43,7 +43,7 @@ struct ProductUnroller<0, Size, Lhs, Rhs> static void run(int row, int col, const Lhs& lhs, const Rhs& rhs, typename Lhs::Scalar &res) { - res = lhs.read(row, 0) * rhs.read(0, col); + res = lhs.coeff(row, 0) * rhs.coeff(0, col); } }; @@ -86,7 +86,7 @@ template class Product : NoOperatorEquals, int _rows() const { return m_lhs.rows(); } int _cols() const { return m_rhs.cols(); } - Scalar _read(int row, int col) const + Scalar _coeff(int row, int col) const { Scalar res; if(EIGEN_UNROLLED_LOOPS @@ -95,9 +95,9 @@ template class Product : NoOperatorEquals, ::run(row, col, m_lhs, m_rhs, res); else { - res = m_lhs.read(row, 0) * m_rhs.read(0, col); + res = m_lhs.coeff(row, 0) * m_rhs.coeff(0, col); for(int i = 1; i < m_lhs.cols(); i++) - res += m_lhs.read(row, i) * m_rhs.read(i, col); + res += m_lhs.coeff(row, i) * m_rhs.coeff(i, col); } return res; } diff --git a/src/Core/Random.h b/src/Core/Random.h index 353985243..905010553 100644 --- a/src/Core/Random.h +++ b/src/Core/Random.h @@ -46,7 +46,7 @@ template class Random : NoOperatorEquals, int _rows() const { return m_rows; } int _cols() const { return m_cols; } - Scalar _read(int, int) const + Scalar _coeff(int, int) const { return random(); } diff --git a/src/Core/Row.h b/src/Core/Row.h index 6da721693..71acbf51f 100644 --- a/src/Core/Row.h +++ b/src/Core/Row.h @@ -60,14 +60,14 @@ template class Row int _rows() const { return 1; } int _cols() const { return m_matrix.cols(); } - Scalar& _write(int, int col) + Scalar& _coeffRef(int, int col) { - return m_matrix.write(m_row, col); + return m_matrix.coeffRef(m_row, col); } - Scalar _read(int, int col) const + Scalar _coeff(int, int col) const { - return m_matrix.read(m_row, col); + return m_matrix.coeff(m_row, col); } protected: diff --git a/src/Core/ScalarMultiple.h b/src/Core/ScalarMultiple.h index 98264c2a6..0f269c197 100644 --- a/src/Core/ScalarMultiple.h +++ b/src/Core/ScalarMultiple.h @@ -48,9 +48,9 @@ template class ScalarMultiple : NoOperatorEquals, int _rows() const { return m_matrix.rows(); } int _cols() const { return m_matrix.cols(); } - Scalar _read(int row, int col) const + Scalar _coeff(int row, int col) const { - return m_matrix.read(row, col) * m_scalar; + return m_matrix.coeff(row, col) * m_scalar; } protected: diff --git a/src/Core/Sum.h b/src/Core/Sum.h index 62eec75ac..cbf1b736a 100644 --- a/src/Core/Sum.h +++ b/src/Core/Sum.h @@ -51,9 +51,9 @@ template class Sum : NoOperatorEquals, int _rows() const { return m_lhs.rows(); } int _cols() const { return m_lhs.cols(); } - Scalar _read(int row, int col) const + Scalar _coeff(int row, int col) const { - return m_lhs.read(row, col) + m_rhs.read(row, col); + return m_lhs.coeff(row, col) + m_rhs.coeff(row, col); } protected: diff --git a/src/Core/Trace.h b/src/Core/Trace.h index e6af33247..214953ac5 100644 --- a/src/Core/Trace.h +++ b/src/Core/Trace.h @@ -31,7 +31,7 @@ template struct TraceUnroller static void run(const Derived &mat, typename Derived::Scalar &trace) { TraceUnroller::run(mat, trace); - trace += mat.read(Index, Index); + trace += mat.coeff(Index, Index); } }; @@ -39,7 +39,7 @@ template struct TraceUnroller<0, Rows, Derived> { static void run(const Derived &mat, typename Derived::Scalar &trace) { - trace = mat.read(0, 0); + trace = mat.coeff(0, 0); } }; @@ -64,9 +64,9 @@ Scalar MatrixBase::trace() const ::run(*static_cast(this), res); else { - res = read(0, 0); + res = coeff(0, 0); for(int i = 1; i < rows(); i++) - res += read(i, i); + res += coeff(i, i); } return res; } diff --git a/src/Core/Transpose.h b/src/Core/Transpose.h index 8141e60b1..f10de9256 100644 --- a/src/Core/Transpose.h +++ b/src/Core/Transpose.h @@ -49,14 +49,14 @@ template class Transpose int _rows() const { return m_matrix.cols(); } int _cols() const { return m_matrix.rows(); } - Scalar& _write(int row, int col) + Scalar& _coeffRef(int row, int col) { - return m_matrix.write(col, row); + return m_matrix.coeffRef(col, row); } - Scalar _read(int row, int col) const + Scalar _coeff(int row, int col) const { - return m_matrix.read(col, row); + return m_matrix.coeff(col, row); } protected: diff --git a/src/Core/Zero.h b/src/Core/Zero.h index 8f01e074c..0f983ce20 100644 --- a/src/Core/Zero.h +++ b/src/Core/Zero.h @@ -46,7 +46,7 @@ template class Zero : NoOperatorEquals, int _rows() const { return m_rows; } int _cols() const { return m_cols; } - Scalar _read(int, int) const + Scalar _coeff(int, int) const { return static_cast(0); }