diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1c76bd9d1..eabc21c61 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,12 +24,11 @@ jobs: - 1.51.0 # MSRV steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@master with: - profile: minimal toolchain: ${{ matrix.rust }} - override: true + - uses: Swatinem/rust-cache@v2 - name: Install openblas run: sudo apt-get install libopenblas-dev gfortran - run: ./scripts/all-tests.sh "$FEATURES" ${{ matrix.rust }} @@ -45,20 +44,14 @@ jobs: target: i686-unknown-linux-gnu steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@master with: - profile: minimal toolchain: ${{ matrix.rust }} - target: ${{ matrix.target }} - override: true - - name: Cache cargo plugins - uses: actions/cache@v1 - with: - path: ~/.cargo/bin/ - key: ${{ runner.os }}-cargo-plugins + targets: ${{ matrix.target }} + - uses: Swatinem/rust-cache@v2 - name: Install cross - run: cargo install cross || true + run: cargo install cross - run: ./scripts/cross-tests.sh "docs" ${{ matrix.rust }} ${{ matrix.target }} clippy: @@ -68,12 +61,10 @@ jobs: rust: - beta steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@master with: - profile: minimal toolchain: ${{ matrix.rust }} - override: true components: clippy + - uses: Swatinem/rust-cache@v2 - run: cargo clippy --features docs - diff --git a/Cargo.toml b/Cargo.toml index 85c410449..a648b09bc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -73,13 +73,15 @@ rayon = ["rayon_", "std"] matrixmultiply-threading = ["matrixmultiply/threading"] -[profile.release] [profile.bench] debug = true +[profile.dev.package.numeric-tests] +opt-level = 2 +[profile.test.package.numeric-tests] +opt-level = 2 [workspace] -members = ["ndarray-rand", "xtest-serialization", "xtest-blas"] -exclude = ["xtest-numeric"] +members = ["ndarray-rand", "xtest-serialization", "xtest-blas", "xtest-numeric"] [package.metadata.release] no-dev-version = true diff --git a/scripts/all-tests.sh b/scripts/all-tests.sh index 98f4e3390..2167f3451 100755 --- a/scripts/all-tests.sh +++ b/scripts/all-tests.sh @@ -6,6 +6,16 @@ set -e FEATURES=$1 CHANNEL=$2 +if [ "$CHANNEL" = "1.51.0" ]; then + cargo update --package rayon --precise 1.5.3 + cargo update --package rayon-core --precise 1.9.3 + cargo update --package serde --precise 1.0.156 + cargo update --package thiserror --precise 1.0.39 + cargo update --package once_cell --precise 1.14.0 + cargo update --package openblas-src --precise 0.10.5 + cargo update --package openblas-build --precise 0.10.5 +fi + cargo build --verbose --no-default-features # Testing both dev and release profiles helps find bugs, especially in low level code cargo test --verbose --no-default-features @@ -17,6 +27,6 @@ cargo test --manifest-path=ndarray-rand/Cargo.toml --features quickcheck --verbo cargo test --manifest-path=xtest-serialization/Cargo.toml --verbose cargo test --manifest-path=xtest-blas/Cargo.toml --verbose --features openblas-system cargo test --examples -CARGO_TARGET_DIR=target/ cargo test --manifest-path=xtest-numeric/Cargo.toml --verbose -CARGO_TARGET_DIR=target/ cargo test --manifest-path=xtest-numeric/Cargo.toml --verbose --features test_blas +cargo test --manifest-path=xtest-numeric/Cargo.toml --verbose +cargo test --manifest-path=xtest-numeric/Cargo.toml --verbose --features test_blas ([ "$CHANNEL" != "nightly" ] || cargo bench --no-run --verbose --features "$FEATURES") diff --git a/scripts/cross-tests.sh b/scripts/cross-tests.sh index 7c4f13111..7473a72fa 100755 --- a/scripts/cross-tests.sh +++ b/scripts/cross-tests.sh @@ -11,4 +11,4 @@ cross build -v --features="$FEATURES" --target=$TARGET cross test -v --no-fail-fast --features="$FEATURES" --target=$TARGET cross test -v --no-fail-fast --target=$TARGET --manifest-path=ndarray-rand/Cargo.toml --features quickcheck cross test -v --no-fail-fast --target=$TARGET --manifest-path=xtest-serialization/Cargo.toml --verbose -CARGO_TARGET_DIR=target/ cross test -v --no-fail-fast --target=$TARGET --manifest-path=xtest-numeric/Cargo.toml +cross test -v --no-fail-fast --target=$TARGET --manifest-path=xtest-numeric/Cargo.toml diff --git a/src/arraytraits.rs b/src/arraytraits.rs index 74ce9d644..9aa45bde3 100644 --- a/src/arraytraits.rs +++ b/src/arraytraits.rs @@ -298,7 +298,7 @@ where { } -#[cfg(any(feature = "serde"))] +#[cfg(feature = "serde")] // Use version number so we can add a packed format later. pub const ARRAY_FORMAT_VERSION: u8 = 1u8; diff --git a/src/dimension/dimension_trait.rs b/src/dimension/dimension_trait.rs index 6ebb9cad4..7181d2268 100644 --- a/src/dimension/dimension_trait.rs +++ b/src/dimension/dimension_trait.rs @@ -83,7 +83,7 @@ pub trait Dimension: /// Compute the size of the dimension (number of elements) fn size(&self) -> usize { - self.slice().iter().fold(1, |s, &a| s * a as usize) + self.slice().iter().product() } /// Compute the size while checking for overflow. @@ -603,7 +603,7 @@ impl Dimension for Dim<[Ix; 2]> { fn size_checked(&self) -> Option { let m = get!(self, 0); let n = get!(self, 1); - (m as usize).checked_mul(n as usize) + m.checked_mul(n) } #[inline] @@ -728,7 +728,7 @@ impl Dimension for Dim<[Ix; 3]> { let m = get!(self, 0); let n = get!(self, 1); let o = get!(self, 2); - m as usize * n as usize * o as usize + m * n * o } #[inline] diff --git a/src/dimension/dynindeximpl.rs b/src/dimension/dynindeximpl.rs index 85b34bdbe..e81bf4f3d 100644 --- a/src/dimension/dynindeximpl.rs +++ b/src/dimension/dynindeximpl.rs @@ -96,7 +96,7 @@ impl PartialEq for IxDynRepr { match (self, rhs) { (&IxDynRepr::Inline(slen, ref sarr), &IxDynRepr::Inline(rlen, ref rarr)) => { slen == rlen - && (0..CAP as usize) + && (0..CAP) .filter(|&i| i < slen as usize) .all(|i| sarr[i] == rarr[i]) } diff --git a/src/dimension/mod.rs b/src/dimension/mod.rs index dd34052ec..6755efeb7 100644 --- a/src/dimension/mod.rs +++ b/src/dimension/mod.rs @@ -47,7 +47,7 @@ mod sequence; /// Calculate offset from `Ix` stride converting sign properly #[inline(always)] pub fn stride_offset(n: Ix, stride: Ix) -> isize { - (n as isize) * ((stride as Ixs) as isize) + (n as isize) * (stride as Ixs) } /// Check whether the given `dim` and `stride` lead to overlapping indices diff --git a/src/impl_methods.rs b/src/impl_methods.rs index 115cd2d71..4a6b42223 100644 --- a/src/impl_methods.rs +++ b/src/impl_methods.rs @@ -1990,7 +1990,7 @@ where let strides = unlimited_transmute::(self.strides); return Ok(ArrayBase::from_data_ptr(self.data, self.ptr) .with_strides_dim(strides, dim)); - } else if D::NDIM == None || D2::NDIM == None { // one is dynamic dim + } else if D::NDIM.is_none() || D2::NDIM.is_none() { // one is dynamic dim // safe because dim, strides are equivalent under a different type if let Some(dim) = D2::from_dimension(&self.dim) { if let Some(strides) = D2::from_dimension(&self.strides) { diff --git a/src/indexes.rs b/src/indexes.rs index 23ae2744c..541570184 100644 --- a/src/indexes.rs +++ b/src/indexes.rs @@ -75,7 +75,7 @@ where .slice() .iter() .zip(ix.slice().iter()) - .fold(0, |s, (&a, &b)| s + a as usize * b as usize); + .fold(0, |s, (&a, &b)| s + a * b); self.dim.size() - gone } }; @@ -286,7 +286,7 @@ where .slice() .iter() .zip(self.index.slice().iter()) - .fold(0, |s, (&a, &b)| s + a as usize * b as usize); + .fold(0, |s, (&a, &b)| s + a * b); let l = self.dim.size() - gone; (l, Some(l)) } diff --git a/src/iterators/mod.rs b/src/iterators/mod.rs index 85da56fe5..063b22053 100644 --- a/src/iterators/mod.rs +++ b/src/iterators/mod.rs @@ -114,7 +114,7 @@ impl ExactSizeIterator for Baseiter { .slice() .iter() .zip(ix.slice().iter()) - .fold(0, |s, (&a, &b)| s + a as usize * b as usize); + .fold(0, |s, (&a, &b)| s + a * b); self.dim.size() - gone } } diff --git a/src/zip/mod.rs b/src/zip/mod.rs index a6cd0c1fe..cc7a4187d 100644 --- a/src/zip/mod.rs +++ b/src/zip/mod.rs @@ -92,6 +92,7 @@ where { type Output = ArrayView<'a, A, E::Dim>; fn broadcast_unwrap(self, shape: E) -> Self::Output { + #[allow(clippy::needless_borrow)] let res: ArrayView<'_, A, E::Dim> = (&self).broadcast_unwrap(shape.into_dimension()); unsafe { ArrayView::new(res.ptr, res.dim, res.strides) } } diff --git a/tests/array.rs b/tests/array.rs index e3922ea8d..8fdbb9992 100644 --- a/tests/array.rs +++ b/tests/array.rs @@ -9,6 +9,7 @@ use approx::assert_relative_eq; use defmac::defmac; +#[allow(deprecated)] use itertools::{zip, Itertools}; use ndarray::prelude::*; use ndarray::{arr3, rcarr2}; @@ -499,12 +500,14 @@ fn test_index() { *elt = i; } + #[allow(deprecated)] for ((i, j), a) in zip(indices((2, 3)), &A) { assert_eq!(*a, A[[i, j]]); } let vi = A.slice(s![1.., ..;2]); let mut it = vi.iter(); + #[allow(deprecated)] for ((i, j), x) in zip(indices((1, 2)), &mut it) { assert_eq!(*x, vi[[i, j]]); } diff --git a/xtest-blas/Cargo.toml b/xtest-blas/Cargo.toml index aee8c3ce4..7ad33953c 100644 --- a/xtest-blas/Cargo.toml +++ b/xtest-blas/Cargo.toml @@ -14,7 +14,7 @@ num-traits = "0.2" num-complex = { version = "0.4", default-features = false } [dependencies] -ndarray = { path = "../", features = ["approx", "blas"] } +ndarray = { path = "..", features = ["approx", "blas"] } blas-src = { version = "0.8", optional = true } diff --git a/xtest-numeric/Cargo.toml b/xtest-numeric/Cargo.toml index 7a6c3cedd..8558d39ad 100644 --- a/xtest-numeric/Cargo.toml +++ b/xtest-numeric/Cargo.toml @@ -8,7 +8,7 @@ edition = "2018" [dependencies] approx = "0.4" ndarray = { path = "..", features = ["approx"] } -ndarray-rand = { path = "../ndarray-rand/" } +ndarray-rand = { path = "../ndarray-rand" } rand_distr = "0.4" blas-src = { optional = true, version = "0.8", default-features = false, features = ["openblas"] } @@ -27,8 +27,3 @@ test = false [features] test_blas = ["ndarray/blas", "blas-src", "openblas-src"] - -[profile.dev] -opt-level = 2 -[profile.test] -opt-level = 2 diff --git a/xtest-serialization/Cargo.toml b/xtest-serialization/Cargo.toml index 973a688fe..857e31fe6 100644 --- a/xtest-serialization/Cargo.toml +++ b/xtest-serialization/Cargo.toml @@ -8,7 +8,7 @@ publish = false test = false [dependencies] -ndarray = { path = "../", features = ["serde"] } +ndarray = { path = "..", features = ["serde"] } [features] default = ["ron"]