1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#![deny(missing_docs)]
#![cfg_attr(feature = "trusted_len", feature(trusted_len))]
#![cfg_attr(feature = "iter_advance_by", feature(iter_advance_by))]
//! `iter_num_tools` is a collection if iterator extensions that
//! make heavy use of number properties.
//! Mostly extending on [Range](std::ops::Range).
//!
//! ## `LinSpace`
//! [`LinSpace`](lin_space) is an iterator over a range with a fixed number of values all evenly spaced.
//!
//! ```
//! use iter_num_tools::lin_space;
//!
//! // Count from 1.0 up to and including 5.0, with 5 numbers counted in total
//! let it = lin_space(1.0..=5.0, 5);
//! assert!(it.eq(vec![1.0, 2.0, 3.0, 4.0, 5.0]));
//!
//! // Count from 0.0 up to and excluding 5.0, with 5 numbers counted in total
//! let it = lin_space(0.0..5.0, 5);
//! assert!(it.eq(vec![0.0, 1.0, 2.0, 3.0, 4.0]));
//! ```
//!
//!
//! ## `GridSpace`
//! [`GridSpace`](grid_space) extends on [`LinSpace`](#linspace).
//!
//! ```
//! use iter_num_tools::grid_space;
//!
//! // count in 2 dimensions (excluding end points),
//! // from 0.0 up to 1.0 in the x direction with 2 even steps,
//! // and 0.0 up to 2.0 in the y direction with 4 even steps
//! let it = grid_space([0.0, 0.0]..[1.0, 2.0], [2, 4]);
//! assert!(it.eq(vec![
//!     [0.0, 0.0], [0.0, 0.5], [0.0, 1.0], [0.0, 1.5],
//!     [0.5, 0.0], [0.5, 0.5], [0.5, 1.0], [0.5, 1.5],
//! ]));
//!
//! // count in 2 dimensions (including end points),
//! // from 0.0 up to 1.0 in the x direction,
//! // and 0.0 up to 2.0 in the y direction with 3 even steps in all directions
//! let it = grid_space([0.0, 0.0]..=[1.0, 2.0], 3);
//! assert!(it.eq(vec![
//!     [0.0, 0.0], [0.0, 1.0], [0.0, 2.0],
//!     [0.5, 0.0], [0.5, 1.0], [0.5, 2.0],
//!     [1.0, 0.0], [1.0, 1.0], [1.0, 2.0],
//! ]));
//! ```
//!
//! ## `Arange`
//! [`Arange`](arange()) is similar to [`LinSpace`](#linspace), but instead of a fixed amount of steps,
//! it steps by a fixed amount.
//!
//! ```
//! use iter_num_tools::arange;
//!
//! let it = arange(0.0..2.0, 0.5);
//! assert!(it.eq(vec![0.0, 0.5, 1.0, 1.5]));
//! ```
//!
//! #### Note
//! There is no inclusive version of arange. Consider the following
//! ```compile_fail
//! use iter_num_tools::arange;
//!
//! let it = arange(0.0..=2.1, 0.5);
//! ```
//! We would not expect 2.1 to ever be a value that the iterator will ever meet, but the range suggests it should be included.
//! Therefore, no [RangeInclusive](std::ops::RangeInclusive) implementation is provided.
//!
//! ## ArangeGrid
//! [`ArangeGrid`](arange_grid()) is the same as [`GridSpace`](#gridspace) but for [`Arange`](#arange) instead of [`LinSpace`](#linspace).
//!
//!
//! ```
//! use iter_num_tools::arange_grid;
//!
//! // count in 2 dimensions,
//! // from 0.0 up to 1.0 in the x direction,
//! // and 0.0 up to 2.0 in the y direction,
//! // stepping by 0.5 each time
//! let it = arange_grid([0.0, 0.0]..[1.0, 2.0], 0.5);
//! assert!(it.eq(vec![
//!     [0.0, 0.0], [0.0, 0.5], [0.0, 1.0], [0.0, 1.5],
//!     [0.5, 0.0], [0.5, 0.5], [0.5, 1.0], [0.5, 1.5],
//! ]));
//!
//! // count in 2 dimensions,
//! // from 0.0 up to 1.0 in the x direction stepping by 0.5 each time,
//! // and 0.0 up to 2.0 in the y direction stepping by 1.0 each time
//! let it = arange_grid([0.0, 0.0]..[1.0, 2.0], [0.5, 1.0]);
//! assert!(it.eq(vec![
//!     [0.0, 0.0], [0.0, 1.0],
//!     [0.5, 0.0], [0.5, 1.0],
//! ]));
//! ```
//!
//! ## `LogSpace`
//! [`LogSpace`](log_space()) is similar to [`LinSpace`](#linspace), but instead of evenly spaced linear steps, it has evenly spaced logarithmic steps.
//!
//! ```
//! use iter_num_tools::log_space;
//! use itertools::zip_eq;
//!
//! // From 1.0 up to and including 1000.0, taking 4 logarithmic steps
//! let it = log_space(1.0..=1000.0, 4);
//! let expected: Vec<f64> = vec![1.0, 10.0, 100.0, 1000.0];
//!
//! assert!(zip_eq(it, expected).all(|(x, y)| (x-y).abs() < 1e-10));
//!
//! // From 1.0 up to 1000.0, taking 3 logarithmic steps
//! let it = log_space(1.0..1000.0, 3);
//! let expected: Vec<f64> = vec![1.0, 10.0, 100.0];
//!
//! assert!(zip_eq(it, expected).all(|(x, y)| (x-y).abs() < 1e-10));
//! ```

#![cfg_attr(not(test), no_std)]

mod arange;
mod arange_grid;
mod gridspace;
mod linspace;
mod logspace;
mod space;

pub use arange::{arange, Arange};
pub use arange_grid::{arange_grid, ArangeGrid};
pub use gridspace::{grid_space, GridSpace};
pub use linspace::{lin_space, LinSpace};
pub use logspace::{log_space, LogSpace};