Skip to content

Commit

Permalink
Factored out argmin-math tests into separate package
Browse files Browse the repository at this point in the history
Due to the additivity requirement on cargo features even for features
that are not enabled simultaneously, together with the requirement that
only one crate in the dependency tree specifies any `links` attribute,
it was not possible to test multiple backend versions for ndarray-linalg
by features: argmin-rs#368 (comment)
Previously this approach worked for different versions of
ndarray-linalg insofar as the used backend `netlib` just coincidentally
remained the same for all tested ndarray-linalg versions.
This is not the case for the intel-mkl backend, which is desirable to
use as the default because it works on all three major platforms. To
enable the change of the backend as well as make the testing more
robust against future changes in ndarray-linalg backend versions, the
tests were factored out into their own crates. This works because the
strict additivity requirement for inactive features is not enforced for
dependencies: rust-lang/cargo#5969 (comment)
  • Loading branch information
Tastaturtaste committed Oct 6, 2023
1 parent c2c8477 commit af2d302
Show file tree
Hide file tree
Showing 49 changed files with 2,856 additions and 2,333 deletions.
32 changes: 16 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ jobs:
- name: argmin-math (ndarray_v0_13-nolinalg)
run: cargo test -p argmin-math --no-default-features --features "ndarray_v0_13-nolinalg"
# ndarray with linalg, without serde
- name: argmin-math (ndarray_latest,_dev_linalg_latest)
run: cargo test -p argmin-math --no-default-features --features "ndarray_latest,_dev_linalg_latest"
- name: argmin-math (ndarray_v0_15,_dev_linalg_0_16)
run: cargo test -p argmin-math --no-default-features --features "ndarray_v0_15,_dev_linalg_0_16"
- name: argmin-math (ndarray_v0_14,_dev_linalg_0_13)
run: cargo test -p argmin-math --no-default-features --features "ndarray_v0_14,_dev_linalg_0_13"
- name: argmin-math (ndarray_v0_13,_dev_linalg_0_12)
run: cargo test -p argmin-math --no-default-features --features "ndarray_v0_13,_dev_linalg_0_12"
- name: argmin-math (ndarray_latest)
run: cargo test --manifest-path ./argmin-math-ndarray-linalg-tests/ndarray_latest/Cargo.toml
- name: argmin-math (ndarray_v0_15)
run: cargo test --manifest-path ./argmin-math-ndarray-linalg-tests/ndarray_0_15/Cargo.toml
- name: argmin-math (ndarray_v0_14)
run: cargo test --manifest-path ./argmin-math-ndarray-linalg-tests/ndarray_0_14/Cargo.toml
- name: argmin-math (ndarray_v0_13)
run: cargo test --manifest-path ./argmin-math-ndarray-linalg-tests/ndarray_0_13/Cargo.toml
# ndarray without linalg, with serde
- name: argmin-math (ndarray_latest-serde,_dev_linalg_latest)
run: cargo test -p argmin-math --no-default-features --features "ndarray_latest-serde,_dev_linalg_latest"
Expand All @@ -105,14 +105,14 @@ jobs:
- name: argmin-math (ndarray_v0_13-serde,_dev_linalg_0_12)
run: cargo test -p argmin-math --no-default-features --features "ndarray_v0_13-serde,_dev_linalg_0_12"
# ndarray with linalg, with serde
- name: argmin-math (ndarray_latest-serde,_dev_linalg_latest)
run: cargo test -p argmin-math --no-default-features --features "ndarray_latest-serde,_dev_linalg_latest"
- name: argmin-math (ndarray_v0_15-serde,_dev_linalg_0_16)
run: cargo test -p argmin-math --no-default-features --features "ndarray_v0_15-serde,_dev_linalg_0_16"
- name: argmin-math (ndarray_v0_14-serde,_dev_linalg_0_13)
run: cargo test -p argmin-math --no-default-features --features "ndarray_v0_14-serde,_dev_linalg_0_13"
- name: argmin-math (ndarray_v0_13-serde,_dev_linalg_0_12)
run: cargo test -p argmin-math --no-default-features --features "ndarray_v0_13-serde,_dev_linalg_0_12"
- name: argmin-math (ndarray_latest)
run: cargo test --manifest-path ./argmin-math-ndarray-linalg-tests/ndarray_latest/Cargo.toml --features serde
- name: argmin-math (ndarray_v0_15)
run: cargo test --manifest-path ./argmin-math-ndarray-linalg-tests/ndarray_0_15/Cargo.toml --features serde
- name: argmin-math (ndarray_v0_14)
run: cargo test --manifest-path ./argmin-math-ndarray-linalg-tests/ndarray_0_14/Cargo.toml --features serde
- name: argmin-math (ndarray_v0_13)
run: cargo test --manifest-path ./argmin-math-ndarray-linalg-tests/ndarray_0_13/Cargo.toml --features serde
# nalgebra without serde
- name: argmin-math (nalgebra_latest)
run: cargo test -p argmin-math --no-default-features --features "nalgebra_latest"
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ members = [

exclude = [
"media/book/tests",
"argmin-math-ndarray-linalg-tests",
]
3 changes: 3 additions & 0 deletions argmin-math-ndarray-linalg-tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This folder contains tests for the argmin-math crate.
Separate projects are needed to test against multiple versions of dependencies because of the required additivity of features even when they are not active and because only one crate can specify a `links` flag in a given dependency graph. This is mainly necessary for the backend dependency of ndarray-linalg.
Read more here: https://github.com/argmin-rs/argmin/issues/368#issue-1929115127
22 changes: 22 additions & 0 deletions argmin-math-ndarray-linalg-tests/ndarray_0_13/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[package]
name = "ndarray_0_13"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dev-dependencies]
argmin-math = { path = "../../argmin-math", version = "0.3", features = [
"ndarray_v0_13",
] }
ndarray = { version = "0.13", default-features = false }
ndarray-linalg = { version = "0.12", default-features = false, features = ["intel-mkl"] }
num-complex = { version = "0.2", default-features = false }
num-traits = { version = "0.2", default-features = false }
num-integer = { version = "0.1", default-features = false }
rand = { version = "0.8.3", default-features = false }
paste = "1"
approx = "0.5.0"

