flory.common.utilities

Utilities shared by package flory.

Functions

convert_and_broadcast

Converts input and broadcasts it to an array with specified shape.

filter_kwargs

Filter the keyword arguments (dict) not accepted by a function.

make_square_blocks

Expands a square np.ndarray into blocks.

convert_and_broadcast(arr, shape)[source]

Converts input and broadcasts it to an array with specified shape.

Parameters:
  • arr (ndarray) – The input array.

  • shape (ndarray) – The target shape to broadcast to.

Returns:

The broadcasted array.

Return type:

ndarray

filter_kwargs(kwargs_full, func)[source]

Filter the keyword arguments (dict) not accepted by a function.

Parameters:
  • kwargs_full (dict[str, Any]) – The dictionary for all keyword arguments, including the redundant ones.

  • func (Callable) – The function to check against.

Returns:

The filtered dictionary

Return type:

dict[str, Any]

make_square_blocks(arr, block_sizes)[source]

Expands a square np.ndarray into blocks.

Parameters:
  • arr (ndarray) – The input array. Must be square (i.e., all dimensions are equal).

  • block_sizes (ndarray) – The sizes for the blocks. Must have the same length as arr.

Returns:
  • The input array expanded into blocks. Each element of arr is

  • repeated according to :paramref:`block_sizes` to create blocks.

Return type:

ndarray