Mercurial > octave
annotate liboctave/operators/Sparse-op-defs.h @ 33636:3ec6fcce7715 default tip @
gui: Avoid using HAVE_QSCINTILLA in more header files.
* gui-settings.h, settings-dialog.h: Don't include QScintilla header.
Forward-declare QSciLexer class instead if necessary. Declare all member
functions unconditionally.
* gui-settings.cc (gui_settings::get_valid_lexer_styles,
gui_settings::read_lexer_settings),
settings-dialog.cc (settings_dialog::update_lexer,
settings_dialog::get_lexer_settings, settings_dialog::write_lexer_settings):
Define functions unconditionally.
* gui-preferences-ed.h: Don't include QScintilla header. Remove definition of
local variable os_eol_mode from header.
* gui-preferences-ed.cc (os_eol_mode): Move definition of local variable here.
author | Markus Mützel <markus.muetzel@gmx.de> |
---|---|
date | Tue, 28 May 2024 14:54:58 +0200 |
parents | 2e484f9f1f18 |
children |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 //////////////////////////////////////////////////////////////////////// |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 // |
32632
2e484f9f1f18
maint: update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
31706
diff
changeset
|
3 // Copyright (C) 1998-2024 The Octave Project Developers |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
4 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 // See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 // distribution or <https://octave.org/copyright/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
7 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
8 // This file is part of Octave. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
9 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
10 // Octave is free software: you can redistribute it and/or modify it |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
11 // under the terms of the GNU General Public License as published by |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
12 // the Free Software Foundation, either version 3 of the License, or |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
13 // (at your option) any later version. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
14 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
15 // Octave is distributed in the hope that it will be useful, but |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
16 // WITHOUT ANY WARRANTY; without even the implied warranty of |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
18 // GNU General Public License for more details. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
19 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
20 // You should have received a copy of the GNU General Public License |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
21 // along with Octave; see the file COPYING. If not, see |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
22 // <https://www.gnu.org/licenses/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 //////////////////////////////////////////////////////////////////////// |
5164 | 25 |
20791
f7084eae3318
maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
26 #if ! defined (octave_Sparse_op_defs_h) |
17822
ebb3ef964372
maint: Use common #define syntax "octave_filename_h" in h_files.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
27 #define octave_Sparse_op_defs_h 1 |
5164 | 28 |
21244
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
21129
diff
changeset
|
29 #include "octave-config.h" |
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
21129
diff
changeset
|
30 |
5164 | 31 #include "Array-util.h" |
23442
53f5f8231c37
allow most header files to be compiled separately
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
32 #include "lo-array-errwarn.h" |
53f5f8231c37
allow most header files to be compiled separately
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
33 #include "mx-inlines.cc" |
8377
25bc2d31e1bf
improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents:
8198
diff
changeset
|
34 #include "oct-locbuf.h" |
5164 | 35 |
19269
65554f5847ac
don't include oct-locbuf.h in header files unnecessarily
John W. Eaton <jwe@octave.org>
parents:
18812
diff
changeset
|
36 // sparse matrix by scalar operations. |
5164 | 37 |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
38 #define SPARSE_SMS_BIN_OP_1(R, F, OP, M, S) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
39 R \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
40 F (const M& m, const S& s) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
41 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
42 octave_idx_type nr = m.rows (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
43 octave_idx_type nc = m.cols (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
44 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
45 R r (nr, nc, (0.0 OP s)); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
46 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
47 for (octave_idx_type j = 0; j < nc; j++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
48 for (octave_idx_type i = m.cidx (j); i < m.cidx (j+1); i++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
49 r.xelem (m.ridx (i), j) = m.data (i) OP s; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
50 return r; \ |
5164 | 51 } |
52 | |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
53 #define SPARSE_SMS_BIN_OP_2(R, F, OP, M, S) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
54 R \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
55 F (const M& m, const S& s) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
56 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
57 octave_idx_type nr = m.rows (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
58 octave_idx_type nc = m.cols (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
59 octave_idx_type nz = m.nnz (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
60 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
61 R r (nr, nc, nz); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
62 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
63 for (octave_idx_type i = 0; i < nz; i++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
64 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
65 r.xdata (i) = m.data (i) OP s; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
66 r.xridx (i) = m.ridx (i); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
67 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
68 for (octave_idx_type i = 0; i < nc + 1; i++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
69 r.xcidx (i) = m.cidx (i); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
70 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
71 r.maybe_compress (true); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
72 return r; \ |
5164 | 73 } |
74 | |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
75 #define SPARSE_SMS_BIN_OPS(R1, R2, M, S) \ |
5164 | 76 SPARSE_SMS_BIN_OP_1 (R1, operator +, +, M, S) \ |
77 SPARSE_SMS_BIN_OP_1 (R1, operator -, -, M, S) \ | |
78 SPARSE_SMS_BIN_OP_2 (R2, operator *, *, M, S) \ | |
79 SPARSE_SMS_BIN_OP_2 (R2, operator /, /, M, S) | |
80 | |
25665
dc073ccde64e
eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents:
25664
diff
changeset
|
81 #define SPARSE_SMS_CMP_OP(F, OP, M, S) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
82 SparseBoolMatrix \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
83 F (const M& m, const S& s) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
84 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
85 octave_idx_type nr = m.rows (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
86 octave_idx_type nc = m.cols (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
87 SparseBoolMatrix r; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
88 \ |
25665
dc073ccde64e
eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents:
25664
diff
changeset
|
89 M::element_type m_zero = M::element_type (); \ |
dc073ccde64e
eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents:
25664
diff
changeset
|
90 \ |
dc073ccde64e
eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents:
25664
diff
changeset
|
91 if (m_zero OP s) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
92 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
93 r = SparseBoolMatrix (nr, nc, true); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
94 for (octave_idx_type j = 0; j < nc; j++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
95 for (octave_idx_type i = m.cidx (j); i < m.cidx (j+1); i++) \ |
25664
fc6081e9607b
eliminate unused conversions from type specs and operator macros
John W. Eaton <jwe@octave.org>
parents:
25663
diff
changeset
|
96 if (! (m.data (i) OP s)) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
97 r.data (m.ridx (i) + j * nr) = false; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
98 r.maybe_compress (true); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
99 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
100 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
101 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
102 r = SparseBoolMatrix (nr, nc, m.nnz ()); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
103 r.cidx (0) = static_cast<octave_idx_type> (0); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
104 octave_idx_type nel = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
105 for (octave_idx_type j = 0; j < nc; j++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
106 { \ |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
107 for (octave_idx_type i = m.cidx (j); i < m.cidx (j+1); i++) \ |
25664
fc6081e9607b
eliminate unused conversions from type specs and operator macros
John W. Eaton <jwe@octave.org>
parents:
25663
diff
changeset
|
108 if (m.data (i) OP s) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
109 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
110 r.ridx (nel) = m.ridx (i); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
111 r.data (nel++) = true; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
112 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
113 r.cidx (j + 1) = nel; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
114 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
115 r.maybe_compress (false); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
116 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
117 return r; \ |
5164 | 118 } |
119 | |
25665
dc073ccde64e
eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents:
25664
diff
changeset
|
120 #define SPARSE_SMS_CMP_OPS(M, S) \ |
dc073ccde64e
eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents:
25664
diff
changeset
|
121 SPARSE_SMS_CMP_OP (mx_el_lt, <, M, S) \ |
dc073ccde64e
eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents:
25664
diff
changeset
|
122 SPARSE_SMS_CMP_OP (mx_el_le, <=, M, S) \ |
dc073ccde64e
eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents:
25664
diff
changeset
|
123 SPARSE_SMS_CMP_OP (mx_el_ge, >=, M, S) \ |
dc073ccde64e
eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents:
25664
diff
changeset
|
124 SPARSE_SMS_CMP_OP (mx_el_gt, >, M, S) \ |
dc073ccde64e
eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents:
25664
diff
changeset
|
125 SPARSE_SMS_CMP_OP (mx_el_eq, ==, M, S) \ |
dc073ccde64e
eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents:
25664
diff
changeset
|
126 SPARSE_SMS_CMP_OP (mx_el_ne, !=, M, S) |
5164 | 127 |
25665
dc073ccde64e
eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents:
25664
diff
changeset
|
128 #define SPARSE_SMS_EQNE_OPS(M, S) \ |
dc073ccde64e
eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents:
25664
diff
changeset
|
129 SPARSE_SMS_CMP_OP (mx_el_eq, ==, M, S) \ |
dc073ccde64e
eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents:
25664
diff
changeset
|
130 SPARSE_SMS_CMP_OP (mx_el_ne, !=, M, S) |
5164 | 131 |
25663
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
132 #define SPARSE_SMS_BOOL_OR_OP(M, S) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
133 SparseBoolMatrix \ |
25663
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
134 mx_el_or (const M& m, const S& s) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
135 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
136 octave_idx_type nr = m.rows (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
137 octave_idx_type nc = m.cols (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
138 SparseBoolMatrix r; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
139 \ |
25663
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
140 M::element_type lhs_zero = M::element_type (); \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
141 S rhs_zero = S (); \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
142 \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
143 if (nr > 0 && nc > 0) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
144 { \ |
25663
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
145 if (s != rhs_zero) \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
146 r = SparseBoolMatrix (nr, nc, true); \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
147 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
148 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
149 r = SparseBoolMatrix (nr, nc, m.nnz ()); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
150 r.cidx (0) = static_cast<octave_idx_type> (0); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
151 octave_idx_type nel = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
152 for (octave_idx_type j = 0; j < nc; j++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
153 { \ |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
154 for (octave_idx_type i = m.cidx (j); i < m.cidx (j+1); i++) \ |
25663
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
155 if (m.data (i) != lhs_zero) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
156 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
157 r.ridx (nel) = m.ridx (i); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
158 r.data (nel++) = true; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
159 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
160 r.cidx (j + 1) = nel; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
161 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
162 r.maybe_compress (false); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
163 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
164 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
165 return r; \ |
5164 | 166 } |
167 | |
25663
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
168 #define SPARSE_SMS_BOOL_AND_OP(M, S) \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
169 SparseBoolMatrix \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
170 mx_el_and (const M& m, const S& s) \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
171 { \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
172 octave_idx_type nr = m.rows (); \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
173 octave_idx_type nc = m.cols (); \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
174 SparseBoolMatrix r; \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
175 \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
176 M::element_type lhs_zero = M::element_type (); \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
177 S rhs_zero = S (); \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
178 \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
179 if (nr > 0 && nc > 0) \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
180 { \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
181 if (s != rhs_zero) \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
182 { \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
183 r = SparseBoolMatrix (nr, nc, m.nnz ()); \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
184 r.cidx (0) = static_cast<octave_idx_type> (0); \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
185 octave_idx_type nel = 0; \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
186 for (octave_idx_type j = 0; j < nc; j++) \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
187 { \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
188 for (octave_idx_type i = m.cidx (j); i < m.cidx (j+1); i++) \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
189 if (m.data (i) != lhs_zero) \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
190 { \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
191 r.ridx (nel) = m.ridx (i); \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
192 r.data (nel++) = true; \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
193 } \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
194 r.cidx (j + 1) = nel; \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
195 } \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
196 r.maybe_compress (false); \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
197 } \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
198 else \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
199 r = SparseBoolMatrix (nr, nc); \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
200 } \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
201 return r; \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
202 } |
5164 | 203 |
25663
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
204 #define SPARSE_SMS_BOOL_OPS(M, S) \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
205 SPARSE_SMS_BOOL_AND_OP (M, S) \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
206 SPARSE_SMS_BOOL_OR_OP (M, S) |
5164 | 207 |
19269
65554f5847ac
don't include oct-locbuf.h in header files unnecessarily
John W. Eaton <jwe@octave.org>
parents:
18812
diff
changeset
|
208 // scalar by sparse matrix operations. |
5164 | 209 |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
210 #define SPARSE_SSM_BIN_OP_1(R, F, OP, S, M) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
211 R \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
212 F (const S& s, const M& m) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
213 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
214 octave_idx_type nr = m.rows (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
215 octave_idx_type nc = m.cols (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
216 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
217 R r (nr, nc, (s OP 0.0)); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
218 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
219 for (octave_idx_type j = 0; j < nc; j++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
220 for (octave_idx_type i = m.cidx (j); i < m.cidx (j+1); i++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
221 r.xelem (m.ridx (i), j) = s OP m.data (i); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
222 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
223 return r; \ |
5164 | 224 } |
225 | |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
226 #define SPARSE_SSM_BIN_OP_2(R, F, OP, S, M) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
227 R \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
228 F (const S& s, const M& m) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
229 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
230 octave_idx_type nr = m.rows (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
231 octave_idx_type nc = m.cols (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
232 octave_idx_type nz = m.nnz (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
233 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
234 R r (nr, nc, nz); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
235 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
236 for (octave_idx_type i = 0; i < nz; i++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
237 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
238 r.xdata (i) = s OP m.data (i); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
239 r.xridx (i) = m.ridx (i); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
240 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
241 for (octave_idx_type i = 0; i < nc + 1; i++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
242 r.xcidx (i) = m.cidx (i); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
243 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
244 r.maybe_compress(true); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
245 return r; \ |
5164 | 246 } |
247 | |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
248 #define SPARSE_SSM_BIN_OPS(R1, R2, S, M) \ |
5164 | 249 SPARSE_SSM_BIN_OP_1 (R1, operator +, +, S, M) \ |
250 SPARSE_SSM_BIN_OP_1 (R1, operator -, -, S, M) \ | |
251 SPARSE_SSM_BIN_OP_2 (R2, operator *, *, S, M) \ | |
252 SPARSE_SSM_BIN_OP_2 (R2, operator /, /, S, M) | |
253 | |
25665
dc073ccde64e
eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents:
25664
diff
changeset
|
254 #define SPARSE_SSM_CMP_OP(F, OP, S, M) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
255 SparseBoolMatrix \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
256 F (const S& s, const M& m) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
257 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
258 octave_idx_type nr = m.rows (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
259 octave_idx_type nc = m.cols (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
260 SparseBoolMatrix r; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
261 \ |
25665
dc073ccde64e
eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents:
25664
diff
changeset
|
262 M::element_type m_zero = M::element_type (); \ |
dc073ccde64e
eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents:
25664
diff
changeset
|
263 \ |
dc073ccde64e
eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents:
25664
diff
changeset
|
264 if (s OP m_zero) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
265 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
266 r = SparseBoolMatrix (nr, nc, true); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
267 for (octave_idx_type j = 0; j < nc; j++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
268 for (octave_idx_type i = m.cidx (j); i < m.cidx (j+1); i++) \ |
25664
fc6081e9607b
eliminate unused conversions from type specs and operator macros
John W. Eaton <jwe@octave.org>
parents:
25663
diff
changeset
|
269 if (! (s OP m.data (i))) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
270 r.data (m.ridx (i) + j * nr) = false; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
271 r.maybe_compress (true); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
272 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
273 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
274 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
275 r = SparseBoolMatrix (nr, nc, m.nnz ()); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
276 r.cidx (0) = static_cast<octave_idx_type> (0); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
277 octave_idx_type nel = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
278 for (octave_idx_type j = 0; j < nc; j++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
279 { \ |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
280 for (octave_idx_type i = m.cidx (j); i < m.cidx (j+1); i++) \ |
25664
fc6081e9607b
eliminate unused conversions from type specs and operator macros
John W. Eaton <jwe@octave.org>
parents:
25663
diff
changeset
|
281 if (s OP m.data (i)) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
282 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
283 r.ridx (nel) = m.ridx (i); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
284 r.data (nel++) = true; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
285 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
286 r.cidx (j + 1) = nel; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
287 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
288 r.maybe_compress (false); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
289 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
290 return r; \ |
5164 | 291 } |
292 | |
25665
dc073ccde64e
eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents:
25664
diff
changeset
|
293 #define SPARSE_SSM_CMP_OPS(S, M) \ |
dc073ccde64e
eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents:
25664
diff
changeset
|
294 SPARSE_SSM_CMP_OP (mx_el_lt, <, S, M) \ |
dc073ccde64e
eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents:
25664
diff
changeset
|
295 SPARSE_SSM_CMP_OP (mx_el_le, <=, S, M) \ |
dc073ccde64e
eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents:
25664
diff
changeset
|
296 SPARSE_SSM_CMP_OP (mx_el_ge, >=, S, M) \ |
dc073ccde64e
eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents:
25664
diff
changeset
|
297 SPARSE_SSM_CMP_OP (mx_el_gt, >, S, M) \ |
dc073ccde64e
eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents:
25664
diff
changeset
|
298 SPARSE_SSM_CMP_OP (mx_el_eq, ==, S, M) \ |
dc073ccde64e
eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents:
25664
diff
changeset
|
299 SPARSE_SSM_CMP_OP (mx_el_ne, !=, S, M) |
5164 | 300 |
25665
dc073ccde64e
eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents:
25664
diff
changeset
|
301 #define SPARSE_SSM_EQNE_OPS(S, M) \ |
dc073ccde64e
eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents:
25664
diff
changeset
|
302 SPARSE_SSM_CMP_OP (mx_el_eq, ==, S, M) \ |
dc073ccde64e
eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents:
25664
diff
changeset
|
303 SPARSE_SSM_CMP_OP (mx_el_ne, !=, S, M) |
5164 | 304 |
25663
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
305 #define SPARSE_SSM_BOOL_OR_OP(S, M) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
306 SparseBoolMatrix \ |
25663
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
307 mx_el_or (const S& s, const M& m) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
308 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
309 octave_idx_type nr = m.rows (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
310 octave_idx_type nc = m.cols (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
311 SparseBoolMatrix r; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
312 \ |
25663
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
313 S lhs_zero = S (); \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
314 M::element_type rhs_zero = M::element_type (); \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
315 \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
316 if (nr > 0 && nc > 0) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
317 { \ |
25663
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
318 if (s != lhs_zero) \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
319 r = SparseBoolMatrix (nr, nc, true); \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
320 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
321 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
322 r = SparseBoolMatrix (nr, nc, m.nnz ()); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
323 r.cidx (0) = static_cast<octave_idx_type> (0); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
324 octave_idx_type nel = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
325 for (octave_idx_type j = 0; j < nc; j++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
326 { \ |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
327 for (octave_idx_type i = m.cidx (j); i < m.cidx (j+1); i++) \ |
25663
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
328 if (m.data (i) != rhs_zero) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
329 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
330 r.ridx (nel) = m.ridx (i); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
331 r.data (nel++) = true; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
332 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
333 r.cidx (j + 1) = nel; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
334 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
335 r.maybe_compress (false); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
336 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
337 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
338 return r; \ |
5164 | 339 } |
340 | |
25663
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
341 #define SPARSE_SSM_BOOL_AND_OP(S, M) \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
342 SparseBoolMatrix \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
343 mx_el_and (const S& s, const M& m) \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
344 { \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
345 octave_idx_type nr = m.rows (); \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
346 octave_idx_type nc = m.cols (); \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
347 SparseBoolMatrix r; \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
348 \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
349 S lhs_zero = S (); \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
350 M::element_type rhs_zero = M::element_type (); \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
351 \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
352 if (nr > 0 && nc > 0) \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
353 { \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
354 if (s != lhs_zero) \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
355 { \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
356 r = SparseBoolMatrix (nr, nc, m.nnz ()); \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
357 r.cidx (0) = static_cast<octave_idx_type> (0); \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
358 octave_idx_type nel = 0; \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
359 for (octave_idx_type j = 0; j < nc; j++) \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
360 { \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
361 for (octave_idx_type i = m.cidx (j); i < m.cidx (j+1); i++) \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
362 if (m.data (i) != rhs_zero) \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
363 { \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
364 r.ridx (nel) = m.ridx (i); \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
365 r.data (nel++) = true; \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
366 } \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
367 r.cidx (j + 1) = nel; \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
368 } \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
369 r.maybe_compress (false); \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
370 } \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
371 else \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
372 r = SparseBoolMatrix (nr, nc); \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
373 } \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
374 return r; \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
375 } |
5164 | 376 |
25663
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
377 #define SPARSE_SSM_BOOL_OPS(S, M) \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
378 SPARSE_SSM_BOOL_AND_OP (S, M) \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
379 SPARSE_SSM_BOOL_OR_OP (S, M) |
5164 | 380 |
19269
65554f5847ac
don't include oct-locbuf.h in header files unnecessarily
John W. Eaton <jwe@octave.org>
parents:
18812
diff
changeset
|
381 // sparse matrix by sparse matrix operations. |
5164 | 382 |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
383 #define SPARSE_SMSM_BIN_OP_1(R, F, OP, M1, M2) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
384 R \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
385 F (const M1& m1, const M2& m2) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
386 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
387 R r; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
388 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
389 octave_idx_type m1_nr = m1.rows (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
390 octave_idx_type m1_nc = m1.cols (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
391 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
392 octave_idx_type m2_nr = m2.rows (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
393 octave_idx_type m2_nc = m2.cols (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
394 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
395 if (m1_nr == 1 && m1_nc == 1) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
396 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
397 if (m1.elem (0,0) == 0.) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
398 r = OP R (m2); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
399 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
400 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
401 r = R (m2_nr, m2_nc, m1.data (0) OP 0.); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
402 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
403 for (octave_idx_type j = 0 ; j < m2_nc ; j++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
404 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
405 octave_quit (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
406 octave_idx_type idxj = j * m2_nr; \ |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
407 for (octave_idx_type i = m2.cidx (j) ; i < m2.cidx (j+1) ; i++) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
408 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
409 octave_quit (); \ |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
410 r.data (idxj + m2.ridx (i)) = m1.data (0) OP m2.data (i); \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
411 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
412 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
413 r.maybe_compress (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
414 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
415 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
416 else if (m2_nr == 1 && m2_nc == 1) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
417 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
418 if (m2.elem (0,0) == 0.) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
419 r = R (m1); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
420 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
421 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
422 r = R (m1_nr, m1_nc, 0. OP m2.data (0)); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
423 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
424 for (octave_idx_type j = 0 ; j < m1_nc ; j++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
425 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
426 octave_quit (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
427 octave_idx_type idxj = j * m1_nr; \ |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
428 for (octave_idx_type i = m1.cidx (j) ; i < m1.cidx (j+1) ; i++) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
429 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
430 octave_quit (); \ |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
431 r.data (idxj + m1.ridx (i)) = m1.data (i) OP m2.data (0); \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
432 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
433 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
434 r.maybe_compress (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
435 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
436 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
437 else if (m1_nr != m2_nr || m1_nc != m2_nc) \ |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
438 octave::err_nonconformant (#F, m1_nr, m1_nc, m2_nr, m2_nc); \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
439 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
440 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
441 r = R (m1_nr, m1_nc, (m1.nnz () + m2.nnz ())); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
442 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
443 octave_idx_type jx = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
444 r.cidx (0) = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
445 for (octave_idx_type i = 0 ; i < m1_nc ; i++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
446 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
447 octave_idx_type ja = m1.cidx (i); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
448 octave_idx_type ja_max = m1.cidx (i+1); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
449 bool ja_lt_max = ja < ja_max; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
450 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
451 octave_idx_type jb = m2.cidx (i); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
452 octave_idx_type jb_max = m2.cidx (i+1); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
453 bool jb_lt_max = jb < jb_max; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
454 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
455 while (ja_lt_max || jb_lt_max) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
456 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
457 octave_quit (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
458 if ((! jb_lt_max) || \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
459 (ja_lt_max && (m1.ridx (ja) < m2.ridx (jb)))) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
460 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
461 r.ridx (jx) = m1.ridx (ja); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
462 r.data (jx) = m1.data (ja) OP 0.; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
463 jx++; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
464 ja++; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
465 ja_lt_max= ja < ja_max; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
466 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
467 else if ((! ja_lt_max) || \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
468 (jb_lt_max && (m2.ridx (jb) < m1.ridx (ja)))) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
469 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
470 r.ridx (jx) = m2.ridx (jb); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
471 r.data (jx) = 0. OP m2.data (jb); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
472 jx++; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
473 jb++; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
474 jb_lt_max= jb < jb_max; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
475 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
476 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
477 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
478 if ((m1.data (ja) OP m2.data (jb)) != 0.) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
479 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
480 r.data (jx) = m1.data (ja) OP m2.data (jb); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
481 r.ridx (jx) = m1.ridx (ja); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
482 jx++; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
483 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
484 ja++; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
485 ja_lt_max= ja < ja_max; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
486 jb++; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
487 jb_lt_max= jb < jb_max; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
488 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
489 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
490 r.cidx (i+1) = jx; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
491 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
492 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
493 r.maybe_compress (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
494 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
495 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
496 return r; \ |
5164 | 497 } |
498 | |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
499 #define SPARSE_SMSM_BIN_OP_2(R, F, OP, M1, M2) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
500 R \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
501 F (const M1& m1, const M2& m2) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
502 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
503 R r; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
504 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
505 octave_idx_type m1_nr = m1.rows (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
506 octave_idx_type m1_nc = m1.cols (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
507 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
508 octave_idx_type m2_nr = m2.rows (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
509 octave_idx_type m2_nc = m2.cols (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
510 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
511 if (m1_nr == 1 && m1_nc == 1) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
512 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
513 if (m1.elem (0,0) == 0.) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
514 r = R (m2_nr, m2_nc); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
515 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
516 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
517 r = R (m2); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
518 octave_idx_type m2_nnz = m2.nnz (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
519 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
520 for (octave_idx_type i = 0 ; i < m2_nnz ; i++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
521 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
522 octave_quit (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
523 r.data (i) = m1.data (0) OP r.data (i); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
524 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
525 r.maybe_compress (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
526 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
527 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
528 else if (m2_nr == 1 && m2_nc == 1) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
529 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
530 if (m2.elem (0,0) == 0.) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
531 r = R (m1_nr, m1_nc); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
532 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
533 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
534 r = R (m1); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
535 octave_idx_type m1_nnz = m1.nnz (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
536 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
537 for (octave_idx_type i = 0 ; i < m1_nnz ; i++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
538 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
539 octave_quit (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
540 r.data (i) = r.data (i) OP m2.data (0); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
541 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
542 r.maybe_compress (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
543 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
544 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
545 else if (m1_nr != m2_nr || m1_nc != m2_nc) \ |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
546 octave::err_nonconformant (#F, m1_nr, m1_nc, m2_nr, m2_nc); \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
547 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
548 { \ |
5681 | 549 r = R (m1_nr, m1_nc, (m1.nnz () > m2.nnz () ? m1.nnz () : m2.nnz ())); \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
550 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
551 octave_idx_type jx = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
552 r.cidx (0) = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
553 for (octave_idx_type i = 0 ; i < m1_nc ; i++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
554 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
555 octave_idx_type ja = m1.cidx (i); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
556 octave_idx_type ja_max = m1.cidx (i+1); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
557 bool ja_lt_max = ja < ja_max; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
558 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
559 octave_idx_type jb = m2.cidx (i); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
560 octave_idx_type jb_max = m2.cidx (i+1); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
561 bool jb_lt_max = jb < jb_max; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
562 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
563 while (ja_lt_max || jb_lt_max) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
564 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
565 octave_quit (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
566 if ((! jb_lt_max) || \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
567 (ja_lt_max && (m1.ridx (ja) < m2.ridx (jb)))) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
568 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
569 ja++; ja_lt_max= ja < ja_max; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
570 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
571 else if ((! ja_lt_max) || \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
572 (jb_lt_max && (m2.ridx (jb) < m1.ridx (ja)))) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
573 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
574 jb++; jb_lt_max= jb < jb_max; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
575 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
576 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
577 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
578 if ((m1.data (ja) OP m2.data (jb)) != 0.) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
579 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
580 r.data (jx) = m1.data (ja) OP m2.data (jb); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
581 r.ridx (jx) = m1.ridx (ja); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
582 jx++; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
583 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
584 ja++; ja_lt_max= ja < ja_max; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
585 jb++; jb_lt_max= jb < jb_max; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
586 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
587 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
588 r.cidx (i+1) = jx; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
589 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
590 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
591 r.maybe_compress (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
592 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
593 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
594 return r; \ |
5164 | 595 } |
596 | |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
597 #define SPARSE_SMSM_BIN_OP_3(R, F, OP, M1, M2) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
598 R \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
599 F (const M1& m1, const M2& m2) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
600 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
601 R r; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
602 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
603 octave_idx_type m1_nr = m1.rows (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
604 octave_idx_type m1_nc = m1.cols (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
605 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
606 octave_idx_type m2_nr = m2.rows (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
607 octave_idx_type m2_nc = m2.cols (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
608 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
609 if (m1_nr == 1 && m1_nc == 1) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
610 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
611 if ((m1.elem (0,0) OP Complex ()) == Complex ()) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
612 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
613 octave_idx_type m2_nnz = m2.nnz (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
614 r = R (m2); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
615 for (octave_idx_type i = 0 ; i < m2_nnz ; i++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
616 r.data (i) = m1.elem (0,0) OP r.data (i); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
617 r.maybe_compress (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
618 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
619 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
620 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
621 r = R (m2_nr, m2_nc, m1.elem (0,0) OP Complex ()); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
622 for (octave_idx_type j = 0 ; j < m2_nc ; j++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
623 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
624 octave_quit (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
625 octave_idx_type idxj = j * m2_nr; \ |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
626 for (octave_idx_type i = m2.cidx (j) ; i < m2.cidx (j+1) ; i++) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
627 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
628 octave_quit (); \ |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
629 r.data (idxj + m2.ridx (i)) = m1.elem (0,0) OP m2.data (i); \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
630 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
631 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
632 r.maybe_compress (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
633 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
634 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
635 else if (m2_nr == 1 && m2_nc == 1) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
636 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
637 if ((Complex () OP m1.elem (0,0)) == Complex ()) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
638 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
639 octave_idx_type m1_nnz = m1.nnz (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
640 r = R (m1); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
641 for (octave_idx_type i = 0 ; i < m1_nnz ; i++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
642 r.data (i) = r.data (i) OP m2.elem (0,0); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
643 r.maybe_compress (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
644 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
645 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
646 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
647 r = R (m1_nr, m1_nc, Complex () OP m2.elem (0,0)); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
648 for (octave_idx_type j = 0 ; j < m1_nc ; j++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
649 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
650 octave_quit (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
651 octave_idx_type idxj = j * m1_nr; \ |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
652 for (octave_idx_type i = m1.cidx (j) ; i < m1.cidx (j+1) ; i++) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
653 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
654 octave_quit (); \ |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
655 r.data (idxj + m1.ridx (i)) = m1.data (i) OP m2.elem (0,0); \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
656 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
657 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
658 r.maybe_compress (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
659 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
660 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
661 else if (m1_nr != m2_nr || m1_nc != m2_nc) \ |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
662 octave::err_nonconformant (#F, m1_nr, m1_nc, m2_nr, m2_nc); \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
663 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
664 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
665 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
666 /* FIXME: Kludge... Always double/Complex, so Complex () */ \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
667 r = R (m1_nr, m1_nc, (Complex () OP Complex ())); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
668 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
669 for (octave_idx_type i = 0 ; i < m1_nc ; i++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
670 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
671 octave_idx_type ja = m1.cidx (i); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
672 octave_idx_type ja_max = m1.cidx (i+1); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
673 bool ja_lt_max = ja < ja_max; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
674 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
675 octave_idx_type jb = m2.cidx (i); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
676 octave_idx_type jb_max = m2.cidx (i+1); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
677 bool jb_lt_max = jb < jb_max; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
678 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
679 while (ja_lt_max || jb_lt_max) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
680 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
681 octave_quit (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
682 if ((! jb_lt_max) || \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
683 (ja_lt_max && (m1.ridx (ja) < m2.ridx (jb)))) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
684 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
685 /* keep those kludges coming */ \ |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
686 r.elem (m1.ridx (ja),i) = m1.data (ja) OP Complex (); \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
687 ja++; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
688 ja_lt_max= ja < ja_max; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
689 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
690 else if ((! ja_lt_max) || \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
691 (jb_lt_max && (m2.ridx (jb) < m1.ridx (ja)))) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
692 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
693 /* keep those kludges coming */ \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
694 r.elem (m2.ridx (jb),i) = Complex () OP m2.data (jb); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
695 jb++; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
696 jb_lt_max= jb < jb_max; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
697 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
698 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
699 { \ |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
700 r.elem (m1.ridx (ja),i) = m1.data (ja) OP m2.data (jb); \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
701 ja++; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
702 ja_lt_max= ja < ja_max; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
703 jb++; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
704 jb_lt_max= jb < jb_max; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
705 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
706 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
707 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
708 r.maybe_compress (true); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
709 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
710 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
711 return r; \ |
5164 | 712 } |
713 | |
714 // Note that SM ./ SM needs to take into account the NaN and Inf values | |
715 // implied by the division by zero. | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
716 // FIXME: Are the NaNs double(NaN) or Complex(NaN,Nan) in the complex case? |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
717 #define SPARSE_SMSM_BIN_OPS(R1, R2, M1, M2) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
718 SPARSE_SMSM_BIN_OP_1 (R1, operator +, +, M1, M2) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
719 SPARSE_SMSM_BIN_OP_1 (R1, operator -, -, M1, M2) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
720 SPARSE_SMSM_BIN_OP_2 (R2, product, *, M1, M2) \ |
5164 | 721 SPARSE_SMSM_BIN_OP_3 (R2, quotient, /, M1, M2) |
722 | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
723 // FIXME: this macro duplicates the bodies of the template functions |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
724 // defined in the SPARSE_SSM_CMP_OP and SPARSE_SMS_CMP_OP macros. |
8198 | 725 |
25665
dc073ccde64e
eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents:
25664
diff
changeset
|
726 #define SPARSE_SMSM_CMP_OP(F, OP, M1, M2) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
727 SparseBoolMatrix \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
728 F (const M1& m1, const M2& m2) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
729 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
730 SparseBoolMatrix r; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
731 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
732 octave_idx_type m1_nr = m1.rows (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
733 octave_idx_type m1_nc = m1.cols (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
734 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
735 octave_idx_type m2_nr = m2.rows (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
736 octave_idx_type m2_nc = m2.cols (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
737 \ |
25665
dc073ccde64e
eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents:
25664
diff
changeset
|
738 M1::element_type Z1 = M1::element_type (); \ |
dc073ccde64e
eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents:
25664
diff
changeset
|
739 M2::element_type Z2 = M2::element_type (); \ |
dc073ccde64e
eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents:
25664
diff
changeset
|
740 \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
741 if (m1_nr == 1 && m1_nc == 1) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
742 { \ |
25664
fc6081e9607b
eliminate unused conversions from type specs and operator macros
John W. Eaton <jwe@octave.org>
parents:
25663
diff
changeset
|
743 if (m1.elem (0,0) OP Z2) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
744 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
745 r = SparseBoolMatrix (m2_nr, m2_nc, true); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
746 for (octave_idx_type j = 0; j < m2_nc; j++) \ |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
747 for (octave_idx_type i = m2.cidx (j); i < m2.cidx (j+1); i++) \ |
25664
fc6081e9607b
eliminate unused conversions from type specs and operator macros
John W. Eaton <jwe@octave.org>
parents:
25663
diff
changeset
|
748 if (! (m1.elem (0,0) OP m2.data (i))) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
749 r.data (m2.ridx (i) + j * m2_nr) = false; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
750 r.maybe_compress (true); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
751 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
752 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
753 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
754 r = SparseBoolMatrix (m2_nr, m2_nc, m2.nnz ()); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
755 r.cidx (0) = static_cast<octave_idx_type> (0); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
756 octave_idx_type nel = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
757 for (octave_idx_type j = 0; j < m2_nc; j++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
758 { \ |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
759 for (octave_idx_type i = m2.cidx (j); i < m2.cidx (j+1); i++) \ |
25664
fc6081e9607b
eliminate unused conversions from type specs and operator macros
John W. Eaton <jwe@octave.org>
parents:
25663
diff
changeset
|
760 if (m1.elem (0,0) OP m2.data (i)) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
761 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
762 r.ridx (nel) = m2.ridx (i); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
763 r.data (nel++) = true; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
764 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
765 r.cidx (j + 1) = nel; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
766 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
767 r.maybe_compress (false); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
768 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
769 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
770 else if (m2_nr == 1 && m2_nc == 1) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
771 { \ |
25664
fc6081e9607b
eliminate unused conversions from type specs and operator macros
John W. Eaton <jwe@octave.org>
parents:
25663
diff
changeset
|
772 if (Z1 OP m2.elem (0,0)) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
773 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
774 r = SparseBoolMatrix (m1_nr, m1_nc, true); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
775 for (octave_idx_type j = 0; j < m1_nc; j++) \ |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
776 for (octave_idx_type i = m1.cidx (j); i < m1.cidx (j+1); i++) \ |
25664
fc6081e9607b
eliminate unused conversions from type specs and operator macros
John W. Eaton <jwe@octave.org>
parents:
25663
diff
changeset
|
777 if (! (m1.data (i) OP m2.elem (0,0))) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
778 r.data (m1.ridx (i) + j * m1_nr) = false; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
779 r.maybe_compress (true); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
780 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
781 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
782 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
783 r = SparseBoolMatrix (m1_nr, m1_nc, m1.nnz ()); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
784 r.cidx (0) = static_cast<octave_idx_type> (0); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
785 octave_idx_type nel = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
786 for (octave_idx_type j = 0; j < m1_nc; j++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
787 { \ |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
788 for (octave_idx_type i = m1.cidx (j); i < m1.cidx (j+1); i++) \ |
25664
fc6081e9607b
eliminate unused conversions from type specs and operator macros
John W. Eaton <jwe@octave.org>
parents:
25663
diff
changeset
|
789 if (m1.data (i) OP m2.elem (0,0)) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
790 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
791 r.ridx (nel) = m1.ridx (i); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
792 r.data (nel++) = true; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
793 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
794 r.cidx (j + 1) = nel; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
795 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
796 r.maybe_compress (false); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
797 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
798 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
799 else if (m1_nr == m2_nr && m1_nc == m2_nc) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
800 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
801 if (m1_nr != 0 || m1_nc != 0) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
802 { \ |
25664
fc6081e9607b
eliminate unused conversions from type specs and operator macros
John W. Eaton <jwe@octave.org>
parents:
25663
diff
changeset
|
803 if (Z1 OP Z2) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
804 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
805 r = SparseBoolMatrix (m1_nr, m1_nc, true); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
806 for (octave_idx_type j = 0; j < m1_nc; j++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
807 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
808 octave_idx_type i1 = m1.cidx (j); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
809 octave_idx_type e1 = m1.cidx (j+1); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
810 octave_idx_type i2 = m2.cidx (j); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
811 octave_idx_type e2 = m2.cidx (j+1); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
812 while (i1 < e1 || i2 < e2) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
813 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
814 if (i1 == e1 || (i2 < e2 && m1.ridx (i1) > m2.ridx (i2))) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
815 { \ |
25664
fc6081e9607b
eliminate unused conversions from type specs and operator macros
John W. Eaton <jwe@octave.org>
parents:
25663
diff
changeset
|
816 if (! (Z1 OP m2.data (i2))) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
817 r.data (m2.ridx (i2) + j * m1_nr) = false; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
818 i2++; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
819 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
820 else if (i2 == e2 || m1.ridx (i1) < m2.ridx (i2)) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
821 { \ |
25664
fc6081e9607b
eliminate unused conversions from type specs and operator macros
John W. Eaton <jwe@octave.org>
parents:
25663
diff
changeset
|
822 if (! (m1.data (i1) OP Z2)) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
823 r.data (m1.ridx (i1) + j * m1_nr) = false; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
824 i1++; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
825 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
826 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
827 { \ |
25664
fc6081e9607b
eliminate unused conversions from type specs and operator macros
John W. Eaton <jwe@octave.org>
parents:
25663
diff
changeset
|
828 if (! (m1.data (i1) OP m2.data (i2))) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
829 r.data (m1.ridx (i1) + j * m1_nr) = false; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
830 i1++; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
831 i2++; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
832 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
833 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
834 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
835 r.maybe_compress (true); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
836 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
837 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
838 { \ |
7269 | 839 r = SparseBoolMatrix (m1_nr, m1_nc, m1.nnz () + m2.nnz ()); \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
840 r.cidx (0) = static_cast<octave_idx_type> (0); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
841 octave_idx_type nel = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
842 for (octave_idx_type j = 0; j < m1_nc; j++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
843 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
844 octave_idx_type i1 = m1.cidx (j); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
845 octave_idx_type e1 = m1.cidx (j+1); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
846 octave_idx_type i2 = m2.cidx (j); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
847 octave_idx_type e2 = m2.cidx (j+1); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
848 while (i1 < e1 || i2 < e2) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
849 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
850 if (i1 == e1 || (i2 < e2 && m1.ridx (i1) > m2.ridx (i2))) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
851 { \ |
25664
fc6081e9607b
eliminate unused conversions from type specs and operator macros
John W. Eaton <jwe@octave.org>
parents:
25663
diff
changeset
|
852 if (Z1 OP m2.data (i2)) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
853 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
854 r.ridx (nel) = m2.ridx (i2); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
855 r.data (nel++) = true; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
856 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
857 i2++; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
858 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
859 else if (i2 == e2 || m1.ridx (i1) < m2.ridx (i2)) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
860 { \ |
25664
fc6081e9607b
eliminate unused conversions from type specs and operator macros
John W. Eaton <jwe@octave.org>
parents:
25663
diff
changeset
|
861 if (m1.data (i1) OP Z2) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
862 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
863 r.ridx (nel) = m1.ridx (i1); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
864 r.data (nel++) = true; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
865 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
866 i1++; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
867 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
868 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
869 { \ |
25664
fc6081e9607b
eliminate unused conversions from type specs and operator macros
John W. Eaton <jwe@octave.org>
parents:
25663
diff
changeset
|
870 if (m1.data (i1) OP m2.data (i2)) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
871 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
872 r.ridx (nel) = m1.ridx (i1); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
873 r.data (nel++) = true; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
874 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
875 i1++; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
876 i2++; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
877 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
878 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
879 r.cidx (j + 1) = nel; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
880 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
881 r.maybe_compress (false); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
882 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
883 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
884 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
885 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
886 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
887 if ((m1_nr != 0 || m1_nc != 0) && (m2_nr != 0 || m2_nc != 0)) \ |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
888 octave::err_nonconformant (#F, m1_nr, m1_nc, m2_nr, m2_nc); \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
889 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
890 return r; \ |
5164 | 891 } |
892 | |
25665
dc073ccde64e
eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents:
25664
diff
changeset
|
893 #define SPARSE_SMSM_CMP_OPS(M1, M2) \ |
dc073ccde64e
eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents:
25664
diff
changeset
|
894 SPARSE_SMSM_CMP_OP (mx_el_lt, <, M1, M2) \ |
dc073ccde64e
eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents:
25664
diff
changeset
|
895 SPARSE_SMSM_CMP_OP (mx_el_le, <=, M1, M2) \ |
dc073ccde64e
eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents:
25664
diff
changeset
|
896 SPARSE_SMSM_CMP_OP (mx_el_ge, >=, M1, M2) \ |
dc073ccde64e
eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents:
25664
diff
changeset
|
897 SPARSE_SMSM_CMP_OP (mx_el_gt, >, M1, M2) \ |
dc073ccde64e
eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents:
25664
diff
changeset
|
898 SPARSE_SMSM_CMP_OP (mx_el_eq, ==, M1, M2) \ |
dc073ccde64e
eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents:
25664
diff
changeset
|
899 SPARSE_SMSM_CMP_OP (mx_el_ne, !=, M1, M2) |
5164 | 900 |
25665
dc073ccde64e
eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents:
25664
diff
changeset
|
901 #define SPARSE_SMSM_EQNE_OPS(M1, M2) \ |
dc073ccde64e
eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents:
25664
diff
changeset
|
902 SPARSE_SMSM_CMP_OP (mx_el_eq, ==, M1, M2) \ |
dc073ccde64e
eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents:
25664
diff
changeset
|
903 SPARSE_SMSM_CMP_OP (mx_el_ne, !=, M1, M2) |
5164 | 904 |
25663
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
905 #define SPARSE_SMSM_BOOL_AND_OP(M1, M2) \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
906 extern SparseBoolMatrix mx_el_and (const M1&, const M2::element_type&); \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
907 extern SparseBoolMatrix mx_el_and (const M1::element_type&, const M2&); \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
908 SparseBoolMatrix \ |
25663
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
909 mx_el_and (const M1& m1, const M2& m2) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
910 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
911 SparseBoolMatrix r; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
912 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
913 octave_idx_type m1_nr = m1.rows (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
914 octave_idx_type m1_nc = m1.cols (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
915 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
916 octave_idx_type m2_nr = m2.rows (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
917 octave_idx_type m2_nc = m2.cols (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
918 \ |
25663
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
919 M1::element_type lhs_zero = M1::element_type (); \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
920 M2::element_type rhs_zero = M2::element_type (); \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
921 \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
922 if (m1_nr == 1 && m1_nc == 1) \ |
25663
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
923 return mx_el_and (m1.elem (0,0), m2); \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
924 else if (m2_nr == 1 && m2_nc == 1) \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
925 return mx_el_and (m1, m2.elem (0,0)); \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
926 else if (m1_nr == m2_nr && m1_nc == m2_nc) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
927 { \ |
25663
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
928 if (m1_nr != 0 || m1_nc != 0) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
929 { \ |
25663
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
930 r = SparseBoolMatrix (m1_nr, m1_nc, m1.nnz () + m2.nnz ()); \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
931 r.cidx (0) = static_cast<octave_idx_type> (0); \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
932 octave_idx_type nel = 0; \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
933 for (octave_idx_type j = 0; j < m1_nc; j++) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
934 { \ |
25663
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
935 octave_idx_type i1 = m1.cidx (j); \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
936 octave_idx_type e1 = m1.cidx (j+1); \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
937 octave_idx_type i2 = m2.cidx (j); \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
938 octave_idx_type e2 = m2.cidx (j+1); \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
939 while (i1 < e1 || i2 < e2) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
940 { \ |
25663
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
941 if (i1 == e1 || (i2 < e2 && m1.ridx (i1) > m2.ridx (i2))) \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
942 i2++; \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
943 else if (i2 == e2 || m1.ridx (i1) < m2.ridx (i2)) \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
944 i1++; \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
945 else \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
946 { \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
947 if (m1.data (i1) != lhs_zero && m2.data (i2) != rhs_zero) \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
948 { \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
949 r.ridx (nel) = m1.ridx (i1); \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
950 r.data (nel++) = true; \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
951 } \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
952 i1++; \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
953 i2++; \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
954 } \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
955 } \ |
25663
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
956 r.cidx (j + 1) = nel; \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
957 } \ |
25663
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
958 r.maybe_compress (false); \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
959 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
960 } \ |
25663
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
961 else \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
962 { \ |
25663
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
963 if ((m1_nr != 0 || m1_nc != 0) && (m2_nr != 0 || m2_nc != 0)) \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
964 octave::err_nonconformant ("mx_el_and_", m1_nr, m1_nc, m2_nr, m2_nc); \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
965 } \ |
25663
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
966 return r; \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
967 } |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
968 |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
969 #define SPARSE_SMSM_BOOL_OR_OP(M1, M2) \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
970 extern SparseBoolMatrix mx_el_or (const M1&, const M2::element_type&); \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
971 extern SparseBoolMatrix mx_el_or (const M1::element_type&, const M2&); \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
972 SparseBoolMatrix \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
973 mx_el_or (const M1& m1, const M2& m2) \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
974 { \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
975 SparseBoolMatrix r; \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
976 \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
977 octave_idx_type m1_nr = m1.rows (); \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
978 octave_idx_type m1_nc = m1.cols (); \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
979 \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
980 octave_idx_type m2_nr = m2.rows (); \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
981 octave_idx_type m2_nc = m2.cols (); \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
982 \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
983 M1::element_type lhs_zero = M1::element_type (); \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
984 M2::element_type rhs_zero = M2::element_type (); \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
985 \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
986 if (m1_nr == 1 && m1_nc == 1) \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
987 return mx_el_or (m1.elem (0,0), m2); \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
988 else if (m2_nr == 1 && m2_nc == 1) \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
989 return mx_el_or (m1, m2.elem (0,0)); \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
990 else if (m1_nr == m2_nr && m1_nc == m2_nc) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
991 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
992 if (m1_nr != 0 || m1_nc != 0) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
993 { \ |
7269 | 994 r = SparseBoolMatrix (m1_nr, m1_nc, m1.nnz () + m2.nnz ()); \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
995 r.cidx (0) = static_cast<octave_idx_type> (0); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
996 octave_idx_type nel = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
997 for (octave_idx_type j = 0; j < m1_nc; j++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
998 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
999 octave_idx_type i1 = m1.cidx (j); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1000 octave_idx_type e1 = m1.cidx (j+1); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1001 octave_idx_type i2 = m2.cidx (j); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1002 octave_idx_type e2 = m2.cidx (j+1); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1003 while (i1 < e1 || i2 < e2) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1004 { \ |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1005 if (i1 == e1 || (i2 < e2 && m1.ridx (i1) > m2.ridx (i2))) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1006 { \ |
25663
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
1007 if (m2.data (i2) != rhs_zero) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1008 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1009 r.ridx (nel) = m2.ridx (i2); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1010 r.data (nel++) = true; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1011 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1012 i2++; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1013 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1014 else if (i2 == e2 || m1.ridx (i1) < m2.ridx (i2)) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1015 { \ |
25663
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
1016 if (m1.data (i1) != lhs_zero) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1017 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1018 r.ridx (nel) = m1.ridx (i1); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1019 r.data (nel++) = true; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1020 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1021 i1++; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1022 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1023 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1024 { \ |
25663
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
1025 if (m1.data (i1) != lhs_zero || m2.data (i2) != rhs_zero) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1026 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1027 r.ridx (nel) = m1.ridx (i1); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1028 r.data (nel++) = true; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1029 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1030 i1++; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1031 i2++; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1032 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1033 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1034 r.cidx (j + 1) = nel; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1035 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1036 r.maybe_compress (false); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1037 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1038 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1039 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1040 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1041 if ((m1_nr != 0 || m1_nc != 0) && (m2_nr != 0 || m2_nc != 0)) \ |
25663
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
1042 octave::err_nonconformant ("mx_el_or", m1_nr, m1_nc, m2_nr, m2_nc); \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1043 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1044 return r; \ |
5164 | 1045 } |
1046 | |
25663
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
1047 #define SPARSE_SMSM_BOOL_OPS(M1, M2) \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
1048 SPARSE_SMSM_BOOL_AND_OP (M1, M2) \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
1049 SPARSE_SMSM_BOOL_OR_OP (M1, M2) |
5164 | 1050 |
19269
65554f5847ac
don't include oct-locbuf.h in header files unnecessarily
John W. Eaton <jwe@octave.org>
parents:
18812
diff
changeset
|
1051 // matrix by sparse matrix operations. |
5164 | 1052 |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1053 #define SPARSE_MSM_BIN_OP_1(R, F, OP, M1, M2) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1054 R \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1055 F (const M1& m1, const M2& m2) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1056 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1057 R r; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1058 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1059 octave_idx_type m1_nr = m1.rows (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1060 octave_idx_type m1_nc = m1.cols (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1061 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1062 octave_idx_type m2_nr = m2.rows (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1063 octave_idx_type m2_nc = m2.cols (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1064 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1065 if (m2_nr == 1 && m2_nc == 1) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1066 r = R (m1 OP m2.elem (0,0)); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1067 else if (m1_nr != m2_nr || m1_nc != m2_nc) \ |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
1068 octave::err_nonconformant (#F, m1_nr, m1_nc, m2_nr, m2_nc); \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1069 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1070 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1071 r = R (F (m1, m2.matrix_value ())); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1072 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1073 return r; \ |
5164 | 1074 } |
1075 | |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1076 #define SPARSE_MSM_BIN_OP_2(R, F, OP, M1, M2) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1077 R \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1078 F (const M1& m1, const M2& m2) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1079 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1080 R r; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1081 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1082 octave_idx_type m1_nr = m1.rows (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1083 octave_idx_type m1_nc = m1.cols (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1084 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1085 octave_idx_type m2_nr = m2.rows (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1086 octave_idx_type m2_nc = m2.cols (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1087 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1088 if (m2_nr == 1 && m2_nc == 1) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1089 r = R (m1 OP m2.elem (0,0)); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1090 else if (m1_nr != m2_nr || m1_nc != m2_nc) \ |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
1091 octave::err_nonconformant (#F, m1_nr, m1_nc, m2_nr, m2_nc); \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1092 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1093 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1094 if (do_mx_check (m1, mx_inline_all_finite<M1::element_type>)) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1095 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1096 /* Sparsity pattern is preserved. */ \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1097 octave_idx_type m2_nz = m2.nnz (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1098 r = R (m2_nr, m2_nc, m2_nz); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1099 for (octave_idx_type j = 0, k = 0; j < m2_nc; j++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1100 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1101 octave_quit (); \ |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1102 for (octave_idx_type i = m2.cidx (j); i < m2.cidx (j+1); i++) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1103 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1104 octave_idx_type mri = m2.ridx (i); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1105 R::element_type x = m1(mri, j) OP m2.data (i); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1106 if (x != 0.0) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1107 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1108 r.xdata (k) = x; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1109 r.xridx (k) = m2.ridx (i); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1110 k++; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1111 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1112 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1113 r.xcidx (j+1) = k; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1114 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1115 r.maybe_compress (false); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1116 return r; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1117 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1118 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1119 r = R (F (m1, m2.matrix_value ())); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1120 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1121 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1122 return r; \ |
5164 | 1123 } |
1124 | |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1125 #define SPARSE_MSM_BIN_OPS(R1, R2, M1, M2) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1126 SPARSE_MSM_BIN_OP_1 (R1, operator +, +, M1, M2) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1127 SPARSE_MSM_BIN_OP_1 (R1, operator -, -, M1, M2) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1128 SPARSE_MSM_BIN_OP_2 (R2, product, *, M1, M2) \ |
10900
b64803a8be4e
optimize element-wise sparse-dense multiplication and division
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
1129 SPARSE_MSM_BIN_OP_1 (R2, quotient, /, M1, M2) |
5164 | 1130 |
25664
fc6081e9607b
eliminate unused conversions from type specs and operator macros
John W. Eaton <jwe@octave.org>
parents:
25663
diff
changeset
|
1131 #define SPARSE_MSM_CMP_OP(F, OP, M1, M2) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1132 SparseBoolMatrix \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1133 F (const M1& m1, const M2& m2) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1134 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1135 SparseBoolMatrix r; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1136 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1137 octave_idx_type m1_nr = m1.rows (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1138 octave_idx_type m1_nc = m1.cols (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1139 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1140 octave_idx_type m2_nr = m2.rows (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1141 octave_idx_type m2_nc = m2.cols (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1142 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1143 if (m2_nr == 1 && m2_nc == 1) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1144 r = SparseBoolMatrix (F (m1, m2.elem (0,0))); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1145 else if (m1_nr == m2_nr && m1_nc == m2_nc) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1146 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1147 if (m1_nr != 0 || m1_nc != 0) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1148 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1149 /* Count num of nonzero elements */ \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1150 octave_idx_type nel = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1151 for (octave_idx_type j = 0; j < m1_nc; j++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1152 for (octave_idx_type i = 0; i < m1_nr; i++) \ |
25664
fc6081e9607b
eliminate unused conversions from type specs and operator macros
John W. Eaton <jwe@octave.org>
parents:
25663
diff
changeset
|
1153 if (m1.elem (i, j) OP m2.elem (i, j)) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1154 nel++; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1155 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1156 r = SparseBoolMatrix (m1_nr, m1_nc, nel); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1157 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1158 octave_idx_type ii = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1159 r.cidx (0) = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1160 for (octave_idx_type j = 0; j < m1_nc; j++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1161 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1162 for (octave_idx_type i = 0; i < m1_nr; i++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1163 { \ |
25664
fc6081e9607b
eliminate unused conversions from type specs and operator macros
John W. Eaton <jwe@octave.org>
parents:
25663
diff
changeset
|
1164 bool el = m1.elem (i, j) OP m2.elem (i, j); \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1165 if (el) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1166 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1167 r.data (ii) = el; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1168 r.ridx (ii++) = i; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1169 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1170 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1171 r.cidx (j+1) = ii; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1172 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1173 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1174 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1175 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1176 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1177 if ((m1_nr != 0 || m1_nc != 0) && (m2_nr != 0 || m2_nc != 0)) \ |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
1178 octave::err_nonconformant (#F, m1_nr, m1_nc, m2_nr, m2_nc); \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1179 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1180 return r; \ |
5164 | 1181 } |
1182 | |
25665
dc073ccde64e
eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents:
25664
diff
changeset
|
1183 #define SPARSE_MSM_CMP_OPS(M1, M2) \ |
25664
fc6081e9607b
eliminate unused conversions from type specs and operator macros
John W. Eaton <jwe@octave.org>
parents:
25663
diff
changeset
|
1184 SPARSE_MSM_CMP_OP (mx_el_lt, <, M1, M2) \ |
fc6081e9607b
eliminate unused conversions from type specs and operator macros
John W. Eaton <jwe@octave.org>
parents:
25663
diff
changeset
|
1185 SPARSE_MSM_CMP_OP (mx_el_le, <=, M1, M2) \ |
fc6081e9607b
eliminate unused conversions from type specs and operator macros
John W. Eaton <jwe@octave.org>
parents:
25663
diff
changeset
|
1186 SPARSE_MSM_CMP_OP (mx_el_ge, >=, M1, M2) \ |
fc6081e9607b
eliminate unused conversions from type specs and operator macros
John W. Eaton <jwe@octave.org>
parents:
25663
diff
changeset
|
1187 SPARSE_MSM_CMP_OP (mx_el_gt, >, M1, M2) \ |
fc6081e9607b
eliminate unused conversions from type specs and operator macros
John W. Eaton <jwe@octave.org>
parents:
25663
diff
changeset
|
1188 SPARSE_MSM_CMP_OP (mx_el_eq, ==, M1, M2) \ |
fc6081e9607b
eliminate unused conversions from type specs and operator macros
John W. Eaton <jwe@octave.org>
parents:
25663
diff
changeset
|
1189 SPARSE_MSM_CMP_OP (mx_el_ne, !=, M1, M2) |
5164 | 1190 |
25665
dc073ccde64e
eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents:
25664
diff
changeset
|
1191 #define SPARSE_MSM_EQNE_OPS(M1, M2) \ |
25664
fc6081e9607b
eliminate unused conversions from type specs and operator macros
John W. Eaton <jwe@octave.org>
parents:
25663
diff
changeset
|
1192 SPARSE_MSM_CMP_OP (mx_el_eq, ==, M1, M2) \ |
fc6081e9607b
eliminate unused conversions from type specs and operator macros
John W. Eaton <jwe@octave.org>
parents:
25663
diff
changeset
|
1193 SPARSE_MSM_CMP_OP (mx_el_ne, !=, M1, M2) |
5164 | 1194 |
25663
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
1195 #define SPARSE_MSM_BOOL_OP(F, OP, M1, M2) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1196 SparseBoolMatrix \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1197 F (const M1& m1, const M2& m2) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1198 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1199 SparseBoolMatrix r; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1200 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1201 octave_idx_type m1_nr = m1.rows (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1202 octave_idx_type m1_nc = m1.cols (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1203 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1204 octave_idx_type m2_nr = m2.rows (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1205 octave_idx_type m2_nc = m2.cols (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1206 \ |
25663
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
1207 M1::element_type lhs_zero = M1::element_type (); \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
1208 M2::element_type rhs_zero = M2::element_type (); \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
1209 \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1210 if (m2_nr == 1 && m2_nc == 1) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1211 r = SparseBoolMatrix (F (m1, m2.elem (0,0))); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1212 else if (m1_nr == m2_nr && m1_nc == m2_nc) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1213 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1214 if (m1_nr != 0 || m1_nc != 0) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1215 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1216 /* Count num of nonzero elements */ \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1217 octave_idx_type nel = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1218 for (octave_idx_type j = 0; j < m1_nc; j++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1219 for (octave_idx_type i = 0; i < m1_nr; i++) \ |
25663
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
1220 if ((m1.elem (i, j) != lhs_zero) \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
1221 OP (m2.elem (i, j) != rhs_zero)) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1222 nel++; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1223 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1224 r = SparseBoolMatrix (m1_nr, m1_nc, nel); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1225 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1226 octave_idx_type ii = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1227 r.cidx (0) = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1228 for (octave_idx_type j = 0; j < m1_nc; j++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1229 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1230 for (octave_idx_type i = 0; i < m1_nr; i++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1231 { \ |
25663
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
1232 bool el = (m1.elem (i, j) != lhs_zero) \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
1233 OP (m2.elem (i, j) != rhs_zero); \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1234 if (el) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1235 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1236 r.data (ii) = el; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1237 r.ridx (ii++) = i; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1238 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1239 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1240 r.cidx (j+1) = ii; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1241 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1242 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1243 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1244 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1245 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1246 if ((m1_nr != 0 || m1_nc != 0) && (m2_nr != 0 || m2_nc != 0)) \ |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
1247 octave::err_nonconformant (#F, m1_nr, m1_nc, m2_nr, m2_nc); \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1248 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1249 return r; \ |
5164 | 1250 } |
1251 | |
25663
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
1252 #define SPARSE_MSM_BOOL_OPS(M1, M2) \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
1253 SPARSE_MSM_BOOL_OP (mx_el_and, &&, M1, M2) \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
1254 SPARSE_MSM_BOOL_OP (mx_el_or, ||, M1, M2) |
5164 | 1255 |
19269
65554f5847ac
don't include oct-locbuf.h in header files unnecessarily
John W. Eaton <jwe@octave.org>
parents:
18812
diff
changeset
|
1256 // sparse matrix by matrix operations. |
5164 | 1257 |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1258 #define SPARSE_SMM_BIN_OP_1(R, F, OP, M1, M2) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1259 R \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1260 F (const M1& m1, const M2& m2) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1261 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1262 R r; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1263 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1264 octave_idx_type m1_nr = m1.rows (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1265 octave_idx_type m1_nc = m1.cols (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1266 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1267 octave_idx_type m2_nr = m2.rows (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1268 octave_idx_type m2_nc = m2.cols (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1269 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1270 if (m1_nr == 1 && m1_nc == 1) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1271 r = R (m1.elem (0,0) OP m2); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1272 else if (m1_nr != m2_nr || m1_nc != m2_nc) \ |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
1273 octave::err_nonconformant (#F, m1_nr, m1_nc, m2_nr, m2_nc); \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1274 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1275 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1276 r = R (m1.matrix_value () OP m2); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1277 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1278 return r; \ |
5164 | 1279 } |
1280 | |
10900
b64803a8be4e
optimize element-wise sparse-dense multiplication and division
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
1281 // sm .* m preserves sparsity if m contains no Infs nor Nans. |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1282 #define SPARSE_SMM_BIN_OP_2_CHECK_product(ET) \ |
13731
3b52038e6e6c
Help dumb compilers to resolve template parameters.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
11523
diff
changeset
|
1283 do_mx_check (m2, mx_inline_all_finite<ET>) |
10900
b64803a8be4e
optimize element-wise sparse-dense multiplication and division
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
1284 |
b64803a8be4e
optimize element-wise sparse-dense multiplication and division
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
1285 // sm ./ m preserves sparsity if m contains no NaNs or zeros. |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1286 #define SPARSE_SMM_BIN_OP_2_CHECK_quotient(ET) \ |
13731
3b52038e6e6c
Help dumb compilers to resolve template parameters.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
11523
diff
changeset
|
1287 ! do_mx_check (m2, mx_inline_any_nan<ET>) && m2.nnz () == m2.numel () |
10900
b64803a8be4e
optimize element-wise sparse-dense multiplication and division
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
1288 |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1289 #define SPARSE_SMM_BIN_OP_2(R, F, OP, M1, M2) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1290 R \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1291 F (const M1& m1, const M2& m2) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1292 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1293 R r; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1294 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1295 octave_idx_type m1_nr = m1.rows (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1296 octave_idx_type m1_nc = m1.cols (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1297 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1298 octave_idx_type m2_nr = m2.rows (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1299 octave_idx_type m2_nc = m2.cols (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1300 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1301 if (m1_nr == 1 && m1_nc == 1) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1302 r = R (m1.elem (0,0) OP m2); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1303 else if (m1_nr != m2_nr || m1_nc != m2_nc) \ |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
1304 octave::err_nonconformant (#F, m1_nr, m1_nc, m2_nr, m2_nc); \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1305 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1306 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1307 if (SPARSE_SMM_BIN_OP_2_CHECK_ ## F(M2::element_type)) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1308 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1309 /* Sparsity pattern is preserved. */ \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1310 octave_idx_type m1_nz = m1.nnz (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1311 r = R (m1_nr, m1_nc, m1_nz); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1312 for (octave_idx_type j = 0, k = 0; j < m1_nc; j++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1313 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1314 octave_quit (); \ |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1315 for (octave_idx_type i = m1.cidx (j); i < m1.cidx (j+1); i++) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1316 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1317 octave_idx_type mri = m1.ridx (i); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1318 R::element_type x = m1.data (i) OP m2 (mri, j); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1319 if (x != 0.0) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1320 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1321 r.xdata (k) = x; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1322 r.xridx (k) = m1.ridx (i); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1323 k++; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1324 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1325 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1326 r.xcidx (j+1) = k; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1327 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1328 r.maybe_compress (false); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1329 return r; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1330 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1331 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1332 r = R (F (m1.matrix_value (), m2)); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1333 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1334 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1335 return r; \ |
5164 | 1336 } |
1337 | |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1338 #define SPARSE_SMM_BIN_OPS(R1, R2, M1, M2) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1339 SPARSE_SMM_BIN_OP_1 (R1, operator +, +, M1, M2) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1340 SPARSE_SMM_BIN_OP_1 (R1, operator -, -, M1, M2) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1341 SPARSE_SMM_BIN_OP_2 (R2, product, *, M1, M2) \ |
10900
b64803a8be4e
optimize element-wise sparse-dense multiplication and division
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
1342 SPARSE_SMM_BIN_OP_2 (R2, quotient, /, M1, M2) |
5164 | 1343 |
25664
fc6081e9607b
eliminate unused conversions from type specs and operator macros
John W. Eaton <jwe@octave.org>
parents:
25663
diff
changeset
|
1344 #define SPARSE_SMM_CMP_OP(F, OP, M1, M2) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1345 SparseBoolMatrix \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1346 F (const M1& m1, const M2& m2) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1347 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1348 SparseBoolMatrix r; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1349 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1350 octave_idx_type m1_nr = m1.rows (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1351 octave_idx_type m1_nc = m1.cols (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1352 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1353 octave_idx_type m2_nr = m2.rows (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1354 octave_idx_type m2_nc = m2.cols (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1355 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1356 if (m1_nr == 1 && m1_nc == 1) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1357 r = SparseBoolMatrix (F (m1.elem (0,0), m2)); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1358 else if (m1_nr == m2_nr && m1_nc == m2_nc) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1359 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1360 if (m1_nr != 0 || m1_nc != 0) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1361 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1362 /* Count num of nonzero elements */ \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1363 octave_idx_type nel = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1364 for (octave_idx_type j = 0; j < m1_nc; j++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1365 for (octave_idx_type i = 0; i < m1_nr; i++) \ |
25664
fc6081e9607b
eliminate unused conversions from type specs and operator macros
John W. Eaton <jwe@octave.org>
parents:
25663
diff
changeset
|
1366 if (m1.elem (i, j) OP m2.elem (i, j)) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1367 nel++; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1368 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1369 r = SparseBoolMatrix (m1_nr, m1_nc, nel); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1370 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1371 octave_idx_type ii = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1372 r.cidx (0) = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1373 for (octave_idx_type j = 0; j < m1_nc; j++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1374 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1375 for (octave_idx_type i = 0; i < m1_nr; i++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1376 { \ |
25664
fc6081e9607b
eliminate unused conversions from type specs and operator macros
John W. Eaton <jwe@octave.org>
parents:
25663
diff
changeset
|
1377 bool el = m1.elem (i, j) OP m2.elem (i, j); \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1378 if (el) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1379 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1380 r.data (ii) = el; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1381 r.ridx (ii++) = i; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1382 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1383 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1384 r.cidx (j+1) = ii; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1385 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1386 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1387 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1388 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1389 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1390 if ((m1_nr != 0 || m1_nc != 0) && (m2_nr != 0 || m2_nc != 0)) \ |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
1391 octave::err_nonconformant (#F, m1_nr, m1_nc, m2_nr, m2_nc); \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1392 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1393 return r; \ |
5164 | 1394 } |
1395 | |
25665
dc073ccde64e
eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents:
25664
diff
changeset
|
1396 #define SPARSE_SMM_CMP_OPS(M1, M2) \ |
25664
fc6081e9607b
eliminate unused conversions from type specs and operator macros
John W. Eaton <jwe@octave.org>
parents:
25663
diff
changeset
|
1397 SPARSE_SMM_CMP_OP (mx_el_lt, <, M1, M2) \ |
fc6081e9607b
eliminate unused conversions from type specs and operator macros
John W. Eaton <jwe@octave.org>
parents:
25663
diff
changeset
|
1398 SPARSE_SMM_CMP_OP (mx_el_le, <=, M1, M2) \ |
fc6081e9607b
eliminate unused conversions from type specs and operator macros
John W. Eaton <jwe@octave.org>
parents:
25663
diff
changeset
|
1399 SPARSE_SMM_CMP_OP (mx_el_ge, >=, M1, M2) \ |
fc6081e9607b
eliminate unused conversions from type specs and operator macros
John W. Eaton <jwe@octave.org>
parents:
25663
diff
changeset
|
1400 SPARSE_SMM_CMP_OP (mx_el_gt, >, M1, M2) \ |
fc6081e9607b
eliminate unused conversions from type specs and operator macros
John W. Eaton <jwe@octave.org>
parents:
25663
diff
changeset
|
1401 SPARSE_SMM_CMP_OP (mx_el_eq, ==, M1, M2) \ |
fc6081e9607b
eliminate unused conversions from type specs and operator macros
John W. Eaton <jwe@octave.org>
parents:
25663
diff
changeset
|
1402 SPARSE_SMM_CMP_OP (mx_el_ne, !=, M1, M2) |
5164 | 1403 |
25665
dc073ccde64e
eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents:
25664
diff
changeset
|
1404 #define SPARSE_SMM_EQNE_OPS(M1, M2) \ |
25664
fc6081e9607b
eliminate unused conversions from type specs and operator macros
John W. Eaton <jwe@octave.org>
parents:
25663
diff
changeset
|
1405 SPARSE_SMM_CMP_OP (mx_el_eq, ==, M1, M2) \ |
fc6081e9607b
eliminate unused conversions from type specs and operator macros
John W. Eaton <jwe@octave.org>
parents:
25663
diff
changeset
|
1406 SPARSE_SMM_CMP_OP (mx_el_ne, !=, M1, M2) |
5164 | 1407 |
25663
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
1408 #define SPARSE_SMM_BOOL_OP(F, OP, M1, M2) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1409 SparseBoolMatrix \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1410 F (const M1& m1, const M2& m2) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1411 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1412 SparseBoolMatrix r; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1413 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1414 octave_idx_type m1_nr = m1.rows (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1415 octave_idx_type m1_nc = m1.cols (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1416 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1417 octave_idx_type m2_nr = m2.rows (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1418 octave_idx_type m2_nc = m2.cols (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1419 \ |
25663
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
1420 M1::element_type lhs_zero = M1::element_type (); \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
1421 M2::element_type rhs_zero = M2::element_type (); \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
1422 \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1423 if (m1_nr == 1 && m1_nc == 1) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1424 r = SparseBoolMatrix (F (m1.elem (0,0), m2)); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1425 else if (m1_nr == m2_nr && m1_nc == m2_nc) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1426 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1427 if (m1_nr != 0 || m1_nc != 0) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1428 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1429 /* Count num of nonzero elements */ \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1430 octave_idx_type nel = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1431 for (octave_idx_type j = 0; j < m1_nc; j++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1432 for (octave_idx_type i = 0; i < m1_nr; i++) \ |
25663
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
1433 if ((m1.elem (i, j) != lhs_zero) \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
1434 OP (m2.elem (i, j) != rhs_zero)) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1435 nel++; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1436 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1437 r = SparseBoolMatrix (m1_nr, m1_nc, nel); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1438 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1439 octave_idx_type ii = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1440 r.cidx (0) = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1441 for (octave_idx_type j = 0; j < m1_nc; j++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1442 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1443 for (octave_idx_type i = 0; i < m1_nr; i++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1444 { \ |
25663
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
1445 bool el = (m1.elem (i, j) != lhs_zero) \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
1446 OP (m2.elem (i, j) != rhs_zero); \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1447 if (el) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1448 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1449 r.data (ii) = el; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1450 r.ridx (ii++) = i; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1451 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1452 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1453 r.cidx (j+1) = ii; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1454 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1455 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1456 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1457 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1458 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1459 if ((m1_nr != 0 || m1_nc != 0) && (m2_nr != 0 || m2_nc != 0)) \ |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
1460 octave::err_nonconformant (#F, m1_nr, m1_nc, m2_nr, m2_nc); \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1461 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1462 return r; \ |
5164 | 1463 } |
1464 | |
25663
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
1465 #define SPARSE_SMM_BOOL_OPS(M1, M2) \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
1466 SPARSE_SMM_BOOL_OP (mx_el_and, &&, M1, M2) \ |
2de707ae8de4
eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
1467 SPARSE_SMM_BOOL_OP (mx_el_or, ||, M1, M2) |
5164 | 1468 |
1469 // Avoid some code duplication. Maybe we should use templates. | |
1470 | |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1471 #define SPARSE_CUMSUM(RET_TYPE, ELT_TYPE, FCN) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1472 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1473 octave_idx_type nr = rows (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1474 octave_idx_type nc = cols (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1475 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1476 RET_TYPE retval; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1477 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1478 if (nr > 0 && nc > 0) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1479 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1480 if ((nr == 1 && dim == -1) || dim == 1) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1481 /* Ugly!! Is there a better way? */ \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1482 retval = transpose (). FCN (0) .transpose (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1483 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1484 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1485 octave_idx_type nel = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1486 for (octave_idx_type i = 0; i < nc; i++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1487 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1488 ELT_TYPE t = ELT_TYPE (); \ |
10312
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1489 for (octave_idx_type j = cidx (i); j < cidx (i+1); j++) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1490 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1491 t += data (j); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1492 if (t != ELT_TYPE ()) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1493 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1494 if (j == cidx (i+1) - 1) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1495 nel += nr - ridx (j); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1496 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1497 nel += ridx (j+1) - ridx (j); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1498 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1499 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1500 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1501 retval = RET_TYPE (nr, nc, nel); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1502 retval.cidx (0) = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1503 octave_idx_type ii = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1504 for (octave_idx_type i = 0; i < nc; i++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1505 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1506 ELT_TYPE t = ELT_TYPE (); \ |
10312
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1507 for (octave_idx_type j = cidx (i); j < cidx (i+1); j++) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1508 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1509 t += data (j); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1510 if (t != ELT_TYPE ()) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1511 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1512 if (j == cidx (i+1) - 1) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1513 { \ |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1514 for (octave_idx_type k = ridx (j); k < nr; k++) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1515 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1516 retval.data (ii) = t; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1517 retval.ridx (ii++) = k; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1518 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1519 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1520 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1521 { \ |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1522 for (octave_idx_type k = ridx (j); k < ridx (j+1); k++) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1523 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1524 retval.data (ii) = t; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1525 retval.ridx (ii++) = k; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1526 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1527 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1528 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1529 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1530 retval.cidx (i+1) = ii; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1531 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1532 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1533 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1534 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1535 retval = RET_TYPE (nr,nc); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1536 \ |
5164 | 1537 return retval |
1538 | |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1539 #define SPARSE_CUMPROD(RET_TYPE, ELT_TYPE, FCN) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1540 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1541 octave_idx_type nr = rows (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1542 octave_idx_type nc = cols (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1543 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1544 RET_TYPE retval; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1545 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1546 if (nr > 0 && nc > 0) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1547 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1548 if ((nr == 1 && dim == -1) || dim == 1) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1549 /* Ugly!! Is there a better way? */ \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1550 retval = transpose (). FCN (0) .transpose (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1551 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1552 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1553 octave_idx_type nel = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1554 for (octave_idx_type i = 0; i < nc; i++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1555 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1556 octave_idx_type jj = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1557 for (octave_idx_type j = cidx (i); j < cidx (i+1); j++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1558 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1559 if (jj == ridx (j)) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1560 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1561 nel++; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1562 jj++; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1563 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1564 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1565 break; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1566 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1567 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1568 retval = RET_TYPE (nr, nc, nel); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1569 retval.cidx (0) = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1570 octave_idx_type ii = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1571 for (octave_idx_type i = 0; i < nc; i++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1572 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1573 ELT_TYPE t = ELT_TYPE (1.); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1574 octave_idx_type jj = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1575 for (octave_idx_type j = cidx (i); j < cidx (i+1); j++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1576 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1577 if (jj == ridx (j)) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1578 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1579 t *= data (j); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1580 retval.data (ii) = t; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1581 retval.ridx (ii++) = jj++; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1582 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1583 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1584 break; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1585 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1586 retval.cidx (i+1) = ii; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1587 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1588 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1589 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1590 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1591 retval = RET_TYPE (nr,nc); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1592 \ |
5164 | 1593 return retval |
1594 | |
1595 #define SPARSE_BASE_REDUCTION_OP(RET_TYPE, EL_TYPE, ROW_EXPR, COL_EXPR, \ | |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1596 INIT_VAL, MT_RESULT) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1597 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1598 octave_idx_type nr = rows (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1599 octave_idx_type nc = cols (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1600 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1601 RET_TYPE retval; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1602 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1603 if (nr > 0 && nc > 0) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1604 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1605 if ((nr == 1 && dim == -1) || dim == 1) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1606 { \ |
7269 | 1607 /* Define j here to allow fancy definition for prod method */ \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1608 octave_idx_type j = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1609 OCTAVE_LOCAL_BUFFER (EL_TYPE, tmp, nr); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1610 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1611 for (octave_idx_type i = 0; i < nr; i++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1612 tmp[i] = INIT_VAL; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1613 for (j = 0; j < nc; j++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1614 { \ |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1615 for (octave_idx_type i = cidx (j); i < cidx (j + 1); i++) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1616 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1617 ROW_EXPR; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1618 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1619 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1620 octave_idx_type nel = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1621 for (octave_idx_type i = 0; i < nr; i++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1622 if (tmp[i] != EL_TYPE ()) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1623 nel++; \ |
10312
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1624 retval = RET_TYPE (nr, static_cast<octave_idx_type> (1), nel); \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1625 retval.cidx (0) = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1626 retval.cidx (1) = nel; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1627 nel = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1628 for (octave_idx_type i = 0; i < nr; i++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1629 if (tmp[i] != EL_TYPE ()) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1630 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1631 retval.data (nel) = tmp[i]; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1632 retval.ridx (nel++) = i; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1633 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1634 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1635 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1636 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1637 OCTAVE_LOCAL_BUFFER (EL_TYPE, tmp, nc); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1638 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1639 for (octave_idx_type j = 0; j < nc; j++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1640 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1641 tmp[j] = INIT_VAL; \ |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1642 for (octave_idx_type i = cidx (j); i < cidx (j + 1); i++) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1643 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1644 COL_EXPR; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1645 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1646 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1647 octave_idx_type nel = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1648 for (octave_idx_type i = 0; i < nc; i++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1649 if (tmp[i] != EL_TYPE ()) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1650 nel++; \ |
10312
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1651 retval = RET_TYPE (static_cast<octave_idx_type> (1), nc, nel); \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1652 retval.cidx (0) = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1653 nel = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1654 for (octave_idx_type i = 0; i < nc; i++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1655 if (tmp[i] != EL_TYPE ()) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1656 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1657 retval.data (nel) = tmp[i]; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1658 retval.ridx (nel++) = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1659 retval.cidx (i+1) = retval.cidx (i) + 1; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1660 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1661 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1662 retval.cidx (i+1) = retval.cidx (i); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1663 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1664 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1665 else if (nc == 0 && (nr == 0 || (nr == 1 && dim == -1))) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1666 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1667 if (MT_RESULT) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1668 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1669 retval = RET_TYPE (static_cast<octave_idx_type> (1), \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1670 static_cast<octave_idx_type> (1), \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1671 static_cast<octave_idx_type> (1)); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1672 retval.cidx (0) = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1673 retval.cidx (1) = 1; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1674 retval.ridx (0) = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1675 retval.data (0) = MT_RESULT; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1676 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1677 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1678 retval = RET_TYPE (static_cast<octave_idx_type> (1), \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1679 static_cast<octave_idx_type> (1), \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1680 static_cast<octave_idx_type> (0)); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1681 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1682 else if (nr == 0 && (dim == 0 || dim == -1)) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1683 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1684 if (MT_RESULT) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1685 { \ |
7197 | 1686 retval = RET_TYPE (static_cast<octave_idx_type> (1), nc, nc); \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1687 retval.cidx (0) = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1688 for (octave_idx_type i = 0; i < nc ; i++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1689 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1690 retval.ridx (i) = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1691 retval.cidx (i+1) = i+1; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1692 retval.data (i) = MT_RESULT; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1693 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1694 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1695 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1696 retval = RET_TYPE (static_cast<octave_idx_type> (1), nc, \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1697 static_cast<octave_idx_type> (0)); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1698 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1699 else if (nc == 0 && dim == 1) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1700 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1701 if (MT_RESULT) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1702 { \ |
7197 | 1703 retval = RET_TYPE (nr, static_cast<octave_idx_type> (1), nr); \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1704 retval.cidx (0) = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1705 retval.cidx (1) = nr; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1706 for (octave_idx_type i = 0; i < nr; i++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1707 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1708 retval.ridx (i) = i; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1709 retval.data (i) = MT_RESULT; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1710 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1711 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1712 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1713 retval = RET_TYPE (nr, static_cast<octave_idx_type> (1), \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1714 static_cast<octave_idx_type> (0)); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1715 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1716 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1717 retval.resize (nr > 0, nc > 0); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1718 \ |
5164 | 1719 return retval |
1720 | |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1721 #define SPARSE_REDUCTION_OP_ROW_EXPR(OP) \ |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1722 tmp[ridx (i)] OP data (i) |
5164 | 1723 |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1724 #define SPARSE_REDUCTION_OP_COL_EXPR(OP) \ |
7269 | 1725 tmp[j] OP data (i) |
5164 | 1726 |
10312
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1727 #define SPARSE_REDUCTION_OP(RET_TYPE, EL_TYPE, OP, INIT_VAL, MT_RESULT) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1728 SPARSE_BASE_REDUCTION_OP (RET_TYPE, EL_TYPE, \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1729 SPARSE_REDUCTION_OP_ROW_EXPR (OP), \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1730 SPARSE_REDUCTION_OP_COL_EXPR (OP), \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1731 INIT_VAL, MT_RESULT) |
5164 | 1732 |
7350 | 1733 // Don't break from this loop if the test succeeds because |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1734 // we are looping over the rows and not the columns in the inner loop. |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1735 #define SPARSE_ANY_ALL_OP_ROW_CODE(TEST_OP, TEST_TRUE_VAL) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1736 if (data (i) TEST_OP 0.0) \ |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1737 tmp[ridx (i)] = TEST_TRUE_VAL; |
5164 | 1738 |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1739 #define SPARSE_ANY_ALL_OP_COL_CODE(TEST_OP, TEST_TRUE_VAL) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1740 if (data (i) TEST_OP 0.0) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1741 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1742 tmp[j] = TEST_TRUE_VAL; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1743 break; \ |
5164 | 1744 } |
1745 | |
7269 | 1746 #define SPARSE_ANY_ALL_OP(DIM, INIT_VAL, MT_RESULT, TEST_OP, TEST_TRUE_VAL) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1747 SPARSE_BASE_REDUCTION_OP (SparseBoolMatrix, char, \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1748 SPARSE_ANY_ALL_OP_ROW_CODE (TEST_OP, TEST_TRUE_VAL), \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1749 SPARSE_ANY_ALL_OP_COL_CODE (TEST_OP, TEST_TRUE_VAL), \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1750 INIT_VAL, MT_RESULT) |
5164 | 1751 |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1752 #define SPARSE_ALL_OP(DIM) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1753 if ((rows () == 1 && dim == -1) || dim == 1) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1754 return transpose (). all (0). transpose (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1755 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1756 { \ |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1757 SPARSE_ANY_ALL_OP (DIM, (cidx (j+1) - cidx (j) < nr ? false : true), \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1758 true, ==, false); \ |
7269 | 1759 } |
5164 | 1760 |
7269 | 1761 #define SPARSE_ANY_OP(DIM) SPARSE_ANY_ALL_OP (DIM, false, false, !=, true) |
5164 | 1762 |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1763 #define SPARSE_SPARSE_MUL(RET_TYPE, RET_EL_TYPE, EL_TYPE) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1764 octave_idx_type nr = m.rows (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1765 octave_idx_type nc = m.cols (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1766 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1767 octave_idx_type a_nr = a.rows (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1768 octave_idx_type a_nc = a.cols (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1769 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1770 if (nr == 1 && nc == 1) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1771 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1772 RET_EL_TYPE s = m.elem (0,0); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1773 octave_idx_type nz = a.nnz (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1774 RET_TYPE r (a_nr, a_nc, nz); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1775 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1776 for (octave_idx_type i = 0; i < nz; i++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1777 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1778 octave_quit (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1779 r.data (i) = s * a.data (i); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1780 r.ridx (i) = a.ridx (i); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1781 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1782 for (octave_idx_type i = 0; i < a_nc + 1; i++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1783 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1784 octave_quit (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1785 r.cidx (i) = a.cidx (i); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1786 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1787 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1788 r.maybe_compress (true); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1789 return r; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1790 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1791 else if (a_nr == 1 && a_nc == 1) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1792 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1793 RET_EL_TYPE s = a.elem (0,0); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1794 octave_idx_type nz = m.nnz (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1795 RET_TYPE r (nr, nc, nz); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1796 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1797 for (octave_idx_type i = 0; i < nz; i++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1798 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1799 octave_quit (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1800 r.data (i) = m.data (i) * s; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1801 r.ridx (i) = m.ridx (i); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1802 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1803 for (octave_idx_type i = 0; i < nc + 1; i++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1804 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1805 octave_quit (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1806 r.cidx (i) = m.cidx (i); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1807 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1808 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1809 r.maybe_compress (true); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1810 return r; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1811 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1812 else if (nc != a_nr) \ |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
1813 octave::err_nonconformant ("operator *", nr, nc, a_nr, a_nc); \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1814 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1815 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1816 OCTAVE_LOCAL_BUFFER (octave_idx_type, w, nr); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1817 RET_TYPE retval (nr, a_nc, static_cast<octave_idx_type> (0)); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1818 for (octave_idx_type i = 0; i < nr; i++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1819 w[i] = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1820 retval.xcidx (0) = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1821 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1822 octave_idx_type nel = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1823 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1824 for (octave_idx_type i = 0; i < a_nc; i++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1825 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1826 for (octave_idx_type j = a.cidx (i); j < a.cidx (i+1); j++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1827 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1828 octave_idx_type col = a.ridx (j); \ |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1829 for (octave_idx_type k = m.cidx (col) ; k < m.cidx (col+1); k++) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1830 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1831 if (w[m.ridx (k)] < i + 1) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1832 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1833 w[m.ridx (k)] = i + 1; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1834 nel++; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1835 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1836 octave_quit (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1837 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1838 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1839 retval.xcidx (i+1) = nel; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1840 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1841 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1842 if (nel == 0) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1843 return RET_TYPE (nr, a_nc); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1844 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1845 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1846 for (octave_idx_type i = 0; i < nr; i++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1847 w[i] = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1848 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1849 OCTAVE_LOCAL_BUFFER (RET_EL_TYPE, Xcol, nr); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1850 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1851 retval.change_capacity (nel); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1852 /* The optimal break-point as estimated from simulations */ \ |
10312
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1853 /* Note that Mergesort is O(nz log(nz)) while searching all */ \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1854 /* values is O(nr), where nz here is nonzero per row of */ \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1855 /* length nr. The test itself was then derived from the */ \ |
10312
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1856 /* simulation with random square matrices and the observation */ \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1857 /* of the number of nonzero elements in the output matrix */ \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1858 /* it was found that the breakpoints were */ \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1859 /* nr: 500 1000 2000 5000 10000 */ \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1860 /* nz: 6 25 97 585 2202 */ \ |
10312
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1861 /* The below is a simplication of the 'polyfit'-ed parameters */ \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1862 /* to these breakpoints */ \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1863 octave_idx_type n_per_col = (a_nc > 43000 ? 43000 : \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1864 (a_nc * a_nc) / 43000); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1865 octave_idx_type ii = 0; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1866 octave_idx_type *ri = retval.xridx (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1867 octave_sort<octave_idx_type> sort; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1868 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1869 for (octave_idx_type i = 0; i < a_nc ; i++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1870 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1871 if (retval.xcidx (i+1) - retval.xcidx (i) > n_per_col) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1872 { \ |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1873 for (octave_idx_type j = a.cidx (i); j < a.cidx (i+1); j++) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1874 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1875 octave_idx_type col = a.ridx (j); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1876 EL_TYPE tmpval = a.data (j); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1877 for (octave_idx_type k = m.cidx (col) ; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1878 k < m.cidx (col+1); k++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1879 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1880 octave_quit (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1881 octave_idx_type row = m.ridx (k); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1882 if (w[row] < i + 1) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1883 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1884 w[row] = i + 1; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1885 Xcol[row] = tmpval * m.data (k); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1886 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1887 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1888 Xcol[row] += tmpval * m.data (k); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1889 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1890 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1891 for (octave_idx_type k = 0; k < nr; k++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1892 if (w[k] == i + 1) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1893 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1894 retval.xdata (ii) = Xcol[k]; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1895 retval.xridx (ii++) = k; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1896 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1897 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1898 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1899 { \ |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1900 for (octave_idx_type j = a.cidx (i); j < a.cidx (i+1); j++) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1901 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1902 octave_idx_type col = a.ridx (j); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1903 EL_TYPE tmpval = a.data (j); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1904 for (octave_idx_type k = m.cidx (col) ; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1905 k < m.cidx (col+1); k++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1906 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1907 octave_quit (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1908 octave_idx_type row = m.ridx (k); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1909 if (w[row] < i + 1) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1910 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1911 w[row] = i + 1; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1912 retval.xridx (ii++) = row; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1913 Xcol[row] = tmpval * m.data (k); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1914 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1915 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1916 Xcol[row] += tmpval * m.data (k); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1917 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1918 } \ |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1919 sort.sort (ri + retval.xcidx (i), ii - retval.xcidx (i)); \ |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1920 for (octave_idx_type k = retval.xcidx (i); k < ii; k++) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1921 retval.xdata (k) = Xcol[retval.xridx (k)]; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1922 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1923 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1924 retval.maybe_compress (true); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1925 return retval; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1926 } \ |
5164 | 1927 } |
1928 | |
25665
dc073ccde64e
eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents:
25664
diff
changeset
|
1929 #define SPARSE_FULL_MUL(RET_TYPE, EL_TYPE) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1930 octave_idx_type nr = m.rows (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1931 octave_idx_type nc = m.cols (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1932 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1933 octave_idx_type a_nr = a.rows (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1934 octave_idx_type a_nc = a.cols (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1935 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1936 if (nr == 1 && nc == 1) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1937 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1938 RET_TYPE retval = m.elem (0,0) * a; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1939 return retval; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1940 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1941 else if (nc != a_nr) \ |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
1942 octave::err_nonconformant ("operator *", nr, nc, a_nr, a_nc); \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1943 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1944 { \ |
25665
dc073ccde64e
eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents:
25664
diff
changeset
|
1945 RET_TYPE::element_type zero = RET_TYPE::element_type (); \ |
dc073ccde64e
eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents:
25664
diff
changeset
|
1946 \ |
dc073ccde64e
eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents:
25664
diff
changeset
|
1947 RET_TYPE retval (nr, a_nc, zero); \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1948 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1949 for (octave_idx_type i = 0; i < a_nc ; i++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1950 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1951 for (octave_idx_type j = 0; j < a_nr; j++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1952 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1953 octave_quit (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1954 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1955 EL_TYPE tmpval = a.elem (j,i); \ |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1956 for (octave_idx_type k = m.cidx (j) ; k < m.cidx (j+1); k++) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1957 retval.elem (m.ridx (k),i) += tmpval * m.data (k); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1958 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1959 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1960 return retval; \ |
7802
1a446f28ce68
implement optimized sparse-dense transposed multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
7350
diff
changeset
|
1961 } |
1a446f28ce68
implement optimized sparse-dense transposed multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
7350
diff
changeset
|
1962 |
25665
dc073ccde64e
eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents:
25664
diff
changeset
|
1963 #define SPARSE_FULL_TRANS_MUL(RET_TYPE, EL_TYPE, CONJ_OP) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1964 octave_idx_type nr = m.rows (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1965 octave_idx_type nc = m.cols (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1966 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1967 octave_idx_type a_nr = a.rows (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1968 octave_idx_type a_nc = a.cols (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1969 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1970 if (nr == 1 && nc == 1) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1971 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1972 RET_TYPE retval = CONJ_OP (m.elem (0,0)) * a; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1973 return retval; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1974 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1975 else if (nr != a_nr) \ |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
1976 octave::err_nonconformant ("operator *", nc, nr, a_nr, a_nc); \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1977 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1978 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1979 RET_TYPE retval (nc, a_nc); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1980 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1981 for (octave_idx_type i = 0; i < a_nc ; i++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1982 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1983 for (octave_idx_type j = 0; j < nc; j++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1984 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1985 octave_quit (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1986 \ |
25665
dc073ccde64e
eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents:
25664
diff
changeset
|
1987 EL_TYPE acc = EL_TYPE (); \ |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1988 for (octave_idx_type k = m.cidx (j) ; k < m.cidx (j+1); k++) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1989 acc += a.elem (m.ridx (k),i) * CONJ_OP (m.data (k)); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1990 retval.xelem (j,i) = acc; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1991 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1992 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1993 return retval; \ |
5429 | 1994 } |
1995 | |
25665
dc073ccde64e
eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents:
25664
diff
changeset
|
1996 #define FULL_SPARSE_MUL(RET_TYPE, EL_TYPE) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1997 octave_idx_type nr = m.rows (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1998 octave_idx_type nc = m.cols (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1999 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
2000 octave_idx_type a_nr = a.rows (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
2001 octave_idx_type a_nc = a.cols (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
2002 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
2003 if (a_nr == 1 && a_nc == 1) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
2004 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
2005 RET_TYPE retval = m * a.elem (0,0); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
2006 return retval; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
2007 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
2008 else if (nc != a_nr) \ |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2009 octave::err_nonconformant ("operator *", nr, nc, a_nr, a_nc); \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
2010 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
2011 { \ |
25665
dc073ccde64e
eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents:
25664
diff
changeset
|
2012 RET_TYPE::element_type zero = RET_TYPE::element_type (); \ |
dc073ccde64e
eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents:
25664
diff
changeset
|
2013 \ |
dc073ccde64e
eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents:
25664
diff
changeset
|
2014 RET_TYPE retval (nr, a_nc, zero); \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
2015 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
2016 for (octave_idx_type i = 0; i < a_nc ; i++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
2017 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
2018 octave_quit (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
2019 for (octave_idx_type j = a.cidx (i); j < a.cidx (i+1); j++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
2020 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
2021 octave_idx_type col = a.ridx (j); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
2022 EL_TYPE tmpval = a.data (j); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
2023 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
2024 for (octave_idx_type k = 0 ; k < nr; k++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
2025 retval.xelem (k,i) += tmpval * m.elem (k,col); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
2026 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
2027 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
2028 return retval; \ |
7802
1a446f28ce68
implement optimized sparse-dense transposed multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
7350
diff
changeset
|
2029 } |
1a446f28ce68
implement optimized sparse-dense transposed multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
7350
diff
changeset
|
2030 |
25665
dc073ccde64e
eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents:
25664
diff
changeset
|
2031 #define FULL_SPARSE_MUL_TRANS(RET_TYPE, EL_TYPE, CONJ_OP) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
2032 octave_idx_type nr = m.rows (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
2033 octave_idx_type nc = m.cols (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
2034 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
2035 octave_idx_type a_nr = a.rows (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
2036 octave_idx_type a_nc = a.cols (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
2037 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
2038 if (a_nr == 1 && a_nc == 1) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
2039 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
2040 RET_TYPE retval = m * CONJ_OP (a.elem (0,0)); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
2041 return retval; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
2042 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
2043 else if (nc != a_nc) \ |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
2044 octave::err_nonconformant ("operator *", nr, nc, a_nc, a_nr); \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
2045 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
2046 { \ |
25665
dc073ccde64e
eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents:
25664
diff
changeset
|
2047 RET_TYPE::element_type zero = RET_TYPE::element_type (); \ |
dc073ccde64e
eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents:
25664
diff
changeset
|
2048 \ |
dc073ccde64e
eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents:
25664
diff
changeset
|
2049 RET_TYPE retval (nr, a_nr, zero); \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
2050 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
2051 for (octave_idx_type i = 0; i < a_nc ; i++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
2052 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
2053 octave_quit (); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
2054 for (octave_idx_type j = a.cidx (i); j < a.cidx (i+1); j++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
2055 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
2056 octave_idx_type col = a.ridx (j); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
2057 EL_TYPE tmpval = CONJ_OP (a.data (j)); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
2058 for (octave_idx_type k = 0 ; k < nr; k++) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
2059 retval.xelem (k,col) += tmpval * m.elem (k,i); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
2060 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
2061 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
2062 return retval; \ |
5429 | 2063 } |
2064 | |
5164 | 2065 #endif |