annotate libinterp/operators/op-dm-sm.cc @ 20595:c1a6c31ac29a

eliminate more simple uses of error_state * ov-classdef.cc: Eliminate simple uses of error_state.
author John W. Eaton <jwe@octave.org>
date Tue, 06 Oct 2015 00:20:02 -0400
parents 4197fc428c7d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8964
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
1 /*
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
2
19731
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
3 Copyright (C) 2009-2015 Jason Riedy, Jaroslav Hajek
8964
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
4
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
5 This file is part of Octave.
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
6
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
9 Free Software Foundation; either version 3 of the License, or (at your
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
10 option) any later version.
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
11
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
15 for more details.
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
16
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
18 along with Octave; see the file COPYING. If not, see
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
19 <http://www.gnu.org/licenses/>.
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
20
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
21 */
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
22
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
23 #ifdef HAVE_CONFIG_H
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
24 #include <config.h>
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
25 #endif
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
26
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
27 #include "gripes.h"
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
28 #include "oct-obj.h"
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
29 #include "ov.h"
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
30 #include "ov-typeinfo.h"
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
31 #include "ops.h"
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
32
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
33 #include "ov-re-diag.h"
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
34 #include "ov-re-sparse.h"
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
35
8965
42aff15e059b Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
36 #include "sparse-xdiv.h"
42aff15e059b Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
37
8964
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
38 // diagonal matrix by sparse matrix ops
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
39
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
40 DEFBINOP (mul_dm_sm, diag_matrix, sparse_matrix)
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
41 {
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
42 CAST_BINOP_ARGS (const octave_diag_matrix&, const octave_sparse_matrix&);
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
43
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
44 if (v2.rows () == 1 && v2.columns () == 1)
8964
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
45 // If v2 is a scalar in disguise, return a diagonal matrix rather than
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
46 // a sparse matrix.
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
47 {
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
48 double d = v2.scalar_value ();
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
49
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
50 return octave_value (v1.diag_matrix_value () * d);
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
51 }
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
52 else
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
53 {
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
54 MatrixType typ = v2.matrix_type ();
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
55 SparseMatrix ret = v1.diag_matrix_value () * v2.sparse_matrix_value ();
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
56 octave_value out = octave_value (ret);
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
57 typ.mark_as_unsymmetric ();
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
58 out.matrix_type (typ);
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
59 return out;
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
60 }
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
61 }
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
62
8965
42aff15e059b Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
63 DEFBINOP (ldiv_dm_sm, diag_matrix, sparse_matrix)
42aff15e059b Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
64 {
42aff15e059b Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
65 CAST_BINOP_ARGS (const octave_diag_matrix&, const octave_sparse_matrix&);
42aff15e059b Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
66
42aff15e059b Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
67 MatrixType typ = v2.matrix_type ();
42aff15e059b Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
68 return xleftdiv (v1.diag_matrix_value (), v2.sparse_matrix_value (), typ);
42aff15e059b Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
69 }
42aff15e059b Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
70
8967
5bbbf482909a fix omissions adjusting JR's patches
Jaroslav Hajek <highegg@gmail.com>
parents: 8966
diff changeset
71 DEFBINOP (add_dm_sm, diag_matrix, sparse_matrix)
8966
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8965
diff changeset
72 {
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8965
diff changeset
73 CAST_BINOP_ARGS (const octave_diag_matrix&, const octave_sparse_matrix&);
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8965
diff changeset
74
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
75 if (v2.rows () == 1 && v2.columns () == 1)
8966
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8965
diff changeset
76 // If v2 is a scalar in disguise, return a diagonal matrix rather than
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8965
diff changeset
77 // a sparse matrix.
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8965
diff changeset
78 {
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8965
diff changeset
79 double d = v2.scalar_value ();
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8965
diff changeset
80
9732
b4fdfee405b5 remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents: 8967
diff changeset
81 return octave_value (v1.matrix_value () + d);
8966
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8965
diff changeset
82 }
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8965
diff changeset
83 else
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8965
diff changeset
84 return v1.diag_matrix_value () + v2.sparse_matrix_value ();
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8965
diff changeset
85 }
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8965
diff changeset
86
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8965
diff changeset
87 DEFBINOP (sub_dm_sm, diag_matrix, sparse_matrix)
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8965
diff changeset
88 {
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8965
diff changeset
89 CAST_BINOP_ARGS (const octave_diag_matrix&, const octave_sparse_matrix&);
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8965
diff changeset
90
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
91 if (v2.rows () == 1 && v2.columns () == 1)
8966
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8965
diff changeset
92 // If v2 is a scalar in disguise, return a diagonal matrix rather than
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8965
diff changeset
93 // a sparse matrix.
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8965
diff changeset
94 {
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8965
diff changeset
95 double d = v2.scalar_value ();
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8965
diff changeset
96
9732
b4fdfee405b5 remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents: 8967
diff changeset
97 return octave_value (v1.matrix_value () - d);
8966
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8965
diff changeset
98 }
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8965
diff changeset
99 else
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8965
diff changeset
100 return v1.diag_matrix_value () - v2.sparse_matrix_value ();
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8965
diff changeset
101 }
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8965
diff changeset
102
8964
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
103 // sparse matrix by diagonal matrix ops
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
104
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
105 DEFBINOP (mul_sm_dm, sparse_matrix, diag_matrix)
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
106 {
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
107 CAST_BINOP_ARGS (const octave_sparse_matrix&, const octave_diag_matrix&);
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
108
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
109 if (v1.rows () == 1 && v1.columns () == 1)
8964
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
110 // If v1 is a scalar in disguise, return a diagonal matrix rather than
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
111 // a sparse matrix.
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
112 {
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
113 double d = v1.scalar_value ();
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
114
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
115 return octave_value (d * v2.diag_matrix_value ());
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
116 }
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
117 else
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
118 {
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
119 MatrixType typ = v1.matrix_type ();
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
120 SparseMatrix ret = v1.sparse_matrix_value () * v2.diag_matrix_value ();
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
121 octave_value out = octave_value (ret);
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
122 typ.mark_as_unsymmetric ();
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
123 out.matrix_type (typ);
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
124 return out;
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
125 }
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
126 }
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
127
8965
42aff15e059b Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
128 DEFBINOP (div_sm_dm, sparse_matrix, diag_matrix)
42aff15e059b Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
129 {
42aff15e059b Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
130 CAST_BINOP_ARGS (const octave_sparse_matrix&, const octave_diag_matrix&);
42aff15e059b Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
131
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
132 if (v2.rows () == 1 && v2.columns () == 1)
8965
42aff15e059b Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
133 {
42aff15e059b Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
134 double d = v2.scalar_value ();
42aff15e059b Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
135
42aff15e059b Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
136 if (d == 0.0)
9931
fb6b6fcafa62 untabify files in src/OPERATORS directory
John W. Eaton <jwe@octave.org>
parents: 9732
diff changeset
137 gripe_divide_by_zero ();
8965
42aff15e059b Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
138
42aff15e059b Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
139 return octave_value (v1.sparse_matrix_value () / d);
42aff15e059b Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
140 }
42aff15e059b Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
141 else
42aff15e059b Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
142 {
42aff15e059b Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
143 MatrixType typ = v2.matrix_type ();
42aff15e059b Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
144 return xdiv (v1.sparse_matrix_value (), v2.diag_matrix_value (), typ);
42aff15e059b Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
145 }
42aff15e059b Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
146 }
42aff15e059b Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
147
8966
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8965
diff changeset
148 DEFBINOP (add_sm_dm, sparse_matrix, diag_matrix)
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8965
diff changeset
149 {
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8965
diff changeset
150 CAST_BINOP_ARGS (const octave_sparse_matrix&, const octave_diag_matrix&);
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8965
diff changeset
151
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
152 if (v1.rows () == 1 && v1.columns () == 1)
8966
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8965
diff changeset
153 // If v1 is a scalar in disguise, return a diagonal matrix rather than
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8965
diff changeset
154 // a sparse matrix.
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8965
diff changeset
155 {
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8965
diff changeset
156 double d = v1.scalar_value ();
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8965
diff changeset
157
9732
b4fdfee405b5 remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents: 8967
diff changeset
158 return octave_value (d + v2.matrix_value ());
8966
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8965
diff changeset
159 }
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8965
diff changeset
160 else
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8965
diff changeset
161 return v1.sparse_matrix_value () + v2.diag_matrix_value ();
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8965
diff changeset
162 }
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8965
diff changeset
163
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8965
diff changeset
164 DEFBINOP (sub_sm_dm, sparse_matrix, diag_matrix)
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8965
diff changeset
165 {
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8965
diff changeset
166 CAST_BINOP_ARGS (const octave_sparse_matrix&, const octave_diag_matrix&);
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8965
diff changeset
167
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
168 if (v1.rows () == 1 && v1.columns () == 1)
8966
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8965
diff changeset
169 // If v1 is a scalar in disguise, return a diagonal matrix rather than
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8965
diff changeset
170 // a sparse matrix.
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8965
diff changeset
171 {
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8965
diff changeset
172 double d = v1.scalar_value ();
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8965
diff changeset
173
9732
b4fdfee405b5 remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents: 8967
diff changeset
174 return octave_value (d - v2.matrix_value ());
8966
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8965
diff changeset
175 }
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8965
diff changeset
176 else
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8965
diff changeset
177 return v1.sparse_matrix_value () - v2.diag_matrix_value ();
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8965
diff changeset
178 }
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8965
diff changeset
179
8964
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
180 void
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
181 install_dm_sm_ops (void)
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
182 {
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
183 INSTALL_BINOP (op_mul, octave_diag_matrix, octave_sparse_matrix,
9931
fb6b6fcafa62 untabify files in src/OPERATORS directory
John W. Eaton <jwe@octave.org>
parents: 9732
diff changeset
184 mul_dm_sm);
8964
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
185
8966
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8965
diff changeset
186 INSTALL_BINOP (op_add, octave_diag_matrix, octave_sparse_matrix, add_dm_sm);
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8965
diff changeset
187 INSTALL_BINOP (op_sub, octave_diag_matrix, octave_sparse_matrix, sub_dm_sm);
8965
42aff15e059b Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
188 INSTALL_BINOP (op_ldiv, octave_diag_matrix, octave_sparse_matrix, ldiv_dm_sm);
42aff15e059b Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
189
8964
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
190 INSTALL_BINOP (op_mul, octave_sparse_matrix, octave_diag_matrix,
9931
fb6b6fcafa62 untabify files in src/OPERATORS directory
John W. Eaton <jwe@octave.org>
parents: 9732
diff changeset
191 mul_sm_dm);
8965
42aff15e059b Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
192
8966
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8965
diff changeset
193 INSTALL_BINOP (op_add, octave_sparse_matrix, octave_diag_matrix, add_sm_dm);
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8965
diff changeset
194 INSTALL_BINOP (op_sub, octave_sparse_matrix, octave_diag_matrix, sub_sm_dm);
8965
42aff15e059b Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
195 INSTALL_BINOP (op_div, octave_sparse_matrix, octave_diag_matrix, div_sm_dm);
8964
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents:
diff changeset
196 }