def inv_sinc(sinc_x, tol=1e-12):
    # Invalid input
    if sinc_x > 1.0:
        raise ValueError("sinc_x > 1.0")

    # Initial guess from reversion of Taylor series
    # https://math.stackexchange.com/questions/3189307/inverse-of-frac-sinxx
    x = t_pow = np.sqrt(6 * np.abs((1 - sinc_x)))
    t_squared = t_pow * t_pow

    for coeff in numba.literal_unroll(_SERIES_COEFFS):
        t_pow *= t_squared
        x += coeff * t_pow

    # Use Newton Raphson to go the rest of the way
    # https://www.wolframalpha.com/input/?i=simplify+%28sinc%5Bx%5D+-+c%29+%2F+D%5Bsinc%5Bx%5D%2Cx%5D
    while True:
        # evaluate delta between this iteration sinc(x) and original
        sinx = np.sin(x)
        𝞓sinc_x = (1.0 if x == 0.0 else sinx / x) - sinc_x

        # Stop if converged
        if np.abs(𝞓sinc_x) < tol:
            break

        # Next iteration
        x -= (x * x * 𝞓sinc_x) / (x * np.cos(x) - sinx)

    return x
Exemple #2
0
 def rebroadcast(x):
     for axis, value in numba.literal_unroll(op_axis):
         if value and x.shape[axis] != 1:
             raise ValueError(
                 ("Dimension in Rebroadcast's input was supposed to be 1")
             )
     return x
Exemple #3
0
 def bar(x):
     acc = 0
     for i in literal_unroll(a):
         if i in {'1': x}:
             acc += 1
         else:
             acc += np.sqrt(x[0, 0])
     return np.sin(x), acc
Exemple #4
0
    def reshape(x, shape):

        new_shape = create_zeros_tuple()

        for i in numba.literal_unroll(range(ndim)):
            new_shape = tuple_setitem(new_shape, i, shape[i])

        return np.reshape(x, new_shape)
 def bar(fcs):
     x = 0
     a = 10
     i, j = fcs[0]
     x += i(j(a))
     for t in literal_unroll(fcs):
         i, j = t
         x += i(j(a))
     return x
    def pd_multi_index_names_impl(self):
        levels_names = sdc_tuple_map(lambda x: x.name, self._levels)

        # this exploits undesired side-effect of literal_unroll - type-unification
        # of resulting list dtype that will be types.Optional(types.unicode_type)
        # as using typed.List of Optional values currently fails to compile
        res = []
        for i in literal_unroll(levels_names):
            res.append(i)
        return res
Exemple #7
0
def all_to_all(w_halosend, taille, mystruct, variables, scount, sdepl, rcount, rdepl):

    w_halorecv = np.zeros(taille, dtype=mystruct)

    for var in literal_unroll(variables):
        s_msg = r_msg = 0
        s_msg = [np.array(w_halosend[var]), (scount, sdepl), MPI.DOUBLE_PRECISION]
        r_msg = [np.array(w_halorecv[var]), (rcount, rdepl), MPI.DOUBLE_PRECISION]

        COMM.Alltoallv(s_msg, r_msg)

        w_halorecv[var] = r_msg[0]

    return w_halorecv
Exemple #8
0
    def _tuple_hash(tup):
        tl = len(tup)
        acc = _PyHASH_XXPRIME_5
        for x in literal_unroll(tup):
            lane = hash(x)
            if lane == _Py_uhash_t(-1):
                return -1
            acc += lane * _PyHASH_XXPRIME_2
            acc = _PyHASH_XXROTATE(acc)
            acc *= _PyHASH_XXPRIME_1

        acc += tl ^ (_PyHASH_XXPRIME_5 ^ _Py_uhash_t(3527539))

        if acc == _Py_uhash_t(-1):
            return process_return(1546275796)

        return process_return(acc)
Exemple #9
0
def set_field4(rec):
    for f in literal_unroll(_FS):
        rec[f] = 10
    return rec
Exemple #10
0
def set_field2(rec):
    fs = ('e', 'f')
    for f in literal_unroll(fs):
        rec[f] = 10
    return rec
Exemple #11
0
def get_field4(rec):
    out = 0
    for f in literal_unroll(_FS):
        out += rec[f]
    return out
