Array#
Core Array class with improved organization.
- class nabla.core.array.Array(shape, dtype=<MagicMock name='mock.float32' id='140511747382336'>, device=max.driver.CPU, materialize=False, name='', batch_dims=())[source]#
Bases:
object
Core tensor-like array class with automatic differentiation support.
- __init__(shape, dtype=<MagicMock name='mock.float32' id='140511747382336'>, device=max.driver.CPU, materialize=False, name='', batch_dims=())[source]#
- dtype: <MagicMock id='140511747387904'>#
- device: max.driver.Device#
- tensor_value: <MagicMock id='140511747378352'> | <MagicMock id='140511747356960'> | <MagicMock id='140511747358256'> | None#
- maxpr: Array], None] | None#
- property impl: max.driver.Tensor | None#
Get the max.Tensor representation of this Array. If the underlying _impl field is a Numpy array, convert it to a Tensor.
- astype(dtype)[source]#
Convert array to a different data type.
- Parameters:
dtype (<MagicMock id='140511747387904'>) – Target data type
- Returns:
New Array with the specified data type
- Return type:
- sum(axes=None, keep_dims=False)[source]#
Sum array elements over given axes.
- Parameters:
axes – Axis or axes along which to sum. Can be int, list of ints, or None (sum all)
keep_dims – If True, reduced axes are left as dimensions with size 1
- Returns:
Array with the sum along the specified axes
- Return type:
Examples:
arr.sum() # Sum all elements arr.sum(axis=0) # Sum along first axis arr.sum(axis=[0,1]) # Sum along first two axes
- reshape(shape)[source]#
Change the shape of an array without changing its data.
- Parameters:
- Returns:
Array with the new shape
- Return type:
Examples:
arr.reshape((2, 3)) # Reshape to 2x3 arr.reshape((-1,)) # Flatten to 1D (note: -1 not yet supported)
- permute(axes)[source]#
Permute the dimensions of the array.
- Parameters:
axes (tuple[int, ...]) – List of integers specifying the new order of dimensions
- Returns:
Array with dimensions permuted according to the specified axes
- Return type:
Examples:
arr.permute([1, 0]) # If arr.shape is (2, 3), this will return an array with shape (3, 2)
- transpose(axes)[source]#
Permute the dimensions of the array.
- Parameters:
axes (tuple[int, ...]) – List of integers specifying the new order of dimensions
- Returns:
Array with dimensions permuted according to the specified axes
- Return type:
Examples:
arr.permute([1, 0]) # If arr.shape is (2, 3), this will return an array with shape (3, 2)
- set(key, value)[source]#
Set values at specified indices/slices, returning a new array.
This is a functional operation that returns a new Array with the specified values updated, leaving the original Array unchanged.
- Parameters:
key – Index specification (int, slice, tuple of indices/slices, ellipsis)
value – Value(s) to set at the specified location
- Returns:
New Array with updated values
- Return type:
Examples
new_arr = arr.set(1, 99.0) # Set single element new_arr = arr.set((1, 2), 99.0) # Set element at (1,2) new_arr = arr.set(slice(1, 3), 99.0) # Set slice new_arr = arr.set(…, 99.0) # Set with ellipsis