set_default_dtypes

Function set_default_dtypes 

pub fn set_default_dtypes<B>(
    device: &<B as BackendTypes>::Device,
    float_dtype: impl Into<FloatDType>,
    int_dtype: impl Into<IntDType>,
) -> Result<(), DeviceError>
where B: Backend,
Expand description

Sets the default data types for the device.

This updates the device’s default data types used for tensor creation.

Settings can only be initialized once per device. Subsequent calls for the same device return DeviceError::AlreadyInitialized.

§Note

Initialization must happen before any tensor creation on the device. The first tensor operation will lock the device to its defaults, causing any subsequent initialization attempt to return DeviceError::AlreadyInitialized.

§Example

fn example<B: Backend>() {
    let device = B::Device::default();
     
    // Update the device settings
    set_default_dtypes::<B>(&device, DType::F16, DType::I32);
     
    // All float tensors created after this will use F16 by default
    let tensor = Tensor::<B, 2>::zeros([2, 3], &device);
    // All int tensors created after this will use I32 default
    let tensor = Tensor::<B, 2, Int>::zeros([2, 3], &device);
}