format_data

Format data to interface with numpy or torch, on a specified device.

Given, adata and a key that points to a specific matrix stored in adata, return the data, formatted either as np.ndarray or torch.Tensor. If formatted as torch.Tensor, device may be specified based on available devices.

Uses the class: adata_query._core.DataFormatter.

data = format_data(
    data: Union[np.ndarray, torch.Tensor],
    torch: bool = False,
    device: torch.device = autodevice.AutoDevice(),
    *args,
    **kwargs,
)
Parameters

data (Union[np.ndarray, torch.Tensor])

  • Input data that should be formatted. Typically an np.ndarray, torch.Tensor, or ArrayView.

torch (bool) = False

  • Boolean indicator of whether data should be formatted as torch.Tensor. If False (default), data is formatted as np.ndarray.

device (torch.device) = autodevice.AutoDevice()

  • Should torch=True, the device ("cpu", "cuda:N", "mps:N") may be set. The default value, autodevice.AutoDevice() will indicate the use of GPU, if available.

Returns

data(Union[torch.Tensor, np.ndarray])

  • Formatted data as np.ndarray or torch.Tensor.

  • If torch=True, the torch.Tensor is allocated to the device indicated by the device argument.

Source code: GitHub.com/mvinyard/AnnDataQuery/adata_query/_core/_formatter.py

Last updated