CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-cupy-cuda12x

CuPy is a NumPy/SciPy-compatible array library for GPU-accelerated computing with Python

Pending
Overview
Eval results
Files

math-functions.mddocs/

Mathematical Functions

Element-wise mathematical operations on GPU arrays, providing the same interface as NumPy while leveraging GPU acceleration. All functions support broadcasting and can operate on arrays of different shapes.

Capabilities

Trigonometric Functions

def sin(x, out=None, **kwargs):
    """Trigonometric sine, 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."""

def hypot(x1, x2, out=None, **kwargs):
    """Hypotenuse given catheti."""

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 phase angles."""

Hyperbolic Functions

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."""

Exponential and Logarithmic Functions

def exp(x, out=None, **kwargs):
    """Calculate exponential of all elements."""

def expm1(x, out=None, **kwargs):
    """Calculate exp(x) - 1 for all elements."""

def exp2(x, out=None, **kwargs):
    """Calculate 2**x for all elements."""

def log(x, out=None, **kwargs):
    """Natural logarithm, element-wise."""

def log10(x, out=None, **kwargs):
    """Base-10 logarithm, element-wise."""

def log2(x, out=None, **kwargs):
    """Base-2 logarithm, element-wise."""

def log1p(x, out=None, **kwargs):
    """Return log(1 + x), element-wise."""

def logaddexp(x1, x2, out=None, **kwargs):
    """Logarithm of the sum of exponentiations."""

def logaddexp2(x1, x2, out=None, **kwargs):
    """Logarithm of the sum of exponentiations in base 2."""

Arithmetic Functions

def add(x1, x2, out=None, **kwargs):
    """Add arguments 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):
    """Returns a true division of the inputs, element-wise."""

def floor_divide(x1, x2, out=None, **kwargs):
    """Return the largest integer smaller or equal to the division."""

def negative(x, out=None, **kwargs):
    """Numerical negative, element-wise."""

def positive(x, out=None, **kwargs):
    """Numerical positive, 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 from second array, element-wise."""

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."""

def fmod(x1, x2, out=None, **kwargs):
    """Return the element-wise remainder of division."""

def divmod(x1, x2, out1=None, out2=None, **kwargs):
    """Return element-wise quotient and remainder simultaneously."""

def modf(x, out1=None, out2=None, **kwargs):
    """Return fractional and integral parts of array, element-wise."""

def reciprocal(x, out=None, **kwargs):
    """Return the reciprocal of the argument, element-wise."""

Rounding Functions

def around(a, decimals=0, out=None):
    """Round to given number of decimals."""

def round_(a, decimals=0, out=None):
    """Round to given number of decimals."""

def rint(x, out=None, **kwargs):
    """Round elements to nearest integers."""

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."""

Sums, Products, Differences

def sum(a, axis=None, dtype=None, out=None, keepdims=False, initial=None, where=True):
    """
    Sum of array elements over given axis.

    Parameters:
    - a: input array
    - axis: axis or axes along which to sum
    - dtype: data type of the output
    - out: output array
    - keepdims: keep dimensions of original array
    - initial: starting value for sum
    - where: elements to include in sum

    Returns:
    cupy.ndarray: sum along specified axis
    """

def prod(a, axis=None, dtype=None, out=None, keepdims=False, initial=None, where=True):
    """Return product of array elements over given axis."""

def nansum(a, axis=None, dtype=None, out=None, keepdims=False):
    """Return sum of array elements, ignoring NaNs."""

def nanprod(a, axis=None, dtype=None, out=None, keepdims=False):
    """Return product of array elements, ignoring NaNs."""

def cumsum(a, axis=None, dtype=None, out=None):
    """Return cumulative sum of elements along axis."""

def cumprod(a, axis=None, dtype=None, out=None):
    """Return cumulative product of elements along axis."""

def nancumsum(a, axis=None, dtype=None, out=None):
    """Return cumulative sum of elements, ignoring NaNs."""

def nancumprod(a, axis=None, dtype=None, out=None):
    """Return cumulative product of elements, ignoring NaNs."""

def diff(a, n=1, axis=-1, prepend=None, append=None):
    """Calculate n-th discrete difference along axis."""

def ediff1d(ary, to_end=None, to_begin=None):
    """Differences between consecutive elements."""

def gradient(f, *varargs, axis=None, edge_order=1):
    """Return gradient of N-dimensional array."""

def trapz(y, x=None, dx=1.0, axis=-1):
    """Integrate using trapezoidal rule."""

Complex Number Functions

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 conj(x, out=None, **kwargs):
    """Return complex conjugate, element-wise."""

def conjugate(x, out=None, **kwargs):
    """Return complex conjugate, element-wise."""

Floating Point Functions

def signbit(x, out=None, **kwargs):
    """Returns element-wise True where signbit is set."""

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 to mantissa and two's exponent."""

