tinygrad runtime.ops_cpu
Note
You likely want the upstream tinygrad, not tinygrab. Tinygrab contains AI generated docstrings for a tinygrad snapshot. Upstream: https://tinygrad.org
- class tinygrad.runtime.ops_cpu.NumpyAllocator[source]
Bases:
Allocator
Allocator class for numpy arrays.
- as_buffer(src: ndarray) memoryview [source]
Converts an np.ndarray to a memoryview object.
- Parameters:
src (np.ndarray) – The numpy array to be converted.
- Returns:
A view into the original numpy array’s data.
- Return type:
memoryview
- tinygrad.runtime.ops_cpu.einsum_mulacc(einsum, get_strides, expand)[source]
This function returns a higher-order function named mulacc. The returned function performs multiplication and accumulation using the numpy.einsum function. It takes two arrays as input along with their shapes and strides.
- tinygrad.runtime.ops_cpu.einsum
A function that performs numpy einsum operation.
- Type:
function
- tinygrad.runtime.ops_cpu.get_strides
Function to calculate the strides of an array.
- Type:
function
- tinygrad.runtime.ops_cpu.expand
Function to perform broadcasting/expansion of arrays.
- Type:
function
- tinygrad.runtime.ops_cpu.match_types(x, y)[source]
Cast two numpy arrays to a common datatype determined by output_type() function and return the casted arrays.
- Parameters:
x (numpy.ndarray) – The first numpy array for casting.
y (numpy.ndarray) – The second numpy array for casting.
- Returns:
A tuple of the casted x and y arrays.
- Return type:
Tuple[numpy.ndarray, numpy.ndarray]
- tinygrad.runtime.ops_cpu.output_type(x, y)[source]
Determine the datatype with higher priority between two numpy arrays.
- Parameters:
x (numpy.ndarray) – The first numpy array to compare.
y (numpy.ndarray) – The second numpy array to compare.
- Returns:
The datatype with higher priority between x and y.
- Return type:
numpy.dtype
- tinygrad.runtime.ops_cpu.shape_to_axis(old_shape: Tuple[int, ...], new_shape: Tuple[int, ...]) Tuple[int, ...] [source]
Compare two shapes and return a tuple containing the indices of axes that differ between the two shapes.
- Parameters:
old_shape (Tuple[int, ...]) – The original shape to be compared.
new_shape (Tuple[int, ...]) – The new shape to compare against the original shape.
- Returns:
A tuple of indices where the axes differ between the two shapes.
- Return type:
Tuple[int, …]
- Raises:
AssertionError – If the dimensions of old_shape and new_shape are not equal.