1
+ """
2
+ GrB_Matrix_reduce_Monoid(w, mask, accum, monoid, A, desc)
3
+
4
+ Reduce the entries in a matrix to a vector. By default these methods compute a column vector w
5
+ such that w(i) = sum(A(i,:)), where "sum" is a commutative and associative monoid with an identity value.
6
+ A can be transposed, which reduces down the columns instead of the rows.
7
+
8
+ # Examples
9
+ ```jldoctest
10
+ julia> using SuiteSparseGraphBLAS
11
+
12
+ julia> GrB_init(GrB_NONBLOCKING)
13
+ GrB_SUCCESS::GrB_Info = 0
14
+
15
+ julia> A = GrB_Matrix{Int64}()
16
+ GrB_Matrix{Int64}
17
+
18
+ julia> GrB_Matrix_new(A, GrB_INT64, 4, 4)
19
+ GrB_SUCCESS::GrB_Info = 0
20
+
21
+ julia> I = [0, 0, 2, 2]; J = [1, 2, 0, 2]; X = [10, 20, 30, 40]; n = 4;
22
+
23
+ julia> GrB_Matrix_build(A, I, J, X, n, GrB_FIRST_INT64)
24
+ GrB_SUCCESS::GrB_Info = 0
25
+
26
+ julia> w = GrB_Vector{Int64}()
27
+ GrB_Vector{Int64}
28
+
29
+ julia> GrB_Vector_new(w, GrB_INT64, 4)
30
+ GrB_SUCCESS::GrB_Info = 0
31
+
32
+ julia> GrB_Matrix_reduce_Monoid(w, GrB_NULL, GrB_NULL, GxB_PLUS_INT64_MONOID, A, GrB_NULL)
33
+ GrB_SUCCESS::GrB_Info = 0
34
+
35
+ julia> @GxB_fprint(w, GxB_COMPLETE)
36
+
37
+ GraphBLAS vector: w
38
+ nrows: 4 ncols: 1 max # entries: 2
39
+ format: standard CSC vlen: 4 nvec_nonempty: 1 nvec: 1 plen: 1 vdim: 1
40
+ hyper_ratio 0.0625
41
+ GraphBLAS type: int64_t size: 8
42
+ number of entries: 2
43
+ column: 0 : 2 entries [0:1]
44
+ row 0: int64 30
45
+ row 2: int64 70
46
+
47
+ ```
48
+ """
1
49
function GrB_Matrix_reduce_Monoid ( # w<mask> = accum (w,reduce(A))
2
50
w:: GrB_Vector , # input/output vector for results
3
51
mask:: T , # optional mask for w, unused if NULL
@@ -17,6 +65,54 @@ function GrB_Matrix_reduce_Monoid( # w<mask> = accum (w,reduce(A))
17
65
)
18
66
end
19
67
68
+ """
69
+ GrB_Matrix_reduce_BinaryOp(w, mask, accum, op, A, desc)
70
+
71
+ Reduce the entries in a matrix to a vector. By default these methods compute a column vector w such that
72
+ w(i) = sum(A(i,:)), where "sum" is a commutative and associative binary operator. A can be transposed,
73
+ which reduces down the columns instead of the rows.
74
+
75
+ # Examples
76
+ ```jldoctest
77
+ julia> using SuiteSparseGraphBLAS
78
+
79
+ julia> GrB_init(GrB_NONBLOCKING)
80
+ GrB_SUCCESS::GrB_Info = 0
81
+
82
+ julia> A = GrB_Matrix{Int64}()
83
+ GrB_Matrix{Int64}
84
+
85
+ julia> GrB_Matrix_new(A, GrB_INT64, 4, 4)
86
+ GrB_SUCCESS::GrB_Info = 0
87
+
88
+ julia> I = [0, 0, 2, 2]; J = [1, 2, 0, 2]; X = [10, 20, 30, 40]; n = 4;
89
+
90
+ julia> GrB_Matrix_build(A, I, J, X, n, GrB_FIRST_INT64)
91
+ GrB_SUCCESS::GrB_Info = 0
92
+
93
+ julia> w = GrB_Vector{Int64}()
94
+ GrB_Vector{Int64}
95
+
96
+ julia> GrB_Vector_new(w, GrB_INT64, 4)
97
+ GrB_SUCCESS::GrB_Info = 0
98
+
99
+ julia> GrB_Matrix_reduce_BinaryOp(w, GrB_NULL, GrB_NULL, GrB_TIMES_INT64, A, GrB_NULL)
100
+ GrB_SUCCESS::GrB_Info = 0
101
+
102
+ julia> @GxB_fprint(w, GxB_COMPLETE)
103
+
104
+ GraphBLAS vector: w
105
+ nrows: 4 ncols: 1 max # entries: 2
106
+ format: standard CSC vlen: 4 nvec_nonempty: 1 nvec: 1 plen: 1 vdim: 1
107
+ hyper_ratio 0.0625
108
+ GraphBLAS type: int64_t size: 8
109
+ number of entries: 2
110
+ column: 0 : 2 entries [0:1]
111
+ row 0: int64 200
112
+ row 2: int64 1200
113
+
114
+ ```
115
+ """
20
116
function GrB_Matrix_reduce_BinaryOp ( # w<mask> = accum (w,reduce(A))
21
117
w:: GrB_Vector , # input/output vector for results
22
118
mask:: T , # optional mask for w, unused if NULL
@@ -36,6 +132,35 @@ function GrB_Matrix_reduce_BinaryOp( # w<mask> = accum (w,reduce(A))
36
132
)
37
133
end
38
134
135
+ """
136
+ GrB_Vector_reduce(accum, monoid, u, desc)
137
+
138
+ Reduce entries in a vector to a scalar. All entries in the vector are "summed"
139
+ using the reduce monoid, which must be associative (otherwise the results are undefined).
140
+ If the vector has no entries, the result is the identity value of the monoid.
141
+
142
+ # Examples
143
+ ```jldoctest
144
+ julia> using SuiteSparseGraphBLAS
145
+
146
+ julia> GrB_init(GrB_NONBLOCKING)
147
+ GrB_SUCCESS::GrB_Info = 0
148
+
149
+ julia> u = GrB_Vector{Int64}()
150
+ GrB_Vector{Int64}
151
+
152
+ julia> GrB_Vector_new(u, GrB_INT64, 5)
153
+ GrB_SUCCESS::GrB_Info = 0
154
+
155
+ julia> I = [0, 2, 4]; X = [10, 20, 30]; n = 3;
156
+
157
+ julia> GrB_Vector_build(u, I, X, n, GrB_FIRST_INT64)
158
+ GrB_SUCCESS::GrB_Info = 0
159
+
160
+ julia> GrB_Vector_reduce(GrB_NULL, GxB_MAX_INT64_MONOID, u, GrB_NULL)
161
+ 30
162
+ ```
163
+ """
39
164
function GrB_Vector_reduce ( # c = accum (c, reduce_to_scalar (u))
40
165
accum:: U , # optional accum for c=accum(c,t)
41
166
monoid:: GrB_Monoid , # monoid to do the reduction
@@ -59,6 +184,35 @@ function GrB_Vector_reduce( # c = accum (c, reduce_to_scalar (u)
59
184
return scalar[]
60
185
end
61
186
187
+ """
188
+ GrB_Matrix_reduce(accum, monoid, A, desc)
189
+
190
+ Reduce entries in a matrix to a scalar. All entries in the matrix are "summed"
191
+ using the reduce monoid, which must be associative (otherwise the results are undefined).
192
+ If the matrix has no entries, the result is the identity value of the monoid.
193
+
194
+ # Examples
195
+ ```jldoctest
196
+ julia> using SuiteSparseGraphBLAS
197
+
198
+ julia> GrB_init(GrB_NONBLOCKING)
199
+ GrB_SUCCESS::GrB_Info = 0
200
+
201
+ julia> A = GrB_Matrix{Int64}()
202
+ GrB_Matrix{Int64}
203
+
204
+ julia> GrB_Matrix_new(A, GrB_INT64, 4, 4)
205
+ GrB_SUCCESS::GrB_Info = 0
206
+
207
+ julia> I = [0, 0, 2, 2]; J = [1, 2, 0, 2]; X = [10, 20, 30, 40]; n = 4;
208
+
209
+ julia> GrB_Matrix_build(A, I, J, X, n, GrB_FIRST_INT64)
210
+ GrB_SUCCESS::GrB_Info = 0
211
+
212
+ julia> GrB_Matrix_reduce(GrB_NULL, GxB_MIN_INT64_MONOID, A, GrB_NULL)
213
+ 10
214
+ ```
215
+ """
62
216
function GrB_Matrix_reduce ( # c = accum (c, reduce_to_scalar (A))
63
217
accum:: U , # optional accum for c=accum(c,t)
64
218
monoid:: GrB_Monoid , # monoid to do the reduction
@@ -74,7 +228,7 @@ function GrB_Matrix_reduce( # c = accum (c, reduce_to_scalar (A)
74
228
dlsym (graphblas_lib, fn_name),
75
229
Cint,
76
230
(Ptr{T}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}),
77
- scalar, A . p, monoid. p, u . p, desc. p
231
+ scalar, accum . p, monoid. p, A . p, desc. p
78
232
)
79
233
)
80
234
0 commit comments