Created
October 18, 2019 17:29
-
-
Save samaid/c0852268d017aa207e44a94d241807ab to your computer and use it in GitHub Desktop.
Illustrates Numba error diagnostics
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 numba.typed import Dict | |
from numba import types, njit | |
import numpy as np | |
# Using Numba dictionary is more efficient for passing into compiled region due to lower unboxing overheads | |
# The Dict.empty() constructs a typed dictionary. | |
# The key and value typed must be explicitly declared. | |
nd = Dict.empty( | |
key_type=types.int64, | |
value_type=types.float64[:] | |
) | |
# Assigning key-values using Numpy arrays | |
nd[1] = np.asarray([1.1, 1.2], dtype='f8') | |
nd[2] = np.asarray([2.2], dtype='f8') | |
nd[3] = np.asarray([3.3, 3.4, 3.5], dtype='f8') | |
print(nd) | |
@njit | |
def foo(d): | |
d[4] = np.asarray([4.4, 4.5], dtype='f8') | |
return d | |
print(foo(nd)) |
Author
samaid
commented
Oct 18, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment