Arrays¶
-
enum hv_dtype¶
Supported pixel value datatypes.
Represents each of the supported underlying types of a dynamic array.
- Remark: Has the same ABI as
Values:
-
enumerator HV_DTYPE_U8¶
Values of uint8_t.
-
enumerator HV_DTYPE_S8¶
Values of int8_t.
-
enumerator HV_DTYPE_U16¶
Values of uint16_t.
-
enumerator HV_DTYPE_S16¶
Values of int16_t.
-
enumerator HV_DTYPE_U32¶
Values of uint32_t.
-
enumerator HV_DTYPE_S32¶
Values of int32_t.
-
enumerator HV_DTYPE_U64¶
Values of uint64_t.
-
enumerator HV_DTYPE_S64¶
Values of int64_t.
-
enumerator HV_DTYPE_F16¶
Values of float16_t.
-
enumerator HV_DTYPE_F32¶
Values of float32_t.
-
enumerator HV_DTYPE_F64¶
Values of float64_t.
-
typedef struct hv_array hv_array_t¶
Multi-dimensional array.
See the exported API.
-
slice_ref_float_t hv_array_as_f32(hv_array_t const *array)¶
Returns the contents of the dynamic array as a slice of
f32if the type matches.- Parameters:
array – Reference to a dynamic array.
- Returns:
Optional slice of
f32values.
-
slice_ref_double_t hv_array_as_f64(hv_array_t const *array)¶
Returns the contents of the dynamic array as a slice of
f64if the type matches.- Parameters:
array – Reference to a dynamic array.
- Returns:
Optional slice of
f64values.
-
slice_ref_int16_t hv_array_as_i16(hv_array_t const *array)¶
Returns the contents of the dynamic array as a slice of
i16if the type matches.- Parameters:
array – Reference to a dynamic array.
- Returns:
Optional slice of
i16values.
-
slice_ref_int32_t hv_array_as_i32(hv_array_t const *array)¶
Returns the contents of the dynamic array as a slice of
i32if the type matches.- Parameters:
array – Reference to a dynamic array.
- Returns:
Optional slice of
i32values.
-
slice_ref_int8_t hv_array_as_i8(hv_array_t const *array)¶
Returns the contents of the dynamic array as a slice of
i8if the type matches.- Parameters:
array – Reference to a dynamic array.
- Returns:
Optional slice of
i8values.
-
int32_t hv_array_as_raw_parts(hv_array_t const *array, size_t *size, size_t *count, uint8_t const **bytes)¶
Returns the raw parts of the dynamic array: element size, element count, and pointer to the data.
- Parameters:
array – Reference to a dynamic array.
size – Output parameter for the element size in bytes.
count – Output parameter for the number of elements.
bytes – Output parameter for the pointer to the data.
- Returns:
0 on success, negative value on error.
-
int32_t hv_array_as_raw_slice(hv_array_t const *array, size_t *size, slice_ref_uint8_t *oslice)¶
Returns the raw slice of the dynamic array as a slice of bytes.
- Parameters:
array – Reference to a dynamic array.
size – Output parameter for the element size in bytes.
oslice – Output parameter for the optional byte slice.
- Returns:
0 on success, negative value on error.
-
slice_ref_uint16_t hv_array_as_u16(hv_array_t const *array)¶
Returns the contents of the dynamic array as a slice of
u16if the type matches.- Parameters:
array – Reference to a dynamic array.
- Returns:
Optional slice of
u16values.
-
slice_ref_uint32_t hv_array_as_u32(hv_array_t const *array)¶
Returns the contents of the dynamic array as a slice of
u32if the type matches.- Parameters:
array – Reference to a dynamic array.
- Returns:
Optional slice of
u32values.
-
slice_ref_uint64_t hv_array_as_u64(hv_array_t const *array)¶
Returns the contents of the dynamic array as a slice of
u64if the type matches.- Parameters:
array – Reference to a dynamic array.
- Returns:
Optional slice of
u64values.
-
slice_ref_uint8_t hv_array_as_u8(hv_array_t const *array)¶
Returns the contents of the dynamic array as a slice of
u8if the type matches.- Parameters:
array – Reference to a dynamic array.
- Returns:
Optional slice of
u8values.
-
hv_array_t *hv_array_clamp(hv_array_t **array, float min, float max)¶
Clamps the values in the dynamic array to the given minimum and maximum values.
WARNING: this function will consume
array- Parameters:
array – Dynamic array to clamp.
min – Minimum value.
max – Maximum value.
- Returns:
Clamped dynamic array.
-
hv_dtype_t hv_array_dtype(hv_array_t const *array)¶
Returns the element type (
DType) of the given dynamic array.- Parameters:
array – Reference to a dynamic array.
- Returns:
The element type of the array.
-
int32_t hv_array_flatten(hv_array_t const *array, hv_array_t **dynarray)¶
Flattens the dynamic array into a one-dimensional array.
- Parameters:
array – Reference to a dynamic array.
dynarray – Output parameter for the flattened array.
- Returns:
0 on success, negative value on error.
-
void hv_array_free(hv_array_t **array)¶
Frees the memory associated with a boxed dynamic array.
- Parameters:
array – Output parameter for the boxed dynamic array to free.
-
int32_t hv_array_from_f32(slice_ref_size_t shape, slice_ref_float_t data, hv_array_t **dynarray)¶
Creates a dynamic array from a shape and a slice of
f32values.- Parameters:
shape – Slice describing the shape of the array.
data – Slice of
f32values.dynarray – Output parameter for the created dynamic array.
- Returns:
0 on success, negative value on error.
-
int32_t hv_array_from_f64(slice_ref_size_t shape, slice_ref_double_t data, hv_array_t **dynarray)¶
Creates a dynamic array from a shape and a slice of
f64values.- Parameters:
shape – Slice describing the shape of the array.
data – Slice of
f64values.dynarray – Output parameter for the created dynamic array.
- Returns:
0 on success, negative value on error.
-
int32_t hv_array_from_i16(slice_ref_size_t shape, slice_ref_int16_t data, hv_array_t **dynarray)¶
Creates a dynamic array from a shape and a slice of
i16values.- Parameters:
shape – Slice describing the shape of the array.
data – Slice of
i16values.dynarray – Output parameter for the created dynamic array.
- Returns:
0 on success, negative value on error.
-
int32_t hv_array_from_i32(slice_ref_size_t shape, slice_ref_int32_t data, hv_array_t **dynarray)¶
Creates a dynamic array from a shape and a slice of
i32values.- Parameters:
shape – Slice describing the shape of the array.
data – Slice of
i32values.dynarray – Output parameter for the created dynamic array.
- Returns:
0 on success, negative value on error.
-
int32_t hv_array_from_i8(slice_ref_size_t shape, slice_ref_int8_t data, hv_array_t **dynarray)¶
Creates a dynamic array from a shape and a slice of
i8values.- Parameters:
shape – Slice describing the shape of the array.
data – Slice of
i8values.dynarray – Output parameter for the created dynamic array.
- Returns:
0 on success, negative value on error.
-
int32_t hv_array_from_raw(slice_ref_size_t shape, hv_dtype_t dtype, slice_ref_uint8_t data, hv_array_t **dynarray)¶
Creates a dynamic array from a raw byte slice.
- Parameters:
shape – Slice describing the shape of the array.
dtype – Data type of the array.
data – Raw byte slice containing the data.
dynarray – Output parameter for the created dynamic array.
- Returns:
0 on success, negative value on error.
-
int32_t hv_array_from_raw_parts(size_t const *shape_data, size_t shape_len, uint8_t const *data, size_t data_len, hv_dtype_t dtype, hv_array_t **dynarray)¶
Creates a dynamic array from raw parts: shape pointer, data pointer, and their lengths.
- Parameters:
shape_data – Pointer to the shape data.
shape_len – Length of the shape data.
data – Pointer to the raw data.
data_len – Length of the raw data.
dtype – Data type of the array.
dynarray – Output parameter for the created dynamic array.
- Returns:
0 on success, negative value on error.
-
int32_t hv_array_from_reader_cb(slice_ref_size_t shape, hv_dtype_t dtype, hv_buf_reader_cb_t cb, hv_array_t **dynarray)¶
Creates a dynamic array from a reader callback function.
- Parameters:
shape – Slice describing the shape of the array.
dtype – Data type of the array.
cb – Reader callback closure.
dynarray – Output parameter for the created dynamic array.
- Returns:
0 on success, negative value on error.
-
int32_t hv_array_from_u16(slice_ref_size_t shape, slice_ref_uint16_t data, hv_array_t **dynarray)¶
Creates a dynamic array from a shape and a slice of
u16values.- Parameters:
shape – Slice describing the shape of the array.
data – Slice of
u16values.dynarray – Output parameter for the created dynamic array.
- Returns:
0 on success, negative value on error.
-
int32_t hv_array_from_u32(slice_ref_size_t shape, slice_ref_uint32_t data, hv_array_t **dynarray)¶
Creates a dynamic array from a shape and a slice of
u32values.- Parameters:
shape – Slice describing the shape of the array.
data – Slice of
u32values.dynarray – Output parameter for the created dynamic array.
- Returns:
0 on success, negative value on error.
-
int32_t hv_array_from_u64(slice_ref_size_t shape, slice_ref_uint64_t data, hv_array_t **dynarray)¶
Creates a dynamic array from a shape and a slice of
u64values.- Parameters:
shape – Slice describing the shape of the array.
data – Slice of
u64values.dynarray – Output parameter for the created dynamic array.
- Returns:
0 on success, negative value on error.
-
int32_t hv_array_from_u8(slice_ref_size_t shape, slice_ref_uint8_t data, hv_array_t **dynarray)¶
Creates a dynamic array from a shape and a slice of
u8values.- Parameters:
shape – Slice describing the shape of the array.
data – Slice of
u8values.dynarray – Output parameter for the created dynamic array.
- Returns:
0 on success, negative value on error.
-
size_t hv_array_len(hv_array_t const *array)¶
Returns the total number of elements in the dynamic array.
- Parameters:
array – Reference to a dynamic array.
- Returns:
Number of elements in the array.
-
size_t hv_array_ndim(hv_array_t const *array)¶
Returns the number of dimensions of the dynamic array.
- Parameters:
array – Reference to a dynamic array.
- Returns:
Number of dimensions.
-
slice_ref_size_t hv_array_shape(hv_array_t const *array)¶
Returns the shape of the dynamic array as a slice of
usize.- Parameters:
array – Reference to a dynamic array.
- Returns:
Slice describing the shape of the array.