On Sat, Jul 9, 2011 at 12:53 PM, Eric Firing <efir...@hawaii.edu> wrote:

> On 07/08/2011 01:31 PM, Mark Wiebe wrote:
> > I've just made pull request 105:
> >
> > https://github.com/numpy/numpy/pull/105
> >
>
> It's merged, which is good, but I have a suggestion relevant to that
> pull and I suspect to many others to come: use defines and macros to
> consolidate some of the implementation details.  For example:
>
> #define MASK_TYPE npy_uint8
> #define EXPOSE 1
> #define HIDE 0
> #define EXPOSED(mask) ( (*(MASK_TYPE *)mask)&0x01 == EXPOSE )
>
> etc.
>
> The potential advantages are readability, reduction of scope for typos,
> and ease of testing alternative implementation details, should that turn
> out to be desirable.  I am assuming that only a few expressions like
> EXPOSED will be needed *many* places in the code.
>

That's a great idea, thanks. The one thing I would slightly adjust is to put
everything in a 'macro namespace' to avoid global namespace pollution.
 Maybe:

typedef npy_uint8 npy_mask;
#define NPY_MASK NPY_UINT8
#define NPY_MASK_ISEXPOSED(mask) (((mask)&0x01) != 0)
#define NPY_MASK_GETPAYLOAD(mask) (((npy_mask)mask) >> 1)
#define NPY_MASK_MAKEMASK(exposed, payload) ((npy_mask)(exposed&0x01) |
(npy_mask)(payload << 1))

-Mark


> Eric
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to