Exemple #12
0
 def impl(*args):
     s = 0
     for arg in literal_unroll(args):
         s += len(arg)
     return s
Exemple #13
0
 def pyfunc(rec):
     x = np.zeros((n,))
     for o in literal_unroll(keys):
         x += rec[o]
     return x
Exemple #14
0
 def impl(lst, x):
     count = 0
     for val in literal_unroll(lst):
         if val == x:
             count += 1
     return count
def get_field2(rec):
    fs = ("e", "f")
    out = 0
    for f in literal_unroll(fs):
        out += rec[f]
    return out
Exemple #16
0
 def impl(lst, item):
     for val in literal_unroll(lst):
         if val == item:
             return True
     return False
Exemple #17
0
 def get_field(rec):
     out = 0
     for f in literal_unroll(fs):
         out += rec[f]
     return out
 def bar(fcs):
     r = 0
     for pair in literal_unroll(fcs):
         f1, f2 = pair
         r += f1() + f2(2)
     return r
Exemple #19
0
 def set_field(rec):
     for f in literal_unroll(fs):
         rec[f] = 10
     return rec
Exemple #20
0
    def run_etl():
        # Read only these columns
        keep_cols = ('YEAR', 'DATANUM', 'SERIAL', 'CBSERIAL', 'HHWT', 'GQ',
                     'PERNUM', 'SEX', 'AGE', 'INCTOT', 'EDUC', 'EDUCD',
                     'EDUC_HEAD', 'EDUC_POP', 'EDUC_MOM', 'EDUCD_MOM2',
                     'EDUCD_POP2', 'INCTOT_MOM', 'INCTOT_POP', 'INCTOT_MOM2',
                     'INCTOT_POP2', 'INCTOT_HEAD', 'SEX_HEAD', 'CPI99')
        dtypes = {
            'YEAR': np.float64,
            'DATANUM': np.float64,
            'SERIAL': np.float64,
            'CBSERIAL': np.float64,
            'HHWT': np.float64,
            'GQ': np.float64,
            'PERNUM': np.float64,
            'SEX': np.float64,
            'AGE': np.float64,
            'INCTOT': np.float64,
            'EDUC': np.float64,
            'EDUCD': np.float64,
            'EDUC_HEAD': np.float64,
            'EDUC_POP': np.float64,
            'EDUC_MOM': np.float64,
            'EDUCD_MOM2': np.float64,
            'EDUCD_POP2': np.float64,
            'INCTOT_MOM': np.float64,
            'INCTOT_POP': np.float64,
            'INCTOT_MOM2': np.float64,
            'INCTOT_POP2': np.float64,
            'INCTOT_HEAD': np.float64,
            'SEX_HEAD': np.float64,
            'CPI99': np.float64
        }
        # https://rapidsai-data.s3.us-east-2.amazonaws.com/datasets/ipums_education2income_1970-2010.csv.gz
        df = pd.read_csv('ipums_education2income_1970-2010.csv',
                         usecols=keep_cols,
                         dtype=dtypes)

        mask = df['INCTOT'] != 9999999

        df = df[mask]
        df = df.reset_index(drop=True)

        res = df['INCTOT'] * df['CPI99']
        df = setitem_impl(df, 'INCTOT', res)

        mask1 = df['EDUC'].notna()

        df = df[mask1]
        df = df.reset_index(drop=True)

        mask2 = df['EDUCD'].notna()

        df = df[mask2]
        df = df.reset_index(drop=True)

        for col in literal_unroll(keep_cols):
            df[col].fillna(-1, inplace=True)

        y = df['EDUC']
        X = df.drop(columns='EDUC')

        return X, y
Exemple #21
0
def get_field2(rec):
    fs = ('e', 'f')
    out = 0
    for f in literal_unroll(fs):
        out += rec[f]
    return out
Exemple #22
0
 def foo():
     l = ['a', 1, 'a', 2, 'a', 3, 'b', 4, 'b', 5, 'c']
     r = []
     for x in literal_unroll(('a', 'd', 2, 6)):
         r.append(x in l)
     return r
Exemple #23
0
 def get_field_sum(rec):
     out = 0
     for f in literal_unroll(fields_gl):
         out += rec[f]
     return out