Struct TensorCreationOptions
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§
§impl<B> TensorCreationOptions<B>where
B: Backend,
impl<B> TensorCreationOptions<B>where
B: Backend,
pub 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.
pub fn with_dtype(self, dtype: DType) -> TensorCreationOptions<B>
pub fn with_dtype(self, dtype: DType) -> TensorCreationOptions<B>
Set the tensor creation data type.
pub 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.
pub fn float() -> TensorCreationOptions<B>
pub fn float() -> TensorCreationOptions<B>
Create options with backend’s default device and float dtype.
pub fn int() -> TensorCreationOptions<B>
pub fn int() -> TensorCreationOptions<B>
Create options with backend’s default device and int dtype.
pub fn bool() -> TensorCreationOptions<B>
pub fn bool() -> TensorCreationOptions<B>
Create options with backend’s default device and bool dtype.
pub 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§
§impl<B> Clone for TensorCreationOptions<B>
impl<B> Clone for TensorCreationOptions<B>
§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 more§impl<B> Debug for TensorCreationOptions<B>
impl<B> Debug for TensorCreationOptions<B>
§impl<B> Default for TensorCreationOptions<B>where
B: Backend,
impl<B> Default for TensorCreationOptions<B>where
B: Backend,
§fn default() -> TensorCreationOptions<B>
fn default() -> TensorCreationOptions<B>
Returns new options with the backend’s default device.
§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,
§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();
}Auto Trait Implementations§
impl<B> Freeze for TensorCreationOptions<B>
impl<B> RefUnwindSafe for TensorCreationOptions<B>
impl<B> Send for TensorCreationOptions<B>
impl<B> Sync for TensorCreationOptions<B>
impl<B> Unpin for TensorCreationOptions<B>
impl<B> UnwindSafe for TensorCreationOptions<B>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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