CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-cupy-rocm-4-3

CuPy: NumPy & SciPy for GPU - A NumPy/SciPy-compatible array library for GPU-accelerated computing with Python, specifically built for AMD ROCm 4.3 platform

Pending
Overview
Eval results
Files

array-creation.mddocs/

Array Creation and Manipulation

Core array creation functions and manipulation operations that provide the foundation for GPU-accelerated computing with CuPy. These functions create and modify GPU arrays while maintaining full NumPy API compatibility.

Capabilities

Basic Array Creation

Creates arrays with specified shapes and values, providing the fundamental building blocks for GPU computations.

def array(object, dtype=None, copy=True, order='K', subok=False, ndmin=0):
    """
    Create an array on GPU from an array-like object.
    
    Parameters:
    - object: array-like, input data to convert to GPU array
    - dtype: data type, if None, inferred from input
    - copy: bool, whether to copy data (default True)
    - order: {'C', 'F', 'A', 'K'}, memory layout
    - subok: bool, whether to allow subclasses
    - ndmin: int, minimum number of dimensions
    
    Returns:
    cupy.ndarray: GPU array
    """

def asarray(a, dtype=None, order=None):
    """
    Convert input to GPU array.
    
    Parameters:
    - a: array-like, input data
    - dtype: data type, if None, preserve input dtype
    - order: {'C', 'F', 'A', 'K'}, memory layout
    
    Returns:
    cupy.ndarray: GPU array
    """

def copy(a, order='K'):
    """
    Return a copy of the array.
    
    Parameters:
    - a: cupy.ndarray, input array
    - order: {'C', 'F', 'A', 'K'}, memory layout of copy
    
    Returns:
    cupy.ndarray: Copy of input array
    """

Array Initialization

Create arrays with specific initialization patterns including zeros, ones, and uninitialized arrays.

def zeros(shape, dtype=float, order='C'):
    """
    Create array filled with zeros.
    
    Parameters:
    - shape: int or tuple of ints, shape of array
    - dtype: data type, default float
    - order: {'C', 'F'}, memory layout
    
    Returns:
    cupy.ndarray: Array of zeros
    """

def ones(shape, dtype=None, order='C'):
    """
    Create array filled with ones.
    
    Parameters:
    - shape: int or tuple of ints, shape of array
    - dtype: data type, default None (float)
    - order: {'C', 'F'}, memory layout
    
    Returns:
    cupy.ndarray: Array of ones
    """

def empty(shape, dtype=float, order='C'):
    """
    Create uninitialized array.
    
    Parameters:
    - shape: int or tuple of ints, shape of array
    - dtype: data type, default float
    - order: {'C', 'F'}, memory layout
    
    Returns:
    cupy.ndarray: Uninitialized array
    """

def full(shape, fill_value, dtype=None, order='C'):
    """
    Create array filled with specified value.
    
    Parameters:
    - shape: int or tuple of ints, shape of array
    - fill_value: scalar, fill value
    - dtype: data type, if None, inferred from fill_value
    - order: {'C', 'F'}, memory layout
    
    Returns:
    cupy.ndarray: Array filled with fill_value
    """

Array-like Creation

Create arrays with same shape and properties as existing arrays.

def zeros_like(a, dtype=None, order='K', subok=True, shape=None):
    """
    Create zeros array with same shape as input.
    
    Parameters:
    - a: array-like, reference array for shape
    - dtype: data type, if None, use dtype of a
    - order: {'C', 'F', 'A', 'K'}, memory layout
    - subok: bool, whether to allow subclasses
    - shape: tuple, override shape if provided
    
    Returns:
    cupy.ndarray: Array of zeros with shape of a
    """

def ones_like(a, dtype=None, order='K', subok=True, shape=None):
    """Create ones array with same shape as input."""

def empty_like(a, dtype=None, order='K', subok=True, shape=None):
    """Create uninitialized array with same shape as input."""

def full_like(a, fill_value, dtype=None, order='K', subok=True, shape=None):
    """Create filled array with same shape as input."""

Range and Sequence Creation

Generate arrays with arithmetic and geometric sequences.

def arange(start, stop=None, step=1, dtype=None):
    """
    Create array with evenly spaced values within given interval.
    
    Parameters:
    - start: number, start of interval (or stop if stop is None)
    - stop: number, end of interval (exclusive)
    - step: number, spacing between values
    - dtype: data type, if None, inferred from inputs
    
    Returns:
    cupy.ndarray: Array of evenly spaced values
    """

def linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None, axis=0):
    """
    Create array with linearly spaced values.
    
    Parameters:
    - start: scalar, start value
    - stop: scalar, end value
    - num: int, number of samples (default 50)
    - endpoint: bool, whether to include stop value
    - retstep: bool, whether to return step size
    - dtype: data type, if None, inferred from inputs
    - axis: int, axis along which to create samples
    
    Returns:
    cupy.ndarray: Array of linearly spaced values
    tuple: (samples, step) if retstep=True
    """

def logspace(start, stop, num=50, endpoint=True, base=10.0, dtype=None, axis=0):
    """
    Create array with logarithmically spaced values.
    
    Parameters:
    - start: scalar, base**start is starting value
    - stop: scalar, base**stop is final value
    - num: int, number of samples
    - endpoint: bool, whether to include stop value
    - base: float, base of log space
    - dtype: data type, if None, inferred
    - axis: int, axis along which to create samples
    
    Returns:
    cupy.ndarray: Array of log-spaced values
    """

Matrix Creation

Create special matrix structures including identity matrices and diagonal arrays.

def eye(N, M=None, k=0, dtype=float, order='C'):
    """
    Create identity matrix.
    
    Parameters:
    - N: int, number of rows
    - M: int, number of columns (default N)
    - k: int, diagonal offset
    - dtype: data type
    - order: {'C', 'F'}, memory layout
    
    Returns:
    cupy.ndarray: Identity matrix
    """

def identity(n, dtype=None):
    """
    Create identity matrix of size n x n.
    
    Parameters:
    - n: int, size of matrix
    - dtype: data type, default None (float)
    
    Returns:
    cupy.ndarray: n x n identity matrix
    """

def diag(v, k=0):
    """
    Extract diagonal or create diagonal matrix.
    
    Parameters:
    - v: array-like, diagonal elements or matrix
    - k: int, diagonal offset
    
    Returns:
    cupy.ndarray: Diagonal elements or diagonal matrix
    """

def diagflat(v, k=0):
    """
    Create 2D array with flattened input as diagonal.
    
    Parameters:
    - v: array-like, input to flatten and use as diagonal
    - k: int, diagonal offset
    
    Returns:
    cupy.ndarray: 2D array with v as diagonal
    """

Shape Manipulation

Modify array shapes and dimensions without changing data.

def reshape(a, newshape, order='C'):
    """
    Return array with new shape.
    
    Parameters:
    - a: cupy.ndarray, input array
    - newshape: int or tuple of ints, new shape
    - order: {'C', 'F', 'A'}, memory layout
    
    Returns:
    cupy.ndarray: Array with new shape
    """

def ravel(a, order='C'):
    """
    Return flattened array.
    
    Parameters:
    - a: array-like, input array
    - order: {'C', 'F', 'A', 'K'}, flattening order
    
    Returns:
    cupy.ndarray: 1D array
    """

def flatten(a, order='C'):
    """Return copy of array collapsed into 1D."""

def squeeze(a, axis=None):
    """
    Remove single-dimensional entries from shape.
    
    Parameters:
    - a: cupy.ndarray, input array
    - axis: None or int or tuple of ints, axes to squeeze
    
    Returns:
    cupy.ndarray: Array with squeezed dimensions
    """

def expand_dims(a, axis):
    """
    Expand array dimensions.
    
    Parameters:
    - a: array-like, input array
    - axis: int or tuple of ints, position of new axes
    
    Returns:
    cupy.ndarray: Array with expanded dimensions
    """

Array Joining

Combine multiple arrays along various axes.

def concatenate(arrays, axis=0, out=None, dtype=None, casting="same_kind"):
    """
    Join arrays along existing axis.
    
    Parameters:
    - arrays: sequence of arrays, arrays to concatenate
    - axis: int, axis along which to concatenate
    - out: cupy.ndarray, output array
    - dtype: data type, output data type
    - casting: casting rule for data type conversion
    
    Returns:
    cupy.ndarray: Concatenated array
    """

def stack(arrays, axis=0, out=None):
    """
    Join arrays along new axis.
    
    Parameters:
    - arrays: sequence of arrays, arrays to stack
    - axis: int, axis along which to stack
    - out: cupy.ndarray, output array
    
    Returns:
    cupy.ndarray: Stacked array
    """

def vstack(arrays):
    """Stack arrays vertically (row-wise)."""

def hstack(arrays):
    """Stack arrays horizontally (column-wise)."""

def dstack(arrays):
    """Stack arrays depth-wise (along third axis)."""

Array Splitting

Split arrays into sub-arrays.

def split(ary, indices_or_sections, axis=0):
    """
    Split array into sub-arrays.
    
    Parameters:
    - ary: cupy.ndarray, array to split
    - indices_or_sections: int or 1D array, split points
    - axis: int, axis along which to split
    
    Returns:
    list: List of sub-arrays
    """

def array_split(ary, indices_or_sections, axis=0):
    """Split array into sub-arrays of equal or near-equal size."""

def hsplit(ary, indices_or_sections):
    """Split array horizontally."""

def vsplit(ary, indices_or_sections):
    """Split array vertically."""

def dsplit(ary, indices_or_sections):
    """Split array depth-wise."""

Data Type Conversion

Convert arrays between different data types and memory layouts.

def astype(a, dtype, order='K', casting='unsafe', subok=True, copy=True):
    """
    Cast array to specified type.
    
    Parameters:
    - a: cupy.ndarray, input array
    - dtype: data type, target data type
    - order: {'C', 'F', 'A', 'K'}, memory layout
    - casting: casting rule
    - subok: bool, allow subclasses
    - copy: bool, whether to copy if dtype matches
    
    Returns:
    cupy.ndarray: Array with new dtype
    """

def ascontiguousarray(a, dtype=None):
    """Return C-contiguous array."""

def asfortranarray(a, dtype=None):
    """Return Fortran-contiguous array."""

Usage Examples

Creating and Manipulating Arrays

import cupy as cp

# Create basic arrays
a = cp.array([1, 2, 3, 4, 5])
b = cp.zeros((3, 4))
c = cp.ones((2, 3), dtype=cp.float32)

# Create sequences
x = cp.arange(0, 10, 0.1)
y = cp.linspace(0, 1, 100)

# Shape manipulation
reshaped = cp.reshape(a, (5, 1))
flattened = cp.ravel(b)

# Array joining
combined = cp.concatenate([a, a], axis=0)
stacked = cp.stack([a, a], axis=1)

# Data type conversion
float_array = a.astype(cp.float64)

Install with Tessl CLI

npx tessl i tessl/pypi-cupy-rocm-4-3

docs

array-creation.md

cuda-integration.md

custom-kernels.md

data-types.md

extended-functionality.md

fft.md

index.md

io-functions.md

linear-algebra.md

logic-functions.md

mathematical-functions.md

polynomial.md

random.md

statistics.md

utilities.md

tile.json