pub struct TensorCreationOptions<B>where
B: Backend,{
pub device: <B as Backend>::Device,
pub dtype: Option<DType>,
}Expand description
Options for tensor creation.
This struct allows specifying the device and/or data type (dtype) when creating a tensor.
Fields§
§device: <B as Backend>::DeviceDevice where the tensor will be created.
dtype: Option<DType>Optional data type.
If None, the dtype will be inferred on creation from the backend’s default dtype for the tensor kind.
Implementations§
Source§impl<B> TensorCreationOptions<B>where
B: Backend,
impl<B> TensorCreationOptions<B>where
B: Backend,
Sourcepub fn new(device: <B as Backend>::Device) -> TensorCreationOptions<B>
pub fn new(device: <B as Backend>::Device) -> TensorCreationOptions<B>
Create new options with a specific device.
Data type will be inferred on creation from the backend’s default dtype for the tensor kind.
Sourcepub fn with_dtype(self, dtype: DType) -> TensorCreationOptions<B>
pub fn with_dtype(self, dtype: DType) -> TensorCreationOptions<B>
Set the tensor creation data type.
Sourcepub fn with_device(
self,
device: <B as Backend>::Device,
) -> TensorCreationOptions<B>
pub fn with_device( self, device: <B as Backend>::Device, ) -> TensorCreationOptions<B>
Set the tensor creation device.
Sourcepub fn float() -> TensorCreationOptions<B>
pub fn float() -> TensorCreationOptions<B>
Create options with backend’s default device and float dtype.
Sourcepub fn int() -> TensorCreationOptions<B>
pub fn int() -> TensorCreationOptions<B>
Create options with backend’s default device and int dtype.
Sourcepub fn bool() -> TensorCreationOptions<B>
pub fn bool() -> TensorCreationOptions<B>
Create options with backend’s default device and bool dtype.
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<B> Clone for TensorCreationOptions<B>
impl<B> Clone for TensorCreationOptions<B>
Source§fn clone(&self) -> TensorCreationOptions<B>
fn clone(&self) -> TensorCreationOptions<B>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<B> Debug for TensorCreationOptions<B>
impl<B> Debug for TensorCreationOptions<B>
Source§impl<B> Default for TensorCreationOptions<B>where
B: Backend,
impl<B> Default for TensorCreationOptions<B>where
B: Backend,
Source§fn default() -> TensorCreationOptions<B>
fn default() -> TensorCreationOptions<B>
Returns new options with the backend’s default device.
Source§impl<B> From<&<B as Backend>::Device> for TensorCreationOptions<B>where
B: Backend,
impl<B> From<&<B as Backend>::Device> for TensorCreationOptions<B>where
B: Backend,
Source§fn from(device: &<B as Backend>::Device) -> TensorCreationOptions<B>
fn from(device: &<B as Backend>::Device) -> TensorCreationOptions<B>
Convenience conversion from a reference to a device.
Example:
use burn_tensor::backend::Backend;
use burn_tensor::TensorCreationOptions;
fn example<B: Backend>(device: B::Device) {
let options: TensorCreationOptions<B> = (&device).into();
}