Skip to content

Commit dc65766

Browse files
add GraphBLASInterface as dependency & use 0-based indexing in higher-level interface (#7)
* add GraphBLAS interface as dependency * update documentation * use 0-based indexing * update Project.toml * bug fixes
1 parent 98515b4 commit dc65766

29 files changed

+749
-2719
lines changed

Project.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ version = "0.1.0"
55

66
[deps]
77
BinaryProvider = "b99e7846-7c00-51b0-8f62-c81ae34c0232"
8+
GraphBLASInterface = "5f047416-9681-11e9-0804-033d9936201f"
89
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
910
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
1011
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1112

1213
[compat]
13-
julia = "1"
1414
BinaryProvider = "0.5"
15+
julia = "1"

docs/make.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
using Documenter, SuiteSparseGraphBLAS
1+
using Documenter, GraphBLASInterface, SuiteSparseGraphBLAS
22

33
makedocs(
4-
modules = [SuiteSparseGraphBLAS],
4+
modules = [GraphBLASInterface, SuiteSparseGraphBLAS],
55
format = Documenter.HTML(),
66
sitename = "SuiteSparseGraphBLAS",
77
doctest = false,

docs/src/desc_methods.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
## Descriptor methods
22

3-
```@autodocs
4-
Modules = [SuiteSparseGraphBLAS]
5-
Pages = [
6-
"Object_Methods/Descriptor_Methods.jl",
7-
]
8-
Private = false
3+
```@docs
4+
GrB_Descriptor_new
5+
GrB_Descriptor_set
96
```

src/Context_Methods.jl

Lines changed: 2 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,10 @@
1-
import Printf.@printf
1+
import GraphBLASInterface:
2+
GrB_init, GrB_finalize
23

3-
"""
4-
GrB_init(mode)
5-
6-
`GrB_init` must called before any other GraphBLAS operation.
7-
`GrB_init` defines the mode that GraphBLAS will use: blocking or non-blocking.
8-
With blocking mode, all operations finish before returning to the user application.
9-
With non-blocking mode, operations can be left pending, and are computed only when needed.
10-
"""
114
function GrB_init(mode::GrB_Mode)
125
return GrB_Info(ccall(dlsym(graphblas_lib, "GrB_init"), Cint, (Cint, ), mode))
136
end
147

15-
"""
16-
GrB_wait()
17-
18-
`GrB_wait` forces all pending operations to complete.
19-
Blocking mode is as if `GrB_wait` is called whenever a GraphBLAS method or operation returns to the user.
20-
"""
21-
function GrB_wait()
22-
return GrB_Info(ccall(dlsym(graphblas_lib, "GrB_wait"), Cint, (), ))
23-
end
24-
25-
"""
26-
GrB_finalize()
27-
28-
`GrB_finalize` must be called as the last GraphBLAS operation.
29-
`GrB_finalize` does not call `GrB_wait`; any pending computations are abandoned.
30-
"""
318
function GrB_finalize()
329
return GrB_Info(ccall(dlsym(graphblas_lib, "GrB_finalize"), Cint, (), ))
3310
end
34-
35-
"""
36-
GrB_error()
37-
38-
Each GraphBLAS method and operation returns a `GrB_Info` error code.
39-
`GrB_error` returns additional information on the error.
40-
41-
# Examples
42-
```jldoctest
43-
julia> using SuiteSparseGraphBLAS
44-
45-
julia> GrB_init(GrB_NONBLOCKING)
46-
GrB_SUCCESS::GrB_Info = 0
47-
48-
julia> GrB_init(GrB_NONBLOCKING)
49-
GrB_INVALID_VALUE::GrB_Info = 5
50-
51-
julia> GrB_error()
52-
GraphBLAS error: GrB_INVALID_VALUE
53-
function: GrB_init (mode)
54-
GrB_init must not be called twice
55-
```
56-
"""
57-
function GrB_error()
58-
@printf("%s", unsafe_string(ccall(dlsym(graphblas_lib, "GrB_error"), Cstring, (), )))
59-
end

src/Enums.jl

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,6 @@
1-
@enum GrB_Info begin
2-
GrB_SUCCESS = 0 # all is well
3-
GrB_NO_VALUE = 1 # A(ij) requested but not there
4-
5-
# In non-blocking mode these errors are caught right away.
6-
7-
GrB_UNINITIALIZED_OBJECT = 2 # object has not been initialized
8-
GrB_INVALID_OBJECT = 3 # object is corrupted
9-
GrB_NULL_POINTER = 4 # input pointer is NULL
10-
GrB_INVALID_VALUE = 5 # generic error code; some value is bad
11-
GrB_INVALID_INDEX = 6 # a row or column index is out of bounds;
12-
# used for indices passed as scalars not
13-
# in a list.
14-
GrB_DOMAIN_MISMATCH = 7 # object domains are not compatible
15-
GrB_DIMENSION_MISMATCH = 8 # matrix dimensions do not match
16-
GrB_OUTPUT_NOT_EMPTY = 9 # output matrix already has values in it
17-
18-
# In non-blocking mode these errors can be deferred.
19-
20-
GrB_OUT_OF_MEMORY = 10 # out of memory
21-
GrB_INSUFFICIENT_SPACE = 11 # output array not large enough
22-
GrB_INDEX_OUT_OF_BOUNDS = 12 # a row or column index is out of bounds
23-
GrB_PANIC = 13 # SuiteSparse:GraphBLAS only panics if a critical section fails
24-
end
25-
26-
@enum GrB_Mode begin
27-
GrB_NONBLOCKING = 0 # methods may return with pending computations
28-
GrB_BLOCKING = 1 # no computations are ever left pending
29-
end
30-
311
@enum GxB_Print_Level begin
322
GxB_SILENT = 0 # nothing is printed just check the object
333
GxB_SUMMARY = 1 # print a terse summary
344
GxB_SHORT = 2 # short description about 30 entries of a matrix
355
GxB_COMPLETE = 3 # print the entire contents of the object
366
end
37-
38-
@enum GrB_Desc_Field begin
39-
GrB_OUTP = 0 # descriptor for output of a method
40-
GrB_MASK = 1 # descriptor for the mask input of a method
41-
GrB_INP0 = 2 # descriptor for the first input of a method
42-
GrB_INP1 = 3 # descriptor for the second input of a method
43-
end
44-
45-
@enum GrB_Desc_Value begin
46-
# for all GrB_Descriptor fields:
47-
GxB_DEFAULT = 0 # default behavior of the method
48-
# for GrB_OUTP only:
49-
GrB_REPLACE = 1 # clear the output before assigning new values to it
50-
# for GrB_MASK only:
51-
GrB_SCMP = 2 # use the structural complement of the input
52-
# for GrB_INP0 and GrB_INP1 only:
53-
GrB_TRAN = 3 # use the transpose of the input
54-
end

src/Interface/Interface.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
module Interface
22

3-
using SuiteSparseGraphBLAS
3+
using GraphBLASInterface, SuiteSparseGraphBLAS
44

55
import Base:
66
getindex, setindex!, empty!, copy, size, adjoint, ==
77

88
import SuiteSparseGraphBLAS:
9-
GrB_Info, GrB_Index, GrB_Matrix, GrB_Vector, GrB_Descriptor, GrB_Desc_Field, GrB_Desc_Value,
10-
valid_types, get_GrB_Type, default_dup, equal_op
9+
GrB_Info, GrB_Index, GrB_Matrix, GrB_Vector, GrB_Descriptor, GrB_Desc_Field, GrB_Desc_Value
1110

11+
include("Utils.jl")
1212
include("./Object_Methods/Matrix_Methods.jl")
1313
include("./Object_Methods/Vector_Methods.jl")
1414
include("./Object_Methods/Descriptor_Methods.jl")

src/Interface/Object_Methods/Matrix_Methods.jl

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,25 @@
33
44
Create a GraphBLAS matrix of dimensions nrows x ncols such that A[I[k], J[k]] = X[k].
55
dup is a GraphBLAS binary operator used to combine duplicates, it defaults to `FIRST`.
6-
If nrows and ncols are not specified, they are set to maximum(I) and maximum(J) respectively.
7-
nvals is set to length(I) is not specified.
8-
9-
# Examples
10-
```jldoctest
11-
julia> using SuiteSparseGraphBLAS
12-
13-
julia> A = GrB_Matrix([1, 1, 2, 3], [1, 1, 2, 3], UInt32[1, 10, 1, 1], dup = GrB_PLUS_UINT32)
14-
GrB_Matrix{UInt32}
15-
16-
julia> A[1, 1]
17-
0x0000000b
18-
```
6+
If nrows and ncols are not specified, they are set to maximum(I)+1 and maximum(J)+1 (because of 0-based indexing)
7+
respectively. nvals is set to length(I) is not specified.
198
"""
209
function GrB_Matrix(
2110
I::Vector{U},
2211
J::Vector{U},
2312
X::Vector{T};
24-
nrows::U = maximum(I),
25-
ncols::U = maximum(J),
13+
nrows::U = maximum(I)+1,
14+
ncols::U = maximum(J)+1,
2615
nvals::U = length(I),
27-
dup::GrB_BinaryOp = default_dup(T)) where {T <: valid_types, U <: GrB_Index}
16+
dup::GrB_BinaryOp = default_dup(T)) where {T, U <: GrB_Index}
2817

2918
A = GrB_Matrix{T}()
3019
GrB_T = get_GrB_Type(T)
3120
res = GrB_Matrix_new(A, GrB_T, nrows, ncols)
3221
if res != GrB_SUCCESS
3322
error(res)
3423
end
35-
res = GrB_Matrix_build(A, I.-1, J.-1, X, nvals, dup)
24+
res = GrB_Matrix_build(A, I, J, X, nvals, dup)
3625
if res != GrB_SUCCESS
3726
error(res)
3827
end
@@ -58,7 +47,7 @@ julia> nnz(A)
5847
0
5948
```
6049
"""
61-
function GrB_Matrix(T::DataType, nrows::GrB_Index, ncols::GrB_Index)
50+
function GrB_Matrix(T, nrows::GrB_Index, ncols::GrB_Index)
6251
A = GrB_Matrix{T}()
6352
GrB_T = get_GrB_Type(T)
6453
res = GrB_Matrix_new(A, GrB_T, nrows, ncols)
@@ -163,7 +152,7 @@ function findnz(A::GrB_Matrix)
163152
error(res)
164153
end
165154
I, J, X = res
166-
return I.+1, J.+1, X
155+
return I, J, X
167156
end
168157

169158
"""
@@ -205,7 +194,7 @@ julia> using SuiteSparseGraphBLAS
205194
julia> GrB_init(GrB_NONBLOCKING)
206195
GrB_SUCCESS::GrB_Info = 0
207196
208-
julia> A = GrB_Matrix([1, 2, 3], [1, 2, 3], [1, 1, 1])
197+
julia> A = GrB_Matrix([0, 1, 2], [0, 1, 2], [1, 1, 1])
209198
GrB_Matrix{Int64}
210199
211200
julia> size(A)
@@ -272,7 +261,7 @@ julia> A[1, 1]
272261
```
273262
"""
274263
function getindex(A::GrB_Matrix, row_index::GrB_Index, col_index::GrB_Index)
275-
res = GrB_Matrix_extractElement(A, row_index-1, col_index-1)
264+
res = GrB_Matrix_extractElement(A, row_index, col_index)
276265
if typeof(res) == GrB_Info
277266
error(res)
278267
end
@@ -304,8 +293,8 @@ julia> A[1, 1]
304293
5
305294
```
306295
"""
307-
function setindex!(A::GrB_Matrix{T}, X::T, I::GrB_Index, J::GrB_Index) where {T <: valid_types}
308-
res = GrB_Matrix_setElement(A, X, I-1, J-1)
296+
function setindex!(A::GrB_Matrix{T}, X::T, I::GrB_Index, J::GrB_Index) where T
297+
res = GrB_Matrix_setElement(A, X, I, J)
309298
if res != GrB_SUCCESS
310299
error(res)
311300
end
@@ -364,7 +353,7 @@ julia> findnz(B)
364353
([1, 2, 3], [1, 2, 3], [1, 1, 1])
365354
```
366355
"""
367-
function copy(A::GrB_Matrix{T}) where T <: valid_types
356+
function copy(A::GrB_Matrix{T}) where T
368357
C = GrB_Matrix{T}()
369358
res = GrB_Matrix_dup(C, A)
370359
if res != GrB_SUCCESS
@@ -392,7 +381,7 @@ julia> findnz(M')
392381
([2, 3], [1, 1], [1, 1])
393382
```
394383
"""
395-
function adjoint(A::GrB_Matrix{T}) where T <: valid_types
384+
function adjoint(A::GrB_Matrix{T}) where T
396385
C = GrB_Matrix(T, size(A, 2), size(A, 1))
397386
res = GrB_transpose(C, GrB_NULL, GrB_NULL, A, GrB_NULL)
398387
if res != GrB_SUCCESS
@@ -406,7 +395,7 @@ end
406395
407396
Return lower triangle of a GraphBLAS matrix.
408397
"""
409-
function LowerTriangular(A::GrB_Matrix{T}) where T <: valid_types
398+
function LowerTriangular(A::GrB_Matrix{T}) where T
410399
nrows, ncols = size(A)
411400
if nrows != ncols
412401
error("Matrix is not square")
@@ -424,7 +413,7 @@ end
424413
425414
Return upper triangle of a GraphBLAS matrix.
426415
"""
427-
function UpperTriangular(A::GrB_Matrix{T}) where T <: valid_types
416+
function UpperTriangular(A::GrB_Matrix{T}) where T
428417
nrows, ncols = size(A)
429418
if nrows != ncols
430419
error("Matrix is not square")
@@ -442,7 +431,7 @@ end
442431
443432
Return diagonal of a GraphBLAS matrix.
444433
"""
445-
function Diagonal(A::GrB_Matrix{T}) where T <: valid_types
434+
function Diagonal(A::GrB_Matrix{T}) where T
446435
nrows, ncols = size(A)
447436
D = GrB_Matrix(T, nrows, ncols)
448437
res = GxB_select(D, GrB_NULL, GrB_NULL, GxB_DIAG, A, 0, GrB_NULL)

0 commit comments

Comments
 (0)