comparison libinterp/operators/op-dm-scm.cc @ 15195:2fc554ffbc28

split libinterp from src * libinterp: New directory. Move all files from src directory here except Makefile.am, main.cc, main-cli.cc, mkoctfile.in.cc, mkoctfilr.in.sh, octave-config.in.cc, octave-config.in.sh. * libinterp/Makefile.am: New file, extracted from src/Makefile.am. * src/Makefile.am: Delete everything except targets and definitions needed to build and link main and utility programs. * Makefile.am (SUBDIRS): Include libinterp in the list. * autogen.sh: Run config-module.sh in libinterp/dldfcn directory, not src/dldfcn directory. * configure.ac (AC_CONFIG_SRCDIR): Use libinterp/octave.cc, not src/octave.cc. (DL_LDFLAGS, LIBOCTINTERP): Use libinterp, not src. (AC_CONFIG_FILES): Include libinterp/Makefile in the list. * find-docstring-files.sh: Look in libinterp, not src. * gui/src/Makefile.am (liboctgui_la_CPPFLAGS): Find header files in libinterp, not src.
author John W. Eaton <jwe@octave.org>
date Sat, 18 Aug 2012 16:23:39 -0400
parents src/operators/op-dm-scm.cc@46b19589b593
children d63878346099
comparison
equal deleted inserted replaced
15194:0f0b795044c3 15195:2fc554ffbc28
1 /*
2
3 Copyright (C) 2009-2012 Jason Riedy, Jaroslav Hajek
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 3 of the License, or (at your
10 option) any 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, see
19 <http://www.gnu.org/licenses/>.
20
21 */
22
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26
27 #include "gripes.h"
28 #include "oct-obj.h"
29 #include "ov.h"
30 #include "ov-typeinfo.h"
31 #include "ops.h"
32
33 #include "ov-re-diag.h"
34 #include "ov-cx-diag.h"
35 #include "ov-re-sparse.h"
36 #include "ov-cx-sparse.h"
37
38 #include "sparse-xdiv.h"
39
40 // diagonal matrix by sparse matrix ops
41
42 DEFBINOP (mul_dm_scm, diag_matrix, sparse_complex_matrix)
43 {
44 CAST_BINOP_ARGS (const octave_diag_matrix&, const octave_sparse_complex_matrix&);
45
46 if (v2.rows () == 1 && v2.columns () == 1)
47 // If v2 is a scalar in disguise, return a diagonal matrix rather than
48 // a sparse matrix.
49 {
50 std::complex<double> d = v2.complex_value ();
51
52 return octave_value (v1.diag_matrix_value () * d);
53 }
54 else
55 {
56 MatrixType typ = v2.matrix_type ();
57 SparseComplexMatrix ret = v1.diag_matrix_value () * v2.sparse_complex_matrix_value ();
58 octave_value out = octave_value (ret);
59 typ.mark_as_unsymmetric ();
60 out.matrix_type (typ);
61 return out;
62 }
63 }
64
65 DEFBINOP (mul_cdm_sm, complex_diag_matrix, sparse_matrix)
66 {
67 CAST_BINOP_ARGS (const octave_complex_diag_matrix&, const octave_sparse_matrix&);
68
69 if (v2.rows () == 1 && v2.columns () == 1)
70 // If v2 is a scalar in disguise, return a diagonal matrix rather than
71 // a sparse matrix.
72 {
73 std::complex<double> d = v2.scalar_value ();
74
75 return octave_value (v1.complex_diag_matrix_value () * d);
76 }
77 else
78 {
79 MatrixType typ = v2.matrix_type ();
80 SparseComplexMatrix ret = v1.complex_diag_matrix_value () * v2.sparse_matrix_value ();
81 octave_value out = octave_value (ret);
82 typ.mark_as_unsymmetric ();
83 out.matrix_type (typ);
84 return out;
85 }
86 }
87
88 DEFBINOP (mul_cdm_scm, complex_diag_matrix, sparse_complex_matrix)
89 {
90 CAST_BINOP_ARGS (const octave_complex_diag_matrix&, const octave_sparse_complex_matrix&);
91
92 if (v2.rows () == 1 && v2.columns () == 1)
93 // If v2 is a scalar in disguise, return a diagonal matrix rather than
94 // a sparse matrix.
95 {
96 std::complex<double> d = v2.complex_value ();
97
98 return octave_value (v1.complex_diag_matrix_value () * d);
99 }
100 else
101 {
102 MatrixType typ = v2.matrix_type ();
103 SparseComplexMatrix ret = v1.complex_diag_matrix_value () * v2.sparse_complex_matrix_value ();
104 octave_value out = octave_value (ret);
105 typ.mark_as_unsymmetric ();
106 out.matrix_type (typ);
107 return out;
108 }
109 }
110
111 DEFBINOP (ldiv_dm_scm, diag_matrix, sparse_complex_matrix)
112 {
113 CAST_BINOP_ARGS (const octave_diag_matrix&,
114 const octave_sparse_complex_matrix&);
115
116 MatrixType typ = v2.matrix_type ();
117 return xleftdiv (v1.diag_matrix_value (), v2.sparse_complex_matrix_value (),
118 typ);
119 }
120
121 DEFBINOP (ldiv_cdm_sm, complex_diag_matrix, sparse_matrix)
122 {
123 CAST_BINOP_ARGS (const octave_complex_diag_matrix&,
124 const octave_sparse_matrix&);
125
126 MatrixType typ = v2.matrix_type ();
127 return xleftdiv (v1.complex_diag_matrix_value (), v2.sparse_matrix_value (),
128 typ);
129 }
130
131 DEFBINOP (ldiv_cdm_scm, complex_diag_matrix, sparse_complex_matrix)
132 {
133 CAST_BINOP_ARGS (const octave_complex_diag_matrix&,
134 const octave_sparse_complex_matrix&);
135
136 MatrixType typ = v2.matrix_type ();
137 return xleftdiv (v1.complex_diag_matrix_value (), v2.sparse_complex_matrix_value (),
138 typ);
139 }
140
141 DEFBINOP (add_dm_scm, diag_matrix, sparse_complex_matrix)
142 {
143 CAST_BINOP_ARGS (const octave_diag_matrix&, const octave_sparse_complex_matrix&);
144
145 if (v2.rows () == 1 && v2.columns () == 1)
146 // If v2 is a scalar in disguise, return a diagonal matrix rather than
147 // a sparse matrix.
148 {
149 std::complex<double> d = v2.complex_value ();
150
151 return octave_value (v1.matrix_value () + d);
152 }
153 else
154 return v1.diag_matrix_value () + v2.sparse_complex_matrix_value ();
155 }
156
157 DEFBINOP (add_cdm_sm, complex_diag_matrix, sparse_matrix)
158 {
159 CAST_BINOP_ARGS (const octave_complex_diag_matrix&, const octave_sparse_matrix&);
160
161 if (v2.rows () == 1 && v2.columns () == 1)
162 // If v2 is a scalar in disguise, return a diagonal matrix rather than
163 // a sparse matrix.
164 {
165 double d = v2.scalar_value ();
166
167 return octave_value (v1.complex_matrix_value () + d);
168 }
169 else
170 return v1.complex_diag_matrix_value () + v2.sparse_matrix_value ();
171 }
172
173 DEFBINOP (add_cdm_scm, complex_diag_matrix, sparse_complex_matrix)
174 {
175 CAST_BINOP_ARGS (const octave_complex_diag_matrix&, const octave_sparse_complex_matrix&);
176
177 if (v2.rows () == 1 && v2.columns () == 1)
178 // If v2 is a scalar in disguise, return a diagonal matrix rather than
179 // a sparse matrix.
180 {
181 std::complex<double> d = v2.complex_value ();
182
183 return octave_value (v1.complex_matrix_value () + d);
184 }
185 else
186 return v1.complex_diag_matrix_value () + v2.sparse_complex_matrix_value ();
187 }
188
189 DEFBINOP (sub_dm_scm, diag_matrix, sparse_complex_matrix)
190 {
191 CAST_BINOP_ARGS (const octave_diag_matrix&, const octave_sparse_complex_matrix&);
192
193 if (v2.rows () == 1 && v2.columns () == 1)
194 // If v2 is a scalar in disguise, return a diagonal matrix rather than
195 // a sparse matrix.
196 {
197 std::complex<double> d = v2.complex_value ();
198
199 return octave_value (v1.matrix_value () + (-d));
200 }
201 else
202 return v1.diag_matrix_value () - v2.sparse_complex_matrix_value ();
203 }
204
205 DEFBINOP (sub_cdm_sm, complex_diag_matrix, sparse_matrix)
206 {
207 CAST_BINOP_ARGS (const octave_complex_diag_matrix&, const octave_sparse_matrix&);
208
209 if (v2.rows () == 1 && v2.columns () == 1)
210 // If v2 is a scalar in disguise, return a diagonal matrix rather than
211 // a sparse matrix.
212 {
213 double d = v2.scalar_value ();
214
215 return octave_value (v1.complex_matrix_value () + (-d));
216 }
217 else
218 return v1.complex_diag_matrix_value () - v2.sparse_matrix_value ();
219 }
220
221 DEFBINOP (sub_cdm_scm, complex_diag_matrix, sparse_complex_matrix)
222 {
223 CAST_BINOP_ARGS (const octave_complex_diag_matrix&, const octave_sparse_complex_matrix&);
224
225 if (v2.rows () == 1 && v2.columns () == 1)
226 // If v2 is a scalar in disguise, return a diagonal matrix rather than
227 // a sparse matrix.
228 {
229 std::complex<double> d = v2.complex_value ();
230
231 return octave_value (v1.complex_matrix_value () + (-d));
232 }
233 else
234 return v1.complex_diag_matrix_value () - v2.sparse_complex_matrix_value ();
235 }
236
237 // sparse matrix by diagonal matrix ops
238
239 DEFBINOP (mul_scm_dm, sparse_complex_matrix, diag_matrix)
240 {
241 CAST_BINOP_ARGS (const octave_sparse_complex_matrix&, const octave_diag_matrix&);
242
243 if (v1.rows () == 1 && v1.columns () == 1)
244 // If v1 is a scalar in disguise, return a diagonal matrix rather than
245 // a sparse matrix.
246 {
247 std::complex<double> d = v1.complex_value ();
248
249 return octave_value (d * v2.diag_matrix_value ());
250 }
251 else
252 {
253 MatrixType typ = v1.matrix_type ();
254 SparseComplexMatrix ret = v1.sparse_complex_matrix_value () * v2.diag_matrix_value ();
255 octave_value out = octave_value (ret);
256 typ.mark_as_unsymmetric ();
257 out.matrix_type (typ);
258 return out;
259 }
260 }
261
262 DEFBINOP (mul_sm_cdm, sparse_matrix, complex_diag_matrix)
263 {
264 CAST_BINOP_ARGS (const octave_sparse_matrix&, const octave_complex_diag_matrix&);
265
266 if (v1.rows () == 1 && v1.columns () == 1)
267 // If v1 is a scalar in disguise, return a diagonal matrix rather than
268 // a sparse matrix.
269 {
270 std::complex<double> d = v1.complex_value ();
271
272 return octave_value (d * v2.complex_diag_matrix_value ());
273 }
274 else
275 {
276 MatrixType typ = v1.matrix_type ();
277 SparseComplexMatrix ret = v1.sparse_matrix_value () * v2.complex_diag_matrix_value ();
278 octave_value out = octave_value (ret);
279 typ.mark_as_unsymmetric ();
280 out.matrix_type (typ);
281 return out;
282 }
283 }
284
285 DEFBINOP (mul_scm_cdm, sparse_complex_matrix, complex_diag_matrix)
286 {
287 CAST_BINOP_ARGS (const octave_sparse_complex_matrix&, const octave_complex_diag_matrix&);
288
289 if (v1.rows () == 1 && v1.columns () == 1)
290 // If v1 is a scalar in disguise, return a diagonal matrix rather than
291 // a sparse matrix.
292 {
293 std::complex<double> d = v1.complex_value ();
294
295 return octave_value (d * v2.complex_diag_matrix_value ());
296 }
297 else if (v2.rows () == 1 && v2.columns () == 1)
298 // If v2 is a scalar in disguise, don't bother with further dispatching.
299 {
300 std::complex<double> d = v2.complex_value ();
301
302 return octave_value (v1.sparse_complex_matrix_value () * d);
303 }
304 else
305 {
306 MatrixType typ = v1.matrix_type ();
307 SparseComplexMatrix ret = v1.sparse_complex_matrix_value () * v2.complex_diag_matrix_value ();
308 octave_value out = octave_value (ret);
309 typ.mark_as_unsymmetric ();
310 out.matrix_type (typ);
311 return out;
312 }
313 }
314
315 DEFBINOP (div_scm_dm, sparse_complex_matrix, diag_matrix)
316 {
317 CAST_BINOP_ARGS (const octave_sparse_complex_matrix&, const octave_diag_matrix&);
318
319 if (v2.rows () == 1 && v2.columns () == 1)
320 {
321 double d = v2.scalar_value ();
322
323 if (d == 0.0)
324 gripe_divide_by_zero ();
325
326 return octave_value (v1.sparse_complex_matrix_value () / d);
327 }
328 else
329 {
330 MatrixType typ = v2.matrix_type ();
331 return xdiv (v1.sparse_complex_matrix_value (), v2.diag_matrix_value (), typ);
332 }
333 }
334
335 DEFBINOP (div_sm_cdm, sparse_matrix, complex_diag_matrix)
336 {
337 CAST_BINOP_ARGS (const octave_sparse_matrix&, const octave_complex_diag_matrix&);
338
339 if (v2.rows () == 1 && v2.columns () == 1)
340 {
341 std::complex<double> d = v2.complex_value ();
342
343 if (d == 0.0)
344 gripe_divide_by_zero ();
345
346 return octave_value (v1.sparse_matrix_value () / d);
347 }
348 else
349 {
350 MatrixType typ = v2.matrix_type ();
351 return xdiv (v1.sparse_matrix_value (), v2.complex_diag_matrix_value (), typ);
352 }
353 }
354
355 DEFBINOP (div_scm_cdm, sparse_complex_matrix, complex_diag_matrix)
356 {
357 CAST_BINOP_ARGS (const octave_sparse_complex_matrix&, const octave_complex_diag_matrix&);
358
359 if (v2.rows () == 1 && v2.columns () == 1)
360 {
361 std::complex<double> d = v2.complex_value ();
362
363 if (d == 0.0)
364 gripe_divide_by_zero ();
365
366 return octave_value (v1.sparse_complex_matrix_value () / d);
367 }
368 else
369 {
370 MatrixType typ = v2.matrix_type ();
371 return xdiv (v1.sparse_complex_matrix_value (), v2.complex_diag_matrix_value (), typ);
372 }
373 }
374
375 DEFBINOP (add_sm_cdm, sparse_matrix, complex_diag_matrix)
376 {
377 CAST_BINOP_ARGS (const octave_sparse_matrix&, const octave_complex_diag_matrix&);
378
379 if (v2.rows () == 1 && v2.columns () == 1)
380 // If v2 is a scalar in disguise, return a diagonal matrix rather than
381 // a sparse matrix.
382 {
383 std::complex<double> d = v2.complex_value ();
384
385 return octave_value (v1.sparse_matrix_value () + d);
386 }
387 else
388 return v1.sparse_matrix_value () + v2.complex_diag_matrix_value ();
389 }
390
391 DEFBINOP (add_scm_dm, sparse_complex_matrix, diag_matrix)
392 {
393 CAST_BINOP_ARGS (const octave_sparse_complex_matrix&, const octave_diag_matrix&);
394
395 if (v2.rows () == 1 && v2.columns () == 1)
396 // If v2 is a scalar in disguise, return a diagonal matrix rather than
397 // a sparse matrix.
398 {
399 double d = v2.scalar_value ();
400
401 return octave_value (v1.sparse_complex_matrix_value () + d);
402 }
403 else
404 return v1.sparse_complex_matrix_value () + v2.diag_matrix_value ();
405 }
406
407 DEFBINOP (add_scm_cdm, sparse_complex_matrix, complex_diag_matrix)
408 {
409 CAST_BINOP_ARGS (const octave_sparse_complex_matrix&, const octave_complex_diag_matrix&);
410
411 if (v2.rows () == 1 && v2.columns () == 1)
412 // If v2 is a scalar in disguise, return a diagonal matrix rather than
413 // a sparse matrix.
414 {
415 std::complex<double> d = v2.complex_value ();
416
417 return octave_value (v1.sparse_complex_matrix_value () + d);
418 }
419 else
420 return v1.sparse_complex_matrix_value () + v2.complex_diag_matrix_value ();
421 }
422
423 DEFBINOP (sub_sm_cdm, sparse_matrix, complex_diag_matrix)
424 {
425 CAST_BINOP_ARGS (const octave_sparse_matrix&, const octave_complex_diag_matrix&);
426
427 if (v2.rows () == 1 && v2.columns () == 1)
428 // If v2 is a scalar in disguise, return a diagonal matrix rather than
429 // a sparse matrix.
430 {
431 std::complex<double> d = v2.complex_value ();
432
433 return octave_value (v1.sparse_matrix_value () + (-d));
434 }
435 else
436 return v1.sparse_matrix_value () - v2.complex_diag_matrix_value ();
437 }
438
439 DEFBINOP (sub_scm_dm, sparse_complex_matrix, diag_matrix)
440 {
441 CAST_BINOP_ARGS (const octave_sparse_complex_matrix&, const octave_diag_matrix&);
442
443 if (v2.rows () == 1 && v2.columns () == 1)
444 // If v2 is a scalar in disguise, return a diagonal matrix rather than
445 // a sparse matrix.
446 {
447 double d = v2.scalar_value ();
448
449 return octave_value (v1.sparse_complex_matrix_value () + (-d));
450 }
451 else
452 return v1.sparse_complex_matrix_value () - v2.diag_matrix_value ();
453 }
454
455 DEFBINOP (sub_scm_cdm, sparse_complex_matrix, complex_diag_matrix)
456 {
457 CAST_BINOP_ARGS (const octave_sparse_complex_matrix&, const octave_complex_diag_matrix&);
458
459 if (v2.rows () == 1 && v2.columns () == 1)
460 // If v2 is a scalar in disguise, return a diagonal matrix rather than
461 // a sparse matrix.
462 {
463 std::complex<double> d = v2.complex_value ();
464
465 return octave_value (v1.sparse_complex_matrix_value () + (-d));
466 }
467 else
468 return v1.sparse_complex_matrix_value () - v2.complex_diag_matrix_value ();
469 }
470
471 void
472 install_dm_scm_ops (void)
473 {
474 INSTALL_BINOP (op_mul, octave_diag_matrix, octave_sparse_complex_matrix,
475 mul_dm_scm);
476 INSTALL_BINOP (op_mul, octave_complex_diag_matrix, octave_sparse_matrix,
477 mul_cdm_sm);
478 INSTALL_BINOP (op_mul, octave_complex_diag_matrix, octave_sparse_complex_matrix,
479 mul_cdm_scm);
480 INSTALL_BINOP (op_ldiv, octave_diag_matrix, octave_sparse_complex_matrix, ldiv_dm_scm);
481 INSTALL_BINOP (op_ldiv, octave_complex_diag_matrix, octave_sparse_matrix, ldiv_cdm_sm);
482 INSTALL_BINOP (op_ldiv, octave_complex_diag_matrix, octave_sparse_complex_matrix,
483 ldiv_cdm_scm);
484
485 INSTALL_BINOP (op_add, octave_diag_matrix, octave_sparse_complex_matrix, add_dm_scm);
486 INSTALL_BINOP (op_add, octave_complex_diag_matrix, octave_sparse_matrix, add_cdm_sm);
487 INSTALL_BINOP (op_add, octave_complex_diag_matrix, octave_sparse_complex_matrix,
488 add_cdm_scm);
489 INSTALL_BINOP (op_sub, octave_diag_matrix, octave_sparse_complex_matrix, sub_dm_scm);
490 INSTALL_BINOP (op_sub, octave_complex_diag_matrix, octave_sparse_matrix, sub_cdm_sm);
491 INSTALL_BINOP (op_sub, octave_complex_diag_matrix, octave_sparse_complex_matrix,
492 sub_cdm_scm);
493
494 INSTALL_BINOP (op_mul, octave_sparse_complex_matrix, octave_diag_matrix,
495 mul_scm_dm);
496 INSTALL_BINOP (op_mul, octave_sparse_matrix, octave_complex_diag_matrix,
497 mul_sm_cdm);
498 INSTALL_BINOP (op_mul, octave_sparse_complex_matrix, octave_complex_diag_matrix,
499 mul_scm_cdm);
500
501 INSTALL_BINOP (op_div, octave_sparse_complex_matrix, octave_diag_matrix, div_scm_dm);
502 INSTALL_BINOP (op_div, octave_sparse_matrix, octave_complex_diag_matrix, div_sm_cdm);
503 INSTALL_BINOP (op_div, octave_sparse_complex_matrix, octave_complex_diag_matrix, div_scm_cdm);
504
505 INSTALL_BINOP (op_add, octave_sparse_complex_matrix, octave_diag_matrix, add_scm_dm);
506 INSTALL_BINOP (op_add, octave_sparse_matrix, octave_complex_diag_matrix, add_sm_cdm);
507 INSTALL_BINOP (op_add, octave_sparse_complex_matrix, octave_complex_diag_matrix, add_scm_cdm);
508 INSTALL_BINOP (op_sub, octave_sparse_complex_matrix, octave_diag_matrix, sub_scm_dm);
509 INSTALL_BINOP (op_sub, octave_sparse_matrix, octave_complex_diag_matrix, sub_sm_cdm);
510 INSTALL_BINOP (op_sub, octave_sparse_complex_matrix, octave_complex_diag_matrix, sub_scm_cdm);
511 }