Skip to content

Instantly share code, notes, and snippets.

@sklam
Last active April 10, 2018 08:29
Show Gist options
  • Select an option

  • Save sklam/77e784a1daed8f22a457ff67ccf421bc to your computer and use it in GitHub Desktop.

Select an option

Save sklam/77e784a1daed8f22a457ff67ccf421bc to your computer and use it in GitHub Desktop.
Numba namedtuple + numpy array
from collections import namedtuple
import numpy as np
from numba import njit
MyRec = namedtuple("MyRec", "indices,values")
@njit
def make(ids, vals):
return MyRec(indices=ids, values=vals)
@njit
def foo(rec):
return rec.indices + rec.values
@njit
def bar():
a = np.arange(10)
b = np.arange(10)
c = make(a, b)
return foo(c)
myrec = make(np.arange(10), np.zeros((1, 10)))
print(myrec)
print(foo(myrec))
print(bar())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment