Skip to content

Commit 659ea3c

Browse files
add built in select operators
1 parent 2a7b3aa commit 659ea3c

File tree

3 files changed

+73
-4
lines changed

3 files changed

+73
-4
lines changed

src/Operations/Select.jl

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
function GxB_select(C::T, Mask, accum, op, A::T, k, desc) where T
2+
if T <: GrB_Matrix
3+
return GxB_Matrix_select(C, Mask, accum, op, A, k, desc)
4+
elseif T <: GrB_Vector
5+
return GxB_Vectorselect(C, Mask, accum, op, A, k, desc)
6+
end
7+
end
8+
9+
function GxB_Vector_select( # w<mask> = accum (w, op(u,k))
10+
w::GrB_Vector, # input/output vector for results
11+
mask::T, # optional mask for w, unused if NULL
12+
accum::U, # optional accum for z=accum(w,t)
13+
op::GxB_SelectOp, # operator to apply to the entries
14+
u::GrB_Vector, # first input: vector u
15+
thunk, # optional input for the select operator
16+
desc::V # descriptor for w and mask
17+
) where {T <: valid_vector_mask_types, U <: valid_accum_types, V <: valid_desc_types}
18+
19+
return GrB_Info(
20+
ccall(
21+
dlsym(graphblas_lib, "GxB_Vector_select"),
22+
Cint,
23+
(Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}),
24+
w.p, mask.p, accum.p, op.p, u.p, Ref(thunk), desc.p
25+
)
26+
)
27+
end
28+
29+
function GxB_Matrix_select( # C<Mask> = accum (C, op(A,k)) or op(A',k)
30+
C::GrB_Matrix, # input/output matrix for results
31+
Mask::T, # optional mask for C, unused if NULL
32+
accum::U, # optional accum for Z=accum(C,T)
33+
op::GxB_SelectOp, # operator to apply to the entries
34+
A::GrB_Matrix, # first input: matrix A
35+
thunk, # optional input for the select operator
36+
desc::V # descriptor for C, mask, and A
37+
) where {T <: valid_matrix_mask_types, U <: valid_accum_types, V <: valid_desc_types}
38+
39+
return GrB_Info(
40+
ccall(
41+
dlsym(graphblas_lib, "GxB_Matrix_select"),
42+
Cint,
43+
(Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}),
44+
C.p, Mask.p, accum.p, op.p, A.p, Ref(thunk), desc.p
45+
)
46+
)
47+
end

src/Structures.jl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ abstract type GrB_Struct end
99
mutable struct GrB_Type{T} <: GrB_Struct
1010
p::Ptr{Cvoid}
1111
end
12-
GrB_Type{T}() where T = GrB_Type{T}(C_NULL)
12+
GrB_Type{T}() where T = GrB_Type{T}(C_NULL)
1313
Base.show(io::IO, ::GrB_Type{T}) where T = print("GrB_Type{" * string(T) * "}")
1414

1515
mutable struct GrB_UnaryOp <: GrB_Struct
@@ -54,13 +54,19 @@ end
5454
GrB_Descriptor() = GrB_Descriptor(C_NULL)
5555
Base.show(io::IO, ::GrB_Descriptor) = print("GrB_Descriptor")
5656

57+
mutable struct GxB_SelectOp
58+
p::Ptr{Cvoid}
59+
end
60+
GxB_SelectOp() = GxB_SelectOp(C_NULL)
61+
Base.show(io::IO, ::GxB_SelectOp) = print("GxB_SelectOp")
62+
5763
struct GrB_NULL_Type
58-
p::Ptr{Cvoid}
64+
p::Ptr{Cvoid}
5965
end
6066
Base.show(io::IO, ::GrB_NULL_Type) = print("GrB_NULL")
6167

6268
mutable struct GrB_ALL_Type
63-
p::Ptr{Cvoid}
69+
p::Ptr{Cvoid}
6470
end
6571
Base.pointer(x::GrB_ALL_Type) = x.p
6672
Base.show(io::IO, ::GrB_ALL_Type) = print("GrB_ALL")

src/SuiteSparseGraphBLAS.jl

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ const GrB_LNOT = GrB_UnaryOp()
6666
const GrB_LOR = GrB_BinaryOp(); const GrB_LAND = GrB_BinaryOp(); const GrB_LXOR = GrB_BinaryOp()
6767
const GxB_LOR_BOOL_MONOID = GrB_Monoid(); const GxB_LAND_BOOL_MONOID = GrB_Monoid()
6868
const GxB_LXOR_BOOL_MONOID = GrB_Monoid(); const GxB_EQ_BOOL_MONOID = GrB_Monoid()
69+
const GxB_TRIL = GxB_SelectOp(); const GxB_TRIU = GxB_SelectOp(); const GxB_DIAG = GxB_SelectOp();
70+
const GxB_OFFDIAG = GxB_SelectOp(); GxB_NONZERO = GxB_SelectOp()
6971

7072
graphblas_lib = C_NULL
7173

@@ -137,6 +139,13 @@ function __init__()
137139
varname = "GxB_" * bool_s * "_" * "BOOL"
138140
@eval const $(Symbol(varname)) = $(GrB_Semiring(load_global(varname)))
139141
end
142+
143+
#load global select operators
144+
GxB_TRIL.p = load_global("GxB_TRIL")
145+
GxB_TRIU.p = load_global("GxB_TRIU")
146+
GxB_DIAG.p = load_global("GxB_DIAG")
147+
GxB_OFFDIAG.p = load_global("GxB_OFFDIAG")
148+
GxB_NONZERO.p = load_global("GxB_NONZERO")
140149
end
141150

142151
include("Enums.jl")
@@ -155,6 +164,7 @@ include("Operations/Apply.jl")
155164
include("Operations/Assign.jl")
156165
include("Operations/Reduce.jl")
157166
include("Operations/Transpose.jl")
167+
include("Operations/Select.jl")
158168

159169
export
160170
# Context Methods
@@ -212,7 +222,10 @@ GrB_reduce, GrB_Matrix_reduce_Monoid, GrB_Matrix_reduce_BinaryOp, GrB_Matrix_red
212222
GrB_Vector_reduce,
213223

214224
# Transpose
215-
GrB_transpose
225+
GrB_transpose,
226+
227+
# Select
228+
GxB_Vector_select, GxB_Matrix_select, GxB_select
216229

217230
# Export global variables
218231

@@ -261,6 +274,9 @@ for bool_s in built_in_boolean_semirings
261274
@eval export $(Symbol(varname))
262275
end
263276

277+
# Select Operators
278+
export GxB_TRIL, GxB_TRIU, GxB_OFFDIAG, GxB_DIAG, GxB_NONZERO
279+
264280
# Enums
265281
export GrB_Info
266282
for s in instances(GrB_Info)

0 commit comments

Comments
 (0)