def gaussian_filter(in_, out, y, x, width, height): in_array = carray(in_, (height, width, 3)) out_array = carray(out, (height, width, 3)) for k in range(3): sum_ = 0. for p in range(-2, 3): for q in range(-2, 3): sum_ += gKernel[p+2, q+2] * in_array[y+p,x+q,k] out_array[y, x, k] = sum_
def _calc_vanmarcke1975_ccdf(n, a): """Calculate the Vanmarcke (1975) complementary CDF. Parameters ---------- n : int Length of arguments a : list of floats Arguments specifying: - function value `x` - number of zero crossing - effective bandwdith Returns ------- ccdf : float Complementary CDF value """ args = numba.carray(a, n) x = args[0] num_zero_crossings = args[1] bandwidth_eff = args[2] return (1 - (1 - np.exp(-x ** 2 / 2)) * np.exp(-1 * num_zero_crossings * ( 1 - np.exp(-1 * np.sqrt(np.pi / 2) * bandwidth_eff * x)) / (np.exp(x ** 2 / 2) - 1)))
def __init__(self, type, value, subslices, nopython, **kwargs): super(NativeSliceNode, self).__init__(**kwargs) value = nodes.CloneableNode(value) self.type = type self.value = value self.subslices = subslices self.shape_type = numba.carray(npy_intp, type.ndim) self.nopython = nopython if not nopython: self.build_array_node = self.build_array() else: self.build_array_node = None
def __init__(self, array_type, operands, **kwargs): super(BroadcastNode, self).__init__(**kwargs) self.operands = operands self.shape_type = numba.carray(npy_intp, array_type.ndim) self.array_type = array_type self.type = npy_intp.pointer() self.broadcast_retvals = {} self.check_errors = [] for op in operands: if op.type.is_array: # TODO: Put the raise code in a separate basic block and jump return_value = nodes.LLVMValueRefNode(int_, None) check_error = nodes.CheckErrorNode( return_value, 0, exc_type=ValueError, exc_msg="Shape mismatch while broadcasting") self.broadcast_retvals[op] = return_value self.check_errors.append(check_error)
def _calc_cartwright_pf(n, a): """Integrand for the Cartwright and Longuet-Higgins peak factor. Parameters ---------- n : int Length of arguments a : list of floats Arguments specifying: - function value `x` - number of extrema - bandwdith Returns ------- dpf : float Portion of the peak factor """ args = numba.carray(a, n) x = args[0] num_extrema = args[1] bandwidth = args[2] return 1. - (1. - bandwidth * np.exp(-x * x)) ** num_extrema
def func_to_apply_c(x, y, z, field_value_): field_value = carray(field_value_, (6, )) # field is array of 6 elements # (Ex, Ey, Ez, Bx, By, Bz) field_value[1] *= np.cos(np.pi / 20.0 * x)**2 # Ey field_value[5] *= np.cos(np.pi / 20.0 * x)**2 # Bz
def _S(outArr, q): Q = carray(q, (V, )) ret = carray(outArr, (V, )) SQ = Sjit(Q) for i in range(V): ret[i] = SQ[i]
def wrapper(z_, x_, y_): z = carray(z_, 1)[0] x = carray(x_, 1)[0] y = carray(y_, 1)[0] jitfunc(z, x, y)
def wrapped(in_values_ptr, len_in, out_values_ptr, len_out, data): in_values = carray(in_values_ptr, (len_in,), dtype=float64) out_values = carray(out_values_ptr, (len_out,), dtype=float64) jitted_function(in_values, out_values) return 1
def foo(ptr, n): base = carray(ptr, n) return calc(base)
def next_double(st): bit_gen_state = carray(st, (2, ), dtype=np.uint64) return (np.uint64(splitmix_next(bit_gen_state)) >> np.uint64(11)) / 9007199254740992.0
def _vega_integrand(u, params): k, t, v, kappa, a, nu, rho = carray(params, (7, )) psi_1, psi_2 = _heston_psi(u - 0.5j, t, kappa, a, nu, rho) return common._vega_integrand(u, k, v, psi_1, psi_2)
def callback(inta, intb): arr_a = numba.carray(inta, (1, )) arr_b = numba.carray(intb, (1, )) return arr_a[0] - arr_b[0]
def A_x_F_real(x, data): xi, xi2, h_nodes, z = numba.carray(data, 4, dtype=numba.float64) return A_x_F(x, xi, xi2, h_nodes, z).real
def impl(): return numba.carray( # pylint: disable-next=no-value-for-parameter _address_as_void_pointer(_MPI_Double_ptr), shape=(1, ), dtype=np.intp)[0]
def array_constructor() -> np.ndarray: """helper that reconstructs the array from the pointer and structural info""" data: np.ndarray = nb.carray(address_as_void_pointer(data_addr), shape, dtype) if strides is not None: data = np.lib.index_tricks.as_strided(data, shape, strides) # type: ignore return data
def _crack_tip_integrand(x, data): alpha, k_p, k_s = numba.carray(data, 3, dtype=numba.float64) return -math.atan( (4 * x ** 2 * math.sqrt(x ** 2 - k_p ** 2) * math.sqrt(k_s ** 2 - x ** 2)) / (2 * x ** 2 - k_s ** 2) ** 2 ) / ((x + alpha) * math.pi)
def my_callback(in_, out, m, n): in_array = carray(in_, (m, n)) out_array = carray(out, (m, n)) for i in range(m): for j in range(n): out_array[i, j] = 2 * in_array[i, j]
def wrapped(output_ptr, input_ptr, output_rank, input_rank, user_data): output_coords = carray(output_ptr, (output_rank,), dtype=intp) input_coords = carray(input_ptr, (output_rank,), dtype=float64) jitted_function(output_coords, input_coords) return 1
def set_all_values_to_float(out_ptr, out_shape_ptr, ndim_out, in_ptr, in_shape_ptr, ndim_in): out_shape = carray(out_shape_ptr, ndim_out) out_arr = carray(out_ptr, (out_shape[0], out_shape[1], out_shape[2])) out_arr[:] = 0.5
def integrand_cfunc(N, XX): vals = numba.carray(XX, N) return jitted(vals)
def change_out_shape(out_ptr, out_shape_ptr, ndim_out, in_ptr, in_shape_ptr, ndim_in): out_shape = carray(out_shape_ptr, ndim_out) out_arr = carray(out_ptr, (out_shape[0], out_shape[1], out_shape[2])) out_arr[:] = 42
def hello_cfunc(in_ptr, out_ptr, size): in_arr = carray(in_ptr, size) out_arr = carray(out_ptr, size) out_arr[:] = 255
def next_64(st): bit_gen_state = carray(st, (2, ), dtype=np.uint64) return splitmix_next(bit_gen_state)
def A_x_F2_imag(x, data): xi, xi2, h_nodes, z = numba.carray(data, 4, dtype=numba.float64) return A_x_F2(x, xi, xi2, h_nodes, z).imag
def eval(values, num_points, value_size, x, gdim, t): np_values = numba.carray(values, (num_points, value_size), dtype=scalar_type) np_x = numba.carray(x, (num_points, gdim), dtype=numba.types.double) f_jit(np_values, np_x, t)
def wrapped(n, xx): values = carray(xx,n) return jitted_function(values)
def wrapped(values_ptr, len_values, result, data): values = carray(values_ptr, (len_values, ), dtype=float64) result[0] = jitted_function(values) return 1
def run_cfunc(out_ptr, out_shapes_ptr, out_ndims_ptr, num_outs, in_ptr, in_shapes_ptr, in_ndims_ptr, num_ins, num_samples): out0 = out1 = out2 = out3 = out4 = out5 = None out_shapes_np = _get_shape_view(out_shapes_ptr, out_ndims_ptr, num_outs, num_samples) out_arr = carray(address_as_void_pointer(out_ptr), (num_outs, num_samples), dtype=np.int64) if num_outs >= 1: out0 = [ out0_lambda(address_as_void_pointer(ptr), shape) for ptr, shape in zip(out_arr[0], out_shapes_np[0]) ] if num_outs >= 2: out1 = [ out1_lambda(address_as_void_pointer(ptr), shape) for ptr, shape in zip(out_arr[1], out_shapes_np[1]) ] if num_outs >= 3: out2 = [ out2_lambda(address_as_void_pointer(ptr), shape) for ptr, shape in zip(out_arr[2], out_shapes_np[2]) ] if num_outs >= 4: out3 = [ out3_lambda(address_as_void_pointer(ptr), shape) for ptr, shape in zip(out_arr[3], out_shapes_np[3]) ] if num_outs >= 5: out4 = [ out4_lambda(address_as_void_pointer(ptr), shape) for ptr, shape in zip(out_arr[4], out_shapes_np[4]) ] if num_outs >= 6: out5 = [ out5_lambda(address_as_void_pointer(ptr), shape) for ptr, shape in zip(out_arr[5], out_shapes_np[5]) ] in0 = in1 = in2 = in3 = in4 = in5 = None in_shapes_np = _get_shape_view(in_shapes_ptr, in_ndims_ptr, num_ins, num_samples) in_arr = carray(address_as_void_pointer(in_ptr), (num_ins, num_samples), dtype=np.int64) if num_ins >= 1: in0 = [ in0_lambda(address_as_void_pointer(ptr), shape) for ptr, shape in zip(in_arr[0], in_shapes_np[0]) ] if num_ins >= 2: in1 = [ in1_lambda(address_as_void_pointer(ptr), shape) for ptr, shape in zip(in_arr[1], in_shapes_np[1]) ] if num_ins >= 3: in2 = [ in2_lambda(address_as_void_pointer(ptr), shape) for ptr, shape in zip(in_arr[2], in_shapes_np[2]) ] if num_ins >= 4: in3 = [ in3_lambda(address_as_void_pointer(ptr), shape) for ptr, shape in zip(in_arr[3], in_shapes_np[3]) ] if num_ins >= 5: in4 = [ in4_lambda(address_as_void_pointer(ptr), shape) for ptr, shape in zip(in_arr[4], in_shapes_np[4]) ] if num_ins >= 6: in5 = [ in5_lambda(address_as_void_pointer(ptr), shape) for ptr, shape in zip(in_arr[5], in_shapes_np[5]) ] run_fn_lambda(run_fn, out0, out1, out2, out3, out4, out5, in0, in1, in2, in3, in4, in5)