Trait HalfFloatVecExt

pub trait HalfFloatVecExt: SealedHalfFloatVec

Extensions to [Vec<f16>] and [Vec<bf16>] to support reinterpret operations.

This trait is sealed and cannot be implemented outside of this crate.

Required Methods

fn reinterpret_into(self) -> Vec<u16>

Reinterprets a vector of [struct@f16]or bf16 numbers as a vector of u16 bits.

This is a zero-copy operation. The reinterpreted vector has the same memory location as self.

Examples

# use half::prelude::*;
let float_buffer = vec![f16::from_f32(1.), f16::from_f32(2.), f16::from_f32(3.)];
let int_buffer = float_buffer.reinterpret_into();

assert_eq!(int_buffer, [f16::from_f32(1.).to_bits(), f16::from_f32(2.).to_bits(), f16::from_f32(3.).to_bits()]);
fn from_f32_slice(slice: &[f32]) -> Self

Converts all of the elements of a [f32] slice into a new [struct@f16] or bf16 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][crate] for more information on hardware conversion support.

Examples

# use half::prelude::*;
let float_values = [1., 2., 3., 4.];
let vec: Vec<f16> = Vec::from_f32_slice(&float_values);

assert_eq!(vec, vec![f16::from_f32(1.), f16::from_f32(2.), f16::from_f32(3.), f16::from_f32(4.)]);
fn from_f64_slice(slice: &[f64]) -> Self

Converts all of the elements of a [f64] slice into a new [struct@f16] or bf16 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][crate] for more information on hardware conversion support.

Examples

# use half::prelude::*;
let float_values = [1., 2., 3., 4.];
let vec: Vec<f16> = Vec::from_f64_slice(&float_values);

assert_eq!(vec, vec![f16::from_f64(1.), f16::from_f64(2.), f16::from_f64(3.), f16::from_f64(4.)]);

Implementors