Skip to content

hotfix VectorOfArray Cartesian indexing #100

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

Merged
merged 1 commit into from
May 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "RecursiveArrayTools"
uuid = "731186ca-8d62-57ce-b412-fbd966d074cd"
authors = ["Chris Rackauckas <[email protected]>"]
version = "2.3.4"
version = "2.3.5"

[deps]
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
Expand Down
8 changes: 4 additions & 4 deletions src/vector_of_array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ Base.@propagate_inbounds Base.getindex(VA::AbstractDiffEqArray{T, N}, I::Abstrac
Base.@propagate_inbounds Base.getindex(VA::AbstractVectorOfArray{T, N}, i::Int,::Colon) where {T, N} = [VA.u[j][i] for j in 1:length(VA)]
Base.@propagate_inbounds function Base.getindex(VA::AbstractVectorOfArray{T,N}, ii::CartesianIndex) where {T, N}
ti = Tuple(ii)
i = first(ti)
jj = CartesianIndex(Base.tail(ti))
i = last(ti)
jj = CartesianIndex(Base.front(ti))
return VA.u[i][jj]
end
Base.@propagate_inbounds Base.setindex!(VA::AbstractVectorOfArray{T, N}, v, I::Int) where {T, N} = VA.u[I] = v
Expand All @@ -56,8 +56,8 @@ Base.@propagate_inbounds function Base.setindex!(VA::AbstractVectorOfArray{T, N}
end
Base.@propagate_inbounds function Base.setindex!(VA::AbstractVectorOfArray{T,N}, x, ii::CartesianIndex) where {T, N}
ti = Tuple(ii)
i = first(ti)
jj = CartesianIndex(Base.tail(ti))
i = last(ti)
jj = CartesianIndex(Base.front(ti))
return VA.u[i][jj] = x
end

Expand Down
7 changes: 4 additions & 3 deletions test/basic_indexing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,14 @@ testva[1:2, 1:2]

# Test broadcast
a = testva .+ rand(3,3)
@test_broken a.= testva
a.= testva
@test all(a .== testva)

recs = [rand(2,2) for i in 1:5]
testva = VectorOfArray(recs)
@test Array(testva) isa Array{Float64,3}

v = VectorOfArray([zeros(20), zeros(10,10), zeros(3,3,3)])
v[CartesianIndex((3, 2, 3, 2))] = 1
@test v[CartesianIndex((3, 2, 3, 2))] == 1
v[CartesianIndex((2, 3, 2, 3))] = 1
@test v[CartesianIndex((2, 3, 2, 3))] == 1
@test v.u[3][2, 3, 2] == 1
2 changes: 2 additions & 0 deletions test/upstream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ sol = solve(prob,Tsit5())
sol = solve(prob,AutoTsit5(Rosenbrock23(autodiff=false)))
sol = solve(prob,AutoTsit5(Rosenbrock23()))

@test all(Array(sol) .== sol)

function f!(F, vars)
x = vars.x[1]
F.x[1][1] = (x[1]+3)*(x[2]^3-7)+18
Expand Down