try_vec_f64_into_vec_real

Function try_vec_f64_into_vec_real 

Source
pub fn try_vec_f64_into_vec_real<RealType: RealScalar>(
    vec: Vec<f64>,
) -> Result<Vec<RealType>, ErrorsTryFromf64<RealType::RawReal>>
Expand description

Attempts to convert a vector of f64 values into a vector of the specified real scalar type.

This function provides a fallible conversion that validates each input value according to the target type’s validation policy. If any value fails validation, the entire operation fails and returns an error.

§Parameters

  • vec: A vector of f64 values to convert

§Return Value

  • Ok(Vec<RealType>): If all values can be successfully converted and validated
  • Err(ErrorsTryFromf64): If any value fails validation, containing details about the failure

§Usage Examples

§Successful Conversion

use num_valid::{try_vec_f64_into_vec_real, RealNative64StrictFinite};

let input = vec![1.0, -2.5, 3.14159];
let result = try_vec_f64_into_vec_real::<RealNative64StrictFinite>(input);
assert!(result.is_ok());

let validated_vec = result.unwrap();
assert_eq!(validated_vec.len(), 3);
assert_eq!(*validated_vec[0].as_ref(), 1.0);

§Failed Conversion

use num_valid::{try_vec_f64_into_vec_real, RealNative64StrictFinite};

let input = vec![1.0, f64::NAN, 3.0]; // Contains NaN
let result = try_vec_f64_into_vec_real::<RealNative64StrictFinite>(input);
assert!(result.is_err()); // Fails due to NaN value