Ignore:
Timestamp:
04/13/18 16:25:46 (6 years ago)
Author:
yushan
Message:

Branch EP merged with Dev_cmip6 @r1481

File:
1 edited

Legend:

Unmodified
Added
Removed
  • XIOS/dev/branch_openmp/src/parse_expr/operator_expr.hpp

    r1038 r1482  
    77#include "exception.hpp" 
    88#include "array_new.hpp" 
     9#include "utils.hpp" 
    910 
    1011using namespace std; 
     
    253254    static inline double div_ss(double x, double y)   { return x / y; } 
    254255    static inline double pow_ss(double x, double y)   { return std::pow(x,y); } 
    255     static inline double eq_ss(double x, double y)    { return x == y; } 
     256    static inline double eq_ss(double x, double y) // specific check for NaN 
     257    { 
     258       bool xNan=NumTraits<double>::isNan(x) ; 
     259       bool yNan=NumTraits<double>::isNan(y) ; 
     260       if (xNan && yNan) return true ; 
     261       else if (xNan) return false ; 
     262       else if (yNan) return false ; 
     263       else return x == y; 
     264    } 
     265 
    256266    static inline double lt_ss(double x, double y)    { return x < y; } 
    257267    static inline double gt_ss(double x, double y)    { return x > y; } 
    258268    static inline double le_ss(double x, double y)    { return x <= y; } 
    259269    static inline double ge_ss(double x, double y)    { return x >= y; } 
    260     static inline double ne_ss(double x, double y)    { return x != y; } 
     270    static inline double ne_ss(double x, double y) // specific check for NaN 
     271    { 
     272       bool xNan=NumTraits<double>::isNan(x) ; 
     273       bool yNan=NumTraits<double>::isNan(y) ; 
     274       if (xNan && yNan) return false ; 
     275       else if (xNan) return true ; 
     276       else if (yNan) return true ;       
     277       else return x != y; 
     278    } 
    261279 
    262280    static inline CArray<double,1> neg_f(const CArray<double,1>& x)   { return Array<double,1>(-x); } 
     
    286304    static inline CArray<double,1> div_fs(const CArray<double,1>& x, double y)   { return Array<double,1>(x / y); } 
    287305    static inline CArray<double,1> pow_fs(const CArray<double,1>& x, double y)   { return Array<double,1>(pow(x,y)); } 
    288     static inline CArray<double,1> eq_fs(const CArray<double,1>& x, double y)    { return Array<double,1>(x == y); } 
     306    static inline CArray<double,1> eq_fs(const CArray<double,1>& x, double y) // specific check for NaN 
     307    { 
     308      if (NumTraits<double>::isNan(y)) 
     309      { 
     310        CArray<double,1> ret(x.numElements()) ; 
     311        Array<double,1>::const_iterator itx=x.begin(),itxe=x.end(); 
     312        Array<double,1>::iterator itret=ret.begin() ; 
     313        for(;itx!=itxe;++itx,++itret) *itret=NumTraits<double>::isNan(*itx) ; 
     314        return ret ; 
     315      } 
     316      else return Array<double,1>(x == y);  
     317    } 
     318 
    289319    static inline CArray<double,1> lt_fs(const CArray<double,1>& x, double y)    { return Array<double,1>(x < y); } 
    290320    static inline CArray<double,1> gt_fs(const CArray<double,1>& x, double y)    { return Array<double,1>(x > y); } 
    291321    static inline CArray<double,1> le_fs(const CArray<double,1>& x, double y)    { return Array<double,1>(x <= y); } 
    292322    static inline CArray<double,1> ge_fs(const CArray<double,1>& x, double y)    { return Array<double,1>(x >= y); } 
    293     static inline CArray<double,1> ne_fs(const CArray<double,1>& x, double y)    { return Array<double,1>(x != y); } 
     323    static  inline CArray<double,1> ne_fs(const CArray<double,1>& x, double y) // specific check for NaN 
     324    { 
     325      if (NumTraits<double>::isNan(y)) 
     326      { 
     327        CArray<double,1> ret(x.numElements()) ; 
     328        Array<double,1>::const_iterator itx=x.begin(),itxe=x.end(); 
     329        Array<double,1>::iterator itret=ret.begin() ; 
     330        for(;itx!=itxe;++itx,++itret) *itret = !NumTraits<double>::isNan(*itx) ; 
     331        return ret ; 
     332      } 
     333      else return Array<double,1>(x != y);  
     334    } 
    294335 
    295336    static inline CArray<double,1> add_sf(double x, const CArray<double,1>& y)   { return Array<double,1>(x + y); } 
     
    297338    static inline CArray<double,1> mult_sf(double x, const CArray<double,1>& y)  { return Array<double,1>(x * y); } 
    298339    static inline CArray<double,1> div_sf(double x, const CArray<double,1>& y)   { return Array<double,1>(x / y); } 
    299     static inline CArray<double,1> eq_sf(double x, const CArray<double,1>& y)    { return Array<double,1>(x == y); } 
     340    static inline CArray<double,1> eq_sf(double x, const CArray<double,1>& y) // specific check for NaN 
     341    { 
     342      if (NumTraits<double>::isNan(x)) 
     343      { 
     344        CArray<double,1> ret(y.numElements()) ; 
     345        Array<double,1>::const_iterator ity=y.begin(),itye=y.end(); 
     346        Array<double,1>::iterator itret=ret.begin() ; 
     347        for(;ity!=itye;++ity,++itret) *itret=NumTraits<double>::isNan(*ity) ; 
     348        return ret ; 
     349      } 
     350      else return Array<double,1>(x == y);  
     351    } 
     352 
    300353    static inline CArray<double,1> lt_sf(double x, const CArray<double,1>& y)    { return Array<double,1>(x < y); } 
    301354    static inline CArray<double,1> gt_sf(double x, const CArray<double,1>& y)    { return Array<double,1>(x > y); } 
    302355    static inline CArray<double,1> le_sf(double x, const CArray<double,1>& y)    { return Array<double,1>(x <= y); } 
    303356    static inline CArray<double,1> ge_sf(double x, const CArray<double,1>& y)    { return Array<double,1>(x >= y); } 
    304     static inline CArray<double,1> ne_sf(double x, const CArray<double,1>& y)    { return Array<double,1>(x != y); } 
     357    static inline CArray<double,1> ne_sf(double x, const CArray<double,1>& y) // specific check for NaN 
     358    { 
     359      if (NumTraits<double>::isNan(x)) 
     360      { 
     361        CArray<double,1> ret(y.numElements()) ; 
     362        Array<double,1>::const_iterator ity=y.begin(),itye=y.end(); 
     363        Array<double,1>::iterator itret=ret.begin() ; 
     364        for(;ity!=itye;++ity,++itret) *itret=!NumTraits<double>::isNan(*ity) ; 
     365        return ret ; 
     366      } 
     367      else return Array<double,1>(x != y); 
     368    } 
     369 
    305370 
    306371 
Note: See TracChangeset for help on using the changeset viewer.