10#ifndef EIGEN_BANDMATRIX_H
11#define EIGEN_BANDMATRIX_H
14#include "./InternalHeaderCheck.h"
20template <
typename Derived>
21class BandMatrixBase :
public EigenBase<Derived> {
24 Flags = internal::traits<Derived>::Flags,
25 CoeffReadCost = internal::traits<Derived>::CoeffReadCost,
26 RowsAtCompileTime = internal::traits<Derived>::RowsAtCompileTime,
27 ColsAtCompileTime = internal::traits<Derived>::ColsAtCompileTime,
28 MaxRowsAtCompileTime = internal::traits<Derived>::MaxRowsAtCompileTime,
29 MaxColsAtCompileTime = internal::traits<Derived>::MaxColsAtCompileTime,
30 Supers = internal::traits<Derived>::Supers,
31 Subs = internal::traits<Derived>::Subs,
32 Options = internal::traits<Derived>::Options
34 typedef typename internal::traits<Derived>::Scalar Scalar;
35 typedef Matrix<Scalar, RowsAtCompileTime, ColsAtCompileTime> DenseMatrixType;
36 typedef typename DenseMatrixType::StorageIndex StorageIndex;
37 typedef typename internal::traits<Derived>::CoefficientsType CoefficientsType;
38 typedef EigenBase<Derived> Base;
43 SizeAtCompileTime = min_size_prefer_dynamic(RowsAtCompileTime, ColsAtCompileTime)
52 inline Index supers()
const {
return derived().supers(); }
55 inline Index subs()
const {
return derived().subs(); }
58 inline const CoefficientsType& coeffs()
const {
return derived().coeffs(); }
61 inline CoefficientsType& coeffs() {
return derived().coeffs(); }
66 inline Block<CoefficientsType, Dynamic, 1> col(
Index i) {
67 EIGEN_STATIC_ASSERT((
int(Options) &
int(
RowMajor)) == 0, THIS_METHOD_IS_ONLY_FOR_COLUMN_MAJOR_MATRICES);
69 Index len = coeffs().rows();
72 len = (std::min)(rows(), std::max<Index>(0, coeffs().rows() - (supers() - i)));
73 }
else if (i >= rows() - subs())
74 len = std::max<Index>(0, coeffs().rows() - (i + 1 - rows() + subs()));
75 return Block<CoefficientsType, Dynamic, 1>(coeffs(), start, i, len, 1);
79 inline Block<CoefficientsType, 1, SizeAtCompileTime> diagonal() {
80 return Block<CoefficientsType, 1, SizeAtCompileTime>(coeffs(), supers(), 0, 1, (std::min)(rows(), cols()));
84 inline const Block<const CoefficientsType, 1, SizeAtCompileTime> diagonal()
const {
85 return Block<const CoefficientsType, 1, SizeAtCompileTime>(coeffs(), supers(), 0, 1, (std::min)(rows(), cols()));
89 struct DiagonalIntReturnType {
93 Conjugate = ReturnOpposite && NumTraits<Scalar>::IsComplex,
98 : (ActualIndex < 0 ? min_size_prefer_dynamic(ColsAtCompileTime, RowsAtCompileTime + ActualIndex)
99 : min_size_prefer_dynamic(RowsAtCompileTime, ColsAtCompileTime - ActualIndex))
101 typedef Block<CoefficientsType, 1, DiagonalSize> BuildType;
102 typedef std::conditional_t<Conjugate, CwiseUnaryOp<internal::scalar_conjugate_op<Scalar>, BuildType>, BuildType>
108 inline typename DiagonalIntReturnType<N>::Type diagonal() {
109 return typename DiagonalIntReturnType<N>::BuildType(coeffs(), supers() - N, (std::max)(0, N), 1, diagonalLength(N));
114 inline const typename DiagonalIntReturnType<N>::Type diagonal()
const {
115 return typename DiagonalIntReturnType<N>::BuildType(coeffs(), supers() - N, (std::max)(0, N), 1, diagonalLength(N));
119 inline Block<CoefficientsType, 1, Dynamic> diagonal(
Index i) {
120 eigen_assert((i < 0 && -i <= subs()) || (i >= 0 && i <= supers()));
121 return Block<CoefficientsType, 1, Dynamic>(coeffs(), supers() - i, std::max<Index>(0, i), 1, diagonalLength(i));
125 inline const Block<const CoefficientsType, 1, Dynamic> diagonal(
Index i)
const {
126 eigen_assert((i < 0 && -i <= subs()) || (i >= 0 && i <= supers()));
127 return Block<const CoefficientsType, 1, Dynamic>(coeffs(), supers() - i, std::max<Index>(0, i), 1,
131 template <
typename Dest>
132 inline void evalTo(Dest& dst)
const {
133 dst.resize(rows(), cols());
135 dst.diagonal() = diagonal();
136 for (
Index i = 1; i <= supers(); ++i) dst.diagonal(i) = diagonal(i);
137 for (
Index i = 1; i <= subs(); ++i) dst.diagonal(-i) = diagonal(-i);
140 DenseMatrixType toDenseMatrix()
const {
141 DenseMatrixType res(rows(), cols());
148 return i < 0 ? (std::min)(cols(), rows() + i) : (std::min)(rows(), cols() - i);
171template <
typename Scalar_,
int Rows_,
int Cols_,
int Supers_,
int Subs_,
int Options_>
172struct traits<BandMatrix<Scalar_, Rows_, Cols_, Supers_, Subs_, Options_> > {
173 typedef Scalar_ Scalar;
174 typedef Dense StorageKind;
177 CoeffReadCost = NumTraits<Scalar>::ReadCost,
178 RowsAtCompileTime = Rows_,
179 ColsAtCompileTime = Cols_,
180 MaxRowsAtCompileTime = Rows_,
181 MaxColsAtCompileTime = Cols_,
188 typedef Matrix<Scalar, DataRowsAtCompileTime, ColsAtCompileTime, int(Options) & int(RowMajor) ?
RowMajor :
ColMajor>
192template <
typename Scalar_,
int Rows,
int Cols,
int Supers,
int Subs,
int Options>
193class BandMatrix :
public BandMatrixBase<BandMatrix<Scalar_, Rows, Cols, Supers, Subs, Options> > {
195 typedef typename internal::traits<BandMatrix>::Scalar Scalar;
196 typedef typename internal::traits<BandMatrix>::StorageIndex StorageIndex;
197 typedef typename internal::traits<BandMatrix>::CoefficientsType CoefficientsType;
199 explicit inline BandMatrix(Index rows = Rows, Index cols = Cols, Index supers = Supers, Index subs = Subs)
200 : m_coeffs(1 + supers + subs, cols), m_rows(rows), m_supers(supers), m_subs(subs) {}
203 inline EIGEN_CONSTEXPR
Index rows()
const {
return m_rows.value(); }
206 inline EIGEN_CONSTEXPR
Index cols()
const {
return m_coeffs.cols(); }
209 inline EIGEN_CONSTEXPR
Index supers()
const {
return m_supers.value(); }
212 inline EIGEN_CONSTEXPR
Index subs()
const {
return m_subs.value(); }
214 inline const CoefficientsType& coeffs()
const {
return m_coeffs; }
215 inline CoefficientsType& coeffs() {
return m_coeffs; }
218 CoefficientsType m_coeffs;
219 internal::variable_if_dynamic<Index, Rows> m_rows;
220 internal::variable_if_dynamic<Index, Supers> m_supers;
221 internal::variable_if_dynamic<Index, Subs> m_subs;
224template <
typename CoefficientsType_,
int Rows_,
int Cols_,
int Supers_,
int Subs_,
int Options_>
225class BandMatrixWrapper;
227template <
typename CoefficientsType_,
int Rows_,
int Cols_,
int Supers_,
int Subs_,
int Options_>
228struct traits<BandMatrixWrapper<CoefficientsType_, Rows_, Cols_, Supers_, Subs_, Options_> > {
229 typedef typename CoefficientsType_::Scalar Scalar;
230 typedef typename CoefficientsType_::StorageKind StorageKind;
231 typedef typename CoefficientsType_::StorageIndex StorageIndex;
233 CoeffReadCost = internal::traits<CoefficientsType_>::CoeffReadCost,
234 RowsAtCompileTime = Rows_,
235 ColsAtCompileTime = Cols_,
236 MaxRowsAtCompileTime = Rows_,
237 MaxColsAtCompileTime = Cols_,
244 typedef CoefficientsType_ CoefficientsType;
247template <
typename CoefficientsType_,
int Rows_,
int Cols_,
int Supers_,
int Subs_,
int Options_>
248class BandMatrixWrapper
249 :
public BandMatrixBase<BandMatrixWrapper<CoefficientsType_, Rows_, Cols_, Supers_, Subs_, Options_> > {
251 typedef typename internal::traits<BandMatrixWrapper>::Scalar Scalar;
252 typedef typename internal::traits<BandMatrixWrapper>::CoefficientsType CoefficientsType;
253 typedef typename internal::traits<BandMatrixWrapper>::StorageIndex StorageIndex;
255 explicit inline BandMatrixWrapper(
const CoefficientsType& coeffs, Index rows = Rows_, Index cols = Cols_,
256 Index supers = Supers_, Index subs = Subs_)
257 : m_coeffs(coeffs), m_rows(rows), m_supers(supers), m_subs(subs) {
258 EIGEN_UNUSED_VARIABLE(cols);
263 inline EIGEN_CONSTEXPR
Index rows()
const {
return m_rows.value(); }
266 inline EIGEN_CONSTEXPR
Index cols()
const {
return m_coeffs.cols(); }
269 inline EIGEN_CONSTEXPR
Index supers()
const {
return m_supers.value(); }
272 inline EIGEN_CONSTEXPR
Index subs()
const {
return m_subs.value(); }
274 inline const CoefficientsType& coeffs()
const {
return m_coeffs; }
277 const CoefficientsType& m_coeffs;
278 internal::variable_if_dynamic<Index, Rows_> m_rows;
279 internal::variable_if_dynamic<Index, Supers_> m_supers;
280 internal::variable_if_dynamic<Index, Subs_> m_subs;
295template <
typename Scalar,
int Size,
int Options>
296class TridiagonalMatrix :
public BandMatrix<Scalar, Size, Size, Options & SelfAdjoint ? 0 : 1, 1, Options | RowMajor> {
297 typedef BandMatrix<Scalar, Size, Size, Options & SelfAdjoint ? 0 : 1, 1, Options | RowMajor> Base;
298 typedef typename Base::StorageIndex StorageIndex;
303 inline typename Base::template DiagonalIntReturnType<1>::Type super() {
return Base::template diagonal<1>(); }
304 inline const typename Base::template DiagonalIntReturnType<1>::Type super()
const {
305 return Base::template diagonal<1>();
307 inline typename Base::template DiagonalIntReturnType<-1>::Type sub() {
return Base::template diagonal<-1>(); }
308 inline const typename Base::template DiagonalIntReturnType<-1>::Type sub()
const {
309 return Base::template diagonal<-1>();
296class TridiagonalMatrix :
public BandMatrix<Scalar, Size, Size, Options & SelfAdjoint ? 0 : 1, 1, Options | RowMajor> {
…};
317template <
typename Scalar_,
int Rows_,
int Cols_,
int Supers_,
int Subs_,
int Options_>
318struct evaluator_traits<BandMatrix<Scalar_, Rows_, Cols_, Supers_, Subs_, Options_> >
319 :
public evaluator_traits_base<BandMatrix<Scalar_, Rows_, Cols_, Supers_, Subs_, Options_> > {
320 typedef BandShape Shape;
323template <
typename CoefficientsType_,
int Rows_,
int Cols_,
int Supers_,
int Subs_,
int Options_>
324struct evaluator_traits<BandMatrixWrapper<CoefficientsType_, Rows_, Cols_, Supers_, Subs_, Options_> >
325 :
public evaluator_traits_base<BandMatrixWrapper<CoefficientsType_, Rows_, Cols_, Supers_, Subs_, Options_> > {
326 typedef BandShape Shape;
330struct AssignmentKind<DenseShape, BandShape> {
331 typedef EigenBase2EigenBase Kind;
EIGEN_CONSTEXPR Index subs() const
Definition BandMatrix.h:212
EIGEN_CONSTEXPR Index supers() const
Definition BandMatrix.h:209
EIGEN_CONSTEXPR Index cols() const
Definition BandMatrix.h:206
EIGEN_CONSTEXPR Index rows() const
Definition BandMatrix.h:203
@ SelfAdjoint
Definition Constants.h:227
@ ColMajor
Definition Constants.h:318
@ RowMajor
Definition Constants.h:320
const unsigned int LvalueBit
Definition Constants.h:148
Namespace containing all symbols from the Eigen library.
Definition B01_Experimental.dox:1
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition Meta.h:82
const int Dynamic
Definition Constants.h:25
EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
Definition EigenBase.h:61
constexpr Derived & derived()
Definition EigenBase.h:49
Eigen::Index Index
The interface type of indices.
Definition EigenBase.h:43
EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
Definition EigenBase.h:59
EIGEN_CONSTEXPR Index size() const EIGEN_NOEXCEPT
Definition EigenBase.h:64