Array#

enum mlx_array_dtype_#

Array element type.

Values:

enumerator MLX_BOOL#
enumerator MLX_UINT8#
enumerator MLX_UINT16#
enumerator MLX_UINT32#
enumerator MLX_UINT64#
enumerator MLX_INT8#
enumerator MLX_INT16#
enumerator MLX_INT32#
enumerator MLX_INT64#
enumerator MLX_FLOAT16#
enumerator MLX_FLOAT32#
enumerator MLX_BFLOAT16#
enumerator MLX_COMPLEX64#
typedef struct mlx_array_ *mlx_array#

An N-dimensional array object.

typedef enum mlx_array_dtype_ mlx_array_dtype#

Array element type.

mlx_array mlx_array_from_bool(bool val)#

New array from a bool scalar.

mlx_array mlx_array_from_int(int val)#

New array from a int scalar.

mlx_array mlx_array_from_float(float val)#

New array from a float scalar.

mlx_array mlx_array_from_complex(float real_val, float imag_val)#

New array from a complex scalar.

mlx_array mlx_array_from_data(const void *data, const int *shape, int dim, mlx_array_dtype dtype)#

New array from existing buffer.

Parameters:
  • data – A buffer which will be copied.

  • shape – Shape of the array.

  • dim – Number of dimensions (size of shape).

  • dtype – Type of array elements.

size_t mlx_array_itemsize(mlx_array arr)#

The size of the array’s datatype in bytes.

size_t mlx_array_size(mlx_array arr)#

Number of elements in the array.

size_t *mlx_array_strides(mlx_array arr)#

The strides of the array.

Returns: a pointer to the sizes of each dimension.

size_t mlx_array_nbytes(mlx_array arr)#

The number of bytes in the array.

size_t mlx_array_ndim(mlx_array arr)#

The array’s dimension.

int *mlx_array_shape(mlx_array arr)#

The shape of the array.

Returns: a pointer to the sizes of each dimension.

int mlx_array_dim(mlx_array arr, int dim)#

The shape of the array in a particular dimension.

mlx_array_dtype mlx_array_get_dtype(mlx_array arr)#

The array element type.

void mlx_array_eval(mlx_array arr)#

Evaluate the array.

bool mlx_array_item_bool(mlx_array arr)#

Access the value of a scalar array.

uint8_t mlx_array_item_uint8(mlx_array arr)#

Access the value of a scalar array.

uint16_t mlx_array_item_uint16(mlx_array arr)#

Access the value of a scalar array.

uint32_t mlx_array_item_uint32(mlx_array arr)#

Access the value of a scalar array.

uint64_t mlx_array_item_uint64(mlx_array arr)#

Access the value of a scalar array.

int8_t mlx_array_item_int8(mlx_array arr)#

Access the value of a scalar array.

int16_t mlx_array_item_int16(mlx_array arr)#

Access the value of a scalar array.

int32_t mlx_array_item_int32(mlx_array arr)#

Access the value of a scalar array.

int64_t mlx_array_item_int64(mlx_array arr)#

Access the value of a scalar array.

float mlx_array_item_float32(mlx_array arr)#

Access the value of a scalar array.

float _Complex mlx_array_item_complex64(mlx_array arr)#

Access the value of a scalar array.

const bool *mlx_array_data_bool(mlx_array arr)#

Returns a pointer to the array data, cast to bool*.

Array must be evaluated, otherwise returns NULL.

const uint8_t *mlx_array_data_uint8(mlx_array arr)#

Returns a pointer to the array data, cast to uint8_t*.

Array must be evaluated, otherwise returns NULL.

const uint16_t *mlx_array_data_uint16(mlx_array arr)#

Returns a pointer to the array data, cast to uint16_t*.

Array must be evaluated, otherwise returns NULL.

const uint32_t *mlx_array_data_uint32(mlx_array arr)#

Returns a pointer to the array data, cast to uint32_t*.

Array must be evaluated, otherwise returns NULL.

const uint64_t *mlx_array_data_uint64(mlx_array arr)#

Returns a pointer to the array data, cast to uint64_t*.

Array must be evaluated, otherwise returns NULL.

const int8_t *mlx_array_data_int8(mlx_array arr)#

Returns a pointer to the array data, cast to int8_t*.

Array must be evaluated, otherwise returns NULL.

const int16_t *mlx_array_data_int16(mlx_array arr)#

Returns a pointer to the array data, cast to int16_t*.

Array must be evaluated, otherwise returns NULL.

const int32_t *mlx_array_data_int32(mlx_array arr)#

Returns a pointer to the array data, cast to int32_t*.

Array must be evaluated, otherwise returns NULL.

const int64_t *mlx_array_data_int64(mlx_array arr)#

Returns a pointer to the array data, cast to int64_t*.

Array must be evaluated, otherwise returns NULL.

const float *mlx_array_data_float32(mlx_array arr)#

Returns a pointer to the array data, cast to float32*.

Array must be evaluated, otherwise returns NULL.

const float _Complex *mlx_array_data_complex64(mlx_array arr)#

Returns a pointer to the array data, cast to _Complex*.

Array must be evaluated, otherwise returns NULL.