|
Boost.Numeric.BindingsIndex |
The Bindings Library contains bindings to popular non-boost (numeric) libraries, usually written in Fortran or C. These non-boost libraries generally use data structures in their API for which there might be boostified equivalents or other popular non-boost equivalents. The Bindings Library offers a generic thin layer API on top of the original API of the external library. This generic API accepts a whole range of data structures from different origins and usually hides or reduces the complexity of the original API.
For instance, ATLAS, a C library implementing BLAS (and few LAPACK routines), represents matrices by means of a pointer and the dimensions. Now boost also contains matrix classes (uBLAS) and there are also other matrix libraries in widespread use. Therefore the Bindings library features a generic interface for ATLAS which provides the possibility to call e.g. the matrix-multiplication routine of ATLAS using matrices defined in uBLAS, TNT, etc.:
#include <boost/numeric/bindings/traits/ublas_matrix.hpp> #include <boost/numeric/bindings/traits/tnt.hpp> #include <boost/numeric/bindings/atlas/cblas3.hpp> namespace ublas = boost::numeric::ublas; namespace atlas = boost::numeric::bindings::atlas; int main() { ublas::matrix<double> A1 (2,2), B1 (2,3), C1 (2,3); // initialisation... // C1 <- A1 * B1 : atlas::gemm (A1, B1, C1); ublas::matrix<double, ublas::column_major> A2 (2,3), B2 (2,2), C2 (3,2); // ... // C2 <- A2^T * B2^T : atlas::gemm (CblasTrans, CblasTrans, 1.0, A2, B2, 0.0, C2); TNT::Array2D<double> A3 (2,2), B3 (2,3), C3 (2, 3); // ... // C3 <- A3^T * B3 : atlas::gemm (CblasTrans, CblasNoTrans, 1.0, A3, B3, 0.0, C3); TNT::Fortran_Array2DIn short,A4 (2,2), B4 (2,3), C4 (2, 3); // ... // C4 <- 2.0 * A4 * B4 + C4 : atlas::gemm (2.0, A4, B4, 1.0, C4); }
gemm()
is BLAS/ATLAS matrix multiplication
function. ATLAS bindings provide
three convenient overloads:
C <- a * op (A) * op (B) + b * C C <- a * A * B + b * C C <- A * Bwhere
a
, b
are scalars,
A
, B
, C
are (rectangular) matrices and
op (A)
== A
|| A
T || A
H.
Function gemm()
is BLAS level 3 routine and therefore
atlas/cblas3.hpp
should be included (all headers
are in subdirectories of boost/numeric/bindings
).
To use bindings with ublas::matrix<>
one should
include traits/ublas_matrix.hpp
(note that there is no
need to include boost/numeric/ublas/matrix.hpp
separately) and to use them with TNT
arrays traits/tnt.hpp
should be included; to learn more
about traits classes see chapter Traits.