Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r75379 - sandbox/variadic_templates/sandbox/stepper/boost/array_stepper/numeric
From: cppljevans_at_[hidden]
Date: 2011-11-07 09:11:16


Author: cppljevans
Date: 2011-11-07 09:11:14 EST (Mon, 07 Nov 2011)
New Revision: 75379
URL: http://svn.boost.org/trac/boost/changeset/75379

Log:
Move to more meaningful directory

Added:
   sandbox/variadic_templates/sandbox/stepper/boost/array_stepper/numeric/solve_tridiag.hpp
      - copied, changed from r75137, /sandbox/variadic_templates/sandbox/stepper/boost/array_stepper/solve_tridiag.hpp
Text files modified:
   sandbox/variadic_templates/sandbox/stepper/boost/array_stepper/numeric/solve_tridiag.hpp | 166 ++++++++++++++++++++++-----------------
   1 files changed, 94 insertions(+), 72 deletions(-)

Copied: sandbox/variadic_templates/sandbox/stepper/boost/array_stepper/numeric/solve_tridiag.hpp (from r75137, /sandbox/variadic_templates/sandbox/stepper/boost/array_stepper/solve_tridiag.hpp)
==============================================================================
--- /sandbox/variadic_templates/sandbox/stepper/boost/array_stepper/solve_tridiag.hpp (original)
+++ sandbox/variadic_templates/sandbox/stepper/boost/array_stepper/numeric/solve_tridiag.hpp 2011-11-07 09:11:14 EST (Mon, 07 Nov 2011)
@@ -1,5 +1,5 @@
-#ifndef BOOST_ARRAY_STEPPER_SOLVE_TRIDIAG_HPP_INCLUDED
-#define BOOST_ARRAY_STEPPER_SOLVE_TRIDIAG_HPP_INCLUDED
+#ifndef BOOST_ARRAY_STEPPER_NUMERIC_SOLVE_TRIDIAG_HPP_INCLUDED
+#define BOOST_ARRAY_STEPPER_NUMERIC_SOLVE_TRIDIAG_HPP_INCLUDED
 #include <boost/array_stepper/index_stack_length_stride_crtp.hpp>
 #include <boost/array_stepper/array_dyn.hpp>
 #include <boost/array_stepper/vector_print.hpp>
@@ -9,12 +9,15 @@
 #define SOLVE_TRIDIAG_VERIFY
 #ifdef SOLVE_TRIDIAG_VERIFY
 #include <boost/assert.hpp>
