Boost logo

Boost-Commit :

From: thomas.klimpel_at_[hidden]
Date: 2008-05-22 09:03:39


Author: klimpel
Date: 2008-05-22 09:03:38 EDT (Thu, 22 May 2008)
New Revision: 45650
URL: http://svn.boost.org/trac/boost/changeset/45650

Log:
reduced code duplication, by moving fill/fill_banded and check_residual to a separate file

Added:
   sandbox/libs/numeric/bindings/lapack/test/ublas_heev.hpp (contents, props changed)
Text files modified:
   sandbox/libs/numeric/bindings/lapack/test/ublas_hbev.cpp | 46 ++-------------------------------------
   sandbox/libs/numeric/bindings/lapack/test/ublas_hbevx.cpp | 45 ++------------------------------------
   sandbox/libs/numeric/bindings/lapack/test/ublas_heev.cpp | 45 --------------------------------------
   sandbox/libs/numeric/bindings/lapack/test/ublas_heevd.cpp | 46 ---------------------------------------
   sandbox/libs/numeric/bindings/lapack/test/ublas_heevx.cpp | 46 ---------------------------------------
   sandbox/libs/numeric/bindings/lapack/test/ublas_syev.cpp | 45 --------------------------------------
   6 files changed, 10 insertions(+), 263 deletions(-)

Modified: sandbox/libs/numeric/bindings/lapack/test/ublas_hbev.cpp
==============================================================================
--- sandbox/libs/numeric/bindings/lapack/test/ublas_hbev.cpp (original)
+++ sandbox/libs/numeric/bindings/lapack/test/ublas_hbev.cpp 2008-05-22 09:03:38 EDT (Thu, 22 May 2008)
@@ -6,7 +6,7 @@
 // http://www.boost.org/LICENSE_1_0.txt)
 //
 
-#include "../../blas/test/random.hpp"
+#include "ublas_heev.hpp"
 
 #include <boost/numeric/bindings/lapack/hbev.hpp>
 #include <boost/numeric/ublas/matrix_proxy.hpp>
@@ -19,31 +19,12 @@
 #include <boost/numeric/ublas/io.hpp>
 
 #include <iostream>
-#include <limits>
 
 
 namespace ublas = boost::numeric::ublas;
 namespace lapack = boost::numeric::bindings::lapack;
 
 
-// Fill a matrix
-template <typename M>
-void fill(M& m) {
- typedef typename M::size_type size_type ;
- typedef typename M::value_type value_type ;
-
- typedef typename boost::numeric::bindings::traits::type_traits<value_type>::real_type real_type ;
-
- int size = m.size2() ;
- int band = m.upper() ;
-
- for (int i=0; i<size; ++i) {
- for (int j=std::max(0,i-band); j<i; ++j) m(j,i) = random_value<value_type>();
- m(i,i) = random_value<real_type>();
- }
-} // randomize()
-
-
 template <typename U>
 int lower() {
    return 0;
@@ -61,27 +42,6 @@
 template <>
 int upper<ublas::upper>() { return 2; }
 
-template <typename H, typename E, typename Z>
-int check_residual(H const& h, E const& e, Z const& z) {
- typedef typename H::value_type value_type ;
- typedef typename E::value_type real_type ;
- real_type safety_factor(1.5);
-
- // Check eigen decomposition
- int n = h.size1();
- ublas::matrix<value_type> error( n, n ); error.clear();
-
- // Copy band matrix in error
- error.assign( h );
- assert( norm_frobenius( error - herm( error ) ) == 0.0 ) ;
-
- for (int i=0; i<n; ++i) {
- error .minus_assign( outer_prod( column(z, i), e(i) * conj( column(z, i) ) ) ) ;
- }
- return (norm_frobenius( error )
- >= safety_factor*n* norm_2( e ) * std::numeric_limits< real_type >::epsilon() ) ;
-} // check_residual()
-
 
 template <typename T, typename W, typename UPLO, typename Orientation>
 int do_memory_uplo(int n, W& workspace ) {
@@ -97,7 +57,7 @@
    vector_type e1( n );
    vector_type e2( n );
 
- fill( a );
+ fill_banded( a );
    banded_type a2( a );
 
    ublas::hermitian_adaptor<banded_type, UPLO> h( a ), h2( a2 );
@@ -111,7 +71,7 @@
    if (norm_2( e1 - e2 ) > n * norm_2( e1 ) * std::numeric_limits< real_type >::epsilon()) return 255 ;
 
    // Test for a matrix range
- fill( a ); a2.assign( a );
+ fill_banded( a ); a2.assign( a );
 
    typedef ublas::matrix_range< banded_type > banded_range ;
 

Modified: sandbox/libs/numeric/bindings/lapack/test/ublas_hbevx.cpp
==============================================================================
--- sandbox/libs/numeric/bindings/lapack/test/ublas_hbevx.cpp (original)
+++ sandbox/libs/numeric/bindings/lapack/test/ublas_hbevx.cpp 2008-05-22 09:03:38 EDT (Thu, 22 May 2008)
@@ -7,7 +7,7 @@
 // http://www.boost.org/LICENSE_1_0.txt)
 //
 
-#include "../../blas/test/random.hpp"
+#include "ublas_heev.hpp"
 
 #include <boost/numeric/bindings/lapack/hbevx.hpp>
 #include <boost/numeric/ublas/matrix_proxy.hpp>
@@ -20,31 +20,12 @@
 #include <boost/numeric/ublas/io.hpp>
 
 #include <iostream>
-#include <limits>
 
 
 namespace ublas = boost::numeric::ublas;
 namespace lapack = boost::numeric::bindings::lapack;
 
 
-// Fill a matrix
-template <typename M>
-void fill(M& m) {
- typedef typename M::size_type size_type ;
- typedef typename M::value_type value_type ;
-
- typedef typename boost::numeric::bindings::traits::type_traits<value_type>::real_type real_type ;
-
- int size = m.size2() ;
- int band = m.upper() ;
-
- for (int i=0; i<size; ++i) {
- for (int j=std::max(0,i-band); j<i; ++j) m(j,i) = random_value<value_type>();
- m(i,i) = random_value<real_type>();
- }
-} // randomize()
-
-
 template <typename U>
 int lower() {
    return 0;
@@ -62,26 +43,6 @@
 template <>
 int upper<ublas::upper>() { return 2; }
 
-template <typename H, typename E, typename Z>
-int check_residual(H const& h, E const& e, Z const& z) {
- typedef typename H::value_type value_type ;
- typedef typename E::value_type real_type ;
-
- // Check eigen decomposition
- int n = h.size1();
- ublas::matrix<value_type> error( n, n ); error.clear();
-
- // Copy band matrix in error
- error.assign( h );
- assert( norm_frobenius( error - herm( error ) ) == 0.0 ) ;
-
- for (int i=0; i<n; ++i) {
- error .minus_assign( outer_prod( column(z, i), e(i) * conj( column(z, i) ) ) ) ;
- }
- return (norm_frobenius( error )
- >= n* norm_2( e ) * std::numeric_limits< real_type >::epsilon() ) ;
-} // check_residual()
-
 
 template <typename T, typename W, typename UPLO, typename Orientation>
 int do_memory_uplo(int n, W& workspace ) {
@@ -98,7 +59,7 @@
    vector_type e1( n );
    vector_type e2( n );
 
- fill( a );
+ fill_banded( a );
    banded_type a2( a );
 
    ublas::hermitian_adaptor<banded_type, UPLO> h( a ), h2( a2 );
@@ -116,7 +77,7 @@
    if (norm_2( e1 - e2 ) > n * norm_2( e1 ) * std::numeric_limits< real_type >::epsilon()) return 255 ;
 
    // Test for a matrix range
- fill( a ); a2.assign( a );
+ fill_banded( a ); a2.assign( a );
 
    typedef ublas::matrix_range< banded_type > banded_range ;
 

Modified: sandbox/libs/numeric/bindings/lapack/test/ublas_heev.cpp
==============================================================================
--- sandbox/libs/numeric/bindings/lapack/test/ublas_heev.cpp (original)
+++ sandbox/libs/numeric/bindings/lapack/test/ublas_heev.cpp 2008-05-22 09:03:38 EDT (Thu, 22 May 2008)
@@ -6,7 +6,7 @@
 // http://www.boost.org/LICENSE_1_0.txt)
 //
 
-#include "../../blas/test/random.hpp"
+#include "ublas_heev.hpp"
 
 #include <boost/numeric/bindings/lapack/heev.hpp>
 #include <boost/numeric/bindings/traits/ublas_matrix.hpp>
@@ -16,55 +16,12 @@
 #include <boost/numeric/ublas/io.hpp>
 
 #include <iostream>
-#include <limits>
 
 
 namespace ublas = boost::numeric::ublas;
 namespace lapack = boost::numeric::bindings::lapack;
 
 
-// Fill a matrix
-template <typename M>
-void fill(M& m) {
- typedef typename M::size_type size_type ;
- typedef typename M::value_type value_type ;
-
- typedef typename boost::numeric::bindings::traits::type_traits<value_type>::real_type real_type ;
-
- int size = m.size2() ;
-
- for (int i=0; i<size; ++i) {
- for (int j=0; j<i; ++j) {
- m(j,i) = random_value<value_type>();
- m(i,j) = conj( m(j,i ) ) ;
- }
- m(i,i) = random_value<real_type>();
- }
-} // randomize()
-
-
-template <typename H, typename E, typename Z>
-int check_residual(H const& h, E const& e, Z const& z) {
- typedef typename H::value_type value_type ;
- typedef typename E::value_type real_type ;
- real_type safety_factor(1.5);
-
- // Check eigen decomposition
- int n = h.size1();
- ublas::matrix<value_type> error( n, n ); error.clear();
-
- // Copy band matrix in error
- error.assign( h );
- assert( norm_frobenius( error - herm( error ) ) == 0.0 ) ;
-
- for (int i=0; i<n; ++i) {
- error .minus_assign( outer_prod( column(z, i), e(i) * conj( column(z, i) ) ) ) ;
- }
- return (norm_frobenius( error )
- >= safety_factor*n* norm_2( e ) * std::numeric_limits< real_type >::epsilon() ) ;
-} // check_residual()
-
-
 template <typename T, typename W, char UPLO>
 int do_memory_uplo(int n, W& workspace ) {
    typedef typename boost::numeric::bindings::traits::type_traits<T>::real_type real_type ;

Added: sandbox/libs/numeric/bindings/lapack/test/ublas_heev.hpp
==============================================================================
--- (empty file)
+++ sandbox/libs/numeric/bindings/lapack/test/ublas_heev.hpp 2008-05-22 09:03:38 EDT (Thu, 22 May 2008)
@@ -0,0 +1,79 @@
+//
+// Copyright Toon Knapen, Karl Meerbergen
+// Copyright Thomas Klimpel 2008
+//
+// 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_LAPACK_TEST_UBLAS_HEEV_HPP
+#define BOOST_NUMERIC_BINDINGS_LAPACK_TEST_UBLAS_HEEV_HPP
+
+#include "../../blas/test/random.hpp"
+
+#include <boost/numeric/bindings/traits/ublas_matrix.hpp>
+#include <boost/numeric/ublas/matrix_proxy.hpp>
+
+#include <limits>
+
+
+inline float conj(float v) { return v; }
+inline double conj(double v) { return v; }
+inline float real(float v) { return v; }
+inline double real(double v) { return v; }
+
+// Fill a banded matrix
+template <typename M>
+void fill_banded(M& m) {
+ typedef typename M::size_type size_type ;
+ typedef typename M::value_type value_type ;
+
+ int size = m.size2() ;
+ int band = m.upper() ;
+
+ for (int i=0; i<size; ++i) {
+ for (int j=std::max(0,i-band); j<i; ++j) m(j,i) = random_value<value_type>();
+ m(i,i) = real( random_value<value_type>() );
+ }
+} // randomize()
+
+// Fill a matrix
+template <typename M>
+void fill(M& m) {
+ typedef typename M::size_type size_type ;
+ typedef typename M::value_type value_type ;
+
+ int size = m.size2() ;
+
+ for (int i=0; i<size; ++i) {
+ for (int j=0; j<i; ++j) {
+ m(j,i) = random_value<value_type>();
+ m(i,j) = conj( m(j,i) ) ;
+ }
+ m(i,i) = real( random_value<value_type>() );
+ }
+} // randomize()
+
+template <typename H, typename E, typename Z>
+int check_residual(H const& h, E const& e, Z const& z) {
+ typedef typename H::value_type value_type ;
+ typedef typename E::value_type real_type ;
+ real_type safety_factor (1.5);
+
+ // Check eigen decomposition
+ int n = h.size1();
+ boost::numeric::ublas::matrix<value_type> error( n, n ); error.clear();
+
+ // Copy band matrix in error
+ error.assign( h );
+ assert( norm_frobenius( error - herm( error ) ) == 0.0 ) ;
+
+ for (int i=0; i<n; ++i) {
+ error .minus_assign( outer_prod( column(z, i), e(i) * conj( column(z, i) ) ) ) ;
+ }
+ return (norm_frobenius( error )
+ >= safety_factor*n* norm_2( e ) * std::numeric_limits< real_type >::epsilon() ) ;
+} // check_residual()
+
+#endif

Modified: sandbox/libs/numeric/bindings/lapack/test/ublas_heevd.cpp
==============================================================================
--- sandbox/libs/numeric/bindings/lapack/test/ublas_heevd.cpp (original)
+++ sandbox/libs/numeric/bindings/lapack/test/ublas_heevd.cpp 2008-05-22 09:03:38 EDT (Thu, 22 May 2008)
@@ -7,7 +7,7 @@
 // http://www.boost.org/LICENSE_1_0.txt)
 //
 
-#include "../../blas/test/random.hpp"
+#include "ublas_heev.hpp"
 
 #include <boost/numeric/bindings/lapack/heevd.hpp>
 #include <boost/numeric/bindings/traits/ublas_matrix.hpp>
@@ -17,55 +17,11 @@
 #include <boost/numeric/ublas/io.hpp>
 
 #include <iostream>
-#include <limits>
 
 
 namespace ublas = boost::numeric::ublas;
 namespace lapack = boost::numeric::bindings::lapack;
 
-inline float conj(float v) { return v; }
-inline double conj(double v) { return v; }
-
-// Fill a matrix
-template <typename M>
-void fill(M& m) {
- typedef typename M::size_type size_type ;
- typedef typename M::value_type value_type ;
-
- typedef typename boost::numeric::bindings::traits::type_traits<value_type>::real_type real_type ;
-
- int size = m.size2() ;
-
- for (int i=0; i<size; ++i) {
- for (int j=0; j<i; ++j) {
- m(j,i) = random_value<value_type>();
- m(i,j) = conj( m(j,i) ) ;
- }
- m(i,i) = random_value<real_type>();
- }
-} // randomize()
-
-
-template <typename H, typename E, typename Z>
-int check_residual(H const& h, E const& e, Z const& z) {
- typedef typename H::value_type value_type ;
- typedef typename E::value_type real_type ;
-
- // Check eigen decomposition
- int n = h.size1();
- ublas::matrix<value_type> error( n, n ); error.clear();
-
- // Copy band matrix in error
- error.assign( h );
- assert( norm_frobenius( error - herm( error ) ) == 0.0 ) ;
-
- for (int i=0; i<n; ++i) {
- error .minus_assign( outer_prod( column(z, i), e(i) * conj( column(z, i) ) ) ) ;
- }
- return (norm_frobenius( error )
- >= n* norm_2( e ) * std::numeric_limits< real_type >::epsilon() ) ;
-} // check_residual()
-
 
 template <typename T, typename W, char UPLO>
 int do_memory_uplo(int n, W& workspace ) {

Modified: sandbox/libs/numeric/bindings/lapack/test/ublas_heevx.cpp
==============================================================================
--- sandbox/libs/numeric/bindings/lapack/test/ublas_heevx.cpp (original)
+++ sandbox/libs/numeric/bindings/lapack/test/ublas_heevx.cpp 2008-05-22 09:03:38 EDT (Thu, 22 May 2008)
@@ -7,7 +7,7 @@
 // http://www.boost.org/LICENSE_1_0.txt)
 //
 
-#include "../../blas/test/random.hpp"
+#include "ublas_heev.hpp"
 
 #include <boost/numeric/bindings/lapack/heevx.hpp>
 #include <boost/numeric/bindings/traits/ublas_matrix.hpp>
@@ -18,55 +18,11 @@
 #include <boost/numeric/ublas/io.hpp>
 
 #include <iostream>
-#include <limits>
 
 
 namespace ublas = boost::numeric::ublas;
 namespace lapack = boost::numeric::bindings::lapack;
 
-inline float conj(float v) { return v; }
-inline double conj(double v) { return v; }
-
-// Fill a matrix
-template <typename M>
-void fill(M& m) {
- typedef typename M::size_type size_type ;
- typedef typename M::value_type value_type ;
-
- typedef typename boost::numeric::bindings::traits::type_traits<value_type>::real_type real_type ;
-
- int size = m.size2() ;
-
- for (int i=0; i<size; ++i) {
- for (int j=0; j<i; ++j) {
- m(j,i) = random_value<value_type>();
- m(i,j) = conj( m(j,i) ) ;
- }
- m(i,i) = random_value<real_type>();
- }
-} // randomize()
-
-
-template <typename H, typename E, typename Z>
-int check_residual(H const& h, E const& e, Z const& z) {
- typedef typename H::value_type value_type ;
- typedef typename E::value_type real_type ;
-
- // Check eigen decomposition
- int n = h.size1();
- ublas::matrix<value_type> error( n, n ); error.clear();
-
- // Copy band matrix in error
- error.assign( h );
- assert( norm_frobenius( error - herm( error ) ) == 0.0 ) ;
-
- for (int i=0; i<n; ++i) {
- error .minus_assign( outer_prod( column(z, i), e(i) * conj( column(z, i) ) ) ) ;
- }
- return (norm_frobenius( error )
- >= n* norm_2( e ) * std::numeric_limits< real_type >::epsilon() ) ;
-} // check_residual()
-
 
 template <typename T, typename W, typename UPLO>
 int do_memory_uplo(int n, W& workspace ) {

Modified: sandbox/libs/numeric/bindings/lapack/test/ublas_syev.cpp
==============================================================================
--- sandbox/libs/numeric/bindings/lapack/test/ublas_syev.cpp (original)
+++ sandbox/libs/numeric/bindings/lapack/test/ublas_syev.cpp 2008-05-22 09:03:38 EDT (Thu, 22 May 2008)
@@ -6,7 +6,7 @@
 // http://www.boost.org/LICENSE_1_0.txt)
 //
 
-#include "../../blas/test/random.hpp"
+#include "ublas_heev.hpp"
 
 #include <boost/numeric/bindings/lapack/syev.hpp>
 #include <boost/numeric/bindings/traits/ublas_matrix.hpp>
@@ -16,55 +16,12 @@
 #include <boost/numeric/ublas/io.hpp>
 
 #include <iostream>
-#include <limits>
 
 
 namespace ublas = boost::numeric::ublas;
 namespace lapack = boost::numeric::bindings::lapack;
 
 
-// Fill a matrix
-template <typename M>
-void fill(M& m) {
- typedef typename M::size_type size_type ;
- typedef typename M::value_type value_type ;
-
- typedef typename boost::numeric::bindings::traits::type_traits<value_type>::real_type real_type ;
-
- int size = m.size2() ;
-
- for (int i=0; i<size; ++i) {
- for (int j=0; j<i; ++j) {
- m(j,i) = random_value<value_type>();
- m(i,j) = m(j,i);
- }
- m(i,i) = random_value<real_type>();
- }
-} // randomize()
-
-
-template <typename H, typename E, typename Z>
-int check_residual(H const& h, E const& e, Z const& z) {
- typedef typename H::value_type value_type ;
- typedef typename E::value_type real_type ;
- real_type safety_factor(1.5);
-
- // Check eigen decomposition
- int n = h.size1();
- ublas::matrix<value_type> error( n, n ); error.clear();
-
- // Copy band matrix in error
- error.assign( h );
- assert( norm_frobenius( error - trans( error ) ) == 0.0 ) ;
-
- for (int i=0; i<n; ++i) {
- error .minus_assign( outer_prod( column(z, i), e(i) * conj( column(z, i) ) ) ) ;
- }
- return (norm_frobenius( error )
- >= safety_factor*n* norm_2( e ) * std::numeric_limits< real_type >::epsilon() ) ;
-} // check_residual()
-
-
 template <typename T, typename W, char UPLO>
 int do_memory_uplo(int n, W& workspace ) {
    typedef typename boost::numeric::bindings::traits::type_traits<T>::real_type real_type ;


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