Skip to content

Commit d62ad5e

Browse files
author
Wimmerer
committed
Docs and Fixes
1 parent 9ec792c commit d62ad5e

25 files changed

+435
-125
lines changed

Project.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@ version = "0.4.0"
55

66
[deps]
77
CEnum = "fa961155-64e5-5f13-b03f-caf6b980ea82"
8-
ChainRules = "082447d4-558c-5d27-93f4-14fc19e9eca2"
9-
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
10-
ChainRulesTestUtils = "cdddcdb0-9152-4a09-a978-84456f9df70a"
118
ContextVariablesX = "6add18c4-b38d-439d-96f6-d6bc489c04c5"
12-
Latexify = "23fbe1c1-3f47-55db-b15f-69d7ec21a316"
139
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
1410
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1511
MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"

docs/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[deps]
22
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
33
Latexify = "23fbe1c1-3f47-55db-b15f-69d7ec21a316"
4-
SuiteSparseGraphBLAS = "c2e53296-7b14-11e9-1210-bddfa8111e1d"
4+
SuiteSparseGraphBLAS = "c2e53296-7b14-11e9-1210-bddfa8111e1d"

docs/make.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Documenter
22
using SuiteSparseGraphBLAS
33
using LinearAlgebra
4+
using SparseArrays
45
makedocs(
56
modules = [SuiteSparseGraphBLAS],
67
sitename="SuiteSparseGraphBLAS.jl",
@@ -9,6 +10,7 @@ makedocs(
910
"Arrays" => "arrays.md",
1011
"Operations" => "operations.md",
1112
"Operators" => [
13+
"operators.md",
1214
"unaryops.md",
1315
"binaryops.md",
1416
"monoids.md",

docs/src/arrays.md

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,74 @@
11
# GBArrays
22

3-
## Construction
3+
There are two datastructures in in `SuiteSparseGraphBLAS.jl`: the `GBVector` and `GBMatrix`.
4+
5+
Both types currently implement most of the `AbstractArray` interface and part of the `SparseArrays`
6+
interface.
7+
The goal is to cover the entirety of both (applicable) interfaces as well as `ArrayInterface.jl`
8+
with the `v1.0` release.
9+
10+
Most functions accept either type, which is represented by the union
11+
`GBArray = {GBVector, GBMatrix, Transpose{<:Any, <:GBMatrix}}`.
12+
13+
## Matrix Construction
14+
```@setup mat
15+
using SuiteSparseGraphBLAS
16+
using SparseArrays
17+
```
18+
```@repl mat
19+
x = GBMatrix{Bool}(20_000_000, 50_000)
20+
x = GBMatrix([[1,2] [3,4]])
21+
x = GBMatrix(sprand(100, 100, 0.5))
22+
x = GBMatrix(rand(1:50_000, 5000), rand(1:500_000, 5000), 1; ncols = 500_000, nrows = 500_000)
23+
```
24+
25+
```@docs
26+
GBMatrix
27+
SuiteSparseGraphBLAS.GBMatrix(::Matrix)
28+
SuiteSparseGraphBLAS.GBMatrix(::SparseMatrixCSC)
29+
```
30+
Conversion back to matrices, sparse or dense, is also supported.
31+
## Vector Construction
32+
```@repl mat
33+
v = GBVector{ComplexF32}(100)
34+
v = GBMatrix(rand(ComplexF64, 3))
35+
v = GBVector(sprand(Bool, 100_000_000, 0.001))
36+
```
37+
38+
```@docs
39+
GBVector
40+
SuiteSparseGraphBLAS.GBVector{T}()
41+
SuiteSparseGraphBLAS.GBVector(::Vector, ::Vector)
42+
SuiteSparseGraphBLAS.GBVector(::SparseVector)
43+
```
44+
45+
# Indexing
46+
47+
The usual AbstractArray and SparseArray indexing should work here. Including indexing by scalars, vectors, and ranges.
48+
49+
!!! danger "Indexing Structural Zeros"
50+
When you index a `SparseMatrixCSC` from `SparseArrays` and hit a structural zero (a value within the dimensions of the matrix but not stored) you can expect a `zero(T)`.
51+
52+
When you index a GBArray you will get `nothing` when you hit a structural zero. This is because the zero in GraphBLAS depends not just on the domain of the elements but also on what you are __doing__ with them. For instance with an element type of `Float64` you could want the zero to be `0.0`, `-∞` or `+∞`.
53+
54+
We'll use the small matrix from the Introduction to illustrate the indexing capabilities. We will also use `SparseArrays.SparseMatrixCSC` for the pretty printing functionality, which should be available in this package in `v1.0`.
55+
56+
```@repl mat
57+
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...])
58+
SparseMatrixCSC(A)
59+
A[4]
60+
A[1,2]
61+
A[[1,3,5,7], :]
62+
A[1:2:7, :]
63+
A[:,:]
64+
A[:, 5]
65+
SparseMatrixCSC(A[:,:, desc=Descriptors.T0]) #Transpose the first argument
66+
```
67+
68+
All of this same functionality exists for vectors in 1-dimension.
69+
70+
# Utilities
71+
72+
```@docs
73+
clear!
74+
```

docs/src/binaryops.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
# Binary Operators
22

3+
Binary operators are defined on three domains $D_1 \times D_2 \rightarrow D_3$.
4+
However, the vast majority of binary operators are defined on a single domain.
5+
36
## Built-Ins
47

8+
All built-in binary oeprators can be found in the `BinaryOps` submodule.
9+
10+
The documentation below uses `T` to refer to any of the valid primitive types listed in [Supported Types](@ref), `` to refer to integers (signed and unsigned), `F` to refer to floating point types, `` to refer to real numbers (non-complex numbers).
11+
512
```@autodocs
613
Modules = [SuiteSparseGraphBLAS]
714
Pages = ["binaryops.jl"]

docs/src/index.md

Lines changed: 22 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
# SuiteSparseGraphBLAS.jl
22

3-
SuiteSparseGraphBLAS.jl is a WIP package for sparse linear algebra on arbitrary semirings, with a particular focus on graph computations.
3+
SuiteSparseGraphBLAS.jl is a package for sparse linear algebra on arbitrary semirings, with a particular focus on graph computations.
44
It aims to provide a Julian wrapper over Tim Davis' SuiteSparse reference implementation of the GraphBLAS C specification.
55

66
# Roadmap
77

8+
!!! note
9+
This library is still very WIP, if you are missing any functionality, or find any incorrectly implemented functions from those interfaces please open an issue or PR!
10+
811
While the core library is mostly complete, and all GraphBLAS functionality is present, there are still quite a few features being worked on for v1.0:
912

1013
1. ChainRules.jl integration for AD.
1114
2. Complete SparseArrays and ArrayInterface interfaces.
12-
3. Printing v2.
13-
4. User-defined types and functions.
15+
3. Fancy printing
16+
4. User-defined types.
1417
5. Alternative syntax for GraphBLAS ops (currently must use `BinaryOps.PLUS` instead of `+`).
15-
6. Complex builtins.
1618

1719
Once these are completed there will be a v1.0 release, with the goal being JuliaCon 2021.
1820

@@ -23,16 +25,12 @@ Post 1.0 goals include:
2325
3. More efficient import and export between Julia and GraphBLAS
2426
4. Support for other GraphBLAS implementations in a follow-up GraphBLAS.jl
2527

26-
!!! danger "Printing"
27-
28-
Printing is done directly by GraphBLAS in this release. This means printed indices are 0-based, and the displayed type is the equivalent C type. The v1.0 release will alleviate this issue.
29-
3028
# Installation
3129

3230
Install using the Julia package manager in the REPL:
3331

3432
```
35-
] add SuiteSparseGraphBLAS#master
33+
] add SuiteSparseGraphBLAS
3634
```
3735

3836
or with `Pkg`
@@ -62,13 +60,15 @@ The three primary components of GraphBLAS are: matrices, operators, and operatio
6260

6361
SuiteSparseGraphBLAS.jl provides `GBVector` and `GBMatrix` array types which are subtypes of `SparseArrays.AbstractSparseVector` and `SparseArrays.AbstractSparseMatrix` respectively. Both can be constructed with no arguments to use the maximum size.
6462

65-
```julia
66-
julia> GBVector{Float64}()
67-
1152921504606846976x1 GraphBLAS double vector, sparse by col
68-
no entries
63+
```@setup intro
64+
using SuiteSparseGraphBLAS
65+
using SparseArrays
66+
```
67+
68+
```@repl intro
69+
GBVector{Float64}()
6970
70-
1152921504606846976x1152921504606846976 GraphBLAS int8_t matrix, hypersparse by col
71-
no entries
71+
GBMatrix{ComplexF64}()
7272
```
7373

7474
GraphBLAS array types are opaque to the user in order to allow the library author to choose the best storage format.
@@ -77,29 +77,10 @@ SuiteSparseGraphBLAS.jl sets the default to column major to ensure fast imports
7777

7878
A complete list of construction methods can be found in [Construction](@ref), but the matrix and vector above can be constructed as follows:
7979

80-
```julia
81-
julia> 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...])
82-
7x7 GraphBLAS int64_t matrix, bitmap by col
83-
12 entries
84-
85-
(3,0) 6
86-
(0,1) 1
87-
(3,2) 7
88-
(5,2) 9
89-
(6,2) 10
90-
(0,3) 2
91-
(6,3) 11
92-
(1,4) 3
93-
(6,4) 12
94-
(2,5) 5
95-
(4,5) 8
96-
(1,6) 4
80+
```@repl intro
81+
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...])
9782
9883
v = GBVector([4], [10])
99-
4x1 GraphBLAS int64_t vector, bitmap by col
100-
1 entry
101-
102-
(3,0) 10
10384
```
10485
## GraphBLAS Operations
10586

@@ -125,49 +106,6 @@ GraphBLAS operations are, where possible, methods of existing Julia functions l
125106

126107
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.
127108

128-
### Common arguments
129-
130-
The operations above have often accept most or all of the following arguments.
131-
132-
#### `op` - `UnaryOp`, `BinaryOp`, `Monoid`, `Semiring`, or `SelectOp`:
133-
134-
This is the most important argument for most of these operations. It determines ``\oplus``, ``\otimes``, or ``f`` in the table above as well as the semiring used in `mul`.
135-
Most operations are restricted to one type of operator.
136-
137-
!!! tip "Built-Ins"
138-
The built-in operators can be found in the submodules: `UnaryOps`, `BinaryOps`, `Monoids`, and `Semirings`.
139-
140-
#### `desc` - `Descriptor`:
141-
142-
The descriptor argument allows the user to modify the operation in some fashion. The most common options are:
143-
144-
- `desc.[input1 | input2] == [DEFAULT | TRANSPOSE]`
145-
146-
Transposes the inputs and can be found in `Descriptors.[T0 | T1 | T0T1]`.
147-
Typically you should use Julia's built-in transpose functionality.
148-
149-
- `desc.mask == [DEFAULT | STRUCTURE | COMPLEMENT | STRUCT_COMP]`
150-
151-
If `STRUCTURE` is set the operation will use the presence of a value rather than the value itself to determine whether the index is masked.
152-
If `COMPLEMENT` is set the presence/truth value is complemented (ie. if **no** value is present or the value is **false** that index is masked).
153-
154-
- `desc.output == [DEFAULT | REPLACE]`
155-
156-
If `REPLACE` is set the operation will replace all values in the output matrix **after** the accumulation step.
157-
If an index is found in the output matrix, but not in the results of the operation it will be set to `nothing`.
158-
159-
160-
#### `accum` - `BinaryOp`:
161-
162-
The `accum` keyword argument provides a binary operation to accumulate results into the result array.
163-
The accumulation step is performed **before** masking.
164-
165-
#### `mask` - `GBArray`:
166-
167-
The `mask` keyword argument determines whether each index from the result of an operation appears in the output.
168-
The mask may be structural, where the presence of a value indicates the mask is `true`, or valued where the value of the mask indicates its truth value.
169-
The mask may also be complemented. These options are controlled by the `desc` argument.
170-
171109
## GraphBLAS Operators
172110

173111
GraphBLAS operators are one of the following:
@@ -180,7 +118,7 @@ GraphBLAS operators are one of the following:
180118
Built-in operators can be found in exported submodules:
181119

182120
```julia
183-
julia> BinaryOps.
121+
julia> BinaryOps.\TAB
184122

