Skip to content

Commit b5a9589

Browse files
committed
Added Caveat and more discussion context to README.
1 parent 6a58169 commit b5a9589

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
Sparse matrix class with efficient successive insertion of entries and entry update.
1010

11+
## Rationale
1112
Without an intermediate data structure, efficient successive insertion/update of possibly duplicate entries in random order into a standard compressed column storage structure appears to be not possible. The package introduces `ExtendableSparseMatrix`, a delegating wrapper containing a Julia standard `SparseMatrixCSC` struct for performing linear algebra operations and a `SparseMatrixLNK` struct realising a linked list based (but realised in vectors) format collecting new entries.
1213

1314
The later is modeled after the linked list sparse matrix format described in the [whitepaper](https://www-users.cs.umn.edu/~saad/software/SPARSKIT/paper.ps) by Y. Saad. See also exercise P.3-16 in his [book](https://www-users.cs.umn.edu/~saad/IterMethBook_2ndEd.pdf).
@@ -16,6 +17,14 @@ Any linear algebra method on `ExtendableSparseMatrix` starts with a `flush!` met
1617

1718
`ExtendableSparseMatrix` is aimed to work as a drop-in replacement to `SparseMatrixCSC` in finite element and finite volume codes especally in those cases where the sparsity structure is hard to detect a priori and where working with an intermediadte COO representation appears to be not convenient.
1819

20+
## Caveat
21+
22+
This package assumes that a $m \times n$ matrix is sparse if *each* row and *each* column have less than $C$ entries with
23+
$C << n$ and $C <<m$ . Adding a full matrix row will be a performance hit.
24+
25+
26+
## Working with ForwardDiff
27+
1928
In particular, it cooperates with [ForwardDiff.jl](https://github.com/JuliaDiff/ForwardDiff.jl) when it comes to the assembly of a sparse jacobian. For a function 'f!(y,x)' returning it's result in a vector `y`, one can use e.g.
2029
````
2130
x=...
@@ -26,6 +35,10 @@ jac=DiffResults.jacobian(dresult)
2635
h=jac\x
2736
````
2837

38+
However, without a priori information on sparsity, ForwardDiff calls element insertion for the full range of n^2 indices,
39+
leading to a O(n^2) scaling behavior due to the nevertheless necessary search operations, see this [discourse thread](https://discourse.julialang.org/t/non-sorted-sparsematrixcsc/37133).
40+
41+
## updateindex!
2942
In addition, the package provides a method `updateindex!(A,op,v,i,j)` for both `SparseMatrixCSC` and for `ExtendableSparse` which allows to update a matrix element with one index search instead of two. It allows to replace e.g. `A[i,j]+=v` by `updateindex!(A,+,v,i,j)`. The former operation is lowered to
3043
````
3144
%1 = Base.getindex(A, 1, 2)
@@ -34,6 +47,8 @@ Base.setindex!(A, %2, 1, 2)
3447
````
3548
triggering two index searches, one for `getindex!` and another one for `setindex!`.
3649

50+
See [Julia issue #15630](https://github.com/JuliaLang/julia/issues/15630) for a discussion on this.
51+
3752

3853

3954

0 commit comments

Comments
 (0)