/* simd.c Test the simd optimization support for gcc */ #include<stdio.h> #define LENGTH(array) (sizeof(array) / sizeof(array[0]))
intmain(){ int vec1 [3]; int vec2 [3]; printf("Input the First Vec:\n"); scanf("%d%d%d",&vec1[0],&vec1[1],&vec1[2]); printf("Input the Secound Vec:\n"); scanf("%d%d%d",&vec2[0],&vec2[1],&vec2[2]);
int vec3[3];
for(int i = 0;i<LENGTH(vec1);i++){ vec3[i] = vec1[i]+vec2[i]; }
printf("Sum Vector is %d %d %d\n",vec3[0],vec3[1],vec3[2]);
# Here are just a few of the key codes import numpy as np import numba as nb # numba jit, which will be introduced next ... @nb.njit(nb.float64[:, :, :](nb.float64[:, :, :], nb.int8), parallel=True, cache=True) defget_lratios_jit(x: np.ndarray, nmom: int = 5) -> np.ndarray: """ Calculates L-moments (up to the specified order) of an array of data using Numba JIT compilation. Args: x (np.ndarray): A 3D array of data. nmom (int, optional): The order of L-moments to compute (default is 5). Returns: np.ndarray: An array containing L-moments up to the specified order. """ defsort_array_with_axis(x: np.ndarray, axis: int) -> np.ndarray: """ Sorts the input array along the specified axis. Args: x (np.ndarray): Input array. axis (int): Axis along which to sort. Returns: np.ndarray: Sorted array. """ for i in nb.prange(x.shape[axis]): x[i] = np.sort(x[i]) return x
x = np.asarray(x, dtype=np.float64) n = x.shape[0]
x = sort_array_with_axis(x, 0)
sum_xtrans = np.empty_like(x[0])
defcomb(n, r): """ Computes the binomial coefficient (n choose r). Args: n (int): Total number of items. r (int): Number of items to choose. Returns: int: Binomial coefficient. """ if r < 0or r > n: return0 if r == 0or r == n: return1 c = 1 for i inrange(1, r + 1): c = c * (n - i + 1) // i return c
@njit(parallel=True) deftest(x): n = x.shape[0] a = np.sin(x) b = np.cos(a * a) acc = 0 for i in prange(n - 2): for j in prange(n - 1): acc += b[i] + b[j + 1] return acc