Skip to content

feat: derive clone for linspace#1594

Merged
akern40 merged 1 commit into
rust-ndarray:masterfrom
skrobchik:feat/linspace-clone
Jun 6, 2026
Merged

feat: derive clone for linspace#1594
akern40 merged 1 commit into
rust-ndarray:masterfrom
skrobchik:feat/linspace-clone

Conversation

@skrobchik
Copy link
Copy Markdown
Contributor

It would be useful for Linspace to implement Clone when the element type is Clone.

For example, iterating over a 2D grid with itertools' cartesian_product requires the iterators to implement Clone.

https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=3ff8d5b95c2b6acef66c577dc9205f5d

which currently does not compile:

error[E0277]: the trait bound `Linspace<{float}>: Clone` is not satisfied
    --> src/main.rs:5:60
     |
   5 |     for (x, y) in linspace(-1.0, 1.0, 3).cartesian_product(linspace(-1.0, 1.0, 3)) {
     |                                          ----------------- ^^^^^^^^^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `Linspace<{float}>`
     |                                          |
     |                                          required by a bound introduced by this call

For a generic struct, #[derive] implements Clone conditionally by adding bound Clone on generic parameters.
https://doc.rust-lang.org/std/clone/trait.Clone.html

@akern40
Copy link
Copy Markdown
Collaborator

akern40 commented Jun 6, 2026

Seems sane, happy to accept after CI finishes, thanks!

@akern40 akern40 merged commit 8cf2c32 into rust-ndarray:master Jun 6, 2026
14 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants