annotate liboctave/MSparse.cc @ 14193:72aebe619641 stable rc-3-6-0-0

3.6.0-rc0 release candidate * configure.ac (AC_INIT): Version is now 3.6.0-rc0. (OCTAVE_RELEASE_DATE): Now 2012-01-10. (OCTAVE_API_VERSION_NUMBER): Now 47.
author John W. Eaton <jwe@octave.org>
date Tue, 10 Jan 2012 16:43:41 -0500
parents 72c96de7a403
children 460a3c6d8bf1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1 /*
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2
14138
72c96de7a403 maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents: 13265
diff changeset
3 Copyright (C) 2004-2012 David Bateman
11523
fd0a3ac60b0e update copyright notices
John W. Eaton <jwe@octave.org>
parents: 10350
diff changeset
4 Copyright (C) 1998-2004 Andy Adler
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6221
diff changeset
5
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6221
diff changeset
6 This file is part of Octave.
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
8 Octave is free software; you can redistribute it and/or modify it
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
9 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6221
diff changeset
10 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6221
diff changeset
11 option) any later version.
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
12
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
13 Octave is distributed in the hope that it will be useful, but WITHOUT
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
16 for more details.
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
17
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6221
diff changeset
19 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6221
diff changeset
20 <http://www.gnu.org/licenses/>.
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
21
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
22 */
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
23
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
24 #ifdef HAVE_CONFIG_H
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
25 #include <config.h>
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
26 #endif
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
27
13264
11c8b60f1b68 Eliminate duplicate code for op+= and op-= for MSparse
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 11586
diff changeset
28 #include <functional>
11c8b60f1b68 Eliminate duplicate code for op+= and op-= for MSparse
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 11586
diff changeset
29
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
30 #include "quit.h"
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
31 #include "lo-error.h"
10350
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
32 #include "MArray.h"
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
33 #include "Array-util.h"
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
34
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
35 #include "MSparse.h"
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
36 #include "MSparse-defs.h"
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
37
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
38 // sparse array with math ops.
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
39
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
40 // Element by element MSparse by MSparse ops.
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
41
13264
11c8b60f1b68 Eliminate duplicate code for op+= and op-= for MSparse
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 11586
diff changeset
42 template <class T, class OP>
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
43 MSparse<T>&
13264
11c8b60f1b68 Eliminate duplicate code for op+= and op-= for MSparse
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 11586
diff changeset
44 plus_or_minus (MSparse<T>& a, const MSparse<T>& b, OP op, const char* op_name)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
45 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
46 MSparse<T> r;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
47
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
48 octave_idx_type a_nr = a.rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
49 octave_idx_type a_nc = a.cols ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
50
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
51 octave_idx_type b_nr = b.rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
52 octave_idx_type b_nc = b.cols ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
53
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
54 if (a_nr != b_nr || a_nc != b_nc)
13264
11c8b60f1b68 Eliminate duplicate code for op+= and op-= for MSparse
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 11586
diff changeset
55 gripe_nonconformant (op_name , a_nr, a_nc, b_nr, b_nc);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
56 else
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
57 {
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5604
diff changeset
58 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
59
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
60 octave_idx_type jx = 0;
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
61 for (octave_idx_type i = 0 ; i < a_nc ; i++)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
62 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
63 octave_idx_type ja = a.cidx(i);
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
64 octave_idx_type ja_max = a.cidx(i+1);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
65 bool ja_lt_max= ja < ja_max;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
66
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
67 octave_idx_type jb = b.cidx(i);
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
68 octave_idx_type jb_max = b.cidx(i+1);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
69 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
70
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
71 while (ja_lt_max || jb_lt_max )
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
72 {
10142
829e69ec3110 make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents: 7344
diff changeset
73 octave_quit ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
74 if ((! jb_lt_max) ||
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
75 (ja_lt_max && (a.ridx(ja) < b.ridx(jb))))
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
76 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
77 r.ridx(jx) = a.ridx(ja);
13264
11c8b60f1b68 Eliminate duplicate code for op+= and op-= for MSparse
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 11586
diff changeset
78 r.data(jx) = op (a.data(ja), 0.);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
79 jx++;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
80 ja++;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
81 ja_lt_max= ja < ja_max;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
82 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
83 else if (( !ja_lt_max ) ||
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
84 (jb_lt_max && (b.ridx(jb) < a.ridx(ja)) ) )
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
85 {
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
86 r.ridx(jx) = b.ridx(jb);
13264
11c8b60f1b68 Eliminate duplicate code for op+= and op-= for MSparse
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 11586
diff changeset
87 r.data(jx) = op (0., b.data(jb));
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
88 jx++;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
89 jb++;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
90 jb_lt_max= jb < jb_max;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
91 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
92 else
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
93 {
13264
11c8b60f1b68 Eliminate duplicate code for op+= and op-= for MSparse
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 11586
diff changeset
94 if (op (a.data(ja), b.data(jb)) != 0.)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
95 {
13264
11c8b60f1b68 Eliminate duplicate code for op+= and op-= for MSparse
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 11586
diff changeset
96 r.data(jx) = op (a.data(ja), b.data(jb));
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
97 r.ridx(jx) = a.ridx(ja);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
98 jx++;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
99 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
100 ja++;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
101 ja_lt_max= ja < ja_max;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
102 jb++;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
103 jb_lt_max= jb < jb_max;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
104 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
105 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
106 r.cidx(i+1) = jx;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
107 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
108
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
109 a = r.maybe_compress ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
110 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
111
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
112 return a;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
113 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
114
13264
11c8b60f1b68 Eliminate duplicate code for op+= and op-= for MSparse
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 11586
diff changeset
115 template <typename T>
11c8b60f1b68 Eliminate duplicate code for op+= and op-= for MSparse
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 11586
diff changeset
116 MSparse<T>&
11c8b60f1b68 Eliminate duplicate code for op+= and op-= for MSparse
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 11586
diff changeset
117 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
118 {
11c8b60f1b68 Eliminate duplicate code for op+= and op-= for MSparse
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 11586
diff changeset
119 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
120 }
11c8b60f1b68 Eliminate duplicate code for op+= and op-= for MSparse
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 11586
diff changeset
121
11c8b60f1b68 Eliminate duplicate code for op+= and op-= for MSparse
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 11586
diff changeset
122 template <typename T>
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
123 MSparse<T>&
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
124 operator -= (MSparse<T>& a, const MSparse<T>& b)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
125 {
13264
11c8b60f1b68 Eliminate duplicate code for op+= and op-= for MSparse
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 11586
diff changeset
126 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
127 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
128
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
129
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
130 // Element by element MSparse by scalar ops.
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
131
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
132 template <class T, class OP>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
133 MArray<T>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
134 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
135 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
136 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
137 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
138
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
139 MArray<T> r (dim_vector (nr, nc), op (0.0, s));
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
140
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
141 for (octave_idx_type j = 0; j < nc; j++)
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
142 for (octave_idx_type i = a.cidx(j); i < a.cidx(j+1); i++)
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
143 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
144 return r;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
145 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
146
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
147 template <typename T>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
148 MArray<T>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
149 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
150 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
151 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
152 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
153
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
154 template <typename T>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
155 MArray<T>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
156 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
157 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
158 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
159 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
160
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
161
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
162 template <class T, class OP>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
163 MSparse<T>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
164 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
165 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
166 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
167 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
168 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
169
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
170 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
171
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
172 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
173 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
174 r.data(i) = 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
175 r.ridx(i) = a.ridx(i);
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 for (octave_idx_type i = 0; i < nc + 1; i++)
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
178 r.cidx(i) = a.cidx(i);
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
179 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
180 return r;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
181 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
182
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
183 template <typename T>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
184 MSparse<T>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
185 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
186 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
187 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
188 }
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 template <typename T>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
191 MSparse<T>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
192 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
193 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
194 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
195 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
196
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
197
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
198 // Element by element scalar by MSparse ops.
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
199
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
200 template <class T, class OP>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
201 MArray<T>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
202 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
203 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
204 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
205 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
206
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
207 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
208
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
209 for (octave_idx_type j = 0; j < nc; j++)
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
210 for (octave_idx_type i = a.cidx(j); i < a.cidx(j+1); i++)
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
211 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
212 return r;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
213 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
214
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
215 template <typename T>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
216 MArray<T>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
217 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
218 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
219 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
220 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
221
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
222 template <typename T>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
223 MArray<T>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
224 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
225 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
226 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
227 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
228
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
229 template <class T, class OP>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
230 MSparse<T>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
231 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
232 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
233 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
234 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
235 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
236
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
237 MSparse<T> r (nr, nc, nz);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
238
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
239 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
240 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
241 r.data(i) = 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
242 r.ridx(i) = a.ridx(i);
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 for (octave_idx_type i = 0; i < nc + 1; i++)
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
245 r.cidx(i) = a.cidx(i);
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
246 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
247 return r;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
248 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
249
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
250 template <class T>
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 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
253 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
254 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
255 }
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 template <class T>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
258 MSparse<T>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
259 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
260 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
261 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
262 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
263
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
264
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
265 // Element by element MSparse by MSparse ops.
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
266
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
267 template <class T, class OP>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
268 MSparse<T>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
269 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
270 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
271 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
272 MSparse<T> r;
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 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
275 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
276
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 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
278 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
279
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
280 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
281 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
282 if (a.elem(0,0) == 0.)
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
283 if (negate)
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
284 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
285 else
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
286 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
287 else
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
288 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
289 r = MSparse<T> (b_nr, b_nc, op (a.data(0), 0.));
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
290
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
291 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
292 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
293 octave_quit ();
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
294 octave_idx_type idxj = j * b_nr;
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 i = b.cidx(j) ; i < b.cidx(j+1) ; i++)
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 r.data(idxj + b.ridx(i)) = op (a.data(0), b.data(i));
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
299 }
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 r.maybe_compress ();
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
302 }
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 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
305 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
306 if (b.elem(0,0) == 0.)
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
307 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
308 else
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
309 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
310 r = MSparse<T> (a_nr, a_nc, op (0.0, b.data(0)));
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 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
313 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
314 octave_quit ();
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
315 octave_idx_type idxj = j * a_nr;
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 = a.cidx(j) ; i < a.cidx(j+1) ; i++)
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
317 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
318 octave_quit ();
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
319 r.data(idxj + a.ridx(i)) = op (a.data(i), b.data(0));
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
320 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
321 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
322 r.maybe_compress ();
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
323 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
324 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
325 else if (a_nr != b_nr || a_nc != b_nc)
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
326 gripe_nonconformant (op_name, a_nr, a_nc, 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
327 else
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
328 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
329 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
330
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
331 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
332 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
333 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
334 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
335 octave_idx_type ja = a.cidx(i);
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
336 octave_idx_type ja_max = a.cidx(i+1);
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
337 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
338
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
339 octave_idx_type jb = b.cidx(i);
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
340 octave_idx_type jb_max = b.cidx(i+1);
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
341 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
342
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
343 while (ja_lt_max || jb_lt_max )
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
344 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
345 octave_quit ();
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
346 if ((! jb_lt_max) ||
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
347 (ja_lt_max && (a.ridx(ja) < b.ridx(jb))))
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
348 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
349 r.ridx(jx) = a.ridx(ja);
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
350 r.data(jx) = op (a.data(ja), 0.);
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
351 jx++;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
352 ja++;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
353 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
354 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
355 else if (( !ja_lt_max ) ||
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
356 (jb_lt_max && (b.ridx(jb) < a.ridx(ja)) ) )
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
357 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
358 r.ridx(jx) = b.ridx(jb);
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
359 r.data(jx) = op (0., b.data(jb));
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
360 jx++;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
361 jb++;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
362 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
363 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
364 else
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 if (op (a.data(ja), b.data(jb)) != 0.)
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 r.data(jx) = op (a.data(ja), b.data(jb));
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
369 r.ridx(jx) = a.ridx(ja);
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
370 jx++;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
371 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
372 ja++;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
373 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
374 jb++;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
375 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
376 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
377 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
378 r.cidx(i+1) = jx;
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
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
381 r.maybe_compress ();
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
382 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
383
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
384 return r;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
385 }
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 template <class T>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
388 MSparse<T>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
389 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
390 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
391 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
392 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
393
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
394 template <class T>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
395 MSparse<T>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
396 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
397 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
398 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
399 }
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 template <class T>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
402 MSparse<T>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
403 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
404 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
405 MSparse<T> r;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
406
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
407 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
408 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
409
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
410 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
411 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
412
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
413 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
414 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
415 if (a.elem(0,0) == 0.)
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
416 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
417 else
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
418 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
419 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
420 octave_idx_type b_nnz = b.nnz();
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
421
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
422 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
423 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
424 octave_quit ();
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
425 r.data (i) = a.data(0) * r.data(i);
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
426 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
427 r.maybe_compress ();
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 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
430 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
431 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
432 if (b.elem(0,0) == 0.)
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);
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
434 else
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
435 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
436 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
437 octave_idx_type a_nnz = a.nnz();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
438
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
439 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
440 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
441 octave_quit ();
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
442 r.data (i) = r.data(i) * b.data(0);
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
443 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
444 r.maybe_compress ();
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
445 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
446 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
447 else if (a_nr != b_nr || a_nc != b_nc)
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
448 gripe_nonconformant ("product", a_nr, a_nc, 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
449 else
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
450 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
451 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
452
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
453 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
454 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
455 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
456 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
457 octave_idx_type ja = a.cidx(i);
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
458 octave_idx_type ja_max = a.cidx(i+1);
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
459 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
460
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
461 octave_idx_type jb = b.cidx(i);
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
462 octave_idx_type jb_max = b.cidx(i+1);
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
463 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
464
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
465 while (ja_lt_max || jb_lt_max )
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 octave_quit ();
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
468 if ((! jb_lt_max) ||
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
469 (ja_lt_max && (a.ridx(ja) < b.ridx(jb))))
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
470 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
471 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
472 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
473 else if (( !ja_lt_max ) ||
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
474 (jb_lt_max && (b.ridx(jb) < a.ridx(ja)) ) )
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 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
477 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
478 else
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
479 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
480 if ((a.data(ja) * b.data(jb)) != 0.)
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
481 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
482 r.data(jx) = a.data(ja) * b.data(jb);
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
483 r.ridx(jx) = a.ridx(ja);
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
484 jx++;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
485 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
486 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
487 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
488 }
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 r.cidx(i+1) = jx;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
491 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
492
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
493 r.maybe_compress ();
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
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
496 return r;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
497 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
498
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
499 template <class T>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
500 MSparse<T>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
501 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
502 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
503 MSparse<T> r;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
504 T Zero = T ();
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
505
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
506 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
507 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
508
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
509 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
510 octave_idx_type b_nc = b.cols ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
511
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
512 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
513 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
514 T val = a.elem (0,0);
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
515 T fill = val / T();
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
516 if (fill == T())
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 octave_idx_type b_nnz = b.nnz();
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
519 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
520 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
521 r.data (i) = val / r.data(i);
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
522 r.maybe_compress ();
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
523 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
524 else
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
525 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
526 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
527 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
528 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
529 octave_quit ();
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
530 octave_idx_type idxj = j * b_nr;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
531 for (octave_idx_type i = b.cidx(j) ; i < b.cidx(j+1) ; i++)
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 octave_quit ();
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
534 r.data(idxj + b.ridx(i)) = val / b.data(i);
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
535 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
536 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
537 r.maybe_compress ();
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
538 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
539 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
540 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
541 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
542 T val = b.elem (0,0);
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
543 T fill = T() / val;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
544 if (fill == T())
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 octave_idx_type a_nnz = a.nnz();
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
547 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
548 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
549 r.data (i) = r.data(i) / val;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
550 r.maybe_compress ();
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
551 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
552 else
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
553 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
554 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
555 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
556 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
557 octave_quit ();
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
558 octave_idx_type idxj = j * a_nr;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
559 for (octave_idx_type i = a.cidx(j) ; i < a.cidx(j+1) ; i++)
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
560 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
561 octave_quit ();
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
562 r.data(idxj + a.ridx(i)) = a.data(i) / val;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
563 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
564 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
565 r.maybe_compress ();
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 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
568 else if (a_nr != b_nr || a_nc != b_nc)
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
569 gripe_nonconformant ("quotient", a_nr, a_nc, 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
570 else
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
571 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
572 r = MSparse<T>( a_nr, a_nc, (Zero / Zero));
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
573
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
574 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
575 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
576 octave_idx_type ja = a.cidx(i);
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
577 octave_idx_type ja_max = a.cidx(i+1);
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
578 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
579
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
580 octave_idx_type jb = b.cidx(i);
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
581 octave_idx_type jb_max = b.cidx(i+1);
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
582 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
583
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
584 while (ja_lt_max || jb_lt_max )
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 octave_quit ();
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
587 if ((! jb_lt_max) ||
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
588 (ja_lt_max && (a.ridx(ja) < b.ridx(jb))))
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 r.elem (a.ridx(ja),i) = a.data(ja) / Zero;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
591 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
592 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
593 else if (( !ja_lt_max ) ||
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
594 (jb_lt_max && (b.ridx(jb) < a.ridx(ja)) ) )
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
595 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
596 r.elem (b.ridx(jb),i) = Zero / b.data(jb);
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
597 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
598 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
599 else
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
600 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
601 r.elem (a.ridx(ja),i) = a.data(ja) / b.data(jb);
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
602 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
603 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
604 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
605 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
606 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
607
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
608 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
609 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
610
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
611 return r;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
612 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
613
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
614
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
615
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
616 // Unary MSparse ops.
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
617
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
618 template <class T>
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
619 MSparse<T>
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
620 operator + (const MSparse<T>& a)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
621 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
622 return a;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
623 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
624
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
625 template <class T>
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
626 MSparse<T>
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
627 operator - (const MSparse<T>& a)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
628 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
629 MSparse<T> retval (a);
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5604
diff changeset
630 octave_idx_type nz = a.nnz ();
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
631 for (octave_idx_type i = 0; i < nz; i++)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
632 retval.data(i) = - retval.data(i);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
633 return retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
634 }