Stan Math Library  2.15.0
reverse mode automatic differentiation
Functions
Compressed Sparse Row matrix format.

A compressed Sparse Row (CSR) sparse matrix is defined by four component vectors labeled w, v, and u. More...

Functions

template<typename T >
const std::vector< int > stan::math::csr_extract_u (const Eigen::SparseMatrix< T, Eigen::RowMajor > &A)
 Extract the NZE index for each entry from a sparse matrix. More...
 
template<typename T , int R, int C>
const std::vector< int > stan::math::csr_extract_u (const Eigen::Matrix< T, R, C > &A)
 Extract the NZE index for each entry from a sparse matrix. More...
 
template<typename T >
const std::vector< int > stan::math::csr_extract_v (const Eigen::SparseMatrix< T, Eigen::RowMajor > &A)
 Extract the column indexes for non-zero value from a sparse matrix. More...
 
template<typename T , int R, int C>
const std::vector< int > stan::math::csr_extract_v (const Eigen::Matrix< T, R, C > &A)
 Extract the column indexes for non-zero values from a dense matrix by converting to sparse and calling the sparse matrix extractor. More...
 
template<typename T >
const Eigen::Matrix< T, Eigen::Dynamic, 1 > stan::math::csr_extract_w (const Eigen::SparseMatrix< T, Eigen::RowMajor > &A)
 
template<typename T , int R, int C>
const Eigen::Matrix< T, Eigen::Dynamic, 1 > stan::math::csr_extract_w (const Eigen::Matrix< T, R, C > &A)
 
template<typename T >
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > stan::math::csr_to_dense_matrix (int m, int n, const Eigen::Matrix< T, Eigen::Dynamic, 1 > &w, const std::vector< int > &v, const std::vector< int > &u)
 Construct a dense Eigen matrix from the CSR format components. More...
 
int stan::math::csr_u_to_z (const std::vector< int > &u, int i)
 Return the z vector computed from the specified u vector at the index for the z vector. More...
 

Detailed Description

A compressed Sparse Row (CSR) sparse matrix is defined by four component vectors labeled w, v, and u.

Return the multiplication of the sparse matrix (specified by by values and indexing) by the specified dense vector.

They are defined as:

With only m/n/w/v/u in hand, it is possible to check all dimensions are sane except the column dimension since it is implicit. The error-checking strategy is to check all dimensions except the column dimension before any work is done inside a function. The column index is checked as it is constructed and used for each entry. If the column index is not needed it is not checked. As a result indexing mistakes might produce non-sensical operations but out-of-bounds indexing will be caught.

Except for possible garbage values in w/v/u, memory usage is calculated from the number of non-zero entries (NNZE) and the number of rows (NR): 2*NNZE + 2*NR + 1.

The sparse matrix X of dimension m by n is represented by the vector w (of values), the integer array v (containing one-based column index of each value), the integer array u (containing one-based indexes of where each row starts in w).

Template Parameters
T1Type of sparse matrix entries.
T2Type of dense vector entries.
Parameters
mNumber of rows in matrix.
nNumber of columns in matrix.
wVector of non-zero values in matrix.
vColumn index of each non-zero value, same length as w.
uIndex of where each row starts in w, length equal to the number of rows plus one.
bEigen vector which the matrix is multiplied by.
Returns
Dense vector for the product.
Exceptions
std::domain_errorif m and n are not positive or are nan.
std::domain_errorif the implied sparse matrix and b are not multiplicable.
std::invalid_argumentif m/n/w/v/u are not internally consistent, as defined by the indexing scheme. Extractors are defined in Stan which guarantee a consistent set of m/n/w/v/u for a given sparse matrix.
std::out_of_rangeif any of the indexes are out of range.

Function Documentation

§ csr_extract_u() [1/2]

template<typename T >
const std::vector<int> stan::math::csr_extract_u ( const Eigen::SparseMatrix< T, Eigen::RowMajor > &  A)

Extract the NZE index for each entry from a sparse matrix.

Template Parameters
TType of matrix entries.
Parameters
ASparse matrix.
Returns
Vector of indexes into non-zero entries of A.

Definition at line 26 of file csr_extract_u.hpp.

§ csr_extract_u() [2/2]

template<typename T , int R, int C>
const std::vector<int> stan::math::csr_extract_u ( const Eigen::Matrix< T, R, C > &  A)

Extract the NZE index for each entry from a sparse matrix.

Template Parameters
TType of matrix entries.
Parameters
ADense matrix.
Returns
Vector of indexes into non-zero entries of A.

Definition at line 42 of file csr_extract_u.hpp.

§ csr_extract_v() [1/2]

template<typename T >
const std::vector<int> stan::math::csr_extract_v ( const Eigen::SparseMatrix< T, Eigen::RowMajor > &  A)

Extract the column indexes for non-zero value from a sparse matrix.

Template Parameters
TType of matrix entries.
Parameters
ASparse matrix.
Returns
Vector of column indexes for non-zero entries of A.

Definition at line 27 of file csr_extract_v.hpp.

§ csr_extract_v() [2/2]

template<typename T , int R, int C>
const std::vector<int> stan::math::csr_extract_v ( const Eigen::Matrix< T, R, C > &  A)

Extract the column indexes for non-zero values from a dense matrix by converting to sparse and calling the sparse matrix extractor.

Template Parameters
TType of matrix entries.
Parameters
[in]Adense matrix.
Returns
Vector of column indexes to non-zero entries of A.

Definition at line 45 of file csr_extract_v.hpp.

§ csr_extract_w() [1/2]

template<typename T >
const Eigen::Matrix<T, Eigen::Dynamic, 1> stan::math::csr_extract_w ( const Eigen::SparseMatrix< T, Eigen::RowMajor > &  A)

Definition at line 22 of file csr_extract_w.hpp.

§ csr_extract_w() [2/2]

template<typename T , int R, int C>
const Eigen::Matrix<T, Eigen::Dynamic, 1> stan::math::csr_extract_w ( const Eigen::Matrix< T, R, C > &  A)

Definition at line 39 of file csr_extract_w.hpp.

§ csr_to_dense_matrix()

template<typename T >
Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> stan::math::csr_to_dense_matrix ( int  m,
int  n,
const Eigen::Matrix< T, Eigen::Dynamic, 1 > &  w,
const std::vector< int > &  v,
const std::vector< int > &  u 
)
inline

Construct a dense Eigen matrix from the CSR format components.

Template Parameters
TType of matrix entries.
Parameters
[in]mNumber of matrix rows.
[in]nNumber of matrix columns.
[in]wValues of non-zero matrix entries.
[in]vColumn index for each value in w.
[in]uIndex of where each row starts in w.
Returns
Dense matrix defined by previous arguments.
Exceptions
std::domain_errorIf the arguments do not define a matrix.
std::invalid_argumentif m/n/w/v/u are not internally consistent, as defined by the indexing scheme. Extractors are defined in Stan which guarantee a consistent set of m/n/w/v/u for a given sparse matrix.
std::out_of_rangeif any of the indices are out of range.

Definition at line 37 of file csr_to_dense_matrix.hpp.

§ csr_u_to_z()

int stan::math::csr_u_to_z ( const std::vector< int > &  u,
int  i 
)
inline

Return the z vector computed from the specified u vector at the index for the z vector.

Parameters
[in]uU vector.
[in]iIndex into resulting z vector.
Returns
z[i] where z is conversion from u.
Exceptions
std::domain_errorif u is zero length.
std::out_of_rangeif i is out of range.

Definition at line 26 of file csr_u_to_z.hpp.


     [ Stan Home Page ] © 2011–2016, Stan Development Team.