# Inconsistent results using view()

**URL:** https://discourse.julialang.org/t/inconsistent-results-using-view/138785
**Category:** General Usage
**Created:** [August 13, 2026, 1:43pm UTC](https://discourse.julialang.org/t/inconsistent-results-using-view/138785 "2026-08-13T13:43:48Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![tomtom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomtom/32/5106_2.png) [@tomtom](https://discourse.julialang.org/u/tomtom)
#### Post date: [August 13, 2026, 1:43pm UTC](https://discourse.julialang.org/t/inconsistent-results-using-view/138785/1 "2026-08-13T13:43:48Z")

</div>

I don’t understand why there would be _any_ difference by using `view()`:

```julia-auto
julia> Random.seed!(1);

julia> xhmat = randn(Float32, 10, 1000);

julia> [sum(xhmat[d, :]) for d in 1:10]
10-element Vector{Float32}:
   6.1436114
  31.91372
   9.005221
 -40.03097
 -48.17327
  -6.9555407
  35.577076
 -33.41585
  12.131447
 -22.086914

julia> [sum(view(xhmat, d, :)) for d in 1:10]
10-element Vector{Float32}:
   6.1436205
  31.913723
   9.005228
 -40.030956
 -48.173267
  -6.9555435
  35.577084
 -33.41586
  12.13145
 -22.086939

```

using 1.12.6

---

<div class="post-metadata">

### Author: ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)
#### Post date: [August 13, 2026, 1:48pm UTC](https://discourse.julialang.org/t/inconsistent-results-using-view/138785/2 "2026-08-13T13:48:49Z")

</div>

I can’t reproduce the difference, and my printed values are close to but not exactly either of your results. Save those 2 vectors to `y` and `z` then check `all(iszero, y .- z)` in case it’s just some odd `display` rounding. If it’s some platform-specific issue, share your full `versioninfo()`.

Here’s what I see:

```julia-auto
julia> versioninfo()
Julia Version 1.12.6
Commit 15346901f0 (2026-04-09 19:20 UTC)
Build Info:
  Official https://julialang.org release
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: 8 × Intel(R) Core(TM) i7-1065G7 CPU @ 1.30GHz
  WORD_SIZE: 64
  LLVM: libLLVM-18.1.7 (ORCJIT, icelake-client)
  GC: Built with stock GC
Threads: 1 default, 1 interactive, 1 GC (on 8 virtual cores)

julia> using Random; Random.seed!(1);

julia> y = [sum(xhmat[d, :]) for d in 1:10];

julia> z = [sum(view(xhmat, d, :)) for d in 1:10];

julia> all(iszero, y .- z)
true

julia> y # z prints the same thing
10-element Vector{Float32}:
   6.143616
  31.913727
   9.005218
 -40.030968
 -48.173264
  -6.9555407
  35.577076
 -33.41585
  12.131446
 -22.086918

```

---

<div class="post-metadata">

### Author: ![tomtom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomtom/32/5106_2.png) [@tomtom](https://discourse.julialang.org/u/tomtom)
#### Post date: [August 13, 2026, 1:52pm UTC](https://discourse.julialang.org/t/inconsistent-results-using-view/138785/3 "2026-08-13T13:52:30Z")

</div>

obviously not from display rounding:

```julia-auto
julia> y = [sum(xhmat[d, :]) for d in 1:10];

julia> z = [sum(view(xhmat, d, :)) for d in 1:10];

julia> all(iszero, y .- z)
false

julia> any(iszero, y .- z)
false

```

```julia-auto
julia> versioninfo()
Julia Version 1.12.6
Commit 15346901f00 (2026-04-09 19:20 UTC)
Build Info:
  Official https://julialang.org release
Platform Info:
  OS: macOS (arm64-apple-darwin24.0.0)
  CPU: 24 × Apple M2 Ultra
  WORD_SIZE: 64
  LLVM: libLLVM-18.1.7 (ORCJIT, apple-m2)
  GC: Built with stock GC
Threads: 1 default, 1 interactive, 1 GC (on 16 virtual cores)
Environment:
  DYLD_LIBRARY_PATH = /Developer/NVIDIA/CUDA-9.1/lib:
  JULIA_EDITOR = Atom

```

---

<div class="post-metadata">

### Author: ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)
#### Post date: [August 13, 2026, 1:56pm UTC](https://discourse.julialang.org/t/inconsistent-results-using-view/138785/4 "2026-08-13T13:56:01Z")

</div>

I think that’s worth filing an issue, I shared my results if you need a Windows comparison.

---

<div class="post-metadata">

### Author: ![tomtom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomtom/32/5106_2.png) [@tomtom](https://discourse.julialang.org/u/tomtom)
#### Post date: [August 13, 2026, 1:57pm UTC](https://discourse.julialang.org/t/inconsistent-results-using-view/138785/5 "2026-08-13T13:57:28Z")

</div>

indeed there’re a lot more strange inconsistencies… I just trying to produce a minimum example here…

how to file an issue???

---

<div class="post-metadata">

### Author: ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)
#### Post date: [August 13, 2026, 2:01pm UTC](https://discourse.julialang.org/t/inconsistent-results-using-view/138785/6 "2026-08-13T14:01:01Z")

</div>

Here:

> **[Issues · JuliaLang/julia](https://github.com/JuliaLang/julia/issues)**
>
> The Julia Programming Language. Contribute to JuliaLang/julia development by creating an account on GitHub.

There might already be an issue there so try searching for it a bit first. If you miss it, people will link them and close the less general ones.

---

<div class="post-metadata">

### Author: ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)
#### Post date: [August 13, 2026, 2:03pm UTC](https://discourse.julialang.org/t/inconsistent-results-using-view/138785/7 "2026-08-13T14:03:56Z")

</div>

This is

> <https://github.com/JuliaLang/julia/issues/52457>
>
> This was originally noticed in:
> https://github.com/JuliaLang/julia/issues/28848…#issuecomment-1832028498
> 
> 
> \> I don't know if this is somewhat related to this issue, but I also found an accuracy issue which I think is more troublesome because it also affects \`DataFrames.jl\`
> \> 
> \> here is the MVP
> \> 
> \> \`\`\`
> \> using Distributions
> \> using Random
> \> 
> \> # It doesn't happen always, here is a seed where this happens.
> \> rng = MersenneTwister(630);
> \> v = rand(rng, Normal(zero(Float32), one(Float32)), 1000)
> \> sa = @view v\[collect(1:end)\]
> \> 
> \> # View (as SubArray) vs Vector
> \> sum(sa) ≈ sum(v) # false
> \> # They are different! and worse part is that the view version is less accurate! (according to Kahan compensated summation)
> \> 
> \> IndexStyle(v) isa IndexLinear # true
> \> IndexStyle(sa) isa IndexCartesian #true
> \> 
> \> # They are dispatched to different implementations in base/reduce.jl \> \_mapreduce 
> \> \`\`\`
> \> 
> 
> Another MWE is:
> 
> \`\`\`
> julia\> using Statistics, Random
> 
> julia\> Random.seed!(1);
> 
> julia\> x = rand(Float32, 10^6);
> 
> julia\> mean(x)
> 0.49974534f0
> 
> julia\> mean(@view x\[:\])
> 0.49974534f0
> 
> julia\> mean(@view x\[collect(1:end)\])
> 0.49974778f0
> \`\`\`
> 
> @mbauman points out that the latter in this MWE hits the naive iterator: \`foldl(+, x)/length(x)\` which leads to the poor floating point accuracy.
> 
> cc @el-oso

Summing floating point numbers doesn’t guarantee the associativity of the operation — and the results really depend upon it!

---

<div class="post-metadata">

### Author: ![tomtom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomtom/32/5106_2.png) [@tomtom](https://discourse.julialang.org/u/tomtom)
#### Post date: [August 13, 2026, 2:05pm UTC](https://discourse.julialang.org/t/inconsistent-results-using-view/138785/8 "2026-08-13T14:05:42Z")

</div>

[issue filed](https://github.com/JuliaLang/julia/issues/62708)

---

<div class="post-metadata">

### Author: ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)
#### Post date: [August 13, 2026, 2:16pm UTC](https://discourse.julialang.org/t/inconsistent-results-using-view/138785/9 "2026-08-13T14:16:27Z")

</div>

It does appear that `sum` SIMDs for the vectors and not the non-contiguous views, so are my equal results just some architecture quirk?
