Skip to content

Commit 927e430

Browse files
committed
Prefix matrix/vector/scalar helper functions with module name
The metadata/utility helpers in matrix.py, vector.py, and scalar.py were named after generic concepts (`new`, `free`, `type`, `format`, `shape`, `size`, etc.). Several of those names shadow Python builtins (`type`, `format`) or collide with common variables, making bare imports awkward (`from suitesparse_graphblas.matrix import type` is asking for trouble). Prefix every helper with its module name so each function is unambiguous on import: matrix.py (16 helpers): free / new / type / nrows / ncols / nvals / shape / format / set_format / sparsity_status / sparsity_control / set_sparsity_control / hyper_switch / set_hyper_switch / bitmap_switch / set_bitmap_switch -> matrix_free, matrix_new, matrix_type, ..., matrix_set_bitmap_switch vector.py (5 helpers): free / new / type / size / nvals -> vector_free, vector_new, vector_type, vector_size, vector_nvals scalar.py (3 helpers): free / new / type -> scalar_free, scalar_new, scalar_type The element setters/getters (set_bool, get_bool, set_int8, get_int8, ..., set_fc64, get_fc64) are NOT renamed -- they already have a clear set_*/get_* naming convention. Internal cross-references updated: - `def matrix_new(T, ..., *, free=matrix_free)` -- the default value of the `free` keyword argument now references the renamed module-level function. The kwarg parameter name itself stays as `free` so existing callers passing `free=None` or `free=my_func` still work. - `matrix_shape()` body now calls `matrix_nrows(A)` and `matrix_ncols(A)`. - All in-module doctests updated: `>>> A = new(...)` -> `>>> A = matrix_new(...)`, `>>> nrows(A)` -> `>>> matrix_nrows(A)`, etc. Element setter/getter doctests that call `new(...)` to construct test instances are also updated to use the prefixed name. - Local variable shadows (e.g. `format = ffi.new(...)` inside `matrix_format()`) and kwarg parameter names (e.g. `format` in `matrix_set_format(A, format)`) are intentionally left alone -- they are local and don't reference the renamed functions. - `ffi.new(...)` (cffi calls) is preserved -- distinguished from the renamed `new(...)` via a negative lookbehind in the rename pattern. External call sites updated: - `suitesparse_graphblas/__init__.py`: `burble` class doctest references `matrix.matrix_new(...)` and `matrix.matrix_nvals(...)`. - `suitesparse_graphblas/io/binary.py`: 13 `matrix.X(...)` call sites in the binread/binwrite serialization paths now call `matrix.matrix_X(...)`. - `suitesparse_graphblas/io/serialize.py`: 2 docstring prose mentions plus 2 attribute references (`matrix.free` -> `matrix.matrix_free`, `vector.free` -> `vector.vector_free`) used as the default GC callback in `deserialize_matrix` / `deserialize_vector`. - `suitesparse_graphblas/tests/test_io.py`: 17 external call sites updated to the prefixed names. Verified by rebuilding the Docker test image and running both the full doctest suite and the pytest suite inside the container: matrix: 97 attempted, 0 failed vector: 90 attempted, 0 failed scalar: 81 attempted, 0 failed TOTAL doctest: 268 attempted, 0 failed pytest: 9 passed test_doctest, test_exceptions, test_io (matrix and vector serialization round-trip), test_jit, test_package, test_scalar
1 parent a062434 commit 927e430

7 files changed

Lines changed: 176 additions & 176 deletions

File tree

suitesparse_graphblas/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ class burble:
228228
229229
>>> from suitesparse_graphblas import burble, lib, matrix
230230
>>>
231-
>>> A = matrix.new(lib.GrB_BOOL, 3, 3)
231+
>>> A = matrix.matrix_new(lib.GrB_BOOL, 3, 3)
232232
>>> burble.is_enabled
233233
False
234234
>>> burble.enable()
@@ -239,15 +239,15 @@ class burble:
239239
Example with explicit enable and disable:
240240
241241
>>> burble.enable()
242-
>>> n = matrix.nvals(A)
242+
>>> n = matrix.matrix_nvals(A)
243243
[ GrB_Matrix_nvals
244244
1.91e-06 sec ]
245245
>>> burble.disable()
246246
247247
Example as a context manager:
248248
249249
>>> with burble():
250-
>>> n = matrix.nvals(A)
250+
>>> n = matrix.matrix_nvals(A)
251251
[ GrB_Matrix_nvals
252252
1.91e-06 sec ]
253253

