I am sorry if this question is incomplete or hard to understand, I am trying to figure it out myself ! I have the following C code, inside python-both languages that I am not very good at.
The following C code copies numpy array I think. Its not working when I use it, it uses the SWITCH statement and prints the "default" answer. Can someone help in this?
Is it the version of python? It seems to work in old versions of python.
static PyObject *llpy_acopy(PyObject *unused, PyObject *args)
{
PyObject *afrom = PyTuple_GET_ITEM(args, 0);
PyObject *ato = PyTuple_GET_ITEM(args, 1);
PyArrayObject *tmp = (PyArrayObject *)afrom;
int nd = tmp->nd;
int n = 1;
int i;
for (i=0; i<nd; i++)
n *= tmp->dimensions[i];
switch(tmp->descr->type_num) {
case PyArray_FLOAT:
memcpy(((PyArrayObject *)ato)->data, tmp->data,
(size_t)(n * sizeof(float)));
break;
case PyArray_INT:
memcpy(IDATA(ato), IDATA(afrom),
(size_t )(n * sizeof(int)));
break;
case PyArray_CHAR:
memcpy(CDATA(ato), CDATA(afrom),
(size_t )(n * sizeof(char)));
break;
default:
PyErr_SetString(PyExc_TypeError, "Cannot copy array now");
return NULL;
}
Py_INCREF(Py_None);
return Py_None;
}
The two arrays being copied from one to the other are -that is the first array is copied into the second, replacing the existing values.
[[ 1. 0. 0. ]
[ 1.51999998 1.42799997 0. ]
[ 0.73699999 2.37800002 0. ]
...,
[-7.55183792 -9.31523228 -0.19252452]
[-6.7193203 -8.40346909 0.58392692]
[-8.47850037 -9.02481842 -0.46105781]]
[[ 1. 0. 0. ]
[ 1.51999998 1.42799997 0. ]
[ 0.73699999 2.37800002 0. ]
...,
[-5.86299992 -9.36299992 -5.0999999 ]
[-5.61800003 -7.94799995 -4.84499979]
[-6.12400007 -9.65600014 -6.02799988]]