annotate liboctave/Array-d.cc @ 8721:e9cb742df9eb

imported patch sort3.diff
author Jaroslav Hajek <highegg@gmail.com>
date Wed, 11 Feb 2009 15:25:53 +0100
parents 314be237cd5b
children d5af326a3ede
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
7017
a1dbe9d80eee [project @ 2007-10-12 21:27:11 by jwe]
jwe
parents: 7016
diff changeset
3 Copyright (C) 1994, 1995, 1996, 1997, 1998, 2000, 2001, 2003, 2004,
a1dbe9d80eee [project @ 2007-10-12 21:27:11 by jwe]
jwe
parents: 7016
diff changeset
4 2005, 2006, 2007 John W. Eaton
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 double values.
b75705dec035 [project @ 1994-10-02 15:19:39 by jwe]
jwe
parents:
diff changeset
29
8700
314be237cd5b sorting optimizations
Jaroslav Hajek <highegg@gmail.com>
parents: 8651
diff changeset
30 #include "lo-ieee.h"
757
b75705dec035 [project @ 1994-10-02 15:19:39 by jwe]
jwe
parents:
diff changeset
31 #include "Array.h"
b75705dec035 [project @ 1994-10-02 15:19:39 by jwe]
jwe
parents:
diff changeset
32 #include "Array.cc"
8377
25bc2d31e1bf improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents: 8290
diff changeset
33 #include "oct-locbuf.h"
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7017
diff changeset
34
8700
314be237cd5b sorting optimizations
Jaroslav Hajek <highegg@gmail.com>
parents: 8651
diff changeset
35 #define INLINE_ASCENDING_SORT
314be237cd5b sorting optimizations
Jaroslav Hajek <highegg@gmail.com>
parents: 8651
diff changeset
36 #define INLINE_DESCENDING_SORT
314be237cd5b sorting optimizations
Jaroslav Hajek <highegg@gmail.com>
parents: 8651
diff changeset
37 #include "oct-sort.cc"
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7017
diff changeset
38
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7017
diff changeset
39 template <>
8700
314be237cd5b sorting optimizations
Jaroslav Hajek <highegg@gmail.com>
parents: 8651
diff changeset
40 inline bool _sort_isnan (double x)
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7017
diff changeset
41 {
8700
314be237cd5b sorting optimizations
Jaroslav Hajek <highegg@gmail.com>
parents: 8651
diff changeset
42 return lo_ieee_isnan (x);
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7017
diff changeset
43 }
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7017
diff changeset
44
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
45 static bool nan_ascending_compare (double x, double y)
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
46 {
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
47 return lo_ieee_isnan (y) ? ! lo_ieee_isnan (x) : x < y;
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
48 }
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
49
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
50 static bool nan_descending_compare (double x, double y)
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
51 {
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
52 return lo_ieee_isnan (x) ? ! lo_ieee_isnan (y) : x > y;
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
53 }
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
54
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
55 bool (*_sortrows_comparator (sortmode mode,
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
56 const Array<double>& a , bool allow_chk))
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
57 (double, double)
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
58 {
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
59 bool (*result) (double, double) = 0;
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
60
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
61 if (allow_chk)
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 octave_idx_type k = 0;
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
64 for (; k < a.numel () && ! xisnan (a(k)); k++) ;
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
65 if (k == a.numel ())
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
66 {
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
67 if (mode == ASCENDING)
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
68 result = octave_sort<double>::ascending_compare;
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
69 else if (mode == DESCENDING)
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
70 result = octave_sort<double>::descending_compare;
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
71 }
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
72 }
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 if (! result)
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 (mode == ASCENDING)
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
77 result = nan_ascending_compare;
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
78 else if (mode == DESCENDING)
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
79 result = nan_descending_compare;
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
80 }
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
81
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
82 return result;
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
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7017
diff changeset
85 INSTANTIATE_ARRAY_SORT (double);
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7017
diff changeset
86
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8700
diff changeset
87 INSTANTIATE_ARRAY (double, OCTAVE_API);
3836
b8c1cb5b9fd9 [project @ 2001-05-31 19:30:49 by jwe]
jwe
parents: 3665
diff changeset
88
1989
a4b0826e240c [project @ 1996-03-02 00:33:22 by jwe]
jwe
parents: 1882
diff changeset
89 #include "Array2.h"
a4b0826e240c [project @ 1996-03-02 00:33:22 by jwe]
jwe
parents: 1882
diff changeset
90
6153
e60688a1ea07 [project @ 2006-11-13 17:30:54 by jwe]
jwe
parents: 5307
diff changeset
91 template class OCTAVE_API Array2<double>;
1989
a4b0826e240c [project @ 1996-03-02 00:33:22 by jwe]
jwe
parents: 1882
diff changeset
92
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3164
diff changeset
93 #include "ArrayN.h"
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3164
diff changeset
94 #include "ArrayN.cc"
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3164
diff changeset
95
6153
e60688a1ea07 [project @ 2006-11-13 17:30:54 by jwe]
jwe
parents: 5307
diff changeset
96 template class OCTAVE_API ArrayN<double>;
4505
e944fbe3fff2 [project @ 2003-09-09 19:14:06 by jwe]
jwe
parents: 3836
diff changeset
97
6153
e60688a1ea07 [project @ 2006-11-13 17:30:54 by jwe]
jwe
parents: 5307
diff changeset
98 template OCTAVE_API std::ostream& operator << (std::ostream&, const ArrayN<double>&);
3665
0689afb1d001 [project @ 2000-05-11 19:07:56 by jwe]
jwe
parents: 3164
diff changeset
99
1989
a4b0826e240c [project @ 1996-03-02 00:33:22 by jwe]
jwe
parents: 1882
diff changeset
100 #include "DiagArray2.h"
a4b0826e240c [project @ 1996-03-02 00:33:22 by jwe]
jwe
parents: 1882
diff changeset
101 #include "DiagArray2.cc"
a4b0826e240c [project @ 1996-03-02 00:33:22 by jwe]
jwe
parents: 1882
diff changeset
102
6153
e60688a1ea07 [project @ 2006-11-13 17:30:54 by jwe]
jwe
parents: 5307
diff changeset
103 template class OCTAVE_API DiagArray2<double>;
1989
a4b0826e240c [project @ 1996-03-02 00:33:22 by jwe]
jwe
parents: 1882
diff changeset
104
757
b75705dec035 [project @ 1994-10-02 15:19:39 by jwe]
jwe
parents:
diff changeset
105 /*
b75705dec035 [project @ 1994-10-02 15:19:39 by jwe]
jwe
parents:
diff changeset
106 ;;; Local Variables: ***
b75705dec035 [project @ 1994-10-02 15:19:39 by jwe]
jwe
parents:
diff changeset
107 ;;; mode: C++ ***
b75705dec035 [project @ 1994-10-02 15:19:39 by jwe]
jwe
parents:
diff changeset
108 ;;; End: ***
b75705dec035 [project @ 1994-10-02 15:19:39 by jwe]
jwe
parents:
diff changeset
109 */