cuLite v0.3.1
A lite CUDA C++ Interface
Loading...
Searching...
No Matches
culite::csr::XxMatrix< T_Int, T_Scalar > Class Template Reference

The device sparse matrix class (compressed sparse row format). More...

Inheritance diagram for culite::csr::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 *rptr, T_Int *cidx, 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_csr< T_Int, T_Scalar > operator- () const
 Unary negation operator.

Arguments

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

Public Member Functions

void clear ()
 Clear the device 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 device sparse matrix.
XxMatrix< T_Int, T_Scalar > rcopy ()
 Create a reference copy (shallow copy) of the device sparse matrix.
Guard< XxMatrix< T_Int, T_Scalar > > rcopy () const
 Create a guarded reference copy (shallow copy) of the device sparse matrix.
XxMatrix< T_Int, T_Scalar > move ()
 Move the device sparse matrix's resources.
void iscale (T_Scalar val)
 Scale the device sparse matrix in-place.
alias::VirtualTrans_csr< T_Int, T_Scalar > transpose () const
 Compute the transpose.
alias::VirtualTrans_csr< T_Int, T_Scalar > ctranspose () const
 Compute the conjugate transpose (Hermitian transpose).
alias::VirtualConj_csr< T_Int, T_Scalar > conjugate () const
 Compute the complex conjugate.
void iconjugate ()
 Conjugate the device sparse matrix in-place.
void copyToHost (::cla3p::csr::XxMatrix< T_Cla3pInt, T_Cla3pScalar > &dest) const
 Copy the device sparse matrix to host memory.
void copyFromHost (const ::cla3p::csr::XxMatrix< T_Cla3pInt, T_Cla3pScalar > &src)
 Copy a host sparse matrix to this device sparse matrix.

Creators/Generators

static Guard< XxMatrix< T_Int, T_Scalar > > view (T_Int nr, T_Int nc, const T_Int *rptr, const T_Int *cidx, const T_Scalar *vals, const Property &pr=Property::General())
 Create a view of existing device CSR arrays.

Detailed Description

template<typename T_Int, typename T_Scalar>
class culite::csr::XxMatrix< T_Int, T_Scalar >

The device sparse matrix class (compressed sparse row format).

Represents a sparse matrix stored on the GPU device in CSR format.

Template Parameters
T_IntThe integer type for indexing (e.g., int32_t, int64_t).
T_ScalarThe scalar type (e.g., float, double, complex).

Constructor & Destructor Documentation

◆ XxMatrix() [1/5]

template<typename T_Int, typename T_Scalar>
culite::csr::XxMatrix< T_Int, T_Scalar >::XxMatrix ( )

Default constructor.

Creates an empty device sparse matrix with no allocated device memory.

◆ XxMatrix() [2/5]

template<typename T_Int, typename T_Scalar>
culite::csr::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 device sparse matrix of the specified dimensions in CSR format and allocates device 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>
culite::csr::XxMatrix< T_Int, T_Scalar >::XxMatrix ( T_Int nr,
T_Int nc,
T_Int * rptr,
T_Int * cidx,
T_Scalar * vals,
bool bind,
const Property & pr = Property::General() )
explicit

Auxiliary constructor.

Creates a device sparse matrix using existing device memory CSR format arrays.

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

◆ XxMatrix() [4/5]

template<typename T_Int, typename T_Scalar>
culite::csr::XxMatrix< T_Int, T_Scalar >::XxMatrix ( const XxMatrix< T_Int, T_Scalar > & other)

Copy constructor.

Creates a new device sparse matrix by copying another device sparse matrix.

Parameters
[in]otherThe device sparse matrix to copy.

◆ XxMatrix() [5/5]

template<typename T_Int, typename T_Scalar>
culite::csr::XxMatrix< T_Int, T_Scalar >::XxMatrix ( XxMatrix< T_Int, T_Scalar > && other)

Move constructor.

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

Parameters
[in]otherThe device sparse matrix to move from.

◆ ~XxMatrix()

template<typename T_Int, typename T_Scalar>
culite::csr::XxMatrix< T_Int, T_Scalar >::~XxMatrix ( )

Destructor.

Destroys the device sparse matrix and releases allocated device memory.

Member Function Documentation

◆ operator=() [1/2]

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

Copy assignment operator.

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

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

◆ operator=() [2/2]

template<typename T_Int, typename T_Scalar>
XxMatrix< T_Int, T_Scalar > & culite::csr::XxMatrix< T_Int, T_Scalar >::operator= ( XxMatrix< T_Int, T_Scalar > && other)

Move assignment operator.

Moves resources from another device sparse matrix to this device sparse matrix.

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

◆ operator-()

template<typename T_Int, typename T_Scalar>
alias::VirtualScal_csr< T_Int, T_Scalar > culite::csr::XxMatrix< T_Int, T_Scalar >::operator- ( ) const

Unary negation operator.

Returns a negated copy of the device sparse matrix.

Returns
A device sparse matrix containing the negated elements.

◆ rowptr() [1/2]

template<typename T_Int, typename T_Scalar>
T_Int * culite::csr::XxMatrix< T_Int, T_Scalar >::rowptr ( )

Access the row pointer array.

Returns a pointer to the row pointer array (CSR format).

Returns
Pointer to the row pointer array.

◆ rowptr() [2/2]

template<typename T_Int, typename T_Scalar>
const T_Int * culite::csr::XxMatrix< T_Int, T_Scalar >::rowptr ( ) const

Access the row pointer array.

Returns a pointer to the row pointer array (CSR format).

Returns
Pointer to the row pointer array.

◆ colidx() [1/2]

template<typename T_Int, typename T_Scalar>
T_Int * culite::csr::XxMatrix< T_Int, T_Scalar >::colidx ( )

Access the column index array.

Returns a pointer to the column index array (CSR format).

Returns
Pointer to the column index array.

◆ colidx() [2/2]

template<typename T_Int, typename T_Scalar>
const T_Int * culite::csr::XxMatrix< T_Int, T_Scalar >::colidx ( ) const

Access the column index array.

Returns a pointer to the column index array (CSR format).

Returns
Pointer to the column index array.

◆ nnz()

template<typename T_Int, typename T_Scalar>
T_Int culite::csr::XxMatrix< T_Int, T_Scalar >::nnz ( ) const

Get the number of non-zero elements.

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

Returns
The number of non-zero elements.

◆ clear()

template<typename T_Int, typename T_Scalar>
void culite::csr::XxMatrix< T_Int, T_Scalar >::clear ( )

Clear the device sparse matrix.

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

◆ info()

template<typename T_Int, typename T_Scalar>
std::string culite::csr::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 > culite::csr::XxMatrix< T_Int, T_Scalar >::copy ( ) const

Create a deep copy of the device sparse matrix.

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

Returns
A new device 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 > culite::csr::XxMatrix< T_Int, T_Scalar >::rcopy ( )

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

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

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

◆ rcopy() [2/2]

template<typename T_Int, typename T_Scalar>
Guard< XxMatrix< T_Int, T_Scalar > > culite::csr::XxMatrix< T_Int, T_Scalar >::rcopy ( ) const

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

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

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

◆ move()

template<typename T_Int, typename T_Scalar>
XxMatrix< T_Int, T_Scalar > culite::csr::XxMatrix< T_Int, T_Scalar >::move ( )

Move the device sparse matrix's resources.

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

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

◆ iscale()

template<typename T_Int, typename T_Scalar>
void culite::csr::XxMatrix< T_Int, T_Scalar >::iscale ( T_Scalar val)

Scale the device sparse matrix in-place.

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

Parameters
[in]valThe scalar value to multiply by.

◆ transpose()

template<typename T_Int, typename T_Scalar>
alias::VirtualTrans_csr< T_Int, T_Scalar > culite::csr::XxMatrix< T_Int, T_Scalar >::transpose ( ) const

Compute the transpose.

Returns a virtual expression representing the transpose of the device sparse matrix. Rows and columns are swapped.

Returns
A virtual expression for the transposed matrix.
Warning
Explicit calculation is not supported. Evaluating the returned expression on an existing matrix will throw an exception.

◆ ctranspose()

template<typename T_Int, typename T_Scalar>
alias::VirtualTrans_csr< T_Int, T_Scalar > culite::csr::XxMatrix< T_Int, T_Scalar >::ctranspose ( ) const

Compute the conjugate transpose (Hermitian transpose).

Returns a virtual expression representing the conjugate transpose of the device sparse matrix. Rows and columns are swapped, and complex elements are conjugated. For real matrices, this is equivalent to transpose().

Returns
A virtual expression for the conjugate transposed matrix.
Warning
Explicit calculation is not supported. Evaluating the returned expression on an existing matrix will throw an exception.

◆ conjugate()

template<typename T_Int, typename T_Scalar>
alias::VirtualConj_csr< T_Int, T_Scalar > culite::csr::XxMatrix< T_Int, T_Scalar >::conjugate ( ) const

Compute the complex conjugate.

Returns a device matrix containing the complex conjugate of each non-zero element.

Returns
A device sparse matrix with conjugated elements.

◆ iconjugate()

template<typename T_Int, typename T_Scalar>
void culite::csr::XxMatrix< T_Int, T_Scalar >::iconjugate ( )

Conjugate the device sparse matrix in-place.

Replaces all non-zero elements with their complex conjugates.

◆ copyToHost()

template<typename T_Int, typename T_Scalar>
void culite::csr::XxMatrix< T_Int, T_Scalar >::copyToHost ( ::cla3p::csr::XxMatrix< T_Cla3pInt, T_Cla3pScalar > & dest) const

Copy the device sparse matrix to host memory.

Transfers the device sparse matrix data to a host sparse matrix.

Parameters
[out]destThe host sparse matrix destination.

◆ copyFromHost()

template<typename T_Int, typename T_Scalar>
void culite::csr::XxMatrix< T_Int, T_Scalar >::copyFromHost ( const ::cla3p::csr::XxMatrix< T_Cla3pInt, T_Cla3pScalar > & src)

Copy a host sparse matrix to this device sparse matrix.

Transfers data from a host sparse matrix to this device sparse matrix.

Parameters
[in]srcThe host sparse matrix source.

◆ view()

template<typename T_Int, typename T_Scalar>
Guard< XxMatrix< T_Int, T_Scalar > > culite::csr::XxMatrix< T_Int, T_Scalar >::view ( T_Int nr,
T_Int nc,
const T_Int * rptr,
const T_Int * cidx,
const T_Scalar * vals,
const Property & pr = Property::General() )
static

Create a view of existing device CSR arrays.

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

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