Create an empty sparse matrix representing an n1 x n2 system of linear equations (currently, n1 must be equal to n2)
Definition at line 63 of file tsparsematrix.ixx.
65 pA(std::make_shared<TArray1<T>>(n1)),
66 pJA(std::make_shared<TArray1<int>>(n1)),
67 pIA(std::make_shared<TArray1<int>>(n1+1))
72 snprintf(errormsg,80,
"numcxx::TSparseMatrix::TSparseMatrix unexpected non-equal matrix dimensions\n");
73 throw std::length_error(errormsg);
std::shared_ptr< TArray1< int > > pJA
Column indices.
std::shared_ptr< TArray1< T > > pA
Entries.
std::shared_ptr< TArray1< int > > pIA
Row pointers.
Create an empty sparse matrix representing an n x n system of linear equations.
Definition at line 86 of file tsparsematrix.ixx.
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;
void flush()
Re-create the internal data structure in order to accomodated all newly created elements.
Copy constructor is deleted.
Static wrapper around corresponding constructor.
Definition at line 101 of file tsparsematrix.ixx.
103 return std::make_shared<TSparseMatrix <T>>(il);
Access operator.
This operator accesses the sparse matrix element at position i,j. If it is not existent, it is created. All freshly created elements are collected in an extension list which is joined with the main data structure using the flush() method.
Definition at line 226 of file tsparsematrix.ixx.
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);
std::shared_ptr< TArray1< int > > pJA
Column indices.
std::shared_ptr< Extension > pExt
bool pattern_changed() const
Check if pattern has changed after last solver update.
std::shared_ptr< TArray1< T > > pA
Entries.
std::shared_ptr< TArray1< int > > pIA
Row pointers.
Re-create the internal data structure in order to accomodated all newly created elements.
- Examples:
- 15-numcxx-umfpack.cxx, and 45-convdiff1d.cxx.
Definition at line 107 of file tsparsematrix.ixx.
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);
std::shared_ptr< TArray1< int > > pJA
Column indices.
A::value_type max(const A &a)
Maximum of array or expression.
std::shared_ptr< Extension > pExt
std::shared_ptr< TArray1< T > > pA
Entries.
static std::shared_ptr< TArray1< T > > create(index n1)
Construct smart pointer empty 1D Array.
std::shared_ptr< TArray1< int > > pIA
Row pointers.
Definition at line 63 of file tsparsematrix.hxx.
63 {
flush(); (*pIA)=0.0;}
void flush()
Re-create the internal data structure in order to accomodated all newly created elements.
Apply sparse matrix to vector.
Reimplemented from numcxx::TLinOperator< T >.
Definition at line 209 of file tsparsematrix.ixx.
215 for (
int i=0;i<
n;i++)
218 for (
int j=IA[i];j<IA[i+1];j++)
std::shared_ptr< TArray1< int > > pJA
Column indices.
std::shared_ptr< Extension > pExt
std::shared_ptr< TArray1< T > > pA
Entries.
std::shared_ptr< TArray1< int > > pIA
Row pointers.
Create a dense matrix from the sparse matrix.
Definition at line 249 of file tsparsematrix.ixx.
259 for (
int i=0;i<
n;i++)
260 for (
int j=IA[i];j<IA[i+1];j++)
std::shared_ptr< TArray1< int > > pJA
Column indices.
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.
std::shared_ptr< TArray1< T > > pA
Entries.
std::shared_ptr< TArray1< int > > pIA
Row pointers.
Calculate inverse of sparse matrix whuch is dense.
Definition at line 403 of file tsparsematrix.ixx.
407 return pLU->calculate_inverse();
std::shared_ptr< TMatrix< T > > copy_as_dense()
Create a dense matrix from the sparse matrix.
static std::shared_ptr< TSolverLapackLU< T > > create(const std::shared_ptr< TMatrix< T >> pMatrix)
Static wrapper around constructor.
std::shared_ptr< TArray1< T > > pA
Entries.
Check if pattern has changed after last solver update.
Definition at line 100 of file tsparsematrix.hxx.
The documentation for this class was generated from the following files: