Skip to content

Commit 7db99bb

Browse files
add element wise multiplication functions
1 parent 4eafa6d commit 7db99bb

File tree

4 files changed

+156
-6
lines changed

4 files changed

+156
-6
lines changed

src/Object_Methods/Print_Objects.jl

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@ function GxB_fprint(A::GrB_Struct, name::String, pr::GxB_Print_Level)
55
ccall(:fclose, Cint, (Ptr{Cvoid},), FILE)
66
foreach(println, eachline(path))
77
end
8-
s = ""
9-
for i in string(typeof(A))[5:end]
10-
i == '{' && break
11-
s *= i
12-
end
8+
s = get_struct_name(A)
139
fn_name = "GxB_" * s * "_fprint"
1410
mktemp(f)
1511
end
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
function GrB_eWiseMult(C::T, mask::T, accum::GrB_BinaryOp, op::U, A::T, B::T,
2+
desc::GrB_Descriptor) where {T <: Union{GrB_Vector, GrB_Matrix}, U <: Union{GrB_BinaryOp, GrB_Monoid, GrB_Semiring}}
3+
4+
T_name = get_struct_name(A)
5+
U_name = get_struct_name(op)
6+
7+
fn_name = "GrB_eWiseMult_" * T_name * "_" * U_name
8+
9+
return GrB_Info(
10+
ccall(
11+
dlsym(graphblas_lib, fn_name),
12+
Cint,
13+
(Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}),
14+
C.p, mask.p, accum.p, op.p, A.p, B.p, desc.p
15+
)
16+
)
17+
end
18+
19+
function GrB_eWiseMult_Vector_Semiring( # w<Mask> = accum (w, u.*v)
20+
w::GrB_Vector, # input/output vector for results
21+
mask::GrB_Vector, # optional mask for w, unused if NULL
22+
accum::GrB_BinaryOp, # optional accum for z=accum(w,t)
23+
semiring::GrB_Semiring, # defines '.*' for t=u.*v
24+
u::GrB_Vector, # first input: vector u
25+
v::GrB_Vector, # second input: vector v
26+
desc::GrB_Descriptor # descriptor for w and mask
27+
)
28+
29+
return GrB_Info(
30+
ccall(
31+
dlsym(graphblas_lib, "GrB_eWiseMult_Vector_Semiring"),
32+
Cint,
33+
(Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}),
34+
w.p, mask.p, accum.p, semiring.p, u.p, v.p, desc.p
35+
)
36+
)
37+
end
38+
39+
function GrB_eWiseMult_Vector_Monoid( # w<Mask> = accum (w, u.*v)
40+
w::GrB_Vector, # input/output vector for results
41+
mask::GrB_Vector, # optional mask for w, unused if NULL
42+
accum::GrB_BinaryOp, # optional accum for z=accum(w,t)
43+
monoid::GrB_Monoid, # defines '.*' for t=u.*v
44+
u::GrB_Vector, # first input: vector u
45+
v::GrB_Vector, # second input: vector v
46+
desc::GrB_Descriptor # descriptor for w and mask
47+
)
48+
49+
return GrB_Info(
50+
ccall(
51+
dlsym(graphblas_lib, "GrB_eWiseMult_Vector_Monoid"),
52+
Cint,
53+
(Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}),
54+
w.p, mask.p, accum.p, monoic.p, u.p, v.p, desc.p
55+
)
56+
)
57+
end
58+
59+
function GrB_eWiseMult_Vector_BinaryOp( # w<Mask> = accum (w, u.*v)
60+
w::GrB_Vector, # input/output vector for results
61+
mask::GrB_Vector, # optional mask for w, unused if NULL
62+
accum::GrB_BinaryOp, # optional accum for z=accum(w,t)
63+
mult::GrB_BinaryOp, # defines '.*' for t=u.*v
64+
u::GrB_Vector, # first input: vector u
65+
v::GrB_Vector, # second input: vector v
66+
desc::GrB_Descriptor # descriptor for w and mask
67+
)
68+
69+
return GrB_Info(
70+
ccall(
71+
dlsym(graphblas_lib, "GrB_eWiseMult_Vector_BinaryOp"),
72+
Cint,
73+
(Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}),
74+
w.p, mask.p, accum.p, mult.p, u.p, v.p, desc.p
75+
)
76+
)
77+
end
78+
79+
function GrB_eWiseMult_Matrix_Semiring( # C<Mask> = accum (C, A.*B)
80+
C::GrB_Matrix, # input/output matrix for results
81+
Mask::GrB_Matrix, # optional mask for C, unused if NULL
82+
accum::GrB_BinaryOp, # optional accum for Z=accum(C,T)
83+
semiring::GrB_Semiring, # defines '.*' for T=A.*B
84+
A::GrB_Matrix, # first input: matrix A
85+
B::GrB_Matrix, # second input: matrix B
86+
desc::GrB_Descriptor # descriptor for C, Mask, A, and B
87+
)
88+
89+
return GrB_Info(
90+
ccall(
91+
dlsym(graphblas_lib, fn_name),
92+
Cint,
93+
(Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}),
94+
C.p, Mask.p, accum.p, semiring.p, A.p, B.p, desc.p
95+
)
96+
)
97+
end
98+
99+
function GrB_eWiseMult_Matrix_Monoid( # C<Mask> = accum (C, A.*B)
100+
C::GrB_Matrix, # input/output matrix for results
101+
Mask::GrB_Matrix, # optional mask for C, unused if NULL
102+
accum::GrB_BinaryOp, # optional accum for Z=accum(C,T)
103+
monoid::GrB_Monoid, # defines '.*' for T=A.*B
104+
A::GrB_Matrix, # first input: matrix A
105+
B::GrB_Matrix, # second input: matrix B
106+
desc::GrB_Descriptor # descriptor for C, Mask, A, and B
107+
)
108+
109+
return GrB_Info(
110+
ccall(
111+
dlsym(graphblas_lib, fn_name),
112+
Cint,
113+
(Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}),
114+
C.p, Mask.p, accum.p, monoid.p, A.p, B.p, desc.p
115+
)
116+
)
117+
end
118+
119+
function GrB_eWiseMult_Matrix_BinaryOp( # C<Mask> = accum (C, A.*B)
120+
C::GrB_Matrix, # input/output matrix for results
121+
Mask::GrB_Matrix, # optional mask for C, unused if NULL
122+
accum::GrB_BinaryOp, # optional accum for Z=accum(C,T)
123+
mult::GrB_BinaryOp, # defines '.*' for T=A.*B
124+
A::GrB_Matrix, # first input: matrix A
125+
B::GrB_Matrix, # second input: matrix B
126+
desc::GrB_Descriptor # descriptor for C, Mask, A, and B
127+
)
128+
129+
return GrB_Info(
130+
ccall(
131+
dlsym(graphblas_lib, fn_name),
132+
Cint,
133+
(Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}),
134+
C.p, Mask.p, accum.p, mult.p, A.p, B.p, desc.p
135+
)
136+
)
137+
end

