annotate liboctave/array/Array-C.cc @ 20595:c1a6c31ac29a

eliminate more simple uses of error_state * ov-classdef.cc: Eliminate simple uses of error_state.
author John W. Eaton <jwe@octave.org>
date Tue, 06 Oct 2015 00:20:02 -0400
parents 40b2c4323c16
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
757
b75705dec035 [project @ 1994-10-02 15:19:39 by jwe]
jwe
parents:
diff changeset
1 /*
b75705dec035 [project @ 1994-10-02 15:19:39 by jwe]
jwe
parents:
diff changeset
2
19731
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19669
diff changeset
3 Copyright (C) 1994-2015 John W. Eaton
10521
4d1fc073fbb7 add some missing copyright stmts
Jaroslav Hajek <highegg@gmail.com>
parents: 10374
diff changeset
4 Copyright (C) 2009 VZLU Prague
757
b75705dec035 [project @ 1994-10-02 15:19:39 by jwe]
jwe
parents:
diff changeset
5
b75705dec035 [project @ 1994-10-02 15:19:39 by jwe]
jwe
parents:
diff changeset
6 This file is part of Octave.
b75705dec035 [project @ 1994-10-02 15:19:39 by jwe]
jwe
parents:
diff changeset
7
b75705dec035 [project @ 1994-10-02 15:19:39 by jwe]
jwe
parents:
diff changeset
8 Octave is free software; you can redistribute it and/or modify it
b75705dec035 [project @ 1994-10-02 15:19:39 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: 6708
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: 6708
diff changeset
11 option) any later version.
757
b75705dec035 [project @ 1994-10-02 15:19:39 by jwe]
jwe
parents:
diff changeset
12
b75705dec035 [project @ 1994-10-02 15:19:39 by jwe]
jwe
parents:
diff changeset
13 Octave is distributed in the hope that it will be useful, but WITHOUT
b75705dec035 [project @ 1994-10-02 15:19:39 by jwe]
jwe
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b75705dec035 [project @ 1994-10-02 15:19:39 by jwe]
jwe
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
b75705dec035 [project @ 1994-10-02 15:19:39 by jwe]
jwe
parents:
diff changeset
16 for more details.
b75705dec035 [project @ 1994-10-02 15:19:39 by jwe]
jwe
parents:
diff changeset
17
b75705dec035 [project @ 1994-10-02 15:19:39 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: 6708
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: 6708
diff changeset
20 <http://www.gnu.org/licenses/>.
757
b75705dec035 [project @ 1994-10-02 15:19:39 by jwe]
jwe
parents:
diff changeset
21
b75705dec035 [project @ 1994-10-02 15:19:39 by jwe]
jwe
parents:
diff changeset
22 */
b75705dec035 [project @ 1994-10-02 15:19:39 by jwe]
jwe
parents:
diff changeset
23
2006
95e952f72d66 [project @ 1996-03-04 00:33:32 by jwe]
jwe
parents: 1993
diff changeset
24 #ifdef HAVE_CONFIG_H
95e952f72d66 [project @ 1996-03-04 00:33:32 by jwe]
jwe
parents: 1993
diff changeset
25 #include <config.h>
95e952f72d66 [project @ 1996-03-04 00:33:32 by jwe]
jwe
parents: 1993
diff changeset
26 #endif
95e952f72d66 [project @ 1996-03-04 00:33:32 by jwe]
jwe
parents: 1993
diff changeset
27
757
b75705dec035 [project @ 1994-10-02 15:19:39 by jwe]
jwe
parents:
diff changeset
28 // Instantiate Arrays of Complex values.
b75705dec035 [project @ 1994-10-02 15:19:39 by jwe]
jwe
parents:
diff changeset
29
1989
a4b0826e240c [project @ 1996-03-02 00:33:22 by jwe]
jwe
parents: 1882
diff changeset
30 #include "oct-cmplx.h"
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
31 #include "lo-mappers.h"
1989
a4b0826e240c [project @ 1996-03-02 00:33:22 by jwe]
jwe
parents: 1882
diff changeset
32
757
b75705dec035 [project @ 1994-10-02 15:19:39 by jwe]
jwe
parents:
diff changeset
33 #include "Array.h"
b75705dec035 [project @ 1994-10-02 15:19:39 by jwe]
jwe
parents:
diff changeset
34 #include "Array.cc"
8700
314be237cd5b sorting optimizations
Jaroslav Hajek <highegg@gmail.com>
parents: 8290
diff changeset
35 #include "oct-sort.cc"
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7017
diff changeset
36
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
37 template <>
8725
d5af326a3ede [mq]: sort-traits
John W. Eaton <jwe@octave.org>
parents: 8721
diff changeset
38 inline bool
d5af326a3ede [mq]: sort-traits
John W. Eaton <jwe@octave.org>
parents: 8721
diff changeset
39 sort_isnan<Complex> (const Complex& x)
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7017
diff changeset
40 {
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
41 return xisnan (x);
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7017
diff changeset
42 }
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7017
diff changeset
43
19669
bdf90710dddf Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents: 19667
diff changeset
44 // Sort Criteria: 1) isnan, 2) magnitude of z, 3) phase of z in range (-pi, pi]
bdf90710dddf Map -pi to pi for principal argument used in complex operators (bug #43313).
Daniel J Sebald <daniel.sebald@ieee.org>
parents: 19667
diff changeset
45
8725
d5af326a3ede [mq]: sort-traits
John W. Eaton <jwe@octave.org>
parents: 8721
diff changeset
46 static bool
d5af326a3ede [mq]: sort-traits
John W. Eaton <jwe@octave.org>
parents: 8721
diff changeset
47 nan_ascending_compare (const Complex& x, const Complex& y)
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
48 {
20001
40b2c4323c16 avoid some code duplication in complex comparison functions (bug #44206)
John W. Eaton <jwe@octave.org>
parents: 19895
diff changeset
49 return xisnan (y) ? ! xisnan (x) : x < y;
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
50 }
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
51
8725
d5af326a3ede [mq]: sort-traits
John W. Eaton <jwe@octave.org>
parents: 8721
diff changeset
52 static bool
d5af326a3ede [mq]: sort-traits
John W. Eaton <jwe@octave.org>
parents: 8721
diff changeset
53 nan_descending_compare (const Complex& x, const Complex& y)
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
54 {
20001
40b2c4323c16 avoid some code duplication in complex comparison functions (bug #44206)
John W. Eaton <jwe@octave.org>
parents: 19895
diff changeset
55 return xisnan (x) ? ! xisnan (y) : x > y;
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
56 }
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
57
8725
d5af326a3ede [mq]: sort-traits
John W. Eaton <jwe@octave.org>
parents: 8721
diff changeset
58 Array<Complex>::compare_fcn_type
9920
56fbe170d354 fix issorted with NaNs in middle
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
59 safe_comparator (sortmode mode, const Array<Complex>& a , bool allow_chk)
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
60 {
8725
d5af326a3ede [mq]: sort-traits
John W. Eaton <jwe@octave.org>
parents: 8721
diff changeset
61 Array<Complex>::compare_fcn_type result = 0;
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
62
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
63 if (allow_chk)
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
64 {
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
65 octave_idx_type k = 0;
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
66 for (; k < a.numel () && ! xisnan (a(k)); k++) ;
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
67 if (k == a.numel ())
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
68 {
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
69 if (mode == ASCENDING)
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
70 result = octave_sort<Complex>::ascending_compare;
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
71 else if (mode == DESCENDING)
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
72 result = octave_sort<Complex>::descending_compare;
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
73 }
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
74 }
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
75
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
76 if (! result)
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
77 {
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
78 if (mode == ASCENDING)
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
79 result = nan_ascending_compare;
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
80 else if (mode == DESCENDING)
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
81 result = nan_descending_compare;
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
82 }
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
83
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
84 return result;
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7017
diff changeset
85 }
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7017
diff changeset
86
19429
fb09907f4e49 Remove single line makro INSTANTIATE_ARRAY_SORT.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 17769
diff changeset
87 template class OCTAVE_API octave_sort<Complex>;
757
b75705dec035 [project @ 1994-10-02 15:19:39 by jwe]
jwe
parents:
diff changeset
88
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
89 INSTANTIATE_ARRAY (Complex, OCTAVE_API);
3836
b8c1cb5b9fd9 [project @ 2001-05-31 19:30:49 by jwe]
jwe
parents: 3164
diff changeset
90
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
91 template OCTAVE_API std::ostream& operator << (std::ostream&,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
92 const Array<Complex>&);
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 3836
diff changeset
93
1989
a4b0826e240c [project @ 1996-03-02 00:33:22 by jwe]
jwe
parents: 1882
diff changeset
94 #include "DiagArray2.h"
a4b0826e240c [project @ 1996-03-02 00:33:22 by jwe]
jwe
parents: 1882
diff changeset
95 #include "DiagArray2.cc"
a4b0826e240c [project @ 1996-03-02 00:33:22 by jwe]
jwe
parents: 1882
diff changeset
96
6108
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 5307
diff changeset
97 template class OCTAVE_API DiagArray2<Complex>;