This page documents the core linear algebra tools included in dlib.
In particular, the three most important objects in this part of the library are the
matrix, vector, and
rectangle. All the other tools on this page
are functions for manipulating these three objects. A good example and introduction
can be found in
the matrix example program.
Most of the linear algebra tools deal with dense matrices. However, there is also
a limited amount of support for working with sparse matrices and vectors.
In particular, the dlib tools represent sparse vectors using the containers
in the C++ STL. For details, see the notes at the top of
dlib/svm/sparse_vector_abstract.h.
Finally, note that all the dense matrix tools can be obtained by #including <dlib/matrix.h>
while the sparse vector tools can be obtained by #including <dlib/sparse_vector.h>. The
geometry tools can be used by #including <dlib/geometry.h>.
sparse_to_densedlib/sparse_vector.hdlib/svm/sparse_vector_abstract.h
This is a set of simple functions that take
sparse vectors
and converts them into equivalent dense vectors.
matdlib/matrix.hdlib/matrix/matrix_mat_abstract.h
This is a set of simple functions that take objects like std::vector or
array2d and convert them into
matrix objects. Note that the conversion is
done using template expressions so there is no runtime cost associated
with calling mat().
matrixdlib/matrix.hdlib/matrix/matrix_abstract.h
This is a 2D matrix object that enables you to write code that deals with
matrices using a simple syntax similar to what can be written in MATLAB. It is implemented using
the expression templates technique which allows it to eliminate the
temporary matrix objects that would normally be returned from expressions
such as M = A+B+C+D; Normally each invocation of the + operator would
construct and return a temporary matrix object but using this technique
we can avoid creating all these temporary objects and receive a large speed boost.
This object is also capable of using BLAS and LAPACK libraries such as ATLAS or the Intel
MKL when available. To enable BLAS support all you have to do is #define
DLIB_USE_BLAS and then make sure you link your application with your
BLAS library. Similarly, to enable LAPACK support just #define DLIB_USE_LAPACK and
link to your LAPACK library. Finally, the use of BLAS and LAPACK is transparent to
the user, that is, the dlib matrix object uses BLAS and LAPACK internally to optimize
various operations while still allowing the user to use a simple MATLAB like syntax.
Note that the cmake files that come with dlib will automatically link with ATLAS or the Intel
MKL if they are installed. So using cmake makes this easy, but by no means are you required
to use cmake or the dlib cmake files.
It is also worth noting that all the preconditions of every function
related to the matrix object are checked by DLIB_ASSERT
statements and thus can be enabled by #defining ENABLE_ASSERTS or DEBUG. Doing
this will cause your program to run slower but should catch any usage errors.
matrix_ex.cpp.htmlmatrix_expressions_ex.cpp.htmlmatrix_utilitiesdlib/matrix/matrix_utilities_abstract.h
This extension contains miscellaneous utility functions
for manipulating matrix objects.
matrix_ladlib/matrix/matrix_la_abstract.h
This extension contains linear algebra functions to calculate
QR, LU, Cholesky, eigenvalue, and singular value decompositions. It also
contains a few other miscellaneous functions that solve systems of
equations or calculate values derived from the above decompositions.
matrix_math_functionsdlib/matrix/matrix_math_functions_abstract.hThis extension contains mathematical functions that operate on each
element of a matrix independently.
matrix_sub_expressionsdlib/matrix/matrix_subexp_abstract.h
This extension contains a number of functions for dealing with sub-matrices.
border_enumeratordlib/geometry.hdlib/geometry/border_enumerator_abstract.h
This object is an enumerator
over the border points of a
rectangle.
nearest_pointdlib/geometry.hdlib/geometry/rectangle_abstract.h
This function takes a rectangle and a
point and returns the point in the given
rectangle that is nearest to the given point.
distance_to_rect_edgedlib/geometry.hdlib/geometry/rectangle_abstract.h
This function takes a rectangle and a
point and returns the Manhattan distance between
the rectangle's edge and the point.
move_rectdlib/geometry.hdlib/geometry/rectangle_abstract.h
This function takes a rectangle and moves
it so that it's upper left corner occupies the given location.
resize_rect_heightdlib/geometry.hdlib/geometry/rectangle_abstract.h
This function takes a rectangle and
returns a new rectangle with the given height but otherwise with the
same edge points as the original rectangle.
resize_rect_widthdlib/geometry.hdlib/geometry/rectangle_abstract.h
This function takes a rectangle and
returns a new rectangle with the given width but otherwise with the
same edge points as the original rectangle.
resize_rectdlib/geometry.hdlib/geometry/rectangle_abstract.h
This function takes a rectangle and
returns a new rectangle with the given size but with the same upper
left corner as the original rectangle.
translate_rectdlib/geometry.hdlib/geometry/rectangle_abstract.h
This function takes a rectangle and moves
it by a given number of units along the x and y axis relative to
where it was before the move.
centerdlib/geometry.hdlib/geometry/rectangle_abstract.h
Returns the center point of a rectangle.
dcenterdlib/geometry.hdlib/geometry/rectangle_abstract.h
Returns the center point of a rectangle. This
is a version of center() which returns a double version
of the point rather than one which uses integers to represent the
result. Therefore, it is slightly more accurate.
centered_rectdlib/geometry.hdlib/geometry/rectangle_abstract.h
There are various overloads of this function but the basic idea is
that it returns a rectangle with a given
width and height and centered about a given point.
shrink_rectdlib/geometry.hdlib/geometry/rectangle_abstract.h
This function takes a rectangle object,
shrinks its borders by a given amount, and returns the result.
grow_rectdlib/geometry.hdlib/geometry/rectangle_abstract.h
This function takes a rectangle object,
grows its borders by a given amount, and returns the result.
rotate_pointdlib/geometry.hdlib/geometry/point_transforms_abstract.h
This is a function that rotates a 2D vector or
point object about a given point.
point_rotatordlib/geometry.hdlib/geometry/point_transforms_abstract.h
This is an object that rotates a 2D vector or
point object about the origin.
point_transformdlib/geometry.hdlib/geometry/point_transforms_abstract.h
This is an object that rotates a 2D vector or
point object about the origin and then adds a
displacement vector.
point_transform_affinedlib/geometry.hdlib/geometry/point_transforms_abstract.h
This is an object that applies an affine transformation to a vector or
point. Note that you can use find_affine_transform
to easily create affine transforms from sets of point correspondences.
find_affine_transformdlib/geometry.hdlib/geometry/point_transforms_abstract.h
This is a routine that takes in two sets of points and finds the
best affine transformation
that maps between them.
point_transform_projectivedlib/geometry.hdlib/geometry/point_transforms_abstract.h
This is an object that applies a projective transformation to a vector or
point. Note that you can use find_projective_transform
to easily create projective transforms from sets of point correspondences.
find_projective_transformdlib/geometry.hdlib/geometry/point_transforms_abstract.h
This is a routine that takes in two sets of points and finds the
best projective transformation
that maps between them.
rotation_matrixdlib/geometry.hdlib/geometry/point_transforms_abstract.h
This is a method for creating 2D rotation matrices.
get_rectdlib/geometry.hdlib/geometry/rectangle_abstract.h
This is a simple template function that returns a rectangle
representing the size of a 2D container (e.g. matrix or
array2d).
rectangledlib/geometry.hdlib/geometry/rectangle_abstract.h
This object represents a rectangular region inside a Cartesian
coordinate system. It allows you to easily represent and manipulate
rectangles.
vectordlib/geometry.hdlib/geometry/vector_abstract.h
This object represents a two or three dimensional vector.
If you
want to work with general N-dimensional column vectors then you
should the matrix object. In particular, you
should usually use a matrix with this type:
dlib::matrix<double,0,1>.
pointdlib/geometry.hdlib/geometry/vector_abstract.h
This object represents a point inside a Cartesian coordinate system.
Note that a point is simply a typedef for a vector
that is 2D and uses longs to represent coordinate values.