Python Forum

Full Version: PyArray_SimpleNew gives "ValueError: array is too big; for 3-cubed array
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am using Anaconda Spyder 3.3.6 (Python 3.7) on CentOS 7. I started out with the following code in the surfaceModules module.

static PyObject *  squeezeSurfaces(PyObject* self, PyObject* args)
{
    PyArrayObject *matin, *matout;
    double ***cin, ***cout, dfactor;
    int i,j,k,n,m,l, dims[3], ifactor;

    // Parse tuples separately since args will differ between C fcns
    if (!PyArg_ParseTuple(args, "O!id",
        &PyArray_Type, &matin, &ifactor, &dfactor))  return NULL;
    if (NULL == matin)  return NULL;

    // Check that object input is 'double' type and a matrix
    //   Not needed if python wrapper function checks before call to this routine
    if (not_doublematrix(matin)) return NULL;

    // Get the dimensions of the input
    n=dims[0]=matin->dimensions[0];
    m=dims[1]=matin->dimensions[1];
    l=dims[2]=matin->dimensions[2];

    // Make a new double matrix of same dims
    matout=(PyArrayObject *) PyArray_SimpleNew(3,dims,NPY_DOUBLE);

    Py_INCREF(matin);
    return PyArray_Return(matin);
}
With the following Python code

import surfaceModules as sm
import numpy as NP

x=NP.zeros(27)
for i in range(0,27): x[i]=i 
x=x.reshape(3,3,3)
jfac=2
xfac=1.5
y=sm.squeezeSurfaces(x, jfac, xfac)
I got the following message

__main__:10: DeprecationWarning: PyArray_FromDims: use PyArray_SimpleNew.
__main__:10: DeprecationWarning: PyArray_FromDimsAndDataAndDescr: use PyArray_NewFromDescr.
So I replaced PyArray_FromDims with PyArray_SimpleNew.

This resulted in

ValueError: array is too big; `arr.size * arr.dtype.itemsize` is larger than the maximum possible size.
with the same Python code. Note that this happens with both Spyder and Jupyter Notebook.
It is a 3-cubed array so should only have 27 elements altogether.
Have you tried declaring dims[] as "npy_intp dims[3];"?

casevh