Skip to content

Commit dcdc91b

Browse files
add free methods
1 parent 87d8eca commit dcdc91b

File tree

2 files changed

+186
-0
lines changed

2 files changed

+186
-0
lines changed

src/Object_Methods/Free_Objects.jl

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
"""
2+
GrB_free(object)
3+
4+
Generic method to free a GraphBLAS object.
5+
6+
# Examples
7+
```jldoctest
8+
julia> using SuiteSparseGraphBLAS
9+
10+
julia> w = GrB_Vector{Int64}()
11+
GrB_Vector{Int64}
12+
13+
julia> I = [0, 2, 4]; X = [10, 20, 30]; n = 3;
14+
15+
julia> GrB_Vector_new(w, GrB_INT64, 5)
16+
GrB_SUCCESS::GrB_Info = 0
17+
18+
julia> GrB_Vector_build(w, I, X, n, GrB_FIRST_INT64)
19+
GrB_SUCCESS::GrB_Info = 0
20+
21+
julia> @GxB_fprint(w, GxB_COMPLETE)
22+
23+
GraphBLAS vector: w
24+
nrows: 5 ncols: 1 max # entries: 3
25+
format: standard CSC vlen: 5 nvec_nonempty: 1 nvec: 1 plen: 1 vdim: 1
26+
hyper_ratio 0.0625
27+
GraphBLAS type: int64_t size: 8
28+
number of entries: 3
29+
column: 0 : 3 entries [0:2]
30+
row 0: int64 10
31+
row 2: int64 20
32+
row 4: int64 30
33+
34+
35+
julia> GrB_free(w)
36+
GrB_SUCCESS::GrB_Info = 0
37+
38+
julia> @GxB_fprint(w, GxB_COMPLETE)
39+
40+
GraphBLAS vector: w NULL
41+
```
42+
"""
43+
function GrB_free(object::GrB_Struct)
44+
object_ptr = pointer_from_objref(object)
45+
fn_name = "GrB_" * get_struct_name(object) * "_free"
46+
47+
return GrB_Info(
48+
ccall(
49+
dlsym(graphblas_lib, fn_name),
50+
Cint,
51+
(Ptr{Cvoid}, ),
52+
object_ptr
53+
)
54+
)
55+
end
56+
57+
"""
58+
GrB_UnaryOp_free(unaryop)
59+
60+
Free unary operator.
61+
"""
62+
function GrB_UnaryOp_free(unaryop::GrB_UnaryOp)
63+
unaryop_ptr = pointer_from_objref(unaryop)
64+
65+
return GrB_Info(
66+
ccall(
67+
dlsym(graphblas_lib, "GrB_UnaryOp_free"),
68+
Cint,
69+
(Ptr{Cvoid}, ),
70+
unaryop_ptr
71+
)
72+
)
73+
end
74+
75+
"""
76+
GrB_BinaryOp_free(binaryop)
77+
78+
Free binary operator.
79+
"""
80+
function GrB_BinaryOp_free(binaryop::GrB_BinaryOp)
81+
binaryop_ptr = pointer_from_objref(binaryop)
82+
83+
return GrB_Info(
84+
ccall(
85+
dlsym(graphblas_lib, "GrB_BinaryOp_free"),
86+
Cint,
87+
(Ptr{Cvoid}, ),
88+
binaryop_ptr
89+
)
90+
)
91+
end
92+
93+
"""
94+
GrB_Monoid_free(monoid)
95+
96+
Free monoid.
97+
"""
98+
function GrB_Monoid_free(monoid::GrB_Monoid)
99+
monoid_ptr = pointer_from_objref(monoid)
100+
101+
return GrB_Info(
102+
ccall(
103+
dlsym(graphblas_lib, "GrB_Monoid_free"),
104+
Cint,
105+
(Ptr{Cvoid}, ),
106+
monoid_ptr
107+
)
108+
)
109+
end
110+
111+
"""
112+
GrB_Semiring_free(semiring)
113+
114+
Free semiring.
115+
"""
116+
function GrB_Semiring_free(semiring::GrB_Semiring)
117+
semiring_ptr = pointer_from_objref(semiring)
118+
119+
return GrB_Info(
120+
ccall(
121+
dlsym(graphblas_lib, "GrB_Semiring_free"),
122+
Cint,
123+
(Ptr{Cvoid}, ),
124+
semiring_ptr
125+
)
126+
)
127+
end
128+
129+
"""
130+
GrB_Vector_free(v)
131+
132+
Free vector.
133+
"""
134+
function GrB_Vector_free(v::GrB_Vector)
135+
v_ptr = pointer_from_objref(v)
136+
137+
return GrB_Info(
138+
ccall(
139+
dlsym(graphblas_lib, "GrB_Vector_free"),
140+
Cint,
141+
(Ptr{Cvoid}, ),
142+
v_ptr
143+
)
144+
)
145+
end
146+
147+
"""
148+
GrB_Matrix_free(A)
149+
150+
Free matrix.
151+
"""
152+
function GrB_Matrix_free(A::GrB_Matrix)
153+
A_ptr = pointer_from_objref(A)
154+
155+
return GrB_Info(
156+
ccall(
157+
dlsym(graphblas_lib, "GrB_Matrix_free"),
158+
Cint,
159+
(Ptr{Cvoid}, ),
160+
A_ptr
161+
)
162+
)
163+
end
164+
165+
"""
166+
GrB_Descriptor_free(desc)
167+
168+
Free descriptor.
169+
"""
170+
function GrB_Descriptor_free(desc::GrB_Descriptor)
171+
desc_ptr = pointer_from_objref(desc)
172+
173+
return GrB_Info(
174+
ccall(
175+
dlsym(graphblas_lib, "GrB_Descriptor_free"),
176+
Cint,
177+
(Ptr{Cvoid}, ),
178+
desc_ptr
179+
)
180+
)
181+
end

src/SuiteSparseGraphBLAS.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ include("Object_Methods/Vector_Methods.jl")
146146
include("Object_Methods/Algebra_Methods.jl")
147147
include("Object_Methods/Descriptor_Methods.jl")
148148
include("Object_Methods/Print_Objects.jl")
149+
include("Object_Methods/Free_Objects.jl")
149150
include("Operations/Multiplication.jl")
150151
include("Operations/Element_wise_multiplication.jl")
151152
include("Operations/Element_wise_addition.jl")
@@ -174,6 +175,10 @@ GrB_Descriptor_new, GrB_Descriptor_set,
174175
# Algebra Methods
175176
GrB_UnaryOp_new, GrB_BinaryOp_new, GrB_Monoid_new, GrB_Semiring_new,
176177

178+
# Free Methods
179+
GrB_free, GrB_UnaryOp_free, GrB_BinaryOp_free, GrB_Monoid_free, GrB_Semiring_free,
180+
GrB_Vector_free, GrB_Matrix_free, GrB_Descriptor_free,
181+
177182
# Print functions
178183
@GxB_UnaryOp_fprint, @GxB_BinaryOp_fprint, @GxB_Monoid_fprint, @GxB_Semiring_fprint,
179184
@GxB_Matrix_fprint, @GxB_Vector_fprint, @GxB_Descriptor_fprint, @GxB_fprint,

0 commit comments

Comments
 (0)