Example #1
0
    def codegen(cgctx, builder, signature, args):
        # This is the implementation defined using LLVM builder.
        lltupty = cgctx.get_value_type(typed_tuple)
        tup = cgutils.get_null_value(lltupty)

        [_, idxaryval] = args

        def array_checker(a):
            if a.size != tuple_size:
                raise IndexError("index array size mismatch")

        # Compile and call array_checker.
        cgctx.compile_internal(builder, array_checker,
                               types.none(indexer_array), [idxaryval])

        def array_indexer(a, i):
            return a[i]

        # loop to fill the tuple
        for i in range(tuple_size):
            dataidx = cgctx.get_constant(types.intp, i)
            # compile and call array_indexer
            data = cgctx.compile_internal(
                builder,
                array_indexer,
                indexer_array.dtype(indexer_array, types.intp),
                [idxaryval, dataidx],
            )
            tup = builder.insert_value(tup, data, i)
        return tup
Example #2
0
def set_null_bits(typingctx, str_arr_typ=None):
    assert is_str_arr_typ(str_arr_typ)

    def codegen(context, builder, sig, args):
        in_str_arr, = args
        string_array = context.make_helper(builder, string_array_type,
                                           in_str_arr)
        # n_bytes = (num_strings+sizeof(uint8_t)-1)/sizeof(uint8_t);
        n_bytes = builder.udiv(
            builder.add(string_array.num_items,
                        lir.Constant(lir.IntType(64), 7)),
            lir.Constant(lir.IntType(64), 8))
        cgutils.memset(builder, string_array.null_bitmap, n_bytes, -1)
        return context.get_dummy_value()

    return types.none(string_array_type), codegen
Example #3
0
def _multi_index_from_tuples_helper(typingctx, val, levels, codes, idx):

    nlevels = len(val)
    if not (nlevels == len(levels) and nlevels == len(codes)):
        assert True, f"Cannot append MultiIndex value to existing codes/levels.\n" \
                     f"Given: val={val}, levels={levels}, codes={codes}"

    def _get_code_for_label(seen_labels, label):

        _code = seen_labels.get(label, -1)
        if _code != -1:
            return _code

        res = len(seen_labels)
        seen_labels[label] = res
        return types.int64(res)

    def _set_code_by_position(codes, new_code, i):
        codes[i] = new_code

    def codegen(context, builder, sig, args):
        index_val, levels_val, codes_val, idx_val = args

        for i in range(nlevels):
            label = builder.extract_value(index_val, i)
            level_i = builder.extract_value(levels_val, i)
            codes_i = builder.extract_value(codes_val, i)

            new_code = context.compile_internal(
                builder, _get_code_for_label,
                signature(types.int64, levels[i], val[i]), [level_i, label])
            context.compile_internal(
                builder, _set_code_by_position,
                signature(types.none, codes[i], types.int64, idx),
                [codes_i, new_code, idx_val])

    return types.none(val, levels, codes, idx), codegen
Example #4
0
                                     np.zeros(num_rotors)]
rotor_axes = np.repeat(np.c_[0, 0, 1], num_rotors, axis=0)
rotor_directions = (-1)**np.r_[0:num_rotors]
# Thrust coefficients from https://www.bitcraze.io/2015/02/measuring-propeller-rpm-part-3/
thrust_rpm_max = (mass + 5) * 9.82
thrust_coeffs = np.r_[+1.0942e-07, -2.1059e-04, 0.0]
thrust_coeffs *= thrust_rpm_max / np.polyval(thrust_coeffs, rpm_max)
z_torque_per_rpm = 5e-4 / rpm_max

(ipx, ipy, ipz, iqi, iqj, iqk, iqr, ivx, ivy, ivz, iwx, iwy, iwz, iw0, iw1,
 iw2, iw3, imax) = range(13 + num_rotors + 1)

num_substeps = env_param('num_substeps', default=2, cast=int)


@nb.njit(none(TimeDeltaT, StateT, ActionT, StateT), cache=True, nogil=True)
def x_dot_out(t, x, u, out):
    x[3:7] /= np.linalg.norm(x[3:7]) + eps
    attq, linvel, angvel, rpms = x[3:7], x[7:10], x[10:13], x[13:]
    rpms = u * rpm_max
    force_bf = np.zeros(3)
    torque = np.zeros(3)
    for i in range(num_rotors):
        rotor_force = polyval(thrust_coeffs, rpms[i]) * rotor_axes[i, :]
        force_bf += rotor_force
        torque += cross(rotor_positions[i, :], rotor_force)
        torque += z_torque_per_rpm * rotor_directions[i] * (
            rpms[i]**2) * rotor_axes[i, :]
    torque -= angvel * friction_torque
    # Disabled because cross(av, v) = 0 for scalar a and vector v. In cases
    # where moment of inertia isn't scalar, this is needed.
Example #5
0
    ll.add_symbol('hpat_h5_write', _hdf5.hpat_h5_write)
    ll.add_symbol('hpat_h5_close', _hdf5.hpat_h5_close)
    ll.add_symbol('h5g_get_num_objs', _hdf5.h5g_get_num_objs)
    ll.add_symbol('h5g_get_objname_by_idx', _hdf5.h5g_get_objname_by_idx)
    ll.add_symbol('h5g_close', _hdf5.hpat_h5g_close)

h5file_lir_type = lir.IntType(64)

if hpat.config._has_h5py:
    # hid_t is 32bit in 1.8 but 64bit in 1.10
    if h5py.version.hdf5_version_tuple[1] == 8:
        h5file_lir_type = lir.IntType(32)
    else:
        assert h5py.version.hdf5_version_tuple[1] == 10

h5g_close = types.ExternalFunction("h5g_close", types.none(h5group_type))


@lower_builtin(operator.getitem, h5file_type, string_type)
@lower_builtin(operator.getitem, h5dataset_or_group_type, string_type)
def h5_open_dset_lower(context, builder, sig, args):
    fg_id, dset_name = args
    dset_name = gen_get_unicode_chars(context, builder, dset_name)

    fnty = lir.FunctionType(h5file_lir_type, [h5file_lir_type, lir.IntType(8).as_pointer()])
    fn = builder.module.get_or_insert_function(fnty, name="hpat_h5_open_dset_or_group_obj")
    return builder.call(fn, [fg_id, dset_name])


if hpat.config._has_h5py:
    @lower_builtin(h5py.File, string_type, string_type)