Skip to content

Commit 442c63a

Browse files
committed
Add GraphBLAS operations, iterators, and option accessors to functional API
Operations (matrix.py / vector.py): - mxm, mxv, vxm, transpose, kronecker - eWiseAdd, eWiseMult, eWiseUnion - apply, apply_first, apply_second, select - reduce (to vector and scalar), vector reduce - assign, assign_scalar, extract, col_extract, row/col_assign - build and extractTuples for all 13 element types - concat, diag (matrix), diag (vector) - dup, clear, wait, print, fprint Scalar operations (scalar.py): - dup, clear, wait, print, fprint Iterator module (new file iterator.py): - iterator_new / iterator_free - matrix entry, row, column, and vector iterator attach/seek/next - Row/column index getters, kount, getp/getpmax - Type-specific value getters for all 13 types - Column iterators require GxB_BY_COL matrix format Global and per-object option accessors (__init__.py, matrix.py, vector.py): - global_option_get/set for INT32, FP64, CHAR - matrix_option_get/set for INT32, FP64 - vector_option_get/set for INT32, FP64 All 1046 doctests pass. 9 pytest tests pass.
1 parent 5989360 commit 442c63a

6 files changed

Lines changed: 3136 additions & 1 deletion

File tree

suitesparse_graphblas/__init__.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,86 @@ def libget(name):
108108
raise
109109

110110

111+
# ---------------------------------------------------------------------------
112+
# Global option get/set
113+
# ---------------------------------------------------------------------------
114+
115+
116+
def global_option_get_int32(field):
117+
"""Get a global option as an int32.
118+
119+
>>> global_option_get_int32(lib.GxB_BURBLE) in (0, 1)
120+
True
121+
122+
"""
123+
val = ffi.new("int32_t*")
124+
info = lib.GxB_Global_Option_get_INT32(field, val)
125+
if info != lib.GrB_SUCCESS:
126+
raise _error_code_lookup.get(info, RuntimeError)(
127+
f"GxB_Global_Option_get_INT32 failed with info={info}"
128+
)
129+
return val[0]
130+
131+
132+
def global_option_set_int32(field, value):
133+
"""Set a global option from an int32.
134+
135+
>>> global_option_set_int32(lib.GxB_BURBLE, 0)
136+
137+
"""
138+
info = lib.GxB_Global_Option_set_INT32(field, ffi.cast("int32_t", value))
139+
if info != lib.GrB_SUCCESS:
140+
raise _error_code_lookup.get(info, RuntimeError)(
141+
f"GxB_Global_Option_set_INT32 failed with info={info}"
142+
)
143+
144+
145+
def global_option_get_fp64(field):
146+
"""Get a global option as a float64.
147+
148+
>>> isinstance(global_option_get_fp64(lib.GxB_HYPER_SWITCH), float)
149+
True
150+
151+
"""
152+
val = ffi.new("double*")
153+
info = lib.GxB_Global_Option_get_FP64(field, val)
154+
if info != lib.GrB_SUCCESS:
155+
raise _error_code_lookup.get(info, RuntimeError)(
156+
f"GxB_Global_Option_get_FP64 failed with info={info}"
157+
)
158+
return val[0]
159+
160+
161+
def global_option_set_fp64(field, value):
162+
"""Set a global option from a float64.
163+
164+
>>> default = global_option_get_fp64(lib.GxB_HYPER_SWITCH)
165+
>>> global_option_set_fp64(lib.GxB_HYPER_SWITCH, default)
166+
167+
"""
168+
info = lib.GxB_Global_Option_set_FP64(field, ffi.cast("double", value))
169+
if info != lib.GrB_SUCCESS:
170+
raise _error_code_lookup.get(info, RuntimeError)(
171+
f"GxB_Global_Option_set_FP64 failed with info={info}"
172+
)
173+
174+
175+
def global_option_get_char(field):
176+
"""Get a global option as a string.
177+
178+
>>> 'SuiteSparse:GraphBLAS' in global_option_get_char(lib.GxB_LIBRARY_NAME)
179+
True
180+
181+
"""
182+
val = ffi.new("char**")
183+
info = lib.GxB_Global_Option_get_CHAR(field, val)
184+
if info != lib.GrB_SUCCESS:
185+
raise _error_code_lookup.get(info, RuntimeError)(
186+
f"GxB_Global_Option_get_CHAR failed with info={info}"
187+
)
188+
return ffi.string(val[0]).decode()
189+
190+
111191
bool_types = frozenset((lib.GrB_BOOL,))
112192

113193
signed_integer_types = frozenset(

0 commit comments

Comments
 (0)