Skip to content

Commit 1a8bc48

Browse files
authored
Merge branch 'master' into blis-msrv
2 parents 4296b7c + fd3ce5d commit 1a8bc48

File tree

12 files changed

+53
-8
lines changed

12 files changed

+53
-8
lines changed

.github/workflows/ci.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,17 @@ jobs:
100100
run: sudo apt-get install libopenblas-dev gfortran
101101
- run: ./scripts/blas-integ-tests.sh "$FEATURES" 1.67.0
102102

103+
miri:
104+
runs-on: ubuntu-latest
105+
name: miri
106+
steps:
107+
- uses: actions/checkout@v4
108+
- uses: dtolnay/rust-toolchain@nightly
109+
with:
110+
components: miri
111+
- uses: Swatinem/rust-cache@v2
112+
- run: ./scripts/miri-tests.sh
113+
103114
cross_test:
104115
#if: ${{ github.event_name == 'merge_group' }}
105116
runs-on: ubuntu-latest
@@ -161,6 +172,7 @@ jobs:
161172
- format # should format be required?
162173
- nostd
163174
- tests
175+
- miri
164176
- cross_test
165177
- cargo-careful
166178
- docs

crates/serialization-tests/tests/serialize.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ fn serial_many_dim_serde()
4545

4646
{
4747
// Test a sliced array.
48-
let mut a = ArcArray::linspace(0., 31., 32)
48+
let mut a = ArcArray::from_iter(0..32)
4949
.into_shape_with_order((2, 2, 2, 4))
5050
.unwrap();
5151
a.slice_collapse(s![..;-1, .., .., ..2]);
5252
let serial = serde_json::to_string(&a).unwrap();
5353
println!("Encode {:?} => {:?}", a, serial);
54-
let res = serde_json::from_str::<ArcArray<f32, _>>(&serial);
54+
let res = serde_json::from_str::<ArcArray<i32, _>>(&serial);
5555
println!("{:?}", res);
5656
assert_eq!(a, res.unwrap());
5757
}
@@ -160,7 +160,7 @@ fn serial_many_dim_serde_msgpack()
160160

161161
{
162162
// Test a sliced array.
163-
let mut a = ArcArray::linspace(0., 31., 32)
163+
let mut a = ArcArray::from_iter(0..32)
164164
.into_shape_with_order((2, 2, 2, 4))
165165
.unwrap();
166166
a.slice_collapse(s![..;-1, .., .., ..2]);
@@ -171,7 +171,7 @@ fn serial_many_dim_serde_msgpack()
171171
.unwrap();
172172

173173
let mut deserializer = rmp_serde::Deserializer::new(&buf[..]);
174-
let a_de: ArcArray<f32, _> = serde::Deserialize::deserialize(&mut deserializer).unwrap();
174+
let a_de: ArcArray<i32, _> = serde::Deserialize::deserialize(&mut deserializer).unwrap();
175175

176176
assert_eq!(a, a_de);
177177
}
@@ -215,14 +215,14 @@ fn serial_many_dim_ron()
215215

216216
{
217217
// Test a sliced array.
218-
let mut a = ArcArray::linspace(0., 31., 32)
218+
let mut a = ArcArray::from_iter(0..32)
219219
.into_shape_with_order((2, 2, 2, 4))
220220
.unwrap();
221221
a.slice_collapse(s![..;-1, .., .., ..2]);
222222

223223
let a_s = ron_serialize(&a).unwrap();
224224

225-
let a_de: ArcArray<f32, _> = ron_deserialize(&a_s).unwrap();
225+
let a_de: ArcArray<i32, _> = ron_deserialize(&a_s).unwrap();
226226

227227
assert_eq!(a, a_de);
228228
}

ndarray-rand/tests/tests.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ fn oversampling_without_replacement_should_panic()
5757
}
5858

