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

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

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