22#ifndef general_band_matrix_h
23#define general_band_matrix_h
57 static constexpr bool isVector {
false};
59 using value_type = AT;
66 explicit Matrix() : memory(), ele(0) {
78 explicit Matrix(
int n_,
int kl_,
int ku_,
Noinit) : memory(n_*(kl_+ku_+1)), ele((AT*)memory.get()), n(n_), kl(kl_), ku(ku_) { }
79 explicit Matrix(
int n_,
int kl_,
int ku_, Init ini=INIT,
const AT &a=AT()) : memory(n_*(kl_+ku_+1)), ele((AT*)memory.get()), n(n_), kl(kl_), ku(ku_) { init(a); }
80 explicit Matrix(
int n_,
int kl_,
int ku_, Eye ini,
const AT &a=1) : memory(n_*(kl_+ku_+1)), ele((AT*)memory.get()), n(n_), kl(kl_), ku(ku_) { init(ini,a); }
81 explicit Matrix(
int m_,
int n_,
int kl_,
int ku_, Noinit) : memory(n_*(kl_+ku_+1)), ele((AT*)memory.get()), n(n_), kl(kl_), ku(ku_) { }
82 explicit Matrix(
int m_,
int n_,
int kl_,
int ku_, Init ini=INIT,
const AT &a=AT()) : memory(n_*(kl_+ku_+1)), ele((AT*)memory.get()), n(n_), kl(kl_), ku(ku_) { init(a); }
83 explicit Matrix(
int m_,
int n_,
int kl_,
int ku_, Eye ini,
const AT &a=1) : memory(n_*(kl_+ku_+1)), ele((AT*)memory.get()), n(n_), kl(kl_), ku(ku_) { init(ini,a); }
99 template<
class Type,
class Row,
class Col>
101 FMATVEC_ASSERT(A.
rows() == A.
cols(), AT);
114 explicit Matrix(
int n_,
int kl_,
int ku_, AT* ele_) : memory(), ele(ele_), n(n_), kl(kl_), ku(ku_) {
122 n = n_; kl = kl_; ku = ku_;
123 memory.resize(n*(kl+ku+1));
124 ele = (AT*)memory.get();
128 Matrix<GeneralBand,Ref,Ref,AT>& resize(
int n,
int kl,
int ku=0,
Init ini=INIT,
const AT &a=AT()) {
return resize(n,kl,ku,
Noinit()).
init(a); }
130 Matrix<GeneralBand,Ref,Ref,AT>& resize(
int n,
int kl,
int ku, Eye ini,
const AT &a=1) {
return resize(n,kl,ku,Noinit()).
init(a); }
139 FMATVEC_ASSERT(n == A.n, AT);
149 template<
class Type,
class Row,
class Col>
151 FMATVEC_ASSERT(n == A.
rows(), AT);
152 FMATVEC_ASSERT(n == A.
cols(), AT);
175 template<
class Type,
class Row,
class Col>
177 if(n!=A.n) resize(A.
rows(),NONINIT);
191 FMATVEC_ASSERT(i>=0, AT);
192 FMATVEC_ASSERT(j>=0, AT);
193 FMATVEC_ASSERT(i<n, AT);
194 FMATVEC_ASSERT(j<n, AT);
199 return ((i-j>kl) || (i-j<-ku)) ? zero : ele[ku+i+j*(kl+ku)];
241 return CblasColMajor;
268 inline Matrix<GeneralBand,Ref,Ref,AT>& init(Eye,
const AT &val=1);
269 inline Matrix<GeneralBand,Ref,Ref,AT>& init(Noinit,
const AT &a=AT()) {
return *
this; }
275 explicit inline operator std::vector<std::vector<AT>>()
const;
280 for(
int i=0; i<kl+ku+1; i++)
281 for(
int j=0; j<n; j++)
282 ele[i+j*(kl+ku+1)] = val;
288 for(
int i=0; i<n; i++)
314 std::vector<std::vector<AT>> ret(rows(),std::vector<AT>(cols()));
315 for(
int r=0; r<rows(); r++) {
316 for(
int c=0; c<cols(); c++)
317 ret[r][c]=
operator()(r,c);
326 for(
int i=0; i<kl+ku+1; i++)
327 for(
int j=0; j<n; j++)
328 ele[i+j*(kl+ku+1)] = A.ele[i+j*(kl+ku+1)];
Shape class for general band matrices.
Definition: types.h:124
This is a matrix class for general band matrices.
Definition: band_matrix.h:40
int size() const
Size.
Definition: band_matrix.h:219
const AT * operator()() const
Pointer operator.
Definition: band_matrix.h:213
CBLAS_ORDER blasOrder() const
Storage convention.
Definition: band_matrix.h:240
AT * operator()()
Pointer operator.
Definition: band_matrix.h:207
const AT & operator()(int i, int j) const
Element operator.
Definition: band_matrix.h:190
int cols() const
Number of columns.
Definition: band_matrix.h:231
Matrix< GeneralBand, Ref, Ref, AT > & init(const AT &val=AT())
Diagonal operator.
Definition: band_matrix.h:279
Matrix(int n_, int kl_, int ku_, AT *ele_)
Regular Constructor.
Definition: band_matrix.h:114
int rows() const
Number of rows.
Definition: band_matrix.h:225
Matrix(const Matrix< Type, Row, Col, AT > &A)
Copy Constructor.
Definition: band_matrix.h:100
~Matrix()=default
Destructor.
Matrix< GeneralBand, Ref, Ref, AT > & operator=(const Matrix< GeneralBand, Ref, Ref, AT > &A)
Assignment operator.
Definition: band_matrix.h:138
Matrix()
Standard constructor.
Definition: band_matrix.h:66
Matrix< GeneralBand, Ref, Ref, AT > & operator=(const Matrix< Type, Row, Col, AT > &A)
Assignment operator.
Definition: band_matrix.h:150
Matrix< GeneralBand, Ref, Ref, AT > & operator&=(Matrix< GeneralBand, Ref, Ref, AT > &A)
Reference operator.
Definition: band_matrix.h:162
Matrix(const Matrix< GeneralBand, Ref, Ref, AT > &A)
Copy Constructor.
Definition: band_matrix.h:90
This is the basic matrix class for arbitrary matrices.
Definition: matrix.h:52
int rows() const
Number of rows.
int cols() const
Number of columns.
Namespace fmatvec.
Definition: _memory.cc:28