probly.representation.sampling.torch_sample

Torch sample implementation.

Classes

TorchTensorSample(tensor, sample_dim)

A sample implementation for torch tensors.

class probly.representation.sampling.torch_sample.TorchTensorSample(tensor, sample_dim)[source]

Bases: Sample[Tensor]

A sample implementation for torch tensors.

Parameters:
classmethod from_iterable(samples, sample_dim=None, sample_axis='auto', dtype=None)[source]

Create an TorchTensorSample from a sequence of samples.

Parameters:
  • samples (Iterable[torch.Tensor]) – The predictions to create the sample from.

  • sample_dim (SampleAxis | None) – The dimension along which samples are organized.

  • sample_axis (SampleAxis | None) – Alias for sample_dim for compatibility.

  • dtype (torch.dtype | None) – Desired data type of the array.

Returns:

The created TorchTensorSample.

Return type:

Self

classmethod from_sample(sample, **kwargs)

Create a new Sample from an existing Sample.

Parameters:
  • sample (Sample[T]) – The sample to create the new sample from.

  • kwargs (Unpack[SampleParams]) – Parameters for sample creation.

Returns:

The created Sample.

Return type:

Self

concat(other)[source]
Parameters:

other (Sample[Tensor])

Return type:

Self

move_sample_axis(new_sample_axis)[source]

Alias for TorchTensorSample.move_sample_dim().

Parameters:

new_sample_axis (int)

Return type:

TorchTensorSample

move_sample_dim(new_sample_dim)[source]

Return a new TorchTensorSample with the sample dimension moved to new_sample_dim.

Parameters:

new_sample_dim (int) – The new sample dimension.

Returns:

A new TorchTensorSample with the sample dimension moved.

Return type:

TorchTensorSample

sample_mean()[source]

Compute the mean of the sample.

Return type:

Tensor

sample_std(ddof=1)[source]

Compute the standard deviation of the sample.

Parameters:

ddof (int)

Return type:

Tensor

sample_var(ddof=1)[source]

Compute the variance of the sample.

Parameters:

ddof (int)

Return type:

Tensor

size(dim: int) int[source]
size(dim: None = None) Size

The total number of elements in the underlying array.

to(*args, **kwargs)[source]

Moves and/or casts the underlying tensor. See torch.Tensor.to for details.

Parameters:
  • *args (Any) – Positional arguments to pass to torch.Tensor.to.

  • **kwargs (Any) – Keyword arguments to pass to torch.Tensor.to.

Returns:

A copy of the TorchTensorSample.

Return type:

Self

property T: Tensor

The transposed version of the underlying array.

property device: Any

The device of the underlying array.

property dtype: dtype

The data type of the underlying array.

property mT: Tensor

The transposed version of the underlying array.

property ndim: int

The number of dimensions of the underlying array.

property sample_axis: int

The axis along which samples are organized.

sample_dim: int
property sample_size: int

Return the number of samples.

property samples: Tensor

Return an iterator over the samples.

property shape: tuple[int, ...]

The shape of the underlying array.

tensor: Tensor