Skip to content

Commit 2623539

Browse files
add generic methods
1 parent f4a0fce commit 2623539

File tree

3 files changed

+30
-9
lines changed

3 files changed

+30
-9
lines changed

src/Operations/Assign.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function GrB_assign(arg1::T, Mask, accum, arg4::U, arg5::V, args...) where {T, U
1212
end
1313
elseif T <: GrB_Matrix
1414
if U <: GrB_Vector
15-
if V <: Union{Vector{GrB_Index}, GrB_ALL_Type}
15+
if V <: Union{Vector{X} where X <: GrB_Index, GrB_ALL_Type}
1616
return GrB_Col_assign(arg1, Mask, accum, arg4, arg5, args...)
1717
elseif V <: GrB_Index
1818
return GrB_Row_assign(arg1, Mask, accum, arg4, arg5, args...)

src/Operations/Reduce.jl

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,28 @@
1+
"""
2+
GrB_reduce(arg1, arg2, arg3, arg4, ...)
3+
4+
Generic method for matrix/vector reduction to a vector or scalar.
5+
"""
6+
function GrB_reduce(arg1::T, arg2, arg3::U, arg4::V, args...) where {T, U, V}
7+
if T <: GrB_Vector
8+
if V <: GrB_Monoid
9+
return GrB_Matrix_reduce_Monoid(arg1, arg2, arg3, arg4, args...)
10+
elseif V <: GrB_BinaryOp
11+
return GrB_Matrix_reduce_BinaryOp(arg1, arg2, arg3, arg4, args...)
12+
end
13+
elseif T <: valid_accum_types
14+
if U <: GrB_Vector
15+
return GrB_Vector_reduce(arg1, arg2, arg3, arg4)
16+
elseif U <: GrB_Matrix
17+
return GrB_Matrix_reduce(arg1, arg2, arg3, arg4)
18+
end
19+
end
20+
end
21+
122
"""
223
GrB_Matrix_reduce_Monoid(w, mask, accum, monoid, A, desc)
324
4-
Reduce the entries in a matrix to a vector. By default these methods compute a column vector w
25+
Reduce the entries in a matrix to a vector. By default these methods compute a column vector w
526
such that w(i) = sum(A(i,:)), where "sum" is a commutative and associative monoid with an identity value.
627
A can be transposed, which reduces down the columns instead of the rows.
728
@@ -34,12 +55,12 @@ GrB_SUCCESS::GrB_Info = 0
3455
3556
julia> @GxB_fprint(w, GxB_COMPLETE)
3657
37-
GraphBLAS vector: w
58+
GraphBLAS vector: w
3859
nrows: 4 ncols: 1 max # entries: 2
3960
format: standard CSC vlen: 4 nvec_nonempty: 1 nvec: 1 plen: 1 vdim: 1
4061
hyper_ratio 0.0625
4162
GraphBLAS type: int64_t size: 8
42-
number of entries: 2
63+
number of entries: 2
4364
column: 0 : 2 entries [0:1]
4465
row 0: int64 30
4566
row 2: int64 70
@@ -68,8 +89,8 @@ end
6889
"""
6990
GrB_Matrix_reduce_BinaryOp(w, mask, accum, op, A, desc)
7091
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,
92+
Reduce the entries in a matrix to a vector. By default these methods compute a column vector w such that
93+
w(i) = sum(A(i,:)), where "sum" is a commutative and associative binary operator. A can be transposed,
7394
which reduces down the columns instead of the rows.
7495
7596
# Examples
@@ -101,12 +122,12 @@ GrB_SUCCESS::GrB_Info = 0
101122
102123
julia> @GxB_fprint(w, GxB_COMPLETE)
103124
104-
GraphBLAS vector: w
125+
GraphBLAS vector: w
105126
nrows: 4 ncols: 1 max # entries: 2
106127
format: standard CSC vlen: 4 nvec_nonempty: 1 nvec: 1 plen: 1 vdim: 1
107128
hyper_ratio 0.0625
108129
GraphBLAS type: int64_t size: 8
109-
number of entries: 2
130+
number of entries: 2
110131
column: 0 : 2 entries [0:1]
111132
row 0: int64 200
112133
row 2: int64 1200

src/SuiteSparseGraphBLAS.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ GrB_apply, GrB_Vector_apply, GrB_Matrix_apply,
203203
GrB_assign, GrB_Vector_assign, GrB_Matrix_assign, GrB_Col_assign, GrB_Row_assign,
204204

205205
# Reduce
206-
GrB_Matrix_reduce_Monoid, GrB_Matrix_reduce_BinaryOp, GrB_Matrix_reduce,
206+
GrB_reduce, GrB_Matrix_reduce_Monoid, GrB_Matrix_reduce_BinaryOp, GrB_Matrix_reduce,
207207
GrB_Vector_reduce,
208208

209209
# Transpose

0 commit comments

Comments
 (0)