10 #ifndef EIGEN_BANDMATRIX_H
11 #define EIGEN_BANDMATRIX_H
19 template<
typename Derived>
20 class BandMatrixBase :
public EigenBase<Derived>
25 Flags = internal::traits<Derived>::Flags,
26 CoeffReadCost = internal::traits<Derived>::CoeffReadCost,
27 RowsAtCompileTime = internal::traits<Derived>::RowsAtCompileTime,
28 ColsAtCompileTime = internal::traits<Derived>::ColsAtCompileTime,
29 MaxRowsAtCompileTime = internal::traits<Derived>::MaxRowsAtCompileTime,
30 MaxColsAtCompileTime = internal::traits<Derived>::MaxColsAtCompileTime,
31 Supers = internal::traits<Derived>::Supers,
32 Subs = internal::traits<Derived>::Subs,
33 Options = internal::traits<Derived>::Options
35 typedef typename internal::traits<Derived>::Scalar Scalar;
36 typedef Matrix<Scalar,RowsAtCompileTime,ColsAtCompileTime> DenseMatrixType;
38 typedef typename internal::traits<Derived>::CoefficientsType CoefficientsType;
39 typedef EigenBase<Derived> Base;
56 inline Index supers()
const {
return derived().supers(); }
62 inline const CoefficientsType& coeffs()
const {
return derived().coeffs(); }
65 inline CoefficientsType& coeffs() {
return derived().coeffs(); }
70 inline Block<CoefficientsType,Dynamic,1>
col(
Index i)
74 Index len = coeffs().rows();
80 else if (
i>=
rows()-subs())
81 len = std::max<Index>(0,coeffs().rows() - (
i + 1 -
rows() + subs()));
82 return Block<CoefficientsType,Dynamic,1>(coeffs(), start,
i, len, 1);
86 inline Block<CoefficientsType,1,SizeAtCompileTime> diagonal()
87 {
return Block<CoefficientsType,1,SizeAtCompileTime>(coeffs(),supers(),0,1,(
std::min)(
rows(),
cols())); }
90 inline const Block<const CoefficientsType,1,SizeAtCompileTime> diagonal()
const
91 {
return Block<const CoefficientsType,1,SizeAtCompileTime>(coeffs(),supers(),0,1,(
std::min)(
rows(),
cols())); }
93 template<
int Index>
struct DiagonalIntReturnType {
95 ReturnOpposite = (int(Options) & int(
SelfAdjoint)) && (((
Index) > 0 && Supers == 0) || ((
Index) < 0 && Subs == 0)),
98 DiagonalSize = (RowsAtCompileTime==
Dynamic || ColsAtCompileTime==
Dynamic)
104 typedef Block<CoefficientsType,1, DiagonalSize> BuildType;
105 typedef std::conditional_t<Conjugate,
106 CwiseUnaryOp<internal::scalar_conjugate_op<Scalar>,BuildType >,
113 return typename DiagonalIntReturnType<N>::BuildType(coeffs(), supers()-N, (
std::max)(0,N), 1, diagonalLength(N));
119 return typename DiagonalIntReturnType<N>::BuildType(coeffs(), supers()-N, (
std::max)(0,N), 1, diagonalLength(N));
123 inline Block<CoefficientsType,1,Dynamic> diagonal(
Index i)
126 return Block<CoefficientsType,1,Dynamic>(coeffs(), supers()-
i, std::max<Index>(0,
i), 1, diagonalLength(
i));
130 inline const Block<const CoefficientsType,1,Dynamic> diagonal(
Index i)
const
133 return Block<const CoefficientsType,1,Dynamic>(coeffs(), supers()-
i, std::max<Index>(0,
i), 1, diagonalLength(
i));
136 template<
typename Dest>
inline void evalTo(Dest& dst)
const
140 dst.diagonal() = diagonal();
142 dst.diagonal(
i) = diagonal(
i);
144 dst.diagonal(-
i) = diagonal(-
i);
147 DenseMatrixType toDenseMatrix()
const
179 template<
typename Scalar_,
int Rows_,
int Cols_,
int Supers_,
int Subs_,
int Options_>
180 struct traits<BandMatrix<Scalar_,Rows_,Cols_,Supers_,Subs_,Options_> >
182 typedef Scalar_ Scalar;
183 typedef Dense StorageKind;
187 RowsAtCompileTime = Rows_,
188 ColsAtCompileTime = Cols_,
189 MaxRowsAtCompileTime = Rows_,
190 MaxColsAtCompileTime = Cols_,
197 typedef Matrix<Scalar, DataRowsAtCompileTime, ColsAtCompileTime, int(Options) & int(
RowMajor) ?
RowMajor :
ColMajor> CoefficientsType;
200 template<
typename Scalar_,
int Rows,
int Cols,
int Supers,
int Subs,
int Options>
201 class BandMatrix :
public BandMatrixBase<BandMatrix<Scalar_,Rows,Cols,Supers,Subs,Options> >
205 typedef typename internal::traits<BandMatrix>::Scalar Scalar;
206 typedef typename internal::traits<BandMatrix>::StorageIndex StorageIndex;
207 typedef typename internal::traits<BandMatrix>::CoefficientsType CoefficientsType;
210 : m_coeffs(1+supers+subs,
cols),
211 m_rows(
rows), m_supers(supers), m_subs(subs)
227 inline const CoefficientsType& coeffs()
const {
return m_coeffs; }
228 inline CoefficientsType& coeffs() {
return m_coeffs; }
232 CoefficientsType m_coeffs;
233 internal::variable_if_dynamic<Index, Rows> m_rows;
234 internal::variable_if_dynamic<Index, Supers> m_supers;
235 internal::variable_if_dynamic<Index, Subs> m_subs;
238 template<
typename CoefficientsType_,
int Rows_,
int Cols_,
int Supers_,
int Subs_,
int Options_>
239 class BandMatrixWrapper;
241 template<
typename CoefficientsType_,
int Rows_,
int Cols_,
int Supers_,
int Subs_,
int Options_>
242 struct traits<BandMatrixWrapper<CoefficientsType_,Rows_,Cols_,Supers_,Subs_,Options_> >
244 typedef typename CoefficientsType_::Scalar Scalar;
245 typedef typename CoefficientsType_::StorageKind StorageKind;
246 typedef typename CoefficientsType_::StorageIndex StorageIndex;
248 CoeffReadCost = internal::traits<CoefficientsType_>::CoeffReadCost,
249 RowsAtCompileTime = Rows_,
250 ColsAtCompileTime = Cols_,
251 MaxRowsAtCompileTime = Rows_,
252 MaxColsAtCompileTime = Cols_,
259 typedef CoefficientsType_ CoefficientsType;
262 template<
typename CoefficientsType_,
int Rows_,
int Cols_,
int Supers_,
int Subs_,
int Options_>
263 class BandMatrixWrapper :
public BandMatrixBase<BandMatrixWrapper<CoefficientsType_,Rows_,Cols_,Supers_,Subs_,Options_> >
267 typedef typename internal::traits<BandMatrixWrapper>::Scalar Scalar;
268 typedef typename internal::traits<BandMatrixWrapper>::CoefficientsType CoefficientsType;
269 typedef typename internal::traits<BandMatrixWrapper>::StorageIndex StorageIndex;
271 explicit inline BandMatrixWrapper(
const CoefficientsType& coeffs,
Index rows=Rows_,
Index cols=Cols_,
Index supers=Supers_,
Index subs=Subs_)
273 m_rows(
rows), m_supers(supers), m_subs(subs)
291 inline const CoefficientsType& coeffs()
const {
return m_coeffs; }
295 const CoefficientsType& m_coeffs;
296 internal::variable_if_dynamic<Index, Rows_> m_rows;
297 internal::variable_if_dynamic<Index, Supers_> m_supers;
298 internal::variable_if_dynamic<Index, Subs_> m_subs;
313 template<
typename Scalar,
int Size,
int Options>
314 class TridiagonalMatrix :
public BandMatrix<Scalar,Size,Size,Options&SelfAdjoint?0:1,1,Options|RowMajor>
316 typedef BandMatrix<Scalar,Size,Size,Options&SelfAdjoint?0:1,1,Options|RowMajor> Base;
317 typedef typename Base::StorageIndex StorageIndex;
322 {
return Base::template diagonal<1>(); }
324 {
return Base::template diagonal<1>(); }
325 inline typename Base::template DiagonalIntReturnType<-1>
::Type sub()
326 {
return Base::template diagonal<-1>(); }
327 inline const typename Base::template DiagonalIntReturnType<-1>
::Type sub()
const
328 {
return Base::template diagonal<-1>(); }
335 template<
typename Scalar_,
int Rows_,
int Cols_,
int Supers_,
int Subs_,
int Options_>
336 struct evaluator_traits<BandMatrix<Scalar_,Rows_,Cols_,Supers_,Subs_,Options_> >
337 :
public evaluator_traits_base<BandMatrix<Scalar_,Rows_,Cols_,Supers_,Subs_,Options_> >
339 typedef BandShape Shape;
342 template<
typename CoefficientsType_,
int Rows_,
int Cols_,
int Supers_,
int Subs_,
int Options_>
343 struct evaluator_traits<BandMatrixWrapper<CoefficientsType_,Rows_,Cols_,Supers_,Subs_,Options_> >
344 :
public evaluator_traits_base<BandMatrixWrapper<CoefficientsType_,Rows_,Cols_,Supers_,Subs_,Options_> >
346 typedef BandShape Shape;
349 template<>
struct AssignmentKind<DenseShape,BandShape> {
typedef EigenBase2EigenBase Kind; };
ColXpr col(Index i)
This is the const version of col().
#define EIGEN_UNUSED_VARIABLE(var)
cout<< "Here is the matrix m:"<< endl<< m<< endl;Matrix< ptrdiff_t, 3, 1 > res
#define EIGEN_STATIC_ASSERT(X, MSG)
internal::traits< Derived >::StorageIndex StorageIndex
The type used to store indices.
const unsigned int LvalueBit
bfloat16() max(const bfloat16 &a, const bfloat16 &b)
bfloat16() min(const bfloat16 &a, const bfloat16 &b)
constexpr int min_size_prefer_dynamic(A a, B b)
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT