| Stan Math Library 2.12.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

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:

- w: the non-zero values in the sparse matrix.
- v: column index for each value in w, as a result this is the same length as w.
- u: index of where each row starts in w, length is equal to the number of rows plus one. Last entry is one-past-the-end in w, following the Eigen spec. Indexing is either zero-based or one-based depending on the value of stan::error_index::value. Following the definition of the format in Eigen, we allow for unused garbage values in w/v which are never read. All indexing internal to a given function is zero-based.

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

  T1 | Type of sparse matrix entries.
  T2 | Type of dense vector entries.

Parameters

  m | Number of rows in matrix.
  n | Number of columns in matrix.
  w | Vector of non-zero values in matrix.
  v | Column index of each non-zero value, same length as w.
  u | Index of where each row starts in w, length equal to the number of rows plus one.
  b | Eigen vector which the matrix is multiplied by.

Returns
  Dense vector for the product.

Exceptions

  std::domain_error | if m and n are not positive or are nan.
  std::domain_error | if the implied sparse matrix and b are not multiplicable.
  std::invalid_argument | if 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_range | if any of the indexes are out of range.

## Function Documentation

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

  T | Type of matrix entries.

Parameters

  A | Sparse matrix.

Returns
  Vector of indexes into non-zero entries of A.

Definition at line 26 of file csr_extract_u.hpp.

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

  T | Type of matrix entries.

Parameters

  A | Dense matrix.

Returns
  Vector of indexes into non-zero entries of A.

Definition at line 42 of file csr_extract_u.hpp.

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

  T | Type of matrix entries.

Parameters

  A | Sparse matrix.

Returns
  Vector of column indexes for non-zero entries of A.

Definition at line 27 of file csr_extract_v.hpp.

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

  T | Type of matrix entries.

Parameters

  [in] | A | dense matrix.

Returns
  Vector of column indexes to non-zero entries of A.

Definition at line 45 of file csr_extract_v.hpp.

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.

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.

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

  T | Type of matrix entries.

Parameters

  [in] | m | Number of matrix rows.
  [in] | n | Number of matrix columns.
  [in] | w | Values of non-zero matrix entries.
  [in] | v | Column index for each value in w.
  [in] | u | Index of where each row starts in w.

Returns
  Dense matrix defined by previous arguments.

Exceptions

  std::domain_error | If the arguments do not define a matrix.
  std::invalid_argument | if 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_range | if any of the indices are out of range.

Definition at line 37 of file csr_to_dense_matrix.hpp.

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] | u | U vector.
  [in] | i | Index into resulting z vector.

Returns
  z[i] where z is conversion from u.

Exceptions

  std::domain_error | if u is zero length.
  std::out_of_range | if i is out of range.

Definition at line 26 of file csr_u_to_z.hpp.

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