[features]
serde = ["argmin-math/ndarray_v0_13-serde"]
51 changes: 51 additions & 0 deletions argmin-math-ndarray-linalg-tests/ndarray_0_13/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
mod add {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/add.rs"));
}
mod conj {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/conj.rs"));
}
mod div {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/div.rs"));
}
mod dot {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/dot.rs"));
}
mod eye {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/eye.rs"));
}
mod inv {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/inv.rs"));
}
mod l1norm {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/l1norm.rs"));
}
mod l2norm {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/l2norm.rs"));
}
mod minmax {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/minmax.rs"));
}
mod mul {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/mul.rs"));
}
mod random {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/random.rs"));
}
mod scaledadd {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/scaledadd.rs"));
}
mod scaledsub {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/scaledsub.rs"));
}
mod signum {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/signum.rs"));
}
mod sub {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/sub.rs"));
}
mod transpose {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/transpose.rs"));
}
mod zero {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/zero.rs"));
}
24 changes: 24 additions & 0 deletions argmin-math-ndarray-linalg-tests/ndarray_0_14/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[package]
name = "ndarray_0_14"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dev-dependencies]
argmin-math = { path = "../../argmin-math", version = "0.3", default-features=false, features = [
"ndarray_v0_14",
] }
ndarray = { version = "0.14", default-features = false }
ndarray-linalg = { version = "0.13", features = ["intel-mkl"] }
num-complex = { version = "0.3", default-features = false, features = ["std"] }
num-traits = { version = "0.2" }
num-integer = { version = "0.1" }
rand = { version = "0.8.3" }
# Higher versions break intel-mkl-tool: https://github.com/rust-math/intel-mkl-src/issues/68#issue-1065394662
anyhow = { version = "<=1.0.48" }
paste = "1"
approx = "0.5.0"

[features]
serde = ["argmin-math/ndarray_v0_14-serde"]
51 changes: 51 additions & 0 deletions argmin-math-ndarray-linalg-tests/ndarray_0_14/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
mod add {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/add.rs"));
}
mod conj {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/conj.rs"));
}
mod div {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/div.rs"));
}
mod dot {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/dot.rs"));
}
mod eye {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/eye.rs"));
}
mod inv {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/inv.rs"));
}
mod l1norm {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/l1norm.rs"));
}
mod l2norm {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/l2norm.rs"));
}
mod minmax {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/minmax.rs"));
}
mod mul {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/mul.rs"));
}
mod random {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/random.rs"));
}
mod scaledadd {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/scaledadd.rs"));
}
mod scaledsub {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/scaledsub.rs"));
}
mod signum {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/signum.rs"));
}
mod sub {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/sub.rs"));
}
mod transpose {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/transpose.rs"));
}
mod zero {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/zero.rs"));
}
22 changes: 22 additions & 0 deletions argmin-math-ndarray-linalg-tests/ndarray_0_15/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[package]
name = "ndarray_0_15"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dev-dependencies]
argmin-math = { path = "../../argmin-math", version = "0.3", features = [
"ndarray_v0_15",
] }
ndarray = { version = "0.15", default-features = false }
ndarray-linalg = { version = "0.16", default-features = false, features = ["intel-mkl"] }
num-complex = { version = "0.4", default-features = false }
num-traits = { version = "0.2", default-features = false }
num-integer = { version = "0.1", default-features = false }
rand = { version = "0.8.3", default-features = false }
paste = "1"
approx = "0.5.0"

[features]
serde = ["argmin-math/ndarray_v0_15-serde"]
51 changes: 51 additions & 0 deletions argmin-math-ndarray-linalg-tests/ndarray_0_15/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
mod add {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/add.rs"));
}
mod conj {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/conj.rs"));
}
mod div {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/div.rs"));
}
mod dot {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/dot.rs"));
}
mod eye {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/eye.rs"));
}
mod inv {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/inv.rs"));
}
mod l1norm {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/l1norm.rs"));
}
mod l2norm {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/l2norm.rs"));
}
mod minmax {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/minmax.rs"));
}
mod mul {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/mul.rs"));
}
mod random {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/random.rs"));
}
mod scaledadd {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/scaledadd.rs"));
}
mod scaledsub {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/scaledsub.rs"));
}
mod signum {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/signum.rs"));
}
mod sub {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/sub.rs"));
}
mod transpose {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/transpose.rs"));
}
mod zero {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/zero.rs"));
}
22 changes: 22 additions & 0 deletions argmin-math-ndarray-linalg-tests/ndarray_latest/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[package]
name = "ndarray_latest"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dev-dependencies]
argmin-math = { path = "../../argmin-math", version = "0.3", features = [
"ndarray_latest",
] }
ndarray = { version = "0.15", default-features = false }
ndarray-linalg = { version = "0.16", default-features = false, features = ["intel-mkl"] }
num-complex = { version = "0.4", default-features = false }
num-traits = { version = "0.2", default-features = false }
num-integer = { version = "0.1", default-features = false }
rand = { version = "0.8.3", default-features = false }
paste = "1"
approx = "0.5.0"

[features]
serde = ["argmin-math/ndarray_latest-serde"]
51 changes: 51 additions & 0 deletions argmin-math-ndarray-linalg-tests/ndarray_latest/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
mod add {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/add.rs"));
}
mod conj {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/conj.rs"));
}
mod div {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/div.rs"));
}
mod dot {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/dot.rs"));
}
mod eye {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/eye.rs"));
}
mod inv {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/inv.rs"));
}
mod l1norm {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/l1norm.rs"));
}
mod l2norm {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/l2norm.rs"));
}
mod minmax {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/minmax.rs"));
}
mod mul {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/mul.rs"));
}
mod random {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/random.rs"));
}
mod scaledadd {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/scaledadd.rs"));
}
mod scaledsub {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/scaledsub.rs"));
}
mod signum {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/signum.rs"));
}
mod sub {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/sub.rs"));
}
mod transpose {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/transpose.rs"));
}
mod zero {
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/../src/zero.rs"));
}
Loading

0 comments on commit af2d302

Please sign in to comment.