src/SuiteSparseGraphBLAS.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ include("Object_Methods/Algebra_Methods.jl")
139139
include("Object_Methods/Descriptor_Methods.jl")
140140
include("Object_Methods/Print_Objects.jl")
141141
include("Operations/Multiplication.jl")
142+
include("Operations/Element_wise_multiplication.jl")
142143

143144
export
144145
# Context Methods
@@ -164,7 +165,14 @@ GrB_UnaryOp_new, GrB_BinaryOp_new, GrB_Monoid_new, GrB_Semiring_new,
164165
@GxB_Matrix_fprint, @GxB_Vector_fprint, @GxB_Descriptor_fprint, @GxB_fprint,
165166

166167
# GraphBLAS Operations
167-
GrB_mxm, GrB_vxm, GrB_mxv
168+
169+
# Multiplication
170+
GrB_mxm, GrB_vxm, GrB_mxv,
171+
172+
# Element wise multiplication
173+
GrB_eWiseMult_Vector_Semiring, GrB_eWiseMult_Vector_Monoid, GrB_eWiseMult_Vector_BinaryOp,
174+
GrB_eWiseMult_Matrix_Semiring, GrB_eWiseMult_Matrix_Monoid, GrB_eWiseMult_Matrix_BinaryOp,
175+
GrB_eWiseMult
168176

169177
# Export global variables
170178

src/Utils.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ function suffix(T::DataType)
2323
return "FP64"
2424
end
2525

26+
function get_struct_name(A::GrB_Struct)
27+
s = ""
28+
for i in string(typeof(A))[5:end]
29+
i == '{' && break
30+
s *= i
31+
end
32+
return s
33+
end
34+
2635
function _GrB_Index(x::T) where T <: GrB_Index
2736
x > typemax(Int64) && return x
2837
return Int64(x)

0 commit comments

Comments
 (0)