Into

Modules

Documentation

moduleMatrices and linear algebra

In Into, matrices are used to store many types of data, including matrices and vectors in plain mathematical sense, images, feature vectors, geometrical objects such as rectangles and circles etc.

The matrix library contains the basic matrix classes, matrix arithmetic routines, and linear algebra algorithms.

Lazy evaluation

The matrix library aims at a good balance between performance and usability. Although the library itself contains some hard-to-digest template code, the programmer seldom has the need to deal with the internals. The library uses template meta-programming techniques to optimize matrix evaluations at compile time. Consider the following example:

 PiiMatrix<double> A(3,3);
 A = A * 5 + 3; 

The textbook approach to make this work - which is still in use in many libraries - is to implement operator* and operator+ functions that take a matrix and a scalar as parameters and return a matrix. This is equivalent to the following:

 PiiMatrix<double> A(3,3);
 PiiMatrix<double> tmp1 = A * 5;
 PiiMatrix<double> tmp2 = tmp1 + 3;
 A = tmp2;

In Into, no temporary matrices need to be created. Instead, the operator functions return matrix concepts that are evaluated only when needed. The following pseudocode shows how this is done:

 A * 5 -> MatrixConcept<multiplies, Matrix>
 MatrixConcept<multiplies, Matrix> + 3 -> MatrixConcept<add, MatrixConcept<multiplies, Matrix>>
 A = MatrixConcept<add, MatrixConcept<multiplies, Matrix>> -> Matrix

The arithmetic operations never actually evaluate the expression but return a conceptual matrix that performs the evaluation if requested to do so. In this example, the assignment at the end does. This kind of lazy evaluation is used not only by arithmetic operators but also with algorithms such as Pii::transpose() and many functions that work with matrices. The following code doesn't create a single temporary object:

 PiiMatrix<int> A(5,5);
 A += pow(abs(A) - 3, 2) + transpose(A);

Sub-matrices

One of the most important implementations of the matrix concept is PiiSubmatrix, a matrix that references a sub-matrix inside another matrix. Sub-matrices make it possible to avoid unnecessary copies, and they are extensively used in Into from low-level algoritms to high-level operations such as PiiImageSplitter.

Linear algebra

The matrix library contains independent, pure C++ implementations of many standard linear algebra algoritms. The main design principles for the algorithms have been numerical stability and code maintainability (which also means readability). The algoritms try to make optimal usage of CPU cache (cache-oblivious algorithms), which makes them also relatively fast. Many algoritms are modeled after their LAPACK and Alglib counterparts, although they have been completely rewritten.

The most important functions of the linear algebra libary are

Namespaces

namespace

This namespace contains general-purpose functions, type definitions, and data structures that are independent of other modules and plug-ins.

Other classes

class

A matrix that models the matrix concept by using a binary function that operates on two other matrices.

class

A superclass for classes that implement the matrix concept.

class

A model of the matrix concept that accesses selected elements of another matrix.

class

A two-dimensional array that models the matrix concept.

struct

A structure that stores a value and its location in a matrix.

class

Represents a rotation parallel to a plane spanned by two coordinates axes.

class

A matrix that provides a mutable reference to a PiiMatrix.

class

Transposed matrix.

class

A two-dimensional dynamic array of non-typed data.

class

A matrix that models the matrix concept by applying a unary function to another matrix.

Notes (0)

Add a note

Not a single note added yet. Be the first, add yours.