|
| 1 | +# SparseArraysBase |
| 2 | + |
| 3 | +Defines a generic interface for sparse arrays in Julia. |
| 4 | + |
| 5 | +The minimal interface is: |
| 6 | +```julia |
| 7 | +nonzeros(a::AbstractArray) = ... |
| 8 | +nonzero_index_to_index(a::AbstractArray, Inz) = ... |
| 9 | +index_to_nonzero_index(a::AbstractArray{<:Any,N}, I::CartesianIndex{N}) where {N} = ... |
| 10 | +Broadcast.BroadcastStyle(arraytype::Type{<:AbstractArray}) = SparseArraysBase.SparseArrayStyle{ndims(arraytype)}() |
| 11 | +``` |
| 12 | +Once these are defined, along with Julia AbstractArray interface functions like |
| 13 | +`Base.size` and `Base.similar`, functions like the following will take advantage of sparsity: |
| 14 | +```julia |
| 15 | +SparseArraysBase.nonzero_length # SparseArrays.nnz |
| 16 | +SparseArraysBase.sparse_getindex |
| 17 | +SparseArraysBase.sparse_setindex! |
| 18 | +SparseArraysBase.sparse_map! |
| 19 | +SparseArraysBase.sparse_copy! |
| 20 | +SparseArraysBase.sparse_copyto! |
| 21 | +SparseArraysBase.sparse_permutedims! |
| 22 | +``` |
| 23 | +which can be used to define the corresponding `Base` functions. |
| 24 | + |
| 25 | +## TODO |
| 26 | +Still need to implement `Base` functions: |
| 27 | +```julia |
| 28 | +[x] sparse_zero(a::AbstractArray) = similar(a) |
| 29 | +[x] sparse_iszero(a::AbstractArray) = iszero(nonzero_length(a)) # Uses `all`, make `sparse_all`? |
| 30 | +[x] sparse_one(a::AbstractArray) = ... |
| 31 | +[x] sparse_isreal(a::AbstractArray) = ... # Uses `all`, make `sparse_all`? |
| 32 | +[x] sparse_isequal(a1::AbstractArray, a2::AbstractArray) = ... |
| 33 | +[x] sparse_conj!(a::AbstractArray) = conj!(nonzeros(a)) |
| 34 | +[x] sparse_reshape(a::AbstractArray, dims) = ... |
| 35 | +[ ] sparse_all(f, a::AbstractArray) = ... |
| 36 | +[ ] sparse_getindex(a::AbstractArray, 1:2, 2:3) = ... # Slicing |
| 37 | +``` |
| 38 | +`LinearAlgebra` functions: |
| 39 | +```julia |
| 40 | +[ ] sparse_mul! |
| 41 | +[ ] sparse_lmul! |
| 42 | +[ ] sparse_ldiv! |
| 43 | +[ ] sparse_rdiv! |
| 44 | +[ ] sparse_axpby! |
| 45 | +[ ] sparse_axpy! |
| 46 | +[ ] sparse_norm |
| 47 | +[ ] sparse_dot/sparse_inner |
| 48 | +[ ] sparse_adoint! |
| 49 | +[ ] sparse_transpose! |
| 50 | + |
| 51 | +# Using conversion to `SparseMatrixCSC`: |
| 52 | +[ ] sparse_qr |
| 53 | +[ ] sparse_eigen |
| 54 | +[ ] sparse_svd |
| 55 | +``` |
| 56 | +`TensorAlgebra` functions: |
| 57 | +```julia |
| 58 | +[ ] add! |
| 59 | +[ ] contract! |
| 60 | +``` |
0 commit comments