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

Make more versatile get_variables #166

Merged
merged 1 commit into from
May 17, 2018
Merged
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
Make more versatile get_variables
  • Loading branch information
Luis Benet committed May 17, 2018
commit 63b0140c491ea9eaa6a6530733d530e46e36f32d
11 changes: 7 additions & 4 deletions src/parameters.jl
Original file line number Diff line number Diff line change
@@ -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])
6 changes: 4 additions & 2 deletions test/manyvariables.jl
Original file line number Diff line number Diff line change
@@ -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