コード例 #1
0
ファイル: buffer.py プロジェクト: guilhermeleobas/rbc
def omnisci_buffer_len_(typingctx, data):
    sig = types.int64(data)

    def codegen(context, builder, signature, args):
        data, = args
        return irutils.get_member_value(builder, data, 1)

    return sig, codegen
コード例 #2
0
    def test_cfunc_custom_pipeline(self):
        self.assertListEqual(self.pipeline_class.custom_pipeline_cache, [])

        @cfunc(types.int64(types.int64), pipeline_class=self.pipeline_class)
        def foo(x):
            return x

        self.assertEqual(foo(4), 4)
        self.assertListEqual(self.pipeline_class.custom_pipeline_cache,
                             [foo.__wrapped__])
コード例 #3
0
ファイル: buffer.py プロジェクト: guilhermeleobas/rbc
def omnisci_buffer_ptr_len_(typingctx, data):
    sig = types.int64(data)

    def codegen(context, builder, signature, args):
        data, = args
        rawptr = cgutils.alloca_once_value(builder, value=data)
        struct = builder.load(builder.gep(rawptr, [int32_t(0)]))
        return builder.load(builder.gep(struct, [int32_t(0), int32_t(1)]))

    return sig, codegen
コード例 #4
0
def omnisci_buffer_len_(typingctx, data):
    sig = types.int64(data)

    def codegen(context, builder, signature, args):
        data, = args
        assert data.opname == 'load'
        struct = data.operands[0]
        return builder.load(builder.gep(struct, [int32_t(0), int32_t(1)]))

    return sig, codegen
コード例 #5
0
            def generic(self, args, kws):
                signature = types.int64(types.float64)

                # insert a new builtin during the compilation process
                @lower_builtin(issue7507_lround, types.float64)
                def codegen(context, builder, sig, args):
                    # Simply truncate with the cast to integer.
                    return context.cast(builder, args[0], sig.args[0],
                                        sig.return_type)

                return signature
コード例 #6
0
    def test_isinstance_numba_types(self):
        # This makes use of type aliasing between python scalars and NumPy
        # scalars, see also test_numba_types()
        pyfunc = isinstance_usecase_numba_types
        cfunc = jit(nopython=True)(pyfunc)

        inputs = ((types.int32(1), 'int32'), (types.int64(2), 'int64'),
                  (types.float32(3.0), 'float32'), (types.float64(4.0),
                                                    'float64'),
                  (types.complex64(5j), 'no match'), (typed.List([1, 2]),
                                                      'typed list'),
                  (typed.Dict.empty(types.int64, types.int64), 'typed dict'))

        for inpt, expected in inputs:
            got = cfunc(inpt)
            self.assertEqual(expected, got)
コード例 #7
0
def add_ints(typingctx, a_type, b_type):
    if (a_type, b_type) != (nb_types.int64, nb_types.int64):
        raise TypingError('add_ints(i64, i64)')

    sig = nb_types.int64(nb_types.int64, nb_types.int64)

    def codegen(context, builder, signature, args):
        assert len(args) == 2
        arg_a, arg_b = args
        int64_t = ir.IntType(64)
        fntype = ir.FunctionType(int64_t, [int64_t, int64_t])
        fn = irutils.get_or_insert_function(builder.module,
                                            fntype,
                                            name="_rbclib_add_ints")
        return builder.call(fn, [arg_a, arg_b])

    return sig, codegen
コード例 #8
0
def int_hash(val):

    _HASH_I64_MIN = -2 if sys.maxsize <= 2**32 else -4
    _SIGNED_MIN = types.int64(-0x8000000000000000)

    # Find a suitable type to hold a "big" value, i.e. iinfo(ty).min/max
    # this is to ensure e.g. int32.min is handled ok as it's abs() is its value
    _BIG = types.int64 if getattr(val, 'signed', False) else types.uint64

    # this is a bit involved due to the CPython repr of ints
    def impl(val):
        # If the magnitude is under PyHASH_MODULUS, just return the
        # value val as the hash, couple of special cases if val == val:
        # 1. it's 0, in which case return 0
        # 2. it's signed int minimum value, return the value CPython computes
        # but Numba cannot as there's no type wide enough to hold the shifts.
        #
        # If the magnitude is greater than PyHASH_MODULUS then... if the value
        # is negative then negate it switch the sign on the hash once computed
        # and use the standard wide unsigned hash implementation
        val = _BIG(val)
        mag = abs(val)
        if mag < _PyHASH_MODULUS:
            if val == 0:
                ret = 0
            elif val == _SIGNED_MIN:  # e.g. int64 min, -0x8000000000000000
                ret = _Py_hash_t(_HASH_I64_MIN)
            else:
                ret = _Py_hash_t(val)
        else:
            needs_negate = False
            if val < 0:
                val = -val
                needs_negate = True
            ret = _long_impl(val)
            if needs_negate:
                ret = -ret
        return process_return(ret)

    return impl
