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
//! Turns a range into a linearly spaced sequence of values.
//!
//! - [`Linspace::linspace`] returns an iterator.
//!
//! - [`Linspace::linspace_array`] returns an array.
//!
//! Only works on bounded ranges like [`Range`](core::ops::Range) and [`RangeInclusive`](core::ops::RangeInclusive).
//!
//! ## Examples
//!
//! Both of these will print `[0, 25, 50, 75]`.
//!
//! ```rust
//! use linspace::*;
//!
//! let x: Vec<u32> = (0..100).linspace(4).collect();
//! assert_eq!(x, [0, 25, 50, 75]);
//! println!("{:?}", x);
//!
//! let y: [u32; 4] = (0..100).linspace_array();
//! assert_eq!(y, [0, 25, 50, 75]);
//! println!("{:?}", y);
//!
//! assert_eq!(x, y);
//! ```
//!
//! Both inclusive and exclusive ranges can be used.
//! And these will print `[0, 25, 50, 75, 100]`.
//!
//! ```rust
//! use linspace::*;
//!
//! let x: Vec<u32> = (0..=100).linspace(5).collect();
//! assert_eq!(x, [0, 25, 50, 75, 100]);
//! println!("{:?}", x);
//!
//! let y: [u32; 5] = (0..=100).linspace_array();
//! assert_eq!(y, [0, 25, 50, 75, 100]);
//! println!("{:?}", y);
//!
//! assert_eq!(x, y);
//! ```
//!
//! Want a non-linear range? That's also possible. After all, [`Linspace::linspace`] just returns an [`Iterator`].
//!
//! ```rust
//! use linspace::*;
//!
//! let x: Vec<f32> = (0.0..1.0)
//! .linspace(10)
//! .map(|z| 10.0f32.powf(z))
//! .collect();
//! println!("{:?}", x);
//! ```
//!
//! Very convenient!
moddef!;