def test_inheritence():
    with kb_context("test_inheritence") as context:
        spec1 = {"A": "string", "B": "number"}
        BOOP1, BOOP1Type = define_fact("BOOP1",
                                       spec1,
                                       context="test_inheritence")
        spec2 = {"inherit_from": BOOP1, "C": "number"}
        BOOP2, BOOP2Type = define_fact("BOOP2",
                                       spec2,
                                       context="test_inheritence")
        spec3 = {"inherit_from": BOOP2, "D": "number"}
        BOOP3, BOOP3Type = define_fact("BOOP3",
                                       spec3,
                                       context="test_inheritence")

        assert context.parents_of["BOOP3"] == ["BOOP1", "BOOP2"]
        assert context.children_of["BOOP3"] == []
        assert context.parents_of["BOOP2"] == ["BOOP1"]
        assert context.children_of["BOOP2"] == ["BOOP3"]
        assert context.parents_of["BOOP1"] == []
        assert context.children_of["BOOP1"] == ["BOOP2", "BOOP3"]

        b1 = BOOP1("A", 7)

        @njit
        def check_has_base(b):
            return b.idrec

        assert check_has_base(b1) == u8(-1)
        assert check_has_base.py_func(b1) == u8(-1)
Ejemplo n.º 2
0
def solve(x0, A, b, omega, tol):
    '''Wrapper function to use SOR algorithm to solve Ax = b
    
    Parameters
    ===========
    x0: numpy array
        First guess for solution
    A: numpy array
        matrix describing linear system
    b: numpy array
        vector of constants
    omega: float
        relaxation factor
    tol: float
        error tolerancd for stopping iteration (error for convergence)
    '''

    # Format dtype of all parameters to numba double precision float
    # this helps @njit work correctly
    x0 = f8(x0)
    A = f8(A)
    b = f8(b)
    omega = f8(omega)
    M = u8(10**6)
    tol = f8(tol)

    # call actual SOR algorithm (need the numba dtypes to allow njit compile)
    x = solve_body(x0, A, b, omega, M, tol)

    return x
Ejemplo n.º 3
0
def get_u64(buf, offset, length):
    if length < 8:
        return (0, offset, length)
    a = nb.u8(buf[offset + 7]) << 54
    b = nb.u8(buf[offset + 6]) << 48
    c = nb.u8(buf[offset + 5]) << 40
    d = nb.u8(buf[offset + 4]) << 32
    e = nb.u8(buf[offset + 3]) << 24
    f = nb.u8(buf[offset + 2]) << 16
    g = nb.u8(buf[offset + 1]) << 8
    h = nb.u8(buf[offset + 0]) << 0
    return a | b | c | d | e | f | g | h, offset + 8, length - 8
Ejemplo n.º 4
0
def solve(v0, b, g, omega, tol, theta, lamb):
    '''Wrapper function to use SOR algorithm to solve Ax = b
    
    Parameters
    ===========
    xv: numpy array
        First guess for solution
    b: numpy array
        vector to represent A * w
    g: numpy array
        vector representing early excercise values
    omega: float
        relaxation factor
    tol: float
        error tolerancd for stopping iteration (error for convergence)
    theta: float
        parameter controlling what discretization method is being used
    lamb: float
        lambda parameter from option pricing model
    '''

    # Format dtype of all parameters to numba double precision float
    # this helps @njit work correctly
    v0 = f8(v0)
    b = f8(b)
    g = f8(g)
    omega = f8(omega)
    M = u8(10**6)
    tol = f8(tol)
    theta = f8(theta)
    lamb = f8(lamb)

    # call actual SOR algorithm (need the numba dtypes to allow njit compile)
    x = solve_body(v0, b, g, omega, tol, theta, lamb, M)

    return x
Ejemplo n.º 5
0
	# #last field
	# # check if actually all fields already taken
	# if running_index < 57 and running_index_map >= 0:
	    # barray_map[end_field_count-1:0] = barray[running_index+7:running_index+8-end_field_count]


	# signal_number = barray_map[signalsize-1:0]


    if isValuetypeiSigned and barray_msb: 
	signal_number = twosComplement(signal_number, signalsize)
    return signal_number*factor_number+offset_number


# big endian assumption 
@njit(numba.u8(numba.u1[:],numba.u1,numba.u1, numba.u4))
def getBigEndiNumberFromBitNpArr(blist, idx, size, id):
    signal_number = 0
    for i in range (0,size):
	signal_number = signal_number | (blist[idx+i] << (size - i  - 1))
    return signal_number
    
@njit(numba.u1(numba.u1[:],numba.u1))
def getIsNegativeBigEndianNumberFormBitNpArr(blist, idx):
    return blist[idx]

@njit(numba.i4(numba.u1[:], numba.u1, numba.u1[:], numba.u1[:], numba.u1[:], numba.u1[:], numba.f8[:], numba.f8[:], numba.u4))
# @njit((numba.u1[:], numba.u1, numba.u1[:], numba.u1[:], numba.u1[:], numba.u1[:], numba.f8[:], numba.f8[:], numba.u4))
def ppParseSignal(barray_unpacked, signal_no, signal_is_signed_types ,signal_start_bits ,signal_is_integers ,signal_sizes ,signal_offsets ,signal_factors , id):
    start_bit_idx = getArrayIdxFromStartBit(signal_start_bits[signal_no])
    this_signal_number = getBigEndiNumberFromBitNpArr(barray_unpacked, start_bit_idx, signal_sizes[signal_no], id)
Ejemplo n.º 6
0
from numba.extending import intrinsic
from numba.core import cgutils
from llvmlite.ir import types as ll_types

#### idrec encoding ####


@njit(Tuple([u2, u8, u1])(u8), cache=True)
def decode_idrec(idrec):
    t_id = idrec >> 48
    f_id = (idrec >> 8) & 0x000FFFFF
    a_id = idrec & 0xF
    return (t_id, f_id, a_id)


@njit(u8(u2, u8, u1), cache=True)
def encode_idrec(t_id, f_id, a_id):
    return (t_id << 48) | (f_id << 8) | a_id


meminfo_type = types.MemInfoPointer(types.voidptr)


@intrinsic
def lower_setattr(typingctx, inst_type, attr_type, val_type):
    if (isinstance(attr_type, types.Literal)
            and isinstance(inst_type, types.StructRef)):

        attr = attr_type.literal_value

        def codegen(context, builder, sig, args):
Ejemplo n.º 7
0
Algorithms currently implemented:
    * xoroshiro128+

References:
    * Wikipedia (https://en.wikipedia.org/wiki/Xorshift)
    * http://xoroshiro.di.unimi.it/
author: Chase Coleman
date: 21 June 2016
"""
import numpy as np

from numba import jit, f8, u8


_PRNGSTATE = np.array([u8(125), u8(234523)])


@jit("u8(u8, u8)", nopython=True, locals={"sf": u8})
def rotl(x, k):
    sf = 64
    return (x<<k) | (x >> (sf - k))


@jit("u8(u8[:])", nopython=True, locals={"result": u8, "s0": u8, "s1": u8, "ff": u8, "ft": u8, "ts": u8})
def next(prngstate):
    # Pull out the states
    s0 = prngstate[0]
    s1 = prngstate[1]

    # Return their sum
Ejemplo n.º 8
0
 def impl(self, identifier):
     return retract_by_idrec(self, u8(identifier))