Crate argmin_math

source ·
Expand description

argmin-math provides mathematics related abstractions needed in argmin. It supports implementations of these abstractions for basic Vecs and for ndarray and nalgebra. The traits can of course also be implemented for your own types to make them compatible with argmin.

For an introduction on how to use argmin, please also have a look at the book.


Add the following line to your dependencies list:

argmin-math = "0.3.0"

This will activate the primitives and vec features. For other backends see the section below.


Support for the various backends can be switched on via features. Please read this section carefully to the end before choosing a backend.

Default features

primitivesyesbasic integer and floating point types
vecyesVecs (basic functionality)


ndarray_latestnolatest supported version
ndarray_latest-nolinalgnolatest supported version without ndarray-linalg
ndarray_latest-serdenolatest supported version + serde support
ndarray_latest-nolinalg-serdenolatest supported version without ndarray-linalg + serde support
ndarray_v0_15noversion 0.15 with ndarray-linalg 0.16
ndarray_v0_15-nolinalgnoversion 0.15 without ndarray-linalg
ndarray_v0_15-serdenoversion 0.15 with ndarray-linalg 0.16 + serde support
ndarray_v0_15-nolinalg-serdenoversion 0.15 without ndarray-linalg + serde support
ndarray_v0_14noversion 0.14 with ndarray-linalg 0.13
ndarray_v0_14-nolinalgnoversion 0.14 without ndarray-linalg
ndarray_v0_14-serdenoversion 0.14 with ndarray-linalg 0.13 + serde support
ndarray_v0_14-nolinalg-serdenoversion 0.14 without ndarray-linalg + serde support
ndarray_v0_13noversion 0.13 with ndarray-linalg 0.12
ndarray_v0_13-nolinalgnoversion 0.13 without ndarray-linalg
ndarray_v0_13-serdenoversion 0.13 with ndarray-linalg 0.12 + serde support
ndarray_v0_13-nolinalg-serdenoversion 0.13 without ndarray-linalg + serde support

Note that the *-nolinalg* features do NOT pull in ndarray-linalg as a dependency. This avoids linking against a BLAS library. This will however disable the implementation of ArgminInv, meaning that any solver which requires the matrix inverse will not work with the ndarray backend. It is recommended to use the *-nolinalg* options if the matrix inverse is not needed in order to keep the compilation times low and avoid problems when linking against a BLAS library.

Using the ndarray_* features with ndarray-linalg support may require to explicitly choose the ndarray-linalg BLAS backend in your Cargo.toml (see the ndarray-linalg documentation for details):

ndarray-linalg = { version = "<appropriate_version>", features = ["<linalg_backend>"] }


nalgebra_latestnolatest supported version
nalgebra_latest-serdenolatest supported version + serde support
nalgebra_v0_32noversion 0.32
nalgebra_v0_32-serdenoversion 0.32 + serde support
nalgebra_v0_31noversion 0.31
nalgebra_v0_31-serdenoversion 0.31 + serde support
nalgebra_v0_30noversion 0.30
nalgebra_v0_30-serdenoversion 0.30 + serde support
nalgebra_v0_29noversion 0.29
nalgebra_v0_29-serdenoversion 0.29 + serde support

Choosing a backend

It is not possible to activate two versions of the same backend.

The features labeled *latest* are an alias for the most recent supported version of the respective backend. It is however recommended to explicitly specify the desired version instead of using any of the *latest* features (see section about semantic versioning below).

Note that argmin by default compiles with serde support. Therefore, unless serde is deliberately turned off in argmin, it is necessary to activate the serde support in argmin-math as well.

The default features primitives and vec can be turned off in order to only compile the trait definitions. If another backend is chosen, primitives will automatically be turned on again.


Activate support for the latest supported ndarray version:

argmin-math = { version = "0.3.0", features = ["ndarray_latest-serde"] }

Semantic versioning

This crate follows semantic versioning. Adding a new backend or a new version of a backend is not considered a breaking change. However, your code may still break if you use any of the features containing *latest*. It is therefore recommended to specify the actual version of the backend you are using.


For development and running the tests a backend for ndarray-linalg must be chosen. Normally one would add those as dev dependencies (the features would then be unified with the regular dependencies). However, linking somehow fails when the non-dev ndarra-linalg dependency is missing (which is the case for the *-nolinalg* features of the ndarray backend). To fix that, the _dev_linalg_* features were introduced. When testing and developing with one of the ndarray features with linalg support on, the appropriate _dev_linalg_* feature must be turned on as well. Note that the version number in _dev_linalg_* is always one below the ndarray version. For instance, for ndarray 0.15, one would use the _dev_linalg_0_14 feature.

Development FeatureComment
_dev_linalg_latestlatest ndarray-linalg for latest ndarray
_dev_linalg_0_16ndarray-linalg v0.16 for ndarray v0.15
_dev_linalg_0_13ndarray-linalg v0.13 for ndarray v0.14
_dev_linalg_0_12ndarray-linalg v0.12 for ndarray v0.13


You found a bug? Your favorite backend is not supported? Feel free to open an issue or ideally submit a PR.


Licensed under either of

at your option.


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


Add a T to self
Return the conjugate
(Pointwise) Divide a T by self
Dot/scalar product of T and self
Identity matrix
Compute the inverse (T) of self
Compute the l1-norm (U) of self
Compute the l2-norm (U) of self
Minimum and Maximum of type T
(Pointwise) Multiply a T with self
Create a random number
Add a T scaled by an U to self
Subtract a T scaled by an U from self
Returns a number that represents the sign of self.
Subtract a T from self
Return the transpose (U) of self
Dot/scalar product of T and self weighted by W (p^TWv)
Return param vector of all zeros (for now, this is a hack. It should be done better)
Zero for dynamically sized objects