Mercurial > jwe > octave
annotate liboctave/array/MSparse.cc @ 21139:538b57866b90
consistently use "typename" intead of "class" in template declarations
* Object.h, QtHandlesUtils.cc, QtHandlesUtils.h, ToolBarButton.cc,
ToolBarButton.h, Cell.h, __lin_interpn__.cc, bitfcns.cc, bsxfun.cc,
cellfun.cc, data.cc, filter.cc, gcd.cc, graphics.cc, help.cc, kron.cc,
lookup.cc, ls-mat5.cc, ls-oct-text.h, lu.cc, max.cc, mgorth.cc,
oct-map.cc, oct-map.h, oct-stream.cc, oct-stream.h, octave-link.h,
pr-output.cc, profiler.h, schur.cc, sparse-xdiv.cc, sparse-xpow.cc,
sqrtm.cc, symtab.h, tril.cc, typecast.cc, variables.cc, xdiv.cc,
zfstream.h, __init_fltk__.cc, __magick_read__.cc, chol.cc, qr.cc,
ov-base-diag.cc, ov-base-diag.h, ov-base-int.cc, ov-base-int.h,
ov-base-mat.cc, ov-base-mat.h, ov-base-scalar.cc, ov-base-scalar.h,
ov-base-sparse.cc, ov-base-sparse.h, ov-base.h, ov-classdef.cc,
ov-int-traits.h, ov-java.h, ov-usr-fcn.h, ov.cc, ov.h,
op-dms-template.cc, oct-parse.in.yy, parse.h, pt-mat.cc, Array-b.cc,
Array.cc, Array.h, CDiagMatrix.h, CMatrix.h, CNDArray.h,
DiagArray2.cc, DiagArray2.h, MArray.cc, MArray.h, MDiagArray2.cc,
MDiagArray2.h, MSparse.cc, MSparse.h, MatrixType.cc, Sparse.cc,
Sparse.h, dDiagMatrix.h, dMatrix.h, dNDArray.h, fCDiagMatrix.h,
fCMatrix.h, fCNDArray.h, fDiagMatrix.h, fMatrix.h, fNDArray.h,
idx-vector.cc, idx-vector.h, intNDArray.cc, intNDArray.h, DET.h,
base-aepbal.h, base-lu.cc, base-lu.h, base-qr.cc, base-qr.h,
bsxfun-defs.cc, eigs-base.cc, lo-mappers.h, lo-specfun.cc,
lo-specfun.h, oct-convn.cc, oct-fftw.cc, oct-norm.cc,
sparse-base-chol.cc, sparse-base-chol.h, sparse-base-lu.cc,
sparse-base-lu.h, sparse-dmsolve.cc, mx-inlines.cc,
action-container.h, base-list.h, lo-traits.h, lo-utils.h,
oct-base64.h, oct-binmap.h, oct-cmplx.h, oct-inttypes.cc,
oct-inttypes.h, oct-locbuf.h, oct-refcount.h, oct-sort.cc, oct-sort.h:
Use "typename" instead of "class" in template declarations.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sun, 24 Jan 2016 13:50:04 -0500 |
parents | 499b851fbfae |
children | 6c2fd62db1f7 |
rev | line source |
---|---|
5164 | 1 /* |
2 | |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
18678
diff
changeset
|
3 Copyright (C) 2004-2015 David Bateman |
11523 | 4 Copyright (C) 1998-2004 Andy Adler |
7016 | 5 |
6 This file is part of Octave. | |
5164 | 7 |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
5164 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
5164 | 21 |
22 */ | |
23 | |
24 // sparse array with math ops. | |
25 | |
26 // Element by element MSparse by MSparse ops. | |
27 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21120
diff
changeset
|
28 template <typename T, typename OP> |
5164 | 29 MSparse<T>& |
13264
11c8b60f1b68
Eliminate duplicate code for op+= and op-= for MSparse
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11586
diff
changeset
|
30 plus_or_minus (MSparse<T>& a, const MSparse<T>& b, OP op, const char* op_name) |
5164 | 31 { |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
32 MSparse<T> r; |
5164 | 33 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
34 octave_idx_type a_nr = a.rows (); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
35 octave_idx_type a_nc = a.cols (); |
5164 | 36 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
37 octave_idx_type b_nr = b.rows (); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
38 octave_idx_type b_nc = b.cols (); |
5164 | 39 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
40 if (a_nr != b_nr || a_nc != b_nc) |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
20506
diff
changeset
|
41 err_nonconformant (op_name , a_nr, a_nc, b_nr, b_nc); |
21120
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
42 |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
43 r = MSparse<T> (a_nr, a_nc, (a.nnz () + b.nnz ())); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
44 |
21120
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
45 octave_idx_type jx = 0; |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
46 for (octave_idx_type i = 0 ; i < a_nc ; i++) |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
47 { |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
48 octave_idx_type ja = a.cidx (i); |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
49 octave_idx_type ja_max = a.cidx (i+1); |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
50 bool ja_lt_max= ja < ja_max; |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
51 |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
52 octave_idx_type jb = b.cidx (i); |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
53 octave_idx_type jb_max = b.cidx (i+1); |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
54 bool jb_lt_max = jb < jb_max; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
55 |
21120
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
56 while (ja_lt_max || jb_lt_max) |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
57 { |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
58 octave_quit (); |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
59 if ((! jb_lt_max) || (ja_lt_max && (a.ridx (ja) < b.ridx (jb)))) |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
60 { |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
61 r.ridx (jx) = a.ridx (ja); |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
62 r.data (jx) = op (a.data (ja), 0.); |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
63 jx++; |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
64 ja++; |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
65 ja_lt_max= ja < ja_max; |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
66 } |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
67 else if ((! ja_lt_max) |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
68 || (jb_lt_max && (b.ridx (jb) < a.ridx (ja)))) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
69 { |
21120
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
70 r.ridx (jx) = b.ridx (jb); |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
71 r.data (jx) = op (0., b.data (jb)); |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
72 jx++; |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
73 jb++; |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
74 jb_lt_max= jb < jb_max; |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
75 } |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
76 else |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
77 { |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
78 if (op (a.data (ja), b.data (jb)) != 0.) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
79 { |
21120
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
80 r.data (jx) = op (a.data (ja), b.data (jb)); |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
81 r.ridx (jx) = a.ridx (ja); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
82 jx++; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
83 } |
21120
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
84 ja++; |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
85 ja_lt_max= ja < ja_max; |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
86 jb++; |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
87 jb_lt_max= jb < jb_max; |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
88 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
89 } |
21120
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
90 r.cidx (i+1) = jx; |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
91 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
92 |
21120
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
93 a = r.maybe_compress (); |
5164 | 94 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
95 return a; |
5164 | 96 } |
97 | |
13264
11c8b60f1b68
Eliminate duplicate code for op+= and op-= for MSparse
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11586
diff
changeset
|
98 template <typename T> |
11c8b60f1b68
Eliminate duplicate code for op+= and op-= for MSparse
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11586
diff
changeset
|
99 MSparse<T>& |
11c8b60f1b68
Eliminate duplicate code for op+= and op-= for MSparse
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11586
diff
changeset
|
100 operator += (MSparse<T>& a, const MSparse<T>& b) |
11c8b60f1b68
Eliminate duplicate code for op+= and op-= for MSparse
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11586
diff
changeset
|
101 { |
11c8b60f1b68
Eliminate duplicate code for op+= and op-= for MSparse
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11586
diff
changeset
|
102 return plus_or_minus (a, b, std::plus<T> (), "operator +="); |
11c8b60f1b68
Eliminate duplicate code for op+= and op-= for MSparse
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11586
diff
changeset
|
103 } |
11c8b60f1b68
Eliminate duplicate code for op+= and op-= for MSparse
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11586
diff
changeset
|
104 |
11c8b60f1b68
Eliminate duplicate code for op+= and op-= for MSparse
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11586
diff
changeset
|
105 template <typename T> |
5164 | 106 MSparse<T>& |
107 operator -= (MSparse<T>& a, const MSparse<T>& b) | |
108 { | |
13264
11c8b60f1b68
Eliminate duplicate code for op+= and op-= for MSparse
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11586
diff
changeset
|
109 return plus_or_minus (a, b, std::minus<T> (), "operator -="); |
11c8b60f1b68
Eliminate duplicate code for op+= and op-= for MSparse
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11586
diff
changeset
|
110 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
111 |
5164 | 112 |
113 // Element by element MSparse by scalar ops. | |
114 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21120
diff
changeset
|
115 template <typename T, typename OP> |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
116 MArray<T> |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
117 plus_or_minus (const MSparse<T>& a, const T& s, OP op) |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
118 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
119 octave_idx_type nr = a.rows (); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
120 octave_idx_type nc = a.cols (); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
121 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
122 MArray<T> r (dim_vector (nr, nc), op (0.0, s)); |
5164 | 123 |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
124 for (octave_idx_type j = 0; j < nc; j++) |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
125 for (octave_idx_type i = a.cidx (j); i < a.cidx (j+1); i++) |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
126 r.elem (a.ridx (i), j) = op (a.data (i), s); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
127 return r; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
128 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
129 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
130 template <typename T> |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
131 MArray<T> |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
132 operator + (const MSparse<T>& a, const T& s) |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
133 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
134 return plus_or_minus (a, s, std::plus<T> ()); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
135 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
136 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
137 template <typename T> |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
138 MArray<T> |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
139 operator - (const MSparse<T>& a, const T& s) |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
140 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
141 return plus_or_minus (a, s, std::minus<T> ()); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
142 } |
5164 | 143 |
144 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21120
diff
changeset
|
145 template <typename T, typename OP> |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
146 MSparse<T> |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
147 times_or_divide (const MSparse<T>& a, const T& s, OP op) |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
148 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
149 octave_idx_type nr = a.rows (); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
150 octave_idx_type nc = a.cols (); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
151 octave_idx_type nz = a.nnz (); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
152 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
153 MSparse<T> r (nr, nc, nz); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
154 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
155 for (octave_idx_type i = 0; i < nz; i++) |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
156 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
157 r.data (i) = op (a.data (i), s); |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
158 r.ridx (i) = a.ridx (i); |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
159 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
160 for (octave_idx_type i = 0; i < nc + 1; i++) |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
161 r.cidx (i) = a.cidx (i); |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
162 r.maybe_compress (true); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
163 return r; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
164 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
165 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
166 template <typename T> |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
167 MSparse<T> |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
168 operator * (const MSparse<T>& a, const T& s) |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
169 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
170 return times_or_divide (a, s, std::multiplies<T> ()); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
171 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
172 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
173 template <typename T> |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
174 MSparse<T> |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
175 operator / (const MSparse<T>& a, const T& s) |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
176 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
177 return times_or_divide (a, s, std::divides<T> ()); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
178 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
179 |
5164 | 180 |
181 // Element by element scalar by MSparse ops. | |
182 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21120
diff
changeset
|
183 template <typename T, typename OP> |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
184 MArray<T> |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
185 plus_or_minus (const T& s, const MSparse<T>& a, OP op) |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
186 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
187 octave_idx_type nr = a.rows (); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
188 octave_idx_type nc = a.cols (); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
189 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
190 MArray<T> r (dim_vector (nr, nc), op (s, 0.0)); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
191 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
192 for (octave_idx_type j = 0; j < nc; j++) |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
193 for (octave_idx_type i = a.cidx (j); i < a.cidx (j+1); i++) |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
194 r.elem (a.ridx (i), j) = op (s, a.data (i)); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
195 return r; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
196 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
197 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
198 template <typename T> |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
199 MArray<T> |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
200 operator + (const T& s, const MSparse<T>& a) |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
201 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
202 return plus_or_minus (s, a, std::plus<T> ()); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
203 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
204 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
205 template <typename T> |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
206 MArray<T> |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
207 operator - (const T& s, const MSparse<T>& a) |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
208 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
209 return plus_or_minus (s, a, std::minus<T> ()); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
210 } |
5164 | 211 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21120
diff
changeset
|
212 template <typename T, typename OP> |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
213 MSparse<T> |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
214 times_or_divides (const T& s, const MSparse<T>& a, OP op) |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
215 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
216 octave_idx_type nr = a.rows (); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
217 octave_idx_type nc = a.cols (); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
218 octave_idx_type nz = a.nnz (); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
219 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
220 MSparse<T> r (nr, nc, nz); |
5164 | 221 |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
222 for (octave_idx_type i = 0; i < nz; i++) |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
223 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
224 r.data (i) = op (s, a.data (i)); |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
225 r.ridx (i) = a.ridx (i); |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
226 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
227 for (octave_idx_type i = 0; i < nc + 1; i++) |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
228 r.cidx (i) = a.cidx (i); |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
229 r.maybe_compress (true); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
230 return r; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
231 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
232 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21120
diff
changeset
|
233 template <typename T> |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
234 MSparse<T> |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
235 operator * (const T& s, const MSparse<T>& a) |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
236 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
237 return times_or_divides (s, a, std::multiplies<T> ()); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
238 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
239 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21120
diff
changeset
|
240 template <typename T> |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
241 MSparse<T> |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
242 operator / (const T& s, const MSparse<T>& a) |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
243 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
244 return times_or_divides (s, a, std::divides<T> ()); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
245 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
246 |
5164 | 247 |
248 // Element by element MSparse by MSparse ops. | |
249 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21120
diff
changeset
|
250 template <typename T, typename OP> |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
251 MSparse<T> |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
252 plus_or_minus (const MSparse<T>& a, const MSparse<T>& b, OP op, |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
253 const char* op_name, bool negate) |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
254 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
255 MSparse<T> r; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
256 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
257 octave_idx_type a_nr = a.rows (); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
258 octave_idx_type a_nc = a.cols (); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
259 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
260 octave_idx_type b_nr = b.rows (); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
261 octave_idx_type b_nc = b.cols (); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
262 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
263 if (a_nr == 1 && a_nc == 1) |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
264 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
265 if (a.elem (0,0) == 0.) |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
266 if (negate) |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
267 r = -MSparse<T> (b); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
268 else |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
269 r = MSparse<T> (b); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
270 else |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
271 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
272 r = MSparse<T> (b_nr, b_nc, op (a.data (0), 0.)); |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
273 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
274 for (octave_idx_type j = 0 ; j < b_nc ; j++) |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
275 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
276 octave_quit (); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
277 octave_idx_type idxj = j * b_nr; |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
278 for (octave_idx_type i = b.cidx (j) ; i < b.cidx (j+1) ; i++) |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
279 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
280 octave_quit (); |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
281 r.data (idxj + b.ridx (i)) = op (a.data (0), b.data (i)); |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
282 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
283 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
284 r.maybe_compress (); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
285 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
286 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
287 else if (b_nr == 1 && b_nc == 1) |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
288 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
289 if (b.elem (0,0) == 0.) |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
290 r = MSparse<T> (a); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
291 else |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
292 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
293 r = MSparse<T> (a_nr, a_nc, op (0.0, b.data (0))); |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
294 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
295 for (octave_idx_type j = 0 ; j < a_nc ; j++) |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
296 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
297 octave_quit (); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
298 octave_idx_type idxj = j * a_nr; |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
299 for (octave_idx_type i = a.cidx (j) ; i < a.cidx (j+1) ; i++) |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
300 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
301 octave_quit (); |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
302 r.data (idxj + a.ridx (i)) = op (a.data (i), b.data (0)); |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
303 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
304 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
305 r.maybe_compress (); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
306 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
307 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
308 else if (a_nr != b_nr || a_nc != b_nc) |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
20506
diff
changeset
|
309 err_nonconformant (op_name, a_nr, a_nc, b_nr, b_nc); |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
310 else |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
311 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
312 r = MSparse<T> (a_nr, a_nc, (a.nnz () + b.nnz ())); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
313 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
314 octave_idx_type jx = 0; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
315 r.cidx (0) = 0; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
316 for (octave_idx_type i = 0 ; i < a_nc ; i++) |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
317 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
318 octave_idx_type ja = a.cidx (i); |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
319 octave_idx_type ja_max = a.cidx (i+1); |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
320 bool ja_lt_max= ja < ja_max; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
321 |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
322 octave_idx_type jb = b.cidx (i); |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
323 octave_idx_type jb_max = b.cidx (i+1); |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
324 bool jb_lt_max = jb < jb_max; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
325 |
18678
6113e0c6920b
maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
326 while (ja_lt_max || jb_lt_max) |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
327 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
328 octave_quit (); |
19864
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
329 if ((! jb_lt_max) || (ja_lt_max && (a.ridx (ja) < b.ridx (jb)))) |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
330 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
331 r.ridx (jx) = a.ridx (ja); |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
332 r.data (jx) = op (a.data (ja), 0.); |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
333 jx++; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
334 ja++; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
335 ja_lt_max= ja < ja_max; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
336 } |
19864
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
337 else if ((! ja_lt_max) |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
338 || (jb_lt_max && (b.ridx (jb) < a.ridx (ja)))) |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
339 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
340 r.ridx (jx) = b.ridx (jb); |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
341 r.data (jx) = op (0., b.data (jb)); |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
342 jx++; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
343 jb++; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
344 jb_lt_max= jb < jb_max; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
345 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
346 else |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
347 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
348 if (op (a.data (ja), b.data (jb)) != 0.) |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
349 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
350 r.data (jx) = op (a.data (ja), b.data (jb)); |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
351 r.ridx (jx) = a.ridx (ja); |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
352 jx++; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
353 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
354 ja++; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
355 ja_lt_max= ja < ja_max; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
356 jb++; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
357 jb_lt_max= jb < jb_max; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
358 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
359 } |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
360 r.cidx (i+1) = jx; |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
361 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
362 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
363 r.maybe_compress (); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
364 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
365 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
366 return r; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
367 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
368 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21120
diff
changeset
|
369 template <typename T> |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
370 MSparse<T> |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
371 operator+ (const MSparse<T>& a, const MSparse<T>& b) |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
372 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
373 return plus_or_minus (a, b, std::plus<T> (), "operator +", false); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
374 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
375 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21120
diff
changeset
|
376 template <typename T> |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
377 MSparse<T> |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
378 operator- (const MSparse<T>& a, const MSparse<T>& b) |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
379 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
380 return plus_or_minus (a, b, std::minus<T> (), "operator -", true); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
381 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
382 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21120
diff
changeset
|
383 template <typename T> |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
384 MSparse<T> |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
385 product (const MSparse<T>& a, const MSparse<T>& b) |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
386 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
387 MSparse<T> r; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
388 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
389 octave_idx_type a_nr = a.rows (); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
390 octave_idx_type a_nc = a.cols (); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
391 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
392 octave_idx_type b_nr = b.rows (); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
393 octave_idx_type b_nc = b.cols (); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
394 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
395 if (a_nr == 1 && a_nc == 1) |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
396 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
397 if (a.elem (0,0) == 0.) |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
398 r = MSparse<T> (b_nr, b_nc); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
399 else |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
400 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
401 r = MSparse<T> (b); |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
402 octave_idx_type b_nnz = b.nnz (); |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
403 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
404 for (octave_idx_type i = 0 ; i < b_nnz ; i++) |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
405 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
406 octave_quit (); |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
407 r.data (i) = a.data (0) * r.data (i); |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
408 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
409 r.maybe_compress (); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
410 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
411 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
412 else if (b_nr == 1 && b_nc == 1) |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
413 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
414 if (b.elem (0,0) == 0.) |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
415 r = MSparse<T> (a_nr, a_nc); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
416 else |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
417 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
418 r = MSparse<T> (a); |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
419 octave_idx_type a_nnz = a.nnz (); |
5164 | 420 |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
421 for (octave_idx_type i = 0 ; i < a_nnz ; i++) |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
422 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
423 octave_quit (); |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
424 r.data (i) = r.data (i) * b.data (0); |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
425 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
426 r.maybe_compress (); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
427 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
428 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
429 else if (a_nr != b_nr || a_nc != b_nc) |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
20506
diff
changeset
|
430 err_nonconformant ("product", a_nr, a_nc, b_nr, b_nc); |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
431 else |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
432 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
433 r = MSparse<T> (a_nr, a_nc, (a.nnz () > b.nnz () ? a.nnz () : b.nnz ())); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
434 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
435 octave_idx_type jx = 0; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
436 r.cidx (0) = 0; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
437 for (octave_idx_type i = 0 ; i < a_nc ; i++) |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
438 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
439 octave_idx_type ja = a.cidx (i); |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
440 octave_idx_type ja_max = a.cidx (i+1); |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
441 bool ja_lt_max= ja < ja_max; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
442 |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
443 octave_idx_type jb = b.cidx (i); |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
444 octave_idx_type jb_max = b.cidx (i+1); |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
445 bool jb_lt_max = jb < jb_max; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
446 |
18678
6113e0c6920b
maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
447 while (ja_lt_max || jb_lt_max) |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
448 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
449 octave_quit (); |
19864
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
450 if ((! jb_lt_max) || (ja_lt_max && (a.ridx (ja) < b.ridx (jb)))) |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
451 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
452 ja++; ja_lt_max= ja < ja_max; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
453 } |
19864
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
454 else if ((! ja_lt_max) |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
455 || (jb_lt_max && (b.ridx (jb) < a.ridx (ja)))) |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
456 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
457 jb++; jb_lt_max= jb < jb_max; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
458 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
459 else |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
460 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
461 if ((a.data (ja) * b.data (jb)) != 0.) |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
462 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
463 r.data (jx) = a.data (ja) * b.data (jb); |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
464 r.ridx (jx) = a.ridx (ja); |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
465 jx++; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
466 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
467 ja++; ja_lt_max= ja < ja_max; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
468 jb++; jb_lt_max= jb < jb_max; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
469 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
470 } |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
471 r.cidx (i+1) = jx; |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
472 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
473 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
474 r.maybe_compress (); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
475 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
476 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
477 return r; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
478 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
479 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21120
diff
changeset
|
480 template <typename T> |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
481 MSparse<T> |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
482 quotient (const MSparse<T>& a, const MSparse<T>& b) |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
483 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
484 MSparse<T> r; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
485 T Zero = T (); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
486 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
487 octave_idx_type a_nr = a.rows (); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
488 octave_idx_type a_nc = a.cols (); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
489 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
490 octave_idx_type b_nr = b.rows (); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
491 octave_idx_type b_nc = b.cols (); |
5164 | 492 |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
493 if (a_nr == 1 && a_nc == 1) |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
494 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
495 T val = a.elem (0,0); |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
496 T fill = val / T (); |
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
497 if (fill == T ()) |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
498 { |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
499 octave_idx_type b_nnz = b.nnz (); |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
500 r = MSparse<T> (b); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
501 for (octave_idx_type i = 0 ; i < b_nnz ; i++) |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
502 r.data (i) = val / r.data (i); |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
503 r.maybe_compress (); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
504 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
505 else |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
506 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
507 r = MSparse<T> (b_nr, b_nc, fill); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
508 for (octave_idx_type j = 0 ; j < b_nc ; j++) |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
509 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
510 octave_quit (); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
511 octave_idx_type idxj = j * b_nr; |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
512 for (octave_idx_type i = b.cidx (j) ; i < b.cidx (j+1) ; i++) |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
513 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
514 octave_quit (); |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
515 r.data (idxj + b.ridx (i)) = val / b.data (i); |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
516 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
517 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
518 r.maybe_compress (); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
519 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
520 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
521 else if (b_nr == 1 && b_nc == 1) |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
522 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
523 T val = b.elem (0,0); |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
524 T fill = T () / val; |
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
525 if (fill == T ()) |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
526 { |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
527 octave_idx_type a_nnz = a.nnz (); |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
528 r = MSparse<T> (a); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
529 for (octave_idx_type i = 0 ; i < a_nnz ; i++) |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
530 r.data (i) = r.data (i) / val; |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
531 r.maybe_compress (); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
532 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
533 else |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
534 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
535 r = MSparse<T> (a_nr, a_nc, fill); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
536 for (octave_idx_type j = 0 ; j < a_nc ; j++) |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
537 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
538 octave_quit (); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
539 octave_idx_type idxj = j * a_nr; |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
540 for (octave_idx_type i = a.cidx (j) ; i < a.cidx (j+1) ; i++) |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
541 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
542 octave_quit (); |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
543 r.data (idxj + a.ridx (i)) = a.data (i) / val; |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
544 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
545 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
546 r.maybe_compress (); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
547 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
548 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
549 else if (a_nr != b_nr || a_nc != b_nc) |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
20506
diff
changeset
|
550 err_nonconformant ("quotient", a_nr, a_nc, b_nr, b_nc); |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
551 else |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
552 { |
18678
6113e0c6920b
maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
553 r = MSparse<T> (a_nr, a_nc, (Zero / Zero)); |
5164 | 554 |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
555 for (octave_idx_type i = 0 ; i < a_nc ; i++) |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
556 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
557 octave_idx_type ja = a.cidx (i); |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
558 octave_idx_type ja_max = a.cidx (i+1); |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
559 bool ja_lt_max= ja < ja_max; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
560 |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
561 octave_idx_type jb = b.cidx (i); |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
562 octave_idx_type jb_max = b.cidx (i+1); |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
563 bool jb_lt_max = jb < jb_max; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
564 |
18678
6113e0c6920b
maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
565 while (ja_lt_max || jb_lt_max) |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
566 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
567 octave_quit (); |
19864
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
568 if ((! jb_lt_max) || (ja_lt_max && (a.ridx (ja) < b.ridx (jb)))) |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
569 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
570 r.elem (a.ridx (ja),i) = a.data (ja) / Zero; |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
571 ja++; ja_lt_max= ja < ja_max; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
572 } |
19864
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
573 else if ((! ja_lt_max) |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
574 || (jb_lt_max && (b.ridx (jb) < a.ridx (ja)))) |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
575 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
576 r.elem (b.ridx (jb),i) = Zero / b.data (jb); |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
577 jb++; jb_lt_max= jb < jb_max; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
578 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
579 else |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
580 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
581 r.elem (a.ridx (ja),i) = a.data (ja) / b.data (jb); |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
582 ja++; ja_lt_max= ja < ja_max; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
583 jb++; jb_lt_max= jb < jb_max; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
584 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
585 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
586 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
587 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
588 r.maybe_compress (true); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
589 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
590 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
591 return r; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
592 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
593 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
594 |
5164 | 595 |
596 // Unary MSparse ops. | |
597 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21120
diff
changeset
|
598 template <typename T> |
5164 | 599 MSparse<T> |
600 operator + (const MSparse<T>& a) | |
601 { | |
602 return a; | |
603 } | |
604 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21120
diff
changeset
|
605 template <typename T> |
5164 | 606 MSparse<T> |
607 operator - (const MSparse<T>& a) | |
608 { | |
609 MSparse<T> retval (a); | |
5681 | 610 octave_idx_type nz = a.nnz (); |
5275 | 611 for (octave_idx_type i = 0; i < nz; i++) |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
612 retval.data (i) = - retval.data (i); |
5164 | 613 return retval; |
614 } |