1993
|
1 // Template array classes with like-type math ops |
1988
|
2 /* |
|
3 |
2847
|
4 Copyright (C) 1996, 1997 John W. Eaton |
1988
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
|
10 Free Software Foundation; either version 2, or (at your option) any |
|
11 later version. |
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
|
19 along with Octave; see the file COPYING. If not, write to the Free |
|
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
21 |
|
22 */ |
|
23 |
|
24 #if defined (__GNUG__) |
|
25 #pragma interface |
|
26 #endif |
|
27 |
|
28 #if !defined (octave_MDiagArray2_h) |
|
29 #define octave_MDiagArray2_h 1 |
|
30 |
|
31 #include "DiagArray2.h" |
|
32 #include "MArray2.h" |
|
33 |
|
34 // Two dimensional diagonal array with math ops. |
|
35 |
|
36 template <class T> |
|
37 class MDiagArray2 : public DiagArray2<T> |
|
38 { |
|
39 protected: |
|
40 |
|
41 MDiagArray2 (T *d, int r, int c) : DiagArray2<T> (d, r, c) { } |
|
42 |
|
43 public: |
|
44 |
|
45 MDiagArray2 (void) : DiagArray2<T> () { } |
|
46 MDiagArray2 (int r, int c) : DiagArray2<T> (r, c) { } |
|
47 MDiagArray2 (int r, int c, const T& val) : DiagArray2<T> (r, c, val) { } |
|
48 MDiagArray2 (const Array<T>& a) : DiagArray2<T> (a) { } |
|
49 MDiagArray2 (const DiagArray2<T>& a) : DiagArray2<T> (a) { } |
|
50 MDiagArray2 (const MDiagArray2<T>& a) : DiagArray2<T> (a) { } |
|
51 |
|
52 ~MDiagArray2 (void) { } |
|
53 |
|
54 MDiagArray2<T>& operator = (const MDiagArray2<T>& a) |
|
55 { |
|
56 DiagArray2<T>::operator = (a); |
|
57 return *this; |
|
58 } |
|
59 |
|
60 operator MArray2<T> () const |
|
61 { |
|
62 MArray2<T> retval (nr, nc, T (0)); |
|
63 |
|
64 int len = nr < nc ? nr : nc; |
|
65 |
|
66 for (int i = 0; i < len; i++) |
|
67 retval.xelem (i, i) = xelem (i, i); |
|
68 |
|
69 return retval; |
|
70 } |
|
71 |
|
72 // element by element MDiagArray2 by MDiagArray2 ops |
|
73 |
|
74 friend MDiagArray2<T>& |
|
75 operator += (MDiagArray2<T>& a, const MDiagArray2<T>& b); |
|
76 |
|
77 friend MDiagArray2<T>& |
|
78 operator -= (MDiagArray2<T>& a, const MDiagArray2<T>& b); |
|
79 |
|
80 // element by element MDiagArray2 by scalar ops |
|
81 |
|
82 friend MDiagArray2<T> operator * (const MDiagArray2<T>& a, const T& s); |
|
83 friend MDiagArray2<T> operator / (const MDiagArray2<T>& a, const T& s); |
|
84 |
|
85 // element by element scalar by MDiagArray2 ops |
|
86 |
|
87 friend MDiagArray2<T> operator * (const T& s, const MDiagArray2<T>& a); |
|
88 |
|
89 // element by element MDiagArray2 by MDiagArray2 ops |
|
90 |
|
91 friend MDiagArray2<T> |
|
92 operator + (const MDiagArray2<T>& a, const MDiagArray2<T>& b); |
|
93 |
|
94 friend MDiagArray2<T> |
|
95 operator - (const MDiagArray2<T>& a, const MDiagArray2<T>& b); |
|
96 |
|
97 friend MDiagArray2<T> |
|
98 product (const MDiagArray2<T>& a, const MDiagArray2<T>& b); |
|
99 |
|
100 friend MDiagArray2<T> operator - (const MDiagArray2<T>& a); |
|
101 }; |
|
102 |
|
103 #define INSTANTIATE_MDIAGARRAY_FRIENDS(T) \ |
1992
|
104 template MDiagArray2<T>& operator += (MDiagArray2<T>& a, const MDiagArray2<T>& b); \ |
|
105 template MDiagArray2<T>& operator -= (MDiagArray2<T>& a, const MDiagArray2<T>& b); \ |
1988
|
106 template MDiagArray2<T> operator * (const MDiagArray2<T>& a, const T& s); \ |
|
107 template MDiagArray2<T> operator / (const MDiagArray2<T>& a, const T& s); \ |
|
108 template MDiagArray2<T> operator * (const T& s, const MDiagArray2<T>& a); \ |
|
109 template MDiagArray2<T> operator + (const MDiagArray2<T>& a, const MDiagArray2<T>& b); \ |
|
110 template MDiagArray2<T> operator - (const MDiagArray2<T>& a, const MDiagArray2<T>& b); \ |
|
111 template MDiagArray2<T> product (const MDiagArray2<T>& a, const MDiagArray2<T>& b); \ |
|
112 template MDiagArray2<T> operator - (const MDiagArray2<T>& a); |
|
113 |
|
114 #endif |
|
115 |
|
116 /* |
|
117 ;;; Local Variables: *** |
|
118 ;;; mode: C++ *** |
|
119 ;;; End: *** |
|
120 */ |