Robert Bradshaw wrote:
> On Jun 6, 2009, at 2:20 AM, Dag Sverre Seljebotn wrote:
>
>> Eric Firing wrote:
>>> Eric Firing wrote:
>>>> In writing a cython extension to work with numpy masked arrays, I
>>>> needed to work with the mask, which is dtype('bool'). Therefore I
>>>> was expecting to be able to use np.bool_t, in analogy to np.float_t.
>>>> Instead I had to use np.int8_t, and cast the input to np.int8 in a
>>>> python wrapper. Can bool_t be added to numpy.pxd?
>>>>
>>>> Thanks.
>>>>
>>>> Eric
>> The reason it is not there is that AFAIK Cython has no support for an
>> 8-bit boolean type. I.e. you want
>>
>> print arr[3] # should print "True", not 1.
>>
>> and furthermore you want
>>
>> arr[3] = obj # should mean arr[3] = bool(obj)
>>
>> Which brings up the questions
>> 1) I suppose the best thing would be to add support for a "bool" which
>> would be a C99 _Bool if compiling on C99, and "unsigned char" with
>> appropriate restrictions otherwise. Thoughts?
>
> How would this relate to the current bint type? bint is an int
> because logical operations in C are ints, and also several operations
> in the Python/C API (and elsewhere) return true/false values as ints.
>
>> 2) Is it better to keep ndarray[bool_t] disabled until this
>> happens, or
>> should it be enabled (as an "unsigned char" array) and then change its
>> semantics later?
>
> I would be OK with allowing bool_t to be a synonym for int8_t, and
> then widening the semantics later (I don't see what would break,
> unless one was storing actual integer (rather than boolean) values).
I think it should be uint8_t, not int8_t, because numpy booleans are
stored as unsigned char.
Eric
>
> - Robert
>
> _______________________________________________
> Cython-dev mailing list
> [email protected]
> http://codespeak.net/mailman/listinfo/cython-dev
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev