Basic Linear and Multilinear Algebra Library
uBLAS is a C++ template class library that provides BLAS level 1, 2, 3 functionality for dense, packed and sparse matrices. The design and implementation unify mathematical notation via operator overloading and efficient code generation via expression templates. Since 2018, uBLAS also supports basic operations for multilinear algebra operations such as the outer and inner product of higher-order tensors. The goal of the new tensor extension is to provide basic operations that simplify the implementation of e.g. machine learning and quantum computing algorithms.
Functionality
uBLAS provides templated C++ classes for dense, unit and sparse vectors, dense, identity, triangular, banded, symmetric, hermitian and sparse matrices. Views into vectors and matrices can be constructed via ranges, slices, adaptor classes and indirect arrays. The library covers the usual basic linear and multilinear algebra operations on vectors, matrices and tensors: reductions like different norms, addition and subtraction of vectors and matrices and multiplication with a scalar, inner and outer products of vectors, matrix vector and matrix matrix products and triangular solver. Similar operations are also provided for the tensor type. The glue between containers, views and expression templated operations is a mostly STL conforming iterator interface.
Known limitations
-
The implementation assumes a linear memory address model.
-
Tuning was focussed on dense matrices.
Further Information
Authors and Credits
uBLAS initially was written by Joerg Walter and Mathias Koch. We would like thank all contributors who has supported this library. Amongst many contributors around the world, David Abrahams, Ed Brey, Fernando Cacciola, Juan Jose Gomez Cadenas, Beman Dawes, Matt Davies, Bob Fletcher, Kresimir Fresl, Joachim Kessel, Patrick Kowalzick, Toon Knapen, Hendrik Kueck, John Maddock, Jens Maurer, Alexei Novakov, Gary Powell, Joachim Pyras, Peter Schmitteckert, Jeremy Siek, Markus Steffl, Michael Stevens, Benedikt Weber, Martin Weiser, Gunter Winkler, Marc Zimmermann, Marco Guazzone, Nasos Iliopoulus and the members of Boost had a great impact and contribution helping the library to grow and mature.
Starting with the GSoC 2018 project, uBlas has been extended by a flexible tensor data type and basic tensor operations supporting general tensor contractions and the Einstein notation. The goal of the new tensor extension is to support the implementation of algorithms for e.g. machine learning and quantum computing applications. The initial implementation of this extension is written by Cem Bassoy. Contributors of the uBLAS extension are Amit Singh, Ashar Khan, Stefan Seefeld, Cem Bassoy and the members of Boost.
This library is currently maintained by David Bellot, Cem Bassoy and Stefan Seefeld.
Frequently Asked Questions
Q: Should I use uBLAS for new projects?
A: At the time of writing (09/2012) there are a lot of good matrix
libraries available, e.g., MTL4,
armadillo,
eigen. uBLAS offers a stable, well tested
set of vector and matrix classes, the typical operations for linear
algebra and solvers for triangular systems of equations. uBLAS offers
dense, structured and sparse matrices - all using similar interfaces.
And finally uBLAS offers good (but not outstanding) performance. On the
other side, the last major improvement of uBLAS was in 2008 and no
significant change was committed since 2009. So one should ask himself
some questions to aid the decision: Availability? uBLAS is part of
boost and thus available in many environments. Easy to use? uBLAS is
easy to use for simple things, but needs decent C knowledge when you
leave the path. _Performance?_ There are faster alternatives. _Cutting
edge?_ uBLAS is more than 10 years old and missed all new stuff from
C11.
Q: I’m running the uBLAS dense vector and matrix benchmarks. Why do I
see a significant performance difference between the native C and
library implementations?
A: uBLAS distinguishes debug mode (size and type conformance checks
enabled, expression templates disabled) and release mode (size and type
conformance checks disabled, expression templates enabled). Please
check, if the preprocessor symbol NDEBUG
of cassert
is defined.
NDEBUG
enables release mode, which in turn uses expression templates.
You can optionally define BOOST_UBLAS_NDEBUG
to disable all bounds,
structure and similar checks of uBLAS.
Q: I’ve written some uBLAS tests, which try to incorrectly assign
different matrix types or overrun vector and matrix dimensions. Why
don’t I get a compile time or runtime diagnostic?
A: uBLAS distinguishes debug mode (size and type conformance checks
enabled, expression templates disabled) and release mode (size and type
conformance checks disabled, expression templates enabled). Please
check, if the preprocessor symbol NDEBUG
of cassert
is defined.
NDEBUG
disables debug mode, which is needed to get size and type
conformance checks.
Q: I’ve written some uBLAS benchmarks to measure the performance of
matrix chain multiplications like prod (A, prod (B, C))
and see a
significant performance penalty due to the use of expression templates.
How can I disable expression templates?
A: You do not need to disable expression templates. Please try
reintroducing temporaries using either prod (A,
matrix_type
(prod (B, C)))
or prod (A, prod<``matrix_type
> (B, C))
.
Overview
Rationale
It would be nice if every kind of numeric software could be written in C without loss of efficiency, but unless something can be found that achieves this without compromising the C type system it may be preferable to rely on Fortran, assembler or architecture-specific extensions (Bjarne Stroustrup).
This C++ library is directed towards scientific computing on the level of basic linear algebra constructions with matrices and vectors and their corresponding abstract operations. The primary design goals were:
-
mathematical notation
-
efficiency
-
functionality
-
compatibility
Another intention was to evaluate, if the abstraction penalty resulting from the use of such matrix and vector classes is acceptable.
Resources
The development of this library was guided by a couple of similar efforts:
BLAS seems to be the most widely used library for basic linear algebra constructions, so it could be called a de-facto standard. Its interface is procedural, the individual functions are somewhat abstracted from simple linear algebra operations. Due to the fact that is has been implemented using Fortran and its optimizations, it also seems to be one of the fastest libraries available. As we decided to design and implement our library in an object-oriented way, the technical approaches are distinct. However anyone should be able to express BLAS abstractions in terms of our library operators and to compare the efficiency of the implementations.
Blitz is an impressive library implemented in C. Its main design seems to be oriented towards multidimensional arrays and their associated operators including tensors. The author of Blitz states, that the library achieves performance on par or better than corresponding Fortran code due to his implementation technique using expression templates and template metaprograms. However we see some reasons, to develop an own design and implementation approach. We do not know whether anybody tries to implement traditional linear algebra and other numerical algorithms using Blitz. We also presume that even today Blitz needs the most advanced C compiler technology due to its implementation idioms. On the other hand, Blitz++ convinced us, that the use of expression templates is mandatory to reduce the abstraction penalty to an acceptable limit.
POOMA’s design goals seem to parallel Blitz's in many parts . It extends Blitz's concepts with classes from the domains of partial differential equations and theoretical physics. The implementation supports even parallel architectures.
MTL is another approach supporting basic linear algebra operations in C. Its design mainly seems to be influenced by BLAS and the C Standard Template Library. We share the insight that a linear algebra library has to provide functionality comparable to BLAS. On the other hand we think, that the concepts of the C++ standard library have not yet been proven to support numerical computations as needed. As another difference MTL currently does not seem to use expression templates. This may result in one of two consequences: a possible loss of expressiveness or a possible loss of performance.
Concepts
Mathematical Notation
The usage of mathematical notation may ease the development of scientific algorithms. So a C library implementing basic linear algebra concepts carefully should overload selected C operators on matrix and vector classes.
We decided to use operator overloading for the following primitives:
Description | Operator |
---|---|
Indexing of vectors and matrices |
|
Assignment of vectors and matrices |
|
Unary operations on vectors and matrices |
|
Binary operations on vectors and matrices |
|
Multiplication of vectors and matrices with a scalar |
|
We decided to use no operator overloading for the following other primitives:
Description | Function |
---|---|
Left multiplication of vectors with a matrix |
|
Right multiplication of vectors with a matrix |
|
Multiplication of matrices |
|
Inner product of vectors |
|
Outer product of vectors |
|
Transpose of a matrix |
|
Efficiency
To achieve the goal of efficiency for numerical computing, one has to overcome two difficulties in formulating abstractions with C++, namely temporaries and virtual function calls. Expression templates solve these problems, but tend to slow down compilation times.
Eliminating Temporaries
Abstract formulas on vectors and matrices normally compose a couple of unary and binary operations. The conventional way of evaluating such a formula is first to evaluate every leaf operation of a composition into a temporary and next to evaluate the composite resulting in another temporary. This method is expensive in terms of time especially for small and space especially for large vectors and matrices. The approach to solve this problem is to use lazy evaluation as known from modern functional programming languages. The principle of this approach is to evaluate a complex expression element wise and to assign it directly to the target.
Two interesting and dangerous facts result:
Aliases
One may get serious side effects using element wise evaluation on vectors or matrices. Consider the matrix vector product x = A x. Evaluation of A1x and assignment to x1 changes the right hand side, so that the evaluation of A2x returns a wrong result. In this case there are aliases of the elements xn on both the left and right hand side of the assignment.
Our solution for this problem is to evaluate the right hand side of an
assignment into a temporary and then to assign this temporary to the
left hand side. To allow further optimizations, we provide a
corresponding member function for every assignment operator and also a
noalias
syntax. By using this
syntax a programmer can confirm, that the left and right hand sides of
an assignment are independent, so that element wise evaluation and
direct assignment to the target is safe.
Complexity
The computational complexity may be unexpectedly large under certain cirumstances. Consider the chained matrix vector product A (B x). Conventional evaluation of A (B x) is quadratic. Deferred evaluation of B xi is linear. As every element B xi is needed linearly depending of the size, a completely deferred evaluation of the chained matrix vector product A (B x) is cubic. In such cases one needs to reintroduce temporaries in the expression.
Eliminating Virtual Function Calls
Lazy expression evaluation normally leads to the definition of a class hierarchy of terms. This results in the usage of dynamic polymorphism to access single elements of vectors and matrices, which is also known to be expensive in terms of time. A solution was found a couple of years ago independently by David Vandervoorde and Todd Veldhuizen and is commonly called expression templates. Expression templates contain lazy evaluation and replace dynamic polymorphism with static, i.e. compile time polymorphism. Expression templates heavily depend on the famous Barton-Nackman trick, also coined 'curiously defined recursive templates' by Jim Coplien.
Expression templates form the base of our implementation.
Compilation times
It is also a well known fact, that expression templates challenge currently available compilers. We were able to significantly reduce the amount of needed expression templates using the Barton-Nackman trick consequently.
We also decided to support a dual conventional implementation (i.e. not
using expression templates) with extensive bounds and type checking of
vector and matrix operations to support the development cycle. Switching
from debug mode to release mode is controlled by the NDEBUG
preprocessor symbol of <cassert>
.
Functionality
Every C++ library supporting linear algebra will be measured against the long-standing Fortran package BLAS. We now describe how BLAS calls may be mapped onto our classes.
The page Overview of Matrix and Vector Operations gives a short summary of the most used operations on vectors and matrices.
Blas Level 1
BLAS Call | Mapped Library Expression | Mathematical Description | Comment |
---|---|---|---|
|
|
|
Computes the l1 (sum) norm of a real vector. |
|
|
|
Computes the sum of elements of a complex vector. |
|
|
|
Computes the l2 (euclidean) norm of a vector. |
|
|
|
Computes the linf (maximum) norm of a vector. |
|
|
xT y or |
Computes the inner product of two vectors. |
|
|
a + xT y |
Computes the inner product in double precision. |
|
|
x ← y |
Copies one vector to
another. |
|
|
x ←→ y |
Swaps two vectors. |
|
|
x ← a x |
Scales a vector. |
|
|
y ← a x + y |
Adds a scaled vector. |
|
|
(x, y) ← (a x + b y, -b x + a y) |
Applies a plane rotation. |
|
|
(a, b) ← |
Constructs a plane rotation. |
Blas Level 2
BLAS Call | Mapped Library Expression | Mathematical Description | Comment |
---|---|---|---|
|
|
x ← A x or + x ← AT x or + x ← AH x |
Computes the product of a matrix with a vector. |
|
|
y ← A-1 x or |
Solves a system of linear equations with triangular form, i.e. A is triangular. |
|
|
y ← a A x + b y or |
Adds the scaled product of a matrix with a vector. |
|
|
A ← a x yT + A or |
Performs a rank 1 update. |
|
|
A ← a x xT + A or |
Performs a symmetric or hermitian rank 1 update. |
|
|
A ← a x yT + a y xT + A or |
Performs a symmetric or hermitian rank 2 update. |
Blas Level 3
BLAS Call | Mapped Library Expression | Mathematical Description | Comment |
---|---|---|---|
|
|
B ← a op (A) op (B) with |
Computes the scaled product of two matrices. |
|
|
C ← A-1 B or |
Solves a system of linear equations with triangular form, i.e. A is triangular. |
|
|
C ← a op (A) op (B) + b
C with |
Adds the scaled product of two matrices. |
|
|
B ← a A AT + b B or |
Performs a symmetric or hermitian rank k update. |
|
|
C ← a A BT + a B AT + b C or |
Performs a symmetric or hermitian rank 2 k update. |
Storage Layout
uBLAS supports many different storage layouts. The full details can be
found at the Overview of Types. Most types
like vector<double>
and matrix<double>
are by default compatible to
C arrays, but can also be configured to contain FORTAN compatible data.
Compatibility
For compatibility reasons we provide array like indexing for vectors and matrices. For some types (hermitian, sparse etc) this can be expensive for matrices due to the needed temporary proxy objects.
uBLAS uses STL compatible allocators for the allocation of the storage required for it’s containers.
Benchmark Results
The following tables contain results of one of our benchmarks. This
benchmark compares a native C implementation ('C array') and some
library based implementations. The safe variants based on the library
assume aliasing, the fast variants do not use temporaries and are
functionally equivalent to the native C implementation. Besides the
generic vector and matrix classes the benchmark utilizes special classes
c_vector
and c_matrix
, which are intended to avoid every overhead
through genericity.
The benchmark program bench1 was compiled with GCC 4.0 and run on an Athlon 64 3000+. Times are scales for reasonable precision by running bench1 100.
First we comment the results for double vectors and matrices of dimension 3 and 3 x 3, respectively.
Comment | ||||
---|---|---|---|---|
inner_prod |
C array |
0.61 |
782 |
Some abstraction penalty |
c_vector |
0.86 |
554 |
||
vector<unbounded_array> |
1.02 |
467 |
||
vector + vector |
C array |
0.51 |
1122 |
Abstraction penalty: factor 2 |
c_vector fast |
1.17 |
489 |
||
vector<unbounded_array> fast |
1.32 |
433 |
||
c_vector safe |
2.02 |
283 |
||
vector<unbounded_array> safe |
6.95 |
82 |
||
outer_prod |
C array |
0.59 |
872 |
Some abstraction penalty |
c_matrix, c_vector fast |
0.88 |
585 |
||
matrix<unbounded_array>, vector<unbounded_array> fast |
0.90 |
572 |
||
c_matrix, c_vector safe |
1.66 |
310 |
||
matrix<unbounded_array>, vector<unbounded_array> safe |
2.95 |
175 |
||
prod (matrix, vector) |
C array |
0.64 |
671 |
No significant abstraction penalty |
c_matrix, c_vector fast |
0.70 |
613 |
||
matrix<unbounded_array>, vector<unbounded_array> fast |
0.79 |
543 |
||
c_matrix, c_vector safe |
0.95 |
452 |
||
matrix<unbounded_array>, vector<unbounded_array> safe |
2.61 |
164 |
||
matrix + matrix |
C array |
0.75 |
686 |
No significant abstraction penalty |
c_matrix fast |
0.99 |
520 |
||
matrix<unbounded_array> fast |
1.29 |
399 |
||
c_matrix safe |
1.7 |
303 |
||
matrix<unbounded_array> safe |
3.14 |
164 |
||
prod (matrix, matrix) |
C array |
0.94 |
457 |
No significant abstraction penalty |
c_matrix fast |
1.17 |
367 |
||
matrix<unbounded_array> fast |
1.34 |
320 |
||
c_matrix safe |
1.56 |
275 |
||
matrix<unbounded_array> safe |
2.06 |
208 |
We notice a two fold performance loss for small vectors and matrices: first the general abstraction penalty for using classes, and then a small loss when using the generic vector and matrix classes. The difference w.r.t. alias assumptions is also significant.
Next we comment the results for double vectors and matrices of dimension 100 and 100 x 100, respectively.
Operation | Implementation | Elapsed [s] | MFLOP/s | Comment |
---|---|---|---|---|
inner_prod |
C array |
0.64 |
889 |
No significant abstraction penalty |
c_vector |
0.66 |
862 |
||
vector<unbounded_array> |
0.66 |
862 |
||
vector + vector |
C array |
0.64 |
894 |
No significant abstraction penalty |
c_vector fast |
0.66 |
867 |
||
vector<unbounded_array> fast |
0.66 |
867 |
||
c_vector safe |
1.14 |
501 |
||
vector<unbounded_array> safe |
1.23 |
465 |
||
outer_prod |
C array |
0.50 |
1144 |
No significant abstraction penalty |
c_matrix, c_vector fast |
0.71 |
806 |
||
matrix<unbounded_array>, vector<unbounded_array> fast |
0.57 |
1004 |
||
c_matrix, c_vector safe |
1.91 |
300 |
||
matrix<unbounded_array>, vector<unbounded_array> safe |
0.89 |
643 |
||
prod (matrix, vector) |
C array |
0.65 |
876 |
No significant abstraction penalty |
c_matrix, c_vector fast |
0.65 |
876 |
||
matrix<unbounded_array>, vector<unbounded_array> fast |
0.66 |
863 |
||
c_matrix, c_vector safe |
0.66 |
863 |
||
matrix<unbounded_array>, vector<unbounded_array> safe |
0.66 |
863 |
||
matrix + matrix |
C array |
0.96 |
596 |
No significant abstraction penalty |
c_matrix fast |
1.21 |
473 |
||
matrix<unbounded_array> fast |
1.00 |
572 |
||
c_matrix safe |
2.44 |
235 |
||
matrix<unbounded_array> safe |
1.30 |
440 |
||
prod (matrix, matrix) |
C array |
0.70 |
813 |
No significant abstraction penalty |
c_matrix fast |
0.73 |
780 |
||
matrix<unbounded_array> fast |
0.76 |
749 |
||
c_matrix safe |
0.75 |
759 |
||
matrix<unbounded_array> safe |
0.76 |
749 |
For larger vectors and matrices the general abstraction penalty for using classes seems to decrease, the small loss when using generic vector and matrix classes seems to remain. The difference w.r.t. alias assumptions remains visible, too.
Vector
Vector Abstract
Description
The templated class vector<T, A>
is the base container adaptor for
dense vectors. For a n-dimensional vector and 0 < = i < n every
element vi is mapped to the i-th element of the container.
Example
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/io.hpp>
int main () {
using namespace boost::numeric::ublas;
vector<double> v (3);
for (unsigned i = 0; i < v.size (); ++ i)
v (i) = i;
std::cout << v << std::endl;
}
Definition
Defined in the header vector.hpp.
Template parameters
Parameter | Description | Default |
---|---|---|
|
The type of object stored in the vector. |
|
|
|
Model of
Type requirements
None, except for those imposed by the requirements of Vector and RandomAccessContainer.
Public base classes
vector_container<vector<T, A> >
Members
Member | Where defined | Description |
---|---|---|
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
Allocates an uninitialized |
|
|
Allocates an uninitialized |
|
|
The copy constructor. |
|
|
The extended copy constructor. |
|
|
Reallocates a |
|
|
Returns the size of the |
|
|
Returns the upper bound on the size of the |
|
|
Equivilent to |
|
|
||
|
||
|
Returns a |
|
|
Returns a reference of the |
|
|
Returns a |
|
|
Returns a reference of the
|
|
|
The assignment operator. |
|
|
Assigns a temporary. May change the vector |
|
|
The extended assignment operator. |
|
|
Assigns a vector expression to the vector. Left and right hand side of the assignment should be independent. |
|
|
A computed assignment operator. Adds the vector expression to the vector. |
|
|
Adds a vector expression to the vector. Left and right hand side of the assignment should be independent. |
|
|
A computed assignment operator. Subtracts the vector expression from the vector. |
|
|
Subtracts a vector expression from the vector. Left and right hand side of the assignment should be independent. |
|
|
A computed assignment operator. Multiplies the vector with a scalar. |
|
|
A computed assignment operator. Divides the vector through a scalar. |
|
|
Swaps the contents of the vectors. |
|
|
Inserts the value |
|
|
Erases the value at the
|
|
|
Clears the vector. |
|
|
Returns a |
|
|
Returns a |
|
|
Returns a |
|
|
Returns a |
|
|
Returns a |
|
|
Returns a |
|
|
Returns a |
|
|
Returns a |
Notes
[1] Common parameters for the Storage array are
unbounded_array<T>
, bounded_array<T>
and std::vector<T>
.
Unit Vector
Description
The templated class unit_vector<T, ALLOC>
represents canonical unit
vectors. For the k-th n-dimensional canonical unit vector and 0 ⇐
i < n holds uki = 0, if i <> k, and uki =
1.
Example
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/io.hpp>
int main () {
using namespace boost::numeric::ublas;
for (int i = 0; i < 3; ++ i) {
unit_vector<double> v (3, i);
std::cout << v << std::endl;
}
}
Definition
Defined in the header vector.hpp.
Template parameters
Parameter | Description | Default |
---|---|---|
|
The type of object stored in the vector. |
|
|
An STL Allocator for size_type and difference_type. |
std::allocator |
Model of
Vector .
Type requirements
None, except for those imposed by the requirements of Vector .
Public base classes
vector_container<unit_vector<T> >
Members
Member | Description |
---|---|
|
Constructs an |
|
Constructs the
|
|
The copy constructor. |
|
Resizes a
|
|
Returns the size of the |
|
Returns the index of the |
|
Returns the value of
the |
|
Returns the value of
the |
|
The assignment operator. |
|
Assigns a temporary.
May change the unit vector |
|
Swaps the contents of the unit vectors. |
|
Returns a |
|
Returns a |
|
Returns a
|
|
Returns a
|
Zero Vector
Description
The templated class zero_vector<T, ALLOC>
represents zero vectors. For
a n-dimensional zero vector and 0 ⇐ i < n holds zi = 0.
Example
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/io.hpp>
int main () {
using namespace boost::numeric::ublas;
zero_vector<double> v (3);
std::cout << v << std::endl;
}
Definition
Defined in the header vector.hpp.
Template parameters
Parameter | Description | Default |
---|---|---|
|
The type of object stored in the vector. |
|
|
An STL Allocator for size_type and difference_type. |
std::allocator |
Model of
Vector .
Type requirements
None, except for those imposed by the requirements of Vector .
Public base classes
vector_container<zero_vector<T> >
Members
Member | Description |
---|---|
|
Constructs a |
|
Constructs a |
|
The copy constructor. |
|
Resizes a
|
|
Returns the size of the |
|
Returns the value of
the |
|
Returns the value of
the |
|
The assignment operator. |
|
Assigns a temporary.
May change the zero vector |
|
Swaps the contents of the zero vectors. |
|
Returns a |
|
Returns a |
|
Returns a
|
|
Returns a
|
Scalar Vector
Description
The templated class scalar_vector<T, ALLOC>
represents scalar vectors.
For a n-dimensional scalar vector and 0 ⇐ i < n holds zi =
s.
Example
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/io.hpp>
int main () {
using namespace boost::numeric::ublas;
scalar_vector<double> v (3);
std::cout << v << std::endl;
}
Definition
Defined in the header vector.hpp.
Template parameters
Parameter | Description | Default |
---|---|---|
|
The type of object stored in the vector. |
|
|
An STL Allocator for size_type and difference_type. |
std::allocator |
Model of
Vector .
Type requirements
None, except for those imposed by the requirements of Vector .
Public base classes
vector_container<scalar_vector<T> >
Members
Member | Description |
---|---|
|
Constructs a |
|
Constructs a
|
|
The copy constructor. |
|
Resizes a
|
|
Returns the size of the |
|
Returns the value of
the |
|
Returns the value of
the |
|
The assignment operator. |
|
Assigns a
temporary. May change the scalar vector |
|
Swaps the contents of the scalar vectors. |
|
Returns a |
|
Returns a |
|
Returns a
|
|
Returns a
|
Sparse Vector
Mapped Vector
Description
The templated class mapped_vector<T, A>
is the base container adaptor
for sparse vectors using element maps. For a n-dimensional sparse
vector and 0 < = i < n the non-zero elements vi are mapped to
consecutive elements of the associative container, i.e. for elements k
= vi1 and k + 1 = vi2 of the container holds
i1 < i2 .
Example
#include <boost/numeric/ublas/vector_sparse.hpp>
#include <boost/numeric/ublas/io.hpp>
int main () {
using namespace boost::numeric::ublas;
mapped_vector<double> v (3, 3);
for (unsigned i = 0; i < v.size (); ++ i)
v (i) = i;
std::cout << v << std::endl;
}
Definition
Defined in the header vector_sparse.hpp.
Template parameters
Parameter | Description | Default |
---|---|---|
|
The type of object stored in the mapped vector. |
|
|
The type of the adapted array. [1] |
|
Model of
Vector .
Type requirements
None, except for those imposed by the requirements of Vector .
Public base classes
vector_container<mapped_vector<T, A> >
Members
Member | Description |
---|---|
|
Allocates a |
|
Allocates a
|
|
The copy constructor. |
|
The extended copy constructor. |
|
Reallocates a
|
|
Returns the size of the |
|
Returns the value of
the |
|
Returns a reference of the
|
|
Returns the value of
the |
|
Returns a reference of the
|
|
The assignment operator. |
|
Assigns a
temporary. May change the mapped vector |
|
The extended assignment operator. |
|
Assigns a vector expression to the mapped vector. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Adds the vector expression to the mapped vector. |
|
Adds a vector expression to the mapped vector. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Subtracts the vector expression from the mapped vector. |
|
Subtracts a vector expression from the mapped vector. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Multiplies the mapped vector with a scalar. |
|
A computed assignment operator. Divides the mapped vector through a scalar. |
|
Swaps the contents of the mapped vectors. |
|
Inserts the value |
|
Erases the value at the |
|
Clears the mapped vector. |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a
|
|
Returns a
|
|
Returns a |
|
Returns a |
Notes
[1] Supported parameters for the adapted array are
map_array<std::size_t, T>
and map_std<std::size_t, T>
. The latter is
equivalent to std::map<std::size_t, T>
.
Compressed Vector
Description
The templated class compressed_vector<T, IB, IA, TA>
is the base
container adaptor for compressed vectors. For a n-dimensional
compressed vector and 0 ⇐ i < n the non-zero elements vi are
mapped to consecutive elements of the index and value container, i.e.
for elements k = vi1 and k + 1 = vi2 of
these containers holds i1 < i2 .
Example
#include <boost/numeric/ublas/vector_sparse.hpp>
#include <boost/numeric/ublas/io.hpp>
int main () {
using namespace boost::numeric::ublas;
compressed_vector<double> v (3, 3);
for (unsigned i = 0; i < v.size (); ++ i)
v (i) = i;
std::cout << v << std::endl;
}
Definition
Defined in the header vector_sparse.hpp.
Template parameters
Parameter | Description | Default |
---|---|---|
|
The type of object stored in the compressed vector. |
|
|
The index base of the compressed vector. [1] |
|
|
The type of the adapted array for indices. [2] |
|
|
The type of the adapted array for values. [2] |
|
Model of
Vector .
Type requirements
None, except for those imposed by the requirements of Vector .
Public base classes
vector_container<compressed_vector<T, IB, IA, TA> >
Members
Member | Description |
---|---|
|
Allocates a |
|
Allocates a
|
|
The copy constructor. |
|
The extended copy constructor. |
|
Reallocates a
|
|
Returns the size of the |
|
Returns the value of
the |
|
Returns a reference of the
|
|
Returns the value of
the |
|
Returns a reference of the
|
|
The assignment operator. |
|
Assigns a
temporary. May change the compressed vector |
|
The extended assignment operator. |
|
Assigns a vector expression to the compressed vector. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Adds the vector expression to the compressed vector. |
|
Adds a vector expression to the compressed vector. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Subtracts the vector expression from the compressed vector. |
|
Subtracts a vector expression from the compressed vector. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Multiplies the compressed vector with a scalar. |
|
A computed assignment operator. Divides the compressed vector through a scalar. |
|
Swaps the contents of the compressed vectors. |
|
Inserts the value |
|
Erases the value at the |
|
Clears the compressed vector. |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a
|
|
Returns a
|
|
Returns a |
|
Returns a |
Notes
[1] Supported parameters for the index base are
0
and 1
at least.
[2] Supported parameters for the adapted array
are unbounded_array<>
, bounded_array<>
and std::vector<>
.
Coordinate Vector
Description
The templated class coordinate_vector<T, IB, IA, TA>
is the base
container adaptor for compressed vectors. For a n-dimensional sorted
coordinate vector and 0 ⇐ i < n the non-zero elements vi are
mapped to consecutive elements of the index and value container, i.e.
for elements k = vi1 and k + 1 = vi2 of
these containers holds i1 < i2 .
Example
#include <boost/numeric/ublas/vector_sparse.hpp>
#include <boost/numeric/ublas/io.hpp>
int main () {
using namespace boost::numeric::ublas;
coordinate_vector<double> v (3, 3);
for (unsigned i = 0; i < v.size (); ++ i)
v (i) = i;
std::cout << v << std::endl;
}
Definition
Defined in the header vector_sparse.hpp.
Template parameters
Parameter | Description | Default |
---|---|---|
|
The type of object stored in the coordinate vector. |
|
|
The index base of the coordinate vector. [1] |
|
|
The type of the adapted array for indices. [2] |
|
|
The type of the adapted array for values. [2] |
|
Model of
Vector .
Type requirements
None, except for those imposed by the requirements of Vector .
Public base classes
vector_container<coordinate_vector<T, IB, IA, TA> >
Members
Member | Description |
---|---|
|
Allocates a |
|
Allocates a
|
|
The copy constructor. |
|
The extended copy constructor. |
|
Reallocates a
|
|
Returns the size of the |
|
Returns the value of
the |
|
Returns a reference of the
|
|
Returns the value of
the |
|
Returns a reference of the
|
|
The assignment operator. |
|
Assigns a
temporary. May change the coordinate vector |
|
The extended assignment operator. |
|
Assigns a vector expression to the coordinate vector. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Adds the vector expression to the coordinate vector. |
|
Adds a vector expression to the coordinate vector. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Subtracts the vector expression from the coordinate vector. |
|
Subtracts a vector expression from the coordinate vector. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Multiplies the coordinate vector with a scalar. |
|
A computed assignment operator. Divides the coordinate vector through a scalar. |
|
Swaps the contents of the coordinate vectors. |
|
Inserts the value |
|
Appends the value |
|
Erases the value at the |
|
Clears the coordinate vector. |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a
|
|
Returns a
|
|
Returns a |
|
Returns a |
Notes
[1] Supported parameters for the index base are
0
and 1
at least.
[2] Supported parameters for the adapted array
are unbounded_array<>
, bounded_array<>
and std::vector<>
.
Vector Proxies
Vector Range
Description
The templated class vector_range<V>
allows addressing a sub-range of a
vector’s element.
Example
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/vector_proxy.hpp>
#include <boost/numeric/ublas/io.hpp>
int main () {
using namespace boost::numeric::ublas;
vector<double> v (3);
vector_range<vector<double> > vr (v, range (0, 3));
for (unsigned i = 0; i < vr.size (); ++ i)
vr (i) = i;
std::cout << vr << std::endl;
}
Definition
Defined in the header vector_proxy.hpp.
Template parameters
Parameter |
Description |
Default |
|
The type of vector referenced. |
Model of
If the specified range falls outside that of the index range of the
vector, then the vector_range
is not a well formed Vector Expression.
That is, access to an element which is outside of index range of the
vector is undefined.
Type requirements
None, except for those imposed by the requirements of Vector Expression .
Public base classes
vector_expression<vector_range<V> >
Members
Member | Description |
---|---|
|
Constructs a sub vector. |
|
Returns the start of the sub vector. |
|
Returns the size of the sub vector. |
|
Returns the value of
the |
|
Returns a reference of the
|
|
Returns the value of
the |
|
Returns a reference of the
|
|
The assignment operator. |
|
Assigns a
temporary. May change the vector range |
|
The extended assignment operator. |
|
Assigns a vector expression to the sub vector. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Adds the vector expression to the sub vector. |
|
Adds a vector expression to the sub vector. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Subtracts the vector expression from the sub vector. |
|
Subtracts a vector expression from the sub vector. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Multiplies the sub vector with a scalar. |
|
A computed assignment operator. Divides the sub vector through a scalar. |
|
Swaps the contents of the sub vectors. |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a
|
|
Returns a
|
|
Returns a |
|
Returns a |
Simple Projections
The free subrange
functions support the construction of vector ranges.
template<class V>
vector_range<V> subrange (V &data,
V::size_type start, V::size_type stop);
template<class V>
const vector_range<const V> subrange (const V &data,
V::size_type start, V::size_type stop);
Generic Projections
The free project
functions support the construction of vector ranges.
Existing matrix_range
's can be composed with a further range. The
resulting range is computed using this existing range’s compose
function.
template<class V>
vector_range<V> project (V &data, const range &r);
template<class V>
const vector_range<const V> project (const V &data, const range &r);
template<class V>
vector_range<V> project (vector_range<V> &data, const range &r);
template<class V>
const vector_range<V> project (const vector_range<V> &data, const range &r);
Defined in the header vector_proxy.hpp.
-
V
is a model of Vector Expression .
Linear depending from the size of the range.
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/vector_proxy.hpp>
#include <boost/numeric/ublas/io.hpp>
int main () {
using namespace boost::numeric::ublas;
vector<double> v (3);
for (int i = 0; i < 3; ++ i)
project (v, range (0, 3)) (i) = i;
std::cout << project (v, range (0, 3)) << std::endl;
}
Vector Slice
Description
The templated class vector_slice<V>
allows addressing a slice of a
vector.
Example
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/vector_proxy.hpp>
#include <boost/numeric/ublas/io.hpp>
int main () {
using namespace boost::numeric::ublas;
vector<double> v (3);
vector_slice<vector<double> > vs (v, slice (0, 1, 3));
for (unsigned i = 0; i < vs.size (); ++ i)
vs (i) = i;
std::cout << vs << std::endl;
}
Definition
Defined in the header vector_proxy.hpp.
Template parameters
Parameter |
Description |
Default |
|
The type of vector referenced. |
Model of
If the specified slice falls outside that of the index range of the
vector, then the vector_slice
is not a well formed Vector Expression.
That is, access to an element which is outside of index range of the
vector is undefined.
Type requirements
None, except for those imposed by the requirements of Vector Expression .
Public base classes
vector_expression<vector_slice<V> >
Members
Member | Description |
---|---|
|
Constructs a sub vector. |
|
Returns the size of the sub vector. |
|
Returns the value of
the |
|
Returns a reference of the
|
|
Returns the value of
the |
|
Returns a reference of the
|
|
The assignment operator. |
|
Assigns a
temporary. May change the vector slice |
|
The extended assignment operator. |
|
Assigns a vector expression to the sub vector. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Adds the vector expression to the sub vector. |
|
Adds a vector expression to the sub vector. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Subtracts the vector expression from the sub vector. |
|
Subtracts a vector expression from the sub vector. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Multiplies the sub vector with a scalar. |
|
A computed assignment operator. Divides the sub vector through a scalar. |
|
Swaps the contents of the sub vectors. |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a
|
|
Returns a
|
|
Returns a |
|
Returns a |
Simple Projections
The free subslice
functions support the construction of vector slices.
template<class V>
vector_slice<V> subslice (V &data,
V::size_type start, V::difference_type stride, V::size_type size);
template<class V>
const vector_slice<const V> subslice (const V &data,
V::size_type start, V::difference_type stride, V::size_type size);
Generic Projections
The free project
functions support the construction of vector slices.
Existing vector_slice
's can be composed with a further range or
slices. The resulting slice is computed using this existing slices’s
compose
function.
template<class V>
vector_slice<V> project (V &data, const slice &s);
template<class V>
const vector_slice<const V> project (const V &data, const slice &s);
template<class V>
vector_slice<V> project (vector_slice<V> &data, const range &r);
template<class V>
const vector_slice<V> project (const vector_slice<V> &data, const range &r);
template<class V>
vector_slice<V> project (vector_slice<V> &data, const slice &s);
template<class V>
const vector_slice<V> project (const vector_slice<V> &data, const slice &s);
Defined in the header vector_proxy.hpp.
-
V
is a model of Vector Expression .
Linear depending from the size of the slice.
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/vector_proxy.hpp>
#include <boost/numeric/ublas/io.hpp>
int main () {
using namespace boost::numeric::ublas;
vector<double> v (3);
for (int i = 0; i < 3; ++ i)
project (v, slice (0, 1, 3)) (i) = i;
std::cout << project (v, slice (0, 1, 3)) << std::endl;
}
Vector Expressions
Description
The templated class vector_expression<E>
is required to be a public
base of all classes which model the Vector Expression concept.
Definition
Defined in the header expression_types.hpp.
Template parameters
Parameter |
Description |
Default |
|
The type of the vector expression. |
|
Model of
None. Not a Vector Expression!
Type requirements
None.
Public base classes
None.
Members
Member | Description |
---|---|
|
Returns a |
|
Returns a reference of the expression. |
Notes
The range
, slice
and project
functions have been removed. Use the
free functions defined in vector proxy instead.
Vector Container
Description
The templated class vector_container<C>
is required to be a public
base of all classes which model the Vector concept. This includes the
class vector
itself.
Definition
Defined in the header expression_types.hpp.
Template parameters
Parameter |
Description |
Default |
|
The type of the vector container. |
|
Model of
None. Not a Vector Expression OR Vector!
Type requirements
None.
Public base classes
vector_expression<C>
Members
Member | Description |
---|---|
|
Returns a |
|
Returns a reference of the container. |
Vector References
Reference
The templated class vector_reference<E>
contains a reference to a
vector expression.
Defined in the header vector_expression.hpp.
Parameter |
Description |
Default |
|
The type of the vector expression. |
|
None, except for those imposed by the requirements of Vector Expression .
vector_expression<vector_reference<E> >
Member | Description |
---|---|
|
Constructs a reference of the expression. |
|
Resizes the expression to hold at most
|
|
Returns the size of the expression. |
|
Returns the value of
the |
|
Returns a reference of the
|
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a
|
|
Returns a
|
|
Returns a |
|
Returns a |
Vector Operations
Unary Operation Description
The templated class vector_unary<E, F>
describes a unary vector
operation.
Defined in the header vector_expression.hpp.
Parameter |
Description |
Default |
|
The type of the vector expression. |
|
|
The type of the operation. |
|
None, except for those imposed by the requirements of Vector Expression .
vector_expression<vector_unary<E, F> >
Member | Description |
---|---|
|
Constructs a description of the expression. |
|
Returns the size of the expression. |
|
Returns the value of
the |
|
Returns a |
|
Returns a |
|
Returns a
|
|
Returns a
|
Unary Operations
template<class E, class F>
struct vector_unary_traits {
typedef vector_unary<typename E::const_closure_type, F> expression_type;
typedef expression_type result_type;
};
// (- v) [i] = - v [i]
template<class E>
typename vector_unary_traits<E, scalar_negate<typename E::value_type> >::result_type
operator - (const vector_expression<E> &e);
// (conj v) [i] = conj (v [i])
template<class E>
typename vector_unary_traits<E, scalar_conj<typename E::value_type> >::result_type
conj (const vector_expression<E> &e);
// (real v) [i] = real (v [i])
template<class E>
typename vector_unary_traits<E, scalar_real<typename E::value_type> >::result_type
real (const vector_expression<E> &e);
// (imag v) [i] = imag (v [i])
template<class E>
typename vector_unary_traits<E, scalar_imag<typename E::value_type> >::result_type
imag (const vector_expression<E> &e);
// (trans v) [i] = v [i]
template<class E>
typename vector_unary_traits<E, scalar_identity<typename E::value_type> >::result_type
trans (const vector_expression<E> &e);
// (herm v) [i] = conj (v [i])
template<class E>
typename vector_unary_traits<E, scalar_conj<typename E::value_type> >::result_type
herm (const vector_expression<E> &e);
operator -
computes the additive inverse of a vector expression.
conj
computes the complex conjugate of a vector expression. real
and
imag
compute the real and imaginary parts of a vector expression.
trans
computes the transpose of a vector expression. herm
computes
the hermitian, i.e. the complex conjugate of the transpose of a vector
expression.
Defined in the header vector_expression.hpp.
-
E
is a model of Vector Expression .
None.
Linear depending from the size of the vector expression.
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/io.hpp>
int main () {
using namespace boost::numeric::ublas;
vector<std::complex<double> > v (3);
for (unsigned i = 0; i < v.size (); ++ i)
v (i) = std::complex<double> (i, i);
std::cout << - v << std::endl;
std::cout << conj (v) << std::endl;
std::cout << real (v) << std::endl;
std::cout << imag (v) << std::endl;
std::cout << trans (v) << std::endl;
std::cout << herm (v) << std::endl;
}
Binary Operation Description
The templated class vector_binary<E1, E2, F>
describes a binary vector
operation.
Defined in the header vector_expression.hpp.
Parameter |
Description |
Default |
|
The type of the first vector expression. |
|
|
The type of the second vector expression. |
|
|
The type of the operation. |
None, except for those imposed by the requirements of Vector Expression .
vector_expression<vector_binary<E1, E2, F> >
Member | Description |
---|---|
|
Constructs a description of the expression. |
|
Returns the size of the expression. |
|
Returns the value of
the |
|
Returns a |
|
Returns a |
|
Returns a
|
|
Returns a
|
Binary Operations
template<class E1, class E2, class F>
struct vector_binary_traits {
typedef vector_binary<typename E1::const_closure_type,
typename E2::const_closure_type, F> expression_type;
typedef expression_type result_type;
};
// (v1 + v2) [i] = v1 [i] + v2 [i]
template<class E1, class E2>
typename vector_binary_traits<E1, E2, scalar_plus<typename E1::value_type,
typename E2::value_type> >::result_type
operator + (const vector_expression<E1> &e1,
const vector_expression<E2> &e2);
// (v1 - v2) [i] = v1 [i] - v2 [i]
template<class E1, class E2>
typename vector_binary_traits<E1, E2, scalar_minus<typename E1::value_type,
typename E2::value_type> >::result_type
operator - (const vector_expression<E1> &e1,
const vector_expression<E2> &e2);
operator +
computes the sum of two vector expressions. operator -
computes the difference of two vector expressions.
Defined in the header vector_expression.hpp.
-
E1
is a model of Vector Expression . -
E2
is a model of Vector Expression .
-
e1 ().size () == e2 ().size ()
Linear depending from the size of the vector expressions.
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/io.hpp>
int main () {
using namespace boost::numeric::ublas;
vector<double> v1 (3), v2 (3);
for (unsigned i = 0; i < std::min (v1.size (), v2.size ()); ++ i)
v1 (i) = v2 (i) = i;
std::cout << v1 + v2 << std::endl;
std::cout << v1 - v2 << std::endl;
}
Binary Outer Operation Description
The templated class vector_matrix_binary<E1, E2, F>
describes a binary
outer vector operation.
Defined in the header matrix_expression.hpp.
Parameter |
Description |
Default |
|
The type of the first vector expression. |
|
|
The type of the second vector expression. |
|
|
The type of the operation. |
None, except for those imposed by the requirements of Matrix Expression .
matrix_expression<vector_matrix_binary<E1, E2, F> >
Member | Description |
---|---|
|
Constructs a description of the expression. |
|
Returns the number of rows. |
|
Returns the number of columns. |
|
Returns
the value of the |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a
|
|
Returns a
|
|
Returns a
|
|
Returns a
|
Binary Outer Operations
template<class E1, class E2, class F>
struct vector_matrix_binary_traits {
typedef vector_matrix_binary<typename E1::const_closure_type,
typename E2::const_closure_type, F> expression_type;
typedef expression_type result_type;
};
// (outer_prod (v1, v2)) [i] [j] = v1 [i] * v2 [j]
template<class E1, class E2>
typename vector_matrix_binary_traits<E1, E2, scalar_multiplies<typename E1::value_type, typename E2::value_type> >::result_type
outer_prod (const vector_expression<E1> &e1,
const vector_expression<E2> &e2);
outer_prod
computes the outer product of two vector expressions.
Defined in the header matrix_expression.hpp.
-
E1
is a model of Vector Expression . -
E2
is a model of Vector Expression .
None.
Quadratic depending from the size of the vector expressions.
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>
int main () {
using namespace boost::numeric::ublas;
vector<double> v1 (3), v2 (3);
for (unsigned i = 0; i < std::min (v1.size (), v2.size ()); ++ i)
v1 (i) = v2 (i) = i;
std::cout << outer_prod (v1, v2) << std::endl;
}
Scalar Vector Operation Description
The templated classes vector_binary_scalar1<E1, E2, F>
and
vector_binary_scalar2<E1, E2, F>
describe binary operations between a
scalar and a vector.
Defined in the header vector_expression.hpp.
Parameter |
Description |
Default |
|
The type of the scalar expression. |
|
|
The type of the vector expression. |
|
|
The type of the operation. |
None, except for those imposed by the requirements of Vector Expression .
vector_expression<vector_binary_scalar1<E1, E2, F> >
and
vector_expression<vector_binary_scalar2<E1, E2, F> >
resp.
Member | Description |
---|---|
|
Constructs a description of the expression. |
|
Constructs a description of the expression. |
|
Returns the size of the expression. |
|
Returns the value of
the |
|
Returns a |
|
Returns a |
|
Returns a
|
|
Returns a
|
Scalar Vector Operations
template<class T1, class E2, class F>
struct vector_binary_scalar1_traits {
typedef vector_binary_scalar1<scalar_const_reference<T1>,
typename E2::const_closure_type, F> expression_type;
typedef expression_type result_type;
};
// (t * v) [i] = t * v [i]
template<class T1, class E2>
typename vector_binary_scalar1_traits<T1, E2, scalar_multiplies<T1, typename E2::value_type> >::result_type
operator * (const T1 &e1,
const vector_expression<E2> &e2);
template<class E1, class T2, class F>
struct vector_binary_scalar2_traits {
typedef vector_binary_scalar2<typename E1::const_closure_type,
scalar_const_reference<T2>, F> expression_type;
typedef expression_type result_type;
};
// (v * t) [i] = v [i] * t
template<class E1, class T2>
typename vector_binary_scalar2_traits<E1, T2, scalar_multiplies<typename E1::value_type, T2> >::result_type
operator * (const vector_expression<E1> &e1,
const T2 &e2);
// (v / t) [i] = v [i] / t
template<class E1, class T2>
typename vector_binary_scalar2_traits<E1, T2, scalar_divides<typename E1::value_type, T2> >::result_type
operator / (const vector_expression<E1> &e1,
const T2 &e2);
operator *
computes the product of a scalar and a vector expression.
operator /
multiplies the vector with the reciprocal of the scalar.
Defined in the header vector_expression.hpp.
-
T1/T2
is a model of Scalar Expression . -
E2/E1
is a model of Vector Expression .
None.
Linear depending from the size of the vector expression.
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/io.hpp>
int main () {
using namespace boost::numeric::ublas;
vector<double> v (3);
for (unsigned i = 0; i < v.size (); ++ i)
v (i) = i;
std::cout << 2.0 * v << std::endl;
std::cout << v * 2.0 << std::endl;
}
Vector Reductions
Unary Reductions
template<class E, class F>
struct vector_scalar_unary_traits {
typedef typename F::result_type result_type;
};
// sum v = sum (v [i])
template<class E>
typename vector_scalar_unary_traits<E, vector_sum<typename E::value_type> >::result_type
sum (const vector_expression<E> &e);
// norm_1 v = sum (abs (v [i]))
template<class E>
typename vector_scalar_unary_traits<E, vector_norm_1<typename E::value_type> >::result_type
norm_1 (const vector_expression<E> &e);
// norm_2 v = sqrt (sum (v [i] * v [i]))
template<class E>
typename vector_scalar_unary_traits<E, vector_norm_2<typename E::value_type> >::result_type
norm_2 (const vector_expression<E> &e);
// norm_2_square v = sum (v [i] * v [i])
template<class E>
typename vector_scalar_unary_traits<E, vector_norm_2_square<typename E::value_type> >::result_type
norm_2_square (const vector_expression<E> &e);
// norm_inf v = max (abs (v [i]))
template<class E>
typename vector_scalar_unary_traits<E, vector_norm_inf<typename E::value_type> >::result_type
norm_inf (const vector_expression<E> &e);
// index_norm_inf v = min (i: abs (v [i]) == max (abs (v [i])))
template<class E>
typename vector_scalar_unary_traits<E, vector_index_norm_inf<typename E::value_type> >::result_type
index_norm_inf (const vector_expression<E> &e);
sum
computes the sum of the vector expression’s elements. norm_1
,
norm_2
and norm_inf
compute the corresponding ||.||1,
||.||2 and ||.||inf vector norms. index_norm_1
computes the index of the vector expression’s first element having
maximal absolute value.
Defined in the header vector_expression.hpp.
-
E
is a model of Vector Expression .
None.
Linear depending from the size of the vector expression.
#include <boost/numeric/ublas/vector.hpp>
int main () {
using namespace boost::numeric::ublas;
vector<double> v (3);
for (unsigned i = 0; i < v.size (); ++ i)
v (i) = i;
std::cout << sum (v) << std::endl;
std::cout << norm_1 (v) << std::endl;
std::cout << norm_2 (v) << std::endl;
std::cout << norm_inf (v) << std::endl;
std::cout << index_norm_inf (v) << std::endl;
}
Binary Reductions
template<class E1, class E2, class F>
struct vector_scalar_binary_traits {
typedef typename F::result_type result_type;
};
// inner_prod (v1, v2) = sum (v1 [i] * v2 [i])
template<class E1, class E2>
typename vector_scalar_binary_traits<E1, E2, vector_inner_prod<typename E1::value_type,
typename E2::value_type,
typename promote_traits<typename E1::value_type,
typename E2::value_type>::promote_type> >::result_type
inner_prod (const vector_expression<E1> &e1,
const vector_expression<E2> &e2);
template<class E1, class E2>
typename vector_scalar_binary_traits<E1, E2, vector_inner_prod<typename E1::value_type,
typename E2::value_type,
typename type_traits<typename promote_traits<typename E1::value_type,
typename E2::value_type>::promote_type>::precision_type> >::result_type
prec_inner_prod (const vector_expression<E1> &e1,
const vector_expression<E2> &e2);
inner_prod
computes the inner product of the vector expressions.
prec_inner_prod
computes the double precision inner product of the
vector expressions`.`
Defined in the header vector_expression.hpp.
-
E1
is a model of Vector Expression . -
E2
is a model of Vector Expression .
-
e1 ().size () == e2 ().size ()
Linear depending from the size of the vector expressions.
#include <boost/numeric/ublas/vector.hpp>
int main () {
using namespace boost::numeric::ublas;
vector<double> v1 (3), v2 (3);
for (unsigned i = 0; i < std::min (v1.size (), v2.size ()); ++ i)
v1 (i) = v2 (i) = i;
std::cout << inner_prod (v1, v2) << std::endl;
}
Matrix
Matrix Abstract
Description
The templated class matrix<T, F, A>
is the base container adaptor for
dense matrices. For a (m x n)-dimensional matrix and 0 ⇐ i < m, 0
⇐ j < n every element mi,j is mapped to the (i x n
j)-th element of the container for row major orientation or the (i+
j x m)-th element of the container for column major orientation.
Example
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>
int main () {
using namespace boost::numeric::ublas;
matrix<double> m (3, 3);
for (unsigned i = 0; i < m.size1 (); ++ i)
for (unsigned j = 0; j < m.size2 (); ++ j)
m (i, j) = 3 * i + j;
std::cout << m << std::endl;
}
Definition
Defined in the header matrix.hpp.
Template parameters
Parameter | Description | Default |
---|---|---|
|
The type of object stored in the matrix. |
|
|
Functor describing the storage organization. [1] |
|
|
|
Model of
Matrix .
Type requirements
None, except for those imposed by the requirements of Matrix .
Public base classes
matrix_container<matrix<T, F, A> >
Members
Member | Description |
---|---|
|
Allocates an uninitialized |
|
Allocates an uninitialized
|
|
The copy constructor. |
|
The extended copy constructor. |
|
Reallocates a |
|
Returns the number of rows. |
|
Returns the number of columns. |
|
|
|
|
|
Returns
a |
|
Returns a reference
of the |
|
The assignment operator. |
|
Assigns a temporary. May change
the matrix |
|
The extended assignment operator. |
|
Assigns a matrix expression to the matrix. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Adds the matrix expression to the matrix. |
|
Adds a matrix expression to the matrix. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Subtracts the matrix expression from the matrix. |
|
Subtracts a matrix expression from the matrix. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Multiplies the matrix with a scalar. |
|
A computed assignment operator. Divides the matrix through a scalar. |
|
Swaps the contents of the matrices. |
|
Inserts the value |
|
Erases the value at
the |
|
Clears the matrix. |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a
|
|
Returns a
|
|
Returns a |
|
Returns a |
|
Returns a
|
|
Returns a
|
|
Returns a |
|
Returns a |
Notes
[1] Supported parameters for the storage organization are
row_major
and column_major
.
[2] Common parameters for the storage array are
unbounded_array<T>
, bounded_array<T>
and std::vector<T>
.
Identity Matrix
Description
The templated class identity_matrix<T, ALLOC>
represents identity
matrices. For a (m x n)-dimensional identity matrix and 0 ⇐ i < m,
0 ⇐ j < n holds idi,j = 0, if i <> j, and idi,i .
Example
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>
int main () {
using namespace boost::numeric::ublas;
identity_matrix<double> m (3);
std::cout << m << std::endl;
}
Definition
Defined in the header matrix.hpp.
Template parameters
Parameter | Description | Default |
---|---|---|
|
The type of object stored in the matrix. |
|
|
An STL Allocator for size_type and difference_type. |
std::allocator |
Model of
Matrix .
Type requirements
None, except for those imposed by the requirements of Matrix .
Public base classes
matrix_container<identity_matrix<T> >
Members
Member | Description |
---|---|
|
Constructs an |
|
Constructs an |
|
The copy constructor. |
|
Resizes a
|
|
Returns the number of rows. |
|
Returns the number of columns. |
|
Returns
the value of the |
|
The assignment operator. |
|
Assigns a
temporary. May change the identity matrix |
|
Swaps the contents of the identity matrices. |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a
|
|
Returns a
|
|
Returns a
|
|
Returns a
|
Zero Matrix
Description
The templated class zero_matrix<T, ALLOC>
represents zero matrices.
For a (m x n)-dimensional zero matrix and 0 ⇐ i < m, 0 ⇐ j < n
holds zi,j = 0.
Example
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>
int main () {
using namespace boost::numeric::ublas;
zero_matrix<double> m (3, 3);
std::cout << m << std::endl;
}
Definition
Defined in the header matrix.hpp.
Template parameters
Parameter | Description | Default |
---|---|---|
|
The type of object stored in the matrix. |
|
|
An STL Allocator for size_type and difference_type. |
std::allocator |
Model of
Matrix .
Type requirements
None, except for those imposed by the requirements of Matrix .
Public base classes
matrix_container<zero_matrix<T> >
Members
Member | Description |
---|---|
|
Constructs a |
|
Constructs a
|
|
The copy constructor. |
|
Resizes a |
|
Returns the number of rows. |
|
Returns the number of columns. |
|
Returns
the value of the |
|
The assignment operator. |
|
Assigns a temporary.
May change the zero matrix |
|
Swaps the contents of the zero matrices. |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a
|
|
Returns a
|
|
Returns a
|
|
Returns a
|
Scalar Matrix
Description
The templated class scalar_matrix<T, ALLOC>
represents scalar
matrices. For a (m x n)-dimensional scalar matrix and 0 ⇐ i < m, 0
⇐ j < n holds zi,j = s.
Example
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>
int main () {
using namespace boost::numeric::ublas;
scalar_matrix<double> m (3, 3);
std::cout << m << std::endl;
}
Definition
Defined in the header matrix.hpp.
Template parameters
Parameter | Description | Default |
---|---|---|
|
The type of object stored in the matrix. |
|
|
An STL Allocator for size_type and difference_type. |
std::allocator |
Model of
Matrix .
Type requirements
None, except for those imposed by the requirements of Matrix .
Public base classes
matrix_container<scalar_matrix<T> >
Members
Member | Description |
---|---|
|
Constructs a |
|
Constructs a |
|
The copy constructor. |
|
Resizes a |
|
Returns the number of rows. |
|
Returns the number of columns. |
|
Returns
the value of the |
|
The assignment operator. |
|
Assigns a
temporary. May change the scalar matrix |
|
Swaps the contents of the scalar matrices. |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a
|
|
Returns a
|
|
Returns a
|
|
Returns a
|
Triangular Matrix
Description
The templated class triangular_matrix<T, F1, F2, A>
is the base
container adaptor for triangular matrices. For a (n x n )-dimensional
lower triangular matrix and 0 < = i < n, 0 < = j < n holds ti,j
= 0 , if i > j. If furthermore holds ti,i= 1 the matrix
is called unit lower triangular. For a (n x n )-dimensional lower
triangular matrix and 0 < = i < n, 0 < = j < n holds ti,j=
0 , if i < j. If furthermore holds ti,i= 1 the matrix is
called unit lower triangular. The storage of triangular matrices is
packed.
Example
#include <boost/numeric/ublas/triangular.hpp>
#include <boost/numeric/ublas/io.hpp>
int main () {
using namespace boost::numeric::ublas;
triangular_matrix<double, lower> ml (3, 3);
for (unsigned i = 0; i < ml.size1 (); ++ i)
for (unsigned j = 0; j <= i; ++ j)
ml (i, j) = 3 * i + j;
std::cout << ml << std::endl;
triangular_matrix<double, upper> mu (3, 3);
for (unsigned i = 0; i < mu.size1 (); ++ i)
for (unsigned j = i; j < mu.size2 (); ++ j)
mu (i, j) = 3 * i + j;
std::cout << mu << std::endl;
}
Please read the full triangular example for more details.
Definition
Defined in the header triangular.hpp.
Template parameters
Parameter | Description | Default |
---|---|---|
|
The type of object stored in the matrix. |
|
|
Functor describing the type of the triangular matrix. [1] |
|
|
Functor describing the storage organization. [2] |
|
|
The type of the adapted array. [3] |
|
Model of
Matrix .
Type requirements
None, except for those imposed by the requirements of Matrix .
Public base classes
matrix_container<triangular_matrix<T, F1, F2, A> >
Members
Member | Description |
---|---|
|
Allocates an uninitialized |
|
Allocates an
uninitialized |
|
The copy constructor. |
|
The extended copy constructor. |
|
Reallocates a |
|
Returns the number of rows. |
|
Returns the number of columns. |
|
Returns
a |
|
Returns a reference
of the |
|
The assignment operator. |
|
Assigns a
temporary. May change the triangular matrix |
|
The extended assignment operator. |
|
Assigns a matrix expression to the triangular matrix. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Adds the matrix expression to the triangular matrix. |
|
Adds a matrix expression to the triangular matrix. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Subtracts the matrix expression from the triangular matrix. |
|
Subtracts a matrix expression from the triangular matrix. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Multiplies the triangular matrix with a scalar. |
|
A computed assignment operator. Divides the triangular matrix through a scalar. |
|
Swaps the contents of the triangular matrices. |
|
Inserts
the value |
|
Erases the value at the |
|
Clears the matrix. |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a
|
|
Returns a
|
|
Returns a |
|
Returns a |
|
Returns a
|
|
Returns a
|
|
Returns a |
|
Returns a |
Notes
[1] Supported parameters for the type of the
triangular matrix are lower
, unit_lower
, upper
and unit_upper
.
[2] Supported parameters for the storage
organization are row_major
and column_major
.
[3] Supported parameters for the adapted array
are unbounded_array<T>
, bounded_array<T>
and std::vector<T>
.
Triangular Adaptor
Description
The templated class triangular_adaptor<M, F>
is a triangular matrix
adaptor for other matrices.
Example
#include <boost/numeric/ublas/triangular.hpp>
#include <boost/numeric/ublas/io.hpp>
int main () {
using namespace boost::numeric::ublas;
matrix<double> m (3, 3);
triangular_adaptor<matrix<double>, lower> tal (m);
for (unsigned i = 0; i < tal.size1 (); ++ i)
for (unsigned j = 0; j <= i; ++ j)
tal (i, j) = 3 * i + j;
std::cout << tal << std::endl;
triangular_adaptor<matrix<double>, upper> tau (m);
for (unsigned i = 0; i < tau.size1 (); ++ i)
for (unsigned j = i; j < tau.size2 (); ++ j)
tau (i, j) = 3 * i + j;
std::cout << tau << std::endl;
}
Please read the full triangular example for more details.
Definition
Defined in the header triangular.hpp.
Template parameters
Parameter | Description | Default |
---|---|---|
|
The type of the adapted matrix. |
|
|
Functor describing the type of the triangular adaptor. [1] |
|
Model of
Type requirements
None, except for those imposed by the requirements of Matrix Expression .
Public base classes
matrix_expression<triangular_adaptor<M, F> >
Members
Member | Description |
---|---|
|
Constructs a
|
|
The copy constructor. |
|
The extended copy constructor. |
|
Returns the number of rows. |
|
Returns the number of columns. |
|
Returns
a |
|
Returns a reference
of the |
|
The assignment operator. |
|
Assigns
a temporary. May change the triangular adaptor |
|
The extended assignment operator. |
|
Assigns a matrix expression to the triangular adaptor. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Adds the matrix expression to the triangular adaptor. |
|
Adds a matrix expression to the triangular adaptor. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Subtracts the matrix expression from the triangular adaptor. |
|
Subtracts a matrix expression from the triangular adaptor. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Multiplies the triangular adaptor with a scalar. |
|
A computed assignment operator. Divides the triangular adaptor through a scalar. |
|
Swaps the contents of the triangular adaptors. |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a
|
|
Returns a
|
|
Returns a |
|
Returns a |
|
Returns a
|
|
Returns a
|
|
Returns a |
|
Returns a |
Notes
[1] Supported parameters for the type of the
triangular adaptor are lower
, unit_lower
, upper
and unit_upper
.
Symmetric Matrix
Description
The templated class symmetric_matrix<T, F1, F2, A>
is the base
container adaptor for symmetric matrices. For a (n x n )-dimensional
symmetric matrix and 0 < = i < n, 0 < = j < n holds si,j=
sj,i. The storage of symmetric matrices is packed.
Example
#include <boost/numeric/ublas/symmetric.hpp>
#include <boost/numeric/ublas/io.hpp>
int main () {
using namespace boost::numeric::ublas;
symmetric_matrix<double, lower> ml (3, 3);
for (unsigned i = 0; i < ml.size1 (); ++ i)
for (unsigned j = 0; j <= i; ++ j)
ml (i, j) = 3 * i + j;
std::cout << ml << std::endl;
symmetric_matrix<double, upper> mu (3, 3);
for (unsigned i = 0; i < mu.size1 (); ++ i)
for (unsigned j = i; j < mu.size2 (); ++ j)
mu (i, j) = 3 * i + j;
std::cout << mu << std::endl;
}
Definition
Defined in the header symmetric.hpp.
Template parameters
Parameter | Description | Default |
---|---|---|
|
The type of object stored in the matrix. |
|
|
Functor describing the type of the symmetric matrix. [1] |
|
|
Functor describing the storage organization. [2] |
|
|
The type of the adapted array. [3] |
|
Model of
Matrix .
Type requirements
None, except for those imposed by the requirements of Matrix .
Public base classes
matrix_container<symmetric_matrix<T, F1, F2, A> >
Members
Member | Description |
---|---|
|
Allocates an uninitialized
|
|
The copy constructor. |
|
The extended copy constructor. |
|
Reallocates a
|
|
Returns the number of rows. |
|
Returns the number of columns. |
|
Returns
a |
|
Returns a reference
of the |
|
The assignment operator. |
|
Assigns a
temporary. May change the symmetric matrix |
|
The extended assignment operator. |
|
Assigns a matrix expression to the symmetric matrix. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Adds the matrix expression to the symmetric matrix. |
|
Adds a matrix expression to the symmetric matrix. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Subtracts the matrix expression from the symmetric matrix. |
|
Subtracts a matrix expression from the symmetric matrix. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Multiplies the symmetric matrix with a scalar. |
|
A computed assignment operator. Divides the symmetric matrix through a scalar. |
|
Swaps the contents of the symmetric matrices. |
|
Inserts
the value |
|
Erases the value at the |
|
Clears the matrix. |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a
|
|
Returns a
|
|
Returns a |
|
Returns a |
|
Returns a
|
|
Returns a
|
|
Returns a |
|
Returns a |
Notes
[1] Supported parameters for the type of the
symmetric matrix are lower
and upper
.
[2] Supported parameters for the storage
organization are row_major
and column_major
.
[3] Supported parameters for the adapted array
are unbounded_array<T>
, bounded_array<T>
and std::vector<T>
.
Symmetric Adaptor
Description
The templated class symmetric_adaptor<M, F>
is a symmetric matrix
adaptor for other matrices.
Example
#include <boost/numeric/ublas/symmetric.hpp>
#include <boost/numeric/ublas/io.hpp>
int main () {
using namespace boost::numeric::ublas;
matrix<double> m (3, 3);
symmetric_adaptor<matrix<double>, lower> sal (m);
for (unsigned i = 0; i < sal.size1 (); ++ i)
for (unsigned j = 0; j <= i; ++ j)
sal (i, j) = 3 * i + j;
std::cout << sal << std::endl;
symmetric_adaptor<matrix<double>, upper> sau (m);
for (unsigned i = 0; i < sau.size1 (); ++ i)
for (unsigned j = i; j < sau.size2 (); ++ j)
sau (i, j) = 3 * i + j;
std::cout << sau << std::endl;
}
Definition
Defined in the header symmetric.hpp.
Template parameters
Parameter | Description | Default |
---|---|---|
|
The type of the adapted matrix. |
|
|
Functor describing the type of the symmetric adaptor. [1] |
|
Model of
Type requirements
None, except for those imposed by the requirements of Matrix Expression .
Public base classes
matrix_expression<symmetric_adaptor<M, F> >
Members
Member | Description |
---|---|
|
Constructs a |
|
Constructs a
|
|
The copy constructor. |
|
The extended copy constructor. |
|
Returns the number of rows. |
|
Returns the number of columns. |
|
Returns
a |
|
Returns a reference
of the |
|
The assignment operator. |
|
Assigns a
temporary. May change the symmetric adaptor |
|
The extended assignment operator. |
|
Assigns a matrix expression to the symmetric adaptor. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Adds the matrix expression to the symmetric adaptor. |
|
Adds a matrix expression to the symmetric adaptor. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Subtracts the matrix expression from the symmetric adaptor. |
|
Subtracts a matrix expression from the symmetric adaptor. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Multiplies the symmetric adaptor with a scalar. |
|
A computed assignment operator. Divides the symmetric adaptor through a scalar. |
|
Swaps the contents of the symmetric adaptors. |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a
|
|
Returns a
|
|
Returns a |
|
Returns a |
|
Returns a
|
|
Returns a
|
|
Returns a |
|
Returns a |
Notes
[1] Supported parameters for the type of the
symmetric adaptor are lower
and upper
.
Hermitian Matrix
Description
The templated class hermitian_matrix<T, F1, F2, A>
is the base
container adaptor for hermitian matrices. For a (n x n )-dimensional
hermitian matrix and 0 < = i < n, 0 < = j < n holds hi,j=
hj,i-. The storage of hermitian matrices is packed.
Example
#include <boost/numeric/ublas/hermitian.hpp>
#include <boost/numeric/ublas/io.hpp>
int main () {
using namespace boost::numeric::ublas;
hermitian_matrix<std::complex<double>, lower> ml (3, 3);
for (unsigned i = 0; i < ml.size1 (); ++ i) {
for (unsigned j = 0; j < i; ++ j)
ml (i, j) = std::complex<double> (3 * i + j, 3 * i + j);
ml (i, i) = std::complex<double> (4 * i, 0);
}
std::cout << ml << std::endl;
hermitian_matrix<std::complex<double>, upper> mu (3, 3);
for (unsigned i = 0; i < mu.size1 (); ++ i) {
mu (i, i) = std::complex<double> (4 * i, 0);
for (unsigned j = i + 1; j < mu.size2 (); ++ j)
mu (i, j) = std::complex<double> (3 * i + j, 3 * i + j);
}
std::cout << mu << std::endl;
}
Definition
Defined in the header hermitian.hpp.
Template parameters
Parameter | Description | Default |
---|---|---|
|
The type of object stored in the matrix. |
|
|
Functor describing the type of the hermitian matrix. [1] |
|
|
Functor describing the storage organization. [2] |
|
|
The type of the adapted array. [3] |
|
Model of
Matrix .
Type requirements
None, except for those imposed by the requirements of Matrix .
Public base classes
matrix_container<hermitian_matrix<T, F1, F2, A> >
Members
Member | Description |
---|---|
|
Allocates an uninitialized |
|
Allocates an uninitialized
|
|
The copy constructor. |
|
The extended copy constructor. |
|
Reallocates a
|
|
Returns the number of rows. |
|
Returns the number of columns. |
|
Returns
a |
|
Returns a reference
of the |
|
The assignment operator. |
|
Assigns a
temporary. May change the hermitian matrix |
|
The extended assignment operator. |
|
Assigns a matrix expression to the hermitian matrix. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Adds the matrix expression to the hermitian matrix. |
|
Adds a matrix expression to the hermitian matrix. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Subtracts the matrix expression from the hermitian matrix. |
|
Subtracts a matrix expression from the hermitian matrix. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Multiplies the hermitian matrix with a scalar. |
|
A computed assignment operator. Divides the hermitian matrix through a scalar. |
|
Swaps the contents of the hermitian matrices. |
|
Inserts
the value |
|
Erases the value at the |
|
Clears the matrix. |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a
|
|
Returns a
|
|
Returns a |
|
Returns a |
|
Returns a
|
|
Returns a
|
|
Returns a |
|
Returns a |
Notes
[1] Supported parameters for the type of the
hermitian matrix are lower
and upper
.
[2] Supported parameters for the storage
organization are row_major
and column_major
.
[3] Supported parameters for the adapted array
are unbounded_array<T>
, bounded_array<T>
and std::vector<T>
.
Hermitian Adaptor
Description
The templated class hermitian_adaptor<M, F>
is a hermitian matrix
adaptor for other matrices.
Example
#include <boost/numeric/ublas/hermitian.hpp>
#include <boost/numeric/ublas/io.hpp>
int main () {
using namespace boost::numeric::ublas;
matrix<std::complex<double> > m (3, 3);
hermitian_adaptor<matrix<std::complex<double> >, lower> hal (m);
for (unsigned i = 0; i < hal.size1 (); ++ i) {
for (unsigned j = 0; j < i; ++ j)
hal (i, j) = std::complex<double> (3 * i + j, 3 * i + j);
hal (i, i) = std::complex<double> (4 * i, 0);
}
std::cout << hal << std::endl;
hermitian_adaptor<matrix<std::complex<double> >, upper> hau (m);
for (unsigned i = 0; i < hau.size1 (); ++ i) {
hau (i, i) = std::complex<double> (4 * i, 0);
for (unsigned j = i + 1; j < hau.size2 (); ++ j)
hau (i, j) = std::complex<double> (3 * i + j, 3 * i + j);
}
std::cout << hau << std::endl;
}
Definition
Defined in the header hermitian.hpp.
Template parameters
Parameter | Description | Default |
---|---|---|
|
The type of the adapted matrix. |
|
|
Functor describing the type of the hermitian adaptor. [1] |
|
Model of
Type requirements
None, except for those imposed by the requirements of Matrix Expression .
Public base classes
matrix_expression<hermitian_adaptor<M, F> >
Members
Member | Description |
---|---|
|
Constructs a
|
|
The copy constructor. |
|
The extended copy constructor. |
|
Returns the number of rows. |
|
Returns the number of columns. |
|
Returns
a |
|
Returns a reference
of the |
|
The assignment operator. |
|
Assigns a
temporary. May change the hermitian adaptor |
|
The extended assignment operator. |
|
Assigns a matrix expression to the hermitian adaptor. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Adds the matrix expression to the hermitian adaptor. |
|
Adds a matrix expression to the hermitian adaptor. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Subtracts the matrix expression from the hermitian adaptor. |
|
Subtracts a matrix expression from the hermitian adaptor. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Multiplies the hermitian adaptor with a scalar. |
|
A computed assignment operator. Divides the hermitian adaptor through a scalar. |
|
Swaps the contents of the hermitian adaptors. |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a
|
|
Returns a
|
|
Returns a |
|
Returns a |
|
Returns a
|
|
Returns a
|
|
Returns a |
|
Returns a |
Notes
[1] Supported parameters for the type of the
hermitian adaptor are lower
and upper
.
Banded Matrix
Description
The templated class banded_matrix<T, F, A>
is the base container
adaptor for banded matrices. For a (m x n)-dimensional banded matrix
with l lower and u upper diagonals and 0 < = i < m, 0 < = j < n
holds bi,j = 0, if i > j + l or i < j - u. The storage of
banded matrices is packed.
Example
#include <boost/numeric/ublas/banded.hpp>
#include <boost/numeric/ublas/io.hpp>
int main () {
using namespace boost::numeric::ublas;
banded_matrix<double> m (3, 3, 1, 1);
for (signed i = 0; i < signed (m.size1 ()); ++ i)
for (signed j = std::max (i - 1, 0); j < std::min (i + 2, signed (m.size2 ())); ++ j)
m (i, j) = 3 * i + j;
std::cout << m << std::endl;
}
Definition
Defined in the header banded.hpp.
Template parameters
Parameter | Description | Default |
---|---|---|
|
The type of object stored in the matrix. |
|
|
Functor describing the storage organization. [1] |
|
|
The type of the adapted array. [2] |
|
Model of
Matrix .
Type requirements
None, except for those imposed by the requirements of Matrix .
Public base classes
matrix_container<banded_matrix<T, F, A> >
Members
Member | Description |
---|---|
|
Allocates an uninitialized |
|
Allocates an uninitialized |
|
The copy constructor. |
|
The extended copy constructor. |
|
Reallocates a |
|
Returns the number of rows. |
|
Returns the number of columns. |
|
Returns the number of diagonals below the main diagonal. |
|
Returns the number of diagonals above the main diagonal. |
|
Returns
a |
|
Returns a reference
of the |
|
The assignment operator. |
|
Assigns a
temporary. May change the banded matrix |
|
The extended assignment operator. |
|
Assigns a matrix expression to the banded matrix. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Adds the matrix expression to the banded matrix. |
|
Adds a matrix expression to the banded matrix. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Subtracts the matrix expression from the banded matrix. |
|
Subtracts a matrix expression from the banded matrix. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Multiplies the banded matrix with a scalar. |
|
A computed assignment operator. Divides the banded matrix through a scalar. |
|
Swaps the contents of the banded matrices. |
|
Inserts
the value |
|
Erases the value at the |
|
Clears the matrix. |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a
|
|
Returns a
|
|
Returns a |
|
Returns a |
|
Returns a
|
|
Returns a
|
|
Returns a |
|
Returns a |
Notes
[1] Supported parameters for the storage
organization are row_major
and column_major
.
[2] Supported parameters for the adapted array are
unbounded_array<T>
, bounded_array<T>
and std::vector<T>
.
Banded Adaptor
Description
The templated class banded_adaptor<M>
is a banded matrix adaptor for
other matrices.
Example
#include <boost/numeric/ublas/banded.hpp>
#include <boost/numeric/ublas/io.hpp>
int main () {
using namespace boost::numeric::ublas;
matrix<double> m (3, 3);
banded_adaptor<matrix<double> > ba (m, 1, 1);
for (signed i = 0; i < signed (ba.size1 ()); ++ i)
for (signed j = std::max (i - 1, 0); j < std::min (i + 2, signed (ba.size2 ())); ++ j)
ba (i, j) = 3 * i + j;
std::cout << ba << std::endl;
}
Definition
Defined in the header banded.hpp.
Template parameters
Parameter |
Description |
Default |
|
The type of the adapted matrix. |
Model of
Type requirements
None, except for those imposed by the requirements of Matrix Expression .
Public base classes
matrix_expression<banded_adaptor<M> >
Members
Member | Description |
---|---|
|
Constructs a |
|
The copy constructor. |
|
The extended copy constructor. |
|
Returns the number of rows. |
|
Returns the number of columns. |
|
Returns the number of diagonals below the main diagonal. |
|
Returns the number of diagonals above the main diagonal. |
|
Returns
a |
|
Returns a reference
of the |
|
The assignment operator. |
|
Assigns a
temporary. May change the banded adaptor |
|
The extended assignment operator. |
|
Assigns a matrix expression to the banded adaptor. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Adds the matrix expression to the banded adaptor. |
|
Adds a matrix expression to the banded adaptor. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Subtracts the matrix expression from the banded adaptor. |
|
Subtracts a matrix expression from the banded adaptor. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Multiplies the banded adaptor with a scalar. |
|
A computed assignment operator. Divides the banded adaptor through a scalar. |
|
Swaps the contents of the banded adaptors. |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a
|
|
Returns a
|
|
Returns a |
|
Returns a |
|
Returns a
|
|
Returns a
|
|
Returns a |
|
Returns a |
Sparse Matricies
Mapped Matrix
Description
The templated class mapped_matrix<T, F, A>
is the base container
adaptor for sparse matricies using element maps. For a (m
xn)-dimensional sparse matrix and 0 < = i < m, 0 < = j < n the
non-zero elements hi,j are mapped via (i x n + j) for row
major orientation or via (i + j x m) for column major orientation to
consecutive elements of the associative container, i.e. for elements k
= mi1,j1 and k + 1 = mi2,j2
of the container holds i1 < i2 or
(i1 = i2 and j1 < j2) with row major
orientation or j1 < j2 or (j1 = j2 and
i1 < i2) with column major orientation.
Example
#include <boost/numeric/ublas/matrix_sparse.hpp>
#include <boost/numeric/ublas/io.hpp>
int main () {
using namespace boost::numeric::ublas;
mapped_matrix<double> m (3, 3, 3 * 3);
for (unsigned i = 0; i < m.size1 (); ++ i)
for (unsigned j = 0; j < m.size2 (); ++ j)
m (i, j) = 3 * i + j;
std::cout << m << std::endl;
}
Definition
Defined in the header matrix_sparse.hpp.
Template parameters
Parameter | Description | Default |
---|---|---|
|
The type of object stored in the mapped matrix. |
|
|
Functor describing the storage organization. [1] |
|
|
The type of the adapted array. [2] |
|
Model of
Matrix .
Type requirements
None, except for those imposed by the requirements of Matrix .
Public base classes
matrix_container<mapped_matrix<T, F, A> >
Members
Member | Description |
---|---|
|
Allocates a |
|
Allocates a |
|
The copy constructor. |
|
The extended copy constructor. |
|
Reallocates a |
|
Returns the number of rows. |
|
Returns the number of columns. |
|
Returns
the value of the |
|
Returns a reference
of the |
|
The assignment operator. |
|
Assigns a
temporary. May change the mapped matrix |
|
The extended assignment operator. |
|
Assigns a matrix expression to the mapped matrix. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Adds the matrix expression to the mapped matrix. |
|
Adds a matrix expression to the mapped matrix. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Subtracts the matrix expression from the mapped matrix. |
|
Subtracts a matrix expression from the mapped matrix. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Multiplies the mapped matrix with a scalar. |
|
A computed assignment operator. Divides the mapped matrix through a scalar. |
|
Swaps the contents of the mapped matrices. |
|
Inserts the value |
|
Erases the value at
the |
|
Clears the mapped matrix. |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a
|
|
Returns a
|
|
Returns a |
|
Returns a |
|
Returns a
|
|
Returns a
|
|
Returns a |
|
Returns a |
Notes
[1] Supported parameters for the storage
organization are row_major
and column_major
.
[2] Supported parameters for the adapted array are
map_array<std::size_t, T>
and map_std<std::size_t, T>
. The latter is
equivalent to std::map<std::size_t, T>
.
Compressed Matrix
Description
The templated class compressed_matrix<T, F, IB, IA, TA>
is the base
container adaptor for compressed matrices. For a (m x n )-dimensional
compressed matrix and 0 < = i < m, 0 < = j < n the non-zero elements
mi,j are mapped via (i x n + j) for row major orientation or
via (i + j x m) for column major orientation to consecutive elements
of the index and value containers, i.e. for elements k =
mi1,j1and k + 1 = mi2,j2
of the container holds i1 < i2 or
(i1 = i2 and j1 < j2) with row major
orientation or j1 < j2 or (j1 = j2 and
i1 < i__2) with column major orientation.
Example
#include <boost/numeric/ublas/matrix_sparse.hpp>
#include <boost/numeric/ublas/io.hpp>
int main () {
using namespace boost::numeric::ublas;
compressed_matrix<double> m (3, 3, 3 * 3);
for (unsigned i = 0; i < m.size1 (); ++ i)
for (unsigned j = 0; j < m.size2 (); ++ j)
m (i, j) = 3 * i + j;
std::cout << m << std::endl;
}
Definition
Defined in the header matrix_sparse.hpp.
Template parameters
Parameter | Description | Default |
---|---|---|
|
The type of object stored in the compressed matrix. |
|
|
Functor describing the storage organization. [1] |
|
|
The index base of the compressed vector. [2] |
|
|
The type of the adapted array for indices. [3] |
|
|
The type of the adapted array for values. [3] |
|
Model of
Matrix .
Type requirements
None, except for those imposed by the requirements of Matrix .
Public base classes
matrix_container<compressed_matrix<T, F, IB, IA, TA> >
Members
Member | Description |
---|---|
|
Allocates a |
|
Allocates a |
|
The copy constructor. |
|
The extended copy constructor. |
|
Reallocates a |
|
Returns the number of rows. |
|
Returns the number of columns. |
|
Returns
the value of the |
|
Returns a reference
of the |
|
The assignment operator. |
|
Assigns a
temporary. May change the compressed matrix |
|
The extended assignment operator. |
|
Assigns a matrix expression to the compressed matrix. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Adds the matrix expression to the compressed matrix. |
|
Adds a matrix expression to the compressed matrix. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Subtracts the matrix expression from the compressed matrix. |
|
Subtracts a matrix expression from the compressed matrix. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Multiplies the compressed matrix with a scalar. |
|
A computed assignment operator. Divides the compressed matrix through a scalar. |
|
Swaps the contents of the compressed matrices. |
|
Inserts the value |
|
Erases the value at
the |
|
Clears the compressed matrix. |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a
|
|
Returns a
|
|
Returns a |
|
Returns a |
|
Returns a
|
|
Returns a
|
|
Returns a |
|
Returns a |
Notes
[1] Supported parameters for the storage
organization are row_major
and column_major
.
[2] Supported parameters for the index base are
0
and 1
at least.
[3] Supported parameters for the adapted array
are unbounded_array<>
, bounded_array<>
and std::vector<>
.
Coordinate Matrix
Description
The templated class coordinate_matrix<T, F, IB, IA, TA>
is the base
container adaptor for compressed matrices. For a (m x n )-dimensional
sorted coordinate matrix and 0 < = i < m, 0 < = j < n the non-zero
elements mi,j are mapped via (i x n + j) for row major
orientation or via (i + j x m) for column major orientation to
consecutive elements of the index and value containers, i.e. for
elements k = mi1,j1 and k + 1 =
mi2,j2 of the container holds i1 <
i2 or (i1 = i2 and j1 < j2) with
row major orientation or j1 < j2 or (j1 =
j2 and i1 < i__2) with column major orientation.
Example
#include <boost/numeric/ublas/matrix_sparse.hpp>
#include <boost/numeric/ublas/io.hpp>
int main () {
using namespace boost::numeric::ublas;
coordinate_matrix<double> m (3, 3, 3 * 3);
for (unsigned i = 0; i < m.size1 (); ++ i)
for (unsigned j = 0; j < m.size2 (); ++ j)
m (i, j) = 3 * i + j;
std::cout << m << std::endl;
}
Definition
Defined in the header matrix_sparse.hpp.
Template parameters
Parameter | Description | Default |
---|---|---|
|
The type of object stored in the coordinate matrix. |
|
|
Functor describing the storage organization. [1] |
|
|
The index base of the coordinate vector. [2] |
|
|
The type of the adapted array for indices. [3] |
|
|
The type of the adapted array for values. [3] |
|
Model of
Matrix .
Type requirements
None, except for those imposed by the requirements of Matrix .
Public base classes
matrix_container<coordinate_matrix<T, F, IB, IA, TA> >
Members
Member | Description |
---|---|
|
Allocates a |
|
Allocates a |
|
The copy constructor. |
|
The extended copy constructor. |
|
Reallocates a |
|
Returns the number of rows. |
|
Returns the number of columns. |
|
Returns
the value of the |
|
Returns a reference
of the |
|
The assignment operator. |
|
Assigns a
temporary. May change the coordinate matrix |
|
The extended assignment operator. |
|
Assigns a matrix expression to the coordinate matrix. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Adds the matrix expression to the coordinate matrix. |
|
Adds a matrix expression to the coordinate matrix. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Subtracts the matrix expression from the coordinate matrix. |
|
Subtracts a matrix expression from the coordinate matrix. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Multiplies the coordinate matrix with a scalar. |
|
A computed assignment operator. Divides the coordinate matrix through a scalar. |
|
Swaps the contents of the coordinate matrices. |
|
Inserts the value |
|
Appends the value |
|
Erases the value at
the |
|
Clears the coordinate matrix. |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a
|
|
Returns a
|
|
Returns a |
|
Returns a |
|
Returns a
|
|
Returns a
|
|
Returns a |
|
Returns a |
Notes
[1] Supported parameters for the storage
organization are row_major
and column_major
.
[2] Supported parameters for the index base are
0
and 1
at least.
[3] Supported parameters for the adapted array
are unbounded_array<>
, bounded_array<>
and std::vector<>
.
Matrix Proxies
Matrix Row
Description
The templated class matrix_row<M>
allows addressing a row of a matrix.
Example
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/matrix_proxy.hpp>
#include <boost/numeric/ublas/io.hpp>
int main () {
using namespace boost::numeric::ublas;
matrix<double> m (3, 3);
for (unsigned i = 0; i < m.size1 (); ++ i) {
matrix_row<matrix<double> > mr (m, i);
for (unsigned j = 0; j < mr.size (); ++ j)
mr (j) = 3 * i + j;
std::cout << mr << std::endl;
}
}
Definition
Defined in the header matrix_proxy.hpp.
Template parameters
Parameter |
Description |
Default |
|
The type of matrix referenced. |
Model of
If the specified row falls outside that of the row index range of the
matrix, then the matrix_row
is not a well formed Vector Expression.
That is, access to an element which is outside of the matrix is
undefined.
Type requirements
None, except for those imposed by the requirements of Vector Expression .
Public base classes
vector_expression<matrix_row<M> >
Members
Member | Description |
---|---|
|
Constructs a sub vector. |
|
Returns the size of the sub vector. |
|
Returns the value of
the |
|
Returns a reference of the
|
|
The assignment operator. |
|
Assigns a temporary.
May change the matrix row |
|
The extended assignment operator. |
|
Assigns a vector expression to the sub vector. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Adds the vector expression to the sub vector. |
|
Adds a vector expression to the sub vector. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Subtracts the vector expression from the sub vector. |
|
Subtracts a vector expression from the sub vector. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Multiplies the sub vector with a scalar. |
|
A computed assignment operator. Divides the sub vector through a scalar. |
|
Swaps the contents of the sub vectors. |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a
|
|
Returns a
|
|
Returns a |
|
Returns a |
Projections
The free row
functions support the construction of matrix rows.
template<class M>
matrix_row<M> row (M &data, std::size_t i);
template<class M>
const matrix_row<const M> row (const M &data, std::size_t i);
Defined in the header matrix_proxy.hpp.
-
M
is a model of Matrix Expression .
Linear depending from the size of the row.
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/matrix_proxy.hpp>
#include <boost/numeric/ublas/io.hpp>
int main () {
using namespace boost::numeric::ublas;
matrix<double> m (3, 3);
for (unsigned i = 0; i < m.size1 (); ++ i) {
for (unsigned j = 0; j < m.size2 (); ++ j)
row (m, i) (j) = 3 * i + j;
std::cout << row (m, i) << std::endl;
}
}
Matrix Column
Description
The templated class matrix_column<M>
allows addressing a column of a
matrix.
Example
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/matrix_proxy.hpp>
#include <boost/numeric/ublas/io.hpp>
int main () {
using namespace boost::numeric::ublas;
matrix<double> m (3, 3);
for (unsigned j = 0; j < m.size2 (); ++ j) {
matrix_column<matrix<double> > mc (m, j);
for (unsigned i = 0; i < mc.size (); ++ i)
mc (i) = 3 * i + j;
std::cout << mc << std::endl;
}
}
Definition
Defined in the header matrix_proxy.hpp.
Template parameters
Parameter |
Description |
Default |
|
The type of matrix referenced. |
Model of
If the specified column falls outside that of the column index range of
the matrix, then the matrix_column
is not a well formed Vector
Expression. That is, access to an element which is outside of the matrix
is undefined.
Type requirements
None, except for those imposed by the requirements of Vector Expression .
Public base classes
vector_expression<matrix_column<M> >
Members
Member | Description |
---|---|
|
Constructs a sub vector. |
|
Returns the size of the sub vector. |
|
Returns the value of
the |
|
Returns a reference of the
|
|
The assignment operator. |
|
Assigns a
temporary. May change the matrix column |
|
The extended assignment operator. |
|
Assigns a vector expression to the sub vector. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Adds the vector expression to the sub vector. |
|
Adds a vector expression to the sub vector. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Subtracts the vector expression from the sub vector. |
|
Subtracts a vector expression from the sub vector. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Multiplies the sub vector with a scalar. |
|
A computed assignment operator. Divides the sub vector through a scalar. |
|
Swaps the contents of the sub vectors. |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a
|
|
Returns a
|
|
Returns a |
|
Returns a |
Projections
The free column
functions support the construction of matrix columns.
template<class M>
matrix_column<M> column (M &data, std::size_t j);
template<class M>
const matrix_column<const M> column (const M &data, std::size_t j);
Defined in the header matrix_proxy.hpp.
-
M
is a model of Matrix Expression .
Linear depending from the size of the column.
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/matrix_proxy.hpp>
#include <boost/numeric/ublas/io.hpp>
int main () {
using namespace boost::numeric::ublas;
matrix<double> m (3, 3);
for (unsigned j = 0; j < m.size2 (); ++ j) {
for (unsigned i = 0; i < m.size1 (); ++ i)
column (m, j) (i) = 3 * i + j;
std::cout << column (m, j) << std::endl;
}
}
Vector Range
Description
The templated class matrix_vector_range<M>
allows addressing a sub
vector of a matrix.
Example
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/matrix_proxy.hpp>
#include <boost/numeric/ublas/io.hpp>
int main () {
using namespace boost::numeric::ublas;
matrix<double> m (3, 3);
for (unsigned i = 0; i < m.size1 (); ++ i)
for (unsigned j = 0; j < m.size2 (); ++ j)
m (i, j) = 3 * i + j;
matrix_vector_range<matrix<double> > mvr (m, range (0, 3), range (0, 3));
std::cout << mvr << std::endl;
}
Definition
Defined in the header matrix_proxy.hpp.
Template parameters
Parameter |
Description |
Default |
|
The type of matrix referenced. |
Model of
If the specified ranges fall outside that of the index range of the
matrix, then the matrix_vector_range
is not a well formed Vector
Expression. That is, access to an element which is outside of the matrix
is undefined.
Type requirements
None, except for those imposed by the requirements of Vector Expression .
Public base classes
vector_expression<matrix_vector_range<M> >
Members
Member | Description |
---|---|
|
Constructs a sub vector. |
|
Returns the size of the sub vector. |
|
Returns the value of
the |
|
Returns a reference of the
|
|
The assignment operator. |
|
Assigns a temporary. May change the matrix vector range |
|
The extended assignment operator. |
|
Assigns a vector expression to the sub vector. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Adds the vector expression to the sub vector. |
|
Adds a vector expression to the sub vector. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Subtracts the vector expression from the sub vector. |
|
Subtracts a vector expression from the sub vector. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Multiplies the sub vector with a scalar. |
|
A computed assignment operator. Divides the sub vector through a scalar. |
|
Swaps the contents of the sub vectors. |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a
|
|
Returns a
|
|
Returns a |
|
Returns a |
Vector Slice
Description
The templated class matrix_vector_slice<M>
allows addressing a sliced
sub vector of a matrix.
Example
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/matrix_proxy.hpp>
#include <boost/numeric/ublas/io.hpp>
int main () {
using namespace boost::numeric::ublas;
matrix<double> m (3, 3);
for (unsigned i = 0; i < m.size1 (); ++ i)
for (unsigned j = 0; j < m.size2 (); ++ j)
m (i, j) = 3 * i + j;
matrix_vector_slice<matrix<double> > mvs (m, slice (0, 1, 3), slice (0, 1, 3));
std::cout << mvs << std::endl;
}
Definition
Defined in the header matrix_proxy.hpp.
Template parameters
Parameter |
Description |
Default |
|
The type of matrix referenced. |
Model of
If the specified slices fall outside that of the index range of the
matrix, then the matrix_vector_slice
is not a well formed Vector
Expression. That is, access to an element which is outside of the matrix
is undefined.
Type requirements
None, except for those imposed by the requirements of Vector Expression .
Public base classes
vector_expression<matrix_vector_slice<M> >
Members
Member | Description |
---|---|
|
Constructs a sub vector. |
|
Returns the size of the sub vector. |
|
Returns the value of
the |
|
Returns a reference of the
|
|
The assignment operator. |
|
Assigns a temporary. May change the matrix vector slice |
|
The extended assignment operator. |
|
Assigns a vector expression to the sub vector. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Adds the vector expression to the sub vector. |
|
Adds a vector expression to the sub vector. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Subtracts the vector expression from the sub vector. |
|
Subtracts a vector expression from the sub vector. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Multiplies the sub vector with a scalar. |
|
A computed assignment operator. Divides the sub vector through a scalar. |
|
Swaps the contents of the sub vectors. |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a
|
|
Returns a
|
|
Returns a |
|
Returns a |
Matrix Range
Description
The templated class matrix_range<M>
allows addressing a sub matrix of
a matrix.
Example
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/matrix_proxy.hpp>
#include <boost/numeric/ublas/io.hpp>
int main () {
using namespace boost::numeric::ublas;
matrix<double> m (3, 3);
matrix_range<matrix<double> > mr (m, range (0, 3), range (0, 3));
for (unsigned i = 0; i < mr.size1 (); ++ i)
for (unsigned j = 0; j < mr.size2 (); ++ j)
mr (i, j) = 3 * i + j;
std::cout << mr << std::endl;
}
Definition
Defined in the header matrix_proxy.hpp.
Template parameters
Parameter |
Description |
Default |
|
The type of matrix referenced. |
Model of
If the specified ranges fall outside that of the index range of the
matrix, then the matrix_range
is not a well formed Matrix Expression.
That is, access to an element which is outside of the matrix is
undefined.
Type requirements
None, except for those imposed by the requirements of Matrix Expression .
Public base classes
matrix_expression<matrix_range<M> >
Members
Member | Description |
---|---|
|
Constructs a sub matrix. |
|
Returns the index of the first row. |
|
Returns the number of rows. |
|
Returns the index of the first column. |
|
Returns the number of columns. |
|
Returns
the value of the |
|
Returns a reference
of the |
|
The assignment operator. |
|
Assigns a
temporary. May change the matrix range |
|
The extended assignment operator. |
|
Assigns a matrix expression to the sub matrix. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Adds the matrix expression to the sub matrix. |
|
Adds a matrix expression to the sub matrix. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Subtracts the matrix expression from the sub matrix. |
|
Subtracts a matrix expression from the sub matrix. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Multiplies the sub matrix with a scalar. |
|
A computed assignment operator. Divides the sub matrix through a scalar. |
|
Swaps the contents of the sub matrices. |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a
|
|
Returns a
|
|
Returns a |
|
Returns a |
|
Returns a
|
|
Returns a
|
|
Returns a |
|
Returns a |
Simple Projections
The free subrange
functions support the construction of matrix ranges.
template<class M>
matrix_range<M> subrange (M &data,
M::size_type start1, M::size_type stop1, M::size_type start2, M::size_type, stop2);
template<class M>
const matrix_range<const M> subrange (const M &data,
M::size_type start1, M::size_type stop1, M::size_type start2, M::size_type, stop2);
Generic Projections
The free project
functions support the construction of matrix ranges.
Existing matrix_range’s can be composed with further ranges. The
resulting ranges are computed using this existing ranges' `compose
function.
template<class M>
matrix_range<M> project (M &data, const range &r1, const range &r2);
template<class M>
const matrix_range<const M> project (const M &data, const range &r1, const range &r2);
template<class M>
matrix_range<M> project (matrix_range<M> &data, const range &r1, const range &r2);
template<class M>
const matrix_range<M> project (const matrix_range<M> &data, const range &r1, const range &r2);
Defined in the header matrix_proxy.hpp.
-
M
is a model of Matrix Expression .
Quadratic depending from the size of the ranges.
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/matrix_proxy.hpp>
#include <boost/numeric/ublas/io.hpp>
int main () {
using namespace boost::numeric::ublas;
matrix<double> m (3, 3);
for (unsigned i = 0; i < m.size1 (); ++ i)
for (unsigned j = 0; j < m.size2 (); ++ j)
project (m, range (0, 3), range (0, 3)) (i, j) = 3 * i + j;
std::cout << project (m, range (0, 3), range (0, 3)) << std::endl;
}
Matrix Slice
Description
The templated class matrix_slice<M>
allows addressing a sliced sub
matrix of a matrix.
Example
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/matrix_proxy.hpp>
#include <boost/numeric/ublas/io.hpp>
int main () {
using namespace boost::numeric::ublas;
matrix<double> m (3, 3);
matrix_slice<matrix<double> > ms (m, slice (0, 1, 3), slice (0, 1, 3));
for (unsigned i = 0; i < ms.size1 (); ++ i)
for (unsigned j = 0; j < ms.size2 (); ++ j)
ms (i, j) = 3 * i + j;
std::cout << ms << std::endl;
}
Definition
Defined in the header matrix_proxy.hpp.
Template parameters
Parameter |
Description |
Default |
|
The type of matrix referenced. |
Model of
If the specified slices fall outside that of the index range of the
matrix, then the matrix_slice
is not a well formed Matrix Expression.
That is, access to an element which is outside of the matrix is
undefined.
Type requirements
None, except for those imposed by the requirements of Matrix Expression .
Public base classes
matrix_expression<matrix_slice<M> >
Members
Member | Description |
---|---|
|
Constructs a sub matrix. |
|
Returns the number of rows. |
|
Returns the number of columns. |
|
Returns
the value of the |
|
Returns a reference
of the |
|
The assignment operator. |
|
Assigns a
temporary. May change the matrix slice |
|
The extended assignment operator. |
|
Assigns a matrix expression to the sub matrix. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Adds the matrix expression to the sub matrix. |
|
Adds a matrix expression to the sub matrix. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Subtracts the matrix expression from the sub matrix. |
|
Subtracts a matrix expression from the sub matrix. Left and right hand side of the assignment should be independent. |
|
A computed assignment operator. Multiplies the sub matrix with a scalar. |
|
A computed assignment operator. Multiplies the sub matrix through a scalar. |
|
Swaps the contents of the sub matrices. |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a
|
|
Returns a
|
|
Returns a |
|
Returns a |
|
Returns a
|
|
Returns a
|
|
Returns a |
|
Returns a |
Simple Projections
The free subslice
functions support the construction of matrix slices.
template<class M>
matrix_slice<M> subslice (M &data,
M::size_type start1, M::difference_type stride1, M::size_type size1,
M::size_type start2, M::difference_type stride2, M::size_type size2);
template<class M>
const matrix_slice<const M> subslice (const M &data,
M::size_type start1, M::difference_type stride1, M::size_type size1,
M::size_type start2, M::difference_type stride2, M::size_type size2);
Generic Projections
The free project
functions support the construction of matrix slices.
Existing matrix_slice
's can be composed with further ranges or slices.
The resulting slices are computed using this existing slices' compose
function.
template<class M>
matrix_slice<M> project (M &data, const slice &s1, const slice &s2);
template<class M>
const matrix_slice<const M> project (const M &data, const slice &s1, const slice &s2);
template<class M>
matrix_slice<M> project (matrix_slice<M> &data, const range &r1, const range &r2);
template<class M>
const matrix_slice<M> project (const matrix_slice<M> &data, const range &r1, const range &r2);
template<class M>
matrix_slice<M> project (matrix_slice<M> &data, const slice &s1, const slice &s2);
template<class M>
const matrix_slice<M> project (const matrix_slice<M> &data, const slice &s1, const slice &s2);
Defined in the header matrix_proxy.hpp.
-
M
is a model of Matrix Expression .
Quadratic depending from the size of the slices.
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/matrix_proxy.hpp>
#include <boost/numeric/ublas/io.hpp>
int main () {
using namespace boost::numeric::ublas;
matrix<double> m (3, 3);
for (unsigned i = 0; i < m.size1 (); ++ i)
for (unsigned j = 0; j < m.size2 (); ++ j)
project (m, slice (0, 1, 3), slice (0, 1, 3)) (i, j) = 3 * i + j;
std::cout << project (m, slice (0, 1, 3), slice (0, 1, 3)) << std::endl;
}
Matrix Expressions
Description
The templated class matrix_expression<E>
is required to be a public
base of all classes which model the Matrix Expression concept.
Definition
Defined in the header expression_types.hpp.
Template parameters
Parameter |
Description |
Default |
|
The type of the matrix expression. |
|
Model of
None. Not a Matrix Expression
Type requirements
None.
Public base classes
None.
Members
Member | Description |
---|---|
|
Returns a |
|
Returns a reference of the expression. |
Notes
The operator[]
, row
, column
, range
, slice
and project
functions have been removed. Use the free functions defined in
matrix proxy instead.
Matrix Container
Description
The templated class matrix_container<C>
is required to be a public
base of all classes which model the Matrix concept. This includes the
class matrix
itself.
Definition
Defined in the header expression_types.hpp.
Template parameters
Parameter |
Description |
Default |
|
The type of the matrix expression. |
|
Model of
None. Not a Matrix Expression OR Matrix
Type requirements
None.
Public base classes
matrix_expression<C>
Members
Member | Description |
---|---|
|
Returns a |
|
Returns a reference of the container. |
Matrix References
Reference
The templated class matrix_reference<E>
contains a reference to a
matrix expression.
Defined in the header matrix_expression.hpp.
Parameter |
Description |
Default |
|
The type of the matrix expression. |
|
None, except for those imposed by the requirements of Matrix Expression .
matrix_expression<matrix_reference<E> >
Member | Description |
---|---|
|
Constructs a constant reference of the expression. |
|
Resizes the expression to hold
at most |
|
Returns the number of rows. |
|
Returns the number of columns. |
|
Returns
the value of the |
|
Returns a reference
of the |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a
|
|
Returns a
|
|
Returns a |
|
Returns a |
|
Returns a
|
|
Returns a
|
|
Returns a |
|
Returns a |
Matrix Operations
Unary Operation Description
The templated classes matrix_unary1<E, F>
and matrix_unary2<E, F>
describe unary matrix operations.
Defined in the header matrix_expression.hpp.
Parameter |
Description |
Default |
|
The type of the matrix expression. |
|
|
The type of the operation. |
|
None, except for those imposed by the requirements of Matrix Expression .
matrix_expression<matrix_unary1<E, F> >
and
matrix_expression<matrix_unary2<E, F> >
resp.
Member | Description |
---|---|
|
Constructs a description of the expression. |
|
Constructs a description of the expression. |
|
Returns the number of rows. |
|
Returns the number of columns. |
|
Returns
the value of the |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a
|
|
Returns a
|
|
Returns a
|
|
Returns a
|
Unary Operations
template<class E, class F>
struct matrix_unary1_traits {
typedef matrix_unary1<typename E::const_closure_type, F> expression_type;
typedef expression_type result_type;
};
// (- m) [i] [j] = - m [i] [j]
template<class E>
typename matrix_unary1_traits<E, scalar_negate<typename E::value_type> >::result_type
operator - (const matrix_expression<E> &e);
// (conj m) [i] [j] = conj (m [i] [j])
template<class E>
typename matrix_unary1_traits<E, scalar_conj<typename E::value_type> >::result_type
conj (const matrix_expression<E> &e);
// (real m) [i] [j] = real (m [i] [j])
template<class E>
typename matrix_unary1_traits<E, scalar_real<typename E::value_type> >::result_type
real (const matrix_expression<E> &e);
// (imag m) [i] [j] = imag (m [i] [j])
template<class E>
typename matrix_unary1_traits<E, scalar_imag<typename E::value_type> >::result_type
imag (const matrix_expression<E> &e);
template<class E, class F>
struct matrix_unary2_traits {
typedef matrix_unary2<typename E::const_closure_type, F> expression_type;
typedef expression_type result_type;
};
// (trans m) [i] [j] = m [j] [i]
template<class E>
typename matrix_unary2_traits<E, scalar_identity<typename E::value_type> >::result_type
trans (const matrix_expression<E> &e);
// (herm m) [i] [j] = conj (m [j] [i])
template<class E>
typename matrix_unary2_traits<E, scalar_conj<typename E::value_type> >::result_type
herm (const matrix_expression<E> &e);
operator -
computes the additive inverse of a matrix expression.
conj
computes the complex conjugate of a matrix expression. real
and
imag
compute the real and imaginary parts of a matrix expression.
trans
computes the transpose of a matrix expression. herm
computes
the hermitian, i.e. the complex conjugate of the transpose of a matrix
expression.
Defined in the header matrix_expression.hpp.
-
E
is a model of Matrix Expression .
None.
Quadratic depending from the size of the matrix expression.
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>
int main () {
using namespace boost::numeric::ublas;
matrix<std::complex<double> > m (3, 3);
for (unsigned i = 0; i < m.size1 (); ++ i)
for (unsigned j = 0; j < m.size2 (); ++ j)
m (i, j) = std::complex<double> (3 * i + j, 3 * i + j);
std::cout << - m << std::endl;
std::cout << conj (m) << std::endl;
std::cout << real (m) << std::endl;
std::cout << imag (m) << std::endl;
std::cout << trans (m) << std::endl;
std::cout << herm (m) << std::endl;
}
Binary Operation Description
The templated class matrix_binary<E1, E2, F>
describes a binary matrix
operation.
Defined in the header matrix_expression.hpp.
Parameter |
Description |
Default |
|
The type of the first matrix expression. |
|
|
The type of the second matrix expression. |
|
|
The type of the operation. |
None, except for those imposed by the requirements of Matrix Expression .
matrix_expression<matrix_binary<E1, E2, F> >
.
Member | Description |
---|---|
|
Constructs a description of the expression. |
|
Returns the number of rows. |
|
Returns the number of columns. |
|
Returns
the value of the |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a
|
|
Returns a
|
|
Returns a
|
|
Returns a
|
Binary Operations
template<class E1, class E2, class F>
struct matrix_binary_traits {
typedef matrix_binary<typename E1::const_closure_type,
typename E2::const_closure_type, F> expression_type;
typedef expression_type result_type;
};
// (m1 + m2) [i] [j] = m1 [i] [j] + m2 [i] [j]
template<class E1, class E2>
typename matrix_binary_traits<E1, E2, scalar_plus<typename E1::value_type,
typename E2::value_type> >::result_type
operator + (const matrix_expression<E1> &e1,
const matrix_expression<E2> &e2);
// (m1 - m2) [i] [j] = m1 [i] [j] - m2 [i] [j]
template<class E1, class E2>
typename matrix_binary_traits<E1, E2, scalar_minus<typename E1::value_type,
typename E2::value_type> >::result_type
operator - (const matrix_expression<E1> &e1,
const matrix_expression<E2> &e2);
operator +
computes the sum of two matrix expressions. operator -
computes the difference of two matrix expressions.
Defined in the header matrix_expression.hpp.
-
E1
is a model of Matrix Expression . -
E2
is a model of Matrix Expression .
-
e1 ().size1 () == e2 ().size1 ()
-
e1 ().size2 () == e2 ().size2 ()
Quadratic depending from the size of the matrix expressions.
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>
int main () {
using namespace boost::numeric::ublas;
matrix<double> m1 (3, 3), m2 (3, 3);
for (unsigned i = 0; i < std::min (m1.size1 (), m2.size1 ()); ++ i)
for (unsigned j = 0; j < std::min (m1.size2 (), m2.size2 ()); ++ j)
m1 (i, j) = m2 (i, j) = 3 * i + j;
std::cout << m1 + m2 << std::endl;
std::cout << m1 - m2 << std::endl;
}
Scalar Matrix Operation Description
The templated classes matrix_binary_scalar1<E1, E2, F>
and
matrix_binary_scalar2<E1, E2, F>
describe binary operations between a
scalar and a matrix.
Defined in the header matrix_expression.hpp.
Parameter |
Description |
Default |
|
The type of the scalar expression. |
|
|
The type of the matrix expression. |
|
|
The type of the operation. |
None, except for those imposed by the requirements of Matrix Expression .
matrix_expression<matrix_binary_scalar1<E1, E2, F> >
and
matrix_expression<matrix_binary_scalar2<E1, E2, F> >
resp.
Member | Description |
---|---|
|
Constructs a description of the expression. |
|
Constructs a description of the expression. |
|
Returns the number of rows. |
|
Returns the number of columns. |
|
Returns
the value of the |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a
|
|
Returns a
|
|
Returns a
|
|
Returns a
|
Scalar Matrix Operations
template<class T1, class E2, class F>
struct matrix_binary_scalar1_traits {
typedef matrix_binary_scalar1<scalar_const_reference<T1>,
typename E2::const_closure_type, F> expression_type;
typedef expression_type result_type;
};
// (t * m) [i] [j] = t * m [i] [j]
template<class T1, class E2>
typename matrix_binary_scalar1_traits<T1, E2, scalar_multiplies<T1, typename E2::value_type> >::result_type
operator * (const T1 &e1,
const matrix_expression<E2> &e2);
template<class E1, class T2, class F>
struct matrix_binary_scalar2_traits {
typedef matrix_binary_scalar2<typename E1::const_closure_type,
scalar_const_reference<T2>, F> expression_type;
typedef expression_type result_type;
};
// (m * t) [i] [j] = m [i] [j] * t
template<class E1, class T2>
typename matrix_binary_scalar2_traits<E1, T2, scalar_multiplies<typename E1::value_type, T2> >::result_type
operator * (const matrix_expression<E1> &e1,
const T2 &e2);
// (m / t) [i] [j] = m [i] [j] / t
template<class E1, class T2>
typename matrix_binary_scalar2_traits<E1, T2, scalar_divides<typename E1::value_type, T2> >::result_type
operator / (const matrix_expression<E1> &e1,
const T2 &e2);
operator *
computes the product of a scalar and a matrix expression.
operator /
multiplies the matrix with the reciprocal of the scalar.
Defined in the header matrix_expression.hpp.
-
T1/T2
is a model of Scalar Expression . -
E2/E1
is a model of Matrix Expression .
None.
Quadratic depending from the size of the matrix expression.
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>
int main () {
using namespace boost::numeric::ublas;
matrix<double> m (3, 3);
for (unsigned i = 0; i < m.size1 (); ++ i)
for (unsigned j = 0; j < m.size2 (); ++ j)
m (i, j) = 3 * i + j;
std::cout << 2.0 * m << std::endl;
std::cout << m * 2.0 << std::endl;
}
Matrix Vector Operations
Binary Operation Description
The templated classes matrix_vector_binary1<E1, E2, F>
and
matrix_vector_binary2<E1, E2, F>
describe binary matrix vector
operations.
Defined in the header matrix_expression.hpp.
Parameter |
Description |
Default |
|
The type of the matrix or vector expression. |
|
|
The type of the vector or matrix expression. |
|
|
The type of the operation. |
None, except for those imposed by the requirements of Vector Expression .
vector_expression<matrix_vector_binary1<E1, E2, F> >
and
vector_expression<matrix_vector_binary2<E1, E2, F> >
resp.
Member | Description |
---|---|
|
Constructs a description of the expression. |
|
Constructs a description of the expression. |
|
Returns the size of the expression. |
|
Returns the value of
the |
|
Returns a |
|
Returns a |
|
Returns a
|
|
Returns a
|
Binary Operations
template<class T1, class E1, class T2, class E2>
struct matrix_vector_binary1_traits {
typedef row_major_tag dispatch_category;
typedef typename promote_traits<T1, T2>::promote_type promote_type;
typedef matrix_vector_binary1<typename E1::const_closure_type,
typename E2::const_closure_type,
matrix_vector_prod1<T1, T2, promote_type> > expression_type;
typedef expression_type result_type;
};
template<class E1, class E2>
typename matrix_vector_binary1_traits<typename E1::value_type, E1,
typename E2::value_type, E2>::result_type
prod (const matrix_expression<E1> &e1,
const vector_expression<E2> &e2,
row_major_tag);
// Dispatcher
template<class E1, class E2>
typename matrix_vector_binary1_traits<typename E1::value_type, E1,
typename E2::value_type, E2>::result_type
prod (const matrix_expression<E1> &e1,
const vector_expression<E2> &e2);
template<class E1, class E2>
typename matrix_vector_binary1_traits<typename type_traits<typename E1::value_type>::precision_type, E1,
typename type_traits<typename E2::value_type>::precision_type, E2>::result_type
prec_prod (const matrix_expression<E1> &e1,
const vector_expression<E2> &e2,
row_major_tag);
// Dispatcher
template<class E1, class E2>
typename matrix_vector_binary1_traits<typename type_traits<typename E1::value_type>::precision_type, E1,
typename type_traits<typename E2::value_type>::precision_type, E2>::result_type
prec_prod (const matrix_expression<E1> &e1,
const vector_expression<E2> &e2);
template<class V, class E1, class E2>
V
prod (const matrix_expression<E1> &e1,
const vector_expression<E2> &e2);
template<class V, class E1, class E2>
V
prec_prod (const matrix_expression<E1> &e1,
const vector_expression<E2> &e2);
template<class T1, class E1, class T2, class E2>
struct matrix_vector_binary2_traits {
typedef column_major_tag dispatch_category;
typedef typename promote_traits<T1, T2>::promote_type promote_type;
typedef matrix_vector_binary2<typename E1::const_closure_type,
typename E2::const_closure_type,
matrix_vector_prod2<T1, T2, promote_type> > expression_type;
typedef expression_type result_type;
};
template<class E1, class E2>
typename matrix_vector_binary2_traits<typename E1::value_type, E1,
typename E2::value_type, E2>::result_type
prod (const vector_expression<E1> &e1,
const matrix_expression<E2> &e2,
column_major_tag);
// Dispatcher
template<class E1, class E2>
typename matrix_vector_binary2_traits<typename E1::value_type, E1,
typename E2::value_type, E2>::result_type
prod (const vector_expression<E1> &e1,
const matrix_expression<E2> &e2);
template<class E1, class E2>
typename matrix_vector_binary2_traits<typename type_traits<typename E1::value_type>::precision_type, E1,
typename type_traits<typename E2::value_type>::precision_type, E2>::result_type
prec_prod (const vector_expression<E1> &e1,
const matrix_expression<E2> &e2,
column_major_tag);
// Dispatcher
template<class E1, class E2>
typename matrix_vector_binary2_traits<typename type_traits<typename E1::value_type>::precision_type, E1,
typename type_traits<typename E2::value_type>::precision_type, E2>::result_type
prec_prod (const vector_expression<E1> &e1,
const matrix_expression<E2> &e2);
template<class V, class E1, class E2>
V
prod (const vector_expression<E1> &e1,
const matrix_expression<E2> &e2);
template<class V, class E1, class E2>
V
prec_prod (const vector_expression<E1> &e1,
const matrix_expression<E2> &e2);
prod
computes the product of the matrix and the vector expression.
prec_prod
computes the double precision product of the matrix and the
vector expression.
Defined in the header matrix_expression.hpp.
-
E1
is a model of Matrix Expression or Vector Expression . -
E2
is a model of Vector Expression or Matrix Expression .
-
e1 ().size2 () == e2 ().size ()
-
e1 ().size () == e2 ().size1 ()
Quadratic depending from the size of the matrix expression.
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>
int main () {
using namespace boost::numeric::ublas;
matrix<double> m (3, 3);
vector<double> v (3);
for (unsigned i = 0; i < std::min (m.size1 (), v.size ()); ++ i) {
for (unsigned j = 0; j < m.size2 (); ++ j)
m (i, j) = 3 * i + j;
v (i) = i;
}
std::cout << prod (m, v) << std::endl;
std::cout << prod (v, m) << std::endl;
}
Triangular Solver
template<class E1, class E2>
struct matrix_vector_solve_traits {
typedef typename promote_traits<typename E1::value_type, typename E2::value_type>::promote_type promote_type;
typedef vector<promote_type> result_type;
};
template<class E1, class E2>
void inplace_solve (const matrix_expression<E1> &e1,
E2 &e2,
lower_tag,
vector_tag);
template<class E1, class E2>
void inplace_solve (const matrix_expression<E1> &e1,
E2 &e2,
upper_tag,
vector_tag);
template<class E1, class E2>
void inplace_solve (const matrix_expression<E1> &e1,
E2 &e2,
unit_lower_tag,
vector_tag);
template<class E1, class E2>
void inplace_solve (const matrix_expression<E1> &e1,
E2 &e2,
unit_upper_tag,
vector_tag);
template<class E1, class E2, class C>
typename matrix_vector_solve_traits<E1, E2>::result_type
solve (const matrix_expression<E1> &e1,
const vector_expression<E2> &e2,
C);
template<class E1, class E2>
void inplace_solve (E1 &e1,
const matrix_expression<E2> &e2,
vector_tag,
lower_tag);
template<class E1, class E2>
void inplace_solve (E1 &e1,
const matrix_expression<E2> &e2,
vector_tag,
upper_tag);
template<class E1, class E2>
void inplace_solve (E1 &e1,
const matrix_expression<E2> &e2,
vector_tag,
unit_lower_tag);
template<class E1, class E2>
void inplace_solve (E1 &e1,
const matrix_expression<E2> &e2,
vector_tag,
unit_upper_tag);
template<class E1, class E2, class C>
typename matrix_vector_solve_traits<E1, E2>::result_type
solve (const vector_expression<E1> &e1,
const matrix_expression<E2> &e2,
C);
solve
solves a linear equation for lower or upper (unit) triangular
matrices.
Defined in the header triangular.hpp.
-
E1
is a model of Matrix Expression or Vector Expression . -
E2
is a model of Vector Expression or Matrix Expression .
-
e1 ().size1 () == e1 ().size2 ()
-
e1 ().size2 () == e2 ().size ()
-
e1 ().size () == e2 ().size1 ()
-
e2 ().size1 () == e2 ().size2 ()
Quadratic depending from the size of the matrix expression.
#include <boost/numeric/ublas/triangular.hpp>
#include <boost/numeric/ublas/io.hpp>
int main () {
using namespace boost::numeric::ublas;
matrix<double> m (3, 3);
vector<double> v (3);
for (unsigned i = 0; i < std::min (m.size1 (), v.size ()); ++ i) {
for (unsigned j = 0; j <= i; ++ j)
m (i, j) = 3 * i + j + 1;
v (i) = i;
}
std::cout << solve (m, v, lower_tag ()) << std::endl;
std::cout << solve (v, m, lower_tag ()) << std::endl;
}
Matrix Matrix Operations
Binary Operation Description
The templated class matrix_matrix_binary<E1, E2, F>
describes a binary
matrix operation.
Defined in the header matrix_expression.hpp.
Parameter |
Description |
Default |
|
The type of the first matrix expression. |
|
|
The type of the second matrix expression. |
|
|
The type of the operation. |
None, except for those imposed by the requirements of Matrix Expression .
matrix_expression<matrix_matrix_binary<E1, E2, F> >
.
Member | Description |
---|---|
|
Constructs a description of the expression. |
|
Returns the number of rows. |
|
Returns the number of columns. |
|
Returns
the value of the |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a
|
|
Returns a
|
|
Returns a
|
|
Returns a
|
Binary Operations
template<class T1, class E1, class T2, class E2>
struct matrix_matrix_binary_traits {
typedef unknown_orientation_tag dispatch_category;
typedef typename promote_traits<T1, T2>::promote_type promote_type;
typedef matrix_matrix_binary<typename E1::const_closure_type,
typename E2::const_closure_type,
matrix_matrix_prod<T1, T2, promote_type> > expression_type;
typedef expression_type result_type;
};
template<class E1, class E2>
typename matrix_matrix_binary_traits<typename E1::value_type, E1,
typename E2::value_type, E2>::result_type
prod (const matrix_expression<E1> &e1,
const matrix_expression<E2> &e2,
unknown_orientation_tag);
// Dispatcher
template<class E1, class E2>
typename matrix_matrix_binary_traits<typename E1::value_type, E1,
typename E2::value_type, E2>::result_type
prod (const matrix_expression<E1> &e1,
const matrix_expression<E2> &e2);
template<class E1, class E2>
typename matrix_matrix_binary_traits<typename type_traits<typename E1::value_type>::precision_type, E1,
typename type_traits<typename E2::value_type>::precision_type, E2>::result_type
prec_prod (const matrix_expression<E1> &e1,
const matrix_expression<E2> &e2,
unknown_orientation_tag);
// Dispatcher
template<class E1, class E2>
typename matrix_matrix_binary_traits<typename type_traits<typename E1::value_type>::precision_type, E1,
typename type_traits<typename E2::value_type>::precision_type, E2>::result_type
prec_prod (const matrix_expression<E1> &e1,
const matrix_expression<E2> &e2);
template<class M, class E1, class E2>
M
prod (const matrix_expression<E1> &e1,
const matrix_expression<E2> &e2);
template<class M, class E1, class E2>
M
prec_prod (const matrix_expression<E1> &e1,
const matrix_expression<E2> &e2);
prod
computes the product of the matrix expressions. prec_prod
computes the double precision product of the matrix expressions.
Defined in the header matrix_expression.hpp.
-
E1
is a model of Matrix Expression . -
E2
is a model of Matrix Expression .
-
e1 ().size2 () == e2 ().size1 ()
Cubic depending from the size of the matrix expression.
#include <boost/numeric/ublas/matrix.hpp> #include <boost/numeric/ublas/io.hpp> int main () { using namespace boost::numeric::ublas; matrix<double> m1 (3, 3), m2 (3, 3); for (unsigned i = 0; i < std::min (m1.size1 (), m2.size1 ()); ++ i) for (unsigned j = 0; j < std::min (m1.size2 (), m2.size2 ()); ++ j) m1 (i, j) = m2 (i, j) = 3 * i + j; std::cout << prod (m1, m2) << std::endl; }
Triangular Solvers
template<class E1, class E2>
struct matrix_matrix_solve_traits {
typedef typename promote_traits<typename E1::value_type, typename E2::value_type>::promote_type promote_type;
typedef matrix<promote_type> result_type;
};
template<class E1, class E2>
void inplace_solve (const matrix_expression<E1> &e1,
E2 &e2,
lower_tag,
matrix_tag);
template<class E1, class E2>
void inplace_solve (const matrix_expression<E1> &e1,
E2 &e2,
upper_tag,
matrix_tag);
template<class E1, class E2>
void inplace_solve (const matrix_expression<E1> &e1,
E2 &e2,
unit_lower_tag,
matrix_tag);
template<class E1, class E2>
void inplace_solve (const matrix_expression<E1> &e1,
E2 &e2,
unit_upper_tag,
matrix_tag);
template<class E1, class E2, class C>
typename matrix_matrix_solve_traits<E1, E2>::result_type
solve (const matrix_expression<E1> &e1,
const matrix_expression<E2> &e2,
C);
solve
solves a linear equation for lower or upper (unit) triangular
matrices.
Defined in the header triangular.hpp.
-
E1
is a model of Matrix Expression . -
E2
is a model of Matrix Expression .
-
e1 ().size1 () == e1 ().size2 ()
-
e1 ().size2 () == e2 ().size1 ()
Cubic depending from the size of the matrix expressions.
#include <boost/numeric/ublas/triangular.hpp>
#include <boost/numeric/ublas/io.hpp>
int main () {
using namespace boost::numeric::ublas;
matrix<double> m1 (3, 3), m2 (3, 3);
for (unsigned i = 0; i < std::min (m1.size1 (), m2.size1 ()); ++ i)
for (unsigned j = 0; j <= i; ++ j)
m1 (i, j) = m2 (i, j) = 3 * i + j + 1;
std::cout << solve (m1, m2, lower_tag ()) << std::endl;
}
Tensor
Tensor Idealogy
tensor_index<value_t, storage_t, array_t, N>
Description
The template class tensor_index
decorates the
tensor template class with indices for
tensor contraction.
Example
#include <boost/numeric/ublas/tensor/einstein.hpp>
int main () {
using namespace boost::numeric::ublas;
shape s{4,3,2};
for (auto i = 0u; i < s.size(); ++i) {
std::cout << s.at(i) << std::endl;
}
}
Definition
Defined in the header tensor/tensor_einstein.hpp.
Public base classes
None.
Template parameters
Parameter |
Description |
|
|
The type of object stored in the tensor. |
|
|
Storage organization of the tensor. |
|
|
The type of the storage array of the tensor. |
|
|
Number of indices provided. |
Tensor Abstract
-
Tensor
a. Description
The templated class tensor<value_t,format_t,storage_t>
is the base
container adaptor for dense tensors. Every element
$(t_/ i_1, i_2, \dots, i_p)$ of a $p$-order $(n_1 \times n_2 \times \cdots
\times n_p)$-dimensional tensor $T$ is mapped to $j$-th element of a
one-dimensional container where $(j = \sum_ /{r=1}^p i_r \cdot w_r)$ with
$1 \leq i_r \leq n_r $ for $1 \leq r \leq p$. For the first-order
orientation $w_1 = 1$ and $(w_k = n_{k-1} \cdot w_{k-1})$ for $k > 1$.
For last-order orientation $w_p = 1$ and $(w_k = n_/{k+1} \cdot w_/{k+1})$ for $k < p$.
b. Example
#include <boost/numeric/ublas/tensor.hpp>
int main () {
using namespace boost::numeric::ublas;
tensor<double> t{4,2,3};
for (auto k = 0ul; k < t.size (2); ++ k)
for (auto j = 0ul; j < t.size (1); ++ j)
for (auto i = 0ul; i < t.size (0); ++ i)
t.at(i,j,k) = 3*i + 2*j + 5*k;
std::cout << t << std::endl;
}
c. Definition
Defined in the header file tensor/tensor.hpp
.
d. Model of
e. Type requirements
None, except for those imposed by the requirements of Tensor .
f. Public base classes
tensor_container<tensor<value_t,format_t,storage_t> >
g. Template parameters
Parameter | Description | Default |
---|---|---|
|
The type of object stored in the tensor. |
|
|
Storage organization. [1] |
|
|
The type of the Storage array. [2] |
|
h. Member types
Member type | Description |
---|---|
|
Type |
|
Format of the tensor which is either |
|
Sequence container type that stores all tensor elements and is accessible with a single index. |
|
Type of the strides vector
|
|
Type of the dimension extents vector |
|
Unsigned integer which is usually |
|
Unsigned integer which is usually |
|
Reference type |
|
Constant reference type
|
|
Pointer type |
|
Constant reference type
|
|
RandomAccessIterator |
|
Constant RandomAccessIterator
|
|
Reverse RandomAccessIterator
|
|
Reverse RandomAccessIterator
|
|
Type of the matrix
|
|
Type of the vector
|
i. Alias templates
Alias template | Description |
---|---|
|
Type of tensor_expression where |
|
Type of matrix_expression. |
|
Type of vector_expression. |
j. Member Functions
Member function | Description |
---|---|
|
Constructs an uninitialized |
|
Constructs an
uninitialized |
|
Constructs an uninitialized
|
|
Constructs an
uninitialized |
|
Constructs
tensor by copying elements from |
|
Constructs tensor by copying elements
from |
|
Constructs tensor by moving elements from
|
|
Constructs tensor by copying
elements from |
|
Constructs tensor by moving elements
from |
|
Constructs tensor by copying
elements from |
|
Constructs tensor by moving elements
from |
|
Constructs
tensor by evaluating the tensor
expression |
|
Constructs
tensor by evaluating the matrix expression
|
|
Constructs
tensor by evaluating the vector expression
|
Member function | Description |
---|---|
|
Evaluates the tensor expression
|
|
Copies or moves elements of |
|
Initialiates all elements of a
tensor with |
Member function | Description |
---|---|
|
Returns true if a tensor has zero elements. |
|
Returns the number of elements of the tensor. |
|
Returns the number of dimensions of the tensor. |
|
Returns the number of dimensions of the tensor. |
|
Returns a constant reference to the strides of the tensor. |
|
Returns a constant reference to the extents of the tensor. |
Member function | Description |
---|---|
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a
|
|
Returns a |
|
Returns a |
Member function | Description |
---|---|
|
Returns a tensor index instance with
index objects |
Member function | Description |
---|---|
|
Returns a const_iterator pointing to the first element of the tensor. |
|
Returns a const_iterator pointing to the first element of the tensor. |
|
Returns an iterator pointing to the first element of the tensor. |
|
Returns a const_iterator pointing to the position after the last element of the tensor. |
|
Returns a const_iterator pointing to the position after the last element of the tensor. |
|
Returns an iterator pointing to the position after the last element of the tensor. |
Member function | Description |
---|---|
|
Reshapes the tensor according to the extents |
[1] Supported parameters for the storage organization are
first_order
and last_order
.
[2] Common parameters for the storage array are
std::array<N,T>
and std::vector<T>
.
Tensor Expressions
Description
The templated class tensor_expression<T,E>
is required to be a public
base of all classes. There is no Tensor Expression concept defined.
Definition
Defined in the header tensor/expression.hpp.
Model of
None. Not a Tensor Expression!
Type requirements
None.
Public base classes
ublas_expression<E>
.
Template parameters
Parameter |
Description |
|
The type of the tensor. |
|
The type of the tensor expression. |
Member types
Member type |
Description |
|
Type of the derived expression which is |
|
Tag for categorization which is |
|
Reference type which is |
Public Member Functions
Member | Description |
---|---|
|
Returns a |
Entrywise Tensor Operations
Binary Tensor Expression
The templated class binary_tensor_expression<T,EL,ER,OP>
contains a
constant reference to a left and right expression that can be evaluated
by using the access operator.
Defined in the header tensor/expression.hpp.
Tensor Expression
None.
tensor_expression<T,binary_tensor_expression<T,EL,ER,OP>>
Parameter |
Description |
|
Type of the tensor. |
|
Type of the left binary tensor expression. |
|
Type of the right binary tensor expression. |
|
Type of the binary operation. |
Member type |
Description |
|
Type of the left expression which is |
|
Type of the right expression which is |
|
Reference type which is |
|
Type of the binary operation which is |
Member | Description |
---|---|
|
Returns a |
Unary Tensor Expression
The templated class unary_tensor_expression<T,E,OP>
contains a
constant reference to an expression that can be evaluated by using the
access operator.
Defined in the header tensor/expression.hpp.
Tensor Expression
None.
tensor_expression<T,unary_tensor_expression<T,E,OP>>
Parameter |
Description |
|
Type of the tensor. |
|
Type of the unary tensor expression. |
|
Type of the unary operation. |
Member type |
Description |
|
Type of the expression which is |
|
Reference type which is |
|
Type of the unary operation which is |
Member | Description |
---|---|
|
Returns a |
Tensor Extents
basic_extents<size_type>
Description
The template class basic_extents
specifies dimension extents of a
tensor instance.
Example
#include <boost/numeric/ublas/tensor/extents.hpp>
int main () {
using namespace boost::numeric::ublas;
shape s{4,3,2};
for (auto i = 0u; i < s.size(); ++i) {
std::cout << s.at(i) << std::endl;
}
}
Definition
Defined in the header tensor/extents.hpp.
Public base classes
None.
Specialization
using shape = basic_extents<std::size_t>
Template parameters
Parameter |
Description |
|
Unsigned integer type. |
Member types
Member type | Description |
---|---|
|
Type |
|
Unsigned integer such as |
|
Reference type which is |
|
Constant reference type which is
|
|
Pointer type which is |
|
Constant reference type which is |
Member Functions
Member Function | Description |
---|---|
|
Constructs an empty instance of |
|
Constructs an instance copying the content of |
|
Constructs an instance moving the content of |
|
Constructs an instance from |
|
Constructs an instance from the range specified by |
|
Constructs an instance from |
|
Constructs an instance from |
|
Assigns the elements of |
|
Returns true if the elements are |
|
Returns true if the elements are |
|
Returns true if the elements are |
|
Returns true if it is not a scalar, vector or matrix. |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns true if the container has no elements. |
|
Returns the number of elements. |
|
Returns true if size()>1 and all elements are greater than one. |
|
Returns the multiplication of all entries. |
|
Returns a new instance where entries equal to one are eliminated. |
|
Returns true if all elements are equal. |
|
Returns true if some elements are not equal. |
|
Returns an |
|
Returns a |
|
Returns a const reference to the private member sequence container holding all elements. |
Tensor Strides
basic_strides<size_type, format_type>
Description
The template class basic_strides
contains weights for a given storage
format in order to map multi-indices to scalar memory indices for
tensor instances.
Example
#include <boost/numeric/ublas/tensor/strides.hpp>
int main () {
using namespace boost::numeric::ublas;
auto wf = strides<first_order>(shape{4,3,2});
for (auto i = 0u; i < wf.size(); ++i)
std::cout << wf.at(i) << std::endl;
// 1,4,12
auto wl = strides<first_order>(shape{4,3,2});
for (auto i = 0u; i < wl.size(); ++i)
std::cout << wl.at(i) << std::endl;
// 6,2,1
}
Definition
Defined in the header tensor/strides.hpp.
Public base classes
None.
Specialization
template<class format_t>using strides = basic_strides<std::size_t,format_t>
Template parameters
Parameter |
Description |
|
Unsigned integer type. |
Member types
Member type | Description |
---|---|
|
Type |
|
Unsigned integer such as |
|
Reference type which is |
|
Constant reference type which is
|
|
Pointer type which is |
|
Constant pointer type which is |
|
Layout type which can be either
|
Member Functions
Member Function | Description |
---|---|
|
Constructs an empty instance of |
|
Constructs an
instance based on the tensor extents specified by |
|
Constructs an
instance copying the content of |
|
Constructs an instance
moving the content of |
|
Constructs an instance
from |
|
Constructs an instance from
|
|
Assigns the elements
of |
|
Returns a |
|
Returns a
|
|
Returns a |
|
Returns true if the container has no elements. |
|
Returns the number of elements. |
|
Erases all elements. |
|
Returns true if all elements are equal. |
|
Returns true if some elements are not equal. |
|
Returns an |
|
Returns a |
|
Returns the private member sequence container holding all elements. |
Non-Member Functions
Function | Description |
---|---|
|
Returns relative memory location depending on the multi-index vector
|
|
Returns relative memory location depending on the indices |
Tensor Expressions
Description
The templated class tensor_expression<T,E>
is required to be a public
base of all classes. There is no Tensor Expression concept defined.
Definition
Defined in the header tensor/expression.hpp.
Model of
None. Not a Tensor Expression!
Type requirements
None.
Public base classes
ublas_expression<E>
.
Template parameters
Parameter |
Description |
|
The type of the tensor. |
|
The type of the tensor expression. |
Member types
Member type |
Description |
|
Type of the derived expression which is |
|
Tag for categorization which is |
|
Reference type which is |
Public Member Functions
Member | Description |
---|---|
|
Returns a |
Entrywise Tensor Operations
Binary Tensor Expression
The templated class binary_tensor_expression<T,EL,ER,OP>
contains a
constant reference to a left and right expression that can be evaluated
by using the access operator.
Defined in the header tensor/expression.hpp.
Tensor Expression
None.
tensor_expression<T,binary_tensor_expression<T,EL,ER,OP>>
Parameter |
Description |
|
Type of the tensor. |
|
Type of the left binary tensor expression. |
|
Type of the right binary tensor expression. |
|
Type of the binary operation. |
Member type |
Description |
|
Type of the left expression which is |
|
Type of the right expression which is |
|
Reference type which is |
|
Type of the binary operation which is |
Member | Description |
---|---|
|
Returns a |
Unary Tensor Expression
The templated class unary_tensor_expression<T,E,OP>
contains a
constant reference to an expression that can be evaluated by using the
access operator.
Defined in the header tensor/expression.hpp.
Tensor Expression
None.
tensor_expression<T,unary_tensor_expression<T,E,OP>>
Parameter |
Description |
|
Type of the tensor. |
|
Type of the unary tensor expression. |
|
Type of the unary operation. |
Member type |
Description |
|
Type of the expression which is |
|
Reference type which is |
|
Type of the unary operation which is |
Member | Description |
---|---|
|
Returns a |
Miscellaneous
Unbounded Array Storage
Description
The templated class unbounded_array<T, ALLOC>
implements a unbounded
storage array using an allocator. The unbounded array is similar to a
std::vector
in that in can grow in size beyond any fixed bound.
However unbounded_array
is aimed at optimal performance. Therefore
unbounded_array
does not model a Sequence
like std::vector
does.
When resized unbounded_array
will reallocate it’s storage even if the
new size requirement is smaller. It is therefore inefficient to resize a
unbounded_array
Example
#include <boost/numeric/ublas/storage.hpp>
int main () {
using namespace boost::numeric::ublas;
unbounded_array<double> a (3);
for (unsigned i = 0; i < a.size (); ++ i) {
a [i] = i;
std::cout << a [i] << std::endl;
}
}
Definition
Defined in the header storage.hpp.
Template parameters
Parameter |
Description |
Default |
|
The type of object stored in the array. |
|
|
An STL Allocator |
std::allocator |
Model of
Type requirements
None, except for those imposed by the requirements of Storage.
Public base classes
None.
Members
-
The description does not describe what the member actually does, this can be looked up in the corresponding concept documentation, but instead contains a remark on the implementation of the member inside this model of the concept.
-
Typography:
-
Members that are not part of the implemented concepts are in blue.
-
Member | Where defined | Description |
---|---|---|
|
||
|
Defined as |
|
|
Defined as |
|
|
Defined as |
|
|
Defined as |
|
|
Defined as |
|
|
Defined as |
|
|
Defined as |
|
|
Defined as |
|
|
Defined as |
|
|
Defined as |
|
allocator_type |
Defined as ALLOC |
|
|
Creates an |
|
|
Creates a uninitialized |
|
|
Creates an initialized |
|
|
The copy constructor. |
|
|
Deallocates the |
|
|
Reallocates an |
|
|
Reallocates an |
|
|
Returns the size of the |
|
|
Returns a |
|
|
Returns a reference of the |
|
|
The assignment operator. |
|
|
Assigns a temporary. May change the array |
|
|
Swaps the contents of the arrays. |
|
|
Returns a |
|
|
Returns a |
|
|
Returns a |
|
|
Returns a |
|
|
Returns a |
|
|
Returns a |
|
|
Returns a |
|
|
Returns a |
Bounded Array Storage
Description
The templated class bounded_array<T, N, ALLOC>
implements a bounded
storage array. The bounded array is similar to a C++ array type in that
its maximum size is bounded by N and is allocated on the stack instead
of the heap. Similarly a bounded_array
requires no secondary storage
and ALLOC is only used to specify size_type
and difference_type
.
When resized bounded_array
never reallocated the storage. It is
therefore always efficient to resize a bounded_array
but the size
bound N must not be exceeded.
Example
#include <boost/numeric/ublas/storage.hpp>
int main () {
using namespace boost::numeric::ublas;
bounded_array<double, 3> a (3);
for (unsigned i = 0; i < a.size (); ++ i) {
a [i] = i;
std::cout << a [i] << std::endl;
}
}
Definition
Defined in the header storage.hpp.
Template parameters
Parameter |
Description |
Default |
|
The type of object stored in the array. |
|
|
The allocation size of the array. |
|
|
An STL Allocator |
std::allocator |
Model of
Type requirements
None, except for those imposed by the requirements of Storage.
Public base classes
None.
Members
-
The description does not describe what the member actually does, this can be looked up in the corresponding concept documentation, but instead contains a remark on the implementation of the member inside this model of the concept.
-
Typography:
-
Members that are not part of the implemented concepts are in blue.
-
Member | Where defined | Description |
---|---|---|
|
||
|
Defined as |
|
|
Defined as |
|
|
Defined as |
|
|
Defined as |
|
|
Defined as |
|
|
Defined as |
|
|
Defined as |
|
|
Defined as |
|
|
Defined as |
|
|
Defined as |
|
|
Creates an |
|
|
Creates a uninitialized |
|
|
Creates an initialized |
|
|
The copy constructor. |
|
|
Deallocates the |
|
|
Reallocates a |
|
|
Reallocates a |
|
|
Returns the size of the |
|
|
Returns a |
|
|
Returns a reference of the |
|
|
The assignment operator. |
|
|
Assigns a temporary. May change the array |
|
|
Swaps the contents of the arrays. |
|
|
Returns a |
|
|
Returns a |
|
|
Returns a |
|
|
Returns a |
|
|
Returns a |
|
|
Returns a |
|
|
Returns a |
|
|
Returns a |
Overview of Tensor, Matrix- and Vector Types
Notation
|
is the data type. For general linear algebra operations this will
be a real type e.g. |
|
is the orientation type, either |
|
is an array storage type, e.g.
|
|
is a triangular functor:
|
|
are unsigned integer sizes ( |
|
is an index base ( |
|
is any vector type |
|
is any matrix type |
|
is any tensor type |
|
denote optional arguments - for more details look at the section "storage layout". |
Vectors
Definition | Description |
---|---|
|
a dense vector of values of type |
|
a dense vector of values of type |
|
a dense vector of values of type |
|
the zero vector of type |
|
the unit vector of type |
|
a sparse vector of values of type
|
|
a sparse vector of
values of type |
|
a sparse vector of
values of type |
Note: the default types are defined in boost/numeric/ublas/fwd.hpp
.
Vector Proxies
Definition | Description |
---|---|
|
a vector referencing a continuous
subvector of elements of vector |
|
a vector referencing a non
continuous subvector of elements of vector |
|
a vector referencing the |
|
a vector referencing the
|
Matrices
Definition | Description |
---|---|
|
a dense matrix of values of
type |
|
a dense matrix of type |
|
a dense matrix of values of
type |
|
a dense matrix of
values of type |
|
a zero matrix of type |
|
an identity matrix of type |
|
a matrix of type |
|
a triangular matrix of
values of type |
|
a
banded matrix of values of type |
|
a symmetric matrix of
values of type |
|
a hermitian matrix of
values of type |
|
a sparse
matrix of values of type |
|
a sparse matrix of values of type |
|
a sparse matrix of values of type |
|
a sparse matrix of values of type |
|
a sparse matrix of values of type |
Note: the default types are defined in boost/numeric/ublas/fwd.hpp
.
Matrix Proxies
Definition | Description |
---|---|
|
a triangular matrix
referencing a selection of elements of the matrix |
|
a symmetric matrix referencing
a selection of elements of the matrix |
|
a hermitian matrix referencing
a selection of elements of the matrix |
|
a banded matrix
referencing a selection of elements of the matrix |
|
a matrix referencing
a submatrix of elements in the matrix |
|
a matrix referencing
a non continues submatrix of elements in the matrix |
Tensors
Definition | Description |
---|---|
|
a dense matrix of values
of type |
Special Storage Layouts
The library supports conventional dense, packed and basic sparse vector and matrix storage layouts. The description of the most common constructions of vectors and matrices comes next.
Construction | Comment |
---|---|
|
a dense vector, storage is
provided by a standard vector. |
|
a dense vector, storage
is provided by a heap-based array. |
|
a dense vector, storage
is provided by a stack-based array. |
|
a sparse vector, storage is provided by a standard map. |
|
a sparse vector, storage is provided by a map array. |
|
a dense matrix, orientation is row major, storage is provided by a standard vector. |
|
a
dense matrix, orientation is column major, storage is provided by a
standard vector. |
|
a dense matrix, orientation is row major, storage is provided by a heap-based array. |
|
a
dense matrix, orientation is column major, storage is provided by a
heap-based array. |
|
a dense matrix, orientation is row major, storage is provided by a stack-based array. |
|
a dense matrix, orientation is column major, storage is provided by a
stack-based array. |
|
a packed triangular matrix, orientation is row major. |
|
a packed
triangular matrix, orientation is column major. |
|
a packed banded matrix, orientation is row major. |
|
a packed banded matrix, orientation is column major. |
|
a packed symmetric matrix, orientation is row major. |
|
a packed
symmetric matrix, orientation is column major. |
|
a packed hermitian matrix, orientation is row major. |
|
a packed
hermitian matrix, orientation is column major. |
|
a sparse matrix, orientation is row major, storage is provided by a standard map. |
|
a sparse matrix, orientation is column major, storage is provided by a standard map. |
|
a sparse matrix, orientation is row major, storage is provided by a map array. |
|
a sparse matrix, orientation is column major, storage is provided by a map array. |
|
a
compressed matrix, orientation is row major. |
|
a
compressed matrix, orientation is column major. |
|
a
coordinate matrix, orientation is row major. |
|
a
coordinate matrix, orientation is column major. |
Range and Slice Storage
Range<SizeType,DistanceType>
Description
The class range
specifies a range of indicies. The range is a sequence
of indices from a start value to stop value. The indices increase by one
and exlude the stop value. range
can therefore be used to specify
ranges of elements from vectors and matrices.
Example
#include <boost/numeric/ublas/storage.hpp>
int main () {
using namespace boost::numeric::ublas;
range r (0, 3);
for (unsigned i = 0; i < r.size (); ++ i) {
std::cout << r (i) << std::endl;
}
}
Definition
Defined in the header storage.hpp.
Model of
Reversible Container.
Type requirements
None, except for those imposed by the requirements of Reversible Container.
Public base classes
None.
Members
Member | Description |
---|---|
|
Constructs a range of
indicies from |
|
Returns the beginning of the |
|
Returns the size of the |
|
Returns the value
|
|
Returns the composite range
from |
|
Tests two ranges for equality. |
|
Tests two ranges for inequality. |
|
Returns a |
|
Returns a |
|
Returns a
|
|
Returns a
|
Preconditions
-
start () < = stop ()
Slice<SizeType,DistanceType>
Description
The class slice
specifies a 'slice' of indicies. Slices are more
general then ranges, the stride allows the sequence of indicies to
increase and decrease by the specified amount between element. slice
can therefore be used to specify slices of element from vectors and
matrices.
Example
#include <boost/numeric/ublas/storage.hpp>
int main () {
using namespace boost::numeric::ublas;
slice s (0, 1, 3);
for (unsigned i = 0; i < s.size (); ++ i) {
std::cout << s (i) << std::endl;
}
}
Definition
Defined in the header storage.hpp.
Model of
Reversible Container.
Type requirements
None, except for those imposed by the requirements of Reversible Container.
Public base classes
None.
Members
Member | Description |
---|---|
|
Constructs
a slice |
|
Returns the beginning of the |
|
Returns the stride of the |
|
Returns the size of the |
|
Returns the value
|
|
Returns the composite slice
from |
|
Returns the composite slice
from |
|
Tests two slices for equality. |
|
Tests two slices for inequality. |
|
Returns a |
|
Returns a |
|
Returns a
|
|
Returns a
|
Preconditions
-
None all strides are vaild. However when an index is returned or an iterator is dereferenced its value must be representable as the size_type.
Boost Basic Linear Algebra - Configuration Options
NDEBUG
Make sure you define NDEBUG The only way uBLAS knows you want a release configuration is to check if you have defined NDEBUG. If you don’t it assumes you want a debug configuration and adds a lot of very useful runtime check. However these are very slow!
BOOST_UBLAS_MOVE_SEMANTICS
The patch and description was provided by Nasos Iliopoulos.
An immediate effect of this option is the elimination of the need for noalias in types vector<T> and matrix<T>, when assigned to the same type. This option doesn’t have an effect on bounded and c types. Although it is rare, not all compilers support copy elision (that allows for move semantics), so a test must be performed to make sure that there is a benefit when it is enabled. A small demonstration and test can be found in test_move_semantics.cpp
In the test example two tests are defined, one for vectors and one for matrices. The aim of this example is to print the pointers of the storage of each of the containers, before and after the assignment to a temporary object. When move semantics are enabled, the vector<T> and matrix<T> storage is moved from the temporary and no copy is performed.
If move semantics are supported by your compiler you will get an output like the following:
matrix<double> --------------------------------------------------------------------
Temporary pointer r: 0x94790c0
Pointer (must be equal to temp. pointer if move semantics are enabled) : 0x94790c0
Notes:
-
It should be no surprise to see matrices and vectors been passed by VALUE, the compiler takes care and either moves (if the underlying code does not modify the object), or copies (if the underlying code modifies the object).
-
There might be some space for some improvements (like clearing the data, before swaping)
-
Move semantics don’t eliminate temporaries. They rather move their storage around so no copies are performed.
-
MSVC does no implement Named Return Value Optimization in debug mode. So if you build in debug with this compiler you might get different behaviour than a release build.
-
Enabling move semantics is done via #define BOOST_UBLAS_MOVE_SEMANTICS.
-
There is plenty of room for optimizations when c++0x standard is out, taking advantage of rvalue references. (I have a sweet vector implementation using that).
-
If you enable move semantics and your compiler does not support them, the operation will just be as passing by const reference.
Interesting links
BOOST_UBLAS_CHECK_ENABLE
When BOOST_UBLAS_CHECK_ENABLE is defined then all index and parameter checks are enabled. This is enabled in debug mode and disabled in release mode.
BOOST_UBLAS_TYPE_CHECK
When BOOST_UBLAS_TYPE_CHECK is enabled then all possibly expensive structure checks are enabled. If this is not desireable then use #define BOOST_UBLAS_TYPE_CHECK 0 before including any uBLAS header. The define BOOST_UBLAS_TYPE_CHECK_EPSILON can be used to control the acceptable tolerance, see detail/matrix_assign.hpp for implementation details of this check.
BOOST_UBLAS_USE_LONG_DOUBLE
Enable uBLAS expressions that involve containers of 'long double'
BOOST_UBLAS_USE_INTERVAL
Enable uBLAS expressions that involve containers of 'boost::numeric::interval' types
Configuring uBLAS with Macros
Many macro’s appear in ublas/config.hpp and elsewhere. Hopefully in the future some of these will disappear! They fall into 4 groups:
-
Automatically set by 'boost/numeric/ublas/config.hpp' based on NDEBUG. Makes the distinction between debug (safe) and release (fast) mode. Similar to STLport
-
Release mode (NDEBUG defined)
-
BOOST_UBLAS_INLINE Compiler dependant definition to control function inlining.
-
BOOST_UBLAS_USE_FAST_SAME
-
-
Debug mode
-
BOOST_UBLAS_CHECK_ENABLE Enable checking of indexs, iterators and parameters. Prevents out of bound access etc.
-
BOOST_UBLAS_TYPE_CHECK Enable additional checks for the results of expressions using non dense types. Picks up runtime error such as the assignment of a numerically non-symmetric matrix to symmertic_matrix. Use #define BOOST_UBLAS_TYPE_CHECK 0 to disable expensive numeric type checks. (Note: "structure check" would be a much better name.)
-
BOOST_UBLAS_TYPE_CHECK_EPSILON default: sqrt(epsilon), controls how large the difference between the expected result and the computed result may become. Increase this value if you are going to use near singular or badly scaled matrices. Please, refer to detail/matrix_assign.hpp for implementation of these type checks.
-
-
-
Automatically set by 'boost/numeric/ublas/config.hpp' based on compiler and boost/config.hpp macro’s. Augments the compiler deficiency workarounds already supplied by boost/config.hpp
-
BOOST_UBLAS_NO_NESTED_CLASS_RELATION A particularly nasty problem with VC7.1 Requires that uBLAS and the user use begin(it) rather then it.begin()
-
BOOST_UBLAS_NO_SMART_PROXIES Disable the automatic propagation of 'constantness' to proxies. Smart proxies automatically determine if the underling container they reference is constant or not. They adjust there definition of iterators and container access to reflect this constantness.
-
-
For use by uBLAS authors to test implementation methods. Preset in config.hpp
-
BOOST_UBLAS_USE_INVARIANT_HOISTING
-
BOOST_UBLAS_USE_INDEXING
-
BOOST_UBLAS_USE_INDEXED_ITERATOR
-
BOOST_UBLAS_NON_CONFORMANT_PROXIES Gappy containers may be non-conformant, that is contain elements at different indices. Assigning between proxies (vector ranges for example) of these containers is difficult as the LHS may need insert new elements. This is slow.
-
BOOST_UBLAS_USE_DUFF_DEVICE Near useless on all platforms (see GCC’s -funroll-loops)
-
-
User options. Can be predefined by user before including any uBLAS headers. They may also be automatically defined for some compilers to work around compile bugs.
-
BOOST_UBLAS_USE_LONG_DOUBLE Enable uBLAS expressions that involve containers of 'long double'
-
BOOST_UBLAS_USE_INTERVAL Enable uBLAS expressions that involve containers of 'boost::numeric::interval' types
-
BOOST_UBLAS_SIMPLE_ET_DEBUG In order to simplify debugging is is possible to simplify expression templateso they are restricted to a single operation
-
BOOST_UBLAS_ENABLE_PROXY_SHORTCUTS enable automatic conversion from proxy class to matrix expression
-
BOOST_UBLAS_NO_ELEMENT_PROXIES Disables the use of element proxies for gappy types.
-
The Gappy types (sparse, coordinate, compressed) store non-zero elements in their own containers. When new non-zero elements are assigned they must rearrange these containers. This invalidates references, iterators or pointers to these elements. This can happen at some surprising times such as the expression "a [1] = a [0] = 1;". Element proxies guarantee all such expressions will work as expected. However they bring their own restrictions and efficiency problems. For example as of Boost 1.30.0 they prevent the assignment of elements between different types.
-
BOOST_UBLAS_REFERENCE_CONST_MEMBER Enable to allow refernces to be returned to fixed (zero or one) elements of triangular or banded matrices
-
BOOST_UBLAS_NO_EXCEPTIONS Disable the use exceptions of uBLAS internal checks and error conditions. BOOST_NO_EXCEPTIONS has same effect.
-
BOOST_UBLAS_SINGULAR_CHECK Check the for singularity in triangular solve() functions
-
Last modified: Wed Sep 16 23:16:45 CEST 2009
Sparse Storage
Default Standard Map
Description
The templated class map_std<I, T, ALLOC>
provides a wrapper for the
standard library associative container std::map
. The wrapper has one
simple purpose. It allows the definition of a default template parameter
(for the adapted array) when declaring the sparse container types.
Example
#include <boost/numeric/ublas/storage_sparse.hpp>
int main () {
using namespace boost::numeric::ublas;
map_std<int, double> a (3);
for (unsigned i = 0; i < a.size (); ++ i) {
a [i] = i;
std::cout << a [i] << std::endl;
}
}
Definition
Defined in the header storage_sparse.hpp.
Template parameters
Parameter |
Description |
Default |
|
The type of index stored in the array. |
|
|
The type of object stored in the array. |
|
|
An STL Allocator |
std::allocator |
Model of
Reversible Container.
Type requirements
None, except for those imposed by the requirements of Reversible Container.
Public base classes
std::map
Map Array
Description
The templated class map_array<I, T, ALLOC>
implements a std::map
like associative container as a sorted array. It therefore some of the
Associative Container interface without having the same semantics as an
std::map.
At any time the map_array
has a capacity up to which new element can
be inserted. If insert
would cause the size of the map_array
to
exceeds its capactity then it is reallocated. Iterators and reference
are invalidated. The capacity can be directly control using the
reserve
member function.
Example
#include <boost/numeric/ublas/storage_sparse.hpp>
int main () {
using namespace boost::numeric::ublas;
map_array<int, double> a (3);
for (unsigned i = 0; i < a.size (); ++ i) {
a [i] = i;
std::cout << a [i] << std::endl;
}
}
Definition
Defined in the header storage_sparse.hpp.
Template parameters
Parameter |
Description |
Default |
|
The type of index stored in the array. |
|
|
The type of object stored in the array. |
|
|
An STL Allocator |
std::allocator |
Model of
Reversible Container.
Type requirements
None, except for those imposed by the requirements of Reversible Container.
Public base classes
None.
Members
Member | Description |
---|---|
|
Allocates a |
|
The copy constructor. |
|
Deallocates the |
|
Changes the`map_array` capacity.
It can hold at most`capacity` elements without reallocation. The
capacity can be reduced such that |
|
Returns the size of the |
|
Returns the capacity of the |
|
Returns a reference of the
element that is associated with a particular index. If the |
|
The assignment operator. |
|
Assigns a temporary. May
change the array |
|
Swaps the contents of the arrays. |
|
Inserts |
|
Inserts |
|
Erases the value at |
|
Clears the array. |
|
Finds an element whose
index is |
|
Finds an element whose index is |
|
Finds the first
element whose index is not less than |
|
Finds the first element whose
index is not less than |
|
Finds the first
element whose index is greater than |
|
Finds the first element whose
index is greater than |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a
|
|
Returns a
|
|
Returns a |
|
Returns a |
Range and Slice Storage
Range<SizeType,DistanceType>
Description
The class range
specifies a range of indicies. The range is a sequence
of indices from a start value to stop value. The indices increase by one
and exlude the stop value. range
can therefore be used to specify
ranges of elements from vectors and matrices.
Example
#include <boost/numeric/ublas/storage.hpp>
int main () {
using namespace boost::numeric::ublas;
range r (0, 3);
for (unsigned i = 0; i < r.size (); ++ i) {
std::cout << r (i) << std::endl;
}
}
Definition
Defined in the header storage.hpp.
Model of
Reversible Container.
Type requirements
None, except for those imposed by the requirements of Reversible Container.
Public base classes
None.
Members
Member | Description |
---|---|
|
Constructs a range of
indicies from |
|
Returns the beginning of the |
|
Returns the size of the |
|
Returns the value
|