I get errors when I try to initialise a Nelder Mead struct from the argmin crate.
Here is my code:
use argmin::solver::neldermead::NelderMead;
fn example() {
let vec_of_parameters = vec![
vec![1.0],
vec![2.0],
];
let nm: NelderMead<Vec<f64>, f64> = NelderMead::new(vec_of_parameters);
}
This returns the followin errors:
the trait argmin_math::ArgminAdd<Vec<f64>, Vec<f64>> is not implemented for Vec<f64>
the trait argmin_math::ArgminSub<Vec<f64>, Vec<f64>> is not implemented for Vec<f64>
the trait argmin_math::ArgminMul<_, Vec<f64>> is not implemented for Vec<f64>
I am using argmin version 10.0.0 and ndarray version 0.16.1, and Rust 1.8.3 - thanks
It seems that argmin-math
makes supporting Vec
s an optional feature. This feature is enabled by default when you depend on argmin-math
(see its Cargo.toml
), but depending on just argmin
by itself doesn’t enable anything at all (because in argmin
's Cargo.toml
, it specifies default-features = false
).
So, if you add argmin-math
to your own Cargo.toml
,
[dependencies]
argmin = { version = "0.10" }
argmin-math = { version = "0.4" }
then that should add the missing implementations (because you've implicitly asked for argmin-math
's default features). Or if you want to be explicit that you need Vec
,
[dependencies]
argmin = { version = "0.10" }
argmin-math = { version = "0.4", features = ["vec"] }
The documentation vaguely alludes to this by saying
In order to use
argmin
, one needs to add bothargmin
andargmin-math
toCargo.toml
: … Via addingargmin-math
one can choose which math backend should be available.
but if you ask me, they could stand to be a little more explicit about how it won’t work if you don’t add both.