CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-cupy-cuda110

NumPy & SciPy for GPU - CUDA 11.0 compatible package providing GPU-accelerated computing with Python through a NumPy/SciPy-compatible array library

Pending
Overview
Eval results
Files

array-operations.mddocs/

Array Operations

Comprehensive array creation and manipulation operations that provide the foundation for GPU computing with CuPy. These functions mirror NumPy's API while operating efficiently on GPU memory.

Capabilities

Array Creation Functions

Create arrays directly on GPU memory with various initialization patterns and data sources.

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

def asarray(a, dtype=None, order=None):
    """Convert input to array, avoiding copy if possible."""

def asanyarray(a, dtype=None, order=None):
    """Convert input to array, preserving subclasses."""

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

def copy(a, order='K', subok=False):
    """Return copy of array."""

def asnumpy(a, stream=None, order='C', out=None):
    """Transfer array from GPU to CPU memory."""

def frombuffer(buffer, dtype=float, count=-1, offset=0):
    """Create array from buffer object."""

def fromfile(file, dtype=float, count=-1, sep=''):
    """Create array from data in text or binary file."""

def fromfunction(function, shape, dtype=float, **kwargs):
    """Create array by executing function over grid."""

def fromiter(iterable, dtype, count=-1):
    """Create array from iterable object."""

def fromstring(string, dtype=float, count=-1, sep=''):
    """Create array from string data."""

def loadtxt(fname, dtype=float, comments='#', delimiter=None, **kwargs):
    """Load data from text file."""

def genfromtxt(fname, dtype=float, comments='#', delimiter=None, **kwargs):
    """Load data from text file with missing value handling."""

Initialization Functions

def zeros(shape, dtype=float, order='C'):
    """Return array filled with zeros."""

def zeros_like(a, dtype=None, order='K', subok=True, shape=None):
    """Return zeros array with same shape and type as input."""

def ones(shape, dtype=float, order='C'):
    """Return array filled with ones."""

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

def empty(shape, dtype=float, order='C'):
    """Return uninitialized array."""

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

def full(shape, fill_value, dtype=None, order='C'):
    """Return array filled with fill_value."""

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

def eye(N, M=None, k=0, dtype=float, order='C'):
    """Return 2-D array with ones on diagonal."""

def identity(n, dtype=float):
    """Return identity array."""

Range Creation

Generate sequences and coordinate arrays for numerical computation.

def arange(start, stop=None, step=1, dtype=None):
    """
    Return evenly spaced values within interval.
    
    Parameters:
    - start: number, start of interval
    - stop: number, end of interval  
    - step: number, spacing between values
    - dtype: data type
    
    Returns:
    cupy.ndarray: Array of evenly spaced values
    """

def linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None):
    """Return evenly spaced numbers over interval."""

def logspace(start, stop, num=50, endpoint=True, base=10.0, dtype=None):
    """Return evenly spaced numbers on log scale."""

def meshgrid(*xi, copy=True, sparse=False, indexing='xy'):
    """Return coordinate matrices from coordinate vectors."""

def mgrid():
    """nd_grid instance for dense multi-dimensional grids."""

def ogrid():  
    """nd_grid instance for open multi-dimensional grids."""

Matrix Creation

Create specialized matrix structures for linear algebra operations.

def diag(v, k=0):
    """Extract diagonal or construct diagonal array."""

def diagflat(v, k=0):
    """Create 2-D array with flattened input as diagonal."""

def tri(N, M=None, k=0, dtype=float):
    """Array with ones at and below given diagonal."""

def tril(m, k=0):
    """Lower triangle of array."""

def triu(m, k=0):
    """Upper triangle of array."""

def vander(x, N=None, increasing=False):
    """Generate Vandermonde matrix."""

Shape Manipulation

Modify array shapes and dimensions while preserving data.

def reshape(a, newshape, order='C'):
    """Return array with new shape."""

def ravel(a, order='C'):
    """Return contiguous flattened array."""

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

def transpose(a, axes=None):
    """Reverse or permute axes of array."""

def swapaxes(a, axis1, axis2):
    """Interchange two axes of array."""

