Skip to content

Commit

Permalink
Merge branch 'master' into blis-msrv
Browse files Browse the repository at this point in the history
  • Loading branch information
akern40 authored Nov 29, 2024
2 parents 4296b7c + fd3ce5d commit 1a8bc48
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 8 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,17 @@ jobs:
run: sudo apt-get install libopenblas-dev gfortran
- run: ./scripts/blas-integ-tests.sh "$FEATURES" 1.67.0

miri:
runs-on: ubuntu-latest
name: miri
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
with:
components: miri
- uses: Swatinem/rust-cache@v2
- run: ./scripts/miri-tests.sh

cross_test:
#if: ${{ github.event_name == 'merge_group' }}
runs-on: ubuntu-latest
Expand Down Expand Up @@ -161,6 +172,7 @@ jobs:
- format # should format be required?
- nostd
- tests
- miri
- cross_test
- cargo-careful
- docs
Expand Down
12 changes: 6 additions & 6 deletions crates/serialization-tests/tests/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ fn serial_many_dim_serde()

{
// Test a sliced array.
let mut a = ArcArray::linspace(0., 31., 32)
let mut a = ArcArray::from_iter(0..32)
.into_shape_with_order((2, 2, 2, 4))
.unwrap();
a.slice_collapse(s![..;-1, .., .., ..2]);
let serial = serde_json::to_string(&a).unwrap();
println!("Encode {:?} => {:?}", a, serial);
let res = serde_json::from_str::<ArcArray<f32, _>>(&serial);
let res = serde_json::from_str::<ArcArray<i32, _>>(&serial);
println!("{:?}", res);
assert_eq!(a, res.unwrap());
}
Expand Down Expand Up @@ -160,7 +160,7 @@ fn serial_many_dim_serde_msgpack()

{
// Test a sliced array.
let mut a = ArcArray::linspace(0., 31., 32)
let mut a = ArcArray::from_iter(0..32)
.into_shape_with_order((2, 2, 2, 4))
.unwrap();
a.slice_collapse(s![..;-1, .., .., ..2]);
Expand All @@ -171,7 +171,7 @@ fn serial_many_dim_serde_msgpack()
.unwrap();

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

assert_eq!(a, a_de);
}
Expand Down Expand Up @@ -215,14 +215,14 @@ fn serial_many_dim_ron()

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

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

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

assert_eq!(a, a_de);
}
Expand Down
2 changes: 2 additions & 0 deletions ndarray-rand/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ fn oversampling_without_replacement_should_panic()
}

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

#[cfg(feature = "quickcheck")]
quickcheck! {
#[cfg_attr(miri, ignore)] // This takes *forever* with Miri
fn sampling_behaves_as_expected(m: u8, n: u8, strategy: SamplingStrategy) -> TestResult {
let (m, n) = (m as usize, n as usize);
let a = Array::random((m, n), Uniform::new(0., 2.));
Expand Down
2 changes: 2 additions & 0 deletions scripts/all-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ cargo build -v --no-default-features

# ndarray with no features
cargo test -p ndarray -v --no-default-features
# ndarray with no_std-compatible features
cargo test -p ndarray -v --no-default-features --features approx
# all with features
cargo test -v --features "$FEATURES" $QC_FEAT
# all with features and release (ignore test crates which is already optimized)
Expand Down
18 changes: 18 additions & 0 deletions scripts/miri-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh

set -x
set -e

# We rely on layout-dependent casts, which should be covered with #[repr(transparent)]
# This should catch if we missed that
RUSTFLAGS="-Zrandomize-layout"

# Miri reports a stacked borrow violation deep within rayon, in a crate called crossbeam-epoch
# The crate has a PR to fix this: https://github.com/crossbeam-rs/crossbeam/pull/871
# but using Miri's tree borrow mode may resolve it for now.
# Disabled until we can figure out a different rayon issue: https://github.com/rust-lang/miri/issues/1371
# MIRIFLAGS="-Zmiri-tree-borrows"

# General tests
# Note that we exclude blas feature because Miri can't do cblas_gemm
cargo miri test -v -p ndarray -p ndarray-rand --features approx,serde
1 change: 1 addition & 0 deletions src/dimension/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1020,6 +1020,7 @@ mod test
}

quickcheck! {
#[cfg_attr(miri, ignore)] // Very slow on CI/CD machines
// FIXME: This test is extremely slow, even with i16 values, investigate
fn arith_seq_intersect_correct(
first1: i8, len1: i8, step1: i8,
Expand Down
1 change: 1 addition & 0 deletions tests/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2629,6 +2629,7 @@ mod array_cow_tests
});
}

#[cfg_attr(miri, ignore)] // Very slow on CI/CD machines
#[test]
fn test_clone_from()
{
Expand Down
4 changes: 2 additions & 2 deletions tests/azip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ fn test_azip2_sum()
}

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

Expand Down
1 change: 1 addition & 0 deletions tests/dimension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ fn test_array_view()
}

#[test]
#[cfg_attr(miri, ignore)] // Very slow on CI/CD machines
#[cfg(feature = "std")]
#[allow(clippy::cognitive_complexity)]
fn test_all_ndindex()
Expand Down
1 change: 1 addition & 0 deletions tests/iterators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,7 @@ fn test_into_iter_2d()
assert_eq!(v, [1, 3, 2, 4]);
}

#[cfg_attr(miri, ignore)] // Very slow on CI/CD machines
#[test]
fn test_into_iter_sliced()
{
Expand Down
2 changes: 2 additions & 0 deletions tests/numeric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ fn std_empty_arr()

#[test]
#[cfg(feature = "approx")]
#[cfg(feature = "std")]
fn var_axis()
{
use ndarray::{aview0, aview2};
Expand Down Expand Up @@ -222,6 +223,7 @@ fn var_axis()

#[test]
#[cfg(feature = "approx")]
#[cfg(feature = "std")]
fn std_axis()
{
use ndarray::aview2;
Expand Down
5 changes: 5 additions & 0 deletions tests/oper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ fn scaled_add()
}

#[cfg(feature = "approx")]
#[cfg_attr(miri, ignore)] // Very slow on CI/CD machines
#[test]
fn scaled_add_2()
{
Expand Down Expand Up @@ -540,6 +541,7 @@ fn scaled_add_2()
}

#[cfg(feature = "approx")]
#[cfg_attr(miri, ignore)] // Very slow on CI/CD machines
#[test]
fn scaled_add_3()
{
Expand Down Expand Up @@ -592,6 +594,7 @@ fn scaled_add_3()
}

#[cfg(feature = "approx")]
#[cfg_attr(miri, ignore)]
#[test]
fn gen_mat_mul()
{
Expand Down Expand Up @@ -681,6 +684,7 @@ fn gen_mat_mul_i32()

#[cfg(feature = "approx")]
#[test]
#[cfg_attr(miri, ignore)] // Takes too long
fn gen_mat_vec_mul()
{
use approx::assert_relative_eq;
Expand Down Expand Up @@ -746,6 +750,7 @@ fn gen_mat_vec_mul()
}

#[cfg(feature = "approx")]
#[cfg_attr(miri, ignore)] // Very slow on CI/CD machines
#[test]
fn vec_mat_mul()
{
Expand Down

0 comments on commit 1a8bc48

Please sign in to comment.