メインページ   クラス階層   構成   ファイル一覧   構成メンバ   ファイルメンバ  

MArray.cc

解説を見る。
00001 /*
00002 
00003 Copyright (C) 1996, 1997 John W. Eaton
00004 
00005 This file is part of Octave.
00006 
00007 Octave is free software; you can redistribute it and/or modify it
00008 under the terms of the GNU General Public License as published by the
00009 Free Software Foundation; either version 2, or (at your option) any
00010 later version.
00011 
00012 Octave is distributed in the hope that it will be useful, but WITHOUT
00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00015 for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Octave; see the file COPYING.  If not, write to the Free
00019 Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00020 
00021 */
00022 
00023 #if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION)
00024 #pragma implementation
00025 #endif
00026 
00027 #ifdef HAVE_CONFIG_H
00028 #include <config.h>
00029 #endif
00030 
00031 #include "MArray.h"
00032 #include "Array-util.h"
00033 #include "lo-error.h"
00034 
00035 #include "MArray-defs.h"
00036 
00037 // One dimensional array with math ops.
00038 
00039 // Element by element MArray by scalar ops.
00040 
00041 template <class T>
00042 MArray<T>&
00043 operator += (MArray<T>& a, const T& s)
00044 {
00045   DO_VS_OP2 (T, a, +=, s)
00046   return a;
00047 }
00048 
00049 template <class T>
00050 MArray<T>&
00051 operator -= (MArray<T>& a, const T& s)
00052 {
00053   DO_VS_OP2 (T, a, -=, s)
00054   return a;
00055 }
00056 
00057 // Element by element MArray by MArray ops.
00058 
00059 template <class T>
00060 MArray<T>&
00061 operator += (MArray<T>& a, const MArray<T>& b)
00062 {
00063   int l = a.length ();
00064   if (l > 0)
00065     {
00066       int bl = b.length ();
00067       if (l != bl)
00068         gripe_nonconformant ("operator +=", l, bl);
00069       else
00070         DO_VV_OP2 (T, a, +=, b);
00071     }
00072   return a;
00073 }
00074 
00075 template <class T>
00076 MArray<T>&
00077 operator -= (MArray<T>& a, const MArray<T>& b)
00078 {
00079   int l = a.length ();
00080   if (l > 0)
00081     {
00082       int bl = b.length ();
00083       if (l != bl)
00084         gripe_nonconformant ("operator -=", l, bl);
00085       else
00086         DO_VV_OP2 (T, a, -=, b);
00087     }
00088   return a;
00089 }
00090 
00091 // Element by element MArray by scalar ops.
00092 
00093 #define MARRAY_AS_OP(OP) \
00094   template <class T> \
00095   MArray<T> \
00096   operator OP (const MArray<T>& a, const T& s) \
00097   { \
00098     MArray<T> result (a.length ()); \
00099     T *r = result.fortran_vec (); \
00100     int l = a.length (); \
00101     const T *v = a.data (); \
00102     DO_VS_OP (r, l, v, OP, s); \
00103     return result; \
00104   }
00105 
00106 MARRAY_AS_OP (+)
00107 MARRAY_AS_OP (-)
00108 MARRAY_AS_OP (*)
00109 MARRAY_AS_OP (/)
00110 
00111 // Element by element scalar by MArray ops.
00112 
00113 #define MARRAY_SA_OP(OP) \
00114   template <class T> \
00115   MArray<T> \
00116   operator OP (const T& s, const MArray<T>& a) \
00117   { \
00118     MArray<T> result (a.length ()); \
00119     T *r = result.fortran_vec (); \
00120     int l = a.length (); \
00121     const T *v = a.data (); \
00122     DO_SV_OP (r, l, s, OP, v); \
00123     return result; \
00124   }
00125 
00126 MARRAY_SA_OP(+)
00127 MARRAY_SA_OP(-)
00128 MARRAY_SA_OP(*)
00129 MARRAY_SA_OP(/)
00130 
00131 // Element by element MArray by MArray ops.
00132 
00133 #define MARRAY_AA_OP(FCN, OP) \
00134   template <class T> \
00135   MArray<T> \
00136   FCN (const MArray<T>& a, const MArray<T>& b) \
00137   { \
00138     int l = a.length (); \
00139     int bl = b.length (); \
00140     if (l != bl) \
00141       { \
00142         gripe_nonconformant (#FCN, l, bl); \
00143         return MArray<T> (); \
00144       } \
00145     if (l == 0) \
00146       return MArray<T> (); \
00147     MArray<T> result (l); \
00148     T *r = result.fortran_vec (); \
00149     const T *x = a.data (); \
00150     const T *y = b.data (); \
00151     DO_VV_OP (r, l, x, OP, y); \
00152     return result; \
00153   }
00154 
00155 MARRAY_AA_OP (operator +, +)
00156 MARRAY_AA_OP (operator -, -)
00157 MARRAY_AA_OP (product,    *)
00158 MARRAY_AA_OP (quotient,   /)
00159 
00160 // Unary MArray ops.
00161 
00162 template <class T>
00163 MArray<T>
00164 operator + (const MArray<T>& a)
00165 {
00166   return a;
00167 }
00168 
00169 template <class T>
00170 MArray<T>
00171 operator - (const MArray<T>& a)
00172 {
00173   int l = a.length ();
00174   MArray<T> result (l);
00175   T *r = result.fortran_vec ();
00176   const T *x = a.data ();
00177   NEG_V (r, l, x);
00178   return result;
00179 }
00180 
00181 /*
00182 ;;; Local Variables: ***
00183 ;;; mode: C++ ***
00184 ;;; End: ***
00185 */

Wed Dec 29 11:51:44 2004に生成されました。 doxygen1.2.18
SEO [PR] 爆速!無料ブログ 無料ホームページ開設 無料ライブ放送