1988
|
1 /* |
|
2 |
|
3 Copyright (C) 1996 John W. Eaton |
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #if defined (__GNUG__) |
|
24 #pragma implementation |
|
25 #endif |
|
26 |
|
27 #ifdef HAVE_CONFIG_H |
|
28 #include <config.h> |
|
29 #endif |
|
30 |
|
31 #include "MDiagArray2.h" |
|
32 #include "lo-error.h" |
|
33 |
|
34 #include "MArray-defs.h" |
|
35 |
|
36 // Two dimensional diagonal array with math ops. |
|
37 |
|
38 // Element by element MDiagArray2 by MDiagArray2 ops. |
|
39 |
|
40 template <class T> |
|
41 MDiagArray2<T>& |
|
42 operator += (MDiagArray2<T>& a, const MDiagArray2<T>& b) |
|
43 { |
|
44 int r = a.rows (); |
|
45 int c = a.cols (); |
|
46 if (r != b.rows () || c != b.cols ()) |
|
47 { |
|
48 (*current_liboctave_error_handler) |
|
49 ("nonconformant array operator += attempted"); |
2006
|
50 static MDiagArray2<T> foo; |
|
51 return foo; |
1988
|
52 } |
|
53 else |
|
54 { |
|
55 int l = a.length (); |
|
56 DO_VV_OP2 (+=); |
|
57 } |
|
58 return a; |
|
59 } |
|
60 |
|
61 template <class T> |
|
62 MDiagArray2<T>& |
|
63 operator -= (MDiagArray2<T>& a, const MDiagArray2<T>& b) |
|
64 { |
|
65 int r = a.rows (); |
|
66 int c = a.cols (); |
|
67 if (r != b.rows () || c != b.cols ()) |
|
68 { |
|
69 (*current_liboctave_error_handler) |
|
70 ("nonconformant array operator -= attempted"); |
2006
|
71 static MDiagArray2<T> foo; |
|
72 return foo; |
1988
|
73 } |
|
74 else |
|
75 { |
|
76 int l = a.length (); |
|
77 DO_VV_OP2 (-=); |
|
78 } |
|
79 return a; |
|
80 } |
|
81 |
|
82 // Element by element MDiagArray2 by scalar ops. |
|
83 |
|
84 #define MARRAY_DAS_OP(OP) \ |
|
85 template <class T> \ |
|
86 MDiagArray2<T> \ |
|
87 operator OP (const MDiagArray2<T>& a, const T& s) \ |
|
88 { \ |
|
89 DO_VS_OP (OP); \ |
|
90 return MDiagArray2<T> (result, a.rows (), a.cols ()); \ |
|
91 } |
|
92 |
|
93 MARRAY_DAS_OP (*) |
|
94 MARRAY_DAS_OP (/) |
|
95 |
|
96 // Element by element scalar by MDiagArray2 ops. |
|
97 |
|
98 template <class T> |
|
99 MDiagArray2<T> |
|
100 operator * (const T& s, const MDiagArray2<T>& a) |
|
101 { |
|
102 DO_SV_OP (*); |
|
103 return MDiagArray2<T> (result, a.rows (), a.cols ()); |
|
104 } |
|
105 |
|
106 // Element by element MDiagArray2 by MDiagArray2 ops. |
|
107 |
|
108 #define MARRAY_DADA_OP(FCN, OP, OP_STR) \ |
|
109 template <class T> \ |
|
110 MDiagArray2<T> \ |
|
111 FCN (const MDiagArray2<T>& a, const MDiagArray2<T>& b) \ |
|
112 { \ |
|
113 int r = a.rows (); \ |
|
114 int c = a.cols (); \ |
|
115 if (r != b.rows () || c != b.cols ()) \ |
|
116 { \ |
|
117 (*current_liboctave_error_handler) \ |
|
118 ("nonconformant diagonal array " OP_STR " attempted"); \ |
|
119 return MDiagArray2<T> (); \ |
|
120 } \ |
|
121 if (c == 0 || r == 0) \ |
|
122 return MDiagArray2<T> (); \ |
|
123 int l = a.length (); \ |
|
124 DO_VV_OP (OP); \ |
|
125 return MDiagArray2<T> (result, r, c); \ |
|
126 } |
|
127 |
|
128 MARRAY_DADA_OP (operator +, +, "addition") |
|
129 MARRAY_DADA_OP (operator -, -, "subtraction") |
|
130 MARRAY_DADA_OP (product, *, "product") |
|
131 |
|
132 // Unary MDiagArray2 ops. |
|
133 |
|
134 template <class T> |
|
135 MDiagArray2<T> |
|
136 operator - (const MDiagArray2<T>& a) |
|
137 { |
|
138 NEG_V; |
|
139 return MDiagArray2<T> (result, a.rows (), a.cols ()); |
|
140 } |
|
141 |
|
142 /* |
|
143 ;;; Local Variables: *** |
|
144 ;;; mode: C++ *** |
|
145 ;;; End: *** |
|
146 */ |