gwexpy.interop.torch_

Interoperability with PyTorch tensors.

Functions

from_torch(cls, tensor, t0, dt[, unit])

Create a TimeSeries from a PyTorch tensor.

to_torch(series[, device, dtype, ...])

Convert a series to a PyTorch tensor.

gwexpy.interop.torch_.to_torch(series: TimeSeries | Any, device: str | torch.device | None = None, dtype: torch.dtype | None = None, requires_grad: bool = False, copy: bool = False) torch.Tensor[source]

Convert a series to a PyTorch tensor.

Parameters:
  • series (TimeSeries or array-like) – Input data.

  • device (str or torch.device, optional) – Target device.

  • dtype (torch.dtype, optional) – Target dtype.

  • requires_grad (bool, optional) – Whether to track gradients.

  • copy (bool, optional) – If True, always copy data; otherwise share memory if possible.

Returns:

The converted tensor.

Return type:

torch.Tensor

gwexpy.interop.torch_.from_torch(cls: type[T], tensor: torch.Tensor, t0: Any, dt: Any, unit: str | None = None) T[source]

Create a TimeSeries from a PyTorch tensor.

Parameters:
  • cls (type) – TimeSeries class to instantiate.

  • tensor (torch.Tensor) – Input tensor.

  • t0 (Quantity or float) – Start time.

  • dt (Quantity or float) – Sample interval.

  • unit (str or Unit, optional) – Data unit.

Returns:

The created time series.

Return type:

TimeSeries