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

MArray2.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 "MArray2.h"
00032 #include "Array-util.h"
00033 #include "lo-error.h"
00034 
00035 #include "MArray-defs.h"
00036 
00037 // Two dimensional array with math ops.
00038 
00039 // Element by element MArray2 by scalar ops.
00040 
00041 template <class T>
00042 MArray2<T>&
00043 operator += (MArray2<T>& a, const T& s)
00044 {
00045   DO_VS_OP2 (T, a, +=, s)
00046   return a;
00047 }
00048 
00049 template <class T>
00050 MArray2<T>&
00051 operator -= (MArray2<T>& a, const T& s)
00052 {
00053   DO_VS_OP2 (T, a, -=, s)
00054   return a;
00055 }
00056 
00057 // Element by element MArray2 by MArray2 ops.
00058 
00059 template <class T>
00060 MArray2<T>&
00061 operator += (MArray2<T>& a, const MArray2<T>& b)
00062 {
00063   int r = a.rows ();
00064   int c = a.cols ();
00065   int br = b.rows ();
00066   int bc = b.cols ();
00067   if (r != br || c != bc)
00068     gripe_nonconformant ("operator +=", r, c, br, bc);
00069   else
00070     {
00071       if (r > 0 && c > 0)
00072         {
00073           int l = a.length ();
00074           DO_VV_OP2 (T, a, +=, b);
00075         }
00076     }
00077   return a;
00078 }
00079 
00080 template <class T>
00081 MArray2<T>&
00082 operator -= (MArray2<T>& a, const MArray2<T>& b)
00083 {
00084   int r = a.rows ();
00085   int c = a.cols ();
00086   int br = b.rows ();
00087   int bc = b.cols ();
00088   if (r != br || c != bc)
00089     gripe_nonconformant ("operator -=", r, c, br, bc);
00090   else
00091     {
00092       if (r > 0 && c > 0)
00093         {
00094           int l = a.length ();
00095           DO_VV_OP2 (T, a, -=, b);
00096         }
00097     }
00098   return a;
00099 }
00100 
00101 // Element by element MArray2 by scalar ops.
00102 
00103 #define MARRAY_A2S_OP(OP) \
00104   template <class T> \
00105   MArray2<T> \
00106   operator OP (const MArray2<T>& a, const T& s) \
00107   { \
00108     MArray2<T> result (a.rows (), a.cols ()); \
00109     T *r = result.fortran_vec (); \
00110     int l = a.length (); \
00111     const T *v = a.data (); \
00112     DO_VS_OP (r, l, v, OP, s); \
00113     return result; \
00114   }
00115 
00116 MARRAY_A2S_OP (+)
00117 MARRAY_A2S_OP (-)
00118 MARRAY_A2S_OP (*)
00119 MARRAY_A2S_OP (/)
00120 
00121 // Element by element scalar by MArray2 ops.
00122 
00123 #define MARRAY_SA2_OP(OP) \
00124   template <class T> \
00125   MArray2<T> \
00126   operator OP (const T& s, const MArray2<T>& a) \
00127   { \
00128     MArray2<T> result (a.rows (), a.cols ()); \
00129     T *r = result.fortran_vec (); \
00130     int l = a.length (); \
00131     const T *v = a.data (); \
00132     DO_SV_OP (r, l, s, OP, v); \
00133     return result; \
00134   }
00135 
00136 MARRAY_SA2_OP (+)
00137 MARRAY_SA2_OP (-)
00138 MARRAY_SA2_OP (*)
00139 MARRAY_SA2_OP (/)
00140 
00141 // Element by element MArray2 by MArray2 ops.
00142 
00143 #define MARRAY_A2A2_OP(FCN, OP) \
00144   template <class T> \
00145   MArray2<T> \
00146   FCN (const MArray2<T>& a, const MArray2<T>& b) \
00147   { \
00148     int a_nr = a.rows (); \
00149     int a_nc = a.cols (); \
00150     int b_nr = b.rows (); \
00151     int b_nc = b.cols (); \
00152     if (a_nr != b_nr || a_nc != b_nc) \
00153       { \
00154         gripe_nonconformant (#FCN, a_nr, a_nc, b_nr, b_nc); \
00155         return MArray2<T> (); \
00156       } \
00157     if (a_nr == 0 || a_nc == 0) \
00158       return MArray2<T> (a_nr, a_nc); \
00159     int l = a.length (); \
00160     MArray2<T> result (a_nr, a_nc); \
00161     T *r = result.fortran_vec (); \
00162     const T *x = a.data (); \
00163     const T *y = b.data (); \
00164     DO_VV_OP (r, l, x, OP, y); \
00165     return result; \
00166   }
00167 
00168 MARRAY_A2A2_OP (operator +, +)
00169 MARRAY_A2A2_OP (operator -, -)
00170 MARRAY_A2A2_OP (product,    *)
00171 MARRAY_A2A2_OP (quotient,   /)
00172 
00173 // Unary MArray2 ops.
00174 
00175 template <class T>
00176 MArray2<T>
00177 operator + (const MArray2<T>& a)
00178 {
00179   return a;
00180 }
00181 
00182 template <class T>
00183 MArray2<T>
00184 operator - (const MArray2<T>& a)
00185 {
00186   int l = a.length ();
00187   MArray2<T> result (a.rows (), a.cols ());
00188   T *r = result.fortran_vec ();
00189   const T *x = a.data ();
00190   NEG_V (r, l, x);
00191   return result;
00192 }
00193 
00194 /*
00195 ;;; Local Variables: ***
00196 ;;; mode: C++ ***
00197 ;;; End: ***
00198 */

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