set_default_float_dtype

Function set_default_float_dtype 

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

Sets the default floating-point data type 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_float_dtype::<B>(&device, DType::F16);
     
    // All float tensors created after this will use F16 by default
    let tensor = Tensor::<B, 2>::zeros([2, 3], &device);
}