Boost logo

Ublas :

From: Thomas Klimpel (Thomas.Klimpel_at_[hidden])
Date: 2008-03-31 12:54:27


> one1 and one2 have been removed from the bindings for ublas::matrix
> a while ago. The change was not done for banded_matrix
> (I actually forgot).
>
> The functions stride1 and stride2 are used instead.

This indeed makes the code more straightforward. So my "improved" patch
is a bit longer, but the code itself is easier to understand.

> Indeed, row_major is the orientation you should use when you use ublas
> banded_matrix in lapack or blas, otherwise the format is not correct.
> I do not recall the precise details, but the ublas banded format is
not
> exactly the same as for blas and lapack.

The banded format of lapack is clear to me, but I can't imagine how a
banded format could be more "column major" than this format. Maybe I
will try to understand the ublas banded format later, but I think my
patch OK even if I don't understand the ublas banded format.

Regards,
Thomas

Index: bindings/traits/ublas_banded.hpp
===================================================================
--- bindings/traits/ublas_banded.hpp (Revision 43794)
+++ bindings/traits/ublas_banded.hpp (Arbeitskopie)
@@ -76,20 +76,24 @@
     static int leading_dimension (matrix_type& m) {
       // g++ 2.95.4 and 3.0.4 (with -pedantic) dislike
       // identifier_type::functor_type::size2()
- return lower_bandwidth(m) + upper_bandwidth(m) + 1 ;
+ //return lower_bandwidth(m) + upper_bandwidth(m) + 1 ;
+ typedef typename identifier_type::orientation_category
orientation_category;
+ return
detail::ublas_banded_ordering<orientation_category>::leading_dimension(m
) ;
     }
 
     // stride1 == distance (m (i, j), m (i+1, j))
     static int stride1 (matrix_type& m) {
       typedef typename identifier_type::orientation_category
orientation_category;
- typedef typename
detail::ublas_ordering<orientation_category>::functor_type functor_t ;
- return functor_t::one2 ( std::max(m.size1(), m.size2()),
leading_dimension(m)-1 ) ;
+ //typedef typename
detail::ublas_ordering<orientation_category>::functor_type functor_t ;
+ //return functor_t::one2 ( std::max(m.size1(), m.size2()),
leading_dimension(m)-1 ) ;
+ return
detail::ublas_banded_ordering<orientation_category>::stride1(m) ;
     }
     // stride2 == distance (m (i, j), m (i, j+1))
     static int stride2 (matrix_type& m) {
       typedef typename identifier_type::orientation_category
orientation_category;
- typedef typename
detail::ublas_ordering<orientation_category>::functor_type functor_t ;
- return functor_t::one1 ( std::max(m.size1(), m.size2()),
leading_dimension(m)-1 ) ;
+ //typedef typename
detail::ublas_ordering<orientation_category>::functor_type functor_t ;
+ //return functor_t::one1 ( std::max(m.size1(), m.size2()),
leading_dimension(m)-1 ) ;
+ return
detail::ublas_banded_ordering<orientation_category>::stride2(m) ;
     }
   };
 
Index: bindings/traits/detail/ublas_ordering.hpp
===================================================================
--- bindings/traits/detail/ublas_ordering.hpp (Revision 43794)
+++ bindings/traits/detail/ublas_ordering.hpp (Arbeitskopie)
@@ -68,6 +68,46 @@
       }
     };
 
+ template <typename StOrdTag>
+ struct ublas_banded_ordering {};
+
+ template<>
+ struct ublas_banded_ordering<boost::numeric::ublas::row_major_tag>
{
+
+ template <typename M>
+ static int leading_dimension( M const& m ) {
+ return m.lower() + m.upper() + 1 ;
+ }
+
+ template <typename M>
+ static int stride1( M const& m ) {
+ return 1 ;
+ }
+
+ template <typename M>
+ static int stride2( M const& m ) {
+ return leading_dimension(m)-1 ;
+ }
+ };
+
+ template<>
+ struct
ublas_banded_ordering<boost::numeric::ublas::column_major_tag> {
+
+ template <typename M>
+ static int leading_dimension( M const& m ) {
+ return m.lower() + m.upper() + 1 ;
+ }
+
+ template <typename M>
+ static int stride1( M const& m ) {
+ return std::max(m.size1(), m.size2()) ;
+ }
+
+ template <typename M>
+ static int stride2( M const& m ) {
+ return 1 ;
+ }
+ };
   }
 
 }}}}