Mercurial > octave-nkf
comparison src/DLD-FUNCTIONS/besselj.cc @ 4844:9f7ef92b50b0
[project @ 2004-04-02 17:26:53 by jwe]
author | jwe |
---|---|
date | Fri, 02 Apr 2004 17:26:54 +0000 |
parents | 6b96ce9f5743 |
children | 23b37da9fd5b |
comparison
equal
deleted
inserted
replaced
4843:7b4e76100964 | 4844:9f7ef92b50b0 |
---|---|
95 } | 95 } |
96 | 96 |
97 return retval; | 97 return retval; |
98 } | 98 } |
99 | 99 |
100 static inline NDArray | |
101 int_arrayN_to_array (const ArrayN<int>& a) | |
102 { | |
103 dim_vector dv = a.dims (); | |
104 int nel = dv.numel (); | |
105 | |
106 NDArray retval (dv); | |
107 | |
108 for (int i = 0; i < nel; i++) | |
109 { | |
110 OCTAVE_QUIT; | |
111 | |
112 retval(i) = (double) (a(i)); | |
113 } | |
114 | |
115 return retval; | |
116 } | |
117 | |
100 static void | 118 static void |
101 gripe_bessel_arg (const char *fn, const char *arg) | 119 gripe_bessel_arg (const char *fn, const char *arg) |
102 { | 120 { |
103 error ("%s: expecting scalar or matrix as %s argument", fn, arg); | 121 error ("%s: expecting scalar or matrix as %s argument", fn, arg); |
104 } | 122 } |
143 else | 161 else |
144 gripe_bessel_arg (fn, "second"); | 162 gripe_bessel_arg (fn, "second"); |
145 } | 163 } |
146 else | 164 else |
147 { | 165 { |
148 ComplexMatrix x = x_arg.complex_matrix_value (); | 166 ComplexNDArray x = x_arg.complex_array_value (); |
149 | 167 |
150 if (! error_state) | 168 if (! error_state) |
151 { | 169 { |
152 Array2<int> ierr; | 170 ArrayN<int> ierr; |
153 octave_value result; | 171 octave_value result; |
154 | 172 |
155 DO_BESSEL (type, alpha, x, scaled, ierr, result); | 173 DO_BESSEL (type, alpha, x, scaled, ierr, result); |
156 | 174 |
157 if (nargout > 1) | 175 if (nargout > 1) |
158 retval(1) = int_array2_to_matrix (ierr); | 176 retval(1) = int_arrayN_to_array (ierr); |
159 | 177 |
160 retval(0) = result; | 178 retval(0) = result; |
161 } | 179 } |
162 else | 180 else |
163 gripe_bessel_arg (fn, "second"); | 181 gripe_bessel_arg (fn, "second"); |
166 else | 184 else |
167 gripe_bessel_arg (fn, "first"); | 185 gripe_bessel_arg (fn, "first"); |
168 } | 186 } |
169 else | 187 else |
170 { | 188 { |
171 Matrix alpha = args(0).matrix_value (); | 189 dim_vector dv0 = args(0).dims (); |
172 | 190 dim_vector dv1 = args(1).dims (); |
173 if (! error_state) | 191 |
192 bool args0_is_row_vector = (dv0 (1) == dv0.numel ()); | |
193 bool args1_is_col_vector = (dv1 (0) == dv1.numel ()); | |
194 | |
195 if (args0_is_row_vector && args1_is_col_vector) | |
174 { | 196 { |
175 if (x_arg.is_scalar_type ()) | 197 RowVector ralpha = args(0).row_vector_value (); |
198 | |
199 if (! error_state) | |
176 { | 200 { |
177 Complex x = x_arg.complex_value (); | 201 ComplexColumnVector cx = |
202 x_arg.complex_column_vector_value (); | |
178 | 203 |
179 if (! error_state) | 204 if (! error_state) |
180 { | 205 { |
181 Array2<int> ierr; | 206 Array2<int> ierr; |
182 octave_value result; | 207 octave_value result; |
183 | 208 |
184 DO_BESSEL (type, alpha, x, scaled, ierr, result); | 209 DO_BESSEL (type, ralpha, cx, scaled, ierr, result); |
185 | 210 |
186 if (nargout > 1) | 211 if (nargout > 1) |
187 retval(1) = int_array2_to_matrix (ierr); | 212 retval(1) = int_array2_to_matrix (ierr); |
188 | 213 |
189 retval(0) = result; | 214 retval(0) = result; |
190 } | 215 } |
191 else | 216 else |
192 gripe_bessel_arg (fn, "second"); | 217 gripe_bessel_arg (fn, "second"); |
193 } | 218 } |
194 else | 219 else |
220 gripe_bessel_arg (fn, "first"); | |
221 } | |
222 else | |
223 { | |
224 NDArray alpha = args(0).array_value (); | |
225 | |
226 if (! error_state) | |
195 { | 227 { |
196 ComplexMatrix x = x_arg.complex_matrix_value (); | 228 if (x_arg.is_scalar_type ()) |
197 | |
198 if (! error_state) | |
199 { | 229 { |
200 if (alpha.rows () == 1 && x.columns () == 1) | 230 Complex x = x_arg.complex_value (); |
231 | |
232 if (! error_state) | |
201 { | 233 { |
202 RowVector ralpha = alpha.row (0); | 234 ArrayN<int> ierr; |
203 ComplexColumnVector cx = x.column (0); | |
204 | |
205 Array2<int> ierr; | |
206 octave_value result; | 235 octave_value result; |
207 | 236 |
208 DO_BESSEL (type, ralpha, cx, scaled, ierr, result); | 237 DO_BESSEL (type, alpha, x, scaled, ierr, result); |
209 | 238 |
210 if (nargout > 1) | 239 if (nargout > 1) |
211 retval(1) = int_array2_to_matrix (ierr); | 240 retval(1) = int_arrayN_to_array (ierr); |
212 | 241 |
213 retval(0) = result; | 242 retval(0) = result; |
214 } | 243 } |
215 else | 244 else |
245 gripe_bessel_arg (fn, "second"); | |
246 } | |
247 else | |
248 { | |
249 ComplexNDArray x = x_arg.complex_array_value (); | |
250 | |
251 if (! error_state) | |
216 { | 252 { |
217 Array2<int> ierr; | 253 ArrayN<int> ierr; |
218 octave_value result; | 254 octave_value result; |
219 | 255 |
220 DO_BESSEL (type, alpha, x, scaled, ierr, result); | 256 DO_BESSEL (type, alpha, x, scaled, ierr, result); |
221 | 257 |
222 if (nargout > 1) | 258 if (nargout > 1) |
223 retval(1) = int_array2_to_matrix (ierr); | 259 retval(1) = int_arrayN_to_array (ierr); |
224 | 260 |
225 retval(0) = result; | 261 retval(0) = result; |
226 } | 262 } |
263 else | |
264 gripe_bessel_arg (fn, "second"); | |
227 } | 265 } |
228 else | |
229 gripe_bessel_arg (fn, "second"); | |
230 } | 266 } |
267 else | |
268 gripe_bessel_arg (fn, "first"); | |
231 } | 269 } |
232 else | |
233 gripe_bessel_arg (fn, "first"); | |
234 } | 270 } |
235 } | 271 } |
236 else | 272 else |
237 print_usage (fn); | 273 print_usage (fn); |
238 | 274 |
420 { | 456 { |
421 bool scale = (nargin == 3); | 457 bool scale = (nargin == 3); |
422 | 458 |
423 int kind = 0; | 459 int kind = 0; |
424 | 460 |
425 ComplexMatrix z; | 461 ComplexNDArray z; |
426 | 462 |
427 if (nargin > 1) | 463 if (nargin > 1) |
428 { | 464 { |
429 double d_kind = args(0).double_value (); | 465 double d_kind = args(0).double_value (); |
430 | 466 |
439 error ("airy: expecting integer value for K"); | 475 error ("airy: expecting integer value for K"); |
440 } | 476 } |
441 | 477 |
442 if (! error_state) | 478 if (! error_state) |
443 { | 479 { |
444 z = args(nargin == 1 ? 0 : 1).complex_matrix_value (); | 480 z = args(nargin == 1 ? 0 : 1).complex_array_value (); |
445 | 481 |
446 if (! error_state) | 482 if (! error_state) |
447 { | 483 { |
448 Array2<int> ierr; | 484 ArrayN<int> ierr; |
449 octave_value result; | 485 octave_value result; |
450 | 486 |
451 if (kind > 1) | 487 if (kind > 1) |
452 result = biry (z, kind == 3, scale, ierr); | 488 result = biry (z, kind == 3, scale, ierr); |
453 else | 489 else |
454 result = airy (z, kind == 1, scale, ierr); | 490 result = airy (z, kind == 1, scale, ierr); |
455 | 491 |
456 if (nargout > 1) | 492 if (nargout > 1) |
457 retval(1) = int_array2_to_matrix (ierr); | 493 retval(1) = int_arrayN_to_array (ierr); |
458 | 494 |
459 retval(0) = result; | 495 retval(0) = result; |
460 } | 496 } |
461 else | 497 else |
462 error ("airy: expecting complex matrix for Z"); | 498 error ("airy: expecting complex matrix for Z"); |