change function to create array

milestone_5_without_improvements
Oli 4 years ago
parent fd71c3faab
commit 96e1dcd704

@ -15,13 +15,13 @@ void clean_real(struct realization_mod* realin, int n[3], struct grid_mod grid,
/*is the output realization already allocated?*/ /*is the output realization already allocated?*/
/*if not, memory allocation*/ /*if not, memory allocation*/
if (realout->vector == NULL || realout->n != realin->n) { /*if (realout->vector == NULL || realout->n != realin->n) {
realout->vector = (double*)malloc(realin->n * sizeof(double)); realout->vector = (double*)malloc(realin->n * sizeof(double));
if (realout->vector == NULL) { if (realout->vector == NULL) {
printf("Clean_real.c: No memory available\n"); printf("Clean_real.c: No memory available\n");
exit; exit;
} }
} }*/
realout->n = realin->n; realout->n = realin->n;
realout->code = 1; realout->code = 1;

@ -28,9 +28,12 @@ static PyObject* genFunc(PyObject* self, PyObject* args)
struct vario_mod variogram; struct vario_mod variogram;
long seed; long seed;
struct statistic_mod stat; struct statistic_mod stat;
PyObject* out_array; PyArrayObject* out_array;
npy_intp out_dims[NPY_MAXDIMS]; npy_intp out_dims[NPY_MAXDIMS];
out_array = (PyArrayObject *) PyArray_FromDims(NDIMENSIONS,out_dims,NPY_DOUBLE);
Y.vector = (double *) out_array->data;
if (!Py_getvalues(args, &seed, &grid, &variogram, &stat)) if (!Py_getvalues(args, &seed, &grid, &variogram, &stat))
return NULL; return NULL;
Py_kgeneration(seed, grid, stat, variogram, &Z, &Y, n); Py_kgeneration(seed, grid, stat, variogram, &Z, &Y, n);
@ -39,11 +42,12 @@ static PyObject* genFunc(PyObject* self, PyObject* args)
out_dims[1] = grid.NY; out_dims[1] = grid.NY;
out_dims[2] = grid.NX; out_dims[2] = grid.NX;
out_array = PyArray_SimpleNewFromData(NDIMENSIONS, out_dims, NPY_DOUBLE, Y.vector); out_array = (PyArrayObject*)PyArray_SimpleNewFromData(NDIMENSIONS, out_dims, NPY_DOUBLE, Y.vector);
if (out_array == NULL) if (out_array == NULL)
return NULL; return NULL;
// PyArray_ENABLEFLAGS(out_array, NPY_ARRAY_OWNDATA);
PyArray_ENABLEFLAGS(out_array, NPY_ARRAY_OWNDATA); // out_array->flags |= NPY_ARRAY_OWNDATA;
free(stat.mean); free(stat.mean);
free(stat.variance); free(stat.variance);

Loading…
Cancel
Save