15 class TSparseMatrix<T>::RowEntry
31 std::shared_ptr<std::vector<int>>
pIA;
34 std::shared_ptr<std::vector<int>>
pJA;
37 std::shared_ptr<std::vector <T> >
pA;
46 T& entry(
int i,
int j);
48 void apply(
const TArray<T>&U, TArray<T>&V);
52 T read_entry(
int i,
int j);
72 snprintf(errormsg,80,
"numcxx::TSparseMatrix::TSparseMatrix unexpected non-equal matrix dimensions\n");
73 throw std::length_error(errormsg);
90 for (
auto jl = il.begin() ; jl != il.end(); jl++,i++)
93 for (
auto x = jl->begin() ; x != jl->end(); x++,j++)
94 this->
operator()(i,j)= *x;
100 template <
typename T>
103 return std::make_shared<TSparseMatrix <T>>(il);
106 template <
typename T>
109 if (
pExt==
nullptr)
return;
110 if (
pExt->empty())
return;
115 int nJA_new=nJA_old+next;
121 auto &New_IA=*pNew_IA;
122 auto &New_JA=*pNew_JA;
129 auto &Ext_IA=*
pExt->pIA;
130 auto &Ext_JA=*
pExt->pJA;
131 auto &Ext_A=*
pExt->pA;
138 for (
int k=k0; k>=0;k0=k, k=Ext_IA[k]) lrow++;
139 maxrow_ext=
std::max(lrow,maxrow_ext);
142 std::vector<RowEntry> row(
maxrow+maxrow_ext+10);
151 for (
int k=k0; k>=0;k0=k, k=Ext_IA[k])
154 row[lxrow].i=Ext_JA[k];
155 row[lxrow].a=Ext_A[k];
160 std::sort(row.begin(),row.begin()+lxrow,
161 [](
const RowEntry&e1,
const RowEntry &e2)->
bool 175 if (k<Old_IA[i+1] && ((irow>lxrow) ||Old_JA[k]<row[irow].i))
186 New_JA[j]=row[irow].i;
187 New_A[j]=row[irow].a;
194 New_maxrow=
std::max(New_maxrow,j-j0);
208 template <
typename T>
215 for (
int i=0;i<
n;i++)
218 for (
int j=IA[i];j<IA[i+1];j++)
225 template <
typename T>
231 #ifdef NUMCXX_CHECK_BOUNDS 232 if (i<0||j<0||i>=
n||j>=
n)
235 snprintf(errormsg,80,
"numcxx::TSparseMatrix::op(): shape=(%d %d) but using index (%d %d)\n",
n,
n,i,j);
236 throw std::out_of_range(errormsg);
239 for (
int k=IA[i];k<IA[i+1];k++)
243 if (
pExt==
nullptr)
pExt=std::make_shared<Extension>(
n);
245 return pExt->entry(i,j);
248 template <
typename T>
259 for (
int i=0;i<
n;i++)
260 for (
int j=IA[i];j<IA[i+1];j++)
271 template <
typename T>
275 pA(std::make_shared<std::vector<T>>(n)),
276 pJA(std::make_shared<std::vector<int>>(n)),
277 pIA(std::make_shared<std::vector<int>>(n))
284 for (
int i=0;i<
n;i++)
292 template <
typename T>
340 for (
int k=k0; k>=0;k0=k, k=IA[k])
359 template <
typename T>
368 for (
int i=0;i<
n; i++)
369 for (
int k=i; k>=0;k=IA[k])
378 template <
typename T>
387 for (
int k=k0; k>=0;k0=k, k=IA[k])
394 template <
typename T>
397 if (next==0)
return true;
402 template <
typename T>
407 return pLU->calculate_inverse();
std::shared_ptr< TArray1< int > > pJA
Column indices.
std::shared_ptr< TMatrix< T > > calculate_inverse()
Calculate inverse of sparse matrix whuch is dense.
Sparse matrix class using CRS storage scheme.
std::shared_ptr< TMatrix< T > > copy_as_dense()
Create a dense matrix from the sparse matrix.
A::value_type max(const A &a)
Maximum of array or expression.
static std::shared_ptr< TSolverLapackLU< T > > create(const std::shared_ptr< TMatrix< T >> pMatrix)
Static wrapper around constructor.
std::shared_ptr< Extension > pExt
static std::shared_ptr< TMatrix< T > > create(index n1, index n2)
Construct empty square matrix.
void flush()
Re-create the internal data structure in order to accomodated all newly created elements.
TArray is the common template base class for arrays and dense matrices of the numcxx project...
size_t size() const
Obtain size of array.
Header for numcxx::TSolverLapackLU.
bool pattern_changed() const
Check if pattern has changed after last solver update.
std::shared_ptr< TArray1< T > > pA
Entries.
One dimensional array class.
void apply(const TArray< T > &U, TArray< T > &V) const
Apply sparse matrix to vector.
void resize(size_t n)
Resize array.
static std::shared_ptr< TArray1< T > > create(index n1)
Construct smart pointer empty 1D Array.
T & operator()(int i, int j)
Access operator.
static std::shared_ptr< TSparseMatrix< T > > create(index n1, index n2)
Static wrapper around corresponding constructor.
std::shared_ptr< TArray1< int > > pIA
Row pointers.