185123
ANY BSET DIV FIRSTJ1 ISGE LDEXP MIN RDIV SECONDJ
186124
ATAN2 BSHIFT EQ FMOD ISGT LE MINUS REMAINDER SECONDJ1
@@ -198,7 +136,7 @@ The methods are drawn from the LAGraph [repo](https://github.com/GraphBLAS/LAGra
198136
Input `A` must be a square, symmetric matrix with any element type.
199137
We'll test it using the matrix from the GBArray section above, which has two triangles in its undirected form.
200138

201-
```julia
139+
```@repl intro
202140
function cohen(A)
203141
U = select(SelectOps.TRIU, A)
204142
L = select(SelectOps.TRIL, A)
@@ -211,6 +149,6 @@ function sandia(A)
211149
end
212150
213151
M = eadd(A, A', BinaryOps.PLUS) #Make undirected/symmetric
214-
cohen(A) # 2
215-
sandia(A) # 2
216-
```
152+
cohen(M)
153+
sandia(M)
154+
```

docs/src/monoids.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
# Monoids
2-
## About
32

43
A monoid is made up of a set or domain $T$ and a binary operator $z = f(x, y)$ operating on the same domain, $T \times T \rightarrow T$.
54
This binary operator must be associative, that is $f(a, f(b, c)) = f(f(a, b), c)$ is always true. Associativity is important for operations like `reduce` and the multiplication step of `mul`.
65

7-
The operator must also be equipped with an identity such that $f(x, 0) = f(0, x) = x$. Some monoids are equipped with a terminal or annihilator such that $z = f(z, x) \forall x$.
6+
The operator is also be equipped with an identity such that $f(x, 0) = f(0, x) = x$. Some monoids are equipped with a terminal or annihilator such that $z = f(z, x) \forall x$.
7+
8+
Monoids are used primarily in the `reduce`(@ref) operation. Their other use is as a component of semirings in the [`mul`](@ref) operation.
89

910
## Built-Ins
11+
12+
All built-in monoids can be found in the `Monoids` submodule.
13+
14+
The documentation below uses `T` to refer to any of the valid primitive types listed in [Supported Types](@ref), `` to refer to integers (signed and unsigned), `F` to refer to floating point types, `` to refer to real numbers (non-complex numbers).
15+
1016
!!! note "Note"
1117
In the case of floating point numbers +∞ and -∞ have their typical meanings. However, for integer types they indicate `typemax` and `typemin` respectively.
1218

docs/src/operations.md

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,49 @@ where ``\bf M`` is a `GBArray` mask, ``\odot`` is a binary operator for accumula
2626
!!! note "assign vs subassign"
2727
`subassign` is equivalent to `assign` except that the mask in `subassign` has the dimensions of ``\bf C(I,J)`` vs the dimensions of ``C`` for `assign`, and elements outside of the mask will never be modified by `subassign`. See the [GraphBLAS User Guide](https://github.com/DrTimothyAldenDavis/GraphBLAS/blob/stable/Doc/GraphBLAS_UserGuide.pdf) for more details.
2828

29+
## Common arguments
30+
31+
The operations above have often accept most or all of the following arguments.
32+
33+
### `op` - `UnaryOp`, `BinaryOp`, `Monoid`, `Semiring`, or `SelectOp`:
34+
35+
This is the most important argument for most of these operations. It determines ``\oplus``, ``\otimes``, or ``f`` in the table above as well as the semiring used in `mul`.
36+
Most operations are restricted to one type of operator.
37+
38+
!!! tip "Built-Ins"
39+
The built-in operators can be found in the submodules: `UnaryOps`, `BinaryOps`, `Monoids`, and `Semirings`.
40+
41+
### `desc` - `Descriptor`:
42+
43+
The descriptor argument allows the user to modify the operation in some fashion. The most common options are:
44+
45+
- `desc.[input1 | input2] == [DEFAULT | TRANSPOSE]`
46+
47+
Transposes the inputs and can be found in `Descriptors.[T0 | T1 | T0T1]`.
48+
Typically you should use Julia's built-in transpose functionality.
49+
50+
- `desc.mask == [DEFAULT | STRUCTURE | COMPLEMENT | STRUCT_COMP]`
51+
52+
If `STRUCTURE` is set the operation will use the presence of a value rather than the value itself to determine whether the index is masked.
53+
If `COMPLEMENT` is set the presence/truth value is complemented (ie. if **no** value is present or the value is **false** that index is masked).
54+
55+
- `desc.output == [DEFAULT | REPLACE]`
56+
57+
If `REPLACE` is set the operation will replace all values in the output matrix **after** the accumulation step.
58+
If an index is found in the output matrix, but not in the results of the operation it will be set to `nothing`.
59+
60+
61+
### `accum` - `BinaryOp`:
62+
63+
The `accum` keyword argument provides a binary operation to accumulate results into the result array.
64+
The accumulation step is performed **before** masking.
65+
66+
### `mask` - `GBArray`:
67+
68+
The `mask` keyword argument determines whether each index from the result of an operation appears in the output.
69+
The mask may be structural, where the presence of a value indicates the mask is `true`, or valued where the value of the mask indicates its truth value.
70+
The mask may also be complemented. These options are controlled by the `desc` argument.
71+
2972
## Order of Operations
3073

3174
A GraphBLAS operation occurs in the following order (steps are skipped when possible):
@@ -38,15 +81,20 @@ If `REPLACE` is set the option in step 3. is `nothing`, otherwise it is `C[i,j]`
3881

3982
## Operation Documentation
4083

84+
All non-mutating operations below support a mutating form by adding an output array as the first argument as well as the `!` function suffix.
85+
86+
### `mul`
4187
```@docs
4288
mul
89+
```
90+
91+
```@docs
4392
emul
4493
eadd
4594
extract
46-
extract!
4795
subassign!
4896
assign!
49-
Base.map(::SuiteSparseGraphBLAS.AbstractOp, ::SuiteSparseGraphBLAS.GBArray, ::Any)
97+
Base.map
5098
select
5199
Base.reduce
52100
gbtranspose

0 commit comments

Comments
 (0)