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

Vector of differently sized arrays #118

Open
antoine-levitt opened this issue Oct 19, 2020 · 6 comments
Open

Vector of differently sized arrays #118

antoine-levitt opened this issue Oct 19, 2020 · 6 comments

Comments

@antoine-levitt
Copy link

julia> size(VectorOfArray([randn(2), randn(4)]))
(2, 2)

This is surprising at least, and runs the risk of subtle bugs if one tries to iterate on the VectorOfArray as if it was a multi-dimensional array.

@ChrisRackauckas
Copy link
Member

This is something we need and use in DiffEq for models which dynamically change over time.

@antoine-levitt
Copy link
Author

Oh I need it too and was pleasantly surprised to see that it worked. The thing is the size method: should it be undefined, or perhaps check that the sizes are all equal at runtime?

@ChrisRackauckas
Copy link
Member

Yeah... I don't know. It's something I've never figured out. size is useful in a lot of cases, but when you have a ragged array it's wrong. Maybe it's worth doing a runtime check.

@antoine-levitt
Copy link
Author

size is useful in a lot of cases

Thought so too but probably it's a code smell for generic code that doesn't assume much about array types. It's only really good for plain old arrays

@ChrisRackauckas
Copy link
Member

Yes, is used when doing conversions like Array(x), but there are issues with it we haven't solved.

@garibarba
Copy link
Contributor

julia> vec(VectorOfArray([rand(3), rand(5)]))
ERROR: ArgumentError: number of rows of each array must match (got [3, 5])
Stacktrace:
 [1] _typed_hcat(#unused#::Type{Float64}, A::Vector{Vector{Float64}})
   @ Base ./abstractarray.jl:1518
 [2] reduce(#unused#::typeof(hcat), A::Vector{Vector{Float64}})
   @ Base ./abstractarray.jl:1572
 [3] Array
   @ ~/.julia/dev/RecursiveArrayTools/src/vector_of_array.jl:11 [inlined]
 [4] convert
   @ ./array.jl:532 [inlined]
 [5] vec(VA::VectorOfArray{Float64, 2, Vector{Vector{Float64}}})
   @ RecursiveArrayTools ~/.julia/dev/RecursiveArrayTools/src/vector_of_array.jl:120
 [6] top-level scope
   @ REPL[11]:1

This can be triggered e.g. when solving a SteadyStateProblem

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

No branches or pull requests

3 participants