Skip to content

Commit 040fc58

Browse files
update documentation
1 parent dc65766 commit 040fc58

16 files changed

+2186
-3
lines changed

src/Context_Methods.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
11
import GraphBLASInterface:
22
GrB_init, GrB_finalize
33

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

16+
"""
17+
GrB_finalize()
18+
19+
`GrB_finalize` must be called as the last GraphBLAS operation.
20+
`GrB_finalize` does not call `GrB_wait`; any pending computations are abandoned.
21+
"""
822
function GrB_finalize()
923
return GrB_Info(ccall(dlsym(graphblas_lib, "GrB_finalize"), Cint, (), ))
1024
end

src/Object_Methods/Algebra_Methods.jl

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,64 @@
11
import GraphBLASInterface:
22
GrB_UnaryOp_new, GrB_BinaryOp_new, GrB_Monoid_new, GrB_Semiring_new
33

4+
"""
5+
GrB_UnaryOp_new(op, fn, ztype, xtype)
6+
7+
Initialize a GraphBLAS unary operator with a specified user-defined function and its types.
8+
The function should take a single value(x) & return an output(z), f(x) = z.
9+
10+
# Examples
11+
```jldoctest
12+
julia> using GraphBLASInterface, SuiteSparseGraphBLAS
13+
14+
julia> GrB_init(GrB_NONBLOCKING)
15+
GrB_SUCCESS::GrB_Info = 0
16+
17+
julia> u = GrB_Vector{Int64}()
18+
GrB_Vector{Int64}
19+
20+
julia> GrB_Vector_new(u, GrB_INT64, 3)
21+
GrB_SUCCESS::GrB_Info = 0
22+
23+
julia> I = [0, 2]; X = [10, 20]; n = 2;
24+
25+
julia> GrB_Vector_build(u, I, X, n, GrB_FIRST_INT64)
26+
GrB_SUCCESS::GrB_Info = 0
27+
28+
julia> w = GrB_Vector{Int64}()
29+
GrB_Vector{Int64}
30+
31+
julia> GrB_Vector_new(w, GrB_INT64, 3)
32+
GrB_SUCCESS::GrB_Info = 0
33+
34+
julia> function NEG(a)
35+
return -a
36+
end
37+
NEG (generic function with 1 method)
38+
39+
julia> negative = GrB_UnaryOp()
40+
GrB_UnaryOp
41+
42+
julia> GrB_UnaryOp_new(negative, NEG, GrB_INT64, GrB_INT64)
43+
GrB_SUCCESS::GrB_Info = 0
44+
45+
julia> GrB_apply(w, GrB_NULL, GrB_NULL, negative, u, GrB_NULL)
46+
GrB_SUCCESS::GrB_Info = 0
47+
48+
julia> @GxB_fprint(w, GxB_COMPLETE)
49+
50+
GraphBLAS vector: w
51+
nrows: 3 ncols: 1 max # entries: 2
52+
format: standard CSC vlen: 3 nvec_nonempty: 1 nvec: 1 plen: 1 vdim: 1
53+
hyper_ratio 0.0625
54+
GraphBLAS type: int64_t size: 8
55+
number of entries: 2
56+
column: 0 : 2 entries [0:1]
57+
row 0: int64 -10
58+
row 2: int64 -20
59+
60+
```
61+
"""
462
function GrB_UnaryOp_new(
563
op::GrB_UnaryOp,
664
fn::Function,
@@ -26,6 +84,55 @@ function GrB_UnaryOp_new(
2684
)
2785
end
2886

87+
"""
88+
GrB_BinaryOp_new(op, fn, ztype, xtype, ytype)
89+
90+
Initialize a GraphBLAS binary operator with a specified user-defined function and its types.
91+
The function should take 2 values(x, y) & return an output(z), f(x, y) = z.
92+
93+
# Examples
94+
```jldoctest
95+
julia> using GraphBLASInterface, SuiteSparseGraphBLAS
96+
97+
julia> GrB_init(GrB_NONBLOCKING)
98+
GrB_SUCCESS::GrB_Info = 0
99+
100+
julia> V = GrB_Vector{Float64}()
101+
GrB_Vector{Float64}
102+
103+
julia> GrB_Vector_new(V, GrB_FP64, 4)
104+
GrB_SUCCESS::GrB_Info = 0
105+
106+
julia> I = [0, 0, 3, 3]; X = [2.1, 3.2, 4.5, 5.0]; n = 4; # two values at position 0 and 3
107+
108+
julia> dup = GrB_BinaryOp() # dup is a binary operator which is applied when duplicate values for the same location are present in the vector
109+
GrB_BinaryOp
110+
111+
julia> function ADD(b, c)
112+
return b+c
113+
end
114+
ADD (generic function with 1 method)
115+
116+
julia> GrB_BinaryOp_new(dup, ADD, GrB_FP64, GrB_FP64, GrB_FP64)
117+
GrB_SUCCESS::GrB_Info = 0
118+
119+
julia> GrB_Vector_build(V, I, X, n, dup)
120+
GrB_SUCCESS::GrB_Info = 0
121+
122+
julia> @GxB_Vector_fprint(V, GxB_SHORT) # the value stored at position 0 and 3 will be the sum of the duplicate values
123+
124+
GraphBLAS vector: V
125+
nrows: 4 ncols: 1 max # entries: 2
126+
format: standard CSC vlen: 4 nvec_nonempty: 1 nvec: 1 plen: 1 vdim: 1
127+
hyper_ratio 0.0625
128+
GraphBLAS type: double size: 8
129+
number of entries: 2
130+
column: 0 : 2 entries [0:1]
131+
row 0: double 5.3
132+
row 3: double 9.5
133+
134+
```
135+
"""
29136
function GrB_BinaryOp_new(
30137
op::GrB_BinaryOp,
31138
fn::Function,
@@ -52,6 +159,11 @@ function GrB_BinaryOp_new(
52159
)
53160
end
54161

162+
"""
163+
GrB_Monoid_new(monoid, binary_op, identity)
164+
165+
Initialize a GraphBLAS monoid with specified binary operator and identity value.
166+
"""
55167
function GrB_Monoid_new(monoid::GrB_Monoid, binary_op::GrB_BinaryOp, identity::T) where T
56168
monoid_ptr = pointer_from_objref(monoid)
57169
fn_name = "GrB_Monoid_new_" * suffix(T)
@@ -108,6 +220,11 @@ function GrB_Monoid_new(monoid::GrB_Monoid, binary_op::GrB_BinaryOp, identity::F
108220
)
109221
end
110222

223+
"""
224+
GrB_Semiring_new(semiring, monoid, binary_op)
225+
226+
Initialize a GraphBLAS semiring with specified monoid and binary operator.
227+
"""
111228
function GrB_Semiring_new(semiring::GrB_Semiring, monoid::GrB_Monoid, binary_op::GrB_BinaryOp)
112229
semiring_ptr = pointer_from_objref(semiring)
113230

src/Object_Methods/Descriptor_Methods.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import GraphBLASInterface:
22
GrB_Descriptor_new, GrB_Descriptor_set
33

4+
"""
5+
GrB_Descriptor_new(desc)
6+
7+
Initialize a descriptor with default field values.
8+
"""
49
function GrB_Descriptor_new(desc::GrB_Descriptor)
510
desc_ptr = pointer_from_objref(desc)
611

@@ -14,6 +19,11 @@ function GrB_Descriptor_new(desc::GrB_Descriptor)
1419
)
1520
end
1621

22+
"""
23+
GrB_Descriptor_set(desc, field, val)
24+
25+
Set the content for a field for an existing descriptor.
26+
"""
1727
function GrB_Descriptor_set(desc::GrB_Descriptor, field::GrB_Desc_Field, val::GrB_Desc_Value)
1828
return GrB_Info(
1929
ccall(

src/Object_Methods/Free_Objects.jl

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ import GraphBLASInterface:
22
GrB_UnaryOp_free, GrB_BinaryOp_free, GrB_Monoid_free, GrB_Semiring_free,
33
GrB_Vector_free, GrB_Matrix_free, GrB_Descriptor_free
44

5+
"""
6+
GrB_UnaryOp_free(unaryop)
7+
8+
Free unary operator.
9+
"""
510
function GrB_UnaryOp_free(unaryop::GrB_UnaryOp)
611
unaryop_ptr = pointer_from_objref(unaryop)
712

@@ -15,6 +20,11 @@ function GrB_UnaryOp_free(unaryop::GrB_UnaryOp)
1520
)
1621
end
1722

23+
"""
24+
GrB_BinaryOp_free(binaryop)
25+
26+
Free binary operator.
27+
"""
1828
function GrB_BinaryOp_free(binaryop::GrB_BinaryOp)
1929
binaryop_ptr = pointer_from_objref(binaryop)
2030

@@ -28,6 +38,11 @@ function GrB_BinaryOp_free(binaryop::GrB_BinaryOp)
2838
)
2939
end
3040

41+
"""
42+
GrB_Monoid_free(monoid)
43+
44+
Free monoid.
45+
"""
3146
function GrB_Monoid_free(monoid::GrB_Monoid)
3247
monoid_ptr = pointer_from_objref(monoid)
3348

@@ -41,6 +56,11 @@ function GrB_Monoid_free(monoid::GrB_Monoid)
4156
)
4257
end
4358

