NumPy & SciPy for GPU - CUDA 11.0 compatible package providing GPU-accelerated computing with Python through a NumPy/SciPy-compatible array library
—
Comprehensive set of mathematical functions providing GPU acceleration for trigonometric, hyperbolic, exponential, logarithmic, and arithmetic operations. All functions support element-wise operations on arrays and universal function (ufunc) behavior.
GPU-accelerated trigonometric functions for angle computations.
def sin(x, out=None, **kwargs):
"""
Trigonometric sine, element-wise.
Parameters:
- x: array_like, input array in radians
- out: ndarray, optional output array
Returns:
cupy.ndarray: Sine of x element-wise
"""
def cos(x, out=None, **kwargs):
"""Trigonometric cosine, element-wise."""
def tan(x, out=None, **kwargs):
"""Trigonometric tangent, element-wise."""
def arcsin(x, out=None, **kwargs):
"""Inverse sine, element-wise."""
def arccos(x, out=None, **kwargs):
"""Inverse cosine, element-wise."""
def arctan(x, out=None, **kwargs):
"""Inverse tangent, element-wise."""
def arctan2(x1, x2, out=None, **kwargs):
"""Element-wise arc tangent of x1/x2 choosing quadrant correctly."""
def hypot(x1, x2, out=None, **kwargs):
"""Return sqrt(x1**2 + x2**2), element-wise."""
def degrees(x, out=None, **kwargs):
"""Convert radians to degrees."""
def radians(x, out=None, **kwargs):
"""Convert degrees to radians."""
def deg2rad(x, out=None, **kwargs):
"""Convert degrees to radians."""
def rad2deg(x, out=None, **kwargs):
"""Convert radians to degrees."""
def unwrap(p, discont=3.141592653589793, axis=-1):
"""Unwrap by changing deltas between values to 2*pi complement."""Hyperbolic trigonometric functions for mathematical computations.
def sinh(x, out=None, **kwargs):
"""Hyperbolic sine, element-wise."""
def cosh(x, out=None, **kwargs):
"""Hyperbolic cosine, element-wise."""
def tanh(x, out=None, **kwargs):
"""Hyperbolic tangent, element-wise."""
def arcsinh(x, out=None, **kwargs):
"""Inverse hyperbolic sine, element-wise."""
def arccosh(x, out=None, **kwargs):
"""Inverse hyperbolic cosine, element-wise."""
def arctanh(x, out=None, **kwargs):
"""Inverse hyperbolic tangent, element-wise."""Functions for exponential and logarithmic computations.
def exp(x, out=None, **kwargs):
"""
Calculate exponential of all elements in input array.
Parameters:
- x: array_like, input values
- out: ndarray, optional output array
Returns:
cupy.ndarray: Element-wise exponential of x
"""
def exp2(x, out=None, **kwargs):
"""Calculate 2**x for all x in input array."""
def expm1(x, out=None, **kwargs):
"""Calculate exp(x) - 1 for all x in input array."""
def log(x, out=None, **kwargs):
"""Natural logarithm, element-wise."""
def log10(x, out=None, **kwargs):
"""Base-10 logarithm of x."""
def log2(x, out=None, **kwargs):
"""Base-2 logarithm of x."""
def log1p(x, out=None, **kwargs):
"""Return natural logarithm of one plus input array."""
def logaddexp(x1, x2, out=None, **kwargs):
"""Logarithm of sum of exponentials of inputs."""
def logaddexp2(x1, x2, out=None, **kwargs):
"""Logarithm of sum of exponentials of inputs in base 2."""Basic arithmetic operations supporting broadcasting and type promotion.
def add(x1, x2, out=None, **kwargs):
"""
Add arguments element-wise.
Parameters:
- x1, x2: array_like, input arrays to add
- out: ndarray, optional output array
Returns:
cupy.ndarray: Sum of x1 and x2, element-wise
"""
def subtract(x1, x2, out=None, **kwargs):
"""Subtract arguments element-wise."""
def multiply(x1, x2, out=None, **kwargs):
"""Multiply arguments element-wise."""
def divide(x1, x2, out=None, **kwargs):
"""Divide arguments element-wise."""
def true_divide(x1, x2, out=None, **kwargs):
"""True division of arguments element-wise."""
def floor_divide(x1, x2, out=None, **kwargs):
"""Floor division of arguments element-wise."""
def power(x1, x2, out=None, **kwargs):
"""First array elements raised to powers from second array."""
def float_power(x1, x2, out=None, **kwargs):
"""First array elements raised to powers, promoting to float."""
def remainder(x1, x2, out=None, **kwargs):
"""Return element-wise remainder of division."""
def mod(x1, x2, out=None, **kwargs):
"""Return element-wise remainder of division (same as remainder)."""
def fmod(x1, x2, out=None, **kwargs):
"""Return element-wise remainder of division."""
def divmod(x1, x2, out1=None, out2=None, **kwargs):
"""Return element-wise quotient and remainder."""
def negative(x, out=None, **kwargs):
"""Numerical negative, element-wise."""
def positive(x, out=None, **kwargs):
"""Numerical positive, element-wise."""
def reciprocal(x, out=None, **kwargs):
"""Return reciprocal of argument, element-wise."""Functions for complex number manipulation and analysis.
def angle(z, deg=False):
"""Return angle of complex argument."""
def real(val):
"""Return real part of complex argument."""
def imag(val):
"""Return imaginary part of complex argument."""
def conjugate(x, out=None, **kwargs):
"""Return complex conjugate, element-wise."""
def conj(x, out=None, **kwargs):
"""Return complex conjugate, element-wise (same as conjugate)."""Functions for rounding and truncating numerical values.
def around(a, decimals=0, out=None):
"""
Round array to given number of decimals.
Parameters:
- a: array_like, input data
- decimals: int, number of decimal places to round to
- out: ndarray, optional output array
Returns:
cupy.ndarray: Rounded array
"""
def round_(a, decimals=0, out=None):
"""Round array to given number of decimals (same as around)."""
def rint(x, out=None, **kwargs):
"""Round elements to nearest integer."""
def fix(x, out=None):
"""Round to nearest integer towards zero."""
def floor(x, out=None, **kwargs):
"""Return floor of input, element-wise."""
def ceil(x, out=None, **kwargs):
"""Return ceiling of input, element-wise."""
def trunc(x, out=None, **kwargs):
"""Return truncated value of input, element-wise."""Various mathematical utility functions.
def sqrt(x, out=None, **kwargs):
"""
Return non-negative square-root of array, element-wise.
Parameters:
- x: array_like, input array
- out: ndarray, optional output array
Returns:
cupy.ndarray: Square-root of x, element-wise
"""
def square(x, out=None, **kwargs):
"""Return element-wise square of input."""
def absolute(x, out=None, **kwargs):
"""Calculate absolute value element-wise."""
def abs(x, out=None, **kwargs):
"""Calculate absolute value element-wise (same as absolute)."""
def cbrt(x, out=None, **kwargs):
"""Return cube-root of array, element-wise."""
def fabs(x, out=None, **kwargs):
"""Compute absolute values element-wise."""
def sign(x, out=None, **kwargs):
"""Returns element-wise indication of sign of number."""
def heaviside(x1, x2, out=None, **kwargs):
"""Compute Heaviside step function."""
def maximum(x1, x2, out=None, **kwargs):
"""Element-wise maximum of array elements."""
def minimum(x1, x2, out=None, **kwargs):
"""Element-wise minimum of array elements."""
def fmax(x1, x2, out=None, **kwargs):
"""Element-wise maximum of array elements (ignores NaNs)."""
def fmin(x1, x2, out=None, **kwargs):
"""Element-wise minimum of array elements (ignores NaNs)."""
def clip(a, a_min, a_max, out=None, **kwargs):
"""Clip values in array to specified range."""
def nan_to_num(x, copy=True, nan=0.0, posinf=None, neginf=None):
"""Replace NaN with zero and infinity with large finite numbers."""
def real_if_close(a, tol=100):
"""If complex input returns real part if imaginary part is close to zero."""
def interp(x, xp, fp, left=None, right=None, period=None):
"""One-dimensional linear interpolation."""
def convolve(a, v, mode='full'):
"""Return discrete linear convolution of one-dimensional arrays."""Special mathematical functions for advanced computations.
def i0(x):
"""Modified Bessel function of first kind, order 0."""
def sinc(x):
"""Return sinc function (sin(pi*x)/(pi*x))."""Functions for floating point number manipulation and analysis.
def copysign(x1, x2, out=None, **kwargs):
"""Change sign of x1 to that of x2, element-wise."""
def frexp(x, out1=None, out2=None, **kwargs):
"""Decompose elements of x into mantissa and exponent."""
def ldexp(x1, x2, out=None, **kwargs):
"""Compute x1 * 2**x2, element-wise."""
def nextafter(x1, x2, out=None, **kwargs):
"""Return next floating-point value after x1 towards x2."""
def signbit(x, out=None, **kwargs):
"""Returns element-wise True where signbit is set."""Functions specific to integer operations.
def gcd(x1, x2, out=None, **kwargs):
"""Return greatest common divisor of |x1| and |x2|."""
def lcm(x1, x2, out=None, **kwargs):
"""Return least common multiple of |x1| and |x2|."""import cupy as cp
# Create sample data
x = cp.linspace(0, 2*cp.pi, 100)
y = cp.random.random((1000, 1000))
# Trigonometric functions
sin_x = cp.sin(x)
cos_x = cp.cos(x)
tan_x = cp.tan(x)
# Combine operations
result = cp.sin(x) * cp.cos(x) + cp.tan(x/2)
# Exponential and logarithmic
exp_y = cp.exp(y)
log_y = cp.log(y + 1) # Add 1 to avoid log(0)
# Power operations
squared = cp.square(y)
sqrt_y = cp.sqrt(y)
power_result = cp.power(y, 2.5)# Complex number operations
complex_arr = cp.array([1+2j, 3-4j, 5+0j])
magnitudes = cp.absolute(complex_arr)
angles = cp.angle(complex_arr)
conjugates = cp.conjugate(complex_arr)
# Rounding and clipping
data = cp.random.normal(0, 1, (100, 100))
rounded = cp.around(data, decimals=2)
clipped = cp.clip(data, -2, 2)
# Element-wise comparisons and selections
a = cp.random.random((100, 100))
b = cp.random.random((100, 100))
max_values = cp.maximum(a, b)
min_values = cp.minimum(a, b)# Broadcasting with different shapes
scalar = 5
vector = cp.array([1, 2, 3, 4])
matrix = cp.random.random((4, 3))
# Operations automatically broadcast
result1 = matrix + scalar # Add scalar to all elements
result2 = matrix + vector.reshape(-1, 1) # Add vector to each column
# Universal function behavior
ufunc_result = cp.add.reduce(matrix, axis=0) # Sum along first axis
accumulated = cp.add.accumulate(vector) # Cumulative sumInstall with Tessl CLI
npx tessl i tessl/pypi-cupy-cuda110