Skip to content

Commit 800c44c

Browse files
committed
forward declare Structural, generalize descriptor
1 parent dd78000 commit 800c44c

File tree

2 files changed

+27
-84
lines changed

2 files changed

+27
-84
lines changed

src/descriptors.jl

Lines changed: 23 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -36,116 +36,59 @@ end
3636

3737
Base.unsafe_convert(::Type{LibGraphBLAS.GrB_Descriptor}, d::Descriptor) = d.p
3838

39-
# Todo: improve these. They can't be wrapped by ccall because they're "generic"?
40-
# Or at least not wrapped by Clang.jl
41-
function GxB_Desc_get(desc, field)
42-
if field [LibGraphBLAS.GrB_OUTP, LibGraphBLAS.GrB_MASK, LibGraphBLAS.GrB_INP0, LibGraphBLAS.GrB_INP1]
43-
T = LibGraphBLAS.GrB_Desc_Value
44-
elseif field [LibGraphBLAS.GxB_DESCRIPTOR_NTHREADS, LibGraphBLAS.GxB_AxB_METHOD, LibGraphBLAS.GxB_SORT]
45-
T = Cint
46-
elseif field [LibGraphBLAS.GxB_DESCRIPTOR_CHUNK]
47-
T = Cdouble
48-
else
49-
error("Not a valid Descriptor option.")
50-
end
51-
v = Ref{T}()
52-
@wraperror ccall(
53-
(:GxB_Desc_get, libgraphblas),
54-
LibGraphBLAS.GrB_Info,
55-
(LibGraphBLAS.GrB_Descriptor, UInt32, Ptr{Cvoid}),
56-
desc,
57-
field,
58-
v
59-
)
60-
return v[]
61-
end
62-
63-
function GxB_Desc_set(d, field, value)
64-
if field [LibGraphBLAS.GrB_OUTP, LibGraphBLAS.GrB_MASK, LibGraphBLAS.GrB_INP0, LibGraphBLAS.GrB_INP1]
65-
@wraperror ccall(
66-
(:GxB_Desc_set, libgraphblas),
67-
LibGraphBLAS.GrB_Info,
68-
(LibGraphBLAS.GrB_Descriptor, LibGraphBLAS.GrB_Desc_Field, LibGraphBLAS.GrB_Desc_Value),
69-
d,
70-
field,
71-
value
72-
)
73-
elseif field [LibGraphBLAS.GxB_DESCRIPTOR_NTHREADS, LibGraphBLAS.GxB_AxB_METHOD, LibGraphBLAS.GxB_SORT]
74-
@wraperror ccall(
75-
(:GxB_Desc_set, libgraphblas),
76-
LibGraphBLAS.GrB_Info,
77-
(LibGraphBLAS.GrB_Descriptor, LibGraphBLAS.GrB_Desc_Field, Cint),
78-
d,
79-
field,
80-
value
81-
)
82-
# chunk is broken, not clear why...
83-
# elseif field ∈ [LibGraphBLAS.GxB_DESCRIPTOR_CHUNK]
84-
# @wraperror ccall(
85-
# (:GxB_Desc_set, libgraphblas),
86-
# LibGraphBLAS.GrB_Info,
87-
# (LibGraphBLAS.GrB_Descriptor, LibGraphBLAS.GrB_Desc_Field, Cdouble),
88-
# d,
89-
# field,
90-
# value
91-
# )
92-
end
93-
end
94-
9539
Base.:+(a::LibGraphBLAS.GrB_Desc_Value, b::LibGraphBLAS.GrB_Desc_Value) =
9640
Integer(a) + Integer(b)
9741

