sarcomp.empty#

sarcomp.empty(shape=(1,), dtype='float32', p2=False, axis=1)#

Create an empty array with the specified shape and data type, optionally padding to the next power of two.

This function generates an empty (uninitialized) array with the given shape and data type. If the p2 flag is set to True, the function adjusts the size of the specified axis (or axes) to the next power of two, useful in certain computations that benefit from array sizes being powers of two.

Parameters:
  • shape (int or tuple of int, optional) – The shape of the array to create. Default is (1,), creating a single-element array. If an integer is provided, it specifies the size of the array along the y-axis, with the x-axis size assumed to be 1.

  • dtype (str or np.dtype, optional) – The desired data type for the array, specified as a string (e.g., ‘float32’) or directly using an np.dtype object. Default is ‘float32’.

  • p2 (bool, optional) – Whether to pad the array’s size along the specified axis (or axes) to the next power of two. Default is False.

  • axis (int or tuple of int, optional) – The axis (or axes) along which to apply padding if p2 is True. Default is 1, indicating the y-axis. If a tuple, applies padding to all specified axes.

Returns:

An empty array of the specified shape and data type. If p2 is True, the shape may be adjusted to have sizes that are powers of two along the specified axis (or axes).

Return type:

Array

Examples

>>> empty()
Array of shape (1,), dtype='float32'
>>> empty(shape=(5, 10), dtype='complex64', p2=True, axis=1)
Array of shape (5, 16), dtype='complex64'  # Assuming 10 padded to 16
>>> empty(shape=5, p2=True)
Array of shape (1, 8), dtype='float32'  # Assuming 5 padded to 8 along y-axis

Notes

The uninitialized array elements can contain any arbitrary value; thus, it’s essential to assign values to the array before using it in computations to avoid undefined behavior.

If p2 is True but the specified axis does not exist in the shape (e.g., axis=2 for a shape of (5,)), an appropriate error should be raised to indicate the mismatch.