Skip to content

Commit

Permalink
numpy: test npymath as well
Browse files Browse the repository at this point in the history
  • Loading branch information
valgur committed Mar 21, 2024
1 parent f19f86d commit 0e99851
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions recipes/numpy/all/test_package/test_package.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@

#include <Python.h>
#include <numpy/arrayobject.h>
#include <numpy/halffloat.h>
#include <numpy/ufuncobject.h>

static PyObject* create_numpy_array(PyObject *self, PyObject *args) {
npy_intp dims[2] = {5, 5};
PyObject *pyArray = PyArray_SimpleNew(2, dims, NPY_FLOAT64);
PyObject *pyArray = PyArray_SimpleNew(2, dims, NPY_HALF);

for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
*((double *)PyArray_GETPTR2(pyArray, i, j)) = (double)i * j;
*((npy_half *)PyArray_GETPTR2((PyArrayObject *)pyArray, i, j)) = npy_float_to_half((float)i * j);
}
}

Expand Down

0 comments on commit 0e99851

Please sign in to comment.