Trait HalfFloatSliceExt
pub trait HalfFloatSliceExt: SealedHalfFloatSlice
Extensions to [f16] and [bf16] slices to support conversion and reinterpret operations.
This trait is sealed and cannot be implemented outside of this crate.
Required Methods
fn reinterpret_cast(&self) -> &[u16]Reinterprets a slice of [
struct@f16] or [struct@bf16] numbers as a slice ofu16bits.This is a zero-copy operation. The reinterpreted slice has the same lifetime and memory location as
self.Examples
# use *; let float_buffer = ; let int_buffer = float_buffer.reinterpret_cast; assert_eq!;fn reinterpret_cast_mut(&mut self) -> &mut [u16]Reinterprets a mutable slice of [
struct@f16] or [struct@bf16] numbers as a mutable slice ofu16. bitsThis is a zero-copy operation. The transmuted slice has the same lifetime as the original, which prevents mutating
selfas long as the returned&mut [u16]is borrowed.Examples
# use *; let mut float_buffer = ; // Note that we need to drop int_buffer before using float_buffer again or we will get a borrow error. assert_eq!;fn convert_from_f32_slice(&mut self, src: &[f32])Converts all of the elements of a
[f32]slice into [struct@f16] or [struct@bf16] values inself.The length of
srcmust be the same asself.The conversion operation is vectorized over the slice, meaning the conversion may be more efficient than converting individual elements on some hardware that supports SIMD conversions. See crate documentation for more information on hardware conversion support.
Panics
This function will panic if the two slices have different lengths.
Examples
# use *; // Initialize an empty buffer let mut buffer = ; let buffer = buffer.; let float_values = ; // Now convert buffer.convert_from_f32_slice; assert_eq!;fn convert_from_f64_slice(&mut self, src: &[f64])Converts all of the elements of a
[f64]slice into [struct@f16] or [struct@bf16] values inself.The length of
srcmust be the same asself.The conversion operation is vectorized over the slice, meaning the conversion may be more efficient than converting individual elements on some hardware that supports SIMD conversions. See crate documentation for more information on hardware conversion support.
Panics
This function will panic if the two slices have different lengths.
Examples
# use *; // Initialize an empty buffer let mut buffer = ; let buffer = buffer.; let float_values = ; // Now convert buffer.convert_from_f64_slice; assert_eq!;fn convert_to_f32_slice(&self, dst: &mut [f32])Converts all of the [
struct@f16] or [struct@bf16] elements ofselfintof32values indst.The length of
srcmust be the same asself.The conversion operation is vectorized over the slice, meaning the conversion may be more efficient than converting individual elements on some hardware that supports SIMD conversions. See crate documentation for more information on hardware conversion support.
Panics
This function will panic if the two slices have different lengths.
Examples
# use *; // Initialize an empty buffer let mut buffer = ; let half_values = ; // Now convert half_values.convert_to_f32_slice; assert_eq!;fn convert_to_f64_slice(&self, dst: &mut [f64])Converts all of the [
struct@f16] or [struct@bf16] elements ofselfintof64values indst.The length of
srcmust be the same asself.The conversion operation is vectorized over the slice, meaning the conversion may be more efficient than converting individual elements on some hardware that supports SIMD conversions. See crate documentation for more information on hardware conversion support.
Panics
This function will panic if the two slices have different lengths.
Examples
# use *; // Initialize an empty buffer let mut buffer = ; let half_values = ; // Now convert half_values.convert_to_f64_slice; assert_eq!;fn to_f32_vec(&self) -> Vec<f32>Converts all of the [
struct@f16] or [struct@bf16] elements ofselfintof32values in a new vectorThe conversion operation is vectorized over the slice, meaning the conversion may be more efficient than converting individual elements on some hardware that supports SIMD conversions. See crate documentation for more information on hardware conversion support.
This method is only available with the
stdorallocfeature.Examples
# use *; let half_values = ; let vec = half_values.to_f32_vec; assert_eq!;fn to_f64_vec(&self) -> Vec<f64>Converts all of the [
struct@f16] or [struct@bf16] elements ofselfintof64values in a new vector.The conversion operation is vectorized over the slice, meaning the conversion may be more efficient than converting individual elements on some hardware that supports SIMD conversions. See crate documentation for more information on hardware conversion support.
This method is only available with the
stdorallocfeature.Examples
# use *; let half_values = ; let vec = half_values.to_f64_vec; assert_eq!;
Implementors
impl HalfFloatSliceExt for [bf16]impl HalfFloatSliceExt for [f16]