mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Removed Column and Row in favor of Block
This commit is contained in:
@@ -79,6 +79,24 @@ template<typename MatrixType, int BlockRows, int BlockCols> 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<matrix.rows())
|
||||
||((BlockRows==MatrixType::RowsAtCompileTime) && (BlockCols==1) && i<matrix.cols())));
|
||||
}
|
||||
|
||||
/** Fixed-size constructor
|
||||
*/
|
||||
Block(const MatRef& matrix, int startRow, int startCol)
|
||||
@@ -354,4 +372,46 @@ const Block<Derived, BlockRows, BlockCols> MatrixBase<Derived>
|
||||
return Block<Derived, BlockRows, BlockCols>(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<typename Derived>
|
||||
Block<Derived, ei_traits<Derived>::RowsAtCompileTime, 1>
|
||||
MatrixBase<Derived>::col(int i)
|
||||
{
|
||||
return Block<Derived, ei_traits<Derived>::RowsAtCompileTime, 1>(asArg(), i);
|
||||
}
|
||||
|
||||
/** This is the const version of col(). */
|
||||
template<typename Derived>
|
||||
const Block<Derived, ei_traits<Derived>::RowsAtCompileTime, 1>
|
||||
MatrixBase<Derived>::col(int i) const
|
||||
{
|
||||
return Block<Derived, ei_traits<Derived>::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<typename Derived>
|
||||
Block<Derived, 1, ei_traits<Derived>::ColsAtCompileTime>
|
||||
MatrixBase<Derived>::row(int i)
|
||||
{
|
||||
return Block<Derived, 1, ei_traits<Derived>::ColsAtCompileTime>(asArg(), i);
|
||||
}
|
||||
|
||||
/** This is the const version of row(). */
|
||||
template<typename Derived>
|
||||
const Block<Derived, 1, ei_traits<Derived>::ColsAtCompileTime>
|
||||
MatrixBase<Derived>::row(int i) const
|
||||
{
|
||||
return Block<Derived, 1, ei_traits<Derived>::ColsAtCompileTime>(asArg(), i);
|
||||
}
|
||||
|
||||
#endif // EIGEN_BLOCK_H
|
||||
|
||||
@@ -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 <jacob@math.jussieu.fr>
|
||||
//
|
||||
// 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
#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<typename MatrixType>
|
||||
struct ei_traits<Column<MatrixType> >
|
||||
{
|
||||
typedef typename MatrixType::Scalar Scalar;
|
||||
enum {
|
||||
RowsAtCompileTime = MatrixType::RowsAtCompileTime,
|
||||
ColsAtCompileTime = 1,
|
||||
MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
|
||||
MaxColsAtCompileTime = 1
|
||||
};
|
||||
};
|
||||
|
||||
template<typename MatrixType> class Column
|
||||
: public MatrixBase<Column<MatrixType> >
|
||||
{
|
||||
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<typename Derived>
|
||||
Column<Derived>
|
||||
MatrixBase<Derived>::col(int i)
|
||||
{
|
||||
return Column<Derived>(asArg(), i);
|
||||
}
|
||||
|
||||
/** This is the const version of col(). */
|
||||
template<typename Derived>
|
||||
const Column<Derived>
|
||||
MatrixBase<Derived>::col(int i) const
|
||||
{
|
||||
return Column<Derived>(asArg(), i);
|
||||
}
|
||||
|
||||
#endif // EIGEN_COLUMN_H
|
||||
@@ -52,8 +52,11 @@ struct MatrixBase<Derived>::CommaInitializer
|
||||
m_row+=m_currentBlockRows;
|
||||
m_col = 0;
|
||||
m_currentBlockRows = 1;
|
||||
assert(m_row<m_matrix.rows()
|
||||
&& "Too many rows passed to MatrixBase::operator<<");
|
||||
}
|
||||
assert(m_col<m_matrix.cols() && "Too many coefficients passed to Matrix::operator<<");
|
||||
assert(m_col<m_matrix.cols()
|
||||
&& "Too many coefficients passed to MatrixBase::operator<<");
|
||||
assert(m_currentBlockRows==1);
|
||||
m_matrix.coeffRef(m_row, m_col++) = s;
|
||||
return *this;
|
||||
@@ -67,10 +70,17 @@ struct MatrixBase<Derived>::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_col<m_matrix.cols() && "Too many coefficients passed to Matrix::operator<<");
|
||||
assert(m_col<m_matrix.cols()
|
||||
&& "Too many coefficients passed to MatrixBase::operator<<");
|
||||
assert(m_currentBlockRows==other.rows());
|
||||
m_matrix.block(m_row, m_col, other.rows(), other.cols()) = other;
|
||||
if (OtherDerived::RowsAtCompileTime>0 && 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;
|
||||
}
|
||||
|
||||
@@ -29,8 +29,6 @@ template<typename T> struct ei_traits;
|
||||
|
||||
template<typename _Scalar, int _Rows, int _Cols, int _StorageOrder, int _MaxRows, int _MaxCols> class Matrix;
|
||||
template<typename MatrixType> class MatrixRef;
|
||||
template<typename MatrixType> class Row;
|
||||
template<typename MatrixType> class Column;
|
||||
template<typename MatrixType> class Minor;
|
||||
template<typename MatrixType, int BlockRows=Dynamic, int BlockCols=Dynamic> class Block;
|
||||
template<typename MatrixType> class Transpose;
|
||||
|
||||
@@ -193,11 +193,11 @@ template<typename Derived> class MatrixBase
|
||||
|
||||
/// \name sub-matrices
|
||||
//@{
|
||||
Row<Derived> row(int i);
|
||||
const Row<Derived> row(int i) const;
|
||||
Block<Derived, 1, ei_traits<Derived>::ColsAtCompileTime> row(int i);
|
||||
const Block<Derived, 1, ei_traits<Derived>::ColsAtCompileTime> row(int i) const;
|
||||
|
||||
Column<Derived> col(int i);
|
||||
const Column<Derived> col(int i) const;
|
||||
Block<Derived, ei_traits<Derived>::RowsAtCompileTime, 1> col(int i);
|
||||
const Block<Derived, ei_traits<Derived>::RowsAtCompileTime, 1> col(int i) const;
|
||||
|
||||
Minor<Derived> minor(int row, int col);
|
||||
const Minor<Derived> minor(int row, int col) const;
|
||||
|
||||
@@ -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 <jacob@math.jussieu.fr>
|
||||
//
|
||||
// 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
#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<typename MatrixType>
|
||||
struct ei_traits<Row<MatrixType> >
|
||||
{
|
||||
typedef typename MatrixType::Scalar Scalar;
|
||||
enum {
|
||||
RowsAtCompileTime = 1,
|
||||
ColsAtCompileTime = MatrixType::ColsAtCompileTime,
|
||||
MaxRowsAtCompileTime = 1,
|
||||
MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime
|
||||
};
|
||||
};
|
||||
|
||||
template<typename MatrixType> class Row
|
||||
: public MatrixBase<Row<MatrixType> >
|
||||
{
|
||||
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<typename Derived>
|
||||
Row<Derived>
|
||||
MatrixBase<Derived>::row(int i)
|
||||
{
|
||||
return Row<Derived>(asArg(), i);
|
||||
}
|
||||
|
||||
/** This is the const version of row(). */
|
||||
template<typename Derived>
|
||||
const Row<Derived>
|
||||
MatrixBase<Derived>::row(int i) const
|
||||
{
|
||||
return Row<Derived>(asArg(), i);
|
||||
}
|
||||
|
||||
#endif // EIGEN_ROW_H
|
||||
Reference in New Issue
Block a user