Generic programming
nalgebra allows several kind of generic programming, either through traits
of the simba crate, or by keeping the various type parameters of the
Matrix<T, R, C, S> structure and the likes. In the end, this allows for:
- Genericity wrt. scalars: the most common kind of abstraction.
This allows you to write code that will work on any scalar group like
i32and fields likef32orf64. - Dimensional genericity: allows you to write code that will work generically for 2D, 3D, and higher dimensions.
Genericity wrt. scalars#
This allows to write code that works with algebraic entities constructed on top
of a generic scalar type, e.g., floating-point numbers like f32 or f64 and
in some more restrictive cases integers like i32 or u64. This can be
achieved by keeping generic the first type parameter T of any structure of
nalgebra (including aliases). The mandatory trait bound of T is
na::Scalar which imposes some simple non-mathematical properties, i.e., T
must copyable, printable (using the {:?} format
string), and
comparable using the equality operator. Other commonly used trait bounds for
T are na::RealField or na::ComplexField from the
simba crate. This
enables operator overloading and useful mathematical functions for signed
integers and floating point numbers respectively. Note that the Scalar trait
bound does not have to be specified if Real already is.
note
This section about dimensional-genericity hasn't been written yet.