$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r61973 - in sandbox/numeric_bindings/libs/numeric/bindings: . lapack/test
From: thomas.klimpel_at_[hidden]
Date: 2010-05-14 19:35:17
Author: klimpel
Date: 2010-05-14 19:35:16 EDT (Fri, 14 May 2010)
New Revision: 61973
URL: http://svn.boost.org/trac/boost/changeset/61973
Log:
use bjam ... matlib=ublas/glas/mtl/eigen to test the bindings for the corresponding matrix library (well, at least the ublas_gesv2 regression test...)
Text files modified: 
   sandbox/numeric_bindings/libs/numeric/bindings/lapack/test/Jamfile.v2     |     1                                         
   sandbox/numeric_bindings/libs/numeric/bindings/lapack/test/ublas_gesv2.cc |    50 +++++++++++++++++++++++++++++++++++---- 
   sandbox/numeric_bindings/libs/numeric/bindings/lapack/test/utils.h        |    29 +++++++++++++++--------                 
   sandbox/numeric_bindings/libs/numeric/bindings/numeric-bindings.jam       |    22 +++++++++++++++++                       
   4 files changed, 86 insertions(+), 16 deletions(-)
Modified: sandbox/numeric_bindings/libs/numeric/bindings/lapack/test/Jamfile.v2
==============================================================================
--- sandbox/numeric_bindings/libs/numeric/bindings/lapack/test/Jamfile.v2	(original)
+++ sandbox/numeric_bindings/libs/numeric/bindings/lapack/test/Jamfile.v2	2010-05-14 19:35:16 EDT (Fri, 14 May 2010)
@@ -6,6 +6,7 @@
 project libs/numeric/bindings/lapack/test : requirements
         <include>$(BOOST_ROOT)
         <include>$(B_ROOT)
+        <library>/numeric-bindings//test_matlib
         <library>/numeric-bindings//lapack_lib ;
 
 import testing ;
Modified: sandbox/numeric_bindings/libs/numeric/bindings/lapack/test/ublas_gesv2.cc
==============================================================================
--- sandbox/numeric_bindings/libs/numeric/bindings/lapack/test/ublas_gesv2.cc	(original)
+++ sandbox/numeric_bindings/libs/numeric/bindings/lapack/test/ublas_gesv2.cc	2010-05-14 19:35:16 EDT (Fri, 14 May 2010)
@@ -1,3 +1,6 @@
+#if !defined(TEST_MATLIB_UBLAS) && !defined(TEST_MATLIB_GLAS) && !defined(TEST_MATLIB_MTL) && !defined(TEST_MATLIB_EIGEN)
+#define TEST_MATLIB_UBLAS
+#endif
 
 // solving A * X = B
 // using driver function gesv()
@@ -6,28 +9,51 @@
 #include <iostream>
 #include <vector>
 #include <boost/numeric/bindings/lapack/driver/gesv.hpp>
-#include <boost/numeric/bindings/ublas/matrix.hpp>
 #include <boost/numeric/bindings/std/vector.hpp>
+#if defined(TEST_MATLIB_UBLAS)
+#include <boost/numeric/bindings/ublas/matrix.hpp>
 #include <boost/numeric/ublas/matrix_proxy.hpp>
+#elif defined(TEST_MATLIB_GLAS)
+#include <boost/numeric/bindings/glas/dense_matrix.hpp>
+#include <glas/toolbox/la/algorithm/operators.hpp>
+#elif defined(TEST_MATLIB_MTL)
+#include <boost/numeric/bindings/mtl/dense2D.hpp>
+#include <boost/numeric/mtl/operation/operators.hpp>
+#elif defined(TEST_MATLIB_EIGEN)
+#include <boost/numeric/bindings/eigen/matrix.hpp>
+#endif
 #include "utils.h"
 
-namespace ublas = boost::numeric::ublas;
 namespace lapack = boost::numeric::bindings::lapack;
+namespace bindings = boost::numeric::bindings;
+#if defined(TEST_MATLIB_UBLAS)
+namespace ublas = boost::numeric::ublas;
+typedef ublas::matrix<double, ublas::column_major> m_t;
+typedef std::size_t size_type;
+#elif defined(TEST_MATLIB_GLAS)
+using namespace glas::la;
+typedef glas::dense_matrix<double, glas::column_orientation> m_t;
+typedef std::ptrdiff_t size_type;
+#elif defined(TEST_MATLIB_MTL)
+typedef mtl::dense2D<double, mtl::matrix::parameters<mtl::tag::col_major> > m_t;
+typedef std::ptrdiff_t size_type;
+#elif defined(TEST_MATLIB_EIGEN)
+typedef Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> m_t;
+typedef int size_type;
+#endif
 
-using std::size_t; 
 using std::cout;
 using std::endl; 
 
