Skip to content

[pull] master from rust-ndarray:master - #32

Open
pull[bot] wants to merge 358 commits into
WiresmithTech:masterfrom
rust-ndarray:master
Open

pull[bot] wants to merge 358 commits into
WiresmithTech:masterfrom
rust-ndarray:master

Conversation

@pull

@pull pull Bot commented Dec 6, 2021 •

Copy link
Copy Markdown

See Commits and Changes for more details.


Created by pull[bot]

Can you help keep this open source service alive? 💖 Please sponsor : )

@pull pull Bot added the ⤵️ pull label Dec 6, 2021
jturner314 and others added 29 commits March 9, 2024 21:51
Before this commit, running `MIRIFLAGS="-Zmiri-tag-raw-pointers" cargo
miri test test_map_axis` caused Miri to report undefined behavior in
the `test_map_axis` test. This commit fixes the underlying issue.
Basically, Miri doesn't like us using a reference to an element to
access other elements. Here's some sample code to illustrate the
issue:

```rust
let a: Vec<i32> = vec![5, 6];
let first_elt: &i32 = &a[0];
let ptr: *const i32 = first_elt as *const i32;
// Okay: the data is contained in the data referenced by `first_elt`.
let a0 = unsafe { &*ptr.offset(0) };
assert_eq!(*a0, 5);
// Not okay: the data is not contained in the data referenced by `first_elt`.
let a1 = unsafe { &*ptr.offset(1) };
assert_eq!(*a1, 6);
```

Before this commit, we were using `self.index_axis(axis,
0).map(|first_elt| ...)` to create views of the lanes, from references
to the first elements in the lanes. Accessing elements within those
views (other than the first element) led to the Miri error, since the
view's pointer was derived from a reference to a single element.