+#include <boost/array_stepper/numeric/almost_equal_relative.hpp>
 #endif
 
 namespace boost
 {
 namespace array_stepper
 {
+namespace numeric
+{
 
   struct
 tridiag_seq_seq_tag
@@ -357,7 +360,10 @@
               <<":n_node="<<n_node
               <<":n_last="<<n_last
               <<":stride_last="<<stride_last
- <<"\n";
+ <<":rotation="<<my_istk.rotation()
+ <<"\n"
+ <<"{ "
+ ;
           #endif
             unsigned i_node;
             for
@@ -373,7 +379,15 @@
               */
             {
               #ifdef TRACE_UPPER_TRIANGULATE_RHS
- ::boost::trace_scope ts("outer");
+ using ::operator<<;
+ if(0<i_node)std::cout<<", ";
+ std::cout<<indent_buf_in;
+ std::cout<<"{ ";
+ std::cout
+ <<":r"<<my_istk.indices()
+ <<"="<<my_r[my_istk.offset_space_val()]
+ <<"\n"
+ ;
               #endif
                 for
                   ( int i_last=0
@@ -384,51 +398,35 @@
                   )
                 {
                     int offset_istk=my_istk.offset_space_val();
+ #ifdef TRACE_UPPER_TRIANGULATE_RHS
+ value_t my_old_r=my_r[offset_istk+stride_last];
+ #endif
                     my_r[offset_istk+stride_last]-=my_trid.l(i_last+1)*my_r[offset_istk]
                     ;
                   #ifdef TRACE_UPPER_TRIANGULATE_RHS
- ::boost::trace_scope ts("inner");
+ std::cout<<", ";
                     std::cout
- <<":i_node="<<i_node
- <<":i_last="<<i_last
- <<":offset_istk="<<offset_istk
- <<":r="<<my_r[offset_istk+stride_last]
+ <<":r"<<my_istk.indices_at_offset(offset_istk+stride_last)
+ <<"="
+ <<my_old_r
+ <<":->"
+ <<my_r[offset_istk+stride_last]
                       <<"\n";
                   #endif
                 }
+ #ifdef TRACE_UPPER_TRIANGULATE_RHS
+ std::cout<<"}\n";
+ std::cout<<indent_buf_out;
+ #endif
             }
+ #ifdef TRACE_UPPER_TRIANGULATE_RHS
+ std::cout<<"}\n";
+ #endif
           #ifdef SOLVE_TRIDIAG_VERIFY
             BOOST_ASSERT_MSG(i_node==n_node,"i_node!=n_node");
           #endif
           #undef TRACE_UPPER_TRIANGULATE_RHS
         }
- #ifdef SOLVE_TRIDIAG_VERIFY
- static
- bool
- almost_equal_relative
- ( value_t value_a
- , value_t value_b
- )
- /**@brief
- * Are value_a and value_b almost equal?
- */
- //Reference:
- // http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm
- //
- {
- value_t max_error=2.0*std::numeric_limits<value_t>::epsilon();
- value_t abs_diff=std::abs(value_a - value_b);
- if (abs_diff < max_error)
- return true;
- value_t abs_a=std::abs(value_a);
- value_t abs_b=std::abs(value_b);
- value_t abs_max=std::max(abs_a,abs_b);
- value_t relative_error=abs_diff / abs_max;
- if (relative_error < max_error)
- return true;
- return false;
- }
- #endif
         void
       back_substitute
         (
@@ -464,7 +462,7 @@
               ;
               int
             offset_istk=my_istk.offset_space_val();
- #define TRACE_BACK_SUBSTITUTE
+ //#define TRACE_BACK_SUBSTITUTE
           #ifdef TRACE_BACK_SUBSTITUTE
             ::boost::trace_scope ts("back_substitute");
             std::cout
@@ -498,7 +496,8 @@
                 std::cout<<indent_buf_in;
                 std::cout<<"{ ";
                 std::cout
- <<":x"<<my_istk.indices()<<"="<<my_x[offset_istk]
+ <<":x"<<my_istk.indices()
+ <<"="<<my_x[offset_istk]
                   <<"\n"
                   ;
               #endif
@@ -545,7 +544,8 @@
               ;
               )
             {
- int i_last=n_last-1;
+ int
+ i_last=n_last-1;
                   value_t
                 rhs=o_r[i_node-1]
                   ;
@@ -554,22 +554,57 @@
                   = my_x[offset_istk-stride_last]*o_trid.l(i_last)
                   + my_x[offset_istk ]*o_trid.d(i_last)
                   ;
- #ifdef TRACE_TRIDIAG_VERIFY
- std::cout
- <<":i_last="<<i_last
- <<":my_x["<<offset_istk-stride_last<<"]="<<my_x[offset_istk-stride_last]
- <<":l="<<o_trid.l(i_last)
- <<":my_x["<<offset_istk<<"]="<<my_x[offset_istk]
- <<":d="<<o_trid.d(i_last)
- <<":r["<<i_node-1<<"]="<<o_r[i_node-1]
- <<"\n:lhs="<<lhs
- <<"\n:rhs="<<rhs
+ bool
+ solved=almost_equal_relative(lhs,rhs)
                   ;
- std::cout<<"\n:my_istk=";
- ::operator<<(std::cout,my_istk);
- std::cout<<"\n";
+ #define TRACE_TRIDIAG_VERIFY 0
+ #define TRACE_LONG_TRIDIAG_VERIFY 1
+ auto
+ trace_verify=
+ [ &i_last
+ , &solved
+ #if TRACE_LONG_TRIDIAG_VERIFY
+ , &my_x
+ , &o_trid
+ , &offset_istk
+ , &stride_last
+ , &i_node
+ , &o_r
+ , &lhs
+ , &rhs
+ , &my_istk
+ #endif
+ ]()
+ {
+ if
+ ( !solved
+ || TRACE_TRIDIAG_VERIFY
+ )
+ {
+ std::cout
+ <<":i_last="<<i_last;
+ #if TRACE_LONG_TRIDIAG_VERIFY
+ std::cout
+ <<":my_x["<<offset_istk-stride_last<<"]="<<my_x[offset_istk-stride_last]
+ <<":l="<<o_trid.l(i_last)
+ <<":my_x["<<offset_istk<<"]="<<my_x[offset_istk]
+ <<":d="<<o_trid.d(i_last)
+ <<":r["<<i_node-1<<"]="<<o_r[i_node-1]
+ <<"\n:lhs="<<lhs
+ <<"\n:rhs="<<rhs
+ ;
+ std::cout<<"\n:my_istk=";
+ ::operator<<(std::cout,my_istk);
+ #endif
+ std::cout<<"\n"<<std::flush;
+ }
+ };
+ #if TRACE_TRIDIAG_VERIFY
+ std::cout<<":i_node="<<i_node<<":solved="<<solved<<"\n";
+ ::boost::indent_scope<> is();
+ trace_verify();
               #endif
- BOOST_ASSERT_MSG(almost_equal_relative(lhs,rhs),"equation not solved");
+ BOOST_ASSERT_MSG(solved,"equation not solved");
                 for
                   ( --i_last
                     , --my_istk
@@ -594,26 +629,12 @@
                          +=my_x[offset_istk-stride_last]*o_trid.l(i_last)
                           ;
                     }
- #ifdef TRACE_TRIDIAG_VERIFY
- std::cout
- <<":i_last="<<i_last;
- if(0<i_last) std::cout
- <<":my_x["<<offset_istk-stride_last<<"]="<<my_x[offset_istk-stride_last]
- <<":l="<<o_trid.l(i_last);
- std::cout
- <<":my_x["<<offset_istk<<"]="<<my_x[offset_istk]
- <<":d="<<o_trid.d(i_last)
- <<":my_x["<<offset_istk+stride_last<<"]="<<my_x[offset_istk+stride_last]
- <<":u="<<o_trid.u(i_last)
- <<":r["<<i_node-1<<"]="<<o_r[i_node-1]
- <<"\n:lhs="<<lhs
- <<"\n:rhs="<<rhs
- ;
- std::cout<<"\n:my_istk=";
- ::operator<<(std::cout,my_istk);
- std::cout<<"\n";
+ solved=almost_equal_relative(lhs,rhs);
+ #if TRACE_TRIDIAG_VERIFY
+ ::boost::indent_scope<> is;
                   #endif
- BOOST_ASSERT_MSG(almost_equal_relative(lhs,rhs),"equation not solved");
+ trace_verify();
+ BOOST_ASSERT_MSG(solved,"equation not solved");
                 }
             }
         #endif
@@ -648,6 +669,7 @@
     #endif
   };//solve_tridiag
   
+}//exit numeric namespace
 }//exit array_stepper namespace
 }//exit boost namespace
 #endif


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