Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r62013 - in sandbox/numeric_bindings: boost/numeric/bindings/glas boost/numeric/bindings/mtl libs/numeric/bindings/umfpack/test
From: thomas.klimpel_at_[hidden]
Date: 2010-05-15 19:49:49


Author: klimpel
Date: 2010-05-15 19:49:48 EDT (Sat, 15 May 2010)
New Revision: 62013
URL: http://svn.boost.org/trac/boost/changeset/62013

Log:
added compressed sparse matrix bindings for glas and mtl,
and adjusted one of the tests to be able to test ublas/glas/mtl compressed sparse matrix bindings.
Compressed sparse matrix bindings for eigen will follow soon (at least that's the plan).
Added:
   sandbox/numeric_bindings/boost/numeric/bindings/glas/compressed.hpp (contents, props changed)
   sandbox/numeric_bindings/boost/numeric/bindings/mtl/compressed2D.hpp (contents, props changed)
Text files modified:
   sandbox/numeric_bindings/libs/numeric/bindings/umfpack/test/Jamfile.v2 | 1
   sandbox/numeric_bindings/libs/numeric/bindings/umfpack/test/umfpack_simple.cc | 68 +++++++++++++++++++++++++++++----------
   2 files changed, 51 insertions(+), 18 deletions(-)

Added: sandbox/numeric_bindings/boost/numeric/bindings/glas/compressed.hpp
==============================================================================
--- (empty file)
+++ sandbox/numeric_bindings/boost/numeric/bindings/glas/compressed.hpp 2010-05-15 19:49:48 EDT (Sat, 15 May 2010)
@@ -0,0 +1,85 @@
+//
+// Copyright (c) 2009--2010
+// Thomas Klimpel and Rutger ter Borg
+//
+// Distributed under 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)
+//
+
+#ifndef BOOST_NUMERIC_BINDINGS_GLAS_COMPRESSED_HPP
+#define BOOST_NUMERIC_BINDINGS_GLAS_COMPRESSED_HPP
+
+#include <boost/numeric/bindings/begin.hpp>
+#include <boost/numeric/bindings/end.hpp>
+#include <boost/numeric/bindings/detail/adaptor.hpp>
+#include <boost/numeric/bindings/detail/copy_const.hpp>
+#include <boost/numeric/bindings/glas/detail/convert_to.hpp>
+#include <boost/numeric/bindings/glas/dense_vector.hpp>
+#include <boost/numeric/bindings/std/vector.hpp>
+#include <glas/sparse/compressed.hpp>
+
+namespace boost {
+namespace numeric {
+namespace bindings {
+namespace detail {
+
+template< typename T, typename O, typename IndexType, typename NNZType, int IB, typename Id, typename Enable >
+struct adaptor< glas::sparse_matrix< T, glas::compressed_sparse_structure<O, IndexType, NNZType, IB> >, Id, Enable > {
+
+ typedef typename copy_const< Id, T >::type value_type;
+ typedef typename copy_const< Id, IndexType >::type index_type;
+ typedef typename convert_to< tag::data_order, O >::type data_order;
+ typedef mpl::map<
+ mpl::pair< tag::value_type, value_type >,
+ mpl::pair< tag::index_type, index_type >,
+ mpl::pair< tag::entity, tag::matrix >,
+ mpl::pair< tag::size_type<1>, std::ptrdiff_t >,
+ mpl::pair< tag::size_type<2>, std::ptrdiff_t >,
+ mpl::pair< tag::matrix_type, tag::general >,
+ mpl::pair< tag::data_structure, tag::compressed_sparse >,
+ mpl::pair< tag::data_order, data_order >
+ > property_map;
+
+ BOOST_STATIC_CONSTANT (std::size_t, index_base = IB);
+
+ static std::ptrdiff_t size1( const Id& id ) {
+ return id.num_rows();
+ }
+
+ static std::ptrdiff_t size2( const Id& id ) {
+ return id.num_columns();
+ }
+
+ static value_type* begin_value( Id& id ) {
+ return bindings::begin_value( id.value_array() );
+ }
+
+ static value_type* end_value( Id& id ) {
+ return bindings::begin_value( id.value_array() ) + id.nnz();
+ }
+
+ static index_type* begin_compressed_index_major( Id& id ) {
+ return bindings::begin_value( id.sparse_structure().compressed_index_array() );
+ }
+
+ static index_type* end_compressed_index_major( Id& id ) {
+ return bindings::end_value( id.sparse_structure().compressed_index_array() );
+ }
+
+ static index_type* begin_index_minor( Id& id ) {
+ return bindings::begin_value( id.sparse_structure().index_array() );
+ }
+
+ static index_type* end_index_minor( Id& id ) {
+ return bindings::begin_value( id.sparse_structure().index_array() ) + id.nnz();
+ }
+
+};
+
+} // namespace detail
+} // namespace bindings
+} // namespace numeric
+} // namespace boost
+
+#endif

Added: sandbox/numeric_bindings/boost/numeric/bindings/mtl/compressed2D.hpp
==============================================================================
--- (empty file)
+++ sandbox/numeric_bindings/boost/numeric/bindings/mtl/compressed2D.hpp 2010-05-15 19:49:48 EDT (Sat, 15 May 2010)
@@ -0,0 +1,89 @@
+//
+// Copyright (c) 2009--2010
+// Thomas Klimpel and Rutger ter Borg
+//
+// Distributed under 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)
+//
+
+#ifndef BOOST_NUMERIC_BINDINGS_MTL_COMPRESSED2D_HPP
+#define BOOST_NUMERIC_BINDINGS_MTL_COMPRESSED2D_HPP
+
+#include <boost/numeric/bindings/detail/adaptor.hpp>
+#include <boost/numeric/bindings/detail/copy_const.hpp>
+#include <boost/numeric/bindings/mtl/detail/convert_to.hpp>
+#include <boost/numeric/mtl/matrix/compressed2D.hpp>
+
+namespace boost {
+namespace numeric {
+namespace bindings {
+namespace detail {
+
+template< typename T, typename Parameters, typename Id, typename Enable >
+struct adaptor< mtl::compressed2D< T, Parameters >, Id, Enable > {
+
+ typedef typename copy_const< Id, T >::type value_type;
+ typedef typename copy_const<
+ Id,
+ //typename Id::index_type
+ //typename Id::size_type // (Seems to be the actually used index_type)
+ std::ptrdiff_t // (Seems to be an actual usable type for bindings purposes)
+ >::type index_type;
+ typedef typename convert_to<
+ tag::data_order,
+ typename Parameters::orientation
+ >::type data_order;
+ typedef mpl::map<
+ mpl::pair< tag::value_type, value_type >,
+ mpl::pair< tag::index_type, index_type >,
+ mpl::pair< tag::entity, tag::matrix >,
+ mpl::pair< tag::size_type<1>, std::ptrdiff_t >,
+ mpl::pair< tag::size_type<2>, std::ptrdiff_t >,
+ mpl::pair< tag::matrix_type, tag::general >,
+ mpl::pair< tag::data_structure, tag::compressed_sparse >,
+ mpl::pair< tag::data_order, data_order >
+ > property_map;
+
+ BOOST_STATIC_CONSTANT (std::size_t, index_base = 0);
+
+ static std::ptrdiff_t size1( const Id& id ) {
+ return id.num_rows();
+ }
+
+ static std::ptrdiff_t size2( const Id& id ) {
+ return id.num_cols();
+ }
+
+ static value_type* begin_value( Id& id ) {
+ return id.address_data();
+ }
+
+ static value_type* end_value( Id& id ) {
+ return id.address_data() + id.nnz();
+ }
+
+ static index_type* begin_compressed_index_major( Id& id ) {
+ return reinterpret_cast<index_type*>(id.address_major());
+ }
+
+ static index_type* end_compressed_index_major( Id& id ) {
+ return reinterpret_cast<index_type*>(id.address_major() + id.dim1() + 1);
+ }
+
+ static index_type* begin_index_minor( Id& id ) {
+ return reinterpret_cast<index_type*>(id.address_minor());
+ }
+
+ static index_type* end_index_minor( Id& id ) {
+ return reinterpret_cast<index_type*>(id.address_minor() + id.nnz());
+ }
+
+};
+
+} // namespace detail
+} // namespace bindings
+} // namespace numeric
+} // namespace boost
+
+#endif

Modified: sandbox/numeric_bindings/libs/numeric/bindings/umfpack/test/Jamfile.v2
==============================================================================
--- sandbox/numeric_bindings/libs/numeric/bindings/umfpack/test/Jamfile.v2 (original)
+++ sandbox/numeric_bindings/libs/numeric/bindings/umfpack/test/Jamfile.v2 2010-05-15 19:49:48 EDT (Sat, 15 May 2010)
@@ -6,6 +6,7 @@
 project libs/numeric/bindings/umfpack/test : requirements
         <include>$(BOOST_ROOT)
         <include>$(BOOST)
+ <library>/numeric-bindings//test_matlib
         <library>/numeric-bindings//umfpack_lib ;
 
 import testing ;

Modified: sandbox/numeric_bindings/libs/numeric/bindings/umfpack/test/umfpack_simple.cc
==============================================================================
--- sandbox/numeric_bindings/libs/numeric/bindings/umfpack/test/umfpack_simple.cc (original)
+++ sandbox/numeric_bindings/libs/numeric/bindings/umfpack/test/umfpack_simple.cc 2010-05-15 19:49:48 EDT (Sat, 15 May 2010)
@@ -39,45 +39,77 @@
  *
  */
 
-/* Used by permission. */
+/* Used by permission. */
 
 
-/* Simple demo program for UMFPACK */
+/* Simple demo program for UMFPACK */
 /* from UMFPACK Version 4.1 Quick Start Guide */
 
 /* modified by Kresimir Fresl, 2003 */
 /* UMFPACK bindings & ublas::compressed_matrix<> */
 
 
+#if !defined(TEST_MATLIB_UBLAS) && !defined(TEST_MATLIB_GLAS) && !defined(TEST_MATLIB_MTL) && !defined(TEST_MATLIB_EIGEN)
+#define TEST_MATLIB_UBLAS
+#endif
+
 #include <iostream>
-#include <boost/numeric/bindings/ublas/vector.hpp>
-#include <boost/numeric/bindings/ublas/matrix_sparse.hpp>
 #include <boost/numeric/bindings/umfpack/umfpack.hpp>
+#include <boost/numeric/bindings/ublas/vector.hpp>
 #include <boost/numeric/ublas/io.hpp>
 
+#if defined(TEST_MATLIB_UBLAS)
+
+#include <boost/numeric/bindings/ublas/matrix_sparse.hpp>
 namespace ublas = boost::numeric::ublas;
+typedef ublas::compressed_matrix<double, ublas::column_major, 0,
+ ublas::unbounded_array<int>, ublas::unbounded_array<double> > m_t;
+typedef m_t& mi_t;
+#define AA(i,j, val) a(i,j) = val
+
+#elif defined(TEST_MATLIB_GLAS)
+
+#include <boost/numeric/bindings/glas/compressed.hpp>
+typedef glas::sparse_matrix< double, glas::compressed_sparse_structure<
+ glas::column_orientation, std::ptrdiff_t, std::ptrdiff_t, 0> > m_t;
+typedef m_t& mi_t;
+#define AA(i,j, val) insert(a,i,j, val)
+
+#elif defined(TEST_MATLIB_MTL)
+
+#include <boost/numeric/bindings/mtl/compressed2D.hpp>
+typedef mtl::compressed2D<double, mtl::matrix::parameters<mtl::tag::col_major> > m_t;
+typedef mtl::matrix::inserter<m_t> mi_t;
+#define AA(i,j, val) a(i,j) = val
+
+#elif defined(TEST_MATLIB_EIGEN)
+
+#endif
+
+typedef boost::numeric::ublas::vector<double> v_t;
 namespace umf = boost::numeric::bindings::umfpack;
 
 int main() {
 
- ublas::compressed_matrix<double, ublas::column_major, 0,
- ublas::unbounded_array<int>, ublas::unbounded_array<double> > A (5,5,12);
- ublas::vector<double> B (5), X (5);
-
- A(0,0) = 2.; A(0,1) = 3;
- A(1,0) = 3.; A(1,2) = 4.; A(1,4) = 6;
- A(2,1) = -1.; A(2,2) = -3.; A(2,3) = 2.;
- A(3,2) = 1.;
- A(4,1) = 4.; A(4,2) = 2.; A(4,4) = 1.;
+ m_t A (5,5,12);
+ v_t B (5), X (5);
 
- B(0) = 8.; B(1) = 45.; B(2) = -3.; B(3) = 3.; B(4) = 19.;
+ {
+ mi_t a(A);
+ AA(0,0, 2.); AA(0,1, 3.);
+ AA(1,0, 3.); AA(1,2, 4.); AA(1,4, 6.);
+ AA(2,1,-1.); AA(2,2,-3.); AA(2,3, 2.);
+ AA(3,2, 1.);
+ AA(4,1, 4.); AA(4,2, 2.); AA(4,4, 1.);
+ }
+ B(0) = 8.; B(1) = 45.; B(2) = -3.; B(3) = 3.; B(4) = 19.;
 
   umf::symbolic_type<double> Symbolic;
   umf::numeric_type<double> Numeric;
 
- umf::symbolic (A, Symbolic);
- umf::numeric (A, Symbolic, Numeric);
- umf::solve (A, X, B, Numeric);
+ umf::symbolic (A, Symbolic);
+ umf::numeric (A, Symbolic, Numeric);
+ umf::solve (A, X, B, Numeric);
 
   std::cout << X << std::endl; // output: [5](1,2,3,4,5)
-}
+}


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk