pub trait Representation: Sealed + 'static {
// Required method
fn default_placement() -> Placement;
}Expand description
Sealed selector for the owned payload representation of a TypedTensor.
The three markers are Host, Gpu and Dynamic. The trait is
sealed: downstream crates select an existing representation, they do not
define one.
§Examples
use tenferro_tensor::{Dynamic, DynRank, Host, Representation, TypedTensor};
fn extent<D: Representation>(tensor: &TypedTensor<f64, DynRank, D>) -> usize {
tensor.shape()[0]
}
let host = TypedTensor::<f64, DynRank, Host>::from_host_vec_col_major(vec![3], vec![0.0; 3])?;
assert_eq!(extent(&host), 3);
let dynamic: TypedTensor<f64, DynRank, Dynamic> = host.into_dynamic();
assert_eq!(extent(&dynamic), 3);Required Methods§
Sourcefn default_placement() -> Placement
fn default_placement() -> Placement
Placement given to an owner of this representation built without one.
Placement metadata is fixed when a Host or Gpu owner is built:
only a Dynamic owner can replace it afterwards, through
TypedTensor::set_placement. Host constructors use this
placement, unpinned host memory with no device and no CPU affinity.
Gpu and Dynamic use the same default when no placement is
supplied; a device-resident owner receives its device placement from
the constructor that adopts the backend buffer.
§Examples
use tenferro_tensor::{DynRank, Host, MemoryKind, Representation, TypedTensor};
let expected = <Host as Representation>::default_placement();
assert_eq!(expected.memory_kind, MemoryKind::UnpinnedHost);
assert!(expected.device.is_none());
let host = TypedTensor::<f64, DynRank, Host>::from_host_vec_col_major(vec![1], vec![1.0])?;
assert_eq!(host.placement(), &expected);Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".