Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug with C array datatype which caused issues on Windows. #247

Merged
merged 4 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ jobs:
targets: |
- linux
- macos
#- windows
- windows
secrets:
pypi_token: ${{ secrets.pypi_token }}
2 changes: 1 addition & 1 deletion hyperion/grid/octree_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ def __getattr__(self, attribute):
@property
def limits(self):
from hyperion.importers._discretize_sph import _get_positions_widths
xc, yc, zc, xw, yw, zw = _get_positions_widths(self.refined,
xc, yc, zc, xw, yw, zw = _get_positions_widths(self.refined.astype(bool),
self.x, self.y, self.z,
self.dx, self.dy, self.dz)
return xc - xw, xc + xw, yc - yw, yc + yw, zc - zw, zc + zw
Expand Down
12 changes: 7 additions & 5 deletions hyperion/importers/_discretize_sph.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
#define Py_LIMITED_API 0x030900f0
#include <stdbool.h>

#include <Python.h>
#include <numpy/arrayobject.h>
Expand All @@ -25,7 +26,7 @@ static PyMethodDef module_methods[] = {
{NULL, NULL, 0, NULL}
};

int recursive_position_width(int i, long *refined,
int recursive_position_width(int i, npy_bool *refined,
double x, double y, double z,
double dx, double dy, double dz,
double *xc, double *yc, double *zc,
Expand Down Expand Up @@ -234,7 +235,7 @@ static PyObject *_get_positions_widths(PyObject *self, PyObject *args)
return NULL;

/* Interpret the input objects as `numpy` arrays. */
PyObject *refined_array = PyArray_FROM_OTF(refined_obj, NPY_LONGLONG, NPY_ARRAY_IN_ARRAY);
PyObject *refined_array = PyArray_FROM_OTF(refined_obj, NPY_BOOL, NPY_ARRAY_IN_ARRAY);

/* If that didn't work, throw an `Exception`. */
if (refined_array == NULL) {
Expand Down Expand Up @@ -294,7 +295,7 @@ static PyObject *_get_positions_widths(PyObject *self, PyObject *args)
}

/* Get pointers to the data as C-types. */
long *refined = (long*)PyArray_DATA(refined_array);
npy_bool *refined = (bool*)PyArray_DATA(refined_array);
double *xc = (double*)PyArray_DATA(xc_array);
double *yc = (double*)PyArray_DATA(yc_array);
double *zc = (double*)PyArray_DATA(zc_array);
Expand All @@ -308,15 +309,16 @@ static PyObject *_get_positions_widths(PyObject *self, PyObject *args)

if(i != ncells - 1) {
PyErr_SetString(PyExc_TypeError, "An error occurred when retrieving the cell properties");
Py_XDECREF(refined_array);
return NULL;
}

// return xc_array, yc_array, zc_array;
return Py_BuildValue("OOOOOO", xc_array, yc_array, zc_array, xw_array, yw_array, zw_array);

}


int recursive_position_width(int i, long *refined,
int recursive_position_width(int i, npy_bool *refined,
double x, double y, double z,
double dx, double dy, double dz,
double *xc, double *yc, double *zc,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ build-backend = 'setuptools.build_meta'
write_to = "hyperion/_version.py"

[tool.cibuildwheel]
skip = "pp* *-musllinux* *aarch64* *i686*"
skip = "pp* *-musllinux* *aarch64* *i686* *win32*"
Loading