3
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
3
|
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 |
1315
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
3
|
20 |
|
21 */ |
|
22 |
2828
|
23 #if !defined (octave_mx_inlines_h) |
|
24 #define octave_mx_inlines_h 1 |
2804
|
25 |
|
26 #include <cstddef> |
|
27 |
1650
|
28 #include "oct-cmplx.h" |
461
|
29 |
2811
|
30 #define VS_OP_FCN(F, OP) \ |
|
31 template <class R, class V, class S> \ |
3262
|
32 inline void \ |
2811
|
33 F ## _vs (R *r, const V *v, size_t n, S s) \ |
|
34 { \ |
|
35 for (size_t i = 0; i < n; i++) \ |
|
36 r[i] = v[i] OP s; \ |
|
37 } |
|
38 |
3769
|
39 VS_OP_FCN (mx_inline_add, +) |
|
40 VS_OP_FCN (mx_inline_subtract, -) |
|
41 VS_OP_FCN (mx_inline_multiply, *) |
|
42 VS_OP_FCN (mx_inline_divide, /) |
3
|
43 |
2804
|
44 #define VS_OP(F, OP, R, V, S) \ |
|
45 static inline R * \ |
|
46 F (const V *v, size_t n, S s) \ |
|
47 { \ |
|
48 R *r = 0; \ |
|
49 if (n > 0) \ |
|
50 { \ |
|
51 r = new R [n]; \ |
2811
|
52 F ## _vs (r, v, n, s); \ |
2804
|
53 } \ |
|
54 return r; \ |
|
55 } |
3
|
56 |
2804
|
57 #define VS_OPS(R, V, S) \ |
3769
|
58 VS_OP (mx_inline_add, +, R, V, S) \ |
|
59 VS_OP (mx_inline_subtract, -, R, V, S) \ |
|
60 VS_OP (mx_inline_multiply, *, R, V, S) \ |
|
61 VS_OP (mx_inline_divide, /, R, V, S) |
3
|
62 |
2804
|
63 VS_OPS (double, double, double) |
|
64 VS_OPS (Complex, double, Complex) |
|
65 VS_OPS (Complex, Complex, double) |
|
66 VS_OPS (Complex, Complex, Complex) |
3
|
67 |
2811
|
68 #define SV_OP_FCN(F, OP) \ |
|
69 template <class R, class S, class V> \ |
3262
|
70 inline void \ |
2811
|
71 F ## _sv (R *r, S s, const V *v, size_t n) \ |
|
72 { \ |
|
73 for (size_t i = 0; i < n; i++) \ |
|
74 r[i] = s OP v[i]; \ |
|
75 } \ |
|
76 |
3769
|
77 SV_OP_FCN (mx_inline_add, +) |
|
78 SV_OP_FCN (mx_inline_subtract, -) |
|
79 SV_OP_FCN (mx_inline_multiply, *) |
|
80 SV_OP_FCN (mx_inline_divide, /) |
2811
|
81 |
2804
|
82 #define SV_OP(F, OP, R, S, V) \ |
|
83 static inline R * \ |
|
84 F (S s, const V *v, size_t n) \ |
|
85 { \ |
|
86 R *r = 0; \ |
|
87 if (n > 0) \ |
|
88 { \ |
|
89 r = new R [n]; \ |
2811
|
90 F ## _sv (r, s, v, n); \ |
2804
|
91 } \ |
|
92 return r; \ |
|
93 } |
3
|
94 |
2804
|
95 #define SV_OPS(R, S, V) \ |
3769
|
96 SV_OP (mx_inline_add, +, R, S, V) \ |
|
97 SV_OP (mx_inline_subtract, -, R, S, V) \ |
|
98 SV_OP (mx_inline_multiply, *, R, S, V) \ |
|
99 SV_OP (mx_inline_divide, /, R, S, V) |
3
|
100 |
2804
|
101 SV_OPS (double, double, double) |
|
102 SV_OPS (Complex, double, Complex) |
|
103 SV_OPS (Complex, Complex, double) |
|
104 SV_OPS (Complex, Complex, Complex) |
3
|
105 |
2811
|
106 #define VV_OP_FCN(F, OP) \ |
|
107 template <class R, class T1, class T2> \ |
3262
|
108 inline void \ |
2811
|
109 F ## _vv (R *r, const T1 *v1, const T2 *v2, size_t n) \ |
|
110 { \ |
|
111 for (size_t i = 0; i < n; i++) \ |
|
112 r[i] = v1[i] OP v2[i]; \ |
|
113 } \ |
|
114 |
3769
|
115 VV_OP_FCN (mx_inline_add, +) |
|
116 VV_OP_FCN (mx_inline_subtract, -) |
|
117 VV_OP_FCN (mx_inline_multiply, *) |
|
118 VV_OP_FCN (mx_inline_divide, /) |
2811
|
119 |
2804
|
120 #define VV_OP(F, OP, R, T1, T2) \ |
|
121 static inline R * \ |
|
122 F (const T1 *v1, const T2 *v2, size_t n) \ |
|
123 { \ |
|
124 R *r = 0; \ |
|
125 if (n > 0) \ |
|
126 { \ |
|
127 r = new R [n]; \ |
2811
|
128 F ## _vv (r, v1, v2, n); \ |
2804
|
129 } \ |
|
130 return r; \ |
|
131 } |
3
|
132 |
2804
|
133 #define VV_OPS(R, T1, T2) \ |
3769
|
134 VV_OP (mx_inline_add, +, R, T1, T2) \ |
|
135 VV_OP (mx_inline_subtract, -, R, T1, T2) \ |
|
136 VV_OP (mx_inline_multiply, *, R, T1, T2) \ |
|
137 VV_OP (mx_inline_divide, /, R, T1, T2) |
3
|
138 |
2804
|
139 VV_OPS (double, double, double) |
|
140 VV_OPS (Complex, double, Complex) |
|
141 VV_OPS (Complex, Complex, double) |
|
142 VV_OPS (Complex, Complex, Complex) |
3
|
143 |
2804
|
144 #define VS_OP2(F, OP, V, S) \ |
|
145 static inline V * \ |
|
146 F (V *v, size_t n, S s) \ |
|
147 { \ |
|
148 for (size_t i = 0; i < n; i++) \ |
|
149 v[i] OP s; \ |
|
150 return v; \ |
|
151 } |
3
|
152 |
2804
|
153 #define VS_OP2S(V, S) \ |
3769
|
154 VS_OP2 (mx_inline_add2, +=, V, S) \ |
|
155 VS_OP2 (mx_inline_subtract2, -=, V, S) \ |
|
156 VS_OP2 (mx_inline_multiply2, *=, V, S) \ |
|
157 VS_OP2 (mx_inline_divide2, /=, V, S) \ |
|
158 VS_OP2 (mx_inline_copy, =, V, S) |
3
|
159 |
2804
|
160 VS_OP2S (double, double) |
|
161 VS_OP2S (Complex, double) |
|
162 VS_OP2S (Complex, Complex) |
3
|
163 |
2804
|
164 #define VV_OP2(F, OP, T1, T2) \ |
|
165 static inline T1 * \ |
|
166 F (T1 *v1, const T2 *v2, size_t n) \ |
|
167 { \ |
|
168 for (size_t i = 0; i < n; i++) \ |
|
169 v1[i] OP v2[i]; \ |
|
170 return v1; \ |
|
171 } |
3
|
172 |
2804
|
173 #define VV_OP2S(T1, T2) \ |
3769
|
174 VV_OP2 (mx_inline_add2, +=, T1, T2) \ |
|
175 VV_OP2 (mx_inline_subtract2, -=, T1, T2) \ |
|
176 VV_OP2 (mx_inline_multiply2, *=, T1, T2) \ |
|
177 VV_OP2 (mx_inline_divide2, /=, T1, T2) \ |
|
178 VV_OP2 (mx_inline_copy, =, T1, T2) |
3
|
179 |
2804
|
180 VV_OP2S (double, double) |
|
181 VV_OP2S (Complex, double) |
|
182 VV_OP2S (Complex, Complex) |
3
|
183 |
2804
|
184 #define OP_EQ_FCN(T1, T2) \ |
|
185 static inline bool \ |
3769
|
186 mx_inline_equal (const T1 *x, const T2 *y, size_t n) \ |
2804
|
187 { \ |
|
188 for (size_t i = 0; i < n; i++) \ |
|
189 if (x[i] != y[i]) \ |
|
190 return false; \ |
|
191 return true; \ |
|
192 } |
3
|
193 |
2828
|
194 OP_EQ_FCN (bool, bool) |
2804
|
195 OP_EQ_FCN (char, char) |
|
196 OP_EQ_FCN (double, double) |
|
197 OP_EQ_FCN (Complex, Complex) |
3
|
198 |
2804
|
199 #define OP_DUP_FCN(OP, F, R, T) \ |
|
200 static inline R * \ |
|
201 F (const T *x, size_t n) \ |
|
202 { \ |
|
203 R *r = 0; \ |
|
204 if (n > 0) \ |
|
205 { \ |
|
206 r = new R [n]; \ |
|
207 for (size_t i = 0; i < n; i++) \ |
|
208 r[i] = OP (x[i]); \ |
|
209 } \ |
|
210 return r; \ |
|
211 } |
3
|
212 |
3769
|
213 OP_DUP_FCN (, mx_inline_dup, double, double) |
|
214 OP_DUP_FCN (, mx_inline_dup, Complex, Complex) |
3
|
215 |
2804
|
216 // These should really return a bool *. Also, they should probably be |
|
217 // in with a collection of other element-by-element boolean ops. |
3769
|
218 OP_DUP_FCN (0.0 ==, mx_inline_not, double, double) |
|
219 OP_DUP_FCN (0.0 ==, mx_inline_not, double, Complex) |
3
|
220 |
3769
|
221 OP_DUP_FCN (, mx_inline_make_complex, Complex, double) |
2804
|
222 |
3769
|
223 OP_DUP_FCN (-, mx_inline_change_sign, double, double) |
|
224 OP_DUP_FCN (-, mx_inline_change_sign, Complex, Complex) |
3
|
225 |
3769
|
226 OP_DUP_FCN (real, mx_inline_real_dup, double, Complex) |
|
227 OP_DUP_FCN (imag, mx_inline_imag_dup, double, Complex) |
|
228 OP_DUP_FCN (conj, mx_inline_conj_dup, Complex, Complex) |
3
|
229 |
2804
|
230 #endif |
3
|
231 |
|
232 /* |
|
233 ;;; Local Variables: *** |
|
234 ;;; mode: C++ *** |
|
235 ;;; End: *** |
|
236 */ |