コード例 #9
0
ファイル: str_ext.py プロジェクト: ls-pepper/sdc
@box(CharType)
def box_char(typ, val, c):
    """
    """
    fnty = lir.FunctionType(lir.IntType(8).as_pointer(), [lir.IntType(8)])
    fn = c.builder.module.get_or_insert_function(fnty, name="get_char_ptr")
    c_str = c.builder.call(fn, [val])
    pystr = c.pyapi.string_from_string_and_size(
        c_str, c.context.get_constant(types.intp, 1))
    # TODO: delete ptr
    return pystr


del_str = types.ExternalFunction("del_str", types.void(std_str_type))
_hash_str = types.ExternalFunction("_hash_str", types.int64(std_str_type))
get_c_str = types.ExternalFunction("get_c_str", types.voidptr(std_str_type))


@overload_method(StringType, 'c_str')
def str_c_str(str_typ):
    return lambda s: get_c_str(s)


@overload_method(StringType, 'join')
def str_join(str_typ, iterable_typ):
    # TODO: more efficient implementation (e.g. C++ string buffer)
    def str_join_impl(sep_str, str_container):
        res = ""
        counter = 0
        for s in str_container:
コード例 #10
0
directions_d[PAWN] = np.array([N, N+N, N+W, N+E, STOP], dtype='i8')
directions_d[KNIGHT] = np.array([N+N+E, E+N+E, E+S+E, S+S+E, S+S+W, W+S+W, W+N+W, N+N+W, STOP], dtype='i8')
directions_d[BISHOP] = np.array([N+E, S+E, S+W, N+W, STOP], dtype='i8')
directions_d[ROOK] = np.array([N, E, S, W, STOP], dtype='i8')
directions_d[QUEEN] = np.array([N, E, S, W, N+E, S+E, S+W, N+W, STOP], dtype='i8')
directions_d[KING] = np.array([N, E, S, W, N+E, S+E, S+W, N+W, STOP], dtype='i8')
directions = np.empty((KING + 1, 10), dtype=np.int64)
for k in directions_d:
    directions[k, :len(directions_d[k])] = directions_d[k]

# Mate value must be greater than 8*queen + 2*(rook+knight+bishop)
# King value is set to twice this value such that if the opponent is
# 8 queens up, but we got the king, we still exceed MATE_VALUE.
# When a MATE is detected, we'll set the score to MATE_UPPER - plies to get there
# E.g. Mate in 3 will be MATE_UPPER - 6
MATE_LOWER = types.int64(piece[KING] - 10*piece[QUEEN])
MATE_UPPER = types.int64(piece[KING] + 10*piece[QUEEN])

# The table size is the maximum number of elements in the transposition table.
TABLE_SIZE = 1e7

# Constants for tuning search
QS_LIMIT = 219
EVAL_ROUGHNESS = 13
DRAW_TEST = True

zobrist = np.random.randint(np.iinfo(np.int64).min, np.iinfo(np.int64).max, size=(len(initial), BLACK_KING + 1), dtype=np.int64)

@njit
def zhash(board):
    h = np.int64(0)
コード例 #11
0
ファイル: nunfish.py プロジェクト: juliusbierk/sunfish
    W + N + W, N + N + W
],
                           dtype='i8')
directions['B'] = np.array([N + E, S + E, S + W, N + W], dtype='i8')
directions['R'] = np.array([N, E, S, W], dtype='i8')
directions['Q'] = np.array([N, E, S, W, N + E, S + E, S + W, N + W],
                           dtype='i8')
directions['K'] = np.array([N, E, S, W, N + E, S + E, S + W, N + W],
                           dtype='i8')

# Mate value must be greater than 8*queen + 2*(rook+knight+bishop)
# King value is set to twice this value such that if the opponent is
# 8 queens up, but we got the king, we still exceed MATE_VALUE.
# When a MATE is detected, we'll set the score to MATE_UPPER - plies to get there
# E.g. Mate in 3 will be MATE_UPPER - 6
MATE_LOWER = types.int64(piece['K'] - 10 * piece['Q'])
MATE_UPPER = types.int64(piece['K'] + 10 * piece['Q'])

# The table size is the maximum number of elements in the transposition table.
TABLE_SIZE = 1e7

# Constants for tuning search
QS_LIMIT = 219
EVAL_ROUGHNESS = 13
DRAW_TEST = True


@njit
def put(board, i, p):
    return board[:i] + p + board[i + 1:]