-
Notifications
You must be signed in to change notification settings - Fork 43
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
Error when mapslices
changes the array size
#396
Comments
mapslices
changes the array size
This isn't actually a problem with show, just where it surfaces. The issue is your With your named To fix we could add a resize check to |
I have a related problem, when I do a mean along one dimension I get a Raster with the same number of dimensions but the time dimension is reduced to a singleton dimension. I think in that case it make sense to keep the name of the dimension, but the lookup type could be changed and the length of the time dimension should also be reduced to one. I can write down an explicit example of my analysis if this is helpful. |
This seems like a solution. If the dims have changed we strip the lookups but keep the names, if not keep everything: @inline function Base.mapslices(f, A::AbstractDimArray; dims=1, kw...)
# Run `mapslices` on the parent array
dimnums = dimnum(A, _astuple(dims))
newdata = mapslices(f, parent(A); dims=dimnums, kw...)
# Run one slice with dimensions to get the transformed dim
d_inds = map(d -> rebuild(d, 1), DD.dims(A, _astuple(dims)))
example_dims = DD.dims(f(view(A, d_inds...)))
newdims = if isnothing(example_dims) || size(example_dims) != size(dims(A, d_inds))
replacement_dims = map(d -> rebuild(d, NoLookup()), d_inds)
newdims = format(setdims(DD.dims(A), replacement_dims), newdata)
else
example_dims
end
return rebuild(A, newdata, newdims)
end Theres a bit of type instability but it works fine: julia> y = mapslices(vec, x; dims=(:chain, :draw))
400×1×2 DimArray{Float64,3} with dimensions: Dim{:chain}, Dim{:draw}, Dim{:x_dim_1}
[:, :, 1]
-0.82393
0.0772902
-0.143477
-0.820947
-0.995829
0.0400354
0.520451
0.696105
0.322051
-1.12305
0.777396
⋮
-0.073463
2.46297
-1.40587
-0.936701
0.691183
0.991734
-0.757005
1.49445
0.857546
-1.05538
-0.0514016
[and 19 more slices...] |
The text was updated successfully, but these errors were encountered: