From 35bce20954581415a9e5057cc24f6e4769ef78f5 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Wed, 12 Mar 2008 18:10:52 +0000 Subject: Removed Column and Row in favor of Block --- Eigen/src/Core/Block.h | 60 ++++++++++++++++++ Eigen/src/Core/Column.h | 119 ---------------------------------- Eigen/src/Core/CommaInitializer.h | 16 ++++- Eigen/src/Core/ForwardDeclarations.h | 2 - Eigen/src/Core/MatrixBase.h | 8 +-- Eigen/src/Core/Row.h | 120 ----------------------------------- 6 files changed, 77 insertions(+), 248 deletions(-) delete mode 100644 Eigen/src/Core/Column.h delete mode 100644 Eigen/src/Core/Row.h (limited to 'Eigen/src') diff --git a/Eigen/src/Core/Block.h b/Eigen/src/Core/Block.h index 8db636ece..a2a581aac 100644 --- a/Eigen/src/Core/Block.h +++ b/Eigen/src/Core/Block.h @@ -79,6 +79,24 @@ template class Block typedef typename MatrixType::AsArg MatRef; + /** Column or Row constructor + */ + Block(const MatRef& matrix, int i) + : m_matrix(matrix), + // It is a row if and only if BlockRows==1 and BlockCols==MatrixType::ColsAtCompileTime, + // and it is a column if and only if BlockRows==MatrixType::RowsAtCompileTime and BlockCols==1, + // all other cases are invalid. + // The case a 1x1 matrix looks ambibuous, but the result is the same anyway. + m_startRow( (BlockRows==1) && (BlockCols==MatrixType::ColsAtCompileTime) ? i : 0), + m_startCol( (BlockRows==MatrixType::RowsAtCompileTime) && (BlockCols==1) ? i : 0), + m_blockRows(matrix.rows()), // if it is a row, then m_blockRows has a fixed-size of 1, so no pb to try to overwrite it + m_blockCols(matrix.cols()) // same for m_blockCols + { + assert( (i>=0) && ( + ((BlockRows==1) && (BlockCols==MatrixType::ColsAtCompileTime) && i MatrixBase return Block(asArg(), startRow, startCol); } +/** \returns an expression of the \a i-th column of *this. Note that the numbering starts at 0. + * + * Example: \include MatrixBase_col.cpp + * Output: \verbinclude MatrixBase_col.out + * + * \sa row(), class Block */ +template +Block::RowsAtCompileTime, 1> +MatrixBase::col(int i) +{ + return Block::RowsAtCompileTime, 1>(asArg(), i); +} + +/** This is the const version of col(). */ +template +const Block::RowsAtCompileTime, 1> +MatrixBase::col(int i) const +{ + return Block::RowsAtCompileTime, 1>(asArg(), i); +} + +/** \returns an expression of the \a i-th row of *this. Note that the numbering starts at 0. + * + * Example: \include MatrixBase_row.cpp + * Output: \verbinclude MatrixBase_row.out + * + * \sa col(), class Block */ +template +Block::ColsAtCompileTime> +MatrixBase::row(int i) +{ + return Block::ColsAtCompileTime>(asArg(), i); +} + +/** This is the const version of row(). */ +template +const Block::ColsAtCompileTime> +MatrixBase::row(int i) const +{ + return Block::ColsAtCompileTime>(asArg(), i); +} + #endif // EIGEN_BLOCK_H diff --git a/Eigen/src/Core/Column.h b/Eigen/src/Core/Column.h deleted file mode 100644 index 943095671..000000000 --- a/Eigen/src/Core/Column.h +++ /dev/null @@ -1,119 +0,0 @@ -// 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-2008 Benoit Jacob -// -// Eigen is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 3 of the License, or (at your option) any later version. -// -// Alternatively, 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 of -// the License, 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 Lesser General Public License or the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License and a copy of the GNU General Public License along with -// Eigen. If not, see . - -#ifndef EIGEN_COLUMN_H -#define EIGEN_COLUMN_H - -/** \class Column - * - * \brief Expression of a column - * - * \param MatrixType the type of the object in which we are taking a column - * - * This class represents an expression of a column. It is the return - * type of MatrixBase::col() and most of the time this is the only way it - * is used. - * - * However, if you want to directly maniputate column expressions, - * for instance if you want to write a function returning such an expression, you - * will need to use this class. - * - * Here is an example illustrating this: - * \include class_Column.cpp - * Output: \verbinclude class_Column.out - * - * \sa MatrixBase::col() - */ -template -struct ei_traits > -{ - typedef typename MatrixType::Scalar Scalar; - enum { - RowsAtCompileTime = MatrixType::RowsAtCompileTime, - ColsAtCompileTime = 1, - MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime, - MaxColsAtCompileTime = 1 - }; -}; - -template class Column - : public MatrixBase > -{ - public: - - EIGEN_BASIC_PUBLIC_INTERFACE(Column) - - typedef typename MatrixType::AsArg MatRef; - - Column(const MatRef& matrix, int col) - : m_matrix(matrix), m_col(col) - { - assert(col >= 0 && col < matrix.cols()); - } - - EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Column) - - private: - - const Column& _asArg() const { return *this; } - int _rows() const { return m_matrix.rows(); } - int _cols() const { return 1; } - - Scalar& _coeffRef(int row, int) - { - return m_matrix.coeffRef(row, m_col); - } - - Scalar _coeff(int row, int) const - { - return m_matrix.coeff(row, m_col); - } - - protected: - MatRef m_matrix; - const int m_col; -}; - -/** \returns an expression of the \a i-th column of *this. Note that the numbering starts at 0. - * - * Example: \include MatrixBase_col.cpp - * Output: \verbinclude MatrixBase_col.out - * - * \sa row(), class Column */ -template -Column -MatrixBase::col(int i) -{ - return Column(asArg(), i); -} - -/** This is the const version of col(). */ -template -const Column -MatrixBase::col(int i) const -{ - return Column(asArg(), i); -} - -#endif // EIGEN_COLUMN_H diff --git a/Eigen/src/Core/CommaInitializer.h b/Eigen/src/Core/CommaInitializer.h index 5456eb7c6..c7a292437 100644 --- a/Eigen/src/Core/CommaInitializer.h +++ b/Eigen/src/Core/CommaInitializer.h @@ -52,8 +52,11 @@ struct MatrixBase::CommaInitializer m_row+=m_currentBlockRows; m_col = 0; m_currentBlockRows = 1; + assert(m_row::CommaInitializer m_row+=m_currentBlockRows; m_col = 0; m_currentBlockRows = other.rows(); + assert(m_row+m_currentBlockRows<=m_matrix.rows() + && "Too many rows passed to MatrixBase::operator<<"); } - assert(m_col0 && OtherDerived::ColsAtCompileTime>0) + m_matrix.block< (OtherDerived::RowsAtCompileTime>0?OtherDerived::RowsAtCompileTime:1) , + (OtherDerived::ColsAtCompileTime>0?OtherDerived::ColsAtCompileTime:1) >(m_row, m_col) = other; + else + m_matrix.block(m_row, m_col, other.rows(), other.cols()) = other; m_col += other.cols(); return *this; } diff --git a/Eigen/src/Core/ForwardDeclarations.h b/Eigen/src/Core/ForwardDeclarations.h index a548cd475..a43a34745 100644 --- a/Eigen/src/Core/ForwardDeclarations.h +++ b/Eigen/src/Core/ForwardDeclarations.h @@ -29,8 +29,6 @@ template struct ei_traits; template class Matrix; template class MatrixRef; -template class Row; -template class Column; template class Minor; template class Block; template class Transpose; diff --git a/Eigen/src/Core/MatrixBase.h b/Eigen/src/Core/MatrixBase.h index 62dfc6bee..18ffdd00f 100644 --- a/Eigen/src/Core/MatrixBase.h +++ b/Eigen/src/Core/MatrixBase.h @@ -193,11 +193,11 @@ template class MatrixBase /// \name sub-matrices //@{ - Row row(int i); - const Row row(int i) const; + Block::ColsAtCompileTime> row(int i); + const Block::ColsAtCompileTime> row(int i) const; - Column col(int i); - const Column col(int i) const; + Block::RowsAtCompileTime, 1> col(int i); + const Block::RowsAtCompileTime, 1> col(int i) const; Minor minor(int row, int col); const Minor minor(int row, int col) const; diff --git a/Eigen/src/Core/Row.h b/Eigen/src/Core/Row.h deleted file mode 100644 index 57a56852c..000000000 --- a/Eigen/src/Core/Row.h +++ /dev/null @@ -1,120 +0,0 @@ -// 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-2008 Benoit Jacob -// -// Eigen is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 3 of the License, or (at your option) any later version. -// -// Alternatively, 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 of -// the License, 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 Lesser General Public License or the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License and a copy of the GNU General Public License along with -// Eigen. If not, see . - -#ifndef EIGEN_ROW_H -#define EIGEN_ROW_H - -/** \class Row - * - * \brief Expression of a row - * - * \param MatrixType the type of the object in which we are taking a row - * - * This class represents an expression of a row. It is the return - * type of MatrixBase::row() and most of the time this is the only way it - * is used. - * - * However, if you want to directly maniputate row expressions, - * for instance if you want to write a function returning such an expression, you - * will need to use this class. - * - * Here is an example illustrating this: - * \include class_Row.cpp - * Output: \verbinclude class_Row.out - * - * \sa MatrixBase::row() - */ -template -struct ei_traits > -{ - typedef typename MatrixType::Scalar Scalar; - enum { - RowsAtCompileTime = 1, - ColsAtCompileTime = MatrixType::ColsAtCompileTime, - MaxRowsAtCompileTime = 1, - MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime - }; -}; - -template class Row - : public MatrixBase > -{ - public: - - EIGEN_BASIC_PUBLIC_INTERFACE(Row) - - typedef typename MatrixType::AsArg MatRef; - - Row(const MatRef& matrix, int row) - : m_matrix(matrix), m_row(row) - { - assert(row >= 0 && row < matrix.rows()); - } - - EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Row) - - private: - - const Row& _asArg() const { return *this; } - - int _rows() const { return 1; } - int _cols() const { return m_matrix.cols(); } - - Scalar& _coeffRef(int, int col) - { - return m_matrix.coeffRef(m_row, col); - } - - Scalar _coeff(int, int col) const - { - return m_matrix.coeff(m_row, col); - } - - protected: - MatRef m_matrix; - const int m_row; -}; - -/** \returns an expression of the \a i-th row of *this. Note that the numbering starts at 0. - * - * Example: \include MatrixBase_row.cpp - * Output: \verbinclude MatrixBase_row.out - * - * \sa col(), class Row */ -template -Row -MatrixBase::row(int i) -{ - return Row(asArg(), i); -} - -/** This is the const version of row(). */ -template -const Row -MatrixBase::row(int i) const -{ - return Row(asArg(), i); -} - -#endif // EIGEN_ROW_H -- cgit v1.2.3