Skip to content

Commit

Permalink
Make more versatile get_variables
Browse files Browse the repository at this point in the history
  • Loading branch information
Luis Benet committed May 17, 2018
1 parent 3035cde commit 63b0140
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
11 changes: 7 additions & 4 deletions src/parameters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,18 @@ function set_variable_names(varnames::Vector{T}) where {T<:AbstractString}
nothing
end
"""
get_variables(;order=get_order())
get_variables(T::Type, [order::Int=get_order()])
Return a `TaylorN` vector with each entry representing an
Return a `TaylorN{T}` vector with each entry representing an
independent variable. It takes the default `_params_TaylorN_` values
if `set_variables` hasn't been changed with the exception that `order`
can be explicitely established by the user without changing internal values
for `num_vars` or `variable_names`.
for `num_vars` or `variable_names`. Ommiting `T` defaults to `Float64`.
"""
get_variables(;order::Integer=get_order()) = [TaylorN(i,order=order) for i in 1:get_numvars()]
get_variables(T::Type, order::Int=get_order()) =
[TaylorN(T, i, order=order) for i in 1:get_numvars()]
get_variables(order::Int=get_order()) =
[TaylorN(Float64, i, order=order) for i in 1:get_numvars()]

"""
set_variables([T::Type], names::String; [order=get_order(), numvars=-1])
Expand Down
6 changes: 4 additions & 2 deletions test/manyvariables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ end
@test get_numvars() == 2

@test get_variables()[1].order == get_order()
@test get_variables(order=2)[1].order == 2
@test get_variables(order=3)[1] == TaylorN(1,order=3)
@test get_variables(2)[1].order == 2
@test get_variables(3)[1] == TaylorN(1, order=3)
@test get_variables(Int, 3)[1] == TaylorN(Int, 1, order=3)
@test length(get_variables()) == get_numvars()

x, y = set_variables("x y", order=6)
@test x.order == 6
Expand Down

0 comments on commit 63b0140

Please sign in to comment.