Releases: rust-ndarray/ndarray
0.17.0
Version 0.17.0 (2025-10-14)
Version 0.17.0 introduces a new array reference type — the preferred way to write functions and extension traits in ndarray
. This release is fully backwards-compatible but represents a major usability improvement. The first section of this changelog explains the change in detail.
It also includes numerous new methods, math functions, and internal improvements — all credited below.
A New Way to Write Functions
TL;DR
ndarray
0.17.0 adds new reference types for writing functions and traits that work seamlessly with owned arrays and views.
When writing functions that accept array arguments:
- Use
&ArrayRef<A, D>
to read elements from any array. - Use
&mut ArrayRef<A, D>
to modify elements. - Use
&T where T: AsRef<LayoutRef<A, D>>
to inspect shape/stride only. - Use
&mut T where T: AsMut<LayoutRef<A, D>>
to modify shape/stride only.
All existing function signatures continue to work; these new types are fully opt-in.
Background
ndarray has multiple ways to write functions that take arrays (a problem captured well in issue #1059). For example:
fn sum(a: ArrayView1<f64>) -> f64;
fn sum(a: &ArrayView1<f64>) -> f64;
fn sum(a: &Array1<f64>) -> f64;
All of these work, but having several equivalent forms causes confusion. The most general solution, writing generically over storage types:
fn sum<S>(a: &ArrayBase<S, Ix1>) -> f64
where S: Data<Elem = f64>;
is powerful but verbose and often hard to read. Version 0.17.0 introduces a new, simpler pattern that expresses the same flexibility more clearly.
Solution
Three new reference types make it easier to write functions that accept any kind of array while clearly expressing what kind of access (data or layout) they need.
Reading / Writing Elements: ArrayRef<A, D>
ArrayRef
is the Deref
target of ArrayBase
. It behaves like &[T]
for Vec<T>
, giving access to elements and layout. Mutability is expressed through the reference itself (&
vs &mut
), not through a trait bound or the type itself. It is used as follows:
fn sum(a: &ArrayRef1<f64>) -> f64;
fn cumsum_mut(a: &mut ArrayRef1<f64>);
(ArrayRef1 is available from the prelude.)
Reading / Writing Shape: LayoutRef<A, D>
LayoutRef lets functions view or modify shape/stride information without touching data. This replaces verbose signatures like:
fn alter_view<S>(a: &mut ArrayBase<S, Ix1>)
where S: Data<Elem = f64>;
Use AsRef / AsMut for best compatibility:
fn alter_shape<T>(a: &mut T)
where T: AsMut<LayoutRef<f64>>;
(Accepting a LayoutRef
directly can cause unnecessary copies; see #1440.)
Reading / Writing Unsafe Elements: RawRef<A, D>
RawRef
augments RawArrayView
and RawArrayViewMut
for power users needing unsafe element access (e.g. uninitialized buffers). Like LayoutRef
, it is best used via AsRef
/ AsMut
.
Added
- A new "array reference" type by @akern40 #1440
- A
diff
method for calculating the difference between elements by @johann-cm #1437 - A
partition
method for partially sorting an array by @NewBornRustacean #1498 - A
meshgrid
method for building regular grids of values by @akern40 #1477 - A
cumprod
method for cumulative products by @NewBornRustacean #1491 - More element-wise math functions for floats by @Waterdragen #1507
- Additions include
exp_m1
,ln_1p
,asin
,acos
,atan
,sinh
,cosh
,tanh
,asinh
,acosh
,atanh
, andhypot
- Additions include
- Dot product support for dynamic arrays by @NewBornRustacean #1483 and @akern40 #1494
- An
axis_windows_with_stride
method for strided windows by @goertzenator #1460 - In-place methods for permuting (
permute_axes
) and reversing (reverse_axes
) axes by @NewBornRustacean #1505 - Adds
into_*_iter
functions as lifetime-preserving versions of into-iterator functionality by @akern40 #1510
Changed
remove_index
can now be called on views, in addition to owned arrays by @akern40
Removed
- Removed the
serde-1
,test
, anddocs
feature flags; by @akern40 #1479- Use
approx,serde,rayon
instead ofdocs
. - Use
serde
instead ofserde-1
- Use
Fixed
last_mut()
now guarantees that the underlying data is uniquely held by @bluss #1429ArrayView
is now covariant over lifetime by @akern40 #1480, so that the following code now compiles
fn fn_cov<'a>(x: ArrayView1<'static, f64>) -> ArrayView1<'a, f64> {
x
}
Documentation
- Filled missing documentation and adds warn(missing_docs) by @akern40
- Fixed a typo in the documentation of
select
by @Drazhar - Fixed a typo in the documentation of
into_raw_vec_and_offset
by @benliepert - Documented
Array::zeros
with how to control the return type by @akern40
Other
0.16.1
Version 0.16.1 (2024-08-14)
- Refactor and simplify BLAS gemm call further by @bluss #1421
- Fix infinite recursion and off-by-one error in triu/tril by @akern40 #1418
- Fix using BLAS for all compatible cases of memory layout by @bluss #1419
- Use PR check instead of Merge Queue, and check rustdoc by @bluss #1420
- Make iterators covariant in element type by @bluss #1417
0.16.0
Version 0.16.0 (2024-08-03)
Featured Changes
- Better shape: Deprecate reshape, into_shape by @bluss #1310
.into_shape()
is now deprecated.
Use.into_shape_with_order()
or.to_shape()
instead, which don't haveinto_shape
's drawbacks.
New Features and Improvements
- Check for aliasing in
RawViewMut::from_shape_ptr
with a debug assertion by @bluss #1413 - Allow aliasing in ArrayView::from_shape by @bluss #1410
- Remove deprecations from 0.15.x by @bluss #1409
- Make
CowArray
an owned storage array, require Clone bound forinto_shared
by @jturner314 #1028 - Change
NdProducer::Dim
ofaxis_windows()
toIx1
by @jonasBoss #1305 - Add
squeeze()
to dynamic dimension arrays by @barakugav #1396 - Add
flatten
,flatten_with_order
andinto_flat
to arrays by @barakugav #1397 - Make compatible with thumbv6m-none-eabi by @BjornTheProgrammer #1384
is_unique
forArcArray
by @daniellga #1399- Add
triu
andtril
methods directly to ArrayBase by @akern40 #1386 - Fix styling of the BLAS integration heading. by @adamreichold #1390
- Implement
product_axis
by @akern40 #1387 - Add reserve method for owned arrays by @ssande7 #1268
- Use inline on spit_at and smaller methods by @bluss #1381
- Update to Approx 0.5 by @bluss #1380
- Add .into_raw_vec_with_offset() and deprecate .into_raw_vec() by @bluss #1379
- Add additional array -> array view conversions by @bluss #1130
- implement DoubleEndedIterator for 1d
LanesIter
by @Muthsera #1237 - Add Zip::any by @nilgoyette #1228
- Make the aview0, aview1, and aview2 free functions be const fns by @jturner314 #1132
- Add missing safety checks to
From<&[[A; N]]> for ArrayView
andFrom<&mut [[A; N]]> for ArrayViewMut
by @jturner314 #1131 - derived Debug for Iter and IterMut by @biskwikman #1353
- Fix Miri errors for WindowsIter and ExactChunksIter/Mut by @jturner314 #1142
- Fix Miri failure with -Zmiri-tag-raw-pointers by @jturner314 #1138
- Track-caller panics by @xd009642 #975
- Add slice_axis_move method by @jturner314 #1211
- iterators: Re-export IntoIter by @bluss #1370
- Fix unsafe blocks in
s![]
macro by @jturner314 #1196 - Fix comparison with NumPy of slicing with negative step by @venkat0791 #1319
- Updated Windows
base
Computations to be Safer by @LazaroHurtado #1297 - Update README-quick-start.md by @fumseckk #1246
- Added stride support to
Windows
by @LazaroHurtado #1249 - Added select example to numpy user docs by @WillAyd #1294
- Add both approx features to the readme by @nilgoyette #1289
- Add NumPy examples combining slicing and assignment by @jturner314 #1210
- Fix contig check for single element arrays by @bluss #1362
- Export Linspace and Logspace iterators by @johann-cm #1348
- Use
clone_from()
in two places by @ChayimFriedman2 #1347 - Update README-quick-start.md by @joelchen #1344
- Provide element-wise math functions for floats by @KmolYuan #1042
- Improve example in doc for columns method by @gkobeaga #1221
- Fix description of stack! in quick start by @jturner314 #1156
Tests, CI and Maintainer tasks
- CI: require rustfmt, nostd by @bluss #1411
- Prepare changelog for 0.16.0 by @bluss #1401
- Organize dependencies with workspace = true (cont.) by @bluss #1407
- Update to use dep: for features by @bluss #1406
- Organize the workspace of test crates a bit better by @bluss #1405
- Add rustfmt commit to ignored revisions for git blame by @lucascolley #1376
- The minimum amount of work required to fix our CI by @adamreichold #1388
- Fixed broke continuous integration badge by @juhotuho10 #1382
- Use mold linker to speed up ci by @bluss #1378
- Add rustformat config and CI by @bluss #1375
- Add docs to CI by @jturner314 #925
- Test using cargo-careful by @bluss #1371
- Further ci updates - numeric tests, and run all tests on PRs by @bluss #1369
- Setup ci so that most checks run in merge queue only by @bluss #1368
- Use merge queue by @bluss #1367
- Try to make the master branch shipshape by @adamreichold #1286
- Update ci - run cross tests only on master by @bluss #1366
- ndarray_for_numpy_users some example to code not pointed out to clippy by @higumachan #1360
- Fix minimum rust version mismatch in lib.rs by @HoKim98 #1352
- Fix MSRV build by pinning crossbeam crates. by @adamreichold #1345
- Fix new rustc lints to make the CI pass. by @adamreichold #1337
- Make Clippy happy and fix MSRV build by [@adamreichold](https://github.com/ada...