[SciPy-Dev] bool wrapper in sparse

Nathaniel Smith njs@pobox....
Wed Jun 26 11:34:56 CDT 2013


On 26 Jun 2013 17:18, "Blake Griffith" <blake.a.griffith@gmail.com> wrote:
>
> Hello scipy, I'm working on the bool_ops.h file in sparse/sparsetools
which wraps numpy bool type for the c++ routines. Currently it just does
>
> typedef npy_int8 npy_bool_wrapper;
>
> So the underlying int can roll over to zero, giving a False when we
should have a True. I'm trying to make a class which inherits from
npy_int8, then override the addition operators to behave like normal
boolean arithmetic (1 + 1 = 1). But I'm having a few problems.
>
> When I try to do something simple like:
>
> class npy_bool_wrapper : public npy_int8 {};
>
> I get an error for that line:
>
> error: expected class-name before '{' token

In c++, user classes can't inherit from primitive types. Thus spake Bjarne.

Make a memory-layout compatible class (i.e., one with a single npy_bool
member), and then cast back and forth as needed?

-n
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-dev/attachments/20130626/5f96f990/attachment.html 


More information about the SciPy-Dev mailing list