Use proper isnan check
authorJunjie Bai <bai@in.tum.de>
Sun, 31 Mar 2019 09:05:14 +0000 (02:05 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Sun, 31 Mar 2019 09:08:11 +0000 (02:08 -0700)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/18663

Differential Revision: D14699385

Pulled By: bddppq

fbshipit-source-id: 596ad3371e7704802591e49f7e1c55dc6cd2896f

aten/src/TH/generic/THTensorMoreMath.cpp

index 0adf1a2..4661ef2 100644 (file)
@@ -544,7 +544,7 @@ void THTensor_(diag)(THTensor *r_, THTensor *t, int k)
 /* Emulate NumPy behavior of putting NaNs
  * at the end of an ascending list. */
 #define GT_OR_NAN(x, y) \
-  ((x != x && y == y) || (x > y))
+  ((th_isnan(x) && !(th_isnan(y))) || (x > y))
 
 static void THTensor_(quicksortascend)(scalar_t *arr, int64_t *idx, int64_t elements, int64_t stride)
 {