Hello everyone,
I must report odd behaviour of the numpy arrays regarding the flags set for
each array object in C++.
Please have a look at the following code:
static PyObject* test(PyObject* self,PyObject* args){
int s[2];
s[0] = 1;
s[1] = 1;
char* value = (char*)PyMem_Malloc(2*sizeof(int));
PyObject* obj= PyArray_FromDimsAndData(1,s,NPY_INTLTR,(char*)value);
PyArrayObject* array = (PyArrayObject*) obj;
printf("%d\n",array->flags);
array->flags=0;
printf("%d\n",array->flags);
return obj;
}
By creating my object with the code above, the flags of the object are not
set right.
The explicit setting of
array->flags=0;
would yield a print out of
0
for the next line, but when I look at the value from the interpreter, I
would get a
>>> a.flags.num
1
???
It seems to me the flags are overridden and that C alignment is a hard coded
default value.
I need to set the Flags to 1286, which means (Fortran alignment)
C_CONTIGUOUS : False
F_CONTIGUOUS : True
OWNDATA : True
WRITEABLE : True
ALIGNED : True
UPDATEIFCOPY : False
Thats exactly what I want to achieve in my real code(similar as above, but
more complex). But for that, however, I would get a
>>> a.flags.num
1285
C_CONTIGUOUS : True
F_CONTIGUOUS : False
OWNDATA : True
WRITEABLE : True
ALIGNED : True
UPDATEIFCOPY : False
even though I set the flags value in my C++ code to 1286 explicitly and a
printf directive prints 1286 .
Does anybody have a clue where the magic happens? Can I override the flags
settings of an array in python and set them to some value? I tried it with
the PyArray_UpdateFlags
function, but it did not work, same results.
Thank you in advance for your help,
Thomas
--
View this message in context: http://www.nabble.com/Numpy-array-flags---BUG--tp19444726p19444726.html
Sent from the Numpy-discussion mailing list archive at Nabble.com.