98-
9942
function Base.getproperty(d::Descriptor, s::Symbol)
10043
if s === :p
10144
return getfield(d, s)
10245
elseif s === :replace_output
103-
x = GxB_Desc_get(d, LibGraphBLAS.GrB_OUTP)
46+
x = LibGraphBLAS.GxB_Desc_get(d, LibGraphBLAS.GrB_OUTP)
10447
if x == LibGraphBLAS.GrB_REPLACE
10548
return true
10649
else
10750
return false
10851
end
10952
elseif s === :complement_mask
110-
x = GxB_Desc_get(d, LibGraphBLAS.GrB_MASK)
111-
if x == LibGraphBLAS.GrB_COMP || x == LibGraphBLAS.GrB_STRUCTURE + LibGraphBLAS.GrB_COMP
53+
x = LibGraphBLAS.GxB_Desc_get(d, LibGraphBLAS.GrB_MASK)
54+
if x == LibGraphBLAS.GrB_COMP || x == (LibGraphBLAS.GrB_STRUCTURE + LibGraphBLAS.GrB_COMP)
11255
return true
11356
else
11457
return false
11558
end
11659
elseif s === :structural_mask
117-
x = GxB_Desc_get(d, LibGraphBLAS.GrB_MASK)
60+
x = LibGraphBLAS.GxB_Desc_get(d, LibGraphBLAS.GrB_MASK)
11861
if x == LibGraphBLAS.GrB_STRUCTURE || x == (LibGraphBLAS.GrB_STRUCTURE + LibGraphBLAS.GrB_COMP)
11962
return true
12063
else
12164
return false
12265
end
12366
elseif s === :transpose_input1
124-
x = GxB_Desc_get(d, LibGraphBLAS.GrB_INP0)
67+
x = LibGraphBLAS.GxB_Desc_get(d, LibGraphBLAS.GrB_INP0)
12568
if x == LibGraphBLAS.GrB_TRAN
12669
return true
12770
else
12871
return false
12972
end
13073
elseif s === :transpose_input2
131-
x = GxB_Desc_get(d, LibGraphBLAS.GrB_INP1)
74+
x = LibGraphBLAS.GxB_Desc_get(d, LibGraphBLAS.GrB_INP1)
13275
if x == LibGraphBLAS.GrB_TRAN
13376
return true
13477
else
13578
return false
13679
end
13780
elseif s === :nthreads
138-
return GxB_Desc_get(d, LibGraphBLAS.GxB_DESCRIPTOR_NTHREADS)
81+
return LibGraphBLAS.GxB_Desc_get(d, LibGraphBLAS.GxB_DESCRIPTOR_NTHREADS)
13982
elseif s === :chunk
140-
return GxB_Desc_get(d, LibGraphBLAS.GxB_DESCRIPTOR_CHUNK)
83+
return LibGraphBLAS.GxB_Desc_get(d, LibGraphBLAS.GxB_DESCRIPTOR_CHUNK)
14184
elseif s === :sort
142-
if GxB_Desc_get(d, LibGraphBLAS.GxB_SORT) == LibGraphBLAS.GxB_DEFAULT
85+
if LibGraphBLAS.GxB_Desc_get(d, LibGraphBLAS.GxB_SORT) == LibGraphBLAS.GxB_DEFAULT
14386
return false
14487
else
14588
return true
14689
end
14790
elseif s === :axb_method
148-
x = GxB_Desc_get(d, LibGraphBLAS.GxB_AxB_METHOD)
91+
x = LibGraphBLAS.GxB_Desc_get(d, LibGraphBLAS.GxB_AxB_METHOD)
14992
if x == LibGraphBLAS.GxB_AxB_GUSTAVSON
15093
return :gustavson
15194
elseif x == LibGraphBLAS.GxB_AxB_DOT
@@ -168,41 +111,41 @@ function Base.setproperty!(d::Descriptor, s::Symbol, x)
168111
return nothing
169112
elseif s === :replace_output
170113
x ? (y = LibGraphBLAS.GrB_REPLACE) : (y = LibGraphBLAS.GxB_DEFAULT)
171-
GxB_Desc_set(d, LibGraphBLAS.GrB_OUTP, y)
114+
LibGraphBLAS.GxB_Desc_set(d, LibGraphBLAS.GrB_OUTP, y)
172115
elseif s === :complement_mask
173116
if x == false
174117
if d.structural_mask
175-
GxB_Desc_set(d, LibGraphBLAS.GrB_MASK, LibGraphBLAS.GrB_STRUCTURE)
118+
LibGraphBLAS.GxB_Desc_set(d, LibGraphBLAS.GrB_MASK, LibGraphBLAS.GrB_STRUCTURE)
176119
else
177-
GxB_Desc_set(d, LibGraphBLAS.GrB_MASK, LibGraphBLAS.GxB_DEFAULT)
120+
LibGraphBLAS.GxB_Desc_set(d, LibGraphBLAS.GrB_MASK, LibGraphBLAS.GxB_DEFAULT)
178121
end
179122
else
180123
if d.structural_mask
181-
GxB_Desc_set(d, LibGraphBLAS.GrB_MASK, LibGraphBLAS.GrB_STRUCTURE + LibGraphBLAS.GrB_COMP)
124+
LibGraphBLAS.GxB_Desc_set(d, LibGraphBLAS.GrB_MASK, LibGraphBLAS.GrB_STRUCTURE + LibGraphBLAS.GrB_COMP)
182125
else
183-
GxB_Desc_set(d, LibGraphBLAS.GrB_MASK, LibGraphBLAS.GrB_COMP)
126+
LibGraphBLAS.GxB_Desc_set(d, LibGraphBLAS.GrB_MASK, LibGraphBLAS.GrB_COMP)
184127
end
185128
end
186129
elseif s === :structural_mask
187130
if x == false
188131
if d.complement_mask
189-
GxB_Desc_set(d, LibGraphBLAS.GrB_MASK, LibGraphBLAS.GrB_COMP)
132+
LibGraphBLAS.GxB_Desc_set(d, LibGraphBLAS.GrB_MASK, LibGraphBLAS.GrB_COMP)
190133
else
191-
GxB_Desc_set(d, LibGraphBLAS.GrB_MASK, LibGraphBLAS.GxB_DEFAULT)
134+
LibGraphBLAS.GxB_Desc_set(d, LibGraphBLAS.GrB_MASK, LibGraphBLAS.GxB_DEFAULT)
192135
end
193136
else
194-
GxB_Desc_set(d, LibGraphBLAS.GrB_MASK, LibGraphBLAS.GrB_STRUCTURE)
137+
LibGraphBLAS.GxB_Desc_set(d, LibGraphBLAS.GrB_MASK, LibGraphBLAS.GrB_STRUCTURE)
195138
end
196139
elseif s === :transpose_input1
197-
GxB_Desc_set(d, LibGraphBLAS.GrB_INP0, x ? LibGraphBLAS.GrB_TRAN : LibGraphBLAS.GxB_DEFAULT)
140+
LibGraphBLAS.GxB_Desc_set(d, LibGraphBLAS.GrB_INP0, x ? LibGraphBLAS.GrB_TRAN : LibGraphBLAS.GxB_DEFAULT)
198141
elseif s === :transpose_input2
199-
GxB_Desc_set(d, LibGraphBLAS.GrB_INP1, x ? LibGraphBLAS.GrB_TRAN : LibGraphBLAS.GxB_DEFAULT)
142+
LibGraphBLAS.GxB_Desc_set(d, LibGraphBLAS.GrB_INP1, x ? LibGraphBLAS.GrB_TRAN : LibGraphBLAS.GxB_DEFAULT)
200143
elseif s === :nthreads
201-
GxB_Desc_set(d, LibGraphBLAS.GxB_DESCRIPTOR_NTHREADS, x)
144+
LibGraphBLAS.GxB_Desc_set(d, LibGraphBLAS.GxB_DESCRIPTOR_NTHREADS, x)
202145
elseif s === :chunk
203-
GxB_Desc_set(d, LibGraphBLAS.GxB_DESCRIPTOR_CHUNK, x)
146+
LibGraphBLAS.GxB_Desc_set(d, LibGraphBLAS.GxB_DESCRIPTOR_CHUNK, x)
204147
elseif s === :sort
205-
GxB_Desc_set(d, LibGraphBLAS.GxB_SORT, x ? 3 : 0)
148+
LibGraphBLAS.GxB_Desc_set(d, LibGraphBLAS.GxB_SORT, x ? 3 : 0)
206149
end
207150
end
208151
function Base.propertynames(::Descriptor)

src/operations/operationutils.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ struct Complement{T}
1818
parent::T
1919
end
2020

21+
struct Structural{T}
22+
parent::T
23+
end
24+
2125
Complement(A::T) where {
2226
T<:Union{GBArrayOrTranspose,
2327
Structural{<:GBArrayOrTranspose},
@@ -30,10 +34,6 @@ Base.:~(A::T) where {
3034
} = Complement(A)
3135
Base.parent(C::Complement) = C.parent
3236

33-
struct Structural{T}
34-
parent::T
35-
end
36-
3737
Structural(A::T) where {T<:GBArrayOrTranspose}= Structural{T}(A)
3838
Base.parent(C::Structural) = C.parent
3939

0 commit comments

Comments
 (0)