Function iter_num_tools::log_space

source ·
pub fn log_space<R>(range: R, steps: usize) -> LogSpace<R::Item>where
    R: ToLogSpace,
Expand description

Creates a logarithmic space over range with a fixed number of steps

use iter_num_tools::log_space;
use itertools::zip_eq;

// Inclusive
let it = log_space(1.0..=1000.0, 4);
let expected: Vec<f64> = vec![1.0, 10.0, 100.0, 1000.0];

// all approx equal
assert!(zip_eq(it, expected).all(|(x, y)| (x-y).abs() < 1e-10));

// Exclusive
let it = log_space(1.0..1000.0, 3);
let expected: Vec<f64> = vec![1.0, 10.0, 100.0];

// all approx equal
assert!(zip_eq(it, expected).all(|(x, y)| (x-y).abs() < 1e-10));