Array-C.cc

Go to the documentation of this file.
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 Complex 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<Complex> (const Complex& x)
00040 {
00041   return xisnan (x);
00042 }
00043 
00044 static bool
00045 nan_ascending_compare (const Complex& x, const Complex& 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 Complex& x, const Complex& 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<Complex>::compare_fcn_type
00063 safe_comparator (sortmode mode, const Array<Complex>& a , bool allow_chk)
00064 {
00065   Array<Complex>::compare_fcn_type result = 0;
00066 
00067   if (allow_chk)
00068     {
00069       octave_idx_type k = 0;
00070       for (; k < a.numel () && ! xisnan (a(k)); k++) ;
00071       if (k == a.numel ())
00072         {
00073           if (mode == ASCENDING)
00074             result = octave_sort<Complex>::ascending_compare;
00075           else if (mode == DESCENDING)
00076             result = octave_sort<Complex>::descending_compare;
00077         }
00078     }
00079 
00080   if (! result)
00081     {
00082       if (mode == ASCENDING)
00083         result = nan_ascending_compare;
00084       else if (mode == DESCENDING)
00085         result = nan_descending_compare;
00086     }
00087 
00088   return result;
00089 }
00090 
00091 INSTANTIATE_ARRAY_SORT (Complex);
00092 
00093 INSTANTIATE_ARRAY (Complex, OCTAVE_API);
00094 
00095 template OCTAVE_API std::ostream& operator << (std::ostream&, const Array<Complex>&);
00096 
00097 #include "DiagArray2.h"
00098 #include "DiagArray2.cc"
00099 
00100 template class OCTAVE_API DiagArray2<Complex>;
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines