Created
December 23, 2021 15:49
-
-
Save nbecker/76ac6e37652e7b0424886f5c9cbfa33d to your computer and use it in GitHub Desktop.
transonic bounds check
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
import numpy as np | |
from transonic import boost | |
A = "complex[:]" | |
S = "int[:]" | |
@boost(boundscheck=True) | |
def call1 (map: A, s: int): | |
return map[s] | |
@boost | |
def call2 (map: A, syms: 'int[:] or int32[:]'): | |
out = np.empty(len(syms), dtype=complex) | |
for i in range (len (syms)): | |
out[i] = map[syms[i]] | |
return out | |
class constellation: | |
#map: A | |
def __init__(self, map: A): | |
self.map = np.require (map, dtype=complex) | |
self.bps = int (np.log2 (len (self.map))) | |
def __call__(self, s): | |
if hasattr (s, '__len__'): | |
return call2 (self.map, s) | |
else: | |
return call1 (self.map, s) | |
def __getitem__(self, s): | |
return self.__call__(s) | |
@property | |
def size(self): | |
return len(self.map) | |
@property | |
def bits_per_sym(self): | |
return self.bps |
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 constellation import constellation | |
import numpy as np | |
A = np.array | |
u = A([1+0j, -1+0j]) | |
c = constellation (u) | |
syms = A ([0,1]) | |
xconst = c(syms) | |
x = c(0) | |
c[10] # should be caught by boundscheck |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment