Skip to content

Commit b4fc05a

Browse files
authored
Fix issue with Scalar_setElement_FC64 with cffi voodoo magic (#41)
* Fix issue with `Scalar_setElement_FC64` with cffi voodoo magic
1 parent 0da4f9f commit b4fc05a

File tree

5 files changed

+22
-11
lines changed

5 files changed

+22
-11
lines changed

.github/workflows/test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
- name: GraphBLAS (from conda-forge)
3535
if: (contains(matrix.source, 'conda-forge'))
3636
run: |
37-
conda install -c conda-forge graphblas=${{ matrix.graphblas-version }}
37+
conda install -c conda-forge graphblas=${{ matrix.graphblas-version }} pytest pytest-randomly
3838
- name: GraphBLAS (from source)
3939
if: (contains(matrix.source, 'source'))
4040
run: |

suitesparse_graphblas/__init__.py

+3
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ def initialize(*, blocking=False, memory_manager="numpy"):
4444
lib.GrB_init(blocking)
4545
else:
4646
raise ValueError(f'memory_manager argument must be "numpy" or "c"; got: {memory_manager!r}')
47+
# See: https://github.com/GraphBLAS/python-suitesparse-graphblas/issues/40
48+
for attr in dir(lib):
49+
getattr(lib, attr)
4750

4851

4952
def libget(name):
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import pytest
2+
3+
from suitesparse_graphblas import ffi, lib, supports_complex # noqa
4+
5+
6+
@pytest.mark.skipif("not supports_complex()")
7+
def test_complex():
8+
s = ffi.new("GrB_Scalar*")
9+
success = lib.GrB_SUCCESS
10+
assert lib.GrB_Scalar_new(s, lib.GxB_FC64) == success
11+
assert lib.GxB_Scalar_setElement_FC64(s[0], 1j) == success
12+
assert lib.GrB_Scalar_free(s) == success

suitesparse_graphblas/utils.pxd

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from libc.stdint cimport uint64_t
2-
from numpy cimport ndarray, npy_intp, dtype as dtype_t
2+
from numpy cimport dtype as dtype_t
3+
from numpy cimport ndarray, npy_intp
34

45

56
cdef extern from "numpy/arrayobject.h" nogil:

suitesparse_graphblas/utils.pyx

+4-9
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
import numpy as np
22
from cpython.ref cimport Py_INCREF
33
from libc.stdint cimport uintptr_t
4-
from numpy cimport (
5-
NPY_ARRAY_F_CONTIGUOUS,
6-
NPY_ARRAY_OWNDATA,
7-
NPY_ARRAY_WRITEABLE,
8-
import_array,
9-
ndarray,
10-
npy_intp,
11-
dtype as dtype_t,
12-
)
4+
from numpy cimport NPY_ARRAY_F_CONTIGUOUS, NPY_ARRAY_OWNDATA, NPY_ARRAY_WRITEABLE
5+
from numpy cimport dtype as dtype_t
6+
from numpy cimport import_array, ndarray, npy_intp
137

148
import_array()
159

@@ -58,6 +52,7 @@ cpdef ndarray claim_buffer_2d(
5852
dims[1] = ncols
5953
if not is_c_order:
6054
flags |= NPY_ARRAY_F_CONTIGUOUS
55+
Py_INCREF(dtype)
6156
array = PyArray_NewFromDescr(
6257
ndarray, dtype, 2, dims, NULL, <void*>ptr, flags, <object>NULL
6358
)

0 commit comments

Comments
 (0)