Skip to content

Commit 60c5e1e

Browse files
committed
Merge global_ into global_options.
1 parent 8d9eb2c commit 60c5e1e

File tree

4 files changed

+71
-75
lines changed

4 files changed

+71
-75
lines changed

suitesparse_graphblas/api/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
container,
2626
context,
2727
descriptor,
28-
global_,
2928
global_options,
3029
grb_type,
3130
indexbinaryop,

suitesparse_graphblas/api/global_.py

Lines changed: 0 additions & 72 deletions
This file was deleted.

suitesparse_graphblas/api/global_options.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,74 @@ def global_option_get_char(field):
7474
f"GxB_Global_Option_get_CHAR failed with info={info}"
7575
)
7676
return ffi.string(val[0]).decode()
77+
78+
79+
def global_get_int32(field):
80+
"""Get a global property as an int32.
81+
82+
>>> isinstance(global_get_int32(lib.GxB_NTHREADS), int)
83+
True
84+
85+
"""
86+
val = ffi.new("int32_t*")
87+
info = lib.GrB_Global_get_INT32(lib.GrB_GLOBAL, val, field)
88+
if info != lib.GrB_SUCCESS:
89+
raise _error_code_lookup.get(info, RuntimeError)(
90+
f"GrB_Global_get_INT32 failed with info={info}"
91+
)
92+
return val[0]
93+
94+
95+
def global_set_int32(field, value):
96+
"""Set a global property from an int32.
97+
98+
>>> nthreads = global_get_int32(lib.GxB_NTHREADS)
99+
>>> global_set_int32(lib.GxB_NTHREADS, nthreads)
100+
101+
"""
102+
info = lib.GrB_Global_set_INT32(lib.GrB_GLOBAL, ffi.cast("int32_t", value), field)
103+
if info != lib.GrB_SUCCESS:
104+
raise _error_code_lookup.get(info, RuntimeError)(
105+
f"GrB_Global_set_INT32 failed with info={info}"
106+
)
107+
108+
109+
def global_get_size(field):
110+
"""Get a global property as a size_t.
111+
112+
>>> isinstance(global_get_size(lib.GrB_NAME), int)
113+
True
114+
115+
"""
116+
val = ffi.new("size_t*")
117+
info = lib.GrB_Global_get_SIZE(lib.GrB_GLOBAL, val, field)
118+
if info != lib.GrB_SUCCESS:
119+
raise _error_code_lookup.get(info, RuntimeError)(
120+
f"GrB_Global_get_SIZE failed with info={info}"
121+
)
122+
return val[0]
123+
124+
125+
def global_get_string(field):
126+
"""Get a global property as a string.
127+
128+
>>> 'SuiteSparse:GraphBLAS' in global_get_string(lib.GrB_NAME)
129+
True
130+
131+
"""
132+
val = ffi.new("char[256]")
133+
info = lib.GrB_Global_get_String(lib.GrB_GLOBAL, val, field)
134+
if info != lib.GrB_SUCCESS:
135+
raise _error_code_lookup.get(info, RuntimeError)(
136+
f"GrB_Global_get_String failed with info={info}"
137+
)
138+
return ffi.string(val).decode()
139+
140+
141+
def global_set_string(field, value):
142+
"""Set a global property from a string."""
143+
info = lib.GrB_Global_set_String(lib.GrB_GLOBAL, value.encode(), field)
144+
if info != lib.GrB_SUCCESS:
145+
raise _error_code_lookup.get(info, RuntimeError)(
146+
f"GrB_Global_set_String failed with info={info}"
147+
)

suitesparse_graphblas/tests/test_doctest.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ def test_run_doctests():
66
container,
77
context,
88
descriptor,
9-
global_,
109
global_options,
1110
grb_type,
1211
indexbinaryop,
@@ -38,6 +37,5 @@ def test_run_doctests():
3837
descriptor,
3938
selectop,
4039
container,
41-
global_,
4240
):
4341
doctest.testmod(mod, optionflags=doctest.ELLIPSIS, raise_on_error=True)

0 commit comments

Comments
 (0)