2007-10-14 14:45:31 +00:00
|
|
|
// This file is part of Eigen, a lightweight C++ template library
|
|
|
|
|
// for linear algebra. Eigen itself is part of the KDE project.
|
|
|
|
|
//
|
2008-01-07 09:34:21 +00:00
|
|
|
// Copyright (C) 2006-2008 Benoit Jacob <jacob@math.jussieu.fr>
|
2007-10-14 14:45:31 +00:00
|
|
|
//
|
2008-02-28 15:44:45 +00:00
|
|
|
// Eigen is free software; you can redistribute it and/or
|
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
2008-03-04 12:34:58 +00:00
|
|
|
// License as published by the Free Software Foundation; either
|
2008-02-28 15:44:45 +00:00
|
|
|
// 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
|
2008-03-04 12:34:58 +00:00
|
|
|
// published by the Free Software Foundation; either version 2 of
|
2008-02-28 15:44:45 +00:00
|
|
|
// the License, or (at your option) any later version.
|
2007-10-14 14:45:31 +00:00
|
|
|
//
|
|
|
|
|
// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
2008-02-28 15:44:45 +00:00
|
|
|
// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
|
|
|
|
|
// GNU General Public License for more details.
|
2007-10-14 14:45:31 +00:00
|
|
|
//
|
2008-03-04 12:34:58 +00:00
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
2008-02-28 15:44:45 +00:00
|
|
|
// License and a copy of the GNU General Public License along with
|
|
|
|
|
// Eigen. If not, see <http://www.gnu.org/licenses/>.
|
2007-10-14 14:45:31 +00:00
|
|
|
|
2007-12-15 18:16:30 +00:00
|
|
|
#ifndef EIGEN_DIAGONALCOEFFS_H
|
|
|
|
|
#define EIGEN_DIAGONALCOEFFS_H
|
2007-10-14 14:45:31 +00:00
|
|
|
|
2007-12-27 21:43:10 +00:00
|
|
|
/** \class DiagonalCoeffs
|
|
|
|
|
*
|
2008-03-15 11:05:38 +00:00
|
|
|
* \brief Expression of the main diagonal of a matrix
|
2007-12-27 21:43:10 +00:00
|
|
|
*
|
|
|
|
|
* \param MatrixType the type of the object in which we are taking the main diagonal
|
|
|
|
|
*
|
2008-03-15 11:05:38 +00:00
|
|
|
* The matrix is not required to be square.
|
|
|
|
|
*
|
2007-12-27 21:43:10 +00:00
|
|
|
* This class represents an expression of the main diagonal of a square matrix.
|
|
|
|
|
* It is the return type of MatrixBase::diagonal() and most of the time this is
|
|
|
|
|
* the only way it is used.
|
|
|
|
|
*
|
|
|
|
|
* \sa MatrixBase::diagonal()
|
|
|
|
|
*/
|
2008-03-10 17:23:11 +00:00
|
|
|
template<typename MatrixType>
|
2008-03-12 17:17:36 +00:00
|
|
|
struct ei_traits<DiagonalCoeffs<MatrixType> >
|
|
|
|
|
{
|
|
|
|
|
typedef typename MatrixType::Scalar Scalar;
|
|
|
|
|
enum {
|
|
|
|
|
RowsAtCompileTime = MatrixType::SizeAtCompileTime == Dynamic ? Dynamic
|
|
|
|
|
: EIGEN_ENUM_MIN(MatrixType::RowsAtCompileTime,
|
|
|
|
|
MatrixType::ColsAtCompileTime),
|
|
|
|
|
ColsAtCompileTime = 1,
|
|
|
|
|
MaxRowsAtCompileTime = MatrixType::MaxSizeAtCompileTime == Dynamic ? Dynamic
|
|
|
|
|
: EIGEN_ENUM_MIN(MatrixType::MaxRowsAtCompileTime,
|
|
|
|
|
MatrixType::MaxColsAtCompileTime),
|
|
|
|
|
MaxColsAtCompileTime = 1
|
|
|
|
|
};
|
|
|
|
|
};
|
2008-03-10 17:23:11 +00:00
|
|
|
|
2007-12-15 18:16:30 +00:00
|
|
|
template<typename MatrixType> class DiagonalCoeffs
|
2008-03-10 17:23:11 +00:00
|
|
|
: public MatrixBase<DiagonalCoeffs<MatrixType> >
|
2007-10-14 14:45:31 +00:00
|
|
|
{
|
|
|
|
|
public:
|
2008-03-12 17:17:36 +00:00
|
|
|
|
2008-03-13 09:33:26 +00:00
|
|
|
EIGEN_GENERIC_PUBLIC_INTERFACE(DiagonalCoeffs)
|
2008-03-12 17:17:36 +00:00
|
|
|
|
2008-03-13 20:36:01 +00:00
|
|
|
DiagonalCoeffs(const MatrixType& matrix) : m_matrix(matrix) {}
|
2008-03-04 12:34:58 +00:00
|
|
|
|
2007-12-15 18:16:30 +00:00
|
|
|
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(DiagonalCoeffs)
|
2008-03-04 12:34:58 +00:00
|
|
|
|
2008-01-06 16:35:21 +00:00
|
|
|
private:
|
2008-01-06 13:17:07 +00:00
|
|
|
|
2007-12-15 18:16:30 +00:00
|
|
|
int _rows() const { return std::min(m_matrix.rows(), m_matrix.cols()); }
|
|
|
|
|
int _cols() const { return 1; }
|
2008-03-04 12:34:58 +00:00
|
|
|
|
2007-12-17 07:25:11 +00:00
|
|
|
Scalar& _coeffRef(int row, int)
|
2007-10-14 14:45:31 +00:00
|
|
|
{
|
2008-03-13 20:36:01 +00:00
|
|
|
return m_matrix.const_cast_derived().coeffRef(row, row);
|
2007-10-14 14:45:31 +00:00
|
|
|
}
|
2008-03-04 12:34:58 +00:00
|
|
|
|
2007-12-17 07:25:11 +00:00
|
|
|
Scalar _coeff(int row, int) const
|
2007-10-14 18:02:16 +00:00
|
|
|
{
|
2007-12-17 07:25:11 +00:00
|
|
|
return m_matrix.coeff(row, row);
|
2007-10-14 18:02:16 +00:00
|
|
|
}
|
2008-03-04 12:34:58 +00:00
|
|
|
|
2007-10-14 14:45:31 +00:00
|
|
|
protected:
|
2008-03-13 20:36:01 +00:00
|
|
|
|
|
|
|
|
const typename MatrixType::XprCopy m_matrix;
|
2007-10-14 14:45:31 +00:00
|
|
|
};
|
|
|
|
|
|
2008-03-15 11:05:38 +00:00
|
|
|
/** \returns an expression of the main diagonal of the matrix \c *this
|
|
|
|
|
*
|
|
|
|
|
* \c *this is not required to be square.
|
2007-12-27 21:43:10 +00:00
|
|
|
*
|
|
|
|
|
* Example: \include MatrixBase_diagonal.cpp
|
|
|
|
|
* Output: \verbinclude MatrixBase_diagonal.out
|
|
|
|
|
*
|
|
|
|
|
* \sa class DiagonalCoeffs */
|
2008-03-10 17:23:11 +00:00
|
|
|
template<typename Derived>
|
2007-12-15 18:16:30 +00:00
|
|
|
DiagonalCoeffs<Derived>
|
2008-03-10 17:23:11 +00:00
|
|
|
MatrixBase<Derived>::diagonal()
|
2007-12-25 17:20:58 +00:00
|
|
|
{
|
2008-03-13 20:36:01 +00:00
|
|
|
return DiagonalCoeffs<Derived>(derived());
|
2007-12-25 17:20:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** This is the const version of diagonal(). */
|
2008-03-10 17:23:11 +00:00
|
|
|
template<typename Derived>
|
2007-12-25 17:20:58 +00:00
|
|
|
const DiagonalCoeffs<Derived>
|
2008-03-10 17:23:11 +00:00
|
|
|
MatrixBase<Derived>::diagonal() const
|
2007-10-14 14:45:31 +00:00
|
|
|
{
|
2008-03-13 20:36:01 +00:00
|
|
|
return DiagonalCoeffs<Derived>(derived());
|
2007-10-14 14:45:31 +00:00
|
|
|
}
|
|
|
|
|
|
2007-12-15 18:16:30 +00:00
|
|
|
#endif // EIGEN_DIAGONALCOEFFS_H
|