Skip to content

Commit cf5f416

Browse files
committed
docs and indexop changes
1 parent 4597922 commit cf5f416

22 files changed

+349
-384
lines changed

docs/make.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Documenter
22
using SuiteSparseGraphBLAS
3+
using SuiteSparseGraphBLAS: UnaryOps, BinaryOps, Monoids, Semirings, GB_KLU, GB_CHOLMOD, GB_UMFPACK
34
using LinearAlgebra
45
using SparseArrays
56
makedocs(

docs/src/api.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
!!! danger "Public vs Private API"
2-
All docstrings are collected on this page. **However**, only assume exported functions and types are part of the public API.
2+
All private docstrings are collected on this page. **However**, only assume exported functions and types are part of the public API.
33

4+
```@docs
5+
SuiteSparseGraphBLAS.gbtype
6+
SuiteSparseGraphBLAS.juliatype
7+
SuiteSparseGraphBLAS.GxBIterator
8+
SuiteSparseGraphBLAS.suffix
9+
SuiteSparseGraphBLAS.idx
10+
SuiteSparseGraphBLAS.GBSparsity
11+
```
412
```@autodocs
5-
Modules = [SuiteSparseGraphBLAS, UnaryOps, BinaryOps, Monoids, Semirings, GB_KLU]
13+
Modules = [LibGraphBLAS]
14+
Public = false
615
```

docs/src/arrays.md

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,30 @@
33
There are two primary array types in SuiteSparseGraphBLAS.jl: [`GBVector`](@ref) and [`GBMatrix`](@ref), as well as a few specialized versions of those array types. The full type hierarchy is:
44

55
```
6-
AbstractGBArray{T, F, N} <: AbstractSparseArray{Union{T, F}, N}
6+
AbstractGBArray{T, F, O, N} <: AbstractSparseArray{Union{T, F}, N}
77
├ N = 2 ─ AbstractGBMatrix{T, F}
8-
│ ├─ GBMatrix{T, F}
9-
│ └─ OrientedGBMatrix{T, F, O}
10-
└ N = 1 ─ AbstractGBVector{T, F}
11-
└─ GBVector{T, F}
8+
│ ├─ GBMatrix{T, F, RuntimeOrder()}
9+
│ ├─ OrientedGBMatrix{T, F, O}
10+
│ └─ GBShallowMatrix{T, F, ColMajor()}
11+
└ N = 1, O = ColMajor() ─ AbstractGBVector{T, F}
12+
├─ GBVector{T, F}
13+
└─ GBShallowVector{T, F}
1214
```
1315

14-
The `T` parameter is the element type of the array, `N` is the dimensionality, `F` is the type of the fill value (often `Nothing` or `T`). The `OrientedGBMatrix` restricts the orientation to the parameter `O` which is either `ByRow()` or `ByCol()`.
16+
The `T` parameter is the element type of the array, `N` is the dimensionality, `F` is the type of the fill value (often `Nothing` or `T`), and `O` is the storage order. The `OrientedGBMatrix` restricts the orientation to the parameter `O` to either `ByRow()` or `ByCol()`.
1517

1618
All of these types attempt to implement most of the `AbstractArray` interface, and the relevant parts of the `SparseArrays` interface.
1719

1820
## GBMatrix
1921

2022
The `GBMatrix` is an opaque sparse matrix structure, which adapts to the sparsity of a matrix by changing the implementation internally. There are 4 different internal representations, all stored in either row or column orientation:
2123

22-
1. **Dense** - Equivalent to a Julia `Matrix`
23-
2. **Bitmap** - 2 dense arrays, one storing booleans in the pattern of the matrix, the other storing the values.
24-
3. **Sparse Compressed** - [Compressed Sparse Column (CSC)](http://netlib.org/linalg/html_templates/node92.html#SECTION00931200000000000000) or [Compressed Sparse Row(CSR)](http://netlib.org/linalg/html_templates/node91.html)
25-
4. **Doubly Compressed** or **Hypersparse** - Doubly Compressed Sparse Column (DCSC or Hypersparse CSC) and Doubly Compressed Sparse Row (DCSR or Hypersparse CSR). See this paper for more information: [pdf](https://people.eecs.berkeley.edu/~aydin/hypersparse-ipdps08.pdf).
24+
1. _**Dense**_ - Equivalent to a Julia `Matrix`, except it may be stored in `RowMajor()` order.
25+
2. _**Bitmap**_ - 2 dense arrays, one storing booleans in the pattern of the matrix, the other storing the values.
26+
3. _**Sparse Compressed**_ - [Compressed Sparse Column (CSC)](http://netlib.org/linalg/html_templates/node92.html#SECTION00931200000000000000) or [Compressed Sparse Row(CSR)](http://netlib.org/linalg/html_templates/node91.html)
27+
4. _**Doubly Compressed**_ or **Hypersparse** - Doubly Compressed Sparse Column (DCSC or Hypersparse CSC) and Doubly Compressed Sparse Row (DCSR or Hypersparse CSR). See this paper for more information: [pdf](https://people.eecs.berkeley.edu/~aydin/hypersparse-ipdps08.pdf).
2628

27-
Additionally, when the stored values in a `GBMatrix` are uniform the value array may be stored in the **iso** version of one of the formats above. Rather than storing the full value array, an iso `GBMatrix` will only store the single scalar to improve performance. This is useful for matrices like the unweighted adjacency matrix, where all stored values may be `true`.
29+
Additionally, when the stored values in a `GBMatrix` are uniform the value array may be stored in the _**iso**_ version of one of the formats above. Rather than storing the full value array, an iso `GBMatrix` will only store the single scalar to improve performance. This is useful for matrices like the unweighted adjacency matrix, where all stored values may be `true`.
2830

2931
Users should rarely need to directly interact with the underlying storage format, SuiteSparse:GraphBLAS will automatically convert between them as necessary.
3032

@@ -40,14 +42,12 @@ x = GBMatrix{Bool}(20_000_000, 50_000)
4042
x = GBMatrix([[1,2] [3,4]])
4143
x = GBMatrix(sprand(100, 100, 0.5); fill = 0.0)
4244
x = GBMatrix(
43-
rand(1:50_000, 5000), rand(1:500_000, 5000), 1,
44-
500_000, 500_000
45+
rand(1:50_000, 5000), rand(1:500_000, 5000), 1, 500_000, 500_000
4546
)
4647
```
4748

4849
```@docs
4950
GBMatrix
50-
SuiteSparseGraphBLAS.GBMatrix(::Matrix)
5151
```
5252

5353
## GBVector
@@ -64,7 +64,6 @@ v = GBVector(sprand(Bool, 100_000_000, 0.001))
6464

6565
```@docs
6666
GBVector
67-
SuiteSparseGraphBLAS.GBVector(::Vector)
6867
```
6968

7069
# Indexing
@@ -97,9 +96,14 @@ The functionality illustrated above extends to `GBVector` as well.
9796

9897
# Transpose
9998
The lazy Julia `transpose` is available, and the adjoint operator `'` is also
100-
overloaded to be equivalent.
99+
overloaded to be equivalent for non-`Complex` types.
101100

102-
!!! danger "Adjoint vs Transpose"
103-
The adjoint operator `'` currently transposes matrices rather than performing the
104-
conjugate transposition. In the future this will change to the eager adjoint
105-
for complex types, but currently you must do `map(conj, A')` to achieve this.
101+
# Special `GBArray` Types
102+
103+
```@docs
104+
GBMatrixR
105+
GBMatrixC
106+
SuiteSparseGraphBLAS.GBShallowMatrix
107+
SuiteSparseGraphBLAS.GBShallowVector
108+
SuiteSparseGraphBLAS.GBScalar
109+
```

docs/src/index.md

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,17 @@ v = GBVector{Float64}(13)
5353
# create a 1000 x 1000 empty sparse matrix with ComplexF64 elements.
5454
A = GBMatrix{ComplexF64}(1000, 1000)
5555
56-
A[1,5] === nothing
56+
# Non-stored values are equal to the fill value of A,
57+
# which is by default zero(eltype(A))
58+
A[1,5] == getfill(A)
5759
```
5860

5961
Here we can already see several differences compared to `SparseArrays.SparseMatrixCSC`.
6062

6163
The first is that `A` is stored in `hypersparse` format, and by row.
6264

6365
`GBArrays` are (technically) opaque to the user in order to allow the library author to choose the best storage format.\
64-
GraphBLAS takes advantage of this by storing matrices in one of four formats: `dense`, `bitmap`, `sparse-compressed`, or `hypersparse-compressed`; and in either `row` or `column` major orientation.\
66+
SuiteSparse:GraphBLAS takes advantage of this by storing matrices in one of four formats: `dense`, `bitmap`, `sparse-compressed`, or `hypersparse-compressed`; and in either `row` or `column` major orientation.\
6567
Different matrices may be better suited to storage in one of those formats, and certain operations may perform differently on `row` or `column` major matrices.
6668

6769
!!! warning "Default Orientation"
@@ -70,18 +72,16 @@ Different matrices may be better suited to storage in one of those formats, and
7072
The orientation of a `GBMatrix` can be modified using
7173
`setstorageorder!(A, RowMajor())` or `setstorageorder!(A, ColMajor())`, and queried by `StorageOrders.storageorder(A)`
7274

73-
Information about storage formats, orientation, conversion, construction and more can be found in [Arrays](@ref).
75+
Information about storage formats, orientation, conversion, construction and more can be found in [Array-Types](@ref).
7476

75-
The second difference is that a `GBArray` doesn't assume the fill-in value of a sparse array.\
76-
Since `A[1,5]` isn't stored in the matrix (it's been "compressed" out), we return `nothing`.\
77-
78-
This better matches the GraphBLAS spec, where `NO_VALUE` is returned, rather than `zero(eltype(A))`. This is better suited to graph algorithms where returning `zero(eltype(A))` might imply the presence of an edge with weight `zero`.\
79-
However this behavior can be changed with the [`setfill!`](@ref) and [`setfill`](@ref) functions.
77+
As noted in the example above, `A` has a fill-value, which defaults to `zero(eltype(A))`.
78+
For normal linear algebra this is a good choice for fill-value, however GraphBLAS is intended for graphs.
79+
To handle this `SuiteSparseGraphBLAS.jl` support `missing` for the fill value (this is an active area of development, and a new fill value that acts like the identity for most operations is better suited to this task).
8080

8181
```@repl intro
82-
A[1, 1] === nothing
82+
A[1, 1] == zero(eltype(A))
8383
84-
B = setfill(A, 0) # no-copy alias
84+
B = setfill(A, missing) # no-copy alias
8585
B[1, 1]
8686
```
8787

@@ -90,30 +90,32 @@ An empty matrix and vector won't do us much good, so let's see how to construct
9090
```@repl intro
9191
A = GBMatrix([1,1,2,2,3,4,4,5,6,7,7,7], [2,4,5,7,6,1,3,6,3,3,4,5], [1:12...])
9292
93-
v = GBVector([4], [10])
93+
v = GBVector([4], [10], 7)
9494
```
9595

9696
## GraphBLAS Operations
9797

9898
The complete documentation of supported operations can be found in [Operations](@ref).
9999
GraphBLAS operations are, where possible, methods of existing Julia functions listed in the third column.
100100

101-
| GraphBLAS | Operation | Julia |
102-
|:--------------------|:----------------------------------------: |----------: |
103-
|`mxm`, `mxv`, `vxm` |``\bf C \langle M \rangle = C \odot AB`` |`mul!` or `*` |
104-
|`eWiseMult` |``\bf C \langle M \rangle = C \odot (A \otimes B)`` |`emul[!]` or `.` broadcasting |
105-
|`eWiseAdd` |``\bf C \langle M \rangle = C \odot (A \oplus B)`` |`eadd[!]` |
106-
|`extract` |``\bf C \langle M \rangle = C \odot A(I,J)`` |`extract[!]`, `getindex` |
107-
|`subassign` |``\bf C (I,J) \langle M \rangle = C(I,J) \odot A`` |`subassign[!]` or `setindex!`|
108-
|`assign` |``\bf C \langle M \rangle (I,J) = C(I,J) \odot A`` |`assign[!]` |
109-
|`apply` |``{\bf C \langle M \rangle = C \odot} f{\bf (A)}`` |`apply[!]`, `map[!]` or `.` broadcasting |
110-
| |``{\bf C \langle M \rangle = C \odot} f({\bf A},y)`` | |
111-
| |``{\bf C \langle M \rangle = C \odot} f(x,{\bf A})`` | |
112-
|`select` |``{\bf C \langle M \rangle = C \odot} f({\bf A},k)`` |`select[!]` |
113-
|`reduce` |``{\bf w \langle m \rangle = w \odot} [{\oplus}_j {\bf A}(:,j)]`` |`reduce[!]` |
114-
| |``s = s \odot [{\oplus}_{ij} {\bf A}(i,j)]`` | |
115-
|`transpose` |``\bf C \langle M \rangle = C \odot A^{\sf T}`` |`gbtranspose[!]`, lazy: `transpose`, `'` |
116-
|`kronecker` |``\bf C \langle M \rangle = C \odot \text{kron}(A, B)`` |`kron[!]` |
101+
| GraphBLAS | Operation | Julia |
102+
|:--------------------|:----------------------------------------: |----------: |
103+
|`mxm`, `mxv`, `vxm` |``\bf C \langle M \rangle = C \odot AB`` |`mul!` or `*` |
104+
|`eWiseMult` |``\bf C \langle M \rangle = C \odot (A \otimes B)`` |`emul[!]` or `.` broadcasting |
105+
|`eWiseAdd` |``\bf C \langle M \rangle = C \odot (A \oplus B)`` |`eadd[!]` |
106+
|`eWiseUnion` |``\bf C \langle M \rangle = C \odot ([ A \vert \alpha ] \oplus [ B \vert \beta ])``|`eunion[!]` |
107+
|`extract` |``\bf C \langle M \rangle = C \odot A(I,J)`` |`extract[!]`, `getindex` |
108+
|`subassign` |``\bf C (I,J) \langle M \rangle = C(I,J) \odot A`` |`subassign[!]` or `setindex!` |
109+
|`assign` |``\bf C \langle M \rangle (I,J) = C(I,J) \odot A`` |`assign[!]` |
110+
|`apply` |``{\bf C \langle M \rangle = C \odot} f{\bf (A)}`` |`apply[!]`, `map[!]` or `.` broadcasting |
111+
| |``{\bf C \langle M \rangle = C \odot} f({\bf A},y)`` | |
112+
| |``{\bf C \langle M \rangle = C \odot} f(x,{\bf A})`` | |
113+
| |``{\bf C \langle M \rangle = C \odot} f({\bf A}_{ij}, i, j, x)`` | |
114+
|`select` |``{\bf C \langle M \rangle = C \odot} f({\bf A}_{ij},i, j, x)`` |`select[!]` |
115+
|`reduce` |``{\bf w \langle m \rangle = w \odot} [{\oplus}_j {\bf A}(:,j)]`` |`reduce[!]` |
116+
| |``s = s \odot [{\oplus}_{ij} {\bf A}(i,j)]`` | |
117+
|`transpose` |``\bf C \langle M \rangle = C \odot A^{\sf T}`` |`gbtranspose[!]`, lazy: `transpose`, `'` |
118+
|`kronecker` |``\bf C \langle M \rangle = C \odot \text{kron}(A, B)`` |`kron[!]` |
117119

118120
where ``\bf M`` is a `GBArray` mask, ``\odot`` is a binary operator for accumulating into ``\bf C``, and ``\otimes`` and ``\oplus`` are a binary operation and commutative monoid respectively. ``f`` is either a unary or binary operator.
119121

@@ -127,18 +129,18 @@ SuiteSparse:GraphBLAS ships with many of the common unary and binary operators a
127129
along with monoids and semirings built commonly used in graph algorithms.
128130
These built-in operators are *fast*, and should be used where possible. However, users are also free to provide their own functions as operators when necessary.
129131

130-
SuiteSparseGraphBLAS.jl will *mostly* take care of operators behind the scenes, and in most cases users should pass in normal functions like `+` and `sin`. For example:
132+
SuiteSparseGraphBLAS.jl will take care of operators behind the scenes, and in most cases users should pass in normal functions like `+` and `sin`. For example:
131133

132134
```@repl intro
133135
emul(A, A, ^) # elementwise exponent
134136
135137
map(sin, A)
136138
```
137139

138-
Broadcasting functionality is also supported, `A .^ A` will lower to `emul(A, A, ^)`, and `sin.(A)` will lower to `map(sin, A)`.
140+
Broadcasting functionality is also supported, `A .^ A` will lower to `emul(A, A, ^)`, and `sin.(A)` will lower to `apply(sin, A)`.
139141

140-
Matrix multiplication, which accepts a semiring, can be called with either `*(max, +)(A, B)` or
141-
`*(A, B, (max, +))`.
142+
Matrix multiplication, which accepts a semiring, can be called with either `*(max, +)(A, B)`,
143+
`*(A, B, (max, +))`, or `LinearAlgebra.mul!(C, A, B, (max, +))`.
142144

143145
We can also use functions that are not already built into SuiteSparseGraphBLAS.jl:
144146

@@ -153,8 +155,8 @@ Compared to `A .+ 1` which lowers to `apply(+, A, 1)` the `map` call above is ~2
153155

154156
!!! warning "Performance of User Defined Functions"
155157
Operators which are not already built-in are automatically constructed using function pointers when called.
156-
Note, however, that their performance is significantly degraded compared to built-in operators,
157-
and where possible user code should avoid this capability. See [Operators](@ref).
158+
Their performance is significantly degraded compared to built-in operators,
159+
and where possible user code should avoid this capability and instead compose built-in operators. See [Operators](@ref).
158160

159161
## Example
160162

docs/src/operations.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,12 @@ Typically you should use Julia's built-in transpose functionality.
4444

4545
- `desc.complement_mask == [true | false]`:
4646

47-
If `complement_mask` is set the presence/truth value of the mask is complemented.
47+
If `complement_mask` is set the presence/truth value of the mask is complemented. See [`SuiteSparseGraphBLAS.Complement`](@ref) for a wrapper that sets this flag.
4848

4949
- `desc.structural_mask == [true | false]`:
5050

5151
If `structural_mask` is set the presence of a value in the mask determines the presence of values in the output, rather than the actual value of the mask.
52+
See [`SuiteSparseGraphBLAS.Structural`](@ref) for a wrapper that sets this flag.
5253

5354
- `desc.replace_output == [true | false]`:
5455

@@ -79,15 +80,23 @@ emul
7980
emul!
8081
eadd
8182
eadd!
83+
eunion
84+
eunion!
8285
extract
86+
extract!
8387
subassign!
8488
assign!
8589
apply
90+
apply!
8691
select
92+
select!
8793
Base.reduce
8894
gbtranspose
95+
gbtranspose!
8996
LinearAlgebra.kron
97+
LinearAlgebra.kron!
9098
mask
99+
mask!
91100
```
92101

93102
## Order of Operations

0 commit comments

Comments
 (0)