From d8ef2f6297a11ff42c64f1f5e15867567998ef70 Mon Sep 17 00:00:00 2001 From: Vivian Date: Thu, 13 Aug 2026 16:42:58 +0200 Subject: [PATCH] Correct and improve documentation for `linspace` --- src/linspace.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/linspace.rs b/src/linspace.rs index 4baf2de5d..8ffad5e1b 100644 --- a/src/linspace.rs +++ b/src/linspace.rs @@ -70,12 +70,29 @@ impl ExactSizeIterator for Linspace where Linspace: Iterator {} /// Return an iterator of evenly spaced floats. /// -/// The `Linspace` has `n` elements from `a` to `b` (inclusive). +/// The `Linspace` produces `n` elements over the specified `range`. If the range is exclusive, the iterator will not include the end bound. /// /// The iterator element type is `F`, where `F` must implement [`Float`], e.g. /// [`f32`] or [`f64`]. /// -/// **Panics** if converting `n` to type `F` fails. +/// ## Panics +/// If converting `n` to type `F` fails. +/// +/// ## Examples +/// +/// An exclusive range (0..10) +/// ``` +/// # use ndarray::linspace; +/// let a: Vec<_> = linspace(0.0..10.0, 5).collect(); +/// assert_eq!(a, [0.0, 2.0, 4.0, 6.0, 8.0]); +/// ``` +/// +/// An inclusive range (1..=9) +/// ``` +/// # use ndarray::linspace; +/// let a: Vec<_> = linspace(1.0..=9.0, 5).collect(); +/// assert_eq!(a, [1.0, 3.0, 5.0, 7.0, 9.0]); +/// ``` #[inline] pub fn linspace(range: R, n: usize) -> Linspace where