# How to declare an array of enum values that is compatible with numba?

**URL:** <https://numba.discourse.group/t/how-to-declare-an-array-of-enum-values-that-is-compatible-with-numba/2841>\
**Category:** Support: How do I do ...?\
**Created:** [December 15, 2024, 7:41am UTC](https://numba.discourse.group/t/how-to-declare-an-array-of-enum-values-that-is-compatible-with-numba/2841 "2024-12-15T07:41:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![blackears](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/blackears/32/1171_2.png) [@blackears](https://numba.discourse.group/u/blackears)\
**Post date:** [December 15, 2024, 7:41am UTC](https://numba.discourse.group/t/how-to-declare-an-array-of-enum-values-that-is-compatible-with-numba/2841/1 "2024-12-15T07:41:05Z")

</div>

I’m new to numba and trying to numbafy an existing python script to hopefully make it run faster.

I’m declaring an array that I want to pass to the constructor of my CheckerBoardState class, but it’s being rejected because it is of type `list(Enum<int64>(Cell))` but it need to be type `ListType[<enum 'Cell'>]`. How do I specify the correct type?

```auto
Cannot cast reflected list(Enum<int64>(Cell))<iv=None> to ListType[<enum 'Cell'>]: %"inserted.parent" = insertvalue {i8*, i8*} %"inserted.meminfo.1", i8* %"arg.pieces.1", 1

```

```auto
from numba.experimental import jitclass
from numba import njit, types
from typing import List
from enum import Enum

class Cell(Enum):
    EMPTY = 0
    BLACK = 1
    BLACK_KING = 2
    WHITE = 3
    WHITE_KING = 4

@jitclass([('black_to_move', types.bool), ('pieces', types.ListType(Cell))])
class CheckerBoardState:
    def __init__ (self, black_to_move:bool, pieces:List[Cell]):
        self.black_to_move = black_to_move
        self.pieces = pieces

board_start:CheckerBoardState = CheckerBoardState(True, [
    Cell.BLACK, Cell.BLACK, Cell.BLACK, Cell.BLACK, 
    Cell.BLACK, Cell.BLACK, Cell.BLACK, Cell.BLACK, 
    Cell.BLACK, Cell.BLACK, Cell.BLACK, Cell.BLACK, 

    Cell.EMPTY, Cell.EMPTY, Cell.EMPTY, Cell.EMPTY, 
    Cell.EMPTY, Cell.EMPTY, Cell.EMPTY, Cell.EMPTY, 

    Cell.WHITE, Cell.WHITE, Cell.WHITE, Cell.WHITE, 
    Cell.WHITE, Cell.WHITE, Cell.WHITE, Cell.WHITE, 
    Cell.WHITE, Cell.WHITE, Cell.WHITE, Cell.WHITE, 
])

```

---

<div class="post-metadata">

**Author:** ![milton](https://avatars.discourse-cdn.com/v4/letter/m/87869e/32.png) [@milton](https://numba.discourse.group/u/milton)\
**Post date:** [December 17, 2024, 2:41pm UTC](https://numba.discourse.group/t/how-to-declare-an-array-of-enum-values-that-is-compatible-with-numba/2841/2 "2024-12-17T14:41:36Z")

</div>

You can try

```auto
from numba import typed

@jitclass([('black_to_move', types.bool), ('pieces', types.ListType(types.EnumMember(Cell, types.int64)))])
class CheckerBoardState:
    def __init__ (self, black_to_move:bool, pieces:List[Cell]):
        self.black_to_move = black_to_move
        self.pieces = pieces

board_start:CheckerBoardState = CheckerBoardState(True, typed.List([
    Cell.BLACK, Cell.BLACK, Cell.BLACK, Cell.BLACK, 
    Cell.BLACK, Cell.BLACK, Cell.BLACK, Cell.BLACK, 
    Cell.BLACK, Cell.BLACK, Cell.BLACK, Cell.BLACK, 

    Cell.EMPTY, Cell.EMPTY, Cell.EMPTY, Cell.EMPTY, 
    Cell.EMPTY, Cell.EMPTY, Cell.EMPTY, Cell.EMPTY, 

    Cell.WHITE, Cell.WHITE, Cell.WHITE, Cell.WHITE, 
    Cell.WHITE, Cell.WHITE, Cell.WHITE, Cell.WHITE, 
    Cell.WHITE, Cell.WHITE, Cell.WHITE, Cell.WHITE, 
]))

```

---

<div class="post-metadata">

**Author:** ![nelson2005](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/nelson2005/32/47_2.png) [@nelson2005](https://numba.discourse.group/u/nelson2005)\
**Post date:** [December 18, 2024, 5:38pm UTC](https://numba.discourse.group/t/how-to-declare-an-array-of-enum-values-that-is-compatible-with-numba/2841/3 "2024-12-18T17:38:34Z")

</div>

That being said, List is relatively slow. Numpy array will likely be faster.
