Skip to main content

TensorConvertible

Trait TensorConvertible 

Source
pub trait TensorConvertible<const R: usize, B: Backend>: Sized {
    // Required methods
    fn to_tensor(&self, device: &<B as BackendTypes>::Device) -> Tensor<B, R>;
    fn from_tensor(tensor: Tensor<B, R>) -> Result<Self, TensorConversionError>;
}
Expand description

Bidirectional conversion between a domain type and a Burn tensor.

Implementors must round-trip: from_tensor(x.to_tensor(device)) equals Ok(x) for any valid x. Strategies and replay buffers rely on this invariant.

§Type Parameters

  • R: Rank of the tensor produced.
  • B: Burn backend.

§Errors

from_tensor returns TensorConversionError when the tensor’s shape, dtype, or contents violate the domain type’s invariants (see State::is_valid / Action::is_valid).

Required Methods§

Source

fn to_tensor(&self, device: &<B as BackendTypes>::Device) -> Tensor<B, R>

Converts self into a tensor on device.

Source

fn from_tensor(tensor: Tensor<B, R>) -> Result<Self, TensorConversionError>

Reconstructs a value from a tensor.

§Errors

Returns TensorConversionError if the tensor’s shape or contents do not describe a valid instance of Self.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§