Adding Sparse Matrix Indexing
Open
@avehtari is already working on this.
Since Mar 12, 2020.
feature
- Dominant language
- C++
- Stars
- 2.8k
- Forks
- 388
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 15
Description
Summary:
Looking over the Eigen docs I think we can support the following in the stan language
data {
int N; // rows
int M; // cols
int nz_vals; // number of nonzero values
int nz_vec_vals; // number of nonzero values in vector
int nz_rows[nnz_vals]; // row position of nonzero values
int nz_cols[nnz_vals]; // col position of nonzero values
int nz_vec_rows[nnz_vals]; // row position of nonzero vector values
matrix[N, M] A_mat; // basic matrix
sparse_matrix[nz_rows, nz_cols, N, M] A_sparse; // sparse matrix
sparse_vector[nz_vec_rows, N] A_sparse_vec; // sparse vector
}
transformed data {
sparse_matrix[N, M] A_sparse_mod = A_sparse;
sparse_vector[N] A_sparse_vec_mod = A_sparse_vec;
// Coeff access anywhere (slow but doable, fine for preallocated nnz areas)
A_sparse_mod[1, 5] = 10.0;
// Row / Column assignment:
// From sparse vec
A_sparse_mod[1, ] = sparse_vector; // stored as column major so efficient
A_sparse[, 1] = sparse_vector; // bad performance but low effort
// From normal mat (possible but why?)
A_sparse_mod[1:10, 1:10] = A_mat[1:10, 1:10];
A_sparse_mod[1, ] = A_mat[1, ];
A_sparse_mod[, 1] = A_mat[, 1];
//
}
@avehtari which of these would we want? All of them? Am I missing any?
Current Version:
v2.22.0
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.