27 typedef gsEigen::SparseVector<T> Row;
37 for (
index_t i = 0; i < rows; ++i)
38 m_rows[i] =
new Row(cols);
42 : m_rows(other.rows())
44 for (
int i = 0; i < rows(); ++i)
45 m_rows[i] =
new Row( *other.m_rows[i] );
51 for (
index_t i = 0; i < rowxpr.num; ++i)
52 m_rows[i] =
new Row( *rowxpr.mat.m_rows[rowxpr.start + i] );
73 index_t rows()
const {
return m_rows.size(); }
74 index_t cols()
const {
return (m_rows.size() > 0) ? m_rows[0]->size() : 0; }
76 Row& row(
index_t i) {
return *m_rows[i]; }
77 const Row& row(
index_t i)
const {
return *m_rows[i]; }
81 for (
int i = 0; i < rows(); ++i)
88 m_rows.swap( other.m_rows );
98 m_rows[i]->insert(i) = (T)(1.0);
103 assert( rows >= 0 && cols >= 0 );
107 for (
index_t i = 0; i < rows; ++i)
108 m_rows[i] =
new Row(cols);
113 if (rows() > 0 && cols() != newCols)
114 throw std::runtime_error(
"cannot resize columns -- not implemented");
116 const index_t oldRows = rows();
120 for (
index_t i = oldRows; i < newRows; ++i)
121 m_rows[i] =
new Row(newCols);
126 assert ( 0 <= k && k < rows() );
132 for (
index_t i = rows() - 1; i > k + 1; --i)
133 m_rows[i] = m_rows[i-1];
136 m_rows[k+1] =
new Row( row(k) );
141 RowBlockXpr topRows(
index_t num) {
return RowBlockXpr(*
this, 0, num); }
142 const RowBlockXpr topRows(
index_t num)
const {
return RowBlockXpr(*
this, 0, num); }
144 RowBlockXpr bottomRows(
index_t num) {
return RowBlockXpr(*
this, rows() - num, num); }
145 const RowBlockXpr bottomRows(
index_t num)
const {
return RowBlockXpr(*
this, rows() - num, num); }
147 RowBlockXpr middleRows(
index_t start,
index_t num) {
return RowBlockXpr(*
this, start, num); }
148 const RowBlockXpr middleRows(
index_t start,
index_t num)
const {
return RowBlockXpr(*
this, start, num); }
153 for (
index_t i = 0; i < rows(); ++i)
154 nnz += m_rows[i]->nonZeros();
158 template <
class Derived>
159 void toSparseMatrix(gsEigen::SparseMatrixBase<Derived>& m)
const
161 m.derived().resize( rows(), cols() );
162 m.derived().reserve( nonZeros() );
163 for (
index_t i = 0; i < rows(); ++i)
165 for (
typename Row::InnerIterator it(*m_rows[i]); it; ++it)
166 m.derived().insert(i, it.index()) = it.value();
168 m.derived().makeCompressed();
174 : mat(const_cast<gsSparseRows&>(_mat)), start(_start), num(_num)
179 assert( 0 <= num && 0 <= start );
180 assert( start < mat.rows() );
181 assert( start + num <= mat.rows() );
187 RowBlockXpr& operator= (
const RowBlockXpr& other)
189 assert(num == other.num);
190 for (
index_t i = 0; i < num; ++i)
191 mat.row(start + i) = other.mat.row(other.start + i);
197 assert(num == other.rows());
198 for (
index_t i = 0; i < num; ++i)
199 mat.row(start + i) = other.row(i);
205 std::vector< Row* > m_rows;
212 for (
index_t i = newRows; i < rows(); ++i)
215 m_rows.resize(newRows);
#define index_t
Definition: gsConfig.h:32
This is the main header file that collects wrappers of Eigen for linear algebra.
A specialized sparse matrix class which stores each row as a separate sparse vector.
Definition: gsSparseRows.hpp:24
void resizeRows(index_t newRows)
Change the number of rows without allocating newly added rows.
Definition: gsSparseRows.hpp:208