Unverified Commit 1cd905b4 authored by Peter Eastman's avatar Peter Eastman Committed by GitHub
Browse files

Support numpy 2 (#4622)

* Support numpy 2

* Debugging

* Removed debugging code
parent 75d4f299
......@@ -10,7 +10,7 @@ dependencies:
- python
- cython
- swig
- numpy <2.0
- numpy
- doxygen 1.8.14
# test
- pytest
......
......@@ -10,7 +10,7 @@ dependencies:
- python
- cython
- swig
- numpy <2.0
- numpy
- doxygen 1.8.14
# test
- pytest
......
......@@ -12,7 +12,7 @@ dependencies:
- python
- cython
- swig
- numpy <2.0
- numpy
- ocl-icd-system
- doxygen 1.8.14
# test
......
......@@ -12,7 +12,7 @@ dependencies:
- pypy
- cython
- swig
- numpy <2.0
- numpy
- ocl-icd-system
- doxygen 1.8.14
# test
......
......@@ -12,7 +12,7 @@ dependencies:
- python
- cython
- swig
- numpy <2.0
- numpy
- doxygen 1.8.14
- khronos-opencl-icd-loader
# test
......
......@@ -8,7 +8,7 @@ dependencies:
# host
- python
- pip
- numpy <2.0
- numpy
- cython
- swig
- doxygen 1.8.14
......
......@@ -161,14 +161,16 @@ int Py_SequenceToVecDouble(PyObject* obj, std::vector<double>& out) {
PyObject* item1 = NULL;
if (isNumpyAvailable()) {
if (PyArray_Check(stripped) && PyArray_ISCARRAY_RO(stripped) && PyArray_NDIM(stripped) == 1) {
int type = PyArray_TYPE(stripped);
int length = PyArray_SIZE(stripped);
void* data = PyArray_DATA((PyArrayObject*) stripped);
if (PyArray_Check(stripped)) {
const PyArrayObject* array = (PyArrayObject*) stripped;
if (PyArray_ISCARRAY_RO(array) && PyArray_NDIM(array) == 1) {
int type = PyArray_TYPE(array);
int length = PyArray_SIZE(array);
void* data = PyArray_DATA(array);
if (type == NPY_DOUBLE) {
out.resize(length);
memcpy(&out[0], data, sizeof(double)*length);
Py_DECREF(stripped);
Py_DECREF(array);
return SWIG_OK;
}
if (type == NPY_FLOAT) {
......@@ -176,7 +178,7 @@ int Py_SequenceToVecDouble(PyObject* obj, std::vector<double>& out) {
float* floatData = (float*) data;
for (int i = 0; i < length; i++)
out[i] = floatData[i];
Py_DECREF(stripped);
Py_DECREF(array);
return SWIG_OK;
}
if (type == NPY_INT32) {
......@@ -184,7 +186,7 @@ int Py_SequenceToVecDouble(PyObject* obj, std::vector<double>& out) {
int* intData = (int*) data;
for (int i = 0; i < length; i++)
out[i] = intData[i];
Py_DECREF(stripped);
Py_DECREF(array);
return SWIG_OK;
}
if (type == NPY_INT64) {
......@@ -192,11 +194,12 @@ int Py_SequenceToVecDouble(PyObject* obj, std::vector<double>& out) {
long long* longData = (long long*) data;
for (int i = 0; i < length; i++)
out[i] = longData[i];
Py_DECREF(stripped);
Py_DECREF(array);
return SWIG_OK;
}
}
}
}
PyObject* iterator = PyObject_GetIter(stripped);
if (iterator == NULL) {
......@@ -233,14 +236,16 @@ int Py_SequenceToVecDouble(PyObject* obj, std::vector<double>& out) {
int Py_SequenceToVecVec3(PyObject* obj, std::vector<Vec3>& out) {
PyObject* stripped = Py_StripOpenMMUnits(obj); // new reference
if (isNumpyAvailable()) {
if (PyArray_Check(stripped) && PyArray_ISCARRAY_RO(stripped) && PyArray_NDIM(stripped) == 2 && PyArray_DIM(stripped, 1) == 3) {
int type = PyArray_TYPE(stripped);
int length = PyArray_DIM(stripped, 0);
void* data = PyArray_DATA((PyArrayObject*) stripped);
if (PyArray_Check(stripped)) {
const PyArrayObject* array = (PyArrayObject*) stripped;
if (PyArray_ISCARRAY_RO(array) && PyArray_NDIM(array) == 2 && PyArray_DIM(array, 1) == 3) {
int type = PyArray_TYPE(array);
int length = PyArray_DIM(array, 0);
void* data = PyArray_DATA((PyArrayObject*) array);
if (type == NPY_DOUBLE) {
out.resize(length);
memcpy(&out[0][0], data, 3*sizeof(double)*length);
Py_DECREF(stripped);
Py_DECREF(array);
return SWIG_OK;
}
if (type == NPY_FLOAT) {
......@@ -248,7 +253,7 @@ int Py_SequenceToVecVec3(PyObject* obj, std::vector<Vec3>& out) {
float* floatData = (float*) data;
for (int i = 0; i < length; i++)
out[i] = Vec3(floatData[3*i], floatData[3*i+1], floatData[3*i+2]);
Py_DECREF(stripped);
Py_DECREF(array);
return SWIG_OK;
}
if (type == NPY_INT32) {
......@@ -256,7 +261,7 @@ int Py_SequenceToVecVec3(PyObject* obj, std::vector<Vec3>& out) {
int* intData = (int*) data;
for (int i = 0; i < length; i++)
out[i] = Vec3(intData[3*i], intData[3*i+1], intData[3*i+2]);
Py_DECREF(stripped);
Py_DECREF(array);
return SWIG_OK;
}
if (type == NPY_INT64) {
......@@ -264,11 +269,12 @@ int Py_SequenceToVecVec3(PyObject* obj, std::vector<Vec3>& out) {
long long* longData = (long long*) data;
for (int i = 0; i < length; i++)
out[i] = Vec3(longData[3*i], longData[3*i+1], longData[3*i+2]);
Py_DECREF(stripped);
Py_DECREF(array);
return SWIG_OK;
}
}
}
}
int ret = 0;
PyObject* item = NULL;
PyObject* item1 = NULL;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment