Add-Even-Indices

Sat 17 May 2025
from numba import njit, prange
import numpy as np
@njit(parallel=True)
def add_even_indices(A):
    s = 0
    # Without "parallel=True" in the jit-decorator
    # the prange statement is equivalent to range
    for i in prange(A.shape[0]):
        if(i % 2 == 0):
            s += A[i]
    return s
abc = add_even_indices(np.array([1, 2, 3, 4, 5, 6]))
abc
9


Score: 5

Category: numba


Add-Even-Numbers

Sat 17 May 2025
from numba import njit, prange
import numpy as np
@njit(parallel=True)
def add_even_numbers(A):
    s = 0
    # Without "parallel=True" in the jit-decorator
    # the prange statement is equivalent to range
    for i in prange(A.shape[0]):
        if(A[i] % 2 == 0):
            s += A[i]
    return s
abc = add_even_numbers(np …

Category: numba

Read More

Monte Carlo Pi

Sat 17 May 2025

title: "Monte Carlo Pi" author: "Raja CSP Raman" date: 2019-05-07 description: "-" type: technical_note draft: false


from numba import jit
import numpy as np
import random
import numba
@numba.jit
def monte_carlo_pi(nsamples):
    acc = 0
    for i in range(nsamples):
        x = random.random()
        y = random.random()
        if (x**2 + y**2 …

Category: numba

Read More

Numba Benchmark

Sat 17 May 2025

title: "Numba Benchmark" author: "Raja CSP Raman" date: 2019-05-07 description: "-" type: technical_note draft: false


from numba import jit
import numpy as np
import time
x = np.arange(100).reshape(10, 10)

@jit(nopython=True)
def go_fast(a): # Function is compiled and runs in machine code
    trace = 0
    for i in …

Category: numba

Read More

Simple-Numba

Sat 17 May 2025

title: "Numba Simple" author: "Raja CSP Raman" date: 2019-05-07 description: "-" type: technical_note draft: false


from numba import njit, prange
import numpy as np

@njit(parallel=True)
def add(A):
    s = 0
    # Without "parallel=True" in the jit-decorator
    # the prange statement is equivalent to range
    for i in prange(A.shape …

Category: numba

Read More
Page 1 of 1