def moveaxis(a, source, destination):
    """Move axes of array to new positions."""

def rollaxis(a, axis, start=0):
    """Roll specified axis backwards."""

Dimension Manipulation

Add, remove, or modify array dimensions.

def atleast_1d(*arys):
    """Convert inputs to arrays with at least 1 dimension."""

def atleast_2d(*arys):
    """Convert inputs to arrays with at least 2 dimensions."""

def atleast_3d(*arys):
    """Convert inputs to arrays with at least 3 dimensions."""

def expand_dims(a, axis):
    """Expand shape of array by inserting new axes."""

def squeeze(a, axis=None):
    """Remove single-dimensional entries from shape."""

def broadcast_to(array, shape, subok=False):
    """Broadcast array to given shape."""

def broadcast_arrays(*args, subok=False):
    """Broadcast arrays against each other."""

Array Joining

Combine multiple arrays into single arrays along various axes.

def concatenate(arrays, axis=0, out=None, dtype=None, casting='same_kind'):
    """Join arrays along existing axis."""

def stack(arrays, axis=0, out=None):
    """Join arrays along new axis."""

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

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

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

def column_stack(tup):
    """Stack 1-D arrays as columns into 2-D array."""

def row_stack(tup):
    """Stack arrays vertically (same as vstack)."""

Array Splitting

Split arrays into multiple sub-arrays along specified axes.

def split(ary, indices_or_sections, axis=0):
    """Split array into multiple sub-arrays."""

def array_split(ary, indices_or_sections, axis=0):
    """Split array into multiple sub-arrays (allows unequal division)."""

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

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

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

Array Tiling and Repetition

Duplicate array contents in various patterns.

def tile(A, reps):
    """Construct array by repeating A given number of times."""

def repeat(a, repeats, axis=None):
    """Repeat elements of array."""

Array Modification

Modify existing arrays by adding, removing, or changing elements.

def append(arr, values, axis=None):
    """Append values to end of array."""

def resize(a, new_shape):
    """Return new array with specified shape."""

def unique(ar, return_index=False, return_inverse=False, return_counts=False, axis=None):
    """Find unique elements of array."""

def trim_zeros(filt, trim='fb'):
    """Trim leading and/or trailing zeros from 1-D array."""

Array Rearrangement

Rearrange array elements in various patterns.

def flip(m, axis=None):
    """Reverse order of elements along given axis."""

def fliplr(m):
    """Flip array left to right."""

def flipud(m):
    """Flip array up to down."""

def roll(a, shift, axis=None):
    """Roll array elements along given axis."""

def rot90(m, k=1, axes=(0, 1)):
    """Rotate array by 90 degrees in plane specified by axes."""

Usage Examples

Basic Array Creation

import cupy as cp

# Create arrays from data
data = [1, 2, 3, 4, 5]
gpu_array = cp.array(data)

# Create initialized arrays
zeros_array = cp.zeros((3, 4))
ones_array = cp.ones((2, 3), dtype=cp.float32)
random_data = cp.random.random((1000, 1000))

# Create ranges
sequence = cp.arange(0, 10, 0.5)
linear_space = cp.linspace(0, 1, 100)

Shape Manipulation

# Reshape operations
original = cp.arange(12)
reshaped = original.reshape(3, 4)
flattened = reshaped.ravel()

# Transpose and axis operations  
matrix = cp.random.random((3, 4, 5))
transposed = cp.transpose(matrix, (2, 0, 1))
swapped = cp.swapaxes(matrix, 0, 2)

Array Joining and Splitting

# Join arrays
a = cp.array([1, 2, 3])
b = cp.array([4, 5, 6])
joined = cp.concatenate([a, b])
stacked = cp.stack([a, b])

# Split arrays
data = cp.arange(10)
parts = cp.split(data, 5)  # Split into 5 equal parts

Install with Tessl CLI

npx tessl i tessl/pypi-cupy-cuda110

docs

array-operations.md

cuda-interface.md

custom-kernels.md

index.md

linear-algebra.md

mathematical-functions.md

random-generation.md

scipy-extensions.md

statistics.md

tile.json