PaddedViews.jl icon indicating copy to clipboard operation
PaddedViews.jl copied to clipboard

support vectors?

Open tbeason opened this issue 4 years ago • 4 comments

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

tbeason avatar May 30 '20 18:05 tbeason

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.

johnnychen94 avatar May 31 '20 05:05 johnnychen94

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.

timholy avatar May 31 '20 11:05 timholy

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    

Lincoln-Hannah avatar May 25 '23 04:05 Lincoln-Hannah

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

tbeason avatar Sep 20 '23 13:09 tbeason