Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
jlchan committed May 6, 2024
1 parent 8ece560 commit f4675f2
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 35 deletions.
72 changes: 39 additions & 33 deletions src/vector_of_array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ returns a vector of the series for each component, that is, `A[i,:]` for each `i
A plot recipe is provided, which plots the `A[i,:]` series.
There is also support for `VectorOfArray` constructed from multi-dimensional arrays
```julia
VectorOfArray(u::AbstractArray{AT}) where {T, N, AT <: AbstractArray{T, N}}
```
Expand Down Expand Up @@ -351,48 +352,53 @@ Base.@propagate_inbounds function _getindex(A::AbstractDiffEqArray, ::NotSymboli
end

struct ParameterIndexingError <: Exception
sym
sym::Any
end

function Base.showerror(io::IO, pie::ParameterIndexingError)
print(io, "Indexing with parameters is deprecated. Use `getp(A, $(pie.sym))` for parameter indexing.")
print(io,

Check warning on line 359 in src/vector_of_array.jl

View check run for this annotation

Codecov / codecov/patch

src/vector_of_array.jl#L359

Added line #L359 was not covered by tests
"Indexing with parameters is deprecated. Use `getp(A, $(pie.sym))` for parameter indexing.")
end

# Symbolic Indexing Methods
for (symtype, elsymtype, valtype, errcheck) in [
(ScalarSymbolic, SymbolicIndexingInterface.SymbolicTypeTrait, Any, :(is_parameter(A, sym))),
(ArraySymbolic, SymbolicIndexingInterface.SymbolicTypeTrait, Any, :(is_parameter(A, sym))),
(NotSymbolic, SymbolicIndexingInterface.SymbolicTypeTrait, Union{<:Tuple, <:AbstractArray},
:(all(x -> is_parameter(A, x), sym))),
(ScalarSymbolic, SymbolicIndexingInterface.SymbolicTypeTrait,
Any, :(is_parameter(A, sym))),
(ArraySymbolic, SymbolicIndexingInterface.SymbolicTypeTrait,
Any, :(is_parameter(A, sym))),
(NotSymbolic, SymbolicIndexingInterface.SymbolicTypeTrait,
Union{<:Tuple, <:AbstractArray},
:(all(x -> is_parameter(A, x), sym)))
]
@eval Base.@propagate_inbounds function _getindex(A::AbstractDiffEqArray, ::$symtype,
::$elsymtype, sym::$valtype)
if $errcheck
throw(ParameterIndexingError(sym))
@eval Base.@propagate_inbounds function _getindex(A::AbstractDiffEqArray, ::$symtype,
::$elsymtype, sym::$valtype)
if $errcheck
throw(ParameterIndexingError(sym))
end
getu(A, sym)(A)
end
getu(A, sym)(A)
end
@eval Base.@propagate_inbounds function _getindex(A::AbstractDiffEqArray, ::$symtype,
::$elsymtype, sym::$valtype, arg)
if $errcheck
throw(ParameterIndexingError(sym))
@eval Base.@propagate_inbounds function _getindex(A::AbstractDiffEqArray, ::$symtype,

Check warning on line 380 in src/vector_of_array.jl

View check run for this annotation

Codecov / codecov/patch

src/vector_of_array.jl#L380

Added line #L380 was not covered by tests
::$elsymtype, sym::$valtype, arg)
if $errcheck
throw(ParameterIndexingError(sym))

Check warning on line 383 in src/vector_of_array.jl

View check run for this annotation

Codecov / codecov/patch

src/vector_of_array.jl#L382-L383

Added lines #L382 - L383 were not covered by tests
end
getu(A, sym)(A, arg)

Check warning on line 385 in src/vector_of_array.jl

View check run for this annotation

Codecov / codecov/patch

src/vector_of_array.jl#L385

Added line #L385 was not covered by tests
end
getu(A, sym)(A, arg)
end
@eval Base.@propagate_inbounds function _getindex(A::AbstractDiffEqArray, ::$symtype,
::$elsymtype, sym::$valtype, arg::Union{AbstractArray{Int}, AbstractArray{Bool}})
if $errcheck
throw(ParameterIndexingError(sym))
@eval Base.@propagate_inbounds function _getindex(A::AbstractDiffEqArray, ::$symtype,
::$elsymtype, sym::$valtype, arg::Union{
AbstractArray{Int}, AbstractArray{Bool}})
if $errcheck
throw(ParameterIndexingError(sym))

Check warning on line 391 in src/vector_of_array.jl

View check run for this annotation

Codecov / codecov/patch

src/vector_of_array.jl#L391

Added line #L391 was not covered by tests
end
getu(A, sym).((A,), arg)
end
getu(A, sym).((A,), arg)
end
@eval Base.@propagate_inbounds function _getindex(A::AbstractDiffEqArray, ::$symtype,
::$elsymtype, sym::$valtype, ::Colon)
if $errcheck
throw(ParameterIndexingError(sym))
@eval Base.@propagate_inbounds function _getindex(A::AbstractDiffEqArray, ::$symtype,
::$elsymtype, sym::$valtype, ::Colon)
if $errcheck
throw(ParameterIndexingError(sym))

Check warning on line 398 in src/vector_of_array.jl

View check run for this annotation

Codecov / codecov/patch

src/vector_of_array.jl#L398

Added line #L398 was not covered by tests
end
getu(A, sym)(A)
end
getu(A, sym)(A)
end
end

Base.@propagate_inbounds function _getindex(A::AbstractDiffEqArray, ::ScalarSymbolic,
Expand All @@ -410,8 +416,9 @@ Base.@propagate_inbounds function Base.getindex(A::AbstractVectorOfArray, _arg,
elsymtype = symbolic_type(eltype(_arg))

if symtype == NotSymbolic() && elsymtype == NotSymbolic()
if _arg isa Union{Tuple, AbstractArray} && any(x -> symbolic_type(x) != NotSymbolic(), _arg)
_getindex(A, symtype, elsymtype, _arg, args...)
if _arg isa Union{Tuple, AbstractArray} &&
any(x -> symbolic_type(x) != NotSymbolic(), _arg)
_getindex(A, symtype, elsymtype, _arg, args...)

Check warning on line 421 in src/vector_of_array.jl

View check run for this annotation

Codecov / codecov/patch

src/vector_of_array.jl#L421

Added line #L421 was not covered by tests
else
_getindex(A, symtype, _arg, args...)
end
Expand Down Expand Up @@ -727,7 +734,6 @@ function Base.similar(vec::VectorOfArray{
return Base.similar(vec, eltype(vec))
end


# fill!
# For DiffEqArray it ignores ts and fills only u
function Base.fill!(VA::AbstractVectorOfArray, x)
Expand Down
4 changes: 2 additions & 2 deletions test/basic_indexing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,13 @@ function foo!(u)
end
foo!(u_matrix)
foo!(u_vector)
@test all(u_matrix .== [3, 10])
@test all(u_matrix .== [3, 10])
@test all(vec(u_matrix) .≈ vec(u_vector))

# test that, for VectorOfArray with multi-dimensional parent arrays,
# broadcast and `similar` preserve the structure of the parent array
@test typeof(parent(similar(u_matrix))) == typeof(parent(u_matrix))
@test typeof(parent((x->x).(u_matrix))) == typeof(parent(u_matrix))
@test typeof(parent((x -> x).(u_matrix))) == typeof(parent(u_matrix))

# test efficiency
num_allocs = @allocations foo!(u_matrix)
Expand Down

0 comments on commit f4675f2

Please sign in to comment.