Thanks to @5225225 for reporting the issue. (This commit fixes #1137.)
Before this commit, running `MIRIFLAGS="-Zmiri-tag-raw-pointers" cargo
miri test` caused Miri to report undefined behavior for code using the
`WindowsIter`, `ExactChunksIter`, and `ExactChunksIterMut` iterators.
This commit fixes the underlying issue. Basically, Miri doesn't like
code which uses a reference to an element to access other elements.
Before this commit, these iterators wrapped the `ElementsBase` and
`ElementsBaseMut` iterators, and they created views from the
references returned by those inner iterators. Accessing elements
within those views (other than the first element) led to the Miri
error, since the view's pointer was derived from a reference to a
single element. Now, the iterators wrap `Baseiter` instead, which
produces raw pointers instead of references.

Although not necessary to satisfy Miri, this commit also changes the
`Windows`, `ExactChunks`, and `ExactChunksMut` producers to wrap raw
views instead of normal views. This avoids potential confusion
regarding which elements are accessible through the views produced by
these producers.
Fix Miri failure with -Zmiri-tag-raw-pointers
Fix Miri errors for WindowsIter and ExactChunksIter/Mut
derived Debug for Iter and IterMut
Add missing safety checks to `From<&[[A; N]]> for ArrayView` and `From<&mut [[A; N]]> for ArrayViewMut`
into_shape_with_order:

If an index ordering is not specified, the default is `RowMajor`.  The
operation will only succeed if the array's memory layout is compatible
with the index ordering.

into_shape:

`.into_shape()` "moves" elements differently depending on if the input
array is C-contig or F-contig, it follows the index order that
corresponds to the memory order.

Because of this, the method is deprecated. That reshapes depend on
memory order is not intuitive.
Make the aview0, aview1, and aview2 free functions be const fns
Better shape: Deprecate reshape, into_shape
akern40 and others added 30 commits January 4, 2026 10:28
All of these are formatting, linting, etc fixes.
This will allow users to ergonomically compare the two types without over-verbose dereferences.

Closes #1549
In preparation for reworking the inner dimension types (see #1506),
we'd like to prepare the name `Layout` to be used for new traits and types. Although the type is largely internal (with hidden documentation), we opt for a conservative deprecation approach.

In the future, we should consider making `LayoutBitset` entirely internal, but this would require larger changes to the codebase.
In #1479 we used `cfg_attr(docsrs, doc(cfg(feature = "...")))` to add feature-gating information to the documentation. However, this required us to "remember" this at every call site. It turns out that there is a `doc(auto_cfg)` setting that we can use globally to do this for us automatically.
This is a follow-on to #1563; it probably should have been the same PR. In additon to reserving the name `Layout`, we'd also like to clean up the `src/layout` module so that we can pack it full of new features for #1506. So we collapse everything that's currently there into `layout::bitset`, and add a `pub use` declaration to re-export it.

As a side note, I'd eventually like `layout` to act as a template for how we handle modules: minimal module-level code and clear module-level documentation. I've made #1566 to track that library-wide.
Both #1563 and #1567 were done in preparation for new code to address #1506. However, those PRs introduce deprecations, which will require a minor version bump to adhere to SemVer. Instead of having them on master, we have created the refactor branch where they will continue to live.
As we try to release versions more quickly, I'd like to avoid our README
looking out of date. I suspect that almost everyone nowadays uses `cargo
add` to add dependencies, rather than putting them directly into their
`Cargo.toml`, so I've opted to just add a short instruction for
installation.
As has been discussed in #1175, I expanded `Zip` for up to 9 producers
(including `azip!`, `par_azip!`). Previously, it was only working for up
to 6 producers.

I also added two simple tests with 9 producers.
Implement phase angle calculation for complex arrays, calculated as atan2(imaginary, real) in radians. Angles are wrapped to (-pi, pi].

---------

Co-authored-by: Adam Kern <[email protected]>
Tighten linting; fix rustdoc warnings across feature gates

I continued using stricter linting and found several odd cases in tests
and
examples, along with rustdoc warnings triggered by feature-gated items.

This commit cleans up those warnings by:
- adjusting tests to avoid clippy false positives under -D warnings
- removing unused generics and ambiguous empty vec initializers
- fixing rustdoc links via feature-gated doc attributes rather than
  linking to non-exported items

All tests are still passing.

Clippy still warns about the use of `1..-1` as an empty range; this
appears
intentional in ndarray slicing semantics, so I’ve left it unchanged for
now.

Please review the rustdoc changes that rely on feature-gated
documentation.
This is a breaking change, since it alters the arguments of `linspace` rather than adding a new function.

Closes #1169
@scho-furiosa pointed out in #1584 that there was an unnecessary `clone`
in `Baseiter::next` that was degrading performance for
dynamic-dimensional arrays. This change switches to a move, netting a
74% speedup in iteration for dynamic-dimensional arrays.

Tests (detailed in #1584) showed that there was a trade-off in
performance between dynamic- and fixed-dimensional iteration. `ArrayD`
performs best when mutating its index; `ArrayN` performs best when using
a move. This is an indication that, in the future, `Baseiter::next`
should dispatch to the "layout" / `Dimension` underlying type.

Co-authored-by: Sungkeun Cho <[email protected]>
Unfortunately, as tends to happen, the ground has shifted beneath our
feet, and we now need MSRV 1.87 to run with our dependencies. The good
news is that this will allow us to go to the 2024 edition. Onwards and
upwards!
As pointed out in #1589, permute_axes had a bug. This uses a simple
algorithm to fix it; explanations for this algorithm are all over the
internet, it's nothing fancy. I did take the opportunity to introduce
proptest, which I'd like to make more use of over time.

Down the line, it would be good to change the argument to `permute_axes`
to be something like `T: Permutation`. Right now, `permute_axes` just
has an assertion that the input is a real permutation. I'd call that a
classic example of this library opting for asserts when we could be
using better typing. But I think that will be easier / better to
introduce after the core rework.

Closes #1859
New Rust releases periodically break CI through new lints and
deprecations (#1620 was the latest), and we usually find out from
failures on unrelated PRs. Running this check daily, and including
stable clippy, should surface those breakages on `master` within a day.

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
The F-order fast paths in triu and tril swap the last two axes and call
each other. That is only safe for 2D arrays, where the swap yields a
C-contiguous view. Higher-D F-and-not-C views (for example a C-order
transpose followed by insert_axis) can remain F-and-not-C after the swap,
so the two functions recurse until they overflow the stack.

Restrict the shortcut to ndim == 2 so normal 2D .f() arrays keep the
optimization, while the issue #1615 repro takes the non-recursive path.
…nite (#1614)

The boolean_ops! macro in src/numeric/impl_float_maths.rs had an inverted $all
predicate: Zip::from(self).all(|&elt| !elt.$func()) tests "all elements are NOT
NaN", the opposite of the documented "true if all elements are NaN". $any was
defined as !self.$all(), so the double negation made is_any_* appear correct
while is_all_* returned true for an all-finite array.

Correct both predicates together (fixing only $all would break the is_any_*
methods that ride on the double negation):
  $all -> Zip::from(self).all(|&elt| elt.$func())
  $any -> Zip::from(self).any(|&elt| elt.$func())

Empty-array semantics are preserved (all -> true, any -> false).
Treat shapes with an empty axis as non-overlapping when validating
mutable views.

This allows zero strides on empty arrays while keeping the existing
overlap checks for non-empty shapes.

Fixes #1609
Add a public `from_slice` that returns `None` when the slice length does not match the type's dimensionality (`IxDyn` accepts any length). Now `from_dimension` uses `from_slice`.

Closes #1330
No changes needed in ndarray-rand itself.

Changes in `crates/numeric-tests/tests/accuracy.rs`:
- Import `RngExt` for `random_range`.
- Replace the removed `SmallRng::from_os_rng` with `SmallRng::from_rng(&mut rand::rng())`.

bump ndarray-rand to 0.17.0

Closes #1590
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.