suitesparse_graphblas/io/binary.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -123,19 +123,19 @@ def binwrite(A, filename, comments=None, opener=Path.open):
123123
typecode = ffinew("int32_t*")
124124
matrix_type = ffi.new("GrB_Type*")
125125

126-
nrows[0] = matrix.nrows(A)
127-
ncols[0] = matrix.ncols(A)
128-
nvals[0] = matrix.nvals(A)
129-
matrix_type[0] = matrix.type(A)
126+
nrows[0] = matrix.matrix_nrows(A)
127+
ncols[0] = matrix.matrix_ncols(A)
128+
nvals[0] = matrix.matrix_nvals(A)
129+
matrix_type[0] = matrix.matrix_type(A)
130130

131131
check_status(A, lib.GxB_Type_size(typesize, matrix_type[0]))
132132
typecode[0] = _ss_typecodes[matrix_type[0]]
133133

134-
format[0] = matrix.format(A)
135-
hyper_switch[0] = matrix.hyper_switch(A)
136-
bitmap_switch[0] = matrix.bitmap_switch(A)
137-
sparsity_status[0] = matrix.sparsity_status(A)
138-
sparsity_control[0] = matrix.sparsity_control(A)
134+
format[0] = matrix.matrix_format(A)
135+
hyper_switch[0] = matrix.matrix_hyper_switch(A)
136+
bitmap_switch[0] = matrix.matrix_bitmap_switch(A)
137+
sparsity_status[0] = matrix.matrix_sparsity_status(A)
138+
sparsity_control[0] = matrix.matrix_sparsity_control(A)
139139

140140
by_row = format[0] == lib.GxB_BY_ROW
141141
by_col = format[0] == lib.GxB_BY_COL
@@ -446,7 +446,7 @@ def binread(filename, opener=Path.open):
446446

447447
Ax[0] = readinto_new_buffer(f, "uint8_t*", typesize[0] if is_iso[0] else Ax_size[0])
448448

449-
A = matrix.new(atype, nrows[0], ncols[0])
449+
A = matrix.matrix_new(atype, nrows[0], ncols[0])
450450

451451
if by_col and is_hyper:
452452
check_status(
@@ -546,7 +546,7 @@ def binread(filename, opener=Path.open):
546546
else:
547547
raise TypeError("Unknown format {format[0]}")
548548

549-
matrix.set_sparsity_control(A, sparsity_control[0])
550-
matrix.set_hyper_switch(A, hyper_switch[0])
551-
matrix.set_bitmap_switch(A, bitmap_switch[0])
549+
matrix.matrix_set_sparsity_control(A, sparsity_control[0])
550+
matrix.matrix_set_hyper_switch(A, hyper_switch[0])
551+
matrix.matrix_set_bitmap_switch(A, bitmap_switch[0])
552552
return A

suitesparse_graphblas/io/serialize.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def deserialize_matrix(data, *, free=True, nthreads=None):
8888
"""Deserialize a Matrix from bytes.
8989
9090
The `free` argument is called when the object is garbage
91-
collected, the default is `matrix.free()`. If `free` is None then
91+
collected, the default is `matrix.matrix_free()`. If `free` is None then
9292
there is no automatic garbage collection and it is up to the user
9393
to free the matrix.
9494
"""
@@ -108,15 +108,15 @@ def deserialize_matrix(data, *, free=True, nthreads=None):
108108
if free:
109109
if callable(free):
110110
return ffi.gc(A, free)
111-
return ffi.gc(A, matrix.free)
111+
return ffi.gc(A, matrix.matrix_free)
112112
return A
113113

114114

115115
def deserialize_vector(data, *, free=True, nthreads=None):
116116
"""Deserialize a Vector from bytes.
117117
118118
The `free` argument is called when the object is garbage
119-
collected, the default is `vector.free()`. If `free` is None then
119+
collected, the default is `vector.vector_free()`. If `free` is None then
120120
there is no automatic garbage collection and it is up to the user
121121
to free the vector.
122122
"""
@@ -136,7 +136,7 @@ def deserialize_vector(data, *, free=True, nthreads=None):
136136
if free:
137137
if callable(free):
138138
return ffi.gc(v, free)
139-
return ffi.gc(v, vector.free)
139+
return ffi.gc(v, vector.vector_free)
140140
return v
141141

142142

0 commit comments

Comments
 (0)