Boost Basic Linear Algebra - Configuration Options
NDEBUG
Make sure you define NDEBUG The only way uBLAS
knows you want a release configuration is to check if you have defined
NDEBUG. If you don't it assumes you want a debug configuration and
adds a lot of very useful runtime check. However these are very slow!
BOOST_UBLAS_MOVE_SEMANTICS
The patch and description was provided by Nasos Iliopoulos.
An immediate effect of this option is the elimination of the need
for noalias in types vector<T> and matrix<T>,
when assigned to the same type. This option doesn't have an effect on
bounded and c types. Although it is rare, not all compilers support copy
elision (that allows for move semantics), so a test must be performed to
make sure that there is a benefit when it is enabled. A small
demonstration and test can be found in
test_move_semantics.cpp
In the test
example two tests are defined, one for vectors and one for
matrices. The aim of this example is to print the pointers of the
storage of each of the containers, before and after the assignment to
a temporary object. When move semantics are enabled, the
vector<T> and matrix<T> storage is moved
from the temporary and no copy is performed.
If move semantics are supported by your compiler you will get an output like the following:
matrix<double> --------------------------------------------------------------------
Temporary pointer r: 0x94790c0
Pointer (must be equal to temp. pointer if move semantics are enabled) : 0x94790c0
Notes:
- It should be no surprise to see matrices and vectors been passed
by VALUE, the compiler takes care and either moves (if the underlying
code does not modify the object), or copies (if the underlying code
modifies the object).
- There might be some space for some improvements (like clearing the
data, before swaping)
- Move semantics don't eliminate temporaries. They rather move their
storage around so no copies are performed.
- MSVC does no implement Named Return Value Optimization in debug
mode. So if you build in debug with this compiler you might get different behaviour than a release build.
- Enabling move semantics is done via #define BOOST_UBLAS_MOVE_SEMANTICS.
- There is plenty of room for optimizations when c++0x standard is
out, taking advantage of rvalue references. (I have a sweet vector
implementation using that).
- If you enable move semantics and your compiler does not support
them, the operation will just be as passing by const reference.
Interesting links
BOOST_UBLAS_CHECK_ENABLE
When BOOST_UBLAS_CHECK_ENABLE is defined then all index and
parameter checks are enabled. This is enabled in debug mode and
disabled in release mode.
BOOST_UBLAS_TYPE_CHECK
When BOOST_UBLAS_TYPE_CHECK is enabled then all possibly expensive
structure checks are enabled. If this is not desireable then use
#define BOOST_UBLAS_TYPE_CHECK 0 before including any uBLAS
header. The define BOOST_UBLAS_TYPE_CHECK_EPSILON can be used to
control the acceptable tolerance, see
detail/matrix_assign.hpp for implementation details of this
check.
BOOST_UBLAS_USE_LONG_DOUBLE
Enable uBLAS expressions that involve containers of 'long double'
BOOST_UBLAS_USE_INTERVAL
Enable uBLAS expressions that involve containers of 'boost::numeric::interval' types
Configuring uBLAS with Macros
Many macro's appear in ublas/config.hpp and elsewhere. Hopefully in the future some of these will disappear!
They fall into 4 groups:
- Automatically set by 'boost/numeric/ublas/config.hpp' based on
NDEBUG. Makes the distinction between debug (safe) and release (fast)
mode. Similar to STLport
- Release mode (NDEBUG defined)
- BOOST_UBLAS_INLINE Compiler dependant definition to control
function inlining.
- BOOST_UBLAS_USE_FAST_SAME
- Debug mode
- BOOST_UBLAS_CHECK_ENABLE Enable checking of indexs, iterators
and parameters. Prevents out of bound access etc.
-
BOOST_UBLAS_TYPE_CHECK Enable additional checks for the results of
expressions using non dense types. Picks up runtime error such as the
assignment of a numerically non-symmetric matrix to
symmertic_matrix. Use #define BOOST_UBLAS_TYPE_CHECK 0 to
disable expensive numeric type checks. (Note: "structure check"
would be a much better name.)
-
BOOST_UBLAS_TYPE_CHECK_EPSILON default: sqrt(epsilon), controls how
large the difference between the expected result and the computed
result may become. Increase this value if you are going to use near
singular or badly scaled matrices. Please, refer to
detail/matrix_assign.hpp for implementation of these type
checks.
- Automatically set by 'boost/numeric/ublas/config.hpp' based on
compiler and boost/config.hpp macro's. Augments the compiler
deficiency workarounds already supplied by boost/config.hpp
- BOOST_UBLAS_NO_NESTED_CLASS_RELATION A particularly nasty
problem with VC7.1 Requires that uBLAS and the user use begin(it)
rather then it.begin()
- BOOST_UBLAS_NO_SMART_PROXIES
Disable the automatic propagation of 'constantness' to
proxies. Smart proxies automatically determine if the underling
container they reference is constant or not. They adjust there
definition of iterators and container access to reflect this
constantness.
- For use by uBLAS authors to test implementation methods. Preset
in config.hpp
- BOOST_UBLAS_USE_INVARIANT_HOISTING
-
BOOST_UBLAS_USE_INDEXING
- BOOST_UBLAS_USE_INDEXED_ITERATOR
- BOOST_UBLAS_NON_CONFORMANT_PROXIES Gappy containers may
be non-conformant, that is contain elements at different
indices. Assigning between proxies (vector ranges for example) of
these containers is difficult as the LHS may need insert new
elements. This is slow.
- BOOST_UBLAS_USE_DUFF_DEVICE
Near useless on all platforms (see GCC's -funroll-loops)
- User options. Can be predefined by user before including any
uBLAS headers. They may also be automatically defined for some
compilers to work around compile bugs.
- BOOST_UBLAS_USE_LONG_DOUBLE Enable uBLAS expressions that
involve containers of 'long double'
-
BOOST_UBLAS_USE_INTERVAL Enable uBLAS expressions that involve
containers of 'boost::numeric::interval' types
-
BOOST_UBLAS_SIMPLE_ET_DEBUG In order to simplify debugging is is
possible to simplify expression templateso they are restricted to a
single operation
- BOOST_UBLAS_ENABLE_PROXY_SHORTCUTS enable automatic
conversion from proxy class to matrix expression
-
BOOST_UBLAS_NO_ELEMENT_PROXIES Disables the use of element proxies
for gappy types.
- The Gappy types (sparse, coordinate,
compressed) store non-zero elements in their own containers. When new
non-zero elements are assigned they must rearrange these
containers. This invalidates references, iterators or pointers to
these elements. This can happen at some surprising times such as the
expression "a [1] = a [0] = 1;". Element proxies guarantee all such
expressions will work as expected. However they bring their own
restrictions and efficiency problems. For example as of Boost 1.30.0
they prevent the assignment of elements between different types.
- BOOST_UBLAS_REFERENCE_CONST_MEMBER Enable to allow refernces
to be returned to fixed (zero or one) elements of triangular or banded
matrices
- BOOST_UBLAS_NO_EXCEPTIONS Disable the use exceptions of
uBLAS internal checks and error conditions. BOOST_NO_EXCEPTIONS has
same effect.
- BOOST_UBLAS_SINGULAR_CHECK Check the for singularity in triangular solve() functions
Copyright (©) 2000-2009 Joerg Walter, Mathias Koch, Gunter Winkler
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
).
Last modified: Wed Sep 16 23:16:45 CEST 2009