59+
"""
60+
GrB_Semiring_free(semiring)
61+
62+
Free semiring.
63+
"""
4464
function GrB_Semiring_free(semiring::GrB_Semiring)
4565
semiring_ptr = pointer_from_objref(semiring)
4666

@@ -54,6 +74,11 @@ function GrB_Semiring_free(semiring::GrB_Semiring)
5474
)
5575
end
5676

77+
"""
78+
GrB_Vector_free(v)
79+
80+
Free vector.
81+
"""
5782
function GrB_Vector_free(v::GrB_Vector)
5883
v_ptr = pointer_from_objref(v)
5984

@@ -67,6 +92,11 @@ function GrB_Vector_free(v::GrB_Vector)
6792
)
6893
end
6994

95+
"""
96+
GrB_Matrix_free(A)
97+
98+
Free matrix.
99+
"""
70100
function GrB_Matrix_free(A::GrB_Matrix)
71101
A_ptr = pointer_from_objref(A)
72102

@@ -80,6 +110,11 @@ function GrB_Matrix_free(A::GrB_Matrix)
80110
)
81111
end
82112

113+
"""
114+
GrB_Descriptor_free(desc)
115+
116+
Free descriptor.
117+
"""
83118
function GrB_Descriptor_free(desc::GrB_Descriptor)
84119
desc_ptr = pointer_from_objref(desc)
85120

0 commit comments

Comments
 (0)