33 #ifndef __INCLUDE_MIST_OPERATOR_ARRAY2__
34 #define __INCLUDE_MIST_OPERATOR_ARRAY2__
47 template <
class T,
class Allocator >
48 inline const array2< T, Allocator >&
operator +=( array2< T, Allocator > &a1,
const array2< T, Allocator > &a2 )
50 typedef typename array2< T, Allocator >::size_type size_type;
51 #if _CHECK_ARRAY2_OPERATION_ != 0
52 if( a1.size( ) != a2.size( ) )
55 ::std::cerr <<
"can't add array2s." << ::std::endl;
59 for( size_type i = 0 ; i < a1.size( ) ; i++ ) a1[i] += static_cast< T >( a2[i] );
73 template <
class T,
class Allocator >
74 inline const array2< T, Allocator >&
operator -=( array2< T, Allocator > &a1,
const array2< T, Allocator > &a2 )
76 typedef typename array2< T, Allocator >::size_type size_type;
77 #if _CHECK_ARRAY2_OPERATION_ != 0
78 if( a1.size( ) != a2.size( ) )
81 ::std::cerr <<
"can't subtract array2s." << ::std::endl;
85 for( size_type i = 0 ; i < a1.size( ) ; i++ ) a1[i] -= static_cast< T >( a2[i] );
99 template <
class T,
class Allocator >
100 inline const array2< T, Allocator >&
operator *=( array2< T, Allocator > &a1,
const array2< T, Allocator > &a2 )
102 typedef typename array2< T, Allocator >::size_type size_type;
103 #if _CHECK_ARRAY2_OPERATION_ != 0
104 if( a1.size( ) != a2.size( ) )
107 ::std::cerr <<
"can't multiply array2s." << ::std::endl;
111 for( size_type i = 0 ; i < a1.size( ) ; i++ ) a1[i] *= static_cast< T >( a2[i] );
125 template <
class T,
class Allocator >
126 inline const array2< T, Allocator >&
operator /=( array2< T, Allocator > &a1,
const array2< T, Allocator > &a2 )
128 typedef typename array2< T, Allocator >::size_type size_type;
129 #if _CHECK_ARRAY2_OPERATION_ != 0
130 if( a1.size( ) != a2.size( ) )
133 ::std::cerr <<
"can't divide array2s." << ::std::endl;
137 for( size_type i = 0 ; i < a1.size( ) ; i++ ) a1[i] /= static_cast< T >( a2[i] );
151 template <
class T,
class Allocator >
152 inline const array2< T, Allocator >&
operator +=( array2< T, Allocator > &a1,
typename array2< T, Allocator >::value_type val )
154 typedef typename array2< T, Allocator >::size_type size_type;
155 for( size_type i = 0 ; i < a1.size( ) ; i++ ) a1[i] += val;
169 template <
class T,
class Allocator >
170 inline const array2< T, Allocator >&
operator -=( array2< T, Allocator > &a1,
typename array2< T, Allocator >::value_type val )
172 typedef typename array2< T, Allocator >::size_type size_type;
173 for( size_type i = 0 ; i < a1.size( ) ; i++ ) a1[i] -= val;
187 template <
class T,
class Allocator >
188 inline const array2< T, Allocator >&
operator *=( array2< T, Allocator > &a1,
typename array2< T, Allocator >::value_type val )
190 typedef typename array2< T, Allocator >::size_type size_type;
191 for( size_type i = 0 ; i < a1.size( ) ; i++ ) a1[i] *= val;
205 template <
class T,
class Allocator >
206 inline const array2< T, Allocator >&
operator /=( array2< T, Allocator > &a1,
typename array2< T, Allocator >::value_type val )
208 typedef typename array2< T, Allocator >::size_type size_type;
209 typedef typename array2< T, Allocator >::value_type value_type;
210 #if _CHECK_ARRAY2_OPERATION_ != 0
211 if( val == value_type( 0 ) )
214 ::std::cerr <<
"zero division occured." << ::std::endl;
218 for( size_type i = 0 ; i < a1.size( ) ; i++ ) a1[i] /= val;
232 template <
class T,
class Allocator >
233 inline array2< T, Allocator >
operator -(
const array2< T, Allocator > &a )
235 typedef typename array2< T, Allocator >::size_type size_type;
236 array2< T, Allocator > o( a.size1( ), a.size2( ), a.reso1( ), a.reso2( ) );
237 for( size_type i = 0 ; i < o.size( ) ; i++ ) o[i] = -a[i];
252 template <
class T,
class Allocator >
253 inline array2< T, Allocator >
operator +(
const array2< T, Allocator > &a1,
const array2< T, Allocator > &a2 )
255 array2< T, Allocator > tmp( a1 );
270 template <
class T,
class Allocator >
271 inline array2< T, Allocator >
operator -(
const array2< T, Allocator > &a1,
const array2< T, Allocator > &a2 )
273 array2< T, Allocator > tmp( a1 );
288 template <
class T,
class Allocator >
289 inline array2< T, Allocator >
operator *(
const array2< T, Allocator > &a1,
const array2< T, Allocator > &a2 )
291 array2< T, Allocator > tmp( a1 );
306 template <
class T,
class Allocator >
307 inline array2< T, Allocator >
operator /(
const array2< T, Allocator > &a1,
const array2< T, Allocator > &a2 )
309 array2< T, Allocator > tmp( a1 );
324 template <
class T,
class Allocator >
325 inline array2< T, Allocator >
operator +(
const array2< T, Allocator > &a,
typename array2< T, Allocator >::value_type val )
327 array2< T, Allocator > tmp( a );
328 return( tmp += val );
341 template <
class T,
class Allocator >
342 inline array2< T, Allocator >
operator +(
typename array2< T, Allocator >::value_type val,
const array2< T, Allocator > &a )
344 array2< T, Allocator > tmp( a );
345 return( tmp += val );
358 template <
class T,
class Allocator >
359 inline array2< T, Allocator >
operator -(
const array2< T, Allocator > &a,
typename array2< T, Allocator >::value_type val )
361 array2< T, Allocator > tmp( a );
362 return( tmp -= val );
375 template <
class T,
class Allocator >
376 inline array2< T, Allocator >
operator -(
typename array2< T, Allocator >::value_type val,
const array2< T, Allocator > &a )
378 array2< T, Allocator > tmp( a.size1( ), a.size2( ), val );
392 template <
class T,
class Allocator >
393 inline array2< T, Allocator >
operator *(
const array2< T, Allocator > &a,
typename array2< T, Allocator >::value_type val )
395 array2< T, Allocator > tmp( a );
396 return( tmp *= val );
409 template <
class T,
class Allocator >
410 inline array2< T, Allocator >
operator *(
typename array2< T, Allocator >::value_type val,
const array2< T, Allocator > &a )
412 array2< T, Allocator > tmp( a );
413 return( tmp *= val );
426 template <
class T,
class Allocator >
427 inline array2< T, Allocator >
operator /(
const array2< T, Allocator > &a,
typename array2< T, Allocator >::value_type val )
429 array2< T, Allocator > tmp( a );
430 return( tmp /= val );
434 #endif // __INCLUDE_MIST_OPERATOR_ARRAY2__