def ldexp(x1, x2, out=None, **kwargs):
    """Return x1 * 2**x2, element-wise."""

def nextafter(x1, x2, out=None, **kwargs):
    """Return next floating-point value after x1 towards x2."""

Rational Functions

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|."""

Miscellaneous Functions

def abs(x, out=None, **kwargs):
    """Absolute value element-wise."""

def absolute(x, out=None, **kwargs):
    """Absolute value element-wise."""

def fabs(x, out=None, **kwargs):
    """Absolute values (floating point only)."""

def sign(x, out=None, **kwargs):
    """Sign function."""

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, ignoring NaNs."""

def fmin(x1, x2, out=None, **kwargs):
    """Element-wise minimum, ignoring NaNs."""

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 a real array if complex parts are close to zero."""

def interp(x, xp, fp, left=None, right=None, period=None):
    """One-dimensional linear interpolation."""

def clip(a, a_min, a_max, out=None, **kwargs):
    """Clip (limit) values in array."""

def sqrt(x, out=None, **kwargs):
    """Return non-negative square-root, element-wise."""

def cbrt(x, out=None, **kwargs):
    """Return cube-root, element-wise."""

def square(x, out=None, **kwargs):
    """Return element-wise square of input."""

def convolve(a, v, mode='full'):
    """Return discrete linear convolution of one-dimensional arrays."""

Special Functions

def i0(x):
    """Modified Bessel function of first kind, order 0."""

def sinc(x):
    """Return sinc function."""

Window Functions

def bartlett(M):
    """Return Bartlett window."""

def blackman(M):
    """Return Blackman window."""

def hamming(M):
    """Return Hamming window."""

def hanning(M):
    """Return Hann window."""

def kaiser(M, beta):
    """Return Kaiser window."""

Usage Examples

Basic Mathematical Operations

import cupy as cp

# Create sample data
x = cp.linspace(0, 2*cp.pi, 100)
y = cp.random.random(100)

# Trigonometric functions
sine_values = cp.sin(x)
cosine_values = cp.cos(x)
tangent_values = cp.tan(x)

# Inverse functions
arcsine = cp.arcsin(y)  # y should be in [-1, 1]
phase_angle = cp.arctan2(sine_values, cosine_values)

Exponentials and Logarithms

import cupy as cp

# Exponential functions
x = cp.linspace(-2, 2, 100)
exp_x = cp.exp(x)
exp2_x = cp.exp2(x)  # 2^x
expm1_x = cp.expm1(x)  # exp(x) - 1

# Logarithmic functions
positive_x = cp.abs(x) + 1e-8  # Ensure positive for log
log_x = cp.log(positive_x)
log10_x = cp.log10(positive_x)
log2_x = cp.log2(positive_x)

Array Arithmetic

import cupy as cp

# Create arrays
a = cp.array([1, 2, 3, 4, 5])
b = cp.array([2, 3, 4, 5, 6])

# Basic arithmetic
sum_ab = cp.add(a, b)
diff_ab = cp.subtract(a, b)
prod_ab = cp.multiply(a, b)
quot_ab = cp.divide(a, b)

# Broadcasting works too
scalar = 2
scaled = cp.multiply(a, scalar)
powered = cp.power(a, scalar)

Statistical Reductions

import cupy as cp

# Create 2D array
data = cp.random.random((100, 50))

# Sum operations
total_sum = cp.sum(data)
row_sums = cp.sum(data, axis=1)  # Sum along columns
col_sums = cp.sum(data, axis=0)  # Sum along rows

# Product operations
total_prod = cp.prod(data)
cumulative_sum = cp.cumsum(data, axis=0)

Complex Number Operations

import cupy as cp

# Create complex arrays
real_part = cp.random.random(100)
imag_part = cp.random.random(100)
complex_array = real_part + 1j * imag_part

# Complex operations
magnitude = cp.abs(complex_array)
phase = cp.angle(complex_array)
conjugate = cp.conj(complex_array)

# Extract parts
real_extracted = cp.real(complex_array)
imag_extracted = cp.imag(complex_array)

Install with Tessl CLI

npx tessl i tessl/pypi-cupy-cuda12x

docs

array-operations.md

cuda-interface.md

custom-kernels.md

fft-operations.md

index.md

linear-algebra.md

math-functions.md

random-numbers.md

statistics-sorting.md

tile.json