00001 /* 00002 00003 Copyright (C) 1994-2012 John W. Eaton 00004 Copyright (C) 2009 VZLU Prague 00005 00006 This file is part of Octave. 00007 00008 Octave is free software; you can redistribute it and/or modify it 00009 under the terms of the GNU General Public License as published by the 00010 Free Software Foundation; either version 3 of the License, or (at your 00011 option) any later version. 00012 00013 Octave is distributed in the hope that it will be useful, but WITHOUT 00014 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00015 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00016 for more details. 00017 00018 You should have received a copy of the GNU General Public License 00019 along with Octave; see the file COPYING. If not, see 00020 <http://www.gnu.org/licenses/>. 00021 00022 */ 00023 00024 #ifdef HAVE_CONFIG_H 00025 #include <config.h> 00026 #endif 00027 00028 // Instantiate Arrays of FloatComplex values. 00029 00030 #include "oct-cmplx.h" 00031 #include "lo-mappers.h" 00032 00033 #include "Array.h" 00034 #include "Array.cc" 00035 #include "oct-sort.cc" 00036 00037 template <> 00038 inline bool 00039 sort_isnan<FloatComplex> (const FloatComplex& x) 00040 { 00041 return xisnan (x); 00042 } 00043 00044 static bool 00045 nan_ascending_compare (const FloatComplex& x, const FloatComplex& y) 00046 { 00047 return (xisnan (y) 00048 ? ! xisnan (x) 00049 : ((std::abs (x) < std::abs (x)) 00050 || ((std::abs (x) == std::abs (x)) && (arg (x) < arg (x))))); 00051 } 00052 00053 static bool 00054 nan_descending_compare (const FloatComplex& x, const FloatComplex& y) 00055 { 00056 return (xisnan (x) 00057 ? ! xisnan (y) 00058 : ((std::abs (x) > std::abs (x)) 00059 || ((std::abs (x) == std::abs (x)) && (arg (x) > arg (x))))); 00060 } 00061 00062 Array<FloatComplex>::compare_fcn_type 00063 safe_comparator (sortmode mode, const Array<FloatComplex>& a, 00064 bool allow_chk) 00065 { 00066 Array<FloatComplex>::compare_fcn_type result = 0; 00067 00068 if (allow_chk) 00069 { 00070 octave_idx_type k = 0; 00071 for (; k < a.numel () && ! xisnan (a(k)); k++) ; 00072 if (k == a.numel ()) 00073 { 00074 if (mode == ASCENDING) 00075 result = octave_sort<FloatComplex>::ascending_compare; 00076 else if (mode == DESCENDING) 00077 result = octave_sort<FloatComplex>::descending_compare; 00078 } 00079 } 00080 00081 if (! result) 00082 { 00083 if (mode == ASCENDING) 00084 result = nan_ascending_compare; 00085 else if (mode == DESCENDING) 00086 result = nan_descending_compare; 00087 } 00088 00089 return result; 00090 } 00091 00092 INSTANTIATE_ARRAY_SORT (FloatComplex); 00093 00094 INSTANTIATE_ARRAY (FloatComplex, OCTAVE_API); 00095 00096 template OCTAVE_API std::ostream& operator << (std::ostream&, const Array<FloatComplex>&); 00097 00098 #include "DiagArray2.h" 00099 #include "DiagArray2.cc" 00100 00101 template class OCTAVE_API DiagArray2<FloatComplex>;