pub fn narrow(
source: &TypedTensor<f32, DynRank, Host>,
) -> Result<TypedTensor<Bf16, DynRank, Host>, Error>Expand description
Round every value to the nearest bfloat16, with ties to even.
§Errors
Returns a validation error carrying
tenferro_tensor_core::ValidationError::ShapeDataLengthMismatch when the
output shape cannot be built, which cannot happen for a shape that already
exists.
§Examples
use tenferro_bf16_proof::conversion::narrow;
use tenferro_tensor::{DynRank, Host, TypedTensor};
// 1.00390625 rounds down to 1.0: bfloat16 keeps eight bits of significand.
let source = TypedTensor::<_, DynRank, Host>::from_host_vec_col_major(vec![1], vec![1.00390625_f32])?;
assert_eq!(narrow(&source)?.as_slice()[0].to_f32(), 1.0);