Repository: cupy/cupy
Pull request: Fix `_count_non_nan` datatype for windows
Closes #2780 

dtype `l` is `int32` in windows and `int64` in linux causing `_count_non_nan` to return different types. 
This value is then passed as parameter to _nanvar_core which explicitly declares it as `int64 _count` in its args list.

Fix it by using the datatype `q` which is int64 in both, windows and linux.
The test suite detects this error when running in windows.

I think we should change several of the `l`s in the code base to `q`s to avoid different behaviors

Problem statement:
`TypeError` when using `cupy.nanstd` and `cupy.nanvar`
Hello, `cupy` raised `TypeError` when I ran the following code.

```python
import cupy as cp

cp.nanstd(cp.asarray([1, 2, 3, 4, 5], dtype='float64'))
```
the error is shown as below:
```python
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-167-1194b91fc5af> in <module>
      1 import cupy as cp
      2 
----> 3 cp.nanstd(cp.asarray([1, 2, 3, 4, 5], dtype='float64'))

~\Anaconda3\envs\py37\lib\site-packages\cupy\statistics\meanvar.py in nanstd(a, axis, dtype, out, ddof, keepdims)
    219     # TODO(okuta): check type
    220     return _statistics._nanstd(
--> 221         a, axis=axis, dtype=dtype, out=out, ddof=ddof, keepdims=keepdims)

cupy/core/_routines_statistics.pyx in cupy.core._routines_statistics._nanstd()

cupy/core/_routines_statistics.pyx in cupy.core._routines_statistics._nanstd()

cupy/core/_routines_statistics.pyx in cupy.core._routines_statistics._nanvar()

cupy/core/reduction.pxi in cupy.core._kernel.ReductionKernel.__call__()

cupy/util.pyx in cupy.util.memoize.decorator.ret()

cupy/core/_kernel.pyx in cupy.core._kernel._decide_params_type()

cupy/core/_kernel.pyx in cupy.core._kernel._decide_params_type_core()

TypeError: Type is mismatched. _count <class 'numpy.int32'> <class 'numpy.int64'>
```

Here is some information about my device:

OS : Windows 10 64 bit

Python : 3.7.5 (default, Oct 31 2019, 15:18:51) [MSC v.1916 64 bit (AMD64)]

numpy Vesion : 1.74.4

CuPy Version : 7.0.0

CUDA Root : C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0

CUDA Build Version : 10000

CUDA Driver Version : 10020

CUDA Runtime Version : 10000

cuBLAS Version : 10000

cuFFT Version : 10000

cuRAND Version : 10000

cuSOLVER Version : (10, 0, 0)

cuSPARSE Version : 10000

NVRTC Version : (10, 0)

cuDNN Build Version : 7605

cuDNN Version : 7605

NCCL Build Version : None

NCCL Runtime Version : None

Hints from issue discussion:
Seems to be a bug on how some datatypes are being handled in windows.
We will look into this.

_count is being returned as int32 instead of int64 
We should check
https://github.com/cupy/cupy/blob/master/cupy/core/_routines_statistics.pyx#L438

Commit message: Dtype clarifications for windows

Patch to review:
diff --git a/cupy/core/_dtype.pyx b/cupy/core/_dtype.pyx
index e0abcda7b8d..54018e1c149 100644
--- a/cupy/core/_dtype.pyx
+++ b/cupy/core/_dtype.pyx
@@ -9,12 +9,12 @@ all_type_chars = '?bhilqBHILQefdFD'
 # b ... int8
 # h ... int16
 # i ... int32
-# l ... int64
+# l ... int64  (int32 in windows)
 # q ... int64
 # B ... uint8
 # H ... uint16
 # I ... uint32
-# L ... uint64
+# L ... uint64  (uint32 in windows0
 # Q ... uint64
 # e ... float16
 # f ... float32
diff --git a/cupy/core/_routines_statistics.pyx b/cupy/core/_routines_statistics.pyx
index 9727dbab176..07c841978cb 100644
--- a/cupy/core/_routines_statistics.pyx
+++ b/cupy/core/_routines_statistics.pyx
@@ -521,7 +521,7 @@ cdef _nanmean_func = create_reduction_func(
 
 _count_non_nan = create_reduction_func(
     'cupy_count_non_nan',
-    ('e->l', 'f->l', 'd->l'),
+    ('e->q', 'f->q', 'd->q'),
     ('isnan(in0) ? 0 : 1', 'a + b', 'out0 = a', None), 0)
 
 


Code review comments:
diff_hunk: @@ -9,12 +9,12 @@ all_type_chars = '?bhilqBHILQefdFD'
 # b ... int8
 # h ... int16
 # i ... int32
-# l ... int64
+# l ... int64  (int32 in windows)
 # q ... int64
 # B ... uint8
 # H ... uint16
 # I ... uint32
-# L ... uint64
+# L ... uint64  (uint32 in windows0
path: cupy/core/_dtype.pyx
text: @user1:
Thanks for adding this, Emilio! Found a typo:
```suggestion
# L ... uint64  (uint32 in windows)
```

@author:
Thanks 😅