Skip to content

Instantly share code, notes, and snippets.

View samaid's full-sized avatar
💚
Make your mind free

samaid

💚
Make your mind free
  • 09:06 (UTC -05:00)
View GitHub Profile
@samaid
samaid / test.py
Created May 17, 2023 02:14
Compute-follows-data breaks on the inverse operation
import dpnp as np
x = np.asarray([1.0, 2.0, 3.0], device="gpu").astype(np.float32)
y = np.float32(1.0) / x
print(type(x))
print(type(y))
assert isinstance(y, np.dpnp_array.dpnp_array)
@samaid
samaid / test2.py
Created May 14, 2023 19:55
Power is only marginally slower in unnested loop
from numba import njit, prange
import numpy as np
from time import time
import math
@njit(parallel=False)
def foo(m):
pos = np.empty_like(m)
for i in prange(len(m)):
@samaid
samaid / test1.py
Created May 14, 2023 19:53
Raising to the power leads to 10x performance slowdown in double-nested loop
from numba import njit, prange
import numpy as np
import math
from time import time
SOFTENING_SQ = 0.001
G = 1.0
@njit(parallel=True)
@samaid
samaid / numba_dict_njit.py
Created October 18, 2019 17:29
Illustrates Numba error diagnostics
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[:]
@samaid
samaid / jitclass_dict.py
Created October 17, 2019 19:53 — forked from sklam/jitclass_dict.py
JITClass Dictionary Example
from numba import jitclass
from numba import types
from numba.typed import Dict
@jitclass([('d', types.DictType(types.intp, types.float64))])
class DictWrapper(object):
def __init__(self):
d = Dict()
d[1] = 1.2