Mercurial > hg > octave-lyh
annotate liboctave/MDiagArray2.cc @ 10521:4d1fc073fbb7
add some missing copyright stmts
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Wed, 14 Apr 2010 12:23:13 +0200 |
parents | b47ab50a6aa8 |
children | fd0a3ac60b0e |
rev | line source |
---|---|
1988 | 1 /* |
2 | |
8920 | 3 Copyright (C) 1996, 1997, 2000, 2002, 2003, 2004, 2005, 2007, 2008 |
7017 | 4 John W. Eaton |
10521
4d1fc073fbb7
add some missing copyright stmts
Jaroslav Hajek <highegg@gmail.com>
parents:
10362
diff
changeset
|
5 Copyright (C) 2010 VZLU Prague |
1988 | 6 |
7 This file is part of Octave. | |
8 | |
9 Octave is free software; you can redistribute it and/or modify it | |
10 under the terms of the GNU General Public License as published by the | |
7016 | 11 Free Software Foundation; either version 3 of the License, or (at your |
12 option) any later version. | |
1988 | 13 |
14 Octave is distributed in the hope that it will be useful, but WITHOUT | |
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
17 for more details. | |
18 | |
19 You should have received a copy of the GNU General Public License | |
7016 | 20 along with Octave; see the file COPYING. If not, see |
21 <http://www.gnu.org/licenses/>. | |
1988 | 22 |
23 */ | |
24 | |
25 #ifdef HAVE_CONFIG_H | |
26 #include <config.h> | |
27 #endif | |
28 | |
29 #include "MDiagArray2.h" | |
4669 | 30 #include "Array-util.h" |
1988 | 31 #include "lo-error.h" |
32 | |
33 #include "MArray-defs.h" | |
34 | |
8367
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
35 template <class T> |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
36 bool |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
37 MDiagArray2<T>::is_multiple_of_identity (T val) const |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
38 { |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
39 bool retval = this->rows () == this->cols (); |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
40 if (retval) |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
41 { |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
42 octave_idx_type len = this->length (), i = 0; |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
43 for (;i < len; i++) |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
44 if (DiagArray2<T>::elem (i, i) != val) break; |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
45 retval = i == len; |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
46 } |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
47 |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
48 return retval; |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
49 } |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
50 |
1988 | 51 // Two dimensional diagonal array with math ops. |
52 | |
53 // Element by element MDiagArray2 by MDiagArray2 ops. | |
54 | |
55 // Element by element MDiagArray2 by scalar ops. | |
56 | |
9612
66970dd627f6
further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
57 #define MARRAY_DAS_OP(OP, FN) \ |
1988 | 58 template <class T> \ |
59 MDiagArray2<T> \ | |
60 operator OP (const MDiagArray2<T>& a, const T& s) \ | |
61 { \ | |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10158
diff
changeset
|
62 return MDiagArray2<T> (do_ms_binary_op<T, T, T> (a, s, FN), a.d1, a.d2); \ |
1988 | 63 } |
64 | |
9612
66970dd627f6
further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
65 MARRAY_DAS_OP (*, mx_inline_mul) |
66970dd627f6
further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
66 MARRAY_DAS_OP (/, mx_inline_div) |
1988 | 67 |
68 // Element by element scalar by MDiagArray2 ops. | |
69 | |
70 template <class T> | |
71 MDiagArray2<T> | |
72 operator * (const T& s, const MDiagArray2<T>& a) | |
73 { | |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10158
diff
changeset
|
74 return MDiagArray2<T> (do_sm_binary_op<T, T, T> (s, a, mx_inline_mul), a.d1, a.d2); |
1988 | 75 } |
76 | |
77 // Element by element MDiagArray2 by MDiagArray2 ops. | |
78 | |
9612
66970dd627f6
further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
79 #define MARRAY_DADA_OP(FCN, OP, FN) \ |
1988 | 80 template <class T> \ |
81 MDiagArray2<T> \ | |
82 FCN (const MDiagArray2<T>& a, const MDiagArray2<T>& b) \ | |
83 { \ | |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10158
diff
changeset
|
84 if (a.d1 != b.d1 || a.d2 != b.d2) \ |
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10158
diff
changeset
|
85 gripe_nonconformant (#FCN, a.d1, a.d2, b.d1, b.d2); \ |
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10158
diff
changeset
|
86 return MDiagArray2<T> (do_mm_binary_op<T, T, T> (a, b, FN, #FCN), a.d1, a.d2); \ |
1988 | 87 } |
88 | |
9612
66970dd627f6
further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
89 MARRAY_DADA_OP (operator +, +, mx_inline_add) |
66970dd627f6
further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
90 MARRAY_DADA_OP (operator -, -, mx_inline_sub) |
66970dd627f6
further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
91 MARRAY_DADA_OP (product, *, mx_inline_mul) |
1988 | 92 |
93 // Unary MDiagArray2 ops. | |
94 | |
95 template <class T> | |
96 MDiagArray2<T> | |
3580 | 97 operator + (const MDiagArray2<T>& a) |
98 { | |
99 return a; | |
100 } | |
101 | |
102 template <class T> | |
103 MDiagArray2<T> | |
1988 | 104 operator - (const MDiagArray2<T>& a) |
105 { | |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10158
diff
changeset
|
106 return MDiagArray2<T> (do_mx_unary_op<T, T> (a, mx_inline_uminus), a.d1, a.d2); |
1988 | 107 } |