uBLAS 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.
Copyright (©) 2000-2002 Joerg Walter, Mathias Koch
Copyright (©) 2021 Shikhar Vashistha
Use, modification and distribution are subject to the Boost Software
License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt ).
Boost.Ublas: The Boost Ublas Library
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.
Documentation
-
Storage and special containers
-
Operations & Functions
-
uBLAS Concept definitions
Release notes
Release notes can be found here.
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))
.
Copyright (©) 2000-2011 Joerg Walter, Mathias Koch, Gunter Winkler,
David Bellot
Copyright (©) 2021 Shikhar Vashistha
Copyright (©) 2021 Cem Bassoy
Use, modification and distribution are subject to the Boost Software
License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt ).
Vector
Vector
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
|
Copyright (©) 2000-2002 Joerg Walter, Mathias Koch
Copyright (©) 2021 Shikhar Vashistha
Use, modification and distribution are subject to the Boost Software
License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt ).
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<>
.
Copyright (©) 2000-2002 Joerg Walter, Mathias Koch
Copyright (©) 2021 Shikhar Vashistha
Use, modification and distribution are subject to the Boost Software
License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt ).
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
Description
The free subrange
functions support the construction of vector ranges.
Prototypes
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
Description
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.
Prototypes
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);
Definition
Defined in the header vector_proxy.hpp.
Type requirements
-
V
is a model of Vector Expression .
Complexity
Linear depending from the size of the range.
Examples
#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
Description
The free subslice
functions support the construction of vector slices.
Prototypes
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
Description
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.
Prototypes
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);
Definition
Defined in the header vector_proxy.hpp.
Type requirements
-
V
is a model of Vector Expression .
Complexity
Linear depending from the size of the slice.
Examples
#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;
}
Copyright (©) 2000-2002 Joerg Walter, Mathias Koch
Copyright (©) 2021 Shikhar Vashistha
Use, modification and distribution are subject to the Boost Software
License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt ).
Vector Expressions
Vector Expression
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
Description
The templated class vector_reference<E>
contains a reference to a
vector expression.
Definition
Defined in the header vector_expression.hpp.
Template parameters
Parameter |
Description |
Default |
|
The type of the vector expression. |
|
Model of
Type requirements
None, except for those imposed by the requirements of Vector Expression .
Public base classes
vector_expression<vector_reference<E> >
Members
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
Description
The templated class vector_unary<E, F>
describes a unary vector
operation.
Definition
Defined in the header vector_expression.hpp.
Template parameters
Parameter |
Description |
Default |
|
The type of the vector expression. |
|
|
The type of the operation. |
|
Model of
Type requirements
None, except for those imposed by the requirements of Vector Expression .
Public base classes
vector_expression<vector_unary<E, F> >
Members
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
Prototypes
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);
Description
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.
Definition
Defined in the header vector_expression.hpp.
Type requirements
-
E
is a model of Vector Expression .
Preconditions
None.
Complexity
Linear depending from the size of the vector expression.
Examples
#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
Description
The templated class vector_binary<E1, E2, F>
describes a binary vector
operation.
Definition
Defined in the header vector_expression.hpp.
Template parameters
Parameter |
Description |
Default |
|
The type of the first vector expression. |
|
|
The type of the second vector expression. |
|
|
The type of the operation. |
Model of
Type requirements
None, except for those imposed by the requirements of Vector Expression .
Public base classes
vector_expression<vector_binary<E1, E2, F> >
Members
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
Prototypes
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);
Description
operator +
computes the sum of two vector expressions. operator -
computes the difference of two vector expressions.
Definition
Defined in the header vector_expression.hpp.
Type requirements
-
E1
is a model of Vector Expression . -
E2
is a model of Vector Expression .
Preconditions
-
e1 ().size () == e2 ().size ()
Complexity
Linear depending from the size of the vector expressions.
Examples
#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
Description
The templated class vector_matrix_binary<E1, E2, F>
describes a binary
outer vector operation.
Definition
Defined in the header matrix_expression.hpp.
Template parameters
Parameter |
Description |
Default |
|
The type of the first vector expression. |
|
|
The type of the second vector expression. |
|
|
The type of the operation. |
Model of
Type requirements
None, except for those imposed by the requirements of Matrix Expression .
Public base classes
matrix_expression<vector_matrix_binary<E1, E2, F> >
Members
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
Prototypes
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);
Description
outer_prod
computes the outer product of two vector expressions.
Definition
Defined in the header matrix_expression.hpp.
Type requirements
-
E1
is a model of Vector Expression . -
E2
is a model of Vector Expression .
Preconditions
None.
Complexity
Quadratic depending from the size of the vector expressions.
Examples
#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
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.
Definition
Defined in the header vector_expression.hpp.
Template parameters
Parameter |
Description |
Default |
|
The type of the scalar expression. |
|
|
The type of the vector expression. |
|
|
The type of the operation. |
Model of
Type requirements
None, except for those imposed by the requirements of Vector Expression .
Public base classes
vector_expression<vector_binary_scalar1<E1, E2, F> >
and
vector_expression<vector_binary_scalar2<E1, E2, F> >
resp.
Members
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
Prototypes
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);
Description
operator *
computes the product of a scalar and a vector expression.
operator /
multiplies the vector with the reciprocal of the scalar.
Definition
Defined in the header vector_expression.hpp.
Type requirements
-
T1/T2
is a model of Scalar Expression . -
E2/E1
is a model of Vector Expression .
Preconditions
None.
Complexity
Linear depending from the size of the vector expression.
Examples
#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
Prototypes
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);
Description
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.
Definition
Defined in the header vector_expression.hpp.
Type requirements
-
E
is a model of Vector Expression .
Preconditions
None.
Complexity
Linear depending from the size of the vector expression.
Examples
#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
Prototypes
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);
Description
inner_prod
computes the inner product of the vector expressions.
prec_inner_prod
computes the double precision inner product of the
vector expressions`.`
Definition
Defined in the header vector_expression.hpp.
Type requirements
-
E1
is a model of Vector Expression . -
E2
is a model of Vector Expression .
Preconditions
-
e1 ().size () == e2 ().size ()
Complexity
Linear depending from the size of the vector expressions.
Examples
#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;
}
Copyright (©) 2000-2002 Joerg Walter, Mathias Koch
Copyright (©) 2021 Shikhar Vashistha
Use, modification and distribution are subject to the Boost Software
License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt ).
Matrix
Matrix
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
|
Copyright (©) 2000-2002 Joerg Walter, Mathias Koch
Copyright (©) 2021 Shikhar Vashistha
Use, modification and distribution are subject to the Boost Software
License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt ).
Triangular Matrix
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
.
Copyright (©) 2000-2002 Joerg Walter, Mathias Koch
Copyright (©) 2021 Shikhar Vashistha
Use, modification and distribution are subject to the Boost Software
License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt ).
Symmetric Matrix
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
.
Copyright (©) 2000-2002 Joerg Walter, Mathias Koch
Copyright (©) 2021 Shikhar Vashistha
Use, modification and distribution are subject to the Boost Software
License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt ).
Hermitian Matrix
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
.
Copyright (©) 2000-2002 Joerg Walter, Mathias Koch
Copyright (©) 2021 Shikhar Vashistha
Use, modification and distribution are subject to the Boost Software
License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt ).
Banded Matrix
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 |
Copyright (©) 2000-2002 Joerg Walter, Mathias Koch
Copyright (©) 2021 Shikhar Vashistha
Use, modification and distribution are subject to the Boost Software
License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt).
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<>
.
Copyright (©) 2000-2002 Joerg Walter, Mathias Koch
Copyright (©) 2021 Shikhar Vashistha
Use, modification and distribution are subject to the Boost Software
License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt ).
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
Description
The free row
functions support the construction of matrix rows.
Prototypes
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);
Definition
Defined in the header matrix_proxy.hpp.
Type requirements
-
M
is a model of Matrix Expression .
Complexity
Linear depending from the size of the row.
Examples
#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
Description
The free column
functions support the construction of matrix columns.
Prototypes
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);
Definition
Defined in the header matrix_proxy.hpp.
Type requirements
-
M
is a model of Matrix Expression .
Complexity
Linear depending from the size of the column.
Examples
#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
Description
The free subrange
functions support the construction of matrix ranges.
Prototypes
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
Description
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.
Prototypes
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);
Definition
Defined in the header matrix_proxy.hpp.
Type requirements
-
M
is a model of Matrix Expression .
Complexity
Quadratic depending from the size of the ranges.
Examples
#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
Description
The free subslice
functions support the construction of matrix slices.
Prototypes
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
Description
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.
Prototypes
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);
Definition
Defined in the header matrix_proxy.hpp.
Type requirements
-
M
is a model of Matrix Expression .
Complexity
Quadratic depending from the size of the slices.
Examples
#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;
}
Copyright (©) 2000-2002 Joerg Walter, Mathias Koch
Copyright (©) 2021 Shikhar Vashistha
Use, modification and distribution are subject to the Boost Software
License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt ).
Matrix Expressions
Matrix Expression
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
Description
The templated class matrix_reference<E>
contains a reference to a
matrix expression.
Definition
Defined in the header matrix_expression.hpp.
Template parameters
Parameter |
Description |
Default |
|
The type of the matrix expression. |
|
Model of
Type requirements
None, except for those imposed by the requirements of Matrix Expression .
Public base classes
matrix_expression<matrix_reference<E> >
Members
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
Description
The templated classes matrix_unary1<E, F>
and matrix_unary2<E, F>
describe unary matrix operations.
Definition
Defined in the header matrix_expression.hpp.
Template parameters
Parameter |
Description |
Default |
|
The type of the matrix expression. |
|
|
The type of the operation. |
|
Model of
Type requirements
None, except for those imposed by the requirements of Matrix Expression .
Public base classes
matrix_expression<matrix_unary1<E, F> >
and
matrix_expression<matrix_unary2<E, F> >
resp.
Members
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
Prototypes
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);
Description
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.
Definition
Defined in the header matrix_expression.hpp.
Type requirements
-
E
is a model of Matrix Expression .
Preconditions
None.
Complexity
Quadratic depending from the size of the matrix expression.
Examples
#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
Description
The templated class matrix_binary<E1, E2, F>
describes a binary matrix
operation.
Definition
Defined in the header matrix_expression.hpp.
Template parameters
Parameter |
Description |
Default |
|
The type of the first matrix expression. |
|
|
The type of the second matrix expression. |
|
|
The type of the operation. |
Model of
Type requirements
None, except for those imposed by the requirements of Matrix Expression .
Public base classes
matrix_expression<matrix_binary<E1, E2, F> >
.
Members
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
Prototypes
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);
Description
operator +
computes the sum of two matrix expressions. operator -
computes the difference of two matrix expressions.
Definition
Defined in the header matrix_expression.hpp.
Type requirements
-
E1
is a model of Matrix Expression . -
E2
is a model of Matrix Expression .
Preconditions
-
e1 ().size1 () == e2 ().size1 ()
-
e1 ().size2 () == e2 ().size2 ()
Complexity
Quadratic depending from the size of the matrix expressions.
Examples
#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
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.
Definition
Defined in the header matrix_expression.hpp.
Template parameters
Parameter |
Description |
Default |
|
The type of the scalar expression. |
|
|
The type of the matrix expression. |
|
|
The type of the operation. |
Model of
Type requirements
None, except for those imposed by the requirements of Matrix Expression .
Public base classes
matrix_expression<matrix_binary_scalar1<E1, E2, F> >
and
matrix_expression<matrix_binary_scalar2<E1, E2, F> >
resp.
Members
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
Prototypes
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);
Description
operator *
computes the product of a scalar and a matrix expression.
operator /
multiplies the matrix with the reciprocal of the scalar.
Definition
Defined in the header matrix_expression.hpp.
Type requirements
-
T1/T2
is a model of Scalar Expression . -
E2/E1
is a model of Matrix Expression .
Preconditions
None.
Complexity
Quadratic depending from the size of the matrix expression.
Examples
#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
Description
The templated classes matrix_vector_binary1<E1, E2, F>
and
matrix_vector_binary2<E1, E2, F>
describe binary matrix vector
operations.
Definition
Defined in the header matrix_expression.hpp.
Template parameters
Parameter |
Description |
Default |
|
The type of the matrix or vector expression. |
|
|
The type of the vector or matrix expression. |
|
|
The type of the operation. |
Model of
Type requirements
None, except for those imposed by the requirements of Vector Expression .
Public base classes
vector_expression<matrix_vector_binary1<E1, E2, F> >
and
vector_expression<matrix_vector_binary2<E1, E2, F> >
resp.
Members
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
Prototypes
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);
Description
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.
Definition
Defined in the header matrix_expression.hpp.
Type requirements
-
E1
is a model of Matrix Expression or Vector Expression . -
E2
is a model of Vector Expression or Matrix Expression .
Preconditions
-
e1 ().size2 () == e2 ().size ()
-
e1 ().size () == e2 ().size1 ()
Complexity
Quadratic depending from the size of the matrix expression.
Examples
#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
Prototypes
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);
Description
solve
solves a linear equation for lower or upper (unit) triangular
matrices.
Definition
Defined in the header triangular.hpp.
Type requirements
-
E1
is a model of Matrix Expression or Vector Expression . -
E2
is a model of Vector Expression or Matrix Expression .
Preconditions
-
e1 ().size1 () == e1 ().size2 ()
-
e1 ().size2 () == e2 ().size ()
-
e1 ().size () == e2 ().size1 ()
-
e2 ().size1 () == e2 ().size2 ()
Complexity
Quadratic depending from the size of the matrix expression.
Examples
#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
Description
The templated class matrix_matrix_binary<E1, E2, F>
describes a binary
matrix operation.
Definition
Defined in the header matrix_expression.hpp.
Template parameters
Parameter |
Description |
Default |
|
The type of the first matrix expression. |
|
|
The type of the second matrix expression. |
|
|
The type of the operation. |
Model of
Type requirements
None, except for those imposed by the requirements of Matrix Expression .
Public base classes
matrix_expression<matrix_matrix_binary<E1, E2, F> >
.
Members
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
Prototypes
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);
Description
prod
computes the product of the matrix expressions. prec_prod
computes the double precision product of the matrix expressions.
Definition
Defined in the header matrix_expression.hpp.
Type requirements
-
E1
is a model of Matrix Expression . -
E2
is a model of Matrix Expression .
Preconditions
-
e1 ().size2 () == e2 ().size1 ()
Complexity
Cubic depending from the size of the matrix expression.
Examples
#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
Prototypes
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);
Description
solve
solves a linear equation for lower or upper (unit) triangular
matrices.
Definition
Defined in the header triangular.hpp.
Type requirements
-
E1
is a model of Matrix Expression . -
E2
is a model of Matrix Expression .
Preconditions
-
e1 ().size1 () == e1 ().size2 ()
-
e1 ().size2 () == e2 ().size1 ()
Complexity
Cubic depending from the size of the matrix expressions.
Examples
#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;
}
Copyright (©) 2000-2002 Joerg Walter, Mathias Koch
Copyright (©) 2021 Shikhar Vashistha
Use, modification and distribution are subject to the Boost Software
License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt ).
Tensor
-
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
i. Construction
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
|
ii. Assignment
Member function | Description |
---|---|
|
Evaluates the tensor expression
|
|
Copies or moves elements of |
|
Initialiates all elements of a
tensor with |
iii. Capacity
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. |
iv. Element access
Member function | Description |
---|---|
|
Returns a |
|
Returns a |
|
Returns a |
|
Returns a
|
|
Returns a |
|
Returns a |
v. Proxy Generation
Member function | Description |
---|---|
|
Returns a tensor index instance with
index objects |
vi. Iterators
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. |
vii. Modifiers
Member function | Description |
---|---|
|
Reshapes the tensor according to the extents |
viii. Notes
[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>
.
Copyright (©) 2018 Cem Bassoy
Copyright (©) 2021 Shikhar Vashistha
Use, modification and distribution are subject to the Boost Software
License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt ).
Tensor Expressions
Tensor Expression
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
Description
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.
Definition
Defined in the header tensor/expression.hpp.
Model of
Tensor Expression
Type requirements
None.
Public base classes
tensor_expression<T,binary_tensor_expression<T,EL,ER,OP>>
Template parameters
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 types
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 |
Public Member Functions
Member | Description |
---|---|
|
Returns a |
Unary Tensor Expression
Description
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.
Definition
Defined in the header tensor/expression.hpp.
Model of
Tensor Expression
Type requirements
None.
Public base classes
tensor_expression<T,unary_tensor_expression<T,E,OP>>
Template parameters
Parameter |
Description |
|
Type of the tensor. |
|
Type of the unary tensor expression. |
|
Type of the unary operation. |
Member types
Member type |
Description |
|
Type of the expression which is |
|
Reference type which is |
|
Type of the unary operation which is |
Public Member Functions
Member | Description |
---|---|
|
Returns a |
Copyright (©) 2018 Cem Bassoy
Copyright (©) 2021 Shikhar Vashistha
Use, modification and distribution are subject to the Boost Software
License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt ).
Unbounded Array Storage
Unbounded Array
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 |
Copyright (©) 2000-2002 Joerg Walter, Mathias Koch
Copyright (©) 2021 Shikhar Vashistha
Use, modification and distribution are subject to the Boost Software
License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt ).
Bounded Array Storage
Bounded Array
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 |
Copyright (©) 2000-2004 Michael Stevens, Mathias Koch, Joerg Walter,
Gunter Winkler
Copyright (©) 2021 Shikhar Vashistha
Use, modification and distribution are subject to the Boost Software
License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt ).
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.
Copyright (©) 2000-2004 Michael Stevens, Mathias Koch, Joerg Walter,
Gunter Winkler
Copyright (©) 2021 Shikhar Vashistha
Use, modification and distribution are subject to the Boost Software
License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt ).
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. |
Copyright (©) 2018 Cem Bassoy
Copyright (©) 2021 Shikhar Vashistha
Use, modification and distribution are subject to the Boost Software
License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt ).
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 |
Copyright (©) 2018 Cem Bassoy
Copyright (©) 2021 Shikhar Vashistha
Use, modification and distribution are subject to the Boost Software
License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt ).
Tensor Expressions
Tensor Expression
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
Description
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.
Definition
Defined in the header tensor/expression.hpp.
Model of
Tensor Expression
Type requirements
None.
Public base classes
tensor_expression<T,binary_tensor_expression<T,EL,ER,OP>>
Template parameters
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 types
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 |
Public Member Functions
Member | Description |
---|---|
|
Returns a |
Unary Tensor Expression
Description
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.
Definition
Defined in the header tensor/expression.hpp.
Model of
Tensor Expression
Type requirements
None.
Public base classes
tensor_expression<T,unary_tensor_expression<T,E,OP>>
Template parameters
Parameter |
Description |
|
Type of the tensor. |
|
Type of the unary tensor expression. |
|
Type of the unary operation. |
Member types
Member type |
Description |
|
Type of the expression which is |
|
Reference type which is |
|
Type of the unary operation which is |
Public Member Functions
Member | Description |
---|---|
|
Returns a |
Copyright (©) 2018 Cem Bassoy
Copyright (©) 2021 Shikhar Vashistha
Use, modification and distribution are subject to the Boost Software
License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt ).
Tensor Index
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. |
Copyright (©) 2018 Cem Bassoy
Copyright (©) 2021 Shikhar Vashistha
Use, modification and distribution are subject to the Boost Software
License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt ).
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 |
Copyright (©) 2000-2002 Joerg Walter, Mathias Koch
Copyright (©) 2021 Shikhar Vashistha
Use, modification and distribution are subject to the Boost Software
License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt ).
Special Products
Functions
template<class V, class E1, class E2> BOOST_UBLAS_INLINE V & |
axpy_prod (const matrix_expression< E1 > &e1, const vector_expression< E2 > &e2, V &v, bool init=true) computes |
template<class V, class E1, class E2> BOOST_UBLAS_INLINE V & |
axpy_prod (const vector_expression< E1 > &e1, const matrix_expression< E2 > &e2, V &v, bool init=true) computes |
template<class M, class E1, class E2> BOOST_UBLAS_INLINE M & |
axpy_prod (const matrix_expression< E1 > &e1, const matrix_expression< E2 > &e2, M &m, bool init=true) computes |
template<class M, class E1, class E2> BOOST_UBLAS_INLINE M & |
opb_prod (const matrix_expression< E1 > &e1, const matrix_expression< E2 > &e2, M &m, bool init=true) computes |
1.
|
computes
Up to now there are some specialisation for compressed matrices that give a large speed up compared to prod. |
2.
|
computes
Up to now there are some specialisation for compressed matrices that give a large speed up compared to prod. |
3.
|
computes
Up to now there are no specialisations. |
4.
|
computes
This function may give a speedup if |
Copyright (©) 2000-2004 Michael Stevens, Mathias Koch, Joerg Walter,
Gunter Winkler
Copyright (©) 2021 Shikhar Vashistha
Use, modification and distribution are subject to the Boost Software
License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt ).
Level 3 BLAS
Functions
template<class M1, class T, class M2, class M3> M1 & boost::numeric::ublas::blas_3::tmm (M1 &m1, const T &t, const M2 &m2, const M3 &m3) triangular matrix multiplication |
template<class M1, class T, class M2, class C> M1 & boost::numeric::ublas::blas_3::tsm (M1 &m1, const T &t, const M2 &m2, C) triangular solve m2 * x = t * m1 in place, m2 is a triangular matrix |
template<class M1, class T1, class T2, class M2, class M3> M1 & boost::numeric::ublas::blas_3::gmm (M1 &m1, const T1 &t1, const T2 &t2, const M2 &m2, const M3 &m3) general matrix multiplication |
template<class M1, class T1, class T2, class M2> M1 & boost::numeric::ublas::blas_3::srk (M1 &m1, const T1 &t1, const T2 &t2, const M2 &m2) symmetric rank k update: m1 = t * m1 + t2 * (m2 * m2T) |
template<class M1, class T1, class T2, class M2> M1 & boost::numeric::ublas::blas_3::hrk (M1 &m1, const T1 &t1, const T2 &t2, const M2 &m2) hermitian rank k update: m1 = t * m1 + t2 * (m2 * m2H) |
template<class M1, class T1, class T2, class M2, class M3> M1 & boost::numeric::ublas::blas_3::sr2k (M1 &m1, const T1 &t1, const T2 &t2, const M2 &m2, const M3 &m3) generalized symmetric rank k update: m1 = t1 * m1 + t2 * (m2 * m3T) + t2 * (m3 * m2T) |
template<class M1, class T1, class T2, class M2, class M3> M1 & boost::numeric::ublas::blas_3::hr2k (M1 &m1, const T1 &t1, const T2 &t2, const M2 &m2, const M3 &m3) generalized hermitian rank k update: m1 = t1 * m1 + t2 * (m2 * m3H) + (m3 * (t2 * m2)H) |
template<class M, class E1, class E2> BOOST_UBLAS_INLINE M & boost::numeric::ublas::axpy_prod (const
matrix_expression< E1 > &e1, const matrix_expression< E2 > &e2, M &m,
bool init=true) computes |
template<class M, class E1, class E2> BOOST_UBLAS_INLINE M & boost::numeric::ublas::opb_prod (const
matrix_expression< E1 > &e1, const matrix_expression< E2 > &e2, M &m,
bool init=true) computes |
Function Documentation
1.
|
|
triangular matrix multiplication |
2.
|
|
triangular solve m2 * x = t * m1 in place, m2 is a triangular matrix |
3.
|
|
general matrix multiplication |
4.
|
|
symmetric rank k update: m1 = t * m1 + t2 * (m2 * m2T)
|
5.
|
|
hermitian rank k update: m1 = t * m1 + t2 * (m2 * m2H)
|
6.
|
|
generalized symmetric rank k update: m1 = t1 * m1 + t2 * (m2 * m3T) + t2 * (m3 * m2T)
|
7.
|
|
generalized hermitian rank k update: m1 = t1 * m1 + t2 * (m2 * m3H) + (m3 * (t2 * m2)H)
|
Copyright (©) 2000-2004 Michael Stevens, Mathias Koch, Joerg Walter,
Gunter Winkler
Copyright (©) 2021 Shikhar Vashistha
Use, modification and distribution are subject to the Boost Software
License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt).
Container Concepts
Vector
Description
A Vector describes common aspects of dense, packed and sparse vectors.
Refinement of
Associated types
In addition to the types defined by Vector Expression
Public base |
vector_container<V> |
V must be derived from this public base type. |
Storage array |
V::array_type |
Dense Vector ONLY. The type of underlying storage array used to store the elements. The array_type must model the Storage concept. |
Notation
|
A type that is a model of Vector |
|
Objects of type |
|
Objects of a type convertible to |
|
Object of a type convertible to |
|
Object of a type convertible to |
Definitions
Valid expressions
In addition to the expressions defined in DefaultConstructible, Vector Expression the following expressions must be valid.
Name | Expression | Type requirements | Return type |
---|---|---|---|
Sizing constructor |
|
|
|
Insert |
|
|
|
Erase |
|
|
|
Clear |
|
|
|
Resize |
|
|
|
Storage |
|
|
|
Expression semantics
Semantics of an expression is defined only where it differs from, or is not defined in Vector Expression .
Name | Expression | Precondition | Semantics | Postcondition |
---|---|---|---|---|
Sizing constructor |
|
|
Allocates a vector of |
|
Element access [2] |
|
|
returns the n-th element in v |
|
Insert |
|
|
Inserts an
element at |
|
Erase |
|
|
Destroys the
element as |
|
Clear |
|
|
Equivalent to |
|
Resize |
|
|
Reallocates the vector so
that it can hold |
|
Storage |
|
Returns a reference to the underlying dense storage. |
|
Complexity guarantees
The run-time complexity of the sizing constructor is linear in the vector’s size.
The run-time complexity of insert_element and erase_element is specific for the Vector model and it depends on increases/decreases in storage requirements.
The run-time complexity of resize is linear in the vector’s size.
Invariants
Models
-
vector
,bounded_vector
,c_vector
-
unit_vector
,zero_vector
,scalar_vector
-
mapped_vector;
,compressed_vector
,coordinate_vector
Notes
[1] As a user you need not care about Vector being a refinement of the VectorExpression. Being a refinement of the VectorExpression is only important for the template-expression engine but not the user.
[2] The operator[]
is added purely for
convenience and compatibility with the std::vector
. In uBLAS however,
generally operator()
is used for indexing because this can be used for
both vectors and matrices.
Matrix
Description
A Matrix describes common aspects of dense, packed and sparse matrices.
Refinement of
Associated types
In addition to the types defined by Matrix Expression
Public base |
matrix_container<M> |
M must be derived from this public base type. |
Storage array |
M::array_type |
Dense Matrix ONLY. The type of underlying storage array used to store the elements. The array_type must model the Storage concept. |
Notation
|
A type that is a model of Matrix |
|
Objects of type |
|
Objects of a type convertible to |
|
Object of a type convertible to |
|
Object of a type convertible to |
Definitions
Valid expressions
In addition to the expressions defined in Matrix Expression the following expressions must be valid.
Name | Expression | Type requirements | Return type |
---|---|---|---|
Sizing constructor |
|
|
|
Insert |
|
|
|
Erase |
|
|
|
Clear |
|
|
|
Resize |
|
|
|
Storage |
|
|
|
Expression semantics
Semantics of an expression is defined only where it differs from, or is not defined in Matrix Expression .
Name | Expression | Precondition | Semantics | Postcondition |
---|---|---|---|---|
Sizing constructor |
|
|
Allocates a matrix of |
|
Insert |
|
|
Inserts an element at |
|
Erase |
|
|
Destroys the element as |
|
Clear |
|
Equivalent to |
||
Resize |
|
Reallocate the matrix so that it can hold |
|
|
Storage |
|
Returns a reference to the underlying dense storage. |
Complexity guarantees
The run-time complexity of the sizing constructor is quadratic in the matrix’s size.
The run-time complexity of insert_element and erase_element is specific for the Matrix model and it depends on increases/decreases in storage requirements.
The run-time complexity of resize is quadratic in the matrix’s size.
Invariants
Models
-
matrix
,bounded_matrix
,c_matrix
-
identity_matrix
,zero_matrix
,scalar_matrix
-
triangular_matrix
,symmetric_matrix
,banded_matrix
-
mapped_matrix
,compressed_matrix
,coordinate_matrix
Notes
[1] As a user you need not care about Matrix being a refinement of the MatrixExpression. Being a refinement of the MatrixExpression is only important for the template-expression engine but not the user.
Tensor
Description
A Tensor describes common aspects of dense multidimensional arrays.
Refinement of
Associated types
In addition to the types defined by Tensor Expression
Public base |
|
|
Storage array |
|
Dense tensor ONLY. The type of underlying storage array used to store the elements. The array_type must model the Storage concept. |
Notation
tensor_t |
A type that is a model of Tensor |
---|---|
|
Objects of type |
`n1, n2, np, m1, m2, mq ` |
Dimension objects of a type convertible to
|
`i1, i2, ip, j, k ` |
Index objects of a type convertible to |
|
Object of a type convertible to |
Definitions
Valid expressions
In addition to the expressions defined in Tensor Expression the following expressions must be valid.
Name | Expression | Type requirements | Return type |
---|---|---|---|
Sizing constructor |
|
|
|
Write |
|
|
|
Read |
|
|
|
Clear |
|
|
|
Resize |
|
|
|
Storage |
|
|
|
Expression semantics
Semantics of an expression is defined only where it differs from, or is not defined in Tensor Expression .
Name | Expression | Precondition | Semantics | Postcondition |
---|---|---|---|---|
Sizing constructor |
|
|
Allocates a |
|
Write |
|
0 < = |
Writes an element at multi-index position |
|
Read |
|
0 < = |
Reads the element at multi-index position |
|
Clear |
|
Removes all elements from the container. |
||
Resize |
|
|
Reallocate the matrix so that it can hold |
|
Storage |
|
Returns a reference to the underlying dense storage. |
Complexity guarantees
The run-time complexity of contructor is linear in the tensor’s size
n1 x n2 x … np
.
The run-time complexity of write()
and read()
is linear in the order
of the tensor.
The run-time complexity of resize is at most linear in the tensor’s size
m1 x m2 x … nq
.
Invariants
Models
-
tensor
Notes
[1] As a user you need not care about Tensor being a refinement of the TensorExpression. Being a refinement of the TensorExpression is only important for the template-expression engine but not the user.
Copyright (©) 2000-2002 Joerg Walter, Mathias Koch
Copyright (©) 2018 Cem Bassoy
Copyright (©) 2021 Shikhar Vashistha
Use, modification and distribution are subject to the Boost Software
License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt ).
Expression Concepts
Scalar Expression
Description
A Scalar Expression is an expression convertible to a scalar type.
Refinement of
Default Constructible.
Associated types
Public base |
scaler_expression<S> |
S must be derived from this public base type. |
Value type |
|
The type of the scalar expression. |
Notation
|
A type that is a model of Scalar Expression |
Definitions
Valid expressions
In addition to the expressions defined in Default Constructible the following expressions must be valid.
Name |
Expression |
Type requirements |
Return type |
Evaluation |
|
|
|
Expression semantics
Semantics of an expression is defined only where it differs from, or is not defined in Default Constructible.
Name | Expression | Precondition | Semantics | Postcondition |
---|---|---|---|---|
Evaluation |
|
|
Evaluates the scalar expression. |
|
Complexity guarantees
The run-time complexity of the evaluation is specific for the evaluated scalar expression.
Invariants
Models
-
vector_scalar_unary
-
vector_scalar_binary
Vector Expression
Description
A Vector Expression is an expression evaluatable to a vector. Vector Expression provides an Indexed Bidirectional Iterator or an Indexed Random Access Iterator .
Refinement of
Default Constructible.
Associated types
Public base |
vector_expression<V> |
V must be derived from this public base type. |
Value type |
|
The element type of the vector expression. |
Reference type |
|
The return type when accessing an element
of a vector expression. |
Const reference type |
|
The return type when accessing
an element of a constant vector expression. |
Size type |
|
The index type of the vector expression. Am
unsigned integral type used to represent size and index values. |
Distance type |
|
A signed integral type used to represent the distance between two of the vector expression’s iterators. |
Const iterator type |
|
A type of iterator that may be used to examine a vector expression’s elements. |
Iterator type |
|
A type of iterator that may be used to modify a vector expression’s elements. |
Const reverse iterator type |
|
A Reverse Iterator adaptor whose base iterator type is the vector expression’s const iterator type. |
Reverse iterator type |
|
A Reverse Iterator adaptor whose base iterator type is the vector expression’s iterator type. |
Notation
|
A type that is a model of Vector Expression |
|
Object of type |
|
Object of a type convertible to |
|
Object of a type convertible to |
Definitions
Valid expressions
In addition to the expressions defined in Default Constructible the following expressions must be valid.
Name | Expression | Type requirements | Return type |
---|---|---|---|
Beginning of range |
|
|
|
|
|
|
|
End of range |
|
|
|
|
|
|
|
Size |
|
|
|
Swap |
|
|
|
Beginning of reverse range |
|
|
|
|
|
|
|
End of reverse range |
|
|
|
|
|
|
|
Element access |
|
|
Convertible to |
Assignment |
|
|
|
|
|
|
|
Computed assignment |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Expression semantics
Semantics of an expression is defined only where it differs from, or is not defined in Default Constructible.
Name | Expression | Precondition | Semantics | Postcondition |
---|---|---|---|---|
Beginning of range |
|
|
Returns an iterator pointing to the first element in the vector expression. |
|
End of range |
|
|
Returns an iterator pointing one past the last element in the vector expression. |
|
Size |
|
|
Returns the size of the vector expression, that is, its number of elements. |
|
Swap |
|
|
Equivalent to |
|
Beginning of reverse range |
|
|
Equivalent to
|
|
End of reverse range |
|
|
Equivalent to
|
|
Element access |
|
|
Returns the |
|
Assignment |
|
|
Assigns every
element of the evaluated vector expression |
|
|
|
Assigns every element
of |
|
|
Computed assignment |
|
|
Adds every
element of the evaluated vector expression |
|
|
|
Adds every element
of |
|
|
|
|
Subtracts every element of
the evaluated vector expression |
|
|
|
|
Subtracts every
element of |
|
|
|
|
Multiplies every element of |
|
Complexity guarantees
The run-time complexity of begin ()
and end ()
is specific for the
evaluated vector expression, typically amortized constant time.
The run-time complexity of size ()
is constant time.
The run-time complexity of swap ()
is specific for the evaluated
vector expression, typically constant time.
The run-time complexity of rbegin ()
and rend ()
is specific for the
evaluated vector expression, typically amortized constant time.
The run-time complexity of the element access is specific for the evaluated vector expression, typically amortized constant time for the dense and logarithmic for the sparse case.
The run-time complexity of the arithmetic operations is specific for the evaluated vector expressions, typically linear in the size of the expressions.
Invariants
Valid range |
For any vector expression |
Completeness |
An algorithm that iterates through the range
|
Valid reverse range |
|
Equivalence of ranges |
The distance from |
Models
-
vector_range;
-
vector_slice
-
matrix_row
-
matrix_column
-
matrix_vector_range
-
matrix_vector_slice
-
vector_unary
-
vector_binary
-
vector_binary_scalar1
-
vector_binary_scalar2
-
matrix_vector_unary1
-
matrix_vector_unary2
-
matrix_vector_binary1
-
matrix_vector_binary2
Matrix Expression
Description
A Matrix Expression is an expression evaluatable to a matrix. Matrix Expression provides an Indexed Bidirectional Column/Row Iterator or an Indexed Random Access Column/Row Iterator .
Refinement of
Default Constructible.
Associated types
immutable types
Public base |
|
M must be derived from this public base type. |
Value type |
|
The element type of the matrix expression. |
Const reference type |
|
The return type when accessing
an element of a constant matrix expression. |
Size type |
|
The index type of the matrix expression. Am
unsigned integral type used to represent size and index values. |
Distance type |
|
A signed integral type used to represent the distance between two of the matrix expression’s iterators. |
Const iterator types |
|
A type of column iterator that may be used to examine a matrix expression’s elements. |
|
A type of row iterator that may be used to examine a matrix expression’s elements. |
|
Const reverse iterator types |
|
A Reverse Iterator adaptor whose base iterator type is the matrix expression’s const column iterator type. |
|
A Reverse Iterator adaptor whose base iterator type is the matrix expression’s const row iterator type. |
mutable types
Reference type |
|
The return type when accessing an element
of a matrix expression. |
Iterator types |
|
A type of column iterator that may be used to modify a matrix expression’s elements. |
|
A type of row iterator that may be used to modify a matrix expression’s elements. |
|
Reverse iterator types |
|
A Reverse Iterator adaptor whose base iterator type is the matrix expression’s column iterator type. |
|
A Reverse Iterator adaptor whose base iterator type is the matrix expression’s row iterator type. |
Notation
|
A type that is a model of Matrix Expression |
|
Object of type |
|
Objects of a type convertible to |
|
Object of a type convertible to |
Definitions
Valid expressions
In addition to the expressions defined in Default Constructible the following expressions must be valid.
immutable expressions
Name | Expression | Type requirements | Return type |
---|---|---|---|
Size |
|
|
|
|
|
|
possibly mutable expressions
Name | Expression | Type requirements | Return type |
---|---|---|---|
Beginning of range |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
End of range |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Swap |
|
|
|
Beginning of reverse range |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
End of reverse range |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Element access |
|
|
Convertible to |
Assignment |
|
|
|
|
|
|
|
Computed assignment |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Expression semantics
Semantics of an expression is defined only where it differs from, or is not defined in Default Constructible.
Name | Expression | Precondition | Semantics | Postcondition |
---|---|---|---|---|
Beginning of range |
|
|
Returns an iterator pointing to the first element in the first column of a matrix expression. |
|
|
|
Returns an iterator pointing to the first element in the first row of a matrix expression. |
|
|
End of range |
|
|
Returns an iterator pointing one past the last element in the matrix expression. |
|
|
|
Returns an iterator pointing one past the last element in the matrix expression. |
|
|
Size |
|
|
Returns the number of rows of the matrix expression. |
|
|
|
Returns the number of columns of the matrix expression. |
|
|
Swap |
|
|
Equivalent to |
|
Beginning of reverse range |
|
|
Equivalent to
|
|
|
|
Equivalent to |
|
|
End of reverse range |
|
|
Equivalent to
|
|
|
|
Equivalent to |
|
|
Element access |
|
|
Returns the |
|
Assignment |
|
|
Assigns every element of the evaluated
matrix expression |
|
|
|
Assigns every element of |
|
|
Computed assignment |
|
|
Adds every element of the evaluated
matrix expression |
|
|
|
Adds every element of |
|
|
|
|
Subtracts every element of the evaluated
matrix expression |
|
|
|
|
Subtracts every element of |
|
|
|
|
Multiplies every element of |
|
Complexity guarantees
The run-time complexity of begin1 ()
, begin2 ()
, end1 ()
and
end2 ()
is specific for the evaluated matrix expression.
The run-time complexity of size1 ()
and size2 ()
is constant time.
The run-time complexity of swap ()
is specific for the evaluated
matrix expression, typically constant time.
The run-time complexity of rbegin1 ()
, rbegin2 ()
, rend1 ()
and
rend2 ()
is specific for the evaluated matrix expression.
The run-time complexity of the element access is specific for the evaluated matrix expression, typically amortized constant time for the dense and logarithmic for the sparse case.
The run-time complexity of the arithmetic operations is specific for the evaluated matrix expressions, typically quadratic in the size of the proxies.
Invariants
Valid range |
For any matrix expression |
Completeness |
An algorithm that iterates through the range
|
Valid reverse range |
|
Equivalence of ranges |
The distance from |
Models
-
matrix_range
-
matrix_slice;
-
triangular_adaptor
-
symmetric_adaptor
-
banded_adaptor
-
vector_matrix_binary
-
matrix_unary1
-
matrix_unary2
-
matrix_binary
-
matrix_binary_scalar1
-
matrix_binary_scalar2
-
matrix_matrix_binary
Copyright (©) 2000-2002 Joerg Walter, Mathias Koch
Copyright (©) 2021 Shikhar Vashistha
Use, modification and distribution are subject to the Boost Software
License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt ).
Storage concept
Storage concept
Description
Storage is a variable-size container whose elements are arranged in a strict linear order.
Storage extends the STL Container concept with some STL Sequence-like functionality. The main difference with the Sequence concept however is that the Storage concept does not require default-initialisation of its elements.
Refinement of
Associated types
No additional types beyond those defined by Random Access Container
Notation
X |
A type that is model of Storage |
T |
The value_type of X |
t |
An object of type T |
n |
object of type convertible to X::size_type |
Definitions
Valid expressions
In addition to the expressions defined in Random Access Container, and Default Constructible the following expressions must be valid:
Name | Expression | Type requirements | Return type |
---|---|---|---|
Size constructor |
X(n) |
T is DefaultConstructible |
X |
Fill constructor |
X(n,t) |
X |
|
Range constructor |
X(i, j) |
i and j are Input Iterators whose value type is convertible to T |
X |
Resize |
a.resize(n, t) |
a is mutable |
void |
Resize |
a.resize(n) |
a is mutable |
void |
Expression semantics
Name | Expression | Precondition | Semantics | Postcondition |
---|---|---|---|---|
Default-constructor |
X() |
Creates 0 elements |
size()==0 |
|
Size-constructor |
X(n) |
n>=0 |
Creates n elements. Elements are constructed without an initializer. That is if T is a (possibly cv-qualified) non-POD class type (or array thereof), the object is default initialized. Otherwise, the object created has indeterminate value. See the sentance "If new initializer is omitted" in section 5.3.4 paragraph 15 of the ISO C++ standard. |
size()==n |
Fill-constructor |
X(n,t) |
n>=0 |
Creates n initialised element with copies of |
size()==n |
Range constructor |
X(i, j) |
[i,j) is a valid range. |
copies the range [i,j) to the storage |
size() is equal to the distance from i to j. Each element is a copy of the corresponding element in the range [i,j). |
Resize |
a.resize(n, t) |
n ⇐ a.max_size() |
Modified the container so that it has exactly n elements. + The container may be reallocated if its size changes. Existing element values are preserved, additional elements are copies of |
a.size() == n |
Resize |
a.resize(n) |
n ⇐ a.max_size() |
Modified the container so that it has exactly n elements. + The container may be reallocated if its size changes. Element values are uninitialised. That is, each element value may be a previously assigned value or default construced value for |
a.size() == n |
Complexity guarantees
Invariants
Models
Notes
Copyright (©) 2000-2002 Joerg Walter, Mathias Koch
Copyright (©) 2021 Shikhar Vashistha
Use, modification and distribution are subject to the Boost Software
License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt ).
Iterator Concepts
An Iterator is a restricted pointer-like object pointing into a vector or matrix container.
Indexed Bidirectional Iterator
Description
An Indexed Bidirectional Iterator is an iterator of a container that can be dereferenced, incremented, decremented and carries index information.
Refinement of
Assignable, Equality Comparable, Default Constructible.
Associated types
Value type |
The type of the value obtained by dereferencing a Indexed Bidirectional Iterator |
Container type |
The type of the container a Indexed Bidirectional Iterator points into. |
Notation
|
A type that is a model of Indexed Bidirectional Iterator |
|
The value type of |
|
The container type of |
|
Objects of type |
|
Object of type |
|
Object of type |
Definitions
A Indexed Bidirectional Iterator may be mutable, meaning that the values referred to by objects of that type may be modified, or constant , meaning that they may not. If an iterator type is mutable, this implies that its value type is a model of Assignable; the converse, though, is not necessarily true.
A Indexed Bidirectional Iterator may have a singular value, meaning that the results of most operations, including comparison for equality, are undefined. The only operation that is guaranteed to be supported is assigning a nonsingular iterator to a singular iterator.
A Indexed Bidirectional Iterator may have a dereferenceable value, meaning that dereferencing it yields a well-defined value. Dereferenceable iterators are always nonsingular, but the converse is not true.
An Indexed Bidirectional Iterator is past-the-end if it points beyond the last element of a container. Past-the-end values are nonsingular and nondereferenceable.
Valid expressions
In addition to the expressions defined for Assignable, Equality Comparable and Default Constructible, the following expressions must be valid.
Name |
Expression |
Type requirements |
Return type |
Default constructor |
|
|
|
Dereference |
|
|
Convertible to |
Dereference assignment |
|
|
|
Member access |
|
|
|
Preincrement |
|
|
|
Postincrement |
|
|
|
Predecrement |
|
|
|
Postdecrement |
|
|
|
Index |
|
|
|
Expression Semantics
Semantics of an expression is defined only where it differs from, or is not defined in, Assignable, Equality Comparable and Default Constructible.
Name | Expression | Precondition | Semantics | Postcondition |
---|---|---|---|---|
Default constructor |
|
|
|
|
Dereference |
|
|
|
|
Dereference assignment |
|
Same as for |
|
|
Member access |
|
|
Equivalent to
|
|
Preincrement |
|
|
|
|
Postincrement |
|
Same as for |
Equivalent to |
|
Predecrement |
|
|
|
|
Postdecrement |
|
Same as for — |
Equivalent to |
|
Index |
|
|
|
If |
Complexity guarantees
The complexity of operations on indexed bidirectional iterators is guaranteed to be amortized constant time.
Invariants
Identity | it1 == it2 if and only if &*it1 == &*it2 . |
---|---|
Symmetry of increment and decrement |
If |
Relation between iterator index and container element operator |
If |
Models
-
sparse_vector::iterator
Indexed Random Access Iterator
Description
An Indexed Random Access Iterator is an iterator of a container that can be dereferenced, moved forward, moved backward and carries index information.
Refinement of
LessThanComparable, Indexed Bidirectional Iterator .
Associated types
Value type |
The type of the value obtained by dereferencing a Indexed Random Access Iterator |
Container type |
The type of the container a Indexed Random Access Iterator points into. |
Notation
|
A type that is a model of Indexed Random Access Iterator |
|
The value type of |
|
The container type of |
|
Objects of type |
|
Object of type |
|
Object of type |
Definitions
An Indexed Random Access Iterator it1
is reachable from an Indexed
Random Access Iterator it2
if, after applying operator ++
to it2
a
finite number of times, it1 == it2
.
Valid expressions
In addition to the expressions defined for Indexed Bidirectional Iterator , the following expressions must be valid.
Name |
Expression |
Type requirements |
Return type |
Forward motion |
|
|
|
Iterator addition |
|
|
|
Backward motion |
|
|
|
Iterator subtraction |
|
|
|
Difference |
|
|
|
Element operator |
|
|
Convertible to |
Element assignment |
|
|
Convertible to |
Expression Semantics
Semantics of an expression is defined only where it differs from, or is not defined in, Indexed Bidirectional Iterator .
Name | Expression | Precondition | Semantics | Postcondition |
---|---|---|---|---|
Forward motion |
|
Including |
If |
|
Iterator addition |
|
Same as for |
Equivalent to |
Result is dereferenceable or past-the-end. |
Backward motion |
|
Including |
Equivalent to
|
|
Iterator subtraction |
|
Same as for |
Equivalent to |
Result is dereferenceable or past-the-end. |
Difference |
|
Either |
Returns a number |
|
Element operator |
|
|
Equivalent to |
|
Element assignment |
|
Same as for |
Equivalent to
|
|
Complexity guarantees
The complexity of operations on indexed random access iterators is guaranteed to be amortized constant time.
Invariants
Symmetry of addition and subtraction |
If |
Relation between distance and addition |
If |
Reachability and distance |
If |
Models
-
vector::iterator
Indexed Bidirectional Column/Row Iterator
Description
An Indexed Bidirectional Column/Row Iterator is an iterator of a container that can be dereferenced, incremented, decremented and carries index information.
Refinement of
Assignable, Equality Comparable, Default Constructible.
Associated types
Value type |
The type of the value obtained by dereferencing a Indexed Bidirectional Column/Row Iterator |
Container type |
The type of the container a Indexed Bidirectional Column/Row Iterator points into. |
Notation
|
A type that is a model of Indexed Bidirectional Column/Row Iterator |
|
A type that is a model of Indexed Bidirectional Row/Column Iterator |
|
The value type of |
|
The container type of |
|
Objects of type |
|
Objects of type |
|
Object of type |
|
Object of type |
Definitions
Valid expressions
In addition to the expressions defined for Assignable, Equality Comparable and Default Constructible, the following expressions must be valid.
Name |
Expression |
Type requirements |
Return type |
Default constructor |
|
|
|
Dereference |
|
|
Convertible to |
Dereference assignment |
|
|
|
Member access |
|
|
|
Preincrement |
|
|
|
Postincrement |
|
|
|
Predecrement |
|
|
|
Postdecrement |
|
|
|
Row Index |
|
|
|
Column Index |
|
|
|
Row/Column Begin |
|
|
|
Row/Column End |
|
|
|
Reverse Row/Column Begin |
|
|
|
Reverse Row/Column End |
|
|
|
Expression Semantics
Semantics of an expression is defined only where it differs from, or is not defined in, Assignable, Equality Comparable and Default Constructible.
Name | Expression | Precondition | Semantics | Postcondition |
---|---|---|---|---|
Default constructor |
|
|
|
|
Dereference |
|
|
|
|
Dereference assignment |
|
Same as for |
|
|
Member access |
|
|
Equivalent to
|
|
Preincrement |
|
|
|
|
Postincrement |
|
Same as for |
Equivalent to |
|
Predecrement |
|
|
|
|
Postdecrement |
|
Same as for — |
Equivalent to |
|
Row Index |
|
If |
|
If |
Column Index |
|
If |
|
If |
Row/Column Begin |
|
|
If If |
|
Row/Column End |
|
|
If If |
|
Reverse Row/Column Begin |
|
|
Equivalent to |
|
Reverse Row/Column End |
|
|
Equivalent to |
|
Complexity guarantees
The complexity of operations on indexed bidirectional column/row iterators is guaranteed to be logarithmic depending on the size of the container. The complexity of one iterator (depending on the storage layout) can be lifted to be amortized constant time. The complexity of the other iterator (depending on the storage layout and the container) can be lifted to be amortized constant time for the first row/first column respectively.
Invariants
Identity | it1 == it2 if and only if &*it1 == &*it2 . |
---|---|
Symmetry of increment and decrement |
If |
Relation between iterator index and container element operator |
If |
Relation between iterator column/row begin and iterator index |
If If |
Relation between iterator column/row end and iterator index |
If If |
Models
-
sparse_matrix::iterator1
-
sparse_matrix::iterator2
Indexed Random Access Column/Row Iterator
Description
An Indexed Random Access Column/Row Iterator is an iterator of a container that can be dereferenced, incremented, decremented and carries index information.
Refinement of
Associated types
Value type |
The type of the value obtained by dereferencing a Indexed Random Access Column/Row Iterator |
Container type |
The type of the container a Indexed Random Access Column/Row Iterator points into. |
Notation
|
A type that is a model of Indexed Random Access Column/Row Iterator |
|
The value type of |
|
The container type of |
|
Objects of type |
|
Object of type |
|
Object of type |
Definitions
Valid expressions
In addition to the expressions defined for Indexed Bidirectional Column/Row Iterator , the following expressions must be valid.
Name |
Expression |
Type requirements |
Return type |
Forward motion |
|
|
|
Iterator addition |
|
|
|
Backward motion |
|
|
|
Iterator subtraction |
|
|
|
Difference |
|
|
|
Element operator |
|
|
Convertible to |
Element assignment |
|
|
Convertible to |
Expression Semantics
Semantics of an expression is defined only where it differs from, or is not defined in, Indexed Bidirectional Column/Row Iterator .
Name | Expression | Precondition | Semantics | Postcondition |
---|---|---|---|---|
Forward motion |
|
Including |
If |
|
Iterator addition |
|
Same as for |
Equivalent to |
Result is dereferenceable or past-the-end. |
Backward motion |
|
Including |
Equivalent to
|
|
Iterator subtraction |
|
Same as for |
Equivalent to |
Result is dereferenceable or past-the-end. |
Difference |
|
Either |
Returns a number |
|
Element operator |
|
|
Equivalent to |
|
Element assignment |
|
Same as for |
Equivalent to
|
|
Complexity guarantees
The complexity of operations on indexed random access Column/Row iterators is guaranteed to be amortized constant time.
Invariants
Symmetry of addition and subtraction |
If |
Relation between distance and addition |
If |
Reachability and distance |
If |
Models
-
matrix::iterator1
-
matrix::iterator2
Copyright (©) 2000-2002 Joerg Walter, Mathias Koch
Copyright (©) 2021 Shikhar Vashistha
Use, modification and distribution are subject to the Boost Software
License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt ).
Appendix A: Copyright and License
This documentation is
-
Copyright 2021 Shikhar Vashistha
and is distributed under the Boost Software License, Version 1.0.