grelu.utils#

General utility functions

Functions#

torch_maxval(→ torch.Tensor)

torch_minval(→ torch.Tensor)

torch_log2fc(→ torch.Tensor)

np_log2fc(→ numpy.ndarray)

get_aggfunc(→ Callable)

Return a function to aggregate values.

get_compare_func(→ Callable)

Return a function to compare two values.

get_transform_func(→ Callable)

Return a function to transform the input.

make_list(→ list)

Convert various kinds of inputs into a list

Module Contents#

grelu.utils.torch_maxval(x: torch.Tensor, **kwargs) torch.Tensor[source]#
grelu.utils.torch_minval(x: torch.Tensor, **kwargs) torch.Tensor[source]#
grelu.utils.torch_log2fc(x: torch.Tensor, y: torch.Tensor) torch.Tensor[source]#
grelu.utils.np_log2fc(x: numpy.ndarray, y: numpy.ndarray) numpy.ndarray[source]#
grelu.utils.get_aggfunc(func: str | Callable | None, tensor: bool = False) Callable[source]#

Return a function to aggregate values.

Parameters:
  • func – A function or the name of a function. Supported names are “max”, “min”, “mean”, and “sum”. If a function is supplied, it will be returned unchanged.

  • tensor – If True, it is assumed that the inputs will be torch tensors. If False, it is assumed that the inputs will be numpy arrays.

Returns:

The desired function.

Raises:

NotImplementedError – If the input is neither a function nor a supported function name.

grelu.utils.get_compare_func(func: str | Callable | None, tensor: bool = False) Callable[source]#

Return a function to compare two values.

Parameters:
  • func – A function or the name of a function. Supported names are “subtract”, “divide”, and “log2FC”. If a function is supplied, it will be returned unchanged. func cannot be None.

  • tensor – If True, it is assumed that the inputs will be torch tensors. If False, it is assumed that the inputs will be numpy arrays.

Returns:

The desired function.

Raises:

NotImplementedError – If the input is neither a function nor a supported function name.

grelu.utils.get_transform_func(func: str | Callable | None, tensor: bool = False) Callable[source]#

Return a function to transform the input.

Parameters:
  • func – A function or the name of a function. Supported names are “log” and “log1p”. If None, the identity function will be returned. If a function is supplied, it will be returned unchanged.

  • tensor – If True, it is assumed that the inputs will be torch tensors. If False, it is assumed that the inputs will be numpy arrays.

Returns:

The desired function.

Raises:

NotImplementedError – If the input is neither a function nor a supported function name.

grelu.utils.make_list(x: pandas.Series | numpy.ndarray | torch.Tensor | Sequence | int | float | str | None) list[source]#

Convert various kinds of inputs into a list

Parameters:

x – An input value or sequence of values.

Returns:

The input values in list format.