Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broadcasting with view() doesn't work as expected #4033

Open
tomchor opened this issue Jan 7, 2025 · 1 comment
Open

Broadcasting with view() doesn't work as expected #4033

tomchor opened this issue Jan 7, 2025 · 1 comment

Comments

@tomchor
Copy link
Collaborator

tomchor commented Jan 7, 2025

Setting Field values using broacasting seems to fail silently when using view(). For example in the MWE below, I'm creating two 2D fields and I'm trying to set the first row of E using the last row of U:

using Oceananigans
grid = RectilinearGrid(topology = (Bounded, Bounded, Flat), size = (3, 3), extent = (1, 1))

U = XFaceField(grid)
set!(U, reshape(1:(grid.Nx+1)*grid.Ny, (:, grid.Ny)))

E = XFaceField(grid)

view(E, 1, :, :) .= view(U, grid.Nx+1, :, :)

However, when I check if what I just set is true I get:

view(E, 1, :, :) == view(U, grid.Nx + 1, :, :) = false

What did happen apparently is that the first row E got assigned the values from the first row of U:

view(E, 1, :, :) == view(U, 1, :, :) = true

Am I missing something here? This works exactly as expected when using interior:

julia> interior(E, 1, :, :) .= interior(U, grid.Nx+1, :, :)
3×1 view(::Array{Float64, 3}, 4, 4:6, 1:1) with eltype Float64:
  4.0
  8.0
 12.0

julia> @show view(E, 1, :, :) == view(U, grid.Nx+1, :, :)
view(E, 1, :, :) == view(U, grid.Nx + 1, :, :) = true
true

julia> @show view(E, 1, :, :) == view(U, 1, :, :)
view(E, 1, :, :) == view(U, 1, :, :) = false
false

But using interior prevents me from using halo indices, so ideally I'd use another method for that.

@glwagner
Copy link
Member

glwagner commented Jan 7, 2025

This is probably an issue with indexing for windowed fields if I had to guess

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants