Skip to content

Commit

Permalink
refactor: format
Browse files Browse the repository at this point in the history
  • Loading branch information
AayushSabharwal committed Dec 11, 2023
1 parent 1e5450b commit b243589
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/parameter_indexing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function _getp(sys, ::ScalarSymbolic, p)
end
end

function _getp(sys, ::ScalarSymbolic, p::Union{Tuple,AbstractArray})
function _getp(sys, ::ScalarSymbolic, p::Union{Tuple, AbstractArray})
idxs = parameter_index.((sys,), p)
return function getter(sol)
return getindex.((parameter_values(sol),), idxs)

Check warning on line 41 in src/parameter_indexing.jl

View check run for this annotation

Codecov / codecov/patch

src/parameter_indexing.jl#L38-L41

Added lines #L38 - L41 were not covered by tests
Expand Down Expand Up @@ -77,7 +77,7 @@ function _setp(sys, ::ScalarSymbolic, p)
end
end

function _setp(sys, ::ScalarSymbolic, p::Union{Tuple,AbstractArray})
function _setp(sys, ::ScalarSymbolic, p::Union{Tuple, AbstractArray})
idxs = parameter_index.((sys,), p)
return function setter!(sol, val)
setindex!.((parameter_values(sol),), val, idxs)

Check warning on line 83 in src/parameter_indexing.jl

View check run for this annotation

Codecov / codecov/patch

src/parameter_indexing.jl#L80-L83

Added lines #L80 - L83 were not covered by tests
Expand Down
29 changes: 22 additions & 7 deletions src/symbol_cache.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,35 @@ at least one independent variable.
The independent variable may be specified as a single symbolic variable instead of an
array containing a single variable if the system has only one independent variable.
"""
struct SymbolCache{V<:Union{Nothing,AbstractVector}, P<:Union{Nothing,AbstractVector}, I}
struct SymbolCache{
V <: Union{Nothing, AbstractVector},
P <: Union{Nothing, AbstractVector},
I,
}
variables::V
parameters::P
independent_variables::I
end

function SymbolCache(vars = nothing, params = nothing, indepvars = nothing)
return SymbolCache{typeof(vars),typeof(params),typeof(indepvars)}(vars, params, indepvars)
return SymbolCache{typeof(vars), typeof(params), typeof(indepvars)}(vars,

Check warning on line 25 in src/symbol_cache.jl

View check run for this annotation

Codecov / codecov/patch

src/symbol_cache.jl#L24-L25

Added lines #L24 - L25 were not covered by tests
params,
indepvars)
end

is_variable(sc::SymbolCache, sym) = sc.variables !== nothing && any(isequal(sym), sc.variables)
variable_index(sc::SymbolCache, sym) = sc.variables === nothing ? nothing : findfirst(isequal(sym), sc.variables)
function is_variable(sc::SymbolCache, sym)
sc.variables !== nothing && any(isequal(sym), sc.variables)

Check warning on line 31 in src/symbol_cache.jl

View check run for this annotation

Codecov / codecov/patch

src/symbol_cache.jl#L30-L31

Added lines #L30 - L31 were not covered by tests
end
function variable_index(sc::SymbolCache, sym)
sc.variables === nothing ? nothing : findfirst(isequal(sym), sc.variables)

Check warning on line 34 in src/symbol_cache.jl

View check run for this annotation

Codecov / codecov/patch

src/symbol_cache.jl#L33-L34

Added lines #L33 - L34 were not covered by tests
end
variable_symbols(sc::SymbolCache, i = nothing) = something(sc.variables, [])
is_parameter(sc::SymbolCache, sym) = sc.parameters !== nothing && any(isequal(sym), sc.parameters)
parameter_index(sc::SymbolCache, sym) = sc.parameters === nothing ? nothing : findfirst(isequal(sym), sc.parameters)
function is_parameter(sc::SymbolCache, sym)
sc.parameters !== nothing && any(isequal(sym), sc.parameters)

Check warning on line 38 in src/symbol_cache.jl

View check run for this annotation

Codecov / codecov/patch

src/symbol_cache.jl#L36-L38

Added lines #L36 - L38 were not covered by tests
end
function parameter_index(sc::SymbolCache, sym)
sc.parameters === nothing ? nothing : findfirst(isequal(sym), sc.parameters)

Check warning on line 41 in src/symbol_cache.jl

View check run for this annotation

Codecov / codecov/patch

src/symbol_cache.jl#L40-L41

Added lines #L40 - L41 were not covered by tests
end
parameter_symbols(sc::SymbolCache) = something(sc.parameters, [])
function is_independent_variable(sc::SymbolCache, sym)
sc.independent_variables === nothing && return false
Expand Down Expand Up @@ -61,5 +75,6 @@ constant_structure(::SymbolCache) = true
function Base.copy(sc::SymbolCache)
return SymbolCache(sc.variables === nothing ? nothing : copy(sc.variables),

Check warning on line 76 in src/symbol_cache.jl

View check run for this annotation

Codecov / codecov/patch

src/symbol_cache.jl#L75-L76

Added lines #L75 - L76 were not covered by tests
sc.parameters === nothing ? nothing : copy(sc.parameters),
sc.independent_variables isa AbstractArray ? copy(sc.independent_variables) : sc.independent_variables)
sc.independent_variables isa AbstractArray ? copy(sc.independent_variables) :
sc.independent_variables)
end
2 changes: 1 addition & 1 deletion src/trait.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@ hasname(::Any) = false
Get the name of a symbolic variable as a `Symbol`
"""
function getname end
function getname end
3 changes: 2 additions & 1 deletion test/fallback_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ all_syms = [:x, :y, :z, :a, :b, :t]
@test variable_index.((sys,), all_syms) == variable_index.((sc,), all_syms)
@test is_parameter.((sys,), all_syms) == is_parameter.((sc,), all_syms)
@test parameter_index.((sys,), all_syms) == parameter_index.((sc,), all_syms)
@test is_independent_variable.((sys,), all_syms) == is_independent_variable.((sc,), all_syms)
@test is_independent_variable.((sys,), all_syms) ==
is_independent_variable.((sc,), all_syms)
@test is_observed.((sys,), all_syms) == is_observed.((sc,), all_syms)
@test is_time_dependent(sys) == is_time_dependent(sc)
@test constant_structure(sys) == constant_structure(sc)
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ end
end
@testset "Parameter indexing test" begin
@time include("parameter_indexing_test.jl")
end
end

0 comments on commit b243589

Please sign in to comment.