Repository navigation
Conversation
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.
Test using cargo-careful
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.
Co-authored-by: Adam Reichold <[email protected]>
Make the aview0, aview1, and aview2 free functions be const fns
Better shape: Deprecate reshape, into_shape
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.
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.
@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
…ring conversion (#1600)
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
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
See Commits and Changes for more details.
Created by
pull[bot]
Can you help keep this open source service alive? 💖 Please sponsor : )