CLA3P v0.3.1
Compact Linear Algebra Parallel Portable Package
Loading...
Searching...
No Matches
cla3p::csc::XxMatrix< T_Int, T_Scalar > Class Template Reference

The sparse matrix class (compressed sparse column format). More...

Inheritance diagram for cla3p::csc::XxMatrix< T_Int, T_Scalar >:

Constructors

 XxMatrix ()
 Default constructor.
 XxMatrix (T_Int nr, T_Int nc, T_Int nz, const Property &pr=Property::General())
 Dimension constructor.
 XxMatrix (T_Int nr, T_Int nc, T_Int *cptr, T_Int *ridx, T_Scalar *vals, bool bind, const Property &pr=Property::General())
 Auxiliary constructor.
 XxMatrix (const XxMatrix< T_Int, T_Scalar > &other)
 Copy constructor.
 XxMatrix (XxMatrix< T_Int, T_Scalar > &&other)
 Move constructor.
 ~XxMatrix ()
 Destructor.

Operators

XxMatrix< T_Int, T_Scalar > & operator= (const XxMatrix< T_Int, T_Scalar > &other)
 Copy assignment operator.
XxMatrix< T_Int, T_Scalar > & operator= (XxMatrix< T_Int, T_Scalar > &&other)
 Move assignment operator.
alias::VirtualScal_csc< T_Int, T_Scalar > operator- () const
 Unary negation operator.

Arguments

T_Int * colptr ()
 Access the column pointer array.
const T_Int * colptr () const
 Access the column pointer array.
T_Int * rowidx ()
 Access the row index array.
const T_Int * rowidx () const
 Access the row index array.
T_Int nnz () const
 Get the number of non-zero elements.

Public Member Functions

void clear ()
 Clear the sparse matrix.
std::string info (const std::string &header="") const
 Get information about the sparse matrix.
XxMatrix< T_Int, T_Scalar > copy () const
 Create a deep copy of the sparse matrix.
XxMatrix< T_Int, T_Scalar > rcopy ()
 Create a reference copy (shallow copy) of the sparse matrix.
Guard< XxMatrix< T_Int, T_Scalar > > rcopy () const
 Create a guarded reference copy (shallow copy) of the sparse matrix.
XxMatrix< T_Int, T_Scalar > move ()
 Move the sparse matrix's resources.
void toStream (std::ostream &os, std::streamsize prec=0) const
 Output the sparse matrix to a stream.
void iscale (T_Scalar val)
 Scale the sparse matrix in-place.
alias::VirtualTrans_csc< T_Int, T_Scalar > transpose () const
 Transpose the sparse matrix.
alias::VirtualTrans_csc< T_Int, T_Scalar > ctranspose () const
 Conjugate transpose the sparse matrix.
alias::VirtualConj_csc< T_Int, T_Scalar > conjugate () const
 Compute the complex conjugate.
void iconjugate ()
 Conjugate the sparse matrix in-place.
T_RScalar normOne () const
 Compute the 1-norm.
T_RScalar normInf () const
 Compute the infinity norm.
T_RScalar normMax () const
 Compute the maximum norm.
T_RScalar normFro () const
 Compute the Frobenius norm.
XxMatrix< T_Int, T_Scalar > general () const
 Convert to general sparse matrix.
dns::XxMatrix< T_Scalar > toDns () const
 Convert to dense matrix format.
XxMatrix< T_Int, T_Scalar > permuteLeftRight (const prm::PxMatrix< T_Int > &P, const prm::PxMatrix< T_Int > &Q) const
 Permute rows and columns.
XxMatrix< T_Int, T_Scalar > permuteLeft (const prm::PxMatrix< T_Int > &P) const
 Permute rows.
XxMatrix< T_Int, T_Scalar > permuteRight (const prm::PxMatrix< T_Int > &Q) const
 Permute columns.
XxMatrix< T_Int, T_Scalar > permuteMirror (const prm::PxMatrix< T_Int > &P) const
 Permute rows and columns symmetrically.
XxMatrix< T_Int, T_Scalar > block (T_Int ibgn, T_Int jbgn, T_Int ni, T_Int nj) const
 Extract a block as a new sparse matrix.

Creators/Generators

static XxMatrix< T_Int, T_Scalar > random (T_Int nr, T_Int nc, T_Int nz, const Property &pr=Property::General(), T_RScalar lo=T_RScalar(0), T_RScalar hi=T_RScalar(1))
 Create a random sparse matrix.
