# Result of mean() is different for CuArray vs. regular Int64 array

**URL:** <https://discourse.julialang.org/t/result-of-mean-is-different-for-cuarray-vs-regular-int64-array/60497>\
**Category:** GPU\
**Created:** [May 4, 2021, 5:23am UTC](https://discourse.julialang.org/t/result-of-mean-is-different-for-cuarray-vs-regular-int64-array/60497 "2021-05-04T05:23:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![drjoke](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/drjoke/32/23562_2.png) [@drjoke](https://discourse.julialang.org/u/drjoke)\
**Post date:** [May 4, 2021, 5:23am UTC](https://discourse.julialang.org/t/result-of-mean-is-different-for-cuarray-vs-regular-int64-array/60497/1 "2021-05-04T05:23:45Z")

</div>

mean() is returning different results for CuArray vs regular Int64 array.

```julia
using CUDA
using Statistics
INT = rand(Int64, 100000000)
CUDA_INT = CuArray(INT)

```

I get 7.086957573875891e14 for mean(INT) and -2.8149924332010597e10 for mean(CUDA\_INT)

Also, I get the following error the first time I run mean(CUDA\_INT)

```julia
┌ Error: Cannot use NVML, as it failed to initialize
│ exception =
│ NVML could not be initialized (NVML_ERROR_DRIVER_NOT_LOADED)

```

But subsequent runs of mean(CUDA\_INT) do not produce the error.

I am running Julia inside WSL2 on Windows 10.

I also tried doing the same thing with Float64, but both regular array and CuArray produce the same mean().

---

<div class="post-metadata">

**Author:** ![maleadt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maleadt/32/10097_2.png) [@maleadt](https://discourse.julialang.org/u/maleadt)\
**Post date:** [May 4, 2021, 5:35am UTC](https://discourse.julialang.org/t/result-of-mean-is-different-for-cuarray-vs-regular-int64-array/60497/2 "2021-05-04T05:35:21Z")

</div>

`mean` is currently implemented as `sum` / `length`, as it was in on the CPU before [https://github.com/JuliaLang/Statistics.jl/pull/25](https://github.com/JuliaLang/Statistics.jl/pull/25), so this just overflows here.