5959
quickcheck! {
60+
#[cfg_attr(miri, ignore)] // Takes an insufferably long time
6061
fn oversampling_with_replacement_is_fine(m: u8, n: u8) -> TestResult {
6162
let (m, n) = (m as usize, n as usize);
6263
let a = Array::random((m, n), Uniform::new(0., 2.));
@@ -86,6 +87,7 @@ quickcheck! {
8687

8788
#[cfg(feature = "quickcheck")]
8889
quickcheck! {
90+
#[cfg_attr(miri, ignore)] // This takes *forever* with Miri
8991
fn sampling_behaves_as_expected(m: u8, n: u8, strategy: SamplingStrategy) -> TestResult {
9092
let (m, n) = (m as usize, n as usize);
9193
let a = Array::random((m, n), Uniform::new(0., 2.));

scripts/all-tests.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ cargo build -v --no-default-features
1313

1414
# ndarray with no features
1515
cargo test -p ndarray -v --no-default-features
16+
# ndarray with no_std-compatible features
17+
cargo test -p ndarray -v --no-default-features --features approx
1618
# all with features
1719
cargo test -v --features "$FEATURES" $QC_FEAT
1820
# all with features and release (ignore test crates which is already optimized)

scripts/miri-tests.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/sh
2+
3+
set -x
4+
set -e
5+
6+
# We rely on layout-dependent casts, which should be covered with #[repr(transparent)]
7+
# This should catch if we missed that
8+
RUSTFLAGS="-Zrandomize-layout"
9+
10+
# Miri reports a stacked borrow violation deep within rayon, in a crate called crossbeam-epoch
11+
# The crate has a PR to fix this: https://github.com/crossbeam-rs/crossbeam/pull/871
12+
# but using Miri's tree borrow mode may resolve it for now.
13+
# Disabled until we can figure out a different rayon issue: https://github.com/rust-lang/miri/issues/1371
14+
# MIRIFLAGS="-Zmiri-tree-borrows"
15+
16+
# General tests
17+
# Note that we exclude blas feature because Miri can't do cblas_gemm
18+
cargo miri test -v -p ndarray -p ndarray-rand --features approx,serde

src/dimension/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,6 +1020,7 @@ mod test
10201020
}
10211021

10221022
quickcheck! {
1023+
#[cfg_attr(miri, ignore)] // Very slow on CI/CD machines
10231024
// FIXME: This test is extremely slow, even with i16 values, investigate
10241025
fn arith_seq_intersect_correct(
10251026
first1: i8, len1: i8, step1: i8,

tests/array.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2629,6 +2629,7 @@ mod array_cow_tests
26292629
});
26302630
}
26312631

2632+
#[cfg_attr(miri, ignore)] // Very slow on CI/CD machines
26322633
#[test]
26332634
fn test_clone_from()
26342635
{

tests/azip.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ fn test_azip2_sum()
216216
}
217217

218218
#[test]
219-
#[cfg(feature = "approx")]
219+
#[cfg(all(feature = "approx", feature = "std"))]
220220
fn test_azip3_slices()
221221
{
222222
use approx::assert_abs_diff_eq;
@@ -232,7 +232,7 @@ fn test_azip3_slices()
232232
*a += b / 10.;
233233
*c = a.sin();
234234
});
235-
let res = Array::linspace(0., 3.1, 32).mapv_into(f32::sin);
235+
let res = Array::from_iter(0..32).mapv(|x| f32::sin(x as f32 / 10.));
236236
assert_abs_diff_eq!(res, ArrayView::from(&c), epsilon = 1e-4);
237237
}
238238

tests/dimension.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ fn test_array_view()
323323
}
324324

325325
#[test]
326+
#[cfg_attr(miri, ignore)] // Very slow on CI/CD machines
326327
#[cfg(feature = "std")]
327328
#[allow(clippy::cognitive_complexity)]
328329
fn test_all_ndindex()

tests/iterators.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,7 @@ fn test_into_iter_2d()
971971
assert_eq!(v, [1, 3, 2, 4]);
972972
}
973973

974+
#[cfg_attr(miri, ignore)] // Very slow on CI/CD machines
974975
#[test]
975976
fn test_into_iter_sliced()
976977
{

0 commit comments

Comments
 (0)