Getting started

nalgebra relies on the official Rust package manager Cargo for dependency resolution and compilation. Therefore, making nalgebra ready to be used by your project is simply a matter of adding a new dependency to your Cargo.toml file.

[dependencies]
nalgebra = "*" # replace * by the latest version of the crate.

Until nalgebra reaches 1.0, it is strongly recommended to always use its latest version, though you might encounter breaking changes from time to time. Once your Cargo.toml file is set up, the corresponding crate must be imported by your project with the usual extern crate directive. We recommend using the na abbreviation for referencing the crate throughout your application.

extern crate nalgebra as na;

Cargo example#

Here is a complete example of Cargo.toml file:

[package]
name = "example-using-nalgebra"
version = "0.0.0"
authors = [ "You" ]
[dependencies]
nalgebra = "*" # replace * by the latest version of the crate.
[[bin]]
name = "example"
path = "./example.rs"

Usage and cargo features#

nalgebra is a monolithic crate with all its functionalities exported at its root. Data types, traits, and functions that do not take mutable inputs are directly accessible behind the nalgebra:: path (or na:: if you use the recommended alias). However, methods that perform in-place modifications (normalization, appending a translation in-place, etc.) are not accessible as free-functions. Instead, see the details of each data structure and the traits they implement.

Finally, many optional features can be enabled if needed:

Feature nameEffect
abomonation-serializeMakes it possible to serialize using abomonation
arbitraryMakes it possible the use of quickcheck by adding implementations of their Arbitrary trait.
ioFor parsing matrices from files using the matrix market format.
libmFor allowing the use of the libm crate to make features based on special math functions work on #[no-std] targets.
libm-forceFor forcing the use of the libm crate in order to make sure the implementations of all special math functions will be the same of all the platforms.
serde-serializeMakes it possible the use of serde by adding implementations of the Serialize and Deserialize traits.
sparseTo make the na::sparse module available for sparse matrix computations.