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

support vectors? #35

Open
tbeason opened this issue May 30, 2020 · 4 comments
Open

support vectors? #35

tbeason opened this issue May 30, 2020 · 4 comments

Comments

@tbeason
Copy link

tbeason commented May 30, 2020

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
@johnnychen94
Copy link
Member

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.

@timholy
Copy link
Member

timholy commented May 31, 2020

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.

@Lincoln-Hannah
Copy link

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    

@tbeason
Copy link
Author

tbeason commented Sep 20, 2023

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

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

No branches or pull requests

4 participants