Last active
April 10, 2018 08:29
-
-
Save sklam/77e784a1daed8f22a457ff67ccf421bc to your computer and use it in GitHub Desktop.
Numba namedtuple + numpy array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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