Main Page | Namespace List | Data Structures | File List | Namespace Members | Data Fields | Globals

nested.cpp

Go to the documentation of this file.
00001 
00002 #include <iostream>
00003 
00004 #define BOOST_UBLAS_USE_ET
00005 
00006 #include <boost/timer.hpp>
00007 #include <boost/numeric/ublas/matrix.hpp>
00008 #include <boost/numeric/ublas/vector.hpp>
00009 #include <boost/numeric/ublas/io.hpp>
00010 
00011 using std::size_t;
00012 using std::cout;
00013 using std::endl;
00014 
00015 // define matrix/vector types
00016 
00017 typedef boost::numeric::ublas::bounded_matrix<double, 3, 3>  TINY;
00018 typedef boost::numeric::ublas::matrix<TINY>                  BIG;
00019 
00020 typedef boost::numeric::ublas::bounded_vector<double, 3>  TINY_VEC;
00021 typedef boost::numeric::ublas::vector<TINY_VEC>           BIG_VEC;
00022 
00023 // define new promote traits
00024 
00025 namespace boost { namespace numeric { namespace ublas {
00026 
00027     template<>
00028     struct promote_traits<TINY, TINY_VEC> {
00029         typedef TINY_VEC promote_type;
00030     };
00031 
00032     template<>
00033     struct promote_traits<TINY, double> {
00034         typedef TINY promote_type;
00035     };
00036 
00037     template<>
00038     struct promote_traits<double, TINY> {
00039         typedef TINY promote_type;
00040     };
00041 
00042     BOOST_UBLAS_INLINE
00043         TINY_VEC
00044         operator * (const TINY& A, const TINY_VEC& x)
00045         {
00046           TINY_VEC tmp;
00047           tmp = prod(A,x);
00048           return tmp;
00049         };
00050   
00051 }}}
00052 
00053 using namespace boost::numeric::ublas;
00054 
00055 int main(size_t argc, char *argv[])
00056 {
00057   size_t size = 20;
00058 
00059   if (argc > 1)
00060         size = ::atoi (argv [1]);
00061 
00062   TINY    tiny;
00063   BIG     big(5,5);
00064 
00065   tiny(0,0) = 1;
00066   tiny(0,1) = 2;
00067   tiny(0,2) = 3;
00068   tiny(1,0) = 4;
00069   tiny(2,0) = 5;
00070   
00071   cout << "tiny: " << tiny << endl;
00072 
00073   big(0,0) = tiny;
00074   big(1,1) = tiny;
00075   big(2,2) = tiny;
00076   big(3,4) = tiny;
00077   big(4,3) = tiny;
00078 
00079   cout << "big: " << big << endl;
00080   
00081   TINY_VEC  tv;
00082 
00083   tv(0) = 1.0;
00084   tv(1) = 1.0;
00085   tv(2) = 1.0;
00086 
00087   BIG_VEC   bv(scalar_vector<TINY_VEC>(5,tv));
00088 
00089   cout << "tiny_vector: " << tv << endl;
00090   cout << "big_vector: " << bv << endl;
00091 
00092   cout << "tiny + tiny = " << (tiny + tiny) << endl;
00093   cout << "big + big   = " << (big + big) << endl;
00094 
00095   cout << "tiny - tiny = " << (tiny - tiny) << endl;
00096   cout << "big - big   = " << (big - big) << endl;
00097 
00098   cout << "2.0 * tiny = " << (2.0 * tiny) << endl;
00099   cout << "2.0 * big  = " << (2.0 * big) << endl;
00100 
00101   cout << "tiny * tiny_vector = " << prod(tiny, tv) << endl;
00102   cout << "big * big_vector   = " << prod(big, bv) << endl;
00103 
00104   return 0;
00105 
00106 }

Generated on Wed Oct 1 14:41:00 2003 for Sample Code by doxygen 1.3.2