comparison liboctave/Array-f.cc @ 8721:e9cb742df9eb

imported patch sort3.diff
author Jaroslav Hajek <highegg@gmail.com>
date Wed, 11 Feb 2009 15:25:53 +0100
parents 739141cde75a
children d5af326a3ede
comparison
equal deleted inserted replaced
8720:dda421a1f1e6 8721:e9cb742df9eb
40 inline bool _sort_isnan (float x) 40 inline bool _sort_isnan (float x)
41 { 41 {
42 return lo_ieee_isnan (x); 42 return lo_ieee_isnan (x);
43 } 43 }
44 44
45 static bool nan_ascending_compare (float x, float y)
46 {
47 return lo_ieee_isnan (y) ? ! lo_ieee_isnan (x) : x < y;
48 }
49
50 static bool nan_descending_compare (float x, float y)
51 {
52 return lo_ieee_isnan (x) ? ! lo_ieee_isnan (y) : x > y;
53 }
54
55 bool (*_sortrows_comparator (sortmode mode,
56 const Array<float>& a , bool allow_chk))
57 (float, float)
58 {
59 bool (*result) (float, float) = 0;
60
61 if (allow_chk)
62 {
63 octave_idx_type k = 0;
64 for (; k < a.numel () && ! xisnan (a(k)); k++) ;
65 if (k == a.numel ())
66 {
67 if (mode == ASCENDING)
68 result = octave_sort<float>::ascending_compare;
69 else if (mode == DESCENDING)
70 result = octave_sort<float>::descending_compare;
71 }
72 }
73
74 if (! result)
75 {
76 if (mode == ASCENDING)
77 result = nan_ascending_compare;
78 else if (mode == DESCENDING)
79 result = nan_descending_compare;
80 }
81
82 return result;
83 }
84
45 INSTANTIATE_ARRAY_SORT (float); 85 INSTANTIATE_ARRAY_SORT (float);
46 86
47 INSTANTIATE_ARRAY_AND_ASSIGN (float, OCTAVE_API); 87 INSTANTIATE_ARRAY (float, OCTAVE_API);
48
49 INSTANTIATE_ARRAY_ASSIGN (float, int, OCTAVE_API)
50 INSTANTIATE_ARRAY_ASSIGN (float, short, OCTAVE_API)
51 INSTANTIATE_ARRAY_ASSIGN (float, char, OCTAVE_API)
52 88
53 #include "Array2.h" 89 #include "Array2.h"
54 90
55 template class OCTAVE_API Array2<float>; 91 template class OCTAVE_API Array2<float>;
56 92