Skip to content

Commit 214b015

Browse files
author
Will Kimmerer
committed
reorg, docs changes
1 parent efff99a commit 214b015

File tree

8 files changed

+282
-283
lines changed

8 files changed

+282
-283
lines changed

docs/src/arrays.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# GBArrays
1+
# Array Types
22

33
There are two primary datastructures in in `SuiteSparseGraphBLAS.jl`: the `GBVector` and `GBMatrix`.
44

@@ -41,9 +41,11 @@ SuiteSparseGraphBLAS.GBVector(::AbstractVector{<:Integer}, ::AbstractVector)
4141
Normal AbstractArray and SparseArray indexing should work here. Including indexing by scalars, vectors, and ranges.
4242

4343
!!! danger "Indexing Structural Zeros"
44-
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)`.
44+
When indexing a `SparseMatrixCSC` from `SparseArrays` a structural, or implicit, zero will be returned as `zero(T)` where `T` is the elemtn type of the matrix.
4545

46-
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 `+∞`.
46+
When indexing a GBArray a structural zero is instead returned as `nothing`. While this is a significant departure from the `SparseMatrixCSC` it more closely matches the GraphBLAS spec, and enables the consuming method to determine the value of implicit zeros.
47+
48+
For instance with an element type of `Float64` you may want the zero to be `0.0`, `-∞` or `+∞` depending on your algorithm. In addition, for graph algorithms there may be a distinction between an implicit zero, indicating the lack of an edge between two vertices in an adjacency matrix, and an explicit zero where the edge exists but has a `0` weight.
4749

4850
```@repl mat
4951
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...])
@@ -57,15 +59,12 @@ A[:, 5]
5759
SparseMatrixCSC(A'[:,:]) #Transpose the first argument
5860
```
5961

60-
All of this same functionality exists for vectors in 1-dimension.
62+
The functionality illustrated above extends to `GBVector` as well.
6163

6264
# Transpose
6365
The lazy Julia `transpose` is available, and the adjoint operator `'` is also
6466
overloaded to be equivalent.
6567

66-
`x = A'` will create a `Transpose` wrapper.
67-
When an operation uses this argument it will cause the `desc` to set `INP<0|1> = T_<0|1>`.
68-
6968
# Utilities
7069

7170
```@docs

docs/src/operations.md

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,23 @@ 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+
### `mul`
30+
```@docs
31+
mul
32+
emul
33+
emul!
34+
eadd
35+
eadd!
36+
extract
37+
subassign!
38+
assign!
39+
Base.map
40+
select
41+
Base.reduce
42+
gbtranspose
43+
LinearAlgebra.kron
44+
```
45+
2946
## Common arguments
3047

3148
The operations above have often accept most or all of the following arguments.
@@ -83,20 +100,4 @@ If `REPLACE` is set the option in step 3. is `nothing`, otherwise it is `C[i,j]`
83100

84101
All non-mutating operations below support a mutating form by adding an output array as the first argument as well as the `!` function suffix.
85102

86-
### `mul`
87-
```@docs
88-
mul
89-
```
90103

91-
```@docs
92-
emul
93-
eadd
94-
extract
95-
subassign!
96-
assign!
97-
Base.map
98-
select
99-
Base.reduce
100-
gbtranspose
101-
LinearAlgebra.kron
102-
```

src/SuiteSparseGraphBLAS.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ include("indexutils.jl")
5555
# Globals
5656
include("constants.jl")
5757

58+
59+
include("operations/extract.jl")
5860
include("scalar.jl")
5961
include("vector.jl")
6062
include("matrix.jl")

src/matrix.jl

Lines changed: 6 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -230,142 +230,7 @@ SparseArrays.nonzeros(A::GBArray) = findnz(A)[end]
230230

231231
# Indexing functions
232232
####################
233-
"""
234-
_outlength(A, I, J)
235-
_outlength(u, I)
236-
Determine the size of the output for an operation like extract or range-based indexing.
237-
"""
238-
function _outlength(A, I, J)
239-
if I == ALL
240-
Ilen = size(A, 1)
241-
else
242-
Ilen = length(I)
243-
end
244-
if J == ALL
245-
Jlen = size(A, 2)
246-
else
247-
Jlen = length(J)
248-
end
249-
return Ilen, Jlen
250-
end
251-
252-
"""
253-
extract!(C::GBMatrix, A::GBMatrix, I, J; kwargs...)::GBMatrix
254-
255-
Extract a submatrix from `A` into `C`.
256-
257-
# Arguments
258-
- `C::GBMatrix`: the submatrix extracted from `A`. It is a dimension mismatch if
259-
`size(C) != (max(I), max(J))`.
260-
- `A::GBMatrix`: the array being indexed.
261-
- `I` and `J`: A colon, scalar, vector, or range indexing A.
262-
263-
# Keywords
264-
- `mask::Union{Nothing, GBMatrix} = nothing`: mask where
265-
`size(M) == (max(I), max(J))`.
266-
- `accum::Union{Nothing, AbstractBinaryOp} = nothing`: binary accumulator operation
267-
where `C[i,j] = accum(C[i,j], T[i,j])` where T is the result of this function before accum is applied.
268-
- `desc::Descriptor = nothing`
269-
270-
# Returns
271-
- `GBMatrix`: the modified matrix `C`, now containing the submatrix `A[I, J]`.
272-
273-
# Throws
274-
- `GrB_DIMENSION_MISMATCH`: If `size(C) != (max(I), max(J))` or `size(C) != size(mask)`.
275-
"""
276-
function extract!(
277-
C::GBMatrix, A::GBMatOrTranspose, I, J;
278-
mask = nothing, accum = nothing, desc = nothing
279-
)
280-
I, ni = idx(I)
281-
J, nj = idx(J)
282-
I isa Number && (I = UInt64[I])
283-
J isa Number && (J = UInt64[J])
284-
mask === nothing && (mask = C_NULL)
285-
desc = _handledescriptor(desc; in1 = A)
286-
libgb.GrB_Matrix_extract(C, mask, getaccum(accum, eltype(C)), parent(A), I, ni, J, nj, desc)
287-
return C
288-
end
289-
290-
function extract!(
291-
C::GBMatrix, A::GBMatOrTranspose, ::Colon, J;
292-
mask = nothing, accum = nothing, desc = nothing
293-
)
294-
return extract!(C, A, ALL, J; mask, accum, desc)
295-
end
296-
297-
function extract!(
298-
C::GBMatrix, A::GBMatOrTranspose, I, ::Colon;
299-
mask = nothing, accum = nothing, desc = nothing
300-
)
301-
return extract!(C, A, I, ALL; mask, accum, desc)
302-
end
303-
304-
function extract!(
305-
C::GBMatrix, A::GBMatOrTranspose, ::Colon, ::Colon;
306-
mask = nothing, accum = nothing, desc = nothing
307-
)
308-
return extract!(C, A, ALL, ALL; mask, accum, desc)
309-
end
310-
311-
"""
312-
extract(A::GBMatrix, I, J; kwargs...)::GBMatrix
313-
314-
Extract a submatrix from `A`.
315-
316-
# Arguments
317-
- `A::GBMatrix`: the array being indexed.
318-
- `I` and `J`: A colon, scalar, vector, or range indexing A.
319-
320-
# Keywords
321-
- `mask::Union{Nothing, GBMatrix} = nothing`: mask where
322-
`size(M) == (max(I), max(J))`.
323-
- `accum::Union{Nothing, AbstractBinaryOp} = nothing`: binary accumulator operation
324-
where `C[i,j] = accum(C[i,j], T[i,j])` where T is the result of this function before accum is applied. `C` is, however, empty.
325-
- `desc::Descriptor = nothing`
326-
327-
# Returns
328-
- `GBMatrix`: the submatrix `A[I, J]`.
329-
330-
# Throws
331-
- `GrB_DIMENSION_MISMATCH`: If `(max(I), max(J)) != size(mask)`.
332-
"""
333-
function extract(
334-
A::GBMatOrTranspose, I, J;
335-
mask = nothing, accum = nothing, desc = nothing
336-
)
337-
Ilen, Jlen = _outlength(A, I, J)
338-
C = similar(A, Ilen, Jlen)
339-
return extract!(C, A, I, J; mask, accum, desc)
340-
end
341233

342-
function extract(
343-
A::GBMatOrTranspose, ::Colon, J;
344-
mask = nothing, accum = nothing, desc = nothing
345-
)
346-
return extract(A, ALL, J; mask, accum, desc)
347-
end
348-
349-
function extract(
350-
A::GBMatOrTranspose, I, ::Colon;
351-
mask = nothing, accum = nothing, desc = nothing
352-
)
353-
return extract(A, I, ALL; mask, accum, desc)
354-
end
355-
356-
function extract(
357-
A::GBMatOrTranspose, ::Colon, ::Colon;
358-
mask = nothing, accum = nothing, desc = nothing
359-
)
360-
return extract(A, ALL, ALL; mask, accum, desc)
361-
end
362-
363-
function Base.getindex(
364-
A::GBMatOrTranspose, ::Colon, j;
365-
mask = nothing, accum = nothing, desc = nothing
366-
)
367-
return extract(A, ALL, j; mask, accum, desc)
368-
end
369234
function Base.getindex(
370235
A::GBMatOrTranspose, i, ::Colon;
371236
mask = nothing, accum = nothing, desc = nothing
@@ -392,7 +257,7 @@ end
392257
"""
393258
subassign!(C::GBMatrix, A::GBMatrix, I, J; kwargs...)::GBMatrix
394259
395-
Assign a submatrix of `C` to `A`. Equivalent to [`assign!`](@ref) except that
260+
Assign a submatrix of `A` to `C`. Equivalent to [`assign!`](@ref) except that
396261
`size(mask) == size(A)`, whereas `size(mask) == size(C)` in `assign!`.
397262
398263
# Arguments
@@ -403,9 +268,9 @@ Assign a submatrix of `C` to `A`. Equivalent to [`assign!`](@ref) except that
403268
# Keywords
404269
- `mask::Union{Nothing, GBMatrix} = nothing`: mask where
405270
`size(M) == size(A)`.
406-
- `accum::Union{Nothing, AbstractBinaryOp} = nothing`: binary accumulator operation
271+
- `accum::Union{Nothing, Function, AbstractBinaryOp} = nothing`: binary accumulator operation
407272
where `C[i,j] = accum(C[i,j], T[i,j])` where T is the result of this function before accum is applied.
408-
- `desc::Descriptor = nothing`
273+
- `desc::Union{Nothing, Descriptor} = nothing`
409274
410275
# Returns
411276
- `GBMatrix`: The input matrix A.
@@ -439,7 +304,7 @@ end
439304
"""
440305
assign!(C::GBMatrix, A::GBMatrix, I, J; kwargs...)::GBMatrix
441306
442-
Assign a submatrix of `C` to `A`. Equivalent to [`subassign!`](@ref) except that
307+
Assign a submatrix of `A` to `C`. Equivalent to [`subassign!`](@ref) except that
443308
`size(mask) == size(C)`, whereas `size(mask) == size(A) in `subassign!`.
444309
445310
# Arguments
@@ -450,9 +315,9 @@ Assign a submatrix of `C` to `A`. Equivalent to [`subassign!`](@ref) except that
450315
# Keywords
451316
- `mask::Union{Nothing, GBMatrix} = nothing`: mask where
452317
`size(M) == size(C)`.
453-
- `accum::Union{Nothing, AbstractBinaryOp} = nothing`: binary accumulator operation
318+
- `accum::Union{Nothing, Function, AbstractBinaryOp} = nothing`: binary accumulator operation
454319
where `C[i,j] = accum(C[i,j], T[i,j])` where T is the result of this function before accum is applied.
455-
- `desc::Descriptor = nothing`
320+
- `desc::Union{Nothing, Descriptor} = nothing`
456321
457322
# Returns
458323
- `GBMatrix`: The input matrix A.

0 commit comments

Comments
 (0)