Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For Sparse Matrix/Vector provide a means to access the non-zero sparse values without enumerating over a complete column/row. #40

Closed
carlnolan opened this issue Jul 1, 2012 · 1 comment

Comments

@carlnolan
Copy link

There are interbal arrays that would be more efficient for access to the non-zero values in a SparseMatrix. Somtheing alaong the lines of:
let last = coMatrix.InternalSparseRowOffsets.Length - 1
if item >= 0 && item <= last then
let (startI, endI) =
if item = last then (coMatrix.InternalSparseRowOffsets.[item], coMatrix.InternalSparseRowOffsets.[item])
else (coMatrix.InternalSparseRowOffsets.[item], coMatrix.InternalSparseRowOffsets.[item + 1] - 1)
seq {
for idx = startI to endI do
let item= coMatrix.InternalSparseColumnValues.[idx]
yield KeyValuePair(coMatrix.InternalSparseValues.[idx], item)
}

It seems the only alternative is to iterate over a Row.
The element-wise operations would allow for more efficient code.

@cdrnet
Copy link
Member

cdrnet commented Aug 29, 2012

Two ways to do that:

  • Use matrix.IndexedEnumerator() to enumerate only over non-zero values - although there is currently no special IndexedColumnEnumerator(columnIndex) available. This could actually be implemented quite easily on our side, also for sparse matrices.
  • Access the compressed row storage directly, by casting matrix.Storage to SparseCompressedRowMatrixStorage<T> (possible since v2.2.1)

Please reopen if this doesn't work for you

@cdrnet cdrnet closed this as completed Aug 29, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants