Mercurial > octave-libgccjit
annotate liboctave/MArray.cc @ 8920:eb63fbe60fab
update copyright notices
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 07 Mar 2009 10:41:27 -0500 |
parents | 82be108cc558 |
children | c2099a4d12ea |
rev | line source |
---|---|
237 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1993, 1995, 1996, 1997, 2000, 2002, 2003, 2004, 2005, |
8920 | 4 2007, 2008 John W. Eaton |
237 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
237 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
237 | 21 |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
1192 | 25 #include <config.h> |
237 | 26 #endif |
27 | |
28 #include "MArray.h" | |
4669 | 29 #include "Array-util.h" |
237 | 30 #include "lo-error.h" |
31 | |
1989 | 32 #include "MArray-defs.h" |
1213 | 33 |
1360 | 34 // One dimensional array with math ops. |
237 | 35 |
6508 | 36 template <class T> |
37 double | |
38 MArray<T>::norm (double) const | |
39 { | |
40 (*current_liboctave_error_handler) | |
41 ("norm: only implemented for double and complex values"); | |
42 | |
43 return 0; | |
44 } | |
45 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
46 template <class T> |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
47 float |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
48 MArray<T>::norm (float) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
49 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
50 (*current_liboctave_error_handler) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
51 ("norm: only implemented for double and complex values"); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
52 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
53 return 0; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
54 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
55 |
237 | 56 // Element by element MArray by scalar ops. |
57 | |
58 template <class T> | |
1213 | 59 MArray<T>& |
1230 | 60 operator += (MArray<T>& a, const T& s) |
237 | 61 { |
4646 | 62 DO_VS_OP2 (T, a, +=, s) |
1230 | 63 return a; |
237 | 64 } |
65 | |
66 template <class T> | |
1213 | 67 MArray<T>& |
1230 | 68 operator -= (MArray<T>& a, const T& s) |
237 | 69 { |
4646 | 70 DO_VS_OP2 (T, a, -=, s) |
1230 | 71 return a; |
237 | 72 } |
73 | |
74 // Element by element MArray by MArray ops. | |
75 | |
76 template <class T> | |
1213 | 77 MArray<T>& |
1230 | 78 operator += (MArray<T>& a, const MArray<T>& b) |
237 | 79 { |
5275 | 80 octave_idx_type l = a.length (); |
1213 | 81 if (l > 0) |
237 | 82 { |
5275 | 83 octave_idx_type bl = b.length (); |
2383 | 84 if (l != bl) |
85 gripe_nonconformant ("operator +=", l, bl); | |
1213 | 86 else |
4646 | 87 DO_VV_OP2 (T, a, +=, b); |
237 | 88 } |
1230 | 89 return a; |
237 | 90 } |
91 | |
92 template <class T> | |
1213 | 93 MArray<T>& |
1230 | 94 operator -= (MArray<T>& a, const MArray<T>& b) |
237 | 95 { |
5275 | 96 octave_idx_type l = a.length (); |
1213 | 97 if (l > 0) |
237 | 98 { |
5275 | 99 octave_idx_type bl = b.length (); |
2383 | 100 if (l != bl) |
101 gripe_nonconformant ("operator -=", l, bl); | |
1213 | 102 else |
4646 | 103 DO_VV_OP2 (T, a, -=, b); |
237 | 104 } |
1230 | 105 return a; |
237 | 106 } |
107 | |
1213 | 108 // Element by element MArray by scalar ops. |
109 | |
110 #define MARRAY_AS_OP(OP) \ | |
111 template <class T> \ | |
112 MArray<T> \ | |
113 operator OP (const MArray<T>& a, const T& s) \ | |
114 { \ | |
3504 | 115 MArray<T> result (a.length ()); \ |
116 T *r = result.fortran_vec (); \ | |
5275 | 117 octave_idx_type l = a.length (); \ |
3504 | 118 const T *v = a.data (); \ |
119 DO_VS_OP (r, l, v, OP, s); \ | |
120 return result; \ | |
1213 | 121 } |
237 | 122 |
1213 | 123 MARRAY_AS_OP (+) |
124 MARRAY_AS_OP (-) | |
125 MARRAY_AS_OP (*) | |
126 MARRAY_AS_OP (/) | |
127 | |
128 // Element by element scalar by MArray ops. | |
237 | 129 |
1213 | 130 #define MARRAY_SA_OP(OP) \ |
131 template <class T> \ | |
132 MArray<T> \ | |
133 operator OP (const T& s, const MArray<T>& a) \ | |
134 { \ | |
3504 | 135 MArray<T> result (a.length ()); \ |
136 T *r = result.fortran_vec (); \ | |
5275 | 137 octave_idx_type l = a.length (); \ |
3504 | 138 const T *v = a.data (); \ |
139 DO_SV_OP (r, l, s, OP, v); \ | |
140 return result; \ | |
141 } | |
237 | 142 |
1213 | 143 MARRAY_SA_OP(+) |
144 MARRAY_SA_OP(-) | |
145 MARRAY_SA_OP(*) | |
146 MARRAY_SA_OP(/) | |
147 | |
148 // Element by element MArray by MArray ops. | |
237 | 149 |
2383 | 150 #define MARRAY_AA_OP(FCN, OP) \ |
1213 | 151 template <class T> \ |
152 MArray<T> \ | |
153 FCN (const MArray<T>& a, const MArray<T>& b) \ | |
154 { \ | |
5275 | 155 octave_idx_type l = a.length (); \ |
156 octave_idx_type bl = b.length (); \ | |
2383 | 157 if (l != bl) \ |
1213 | 158 { \ |
2383 | 159 gripe_nonconformant (#FCN, l, bl); \ |
1213 | 160 return MArray<T> (); \ |
161 } \ | |
162 if (l == 0) \ | |
163 return MArray<T> (); \ | |
3504 | 164 MArray<T> result (l); \ |
165 T *r = result.fortran_vec (); \ | |
166 const T *x = a.data (); \ | |
167 const T *y = b.data (); \ | |
168 DO_VV_OP (r, l, x, OP, y); \ | |
169 return result; \ | |
1213 | 170 } |
237 | 171 |
2383 | 172 MARRAY_AA_OP (operator +, +) |
173 MARRAY_AA_OP (operator -, -) | |
174 MARRAY_AA_OP (product, *) | |
175 MARRAY_AA_OP (quotient, /) | |
237 | 176 |
177 // Unary MArray ops. | |
178 | |
179 template <class T> | |
180 MArray<T> | |
3574 | 181 operator + (const MArray<T>& a) |
182 { | |
183 return a; | |
184 } | |
185 | |
186 template <class T> | |
187 MArray<T> | |
237 | 188 operator - (const MArray<T>& a) |
189 { | |
5275 | 190 octave_idx_type l = a.length (); |
3504 | 191 MArray<T> result (l); |
192 T *r = result.fortran_vec (); | |
193 const T *x = a.data (); | |
194 NEG_V (r, l, x); | |
195 return result; | |
237 | 196 } |
197 | |
198 /* | |
199 ;;; Local Variables: *** | |
200 ;;; mode: C++ *** | |
201 ;;; End: *** | |
202 */ |