pub fn to_df64(tensor: &Tensor) -> Result<Tensor>Expand description
Convert an f64 tensor to an external Df64 tensor.
Rounding: exact. Every f64 value is a Df64 value with a zero low
component, so the result’s high component is the input bit for bit and its
low component is zero. Information a previous narrowing discarded is not
recovered here.
Range: the transformation preserves f64 infinity and NaN unchanged.
Allocation: a new externally defined tensor with the same shape is allocated at the destination; the input is neither consumed nor modified.
§Errors
Returns tenferro_tensor::Error::UnsupportedDType when tensor is not an
f64 value, and tenferro_tensor::Error::RuntimeState when its values are
not reachable as one borrowed slice.
§Examples
use tenferro_df64_proof::{conversion, Df64};
use tenferro_tensor::Tensor;
let tensor = Tensor::from_vec_col_major(vec![2], vec![1.0_f64, 2.0])?;
let widened = conversion::to_df64(&tensor)?;
let payload = widened.external_payload().expect("an external payload");
let values = payload.downcast_ref::<Df64>().expect("the payload type");
assert_eq!(values.as_slice(), &[Df64::from_f64(1.0), Df64::from_f64(2.0)]);