pespace.utils.utils

Utility functions and data structures.

Functions

complex_dict_to_field(array_dict, ...)

Convert a dictionary of complex NumPy arrays to a Taichi field.

field_to_complex_dict(field_container)

Convert a Taichi field to a dictionary of complex NumPy arrays.

lagrange_interpolate_kernel()

Lagrange interpolation kernel (not implemented).

linear_interpolate_kernel(left, right, frac)

Perform linear interpolation between two values.

next_power_of_2(n)

Compute the next power of 2 greater than or equal to n.

recursively_load_dict_contents_from_group(...)

Recursively load an HDF5 group into a dictionary.

recursively_save_dict_contents_to_group(...)

Recursively save a dictionary to an HDF5 group.

sinc_interpolate_kernel()

Sinc interpolation kernel (not implemented).

ti_sinc(x)

Compute the sinc function: sin(x)/x.

pespace.utils.utils.next_power_of_2(n)[source]

Compute the next power of 2 greater than or equal to n.

Parameters:

n (ti.u32) – Input unsigned 32-bit integer.

Returns:

The smallest power of 2 that is greater than or equal to n.

Return type:

ti.u32

pespace.utils.utils.ti_sinc(x)[source]

Compute the sinc function: sin(x)/x.

Parameters:

x (float) – Input value.

Returns:

The value of sinc(x). Returns 1.0 when x = 0.0.

Return type:

float

pespace.utils.utils.linear_interpolate_kernel(left, right, frac)[source]

Perform linear interpolation between two values.

Parameters:
  • left (float) – Left boundary value.

  • right (float) – Right boundary value.

  • frac (float) – Fractional position between left and right, in the range [0, 1].

Returns:

Interpolated value.

Return type:

float

pespace.utils.utils.lagrange_interpolate_kernel()[source]

Lagrange interpolation kernel (not implemented).

Notes

This function is a placeholder for future implementation.

pespace.utils.utils.sinc_interpolate_kernel()[source]

Sinc interpolation kernel (not implemented).

Notes

This function is a placeholder for future implementation.

pespace.utils.utils.field_to_complex_dict(field_container)[source]

Convert a Taichi field to a dictionary of complex NumPy arrays.

Parameters:

field_container (ti.Field) – Taichi field container with shape (N, 2), where the last dimension represents [real, imaginary] components.

Returns:

Dictionary mapping field names to complex-valued NumPy arrays of shape (N,).

Return type:

dict[str, NDArray]

pespace.utils.utils.complex_dict_to_field(array_dict, field_container)[source]

Convert a dictionary of complex NumPy arrays to a Taichi field.

Parameters:
  • array_dict (dict[str, NDArray]) – Dictionary mapping field names to 1D complex-valued NumPy arrays.

  • field_container (ti.Field) – Target Taichi field container with shape (N, 2) to store [real, imaginary] components.

Return type:

None

pespace.utils.utils.recursively_save_dict_contents_to_group(h5file, path, dic)[source]

Recursively save a dictionary to an HDF5 group.

Parameters:
  • h5file (h5py.File) – HDF5 file object.

  • path (str) – Path inside the HDF5 file where the dictionary will be saved.

  • dic (dict) – Dictionary containing the data to save. Supports nested dictionaries, lists, NumPy arrays, and None values.

Raises:

ValueError – If the dictionary contains values of unsupported types.

Notes

This function is adapted from bilby.core.utils.io.recursively_save_dict_contents_to_group. Supported value types: dict, list, np.ndarray, None.

pespace.utils.utils.recursively_load_dict_contents_from_group(h5file, path)[source]

Recursively load an HDF5 group into a dictionary.

Parameters:
  • h5file (h5py.File) – HDF5 file object.

  • path (str) – Path within the HDF5 file to load from.

Returns:

Dictionary containing the contents of the HDF5 group, with nested structure preserved.

Return type:

dict

Notes

This function is adapted from bilby.core.utils.io.recursively_load_dict_contents_from_group.