pub struct TensorCreationOptions {
pub device: Device,
pub dtype: Option<DType>,
}Expand description
Options for tensor creation.
This struct allows specifying the device and overriding the data type when creating a tensor.
When the dtype is not specified, the device’s default settings is used.
Fields§
§device: DeviceDevice where the tensor will be created.
dtype: Option<DType>Optional data type.
If None, the dtype will be inferred on creation from the device settings.
Implementations§
Source§impl TensorCreationOptions
impl TensorCreationOptions
Sourcepub fn new(device: Device) -> TensorCreationOptions
pub fn new(device: Device) -> TensorCreationOptions
Create new options with a specific device.
Data type will follow the device settings on tensor creation.
Sourcepub fn with_dtype(self, dtype: DType) -> TensorCreationOptions
pub fn with_dtype(self, dtype: DType) -> TensorCreationOptions
Set the tensor creation data type.
Sourcepub fn with_device(self, device: Device) -> TensorCreationOptions
pub fn with_device(self, device: Device) -> TensorCreationOptions
Set the tensor creation device.
Sourcepub fn dtype_or(&self, dtype: DType) -> DType
pub fn dtype_or(&self, dtype: DType) -> DType
Returns the tensor data type, or a provided default if not set.
This is useful for cases where TensorCreationOptions may not have an explicit dtype.
Trait Implementations§
Source§impl Clone for TensorCreationOptions
impl Clone for TensorCreationOptions
Source§fn clone(&self) -> TensorCreationOptions
fn clone(&self) -> TensorCreationOptions
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TensorCreationOptions
impl Debug for TensorCreationOptions
Source§impl Default for TensorCreationOptions
impl Default for TensorCreationOptions
Source§fn default() -> TensorCreationOptions
fn default() -> TensorCreationOptions
Returns new options with the backend’s default device.
Source§impl From<&Device> for TensorCreationOptions
impl From<&Device> for TensorCreationOptions
Source§fn from(device: &Device) -> TensorCreationOptions
fn from(device: &Device) -> TensorCreationOptions
Convenience conversion from a reference to a device.
Example:
use burn_tensor::TensorCreationOptions;
use burn_tensor::Device;
fn example(device: Device) {
let options: TensorCreationOptions = (&device).into();
}Auto Trait Implementations§
impl Freeze for TensorCreationOptions
impl RefUnwindSafe for TensorCreationOptions
impl Send for TensorCreationOptions
impl Sync for TensorCreationOptions
impl Unpin for TensorCreationOptions
impl UnsafeUnpin for TensorCreationOptions
impl UnwindSafe for TensorCreationOptions
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more