00001 
00002 
00003 
00004 
00005 
00006 
00008 #ifndef synaps_linalg_TENSOR3D_H
00009 #define synaps_linalg_TENSOR3D_H
00010 
00011 
00012 
00013 #ifdef HAVE_CONFIG_H
00014 #include <synaps/init.h>
00015 #endif 
00016 
00017 #include <iostream>
00018 #include <assert.h>
00019 
00020 #include <synaps/linalg/MethodName.h>
00021 
00022 __BEGIN_NAMESPACE_SYNAPS
00023 
00024 
00026 namespace TENSOR3D {
00027  
00028   typedef unsigned size_type;
00029   
00032   template < class R >
00033   inline std::ostream & print( std::ostream & os, const R & m ) {
00034     typedef typename R::size_type  size_type;
00035     
00036     for ( size_type k = 0 ; k < m.nbhgt() ; k++ ) {
00037       for ( size_type i = 0 ; i < m.nbrow(); ++i ){
00038         os << "[ ";
00039         for ( size_type j = 0 ; j < m.nbcol() ; j++ )
00040           os<< m( i, j, k ) << " ";
00041         os << "]"<< std::endl;
00042       }
00043       os << std::endl;
00044     }
00045     return os;
00046   }
00047 
00050   template < class R >
00051   inline std::ostream & printsign( std::ostream & os, const R & m ) {
00052     typedef typename R::size_type  size_type;
00053     
00054     for ( size_type k = 0 ; k < m.nbhgt() ; k++ ) {
00055       for ( size_type i = 0 ; i < m.nbrow(); ++i ){     
00056         for( size_type u=0;u<k;u++) os<<" ";
00057         os << "[";
00058         for ( size_type j = 0 ; j < m.nbcol() ; j++ )
00059           if(m(i,j,k)<0) os<< "-"; else if (m(i,j,k)>0) os<< "+"; else os << "0"; 
00060         os << "]"<< std::endl;
00061       }
00062       os << std::endl;
00063     }
00064     return os;
00065   }
00066 
00067   
00073   template< class R >  inline
00074   std::istream & read( std::istream & is, R & M ){
00075     typedef typename R::size_type size_type;
00076     size_type m, n, o;
00077     is >> m >> n >> o;
00078     M.rep().resize( m, n );
00079  
00080     for ( size_type k = 0; k < o ; k++ )
00081       for ( size_type i = 0 ; i < m ; i++ )
00082         for (size_type j = 0 ; j < n ; j++ ) {
00083           is >> M(i,j);
00084         }
00085     return( is );
00086   }
00087 
00090   template< class R, class C > inline
00091   void init( R & a, const C & c) { 
00092     typedef typename R::size_type size_type;
00093 
00094     for ( size_type i = 0 ; i < a.nbrow() ; i++ ) 
00095       for ( size_type j = 0 ; j < a.nbcol(); j++ )
00096         for ( size_type k = 0 ; k < a.nbhgt() ; k++)
00097           a( i, j, k ) = c;
00098   }
00099 
00103   template < class R1, class R2 >
00104   inline void assign( R1 & r, const R2 & m ) {
00105     typedef typename R1::size_type  size_type;
00106     
00107     for ( size_type i = 0 ; i < m.nbrow(); ++i )
00108       for (size_type j = 0 ; j < m.nbcol(); j++ )
00109         for( size_type k = 0 ; k < m.nbhgt() ; k++ )
00110           r( i, j, k ) = m( i, j, k );
00111   }
00112   
00113   
00114 } 
00115 
00116 
00117 
00118 __END_NAMESPACE_SYNAPS
00119 
00120 #endif // synaps_linalg_TENSOR3D_H