static Guard< XxMatrix< T_Int, T_Scalar > > view (T_Int nr, T_Int nc, const T_Int *cptr, const T_Int *ridx, const T_Scalar *vals, const Property &pr=Property::General())
 Create a view of existing CSC arrays.

Additional Inherited Members

Public Member Functions inherited from cla3p::MatrixMeta< T_Int >
const Propertyprop () const
 Matrix property accessor.
Public Member Functions inherited from cla3p::Meta2D< T_Int >
virtual T_Int nrows () const
 Number of rows.
virtual T_Int ncols () const
 Number of columns.
bool empty () const
 Tests whether the object has zero dimensions.
 operator bool () const
 Boolean conversion operator.
Public Member Functions inherited from cla3p::csx::XxContainerBase< T_Int, T_Scalar >
T_Scalar * values ()
 Access the data buffer.
const T_Scalar * values () const
 Access the data buffer.
Public Member Functions inherited from cla3p::Ownership
 Ownership ()
 Default constructor.
 Ownership (bool owner)
 Ownership constructor.
 ~Ownership ()
 Destructor.
bool owner () const
 Tests memory ownership.
void unbind ()
 Relinquishes memory ownership.

Detailed Description

template<typename T_Int, typename T_Scalar>
class cla3p::csc::XxMatrix< T_Int, T_Scalar >

The sparse matrix class (compressed sparse column format).

Constructor & Destructor Documentation

◆ XxMatrix() [1/5]

template<typename T_Int, typename T_Scalar>
cla3p::csc::XxMatrix< T_Int, T_Scalar >::XxMatrix ( )

Default constructor.

Creates an empty sparse matrix with no allocated memory.

◆ XxMatrix() [2/5]

template<typename T_Int, typename T_Scalar>
cla3p::csc::XxMatrix< T_Int, T_Scalar >::XxMatrix ( T_Int nr,
T_Int nc,
T_Int nz,
const Property & pr = Property::General() )
explicit

Dimension constructor.

Creates a sparse matrix of the specified dimensions in CSC format and allocates memory.

Parameters
[in]nrThe number of rows.
[in]ncThe number of columns.
[in]nzThe number of non-zero elements.
[in]prThe matrix property (default: General).

◆ XxMatrix() [3/5]

template<typename T_Int, typename T_Scalar>
cla3p::csc::XxMatrix< T_Int, T_Scalar >::XxMatrix ( T_Int nr,
T_Int nc,
T_Int * cptr,
T_Int * ridx,
T_Scalar * vals,
bool bind,
const Property & pr = Property::General() )
explicit

Auxiliary constructor.

Creates a sparse matrix using existing CSC format arrays.

Parameters
[in]nrThe number of rows.
[in]ncThe number of columns.
[in]cptrPointer to existing column pointer array.
[in]ridxPointer to existing row index array.
[in]valsPointer to existing values array.
[in]bindIf true, the matrix takes ownership of the memory.
[in]prThe matrix property (default: General).

◆ XxMatrix() [4/5]

template<typename T_Int, typename T_Scalar>
cla3p::csc::XxMatrix< T_Int, T_Scalar >::XxMatrix ( const XxMatrix< T_Int, T_Scalar > & other)

Copy constructor.

Creates a new sparse matrix by copying another sparse matrix.

Parameters
[in]otherThe sparse matrix to copy.

◆ XxMatrix() [5/5]

template<typename T_Int, typename T_Scalar>
cla3p::csc::XxMatrix< T_Int, T_Scalar >::XxMatrix ( XxMatrix< T_Int, T_Scalar > && other)

Move constructor.

Creates a new sparse matrix by moving resources from another sparse matrix.

Parameters
[in]otherThe sparse matrix to move from.

◆ ~XxMatrix()

template<typename T_Int, typename T_Scalar>
cla3p::csc::XxMatrix< T_Int, T_Scalar >::~XxMatrix ( )

Destructor.

Destroys the sparse matrix and releases allocated memory.

Member Function Documentation

◆ operator=() [1/2]

template<typename T_Int, typename T_Scalar>
XxMatrix< T_Int, T_Scalar > & cla3p::csc::XxMatrix< T_Int, T_Scalar >::operator= ( const XxMatrix< T_Int, T_Scalar > & other)

