PaddedViews.jl
PaddedViews.jl copied to clipboard
support vectors?
Why is it not possible to provide a PaddedView
for a Vector
?
a = collect(1:10)
PaddedView(1,a,(10,2),(1,2)) # doesn't work
PaddedView(1,hcat(a,a),(10,3),(1,2)) # works
Right now, PaddedView
doesn't change ndims
, so the correct way is to
-
PaddedView(1,a,(10,), (1,))
-
PaddedView(1, repeat(a, 1, 1), (10, 3), (1, 2))
Said that, I suppose not doing this might just be an oversight. If there isn't type instability issue, supporting cases when ndims(data) != length(padded_axes)
could be handy. If you could help to make a PR for this, I'm glad to review and merge it.
One could implement this with reshape(parent, Val(N))
where N
comes from the dims/axes tuple. One would have to decide whether N < dims(A)
is acceptable or not.
Marking this as "help wanted," meaning a PR would be considered but does not seem to be a priority for any of the maintainers.
A related useful functionality would be converting uneven nested vectors to a padded matrix.
x = [ [1,2], [3,4,5] ]
[vcat(y, fill(missing, maximum( length, x) - length(y))) for y in x] |> SplitApplyCombine.combinedims
Is this maybe a better way than using the repeat
trick above?
julia> PaddedView(1,view(a,:,:),(10,2),(1,2))
10×2 PaddedView(1, OffsetArray(view(::Matrix{Int64}, :, :), 1:10, 2:2), (Base.OneTo(10), Base.OneTo(2))) with eltype Int64:
1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10