Skip to content

Commit be4561d

Browse files
add descriptor methods
1 parent 0373f17 commit be4561d

File tree

5 files changed

+80
-2
lines changed

5 files changed

+80
-2
lines changed

src/Enums.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,21 @@ end
3434
GxB_SHORT = 2 # short description about 30 entries of a matrix
3535
GxB_COMPLETE = 3 # print the entire contents of the object
3636
end
37+
38+
@enum GrB_Desc_Field begin
39+
GrB_OUTP = 0 # descriptor for output of a method
40+
GrB_MASK = 1 # descriptor for the mask input of a method
41+
GrB_INP0 = 2 # descriptor for the first input of a method
42+
GrB_INP1 = 3 # descriptor for the second input of a method
43+
end
44+
45+
@enum GrB_Desc_Value begin
46+
# for all GrB_Descriptor fields:
47+
GxB_DEFAULT = 0 # default behavior of the method
48+
# for GrB_OUTP only:
49+
GrB_REPLACE = 1 # clear the output before assigning new values to it
50+
# for GrB_MASK only:
51+
GrB_SCMP = 2 # use the structural complement of the input
52+
# for GrB_INP0 and GrB_INP1 only:
53+
GrB_TRAN = 3 # use the transpose of the input
54+
end
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
function GrB_Descriptor_new(descriptor::GrB_Descriptor)
2+
desc_ptr = pointer_from_objref(descriptor)
3+
4+
return GrB_Info(
5+
ccall(
6+
dlsym(graphblas_lib, "GrB_Descriptor_new"),
7+
Cint,
8+
(Ptr{Cvoid}, ),
9+
desc_ptr
10+
)
11+
)
12+
end
13+
14+
function GrB_Descriptor_set(desc::GrB_Descriptor, field::GrB_Desc_Field, val::GrB_Desc_Value)
15+
return GrB_Info(
16+
ccall(
17+
dlsym(graphblas_lib, "GrB_Descriptor_set"),
18+
Cint,
19+
(Ptr{Cvoid}, Cint, Cint),
20+
desc.p, field, val
21+
)
22+
)
23+
end

src/Object_Methods/Print_Objects.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,18 @@ macro GxB_Vector_fprint(v, pr)
2727
name = string(v)
2828
return :(GxB_Vector_fprint($(esc(v)), $name, $pr))
2929
end
30+
31+
function GxB_Descriptor_fprint(desc::GrB_Descriptor, name::String, pr::GxB_Print_Level)
32+
function fn(path, io)
33+
FILE = Libc.FILE(io)
34+
ccall(dlsym(graphblas_lib, "GxB_Descriptor_fprint"), Cint, (Ptr{Cvoid}, Ptr{UInt8}, Cint, Ptr{Cvoid}), desc.p, pointer(name), pr, FILE)
35+
ccall(:fclose, Cint, (Ptr{Cvoid},), FILE)
36+
foreach(println, eachline(path))
37+
end
38+
mktemp(fn)
39+
end
40+
41+
macro GxB_Descriptor_fprint(desc, pr)
42+
name = string(desc)
43+
return :(GxB_Descriptor_fprint($(esc(desc)), $name, $pr))
44+
end

src/Structures.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Base.show
22
import Base.==
3-
export GrB_Type, GrB_UnaryOp, GrB_BinaryOp, GrB_Vector, GrB_Matrix
3+
export GrB_Type, GrB_UnaryOp, GrB_BinaryOp, GrB_Vector, GrB_Matrix, GrB_Descriptor
44

55
mutable struct GrB_Type
66
p::Ptr{Cvoid}
@@ -34,3 +34,9 @@ mutable struct GrB_Matrix{T}
3434
end
3535
GrB_Matrix{T}() where T = GrB_Matrix{T}(Ptr{Cvoid}(0))
3636
Base.show(io::IO, ::GrB_Matrix{T}) where T = print("GrB_Matrix{" * string(T) * "}")
37+
38+
mutable struct GrB_Descriptor
39+
p::Ptr{Cvoid}
40+
end
41+
GrB_Descriptor() = GrB_Descriptor(Ptr{Cvoid}(0))
42+
Base.show(io::IO, ::GrB_Descriptor) = print("GrB_Descriptor")

src/SuiteSparseGraphBLAS.jl

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ include("Context_Methods.jl")
7272
include("Utils.jl")
7373
include("Object_Methods/Matrix_Methods.jl")
7474
include("Object_Methods/Vector_Methods.jl")
75+
include("Object_Methods/Descriptor_Methods.jl")
7576
include("Object_Methods/Print_Objects.jl")
7677

7778
export
@@ -87,8 +88,11 @@ GrB_Matrix_extractElement, GrB_Matrix_extractTuples,
8788
GrB_Vector_new, GrB_Vector_build, GrB_Vector_dup, GrB_Vector_clear, GrB_Vector_size,
8889
GrB_Vector_nvals, GrB_Vector_setElement, GrB_Vector_extractElement, GrB_Vector_extractTuples,
8990

91+
# Descriptor Methods
92+
GrB_Descriptor_new, GrB_Descriptor_set,
93+
9094
# Print functions
91-
@GxB_Matrix_fprint, @GxB_Vector_fprint
95+
@GxB_Matrix_fprint, @GxB_Vector_fprint, @GxB_Descriptor_fprint
9296

9397
# Export global variables
9498

@@ -116,16 +120,28 @@ for op in binary_operators
116120
end
117121

118122
# Enums
123+
export GrB_Info
119124
for s in instances(GrB_Info)
120125
@eval export $(Symbol(s))
121126
end
122127

128+
export GrB_Mode
123129
for s in instances(GrB_Mode)
124130
@eval export $(Symbol(s))
125131
end
126132

133+
export GxB_Print_Level
127134
for s in instances(GxB_Print_Level)
128135
@eval export $(Symbol(s))
129136
end
130137

138+
export GrB_Desc_Field
139+
for s in instances(GrB_Desc_Field)
140+
@eval export $(Symbol(s))
141+
end
142+
143+
export GrB_Desc_Value
144+
for s in instances(GrB_Desc_Value)
145+
@eval export $(Symbol(s))
146+
end
131147
end #end of module

0 commit comments

Comments
 (0)