Numeric Library Bindings for Boost UBlas

Submitted by inducer on Sat, 21/01/2006 - 00:37

Boost Bindings is a bindings library (not just) for Boost.Ublas. It offers an easy way of calling BLAS, LAPACK, UMFPACK, MUMPS and many other mature legacy numerical codes from within C++.

This library was mainly written by Kresimir Fresl and others a few years back, and has since languished in dark corners of version control systems. Many people (including myself) posted improvements, some got integrated, others got silently dropped on the floor.

This here is my contribution to keeping the bindings alive: I try to collect contributions and roll them into downloadable releases, in the hope of making the library more accessible to potential users. Previously, all I did was make snapshot releases of the current state of CVS; this has changed. The most recent release includes significant updates scavenged from the Boost.Ublas mailing list, see the version control browser below for details.

(Disclaimer: Though I have contributed to the library, it is mostly other people’s work that I rerelease here.)

Obtaining a Copy

Download ready-made releases. Check out of version control:

git clone http://git.tiker.net/trees/boost-numeric-bindings.git

Browse the current git tree.

Installation

Download the archive, then type the following commands into your shell:

$ tar xvfz /where/to/you/downloaded/it/boost-numeric-bindings-NNNNNNNN-.tar.gz
$ cd boost-numeric-bindings
$ ./configure --prefix=/where/you/want/to/install/it
$ make install

Then, when compiling your boost-numeric-bindings-dependent software, do that with

$ c++ -I/where/you/want/to/install/it/include/boost-numeric-bindings

or, for, previous versions:

$ c++ -I/where/you/want/to/install/it/include/boost-bindings

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Is there a binding for Intel MKL or am I just missing something? Quite strange how such well-known math library isnt one of them?

  • I presume the BLAS/LAPACK portions of MKL are accessible through the bindings.
  • The content of the bindings is driven by people’s needs. So far, nobody has seemed to need what’s in MKL.
  • In my highly personal opinion, MKL is vendor-specific and therefore undesirable for my work.

That said, if you’re feeling a pressing need for something in the MKL, I’m sure your contribution would be more than welcome.

Andreas

Hi,

I’m using gels, gelss and gelsd of bindings-20080816 to solve least squares problems and I noticed typename is missing.

boost/numeric/bindings/lapack/gels.hpp

Line 151
- MatrA::value_type work;
+ typename MatrA::value_type work;
Line 180
- traits::detail::array<MatrA::value_type> work(work_size);
+ traits::detail::array<typename MatrA::value_type> work(work_size);
Line 197
- traits::detail::array<MatrA::value_type> work(minmn + std::max(1, maxdim));
+ traits::detail::array<typename MatrA::value_type> work(minmn + std::max(1, maxdim));

boost/numeric/bindings/lapack/gelss.hpp

Line 81, 123, 191, 246, 266
- typedef traits::type_traits<val_t>::real_type real_t;
+ typedef typename traits::type_traits<val_t>::real_type real_t;

boost/numeric/bindings/lapack/gelsd.hpp

Line 86, 136, 217, 282, 310, 405
- typedef traits::type_traits<val_t>::real_type real_t;
+ typedef typename traits::type_traits<val_t>::real_type real_t;

Cheers,

Naoki

Applied, thanks!

Andreas

Hi I seem to be doing something wrong here. Here is the code I’m trying to run:

namespace ublas = boost::numeric::ublas;
namespace lapack = boost::numeric::bindings::lapack;

int main()
{
  ublas::matrix<double, ublas::column_major> mme ( 3,3);
  ublas::matrix<double,ublas::column_major>temp(3,1);
  lapack::gesv(mme,temp);
}

I try to compile with the following command:

gcc  example1.cpp -o example1 -lboost_filesystem

and I get the following error message:

/tmp/ccD9EEmm.o: In function
`boost::numeric::bindings::lapack::detail::gesv(int, int, double*, int,
int*, double*, int, int*)':
example1.cpp:(.text._ZN5boost7numeric8bindings6lapack6detail4gesvEiiPdiPiS4_iS5_
[boost::numeric::bindings::lapack::detail::gesv(int, int, double*, int,
int*, double*, int, int*)]+0x59): undefined reference to `dgesv_'
collect2: ld returned 1 exit status

I see that a previous posts had a similar problem with seems related to clapack but I’m using regular lapack Any thoughts?

Thanks K

[Edited for markup and brevity —Andreas]

You need to link with lapack, -llapack, plus any flags libraries that your lapack requires. Likely, that’ll be -lf77blas -latlas or some such.

I guess it’s time for a dumb question. I’m really green on the subject so please forgive me, but is there any information on how to install the library? K

I’ve written something in the main page text.

Hope that helps, Andreas

Hello,

I’m using the Bindings library in a large project to bind standard BLAS implementations to our own data types. We’re using traits definitions for this and I just noticed that there are some checks missing for the BOOST_NUMERIC_POOR_MANS_TRAITS define in blas/blas1.hpp for the functions dotu and dotc.

Here’s a quick svn diff for my fix to this.

Cheers Roel

Index: blas/blas1.hpp
===================================================================
—- blas/blas1.hpp      (revision 47501)
+++ blas/blas1.hpp      (working copy)
@@ -130,7 +130,13 @@
 #endif
     assert( traits::vector_size( x ) == traits::vector_size( y ) ) ;
 
-    typedef typename vector_type_x::value_type value_type ;
+    typedef
+#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
+    typename traits::vector_traits< vector_type_x >::value_type
+#else
+    typename vector_type_x::value_type
+#endif
+    value_type ;
 
     const int n = traits::vector_size( x ) ;
     const int stride_x = traits::vector_stride( x ) ;
@@ -159,7 +165,13 @@
 #endif
     assert( traits::vector_size( x ) == traits::vector_size( y ) ) ;
 
-    typedef typename vector_type_x::value_type value_type ;
+    typedef
+#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
+    typename traits::vector_traits< vector_type_x >::value_type
+#else
+    typename vector_type_x::value_type
+#endif
+    value_type ;
 
     const int n = traits::vector_size( x ) ;
     const int stride_x = traits::vector_stride( x ) ;

Thanks for making this available, I’ve been using it for some time, appreciate it. Just wanted to point out that the Makefile included in your latest download does not install the .h header files (e.g. boost/numeric/bindings/lapack/lapack.h), only the .hpp files. So it’s still necessary to copy the files over manually to install.

Cheers.

www.indii.org

Fixed a while ago—thanks for reporthing this.

hi, thanks to the person who put these bindings together. you say that this will not work with boost_1_34 and older. i google searched for boost 1.35 and did not find it. could someone pls help?

ps: here’s the problem i have:

installed atlas version 3.6.0-20.6. /usr/lib/atlas3-test runs just fine. header cblas.h and clapack.h are in /usr/include/ which is by default in my include path. i therefore changed and to and in cblas_inc.hpp and clapack_inc.hpp, respectively.

Configuration:
-I/usr/local/include/boost_1_34_1
-I/usr/local/include/boost-bindings
-L/usr/lib/atlas
-llapack
-lblas

i’m trying to run the program:

 #include <boost/numeric/bindings/atlas/clapack.hpp>
 #include <boost/numeric/bindings/traits/ublas_matrix.hpp>
 #include <boost/numeric/bindings/traits/std_vector.hpp>
// #include <atlas/cblas.h>

 namespace ublas = boost::numeric::ublas;
 namespace atlas = boost::numeric::bindings::atlas;

 int main() {
      std::size_t n = 5;
      ublas::matrix<double> a(n, n);
      // fill matrix a

      std::vector<int> ipiv (n);   // pivot vector
      atlas::lu_factor (a, ipiv);  // alias for getrf()
      atlas::lu_invert (a, ipiv);  // alias for getri()

      return 0;
 };

i get the error

Building target: testing_numeric_bindings
Invoking: GCC C++ Linker
g++ -L/usr/lib/atlas -o"testing_numeric_bindings"  ./main.o   -llapack
-lblas
./main.o: In function
`boost::numeric::bindings::atlas::detail::getrf(CBLAS_ORDER, int, int,
double*, int, int*)':
/usr/local/include/boost-bindings/boost/numeric/bindings/atlas/clapack_overloads.hpp:87:
undefined reference to `clapack_dgetrf'
./main.o: In function
`boost::numeric::bindings::atlas::detail::getri(CBLAS_ORDER, int, double*, int, int const*)':
/usr/local/include/boost-bindings/boost/numeric/bindings/atlas/clapack_overloads.hpp:163:
undefined reference to `clapack_dgetri'
collect2: ld returned 1 exit status
make: *** [testing_numeric_bindings] Error 1
make: Target `all' not remade because of errors.
Build complete for project testing_numeric_bindings

edited for formatting —Andreas

CLAPACK is different from regular LAPACK. If you want it, you need a CLAPACK implementation, regular -llapack will not do the trick.

I’d advise you to stick with regular (Fortran) lapack, though.

Hello there,

I am planning to use that binding libraries for uBLAS for a project of mine. I am setting up an automatic configuration, and I find it easier to get the files from the CVS for I can then easily request specific versions or dates and stay on the top of it. So I would like to know the status of the boost sandbox cvs compared to the archive linked from your blog? Are they going to be kept in synch? If not, have you already incorporated changes in that archive compared to the code on the CVS? If I may voice my opinion, it seems to me it would be better to keep the CVS up-to-date…

That binding looks really mature indeed and I am looking forward to be using it. How would I cite your and your fellow collaborators work by the by? My project is an academic project, you see…

Thank you very much,

Best wishes,

Luc

These bindings are strictly CVS snapshots, there is no “magical sauce” added. I intend to keep them in sync if major things happen in the bindings. My main purpose in pushing out these snapshots is to facilitate the use of PyLinear.

The main work on this was definitely done by Kresimir Fresl, but you should be able to extract all credits by looking at each file’s copyright notice.

Best, Andreas

This is not 100% true any more, see page text.

Post new comment

  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>.
  • You can use Markdown syntax to format and style the text. Also see and Markdown Extra for tables, footnotes, and more.

More information about formatting options