Skip to content

Commit a0e1847

Browse files
authored
Merge pull request #3 from gridap/add/Idx-based_SparseMatrixCSR
Add idx-based SparseMatrixCSR
2 parents 05cf781 + 2bb01fa commit a0e1847

9 files changed

+461
-94
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "SparseMatricesCSR"
22
uuid = "a0a7dd2c-ebf4-11e9-1f05-cf50bc540ca1"
33
authors = ["Víctor Sande <[email protected]>"]
4-
version = "0.3.1"
4+
version = "0.4.0"
55

66
[deps]
77
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

README.md

-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ Compressed Sparse Row (CSR) sparse matrix implementations.
99

1010
It includes `SparseMatrixCSR` and `SymSparseMatrixCSR` wrappers.
1111

12-
CSR wrappers relies on `SparseMatrixCSC` native Julia type.
13-
1412
## Basic Usage
1513

1614
```julia

src/SparseMatricesCSR.jl

+33-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,44 @@
1+
"""
2+
This module contains:
3+
4+
- Data types:
5+
+ `SparseMatrixCSR`:Compressed Sparse Row (CSR) sparse matrix implementation with Bi-based indexing.
6+
+ `SymSparseMatrixCSR`: Symmetric Compressed Sparse Row sparse matrix implementation with Bi-based indexing.
7+
8+
- Procedures:
9+
+ `push_coo!`: Helper function to build COO arrays for further building a SparseMatrix
10+
+ `finalize_coo!`: Finalization of COO arrays building.
11+
+ `sparsecsr`: Analogous method to [`sparse`](@ref) function to build a SparseMatrixCSR.
12+
+ `symsparsecsr`: Analogous method to [`sparse`](@ref) function to build a SymSparseMatrixCSR.
13+
+ `colvals`: Analogous method to [`rowvals`](@ref) to return `colvals` array.
14+
+ `hasrowmajororder`: Return `true` if matrix values are ordered by row.
15+
+ `hascolmajororder`: Return `true` if matrix values are ordered by column.
16+
+ `getptr`: Return the pointer array of a SparseMatrix (`rowptr` or `colptr` depending on the SparseMatrix type)
17+
+ `getindices`: Return the indices array of a SparseMatrix (`rowval` or `colval` depending on the SparseMatrix type)
18+
19+
- Overloaded procedures:
20+
+ `*`: SparseMatrix-Vector product.
21+
+ `mul!`: SparseMatrix-Vector product.
22+
+ `nnz`: Return the number of stored (filled) elements in a sparse array.
23+
+ `nonzeros`: Return `nzval` array.
24+
+ `nzrange`: Return the range of indices for a particular row or column (Depending on the SparseMatrix type)
25+
+ `findnz`: Return a tuple (I, J, V) where I and J are the row and column indices.
26+
+ `rowvals`: Return row indices or raises an error (Depending on the SparseMatrix type)
27+
28+
"""
129
module SparseMatricesCSR
230

331
using SparseArrays
432
using LinearAlgebra
533

6-
import Base: size, getindex, show, count
7-
import SparseArrays: nnz, getnzval, nzvalview, nonzeros, nzrange, findnz
34+
import Base: size, getindex, show, count, *
35+
import LinearAlgebra: mul!
36+
import SparseArrays: nnz, getnzval, nonzeros, nzrange, findnz, rowvals
837

938
export SparseMatrixCSR
1039
export SymSparseMatrixCSR
11-
export push_coo!, finalize_coo!, sparsecsr, symsparsecsr, getrowptr, getcolval
40+
export push_coo!, finalize_coo!, sparsecsr, symsparsecsr, colvals
41+
export hasrowmajororder, hascolmajororder, getptr, getindices
1242

1343
include("SparseMatrixCSC.jl")
1444
include("SparseMatrixCSR.jl")

src/SparseMatrixCSC.jl

+36-1
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,43 @@ end
2727
"""
2828
function finalize_coo!(I,J,V,m,n)
2929
30-
Check and insert diagonal entries in COO vectors if needed.
30+
Finalize COO arrays for building a SparseMatrixCSC.
3131
"""
3232
function finalize_coo!(I::Vector,J::Vector,V::Vector,m::Integer,n::Integer)
3333
finalize_coo!(SparseMatrixCSC,I,J,V,m,n)
3434
end
35+
36+
37+
"""
38+
function hasrowmajororder(::Type{SparseMatrixCSC})
39+
40+
Check if values are stored in row-major order.
41+
Return false.
42+
"""
43+
hasrowmajororder(::Type{SparseMatrixCSC}) = false
44+
hasrowmajororder(a::SparseMatrixCSC) = hasrowmajororder(SparseMatrixCSC)
45+
46+
"""
47+
function hascolmajororder(::Type{SparseMatrixCSC})
48+
49+
Check if values are stored in col-major order.
50+
Return true.
51+
"""
52+
hascolmajororder(::Type{SparseMatrixCSC}) = true
53+
hascolmajororder(a::SparseMatrixCSC) = hascolmajororder(SparseMatrixCSC)
54+
55+
"""
56+
function getptr(S::SparseMatrixCSC)
57+
58+
Return columns pointer.
59+
"""
60+
getptr(S::SparseMatrixCSC) = S.colptr
61+
62+
"""
63+
function getvals(S::SparseMatrixCSC)
64+
65+
Return row indices.
66+
"""
67+
getindices(S::SparseMatrixCSC) = rowvals(S)
68+
69+

0 commit comments

Comments
 (0)