1
1
import GraphBLASInterface:
2
2
GrB_UnaryOp_new, GrB_BinaryOp_new, GrB_Monoid_new, GrB_Semiring_new
3
3
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
+ """
4
62
function GrB_UnaryOp_new (
5
63
op:: GrB_UnaryOp ,
6
64
fn:: Function ,
@@ -26,6 +84,55 @@ function GrB_UnaryOp_new(
26
84
)
27
85
end
28
86
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
+ """
29
136
function GrB_BinaryOp_new (
30
137
op:: GrB_BinaryOp ,
31
138
fn:: Function ,
@@ -52,6 +159,11 @@ function GrB_BinaryOp_new(
52
159
)
53
160
end
54
161
162
+ """
163
+ GrB_Monoid_new(monoid, binary_op, identity)
164
+
165
+ Initialize a GraphBLAS monoid with specified binary operator and identity value.
166
+ """
55
167
function GrB_Monoid_new (monoid:: GrB_Monoid , binary_op:: GrB_BinaryOp , identity:: T ) where T
56
168
monoid_ptr = pointer_from_objref (monoid)
57
169
fn_name = " GrB_Monoid_new_" * suffix (T)
@@ -108,6 +220,11 @@ function GrB_Monoid_new(monoid::GrB_Monoid, binary_op::GrB_BinaryOp, identity::F
108
220
)
109
221
end
110
222
223
+ """
224
+ GrB_Semiring_new(semiring, monoid, binary_op)
225
+
226
+ Initialize a GraphBLAS semiring with specified monoid and binary operator.
227
+ """
111
228
function GrB_Semiring_new (semiring:: GrB_Semiring , monoid:: GrB_Monoid , binary_op:: GrB_BinaryOp )
112
229
semiring_ptr = pointer_from_objref (semiring)
113
230
0 commit comments