Comments (8)
Actually, I have to rectify, both commands do the same thing because c1[1, :, 1]
on the LHS calls view(c1, 1, :, 1)
from oceananigans.jl.
It has to do with view(field, i, j, k)
that returns a WindowedField
with 3 dimensions while getindex(field, i, j, k)
returns field.data[i, j, k]
broadcast follows this pattern:
julia> Meta.@lower c1[1, :, 1] .= c2[2, :, 3]
:($(Expr(:thunk, CodeInfo(
@ none within `top-level scope`
1 ─ %1 = Base.dotview(c1, 1, :, 1)
│ %2 = Base.getindex(c2, 2, :, 3)
│ %3 = Base.broadcasted(Base.identity, %2)
│ %4 = Base.materialize!(%1, %3)
└── return %4
))))
and
julia> axes(Base.dotview(c1, 1, :, 1))
(1:1, Base.OneTo(3), 1:1)
julia> axes(Base.getindex(c2, 2, :, 3))
(OffsetArrays.IdOffsetRange(values=-2:6, indices=-2:6),)
This will work:
c1[1, :, 1] .= view(c2, 1, :, 1)
In general c1[1, :, 1] .= c2[1, :, 1]
is not really GPU-compatible. Anyways, if we want to support this behavior we need to change getindex(field, i, j, k)
to return a view instead of the underlying data in case of a Colon
index.
We might need to think this a bit though, because it would be a big change and might break other implementations
from oceananigans.jl.
This in src/Fields/field.jl
should allow that type of broadcasting
@propagate_inbounds Base.getindex(f::Field, ::Colon, j, k) = view(f, :, j, k)
@propagate_inbounds Base.getindex(f::Field, i, ::Colon, k) = view(f, i, :, k)
@propagate_inbounds Base.getindex(f::Field, i, j, ::Colon) = view(f, i, j, :)
@propagate_inbounds Base.getindex(f::Field, ::Colon, ::Colon, k) = view(f, :, :, k)
@propagate_inbounds Base.getindex(f::Field, ::Colon, j, ::Colon) = view(f, :, j, :)
@propagate_inbounds Base.getindex(f::Field, i, ::Colon, ::Colon) = view(f, i, :, :)
@propagate_inbounds Base.getindex(f::Field, ::Colon, ::Colon, ::Colon) = view(f, :, :, :)
from oceananigans.jl.
I see!
is this
c1[1, :, 1] .= view(c2, 1, :, 1)or this
view(c1, 1, :, 1) .= view(c2, 1, :, 1)preferred?
The second one is preferred because it's GPU-compatible.
I am not sure if we should add that behavior. That would essentially change the underlying functionality of getindex
to return different types when using different indices, so it would be a big change. I am not sure allowing sliced broadcasts is enough to justify this change.
from oceananigans.jl.
I see!
is thisc1[1, :, 1] .= view(c2, 1, :, 1)or this
view(c1, 1, :, 1) .= view(c2, 1, :, 1)preferred?
The second one is preferred because it's GPU-compatible. I am not sure if we should add that behavior. That would essentially change the underlying functionality of
getindex
to return different types when using different indices, so it would be a big change. I am not sure allowing sliced broadcasts is enough to justify this change.
I think those are actually identical (or they could be --- for arrays broadcasting will call view
under the hood)
from oceananigans.jl.
I see!
is this
c1[1, :, 1] .= view(c2, 1, :, 1)
or this
view(c1, 1, :, 1) .= view(c2, 1, :, 1)
preferred?
from oceananigans.jl.
This in
src/Fields/field.jl
should allow that type of broadcasting@propagate_inbounds Base.getindex(f::Field, ::Colon, j, k) = view(f, :, j, k) @propagate_inbounds Base.getindex(f::Field, i, ::Colon, k) = view(f, i, :, k) @propagate_inbounds Base.getindex(f::Field, i, j, ::Colon) = view(f, i, j, :) @propagate_inbounds Base.getindex(f::Field, ::Colon, ::Colon, k) = view(f, :, :, k) @propagate_inbounds Base.getindex(f::Field, ::Colon, j, ::Colon) = view(f, :, j, :) @propagate_inbounds Base.getindex(f::Field, i, ::Colon, ::Colon) = view(f, i, :, :) @propagate_inbounds Base.getindex(f::Field, ::Colon, ::Colon, ::Colon) = view(f, :, :, :)
Would this be a good idea to add?
from oceananigans.jl.
Ok cool. Gotcha. I’m closing this.
from oceananigans.jl.
Related Issues (20)
- Mid-Level Enzyme + Oceananigans Integration Test HOT 1
- Update docs to change `FieldSlicer` to `indices` HOT 1
- `interpolate` doesn't work with `Nothing` locations HOT 7
- Should the time step wizard take into account of background velocity in calculation of CFL number?
- bug with background fields? HOT 14
- Are we actually `@unroll`ing when we think we are? HOT 13
- Documentation for latest versions does not seem to be working HOT 3
- Slow initialization after updating to v0.90.0 HOT 35
- `compute_regionally` must be deprecated HOT 3
- Prescribing realistic bottom bathymetry HOT 3
- Fix up `ShallowWaterModel.jl` HOT 15
- Nonhydrostatic pressure correction broken? HOT 6
- `JLD2OutputWriter` and `Checkpointer` don't work when `max_filesize` and `part` are specified. HOT 2
- Bugs in the Tilted Bottom Boundary Layer Example Code HOT 7
- `LagrangianParticles` get moved at the right of `Periodic` topology when it shouldn't be HOT 3
- Split-explicit inbounds checks? HOT 2
- Three-dimensional `StokesDrift` docstring example may be misleading HOT 2
- Improve example for 3D Stokes drift HOT 1
- `maximum(abs, v)` doesn't work on GPU in Julia 1.10.0 with grid size larger than (10, 10, 10) HOT 14
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from oceananigans.jl.