Copy assignment operator.

Copies the contents of another sparse matrix to this sparse matrix.

Parameters
[in]otherThe sparse matrix to copy.
Returns
Reference to this sparse matrix.

◆ operator=() [2/2]

template<typename T_Int, typename T_Scalar>
XxMatrix< T_Int, T_Scalar > & cla3p::csc::XxMatrix< T_Int, T_Scalar >::operator= ( XxMatrix< T_Int, T_Scalar > && other)

Move assignment operator.

Moves resources from another sparse matrix to this sparse matrix.

Parameters
[in]otherThe sparse matrix to move from.
Returns
Reference to this sparse matrix.

◆ operator-()

template<typename T_Int, typename T_Scalar>
alias::VirtualScal_csc< T_Int, T_Scalar > cla3p::csc::XxMatrix< T_Int, T_Scalar >::operator- ( ) const

Unary negation operator.

Returns a negated copy of the sparse matrix.

Returns
A virtual expression containing the negated elements.

◆ colptr() [1/2]

template<typename T_Int, typename T_Scalar>
T_Int * cla3p::csc::XxMatrix< T_Int, T_Scalar >::colptr ( )

Access the column pointer array.

Returns a pointer to the column pointer array (CSC format).

Returns
Pointer to the column pointer array.

◆ colptr() [2/2]

template<typename T_Int, typename T_Scalar>
const T_Int * cla3p::csc::XxMatrix< T_Int, T_Scalar >::colptr ( ) const

Access the column pointer array.

Returns a pointer to the column pointer array (CSC format).

Returns
Pointer to the column pointer array.

◆ rowidx() [1/2]

template<typename T_Int, typename T_Scalar>
T_Int * cla3p::csc::XxMatrix< T_Int, T_Scalar >::rowidx ( )

Access the row index array.

Returns a pointer to the row index array (CSC format).

Returns
Pointer to the row index array.

◆ rowidx() [2/2]

template<typename T_Int, typename T_Scalar>
const T_Int * cla3p::csc::XxMatrix< T_Int, T_Scalar >::rowidx ( ) const

Access the row index array.

Returns a pointer to the row index array (CSC format).

Returns
Pointer to the row index array.

◆ nnz()

template<typename T_Int, typename T_Scalar>
T_Int cla3p::csc::XxMatrix< T_Int, T_Scalar >::nnz ( ) const

Get the number of non-zero elements.

Returns the number of stored non-zero elements in the sparse matrix.

Returns
The number of non-zero elements.

◆ clear()

template<typename T_Int, typename T_Scalar>
void cla3p::csc::XxMatrix< T_Int, T_Scalar >::clear ( )

Clear the sparse matrix.

Releases all memory and resets the matrix to an empty state.

◆ info()

template<typename T_Int, typename T_Scalar>
std::string cla3p::csc::XxMatrix< T_Int, T_Scalar >::info ( const std::string & header = "") const

Get information about the sparse matrix.

Returns a string containing information about the matrix's dimensions, non-zeros, and properties.

Parameters
[in]headerOptional header string to prepend to the information.
Returns
A string containing matrix information.

◆ copy()

template<typename T_Int, typename T_Scalar>
XxMatrix< T_Int, T_Scalar > cla3p::csc::XxMatrix< T_Int, T_Scalar >::copy ( ) const

Create a deep copy of the sparse matrix.

Creates a new sparse matrix with its own memory allocation and copies all elements from this matrix to the new matrix.

Returns
A new sparse matrix containing a copy of this matrix's data.

◆ rcopy() [1/2]

template<typename T_Int, typename T_Scalar>
XxMatrix< T_Int, T_Scalar > cla3p::csc::XxMatrix< T_Int, T_Scalar >::rcopy ( )

Create a reference copy (shallow copy) of the sparse matrix.

Creates a new sparse matrix object that references the same memory as this matrix. Changes to either matrix will affect both.

Returns
A sparse matrix that shares memory with this matrix.

◆ rcopy() [2/2]

template<typename T_Int, typename T_Scalar>
Guard< XxMatrix< T_Int, T_Scalar > > cla3p::csc::XxMatrix< T_Int, T_Scalar >::rcopy ( ) const

Create a guarded reference copy (shallow copy) of the sparse matrix.

Creates a guarded sparse matrix object that references the same memory as this matrix. The guard ensures the reference is read-only.

Returns
A guarded sparse matrix that shares memory with this matrix.

◆ move()

template<typename T_Int, typename T_Scalar>
XxMatrix< T_Int, T_Scalar > cla3p::csc::XxMatrix< T_Int, T_Scalar >::move ( )

Move the sparse matrix's resources.

Transfers ownership of the memory to a new sparse matrix object, leaving this matrix in an empty state.

Returns
A new sparse matrix containing this matrix's memory.

◆ toStream()

template<typename T_Int, typename T_Scalar>
void cla3p::csc::XxMatrix< T_Int, T_Scalar >::toStream ( std::ostream & os,
std::streamsize prec = 0 ) const

Output the sparse matrix to a stream.

Writes the sparse matrix elements to the specified output stream with specified precision.

Parameters
[in,out]osThe output stream to write to.
[in]precThe output precision (default: 0 for default precision).

◆ iscale()

template<typename T_Int, typename T_Scalar>
void cla3p::csc::XxMatrix< T_Int, T_Scalar >::iscale ( T_Scalar val)

Scale the sparse matrix in-place.

Multiplies all non-zero elements of the sparse matrix by a scalar value.

Parameters
[in]valThe scalar value to multiply by.

◆ transpose()

template<typename T_Int, typename T_Scalar>
alias::VirtualTrans_csc< T_Int, T_Scalar > cla3p::csc::XxMatrix< T_Int, T_Scalar >::transpose ( ) const

Transpose the sparse matrix.

Returns a transposed view of the sparse matrix.

Returns
A virtual transpose expression.

◆ ctranspose()

template<typename T_Int, typename T_Scalar>
alias::VirtualTrans_csc< T_Int, T_Scalar > cla3p::csc::XxMatrix< T_Int, T_Scalar >::ctranspose ( ) const

Conjugate transpose the sparse matrix.

Returns a conjugate transposed view of the sparse matrix.

Returns
A virtual conjugate transpose expression.

◆ conjugate()

template<typename T_Int, typename T_Scalar>
alias::VirtualConj_csc< T_Int, T_Scalar > cla3p::csc::XxMatrix< T_Int, T_Scalar >::conjugate ( ) const

Compute the complex conjugate.

Returns a virtual expression containing the complex conjugate of each non-zero element.

Returns
A virtual expression with conjugated elements.

◆ iconjugate()

template<typename T_Int, typename T_Scalar>
void cla3p::csc::XxMatrix< T_Int, T_Scalar >::iconjugate ( )

Conjugate the sparse matrix in-place.

Replaces all non-zero elements with their complex conjugates.

◆ normOne()

template<typename T_Int, typename T_Scalar>
T_RScalar cla3p::csc::XxMatrix< T_Int, T_Scalar >::normOne ( ) const

Compute the 1-norm.

Computes the maximum absolute column sum.

Returns
The 1-norm of the sparse matrix.

◆ normInf()

template<typename T_Int, typename T_Scalar>
T_RScalar cla3p::csc::XxMatrix< T_Int, T_Scalar >::normInf ( ) const

Compute the infinity norm.

Computes the maximum absolute row sum.

Returns
The infinity norm of the sparse matrix.

◆ normMax()

template<typename T_Int, typename T_Scalar>
T_RScalar cla3p::csc::XxMatrix< T_Int, T_Scalar >::normMax ( ) const

Compute the maximum norm.

Computes the maximum absolute value of all non-zero elements.

Returns
The maximum norm of the sparse matrix.

◆ normFro()

template<typename T_Int, typename T_Scalar>
T_RScalar cla3p::csc::XxMatrix< T_Int, T_Scalar >::normFro ( ) const

Compute the Frobenius norm.

Computes the square root of the sum of squared absolute values of all non-zero elements.

Returns
The Frobenius norm of the sparse matrix.

◆ general()

template<typename T_Int, typename T_Scalar>
XxMatrix< T_Int, T_Scalar > cla3p::csc::XxMatrix< T_Int, T_Scalar >::general ( ) const

Convert to general sparse matrix.

Creates a new general sparse matrix by copying all relevant elements from a structured sparse matrix.

Returns
A general sparse matrix containing the full data.

◆ toDns()

template<typename T_Int, typename T_Scalar>
dns::XxMatrix< T_Scalar > cla3p::csc::XxMatrix< T_Int, T_Scalar >::toDns ( ) const

Convert to dense matrix format.

Converts the sparse matrix to a dense matrix by expanding all elements.

Returns
A dense matrix containing the same data.

◆ permuteLeftRight()

template<typename T_Int, typename T_Scalar>
XxMatrix< T_Int, T_Scalar > cla3p::csc::XxMatrix< T_Int, T_Scalar >::permuteLeftRight ( const prm::PxMatrix< T_Int > & P,
const prm::PxMatrix< T_Int > & Q ) const

Permute rows and columns.

Applies left and right permutations to the sparse matrix.

Parameters
[in]PThe row permutation matrix.
[in]QThe column permutation matrix.
Returns
A new sparse matrix containing the permuted elements.

◆ permuteLeft()

template<typename T_Int, typename T_Scalar>
XxMatrix< T_Int, T_Scalar > cla3p::csc::XxMatrix< T_Int, T_Scalar >::permuteLeft ( const prm::PxMatrix< T_Int > & P) const

Permute rows.

Applies a left (row) permutation to the sparse matrix.

Parameters
[in]PThe row permutation matrix.
Returns
A new sparse matrix containing the permuted elements.

◆ permuteRight()

template<typename T_Int, typename T_Scalar>
XxMatrix< T_Int, T_Scalar > cla3p::csc::XxMatrix< T_Int, T_Scalar >::permuteRight ( const prm::PxMatrix< T_Int > & Q) const

Permute columns.

Applies a right (column) permutation to the sparse matrix.

Parameters
[in]QThe column permutation matrix.
Returns
A new sparse matrix containing the permuted elements.

◆ permuteMirror()

template<typename T_Int, typename T_Scalar>
XxMatrix< T_Int, T_Scalar > cla3p::csc::XxMatrix< T_Int, T_Scalar >::permuteMirror ( const prm::PxMatrix< T_Int > & P) const

Permute rows and columns symmetrically.

Applies the same permutation to both rows and columns (mirror permutation).

Parameters
[in]PThe permutation matrix to apply to both rows and columns.
Returns
A new sparse matrix containing the permuted elements.

◆ block()

template<typename T_Int, typename T_Scalar>
XxMatrix< T_Int, T_Scalar > cla3p::csc::XxMatrix< T_Int, T_Scalar >::block ( T_Int ibgn,
T_Int jbgn,
T_Int ni,
T_Int nj ) const

Extract a block as a new sparse matrix.

Creates a new sparse matrix containing a copy of a contiguous block of elements.

Parameters
[in]ibgnThe starting row index of the block.
[in]jbgnThe starting column index of the block.
[in]niThe number of rows in the block.
[in]njThe number of columns in the block.
Returns
A new sparse matrix containing the block's data.

◆ random()

template<typename T_Int, typename T_Scalar>
XxMatrix< T_Int, T_Scalar > cla3p::csc::XxMatrix< T_Int, T_Scalar >::random ( T_Int nr,
T_Int nc,
T_Int nz,
const Property & pr = Property::General(),
T_RScalar lo = T_RScalar(0),
T_RScalar hi = T_RScalar(1) )
static

Create a random sparse matrix.

Creates a sparse matrix with random non-zero values uniformly distributed in the specified range.

Parameters
[in]nrThe number of rows.
[in]ncThe number of columns.
[in]nzThe number of non-zero elements.
[in]prThe matrix property (default: General).
[in]loThe lower bound of the random values (default: 0).
[in]hiThe upper bound of the random values (default: 1).
Returns
A sparse matrix containing random values.

◆ view()

template<typename T_Int, typename T_Scalar>
Guard< XxMatrix< T_Int, T_Scalar > > cla3p::csc::XxMatrix< T_Int, T_Scalar >::view ( T_Int nr,
T_Int nc,
const T_Int * cptr,
const T_Int * ridx,
const T_Scalar * vals,
const Property & pr = Property::General() )
static

Create a view of existing CSC arrays.

Creates a guarded sparse matrix that references existing CSC format memory without taking ownership. The memory must remain valid for the lifetime of the returned view.

Parameters
[in]nrThe number of rows.
[in]ncThe number of columns.
[in]cptrPointer to the column pointer array.
[in]ridxPointer to the row index array.
[in]valsPointer to the values array.
[in]prThe matrix property (default: General).
Returns
A guarded sparse matrix that views the specified CSC arrays.