[Numpy-discussion] Enum type

Wes McKinney wesmckinn at gmail.com
Tue Jan 3 13:05:37 EST 2012


On Tue, Jan 3, 2012 at 12:46 PM, Ognen Duzlevski <ognen at enthought.com> wrote:
> Hello,
>
> I am playing with adding an enum dtype to numpy (to get my feet wet in
> numpy really). I have looked at the
> https://github.com/martinling/numpy_quaternion and I feel comfortable
> with my understanding of adding a simple type to numpy in technical
> terms.
>
> I am mostly a C programmer and have programmed in Python but not at
> the level where my code wcould be considered "pretty" or maybe even
> "pythonic". I know enums from C and have browsed around a few python
> enum implementations online. Most of them use hash tables or lists to
> associate names to numbers - these approaches just feel "heavy" to me.
>
> What would be a proper "numpy approach" to this? I am looking mostly
> for direction and advice as I would like to do the work myself :-)
>
> Any input appreciated :-)
> Ognen
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion

You should use a hash table internally in my opinion. I've started
using khash from klib (https://github.com/attractivechaos/klib) which
has excellent memory usage (more than 50% less than Python dict with
large hash tables) and good performance characteristics. With the enum
dtype you can avoid reference counting with primitive types, not sure
about object dtype. If enum arrays are mutable this will be very
tricky.

- Wes



More information about the NumPy-Discussion mailing list