mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-06-04 18:54:00 +08:00
change the implementation of BandMatrix to follow the BLAS/LAPACK storage scheme
This commit is contained in:
parent
587029a612
commit
df6561a73f
@ -28,28 +28,28 @@
|
|||||||
/** \nonstableyet
|
/** \nonstableyet
|
||||||
* \class BandMatrix
|
* \class BandMatrix
|
||||||
*
|
*
|
||||||
* \brief
|
* \brief
|
||||||
*
|
*
|
||||||
* \param
|
* \param
|
||||||
*
|
*
|
||||||
* \sa
|
* \sa
|
||||||
*/
|
*/
|
||||||
template<typename _Scalar, int Size, int Supers, int Subs, int Options>
|
template<typename _Scalar, int Rows, int Cols, int Supers, int Subs, int Options>
|
||||||
struct ei_traits<BandMatrix<_Scalar,Size,Supers,Subs,Options> >
|
struct ei_traits<BandMatrix<_Scalar,Rows,Cols,Supers,Subs,Options> >
|
||||||
{
|
{
|
||||||
typedef _Scalar Scalar;
|
typedef _Scalar Scalar;
|
||||||
enum {
|
enum {
|
||||||
CoeffReadCost = NumTraits<Scalar>::ReadCost,
|
CoeffReadCost = NumTraits<Scalar>::ReadCost,
|
||||||
RowsAtCompileTime = Size,
|
RowsAtCompileTime = Rows,
|
||||||
ColsAtCompileTime = Size,
|
ColsAtCompileTime = Cols,
|
||||||
MaxRowsAtCompileTime = Size,
|
MaxRowsAtCompileTime = Rows,
|
||||||
MaxColsAtCompileTime = Size,
|
MaxColsAtCompileTime = Cols,
|
||||||
Flags = 0
|
Flags = 0
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename _Scalar, int Size, int Supers, int Subs, int Options>
|
template<typename _Scalar, int Rows, int Cols, int Supers, int Subs, int Options>
|
||||||
class BandMatrix : public MultiplierBase<BandMatrix<_Scalar,Supers,Subs,Options> >
|
class BandMatrix : public MultiplierBase<BandMatrix<_Scalar,Rows,Cols,Supers,Subs,Options> >
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -63,67 +63,79 @@ class BandMatrix : public MultiplierBase<BandMatrix<_Scalar,Supers,Subs,Options>
|
|||||||
};
|
};
|
||||||
typedef typename ei_traits<BandMatrix>::Scalar Scalar;
|
typedef typename ei_traits<BandMatrix>::Scalar Scalar;
|
||||||
typedef Matrix<Scalar,RowsAtCompileTime,ColsAtCompileTime> PlainMatrixType;
|
typedef Matrix<Scalar,RowsAtCompileTime,ColsAtCompileTime> PlainMatrixType;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
enum {
|
enum {
|
||||||
DataSizeAtCompileTime = ((Size!=Dynamic) && (Supers!=Dynamic) && (Subs!=Dynamic))
|
DataRowsAtCompileTime = ((Supers!=Dynamic) && (Subs!=Dynamic))
|
||||||
? Size*(Supers+Subs+1) - (Supers*Supers+Subs*Subs)/2
|
? 1 + Supers + Subs
|
||||||
: Dynamic
|
: Dynamic,
|
||||||
|
SizeAtCompileTime = EIGEN_ENUM_MIN(Rows,Cols)
|
||||||
};
|
};
|
||||||
typedef Matrix<Scalar,DataSizeAtCompileTime,1> DataType;
|
typedef Matrix<Scalar,DataRowsAtCompileTime,ColsAtCompileTime,Options&RowMajor?RowMajor:ColMajor> DataType;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// inline BandMatrix() { }
|
inline BandMatrix(int rows=Rows, int cols=Cols, int supers=Supers, int subs=Subs)
|
||||||
|
: m_data(1+supers+subs,cols),
|
||||||
inline BandMatrix(int size=Size, int supers=Supers, int subs=Subs)
|
m_rows(rows), m_supers(supers), m_subs(subs)
|
||||||
: m_data(size*(supers+subs+1) - (supers*supers+subs*subs)/2),
|
|
||||||
m_size(size), m_supers(supers), m_subs(subs)
|
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
inline int rows() const { return m_size.value(); }
|
/** \returns the number of columns */
|
||||||
inline int cols() const { return m_size.value(); }
|
inline int rows() const { return m_rows.value(); }
|
||||||
|
|
||||||
|
/** \returns the number of rows */
|
||||||
|
inline int cols() const { return m_data.cols(); }
|
||||||
|
|
||||||
|
/** \returns the number of super diagonals */
|
||||||
inline int supers() const { return m_supers.value(); }
|
inline int supers() const { return m_supers.value(); }
|
||||||
|
|
||||||
|
/** \returns the number of sub diagonals */
|
||||||
inline int subs() const { return m_subs.value(); }
|
inline int subs() const { return m_subs.value(); }
|
||||||
|
|
||||||
inline VectorBlock<DataType,Size> diagonal()
|
/** \returns a vector expression of the main diagonal */
|
||||||
{ return VectorBlock<DataType,Size>(m_data,0,m_size.value()); }
|
inline Block<DataType,1,SizeAtCompileTime> diagonal()
|
||||||
|
{ return Block<DataType,1,SizeAtCompileTime>(m_data,supers(),0,1,std::min(rows(),cols())); }
|
||||||
|
|
||||||
inline const VectorBlock<DataType,Size> diagonal() const
|
/** \returns a vector expression of the main diagonal (const version) */
|
||||||
{ return VectorBlock<DataType,Size>(m_data,0,m_size.value()); }
|
inline const Block<DataType,1,SizeAtCompileTime> diagonal() const
|
||||||
|
{ return Block<DataType,1,SizeAtCompileTime>(m_data,supers(),0,1,std::min(rows(),cols())); }
|
||||||
|
|
||||||
template<int Index>
|
template<int Index> struct DiagonalIntReturnType {
|
||||||
VectorBlock<DataType,Size==Dynamic?Dynamic:Size-(Index<0?-Index:Index)>
|
enum {
|
||||||
diagonal()
|
DiagonalSize = RowsAtCompileTime==Dynamic || ColsAtCompileTime==Dynamic
|
||||||
|
? Dynamic
|
||||||
|
: Index<0
|
||||||
|
? EIGEN_ENUM_MIN(ColsAtCompileTime, RowsAtCompileTime + Index)
|
||||||
|
: EIGEN_ENUM_MIN(RowsAtCompileTime, ColsAtCompileTime - Index)
|
||||||
|
};
|
||||||
|
typedef Block<DataType,1, DiagonalSize> Type;
|
||||||
|
};
|
||||||
|
|
||||||
|
/** \returns a vector expression of the \a Index -th sub or super diagonal */
|
||||||
|
template<int Index> inline typename DiagonalIntReturnType<Index>::Type diagonal()
|
||||||
{
|
{
|
||||||
return VectorBlock<DataType,Size==Dynamic?Dynamic:Size-(Index<0?-Index:Index)>
|
return typename DiagonalIntReturnType<Index>::Type(m_data, supers()-Index, ei_abs(Index), 1, diagonalLength(Index));
|
||||||
(m_data,Index<0 ? subDiagIndex(-Index) : superDiagIndex(Index), m_size.value()-ei_abs(Index));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<int Index>
|
/** \returns a vector expression of the \a Index -th sub or super diagonal */
|
||||||
const VectorBlock<DataType,Size==Dynamic?Dynamic:Size-(Index<0?-Index:Index)>
|
template<int Index> inline const typename DiagonalIntReturnType<Index>::Type diagonal() const
|
||||||
diagonal() const
|
|
||||||
{
|
{
|
||||||
return VectorBlock<DataType,Size==Dynamic?Dynamic:Size-(Index<0?-Index:Index)>
|
return typename DiagonalIntReturnType<Index>::Type(m_data, supers()-Index, ei_abs(Index), 1, diagonalLength(Index));
|
||||||
(m_data,Index<0 ? subDiagIndex(-Index) : superDiagIndex(Index), m_size.value()-ei_abs(Index));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline VectorBlock<DataType,Dynamic> diagonal(int index)
|
/** \returns a vector expression of the \a i -th sub or super diagonal */
|
||||||
|
inline Block<DataType,1,Dynamic> diagonal(int i)
|
||||||
{
|
{
|
||||||
ei_assert((index<0 && -index<=subs()) || (index>=0 && index<=supers()));
|
ei_assert((i<0 && -i<=subs()) || (i>=0 && i<=supers()));
|
||||||
return VectorBlock<DataType,Dynamic>(m_data,
|
return Block<DataType,1,Dynamic>(m_data, supers()-i, ei_abs(i), 1, diagonalLength(i));
|
||||||
index<0 ? subDiagIndex(-index) : superDiagIndex(index), m_size.value()-ei_abs(index));
|
|
||||||
}
|
|
||||||
const VectorBlock<DataType,Dynamic> diagonal(int index) const
|
|
||||||
{
|
|
||||||
ei_assert((index<0 && -index<=subs()) || (index>=0 && index<=supers()));
|
|
||||||
return VectorBlock<DataType,Dynamic>(m_data,
|
|
||||||
index<0 ? subDiagIndex(-index) : superDiagIndex(index), m_size.value()-ei_abs(index));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// inline VectorBlock<DataType,Size> subDiagonal()
|
/** \returns a vector expression of the \a i -th sub or super diagonal */
|
||||||
// { return VectorBlock<DataType,Size>(m_data,0,m_size.value()); }
|
inline const Block<DataType,1,Dynamic> diagonal(int i) const
|
||||||
|
{
|
||||||
|
ei_assert((i<0 && -i<=subs()) || (i>=0 && i<=supers()));
|
||||||
|
return Block<DataType,1,Dynamic>(m_data, supers()-i, ei_abs(i), 1, diagonalLength(i));
|
||||||
|
}
|
||||||
|
|
||||||
PlainMatrixType toDense() const
|
PlainMatrixType toDense() const
|
||||||
{
|
{
|
||||||
@ -139,14 +151,11 @@ class BandMatrix : public MultiplierBase<BandMatrix<_Scalar,Supers,Subs,Options>
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
inline int subDiagIndex(int i) const
|
inline int diagonalLength(int i) const
|
||||||
{ return m_size.value()*(m_supers.value()+i)-(ei_abs2(i-1) + ei_abs2(m_supers.value()))/2; }
|
{ return i<0 ? std::min(cols(),rows()+i) : std::min(rows(),cols()-i); }
|
||||||
|
|
||||||
inline int superDiagIndex(int i) const
|
|
||||||
{ return m_size.value()*i-ei_abs2(i-1)/2; }
|
|
||||||
|
|
||||||
DataType m_data;
|
DataType m_data;
|
||||||
ei_int_if_dynamic<Size> m_size;
|
ei_int_if_dynamic<Rows> m_rows;
|
||||||
ei_int_if_dynamic<Supers> m_supers;
|
ei_int_if_dynamic<Supers> m_supers;
|
||||||
ei_int_if_dynamic<Subs> m_subs;
|
ei_int_if_dynamic<Subs> m_subs;
|
||||||
};
|
};
|
||||||
|
@ -66,7 +66,7 @@ template<typename ExpressionType> class WithFormat;
|
|||||||
template<typename MatrixType> struct CommaInitializer;
|
template<typename MatrixType> struct CommaInitializer;
|
||||||
template<typename Functor, typename EvalType> class ReturnByValue;
|
template<typename Functor, typename EvalType> class ReturnByValue;
|
||||||
|
|
||||||
template<typename _Scalar, int Size=Dynamic, int Supers=Dynamic, int Subs=Dynamic, int Options=0> class BandMatrix;
|
template<typename _Scalar, int Rows=Dynamic, int Cols=Dynamic, int Supers=Dynamic, int Subs=Dynamic, int Options=0> class BandMatrix;
|
||||||
|
|
||||||
|
|
||||||
template<typename Lhs, typename Rhs> struct ei_product_mode;
|
template<typename Lhs, typename Rhs> struct ei_product_mode;
|
||||||
|
154
disabled/SkylineMatrix.h
Normal file
154
disabled/SkylineMatrix.h
Normal file
@ -0,0 +1,154 @@
|
|||||||
|
// This file is part of Eigen, a lightweight C++ template library
|
||||||
|
// for linear algebra.
|
||||||
|
//
|
||||||
|
// Copyright (C) 2009 Gael Guennebaud <g.gael@free.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_BANDMATRIX_H
|
||||||
|
#define EIGEN_BANDMATRIX_H
|
||||||
|
|
||||||
|
/** \nonstableyet
|
||||||
|
* \class BandMatrix
|
||||||
|
*
|
||||||
|
* \brief
|
||||||
|
*
|
||||||
|
* \param
|
||||||
|
*
|
||||||
|
* \sa
|
||||||
|
*/
|
||||||
|
template<typename _Scalar, int Size, int Supers, int Subs, int Options>
|
||||||
|
struct ei_traits<BandMatrix<_Scalar,Size,Supers,Subs,Options> >
|
||||||
|
{
|
||||||
|
typedef _Scalar Scalar;
|
||||||
|
enum {
|
||||||
|
CoeffReadCost = NumTraits<Scalar>::ReadCost,
|
||||||
|
RowsAtCompileTime = Size,
|
||||||
|
ColsAtCompileTime = Size,
|
||||||
|
MaxRowsAtCompileTime = Size,
|
||||||
|
MaxColsAtCompileTime = Size,
|
||||||
|
Flags = 0
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename _Scalar, int Size, int Supers, int Subs, int Options>
|
||||||
|
class BandMatrix : public MultiplierBase<BandMatrix<_Scalar,Supers,Subs,Options> >
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
enum {
|
||||||
|
Flags = ei_traits<BandMatrix>::Flags,
|
||||||
|
CoeffReadCost = ei_traits<BandMatrix>::CoeffReadCost,
|
||||||
|
RowsAtCompileTime = ei_traits<BandMatrix>::RowsAtCompileTime,
|
||||||
|
ColsAtCompileTime = ei_traits<BandMatrix>::ColsAtCompileTime,
|
||||||
|
MaxRowsAtCompileTime = ei_traits<BandMatrix>::MaxRowsAtCompileTime,
|
||||||
|
MaxColsAtCompileTime = ei_traits<BandMatrix>::MaxColsAtCompileTime
|
||||||
|
};
|
||||||
|
typedef typename ei_traits<BandMatrix>::Scalar Scalar;
|
||||||
|
typedef Matrix<Scalar,RowsAtCompileTime,ColsAtCompileTime> PlainMatrixType;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
enum {
|
||||||
|
DataSizeAtCompileTime = ((Size!=Dynamic) && (Supers!=Dynamic) && (Subs!=Dynamic))
|
||||||
|
? Size*(Supers+Subs+1) - (Supers*Supers+Subs*Subs)/2
|
||||||
|
: Dynamic
|
||||||
|
};
|
||||||
|
typedef Matrix<Scalar,DataSizeAtCompileTime,1> DataType;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
// inline BandMatrix() { }
|
||||||
|
|
||||||
|
inline BandMatrix(int size=Size, int supers=Supers, int subs=Subs)
|
||||||
|
: m_data(size*(supers+subs+1) - (supers*supers+subs*subs)/2),
|
||||||
|
m_size(size), m_supers(supers), m_subs(subs)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
inline int rows() const { return m_size.value(); }
|
||||||
|
inline int cols() const { return m_size.value(); }
|
||||||
|
|
||||||
|
inline int supers() const { return m_supers.value(); }
|
||||||
|
inline int subs() const { return m_subs.value(); }
|
||||||
|
|
||||||
|
inline VectorBlock<DataType,Size> diagonal()
|
||||||
|
{ return VectorBlock<DataType,Size>(m_data,0,m_size.value()); }
|
||||||
|
|
||||||
|
inline const VectorBlock<DataType,Size> diagonal() const
|
||||||
|
{ return VectorBlock<DataType,Size>(m_data,0,m_size.value()); }
|
||||||
|
|
||||||
|
template<int Index>
|
||||||
|
VectorBlock<DataType,Size==Dynamic?Dynamic:Size-(Index<0?-Index:Index)>
|
||||||
|
diagonal()
|
||||||
|
{
|
||||||
|
return VectorBlock<DataType,Size==Dynamic?Dynamic:Size-(Index<0?-Index:Index)>
|
||||||
|
(m_data,Index<0 ? subDiagIndex(-Index) : superDiagIndex(Index), m_size.value()-ei_abs(Index));
|
||||||
|
}
|
||||||
|
|
||||||
|
template<int Index>
|
||||||
|
const VectorBlock<DataType,Size==Dynamic?Dynamic:Size-(Index<0?-Index:Index)>
|
||||||
|
diagonal() const
|
||||||
|
{
|
||||||
|
return VectorBlock<DataType,Size==Dynamic?Dynamic:Size-(Index<0?-Index:Index)>
|
||||||
|
(m_data,Index<0 ? subDiagIndex(-Index) : superDiagIndex(Index), m_size.value()-ei_abs(Index));
|
||||||
|
}
|
||||||
|
|
||||||
|
inline VectorBlock<DataType,Dynamic> diagonal(int index)
|
||||||
|
{
|
||||||
|
ei_assert((index<0 && -index<=subs()) || (index>=0 && index<=supers()));
|
||||||
|
return VectorBlock<DataType,Dynamic>(m_data,
|
||||||
|
index<0 ? subDiagIndex(-index) : superDiagIndex(index), m_size.value()-ei_abs(index));
|
||||||
|
}
|
||||||
|
const VectorBlock<DataType,Dynamic> diagonal(int index) const
|
||||||
|
{
|
||||||
|
ei_assert((index<0 && -index<=subs()) || (index>=0 && index<=supers()));
|
||||||
|
return VectorBlock<DataType,Dynamic>(m_data,
|
||||||
|
index<0 ? subDiagIndex(-index) : superDiagIndex(index), m_size.value()-ei_abs(index));
|
||||||
|
}
|
||||||
|
|
||||||
|
// inline VectorBlock<DataType,Size> subDiagonal()
|
||||||
|
// { return VectorBlock<DataType,Size>(m_data,0,m_size.value()); }
|
||||||
|
|
||||||
|
PlainMatrixType toDense() const
|
||||||
|
{
|
||||||
|
PlainMatrixType res(rows(),cols());
|
||||||
|
res.setZero();
|
||||||
|
res.diagonal() = diagonal();
|
||||||
|
for (int i=1; i<=supers();++i)
|
||||||
|
res.diagonal(i) = diagonal(i);
|
||||||
|
for (int i=1; i<=subs();++i)
|
||||||
|
res.diagonal(-i) = diagonal(-i);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
inline int subDiagIndex(int i) const
|
||||||
|
{ return m_size.value()*(m_supers.value()+i)-(ei_abs2(i-1) + ei_abs2(m_supers.value()))/2; }
|
||||||
|
|
||||||
|
inline int superDiagIndex(int i) const
|
||||||
|
{ return m_size.value()*i-ei_abs2(i-1)/2; }
|
||||||
|
|
||||||
|
DataType m_data;
|
||||||
|
ei_int_if_dynamic<Size> m_size;
|
||||||
|
ei_int_if_dynamic<Supers> m_supers;
|
||||||
|
ei_int_if_dynamic<Subs> m_subs;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // EIGEN_BANDMATRIX_H
|
@ -55,7 +55,7 @@ template<typename MatrixType> void bandmatrix(MatrixType& m)
|
|||||||
void test_bandmatrix()
|
void test_bandmatrix()
|
||||||
{
|
{
|
||||||
for(int i = 0; i < g_repeat ; i++) {
|
for(int i = 0; i < g_repeat ; i++) {
|
||||||
BandMatrix<float,Dynamic,Dynamic,Dynamic> m(6,3,2);
|
BandMatrix<float,Dynamic,Dynamic,Dynamic> m(6,6,3,2);
|
||||||
CALL_SUBTEST( bandmatrix(m) );
|
CALL_SUBTEST( bandmatrix(m) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user