-typedef ublas::matrix<double, ublas::column_major> m_t;
 
 int main() {
 
   cout << endl; 
 
-  size_t n = 5;   
+  size_type n = 5;   
   m_t a (n, n);   // system matrix 
 
-  size_t nrhs = 2; 
+  size_type nrhs = 2; 
   m_t x (n, nrhs), b (n, nrhs);  // b -- right-hand side matrix
 
   init_symm (a); 
@@ -39,12 +65,20 @@
 
   m_t aa (a); // copy of a, because a is `lost' after gesv()
 
+#if defined(TEST_MATLIB_UBLAS)
   ublas::matrix_column<m_t> xc0 (x, 0), xc1 (x, 1); 
   for (int i = 0; i < xc0.size(); ++i) {
     xc0 (i) = 1.;
     xc1 (i) = 2.; 
   }
   b = prod (a, x); 
+#elif defined(TEST_MATLIB_GLAS) || defined(TEST_MATLIB_MTL) || defined(TEST_MATLIB_EIGEN)
+  for (int i = 0; i < bindings::size_row (x); ++i) {
+    x (i,0) = 1.;
+    x (i,1) = 2.; 
+  }
+  b = a * x;
+#endif
 
   print_m (a, "A"); 
   cout << endl; 
@@ -59,7 +93,11 @@
   print_m (b, "X");
   cout << endl; 
 
+#if defined(TEST_MATLIB_UBLAS)
   x = prod (aa, b); 
+#elif defined(TEST_MATLIB_GLAS) || defined(TEST_MATLIB_MTL) || defined(TEST_MATLIB_EIGEN)
+  x = aa * b;
+#endif
   print_m (x, "B = A X"); 
 
   cout << endl; 
Modified: sandbox/numeric_bindings/libs/numeric/bindings/lapack/test/utils.h
==============================================================================
--- sandbox/numeric_bindings/libs/numeric/bindings/lapack/test/utils.h	(original)
+++ sandbox/numeric_bindings/libs/numeric/bindings/lapack/test/utils.h	2010-05-14 19:35:16 EDT (Fri, 14 May 2010)
@@ -97,24 +97,33 @@
 
 
 /////////////////////////////////////
-// matrices 
+// matrices
 
-// element access: 
+// element access:
 template <typename M>
 struct matr_access_traits {
-  typedef typename 
-  M::reference ref_t;
-  //boost::numeric::bindings::traits::matrix_traits<M>::value_type val_t;
-  //typedef val_t& ref_t; 
-  static ref_t elem (M& m, size_t i, size_t j) { return m (i, j); }
+  typedef M mat_t;
+  typedef typename boost::numeric::bindings::value_type<mat_t>::type val_t;
+  typedef typename mat_t::reference ref_t;
+  static ref_t elem (mat_t& m, size_t i, size_t j) { return m (i, j); }
 };
 
+#ifdef EIGEN_FORWARDDECLARATIONS_H
+template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
+struct matr_access_traits<Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> > {
+  typedef Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> mat_t;
+  typedef typename boost::numeric::bindings::value_type<mat_t>::type val_t;
+  typedef val_t& ref_t;
+  static ref_t elem (mat_t& m, size_t i, size_t j) { return m (i, j); }
+};
+#endif
+
 template <typename M>
 struct matr_access_traits<M const> {
-  typedef typename 
-  boost::numeric::bindings::value_type<M>::type val_t;
+  typedef M const mat_t;
+  typedef typename boost::numeric::bindings::value_type<mat_t>::type val_t;
   typedef val_t ref_t; 
-  static ref_t elem (M const& m, size_t i, size_t j) { return m (i, j); }
+  static ref_t elem (mat_t& m, size_t i, size_t j) { return m (i, j); }
 };
 
 template <typename M>
Modified: sandbox/numeric_bindings/libs/numeric/bindings/numeric-bindings.jam
==============================================================================
--- sandbox/numeric_bindings/libs/numeric/bindings/numeric-bindings.jam	(original)
+++ sandbox/numeric_bindings/libs/numeric/bindings/numeric-bindings.jam	2010-05-14 19:35:16 EDT (Fri, 14 May 2010)
@@ -12,11 +12,19 @@
           mkl-gcc      mkl-msvc
         : optional propagated ;
 
+feature matlib
+        : ublas glas mtl eigen
+        : optional propagated ;
+
 # Make this module a project
 import project ;
 project.initialize $(__name__) ;
 project numeric-bindings ;
 
+GLAS_INCLUDE ?= /usr/local/lib ;
+MTL_INCLUDE ?= /usr/local/lib ;
+EIGEN_INCLUDE ?= /usr/local/lib ;
+
 NUMERIC_LIB_PATH ?= /usr/lib ;
 NUMERIC_INCLUDE ?= /usr/local/lib ;
 SUITESPARSE_INCLUDE ?= $(NUMERIC_INCLUDE)/SuiteSparse ;
@@ -58,6 +66,20 @@
 AMD_PATH ?= $(NUMERIC_LIB_PATH) ;
 AMD_LIB ?= amd ;
 
+alias test_matlib : :
+                  : : <define>TEST_MATLIB_UBLAS ;
+alias test_matlib : : <matlib>ublas
+                  : : <define>TEST_MATLIB_UBLAS ;
+alias test_matlib : : <matlib>glas
+                  : : <define>TEST_MATLIB_GLAS
+                      <include>$(GLAS_INCLUDE) ;
+alias test_matlib : : <matlib>mtl
+                  : : <define>TEST_MATLIB_MTL
+                      <include>$(MTL_INCLUDE) ;
+alias test_matlib : : <matlib>eigen
+                  : : <define>TEST_MATLIB_EIGEN
+                      <include>$(EIGEN_INCLUDE) ;
+
 lib acml_lib : : <name>$(ACML_LIB) <search>$(ACML_PATH)
              : : <define>BIND_FORTRAN_NO_F2C_RETURN_CONVENTIONS ;
 #lib msvc_acml_fortran_lib : : <name>$(ACML_FORTRAN_DLL) <search>$(ACML_DLL_PATH) <toolset>msvc:<link>shared