-
Notifications
You must be signed in to change notification settings - Fork 53
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
WIP: Nested Taylors #126
base: master
Are you sure you want to change the base?
WIP: Nested Taylors #126
Changes from 3 commits
d2438b9
5d2793b
9ada5a9
3b68fb3
2111846
909689b
d2eedd7
cde8874
88c73c4
dc6f100
8a8d3fb
8c385c7
5d9794f
c00bae7
008b67d
10ab42c
34f7a48
4a1eed0
c6b45d2
54ad15d
ffc2436
1c32f7c
5007129
21d786c
c5f366c
cb16e09
8efe0f1
23c0657
81b4649
3035cde
3aa1073
b1e12bd
b2b85ed
43cb5f0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# This file is part of the TaylorSeries.jl Julia package, MIT license | ||
# | ||
# Luis Benet & David P. Sanders | ||
# UNAM | ||
# | ||
# MIT Expat license | ||
# | ||
|
||
|
||
#number of variables in a nested polynomial | ||
function get_nested_numvars{T<:Number}(a::Taylor1{T}) | ||
a_aux = a.coeffs[1] | ||
dim_a = 1 | ||
while !(typeof(a_aux) <: TaylorSeries.NumberNotSeries) | ||
dim_a += 1 | ||
a_aux = a_aux.coeffs[1] | ||
end | ||
return dim_a | ||
end | ||
|
||
|
||
function nest{T<:Number}(a::Taylor1{T},num_vars::Integer,dim_a::Integer) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again here, |
||
ord = a.order | ||
|
||
for nest in 1:(num_vars-dim_a) | ||
a = Taylor1([a],ord) | ||
end | ||
|
||
return a | ||
end | ||
|
||
function nest{T<:Number}(a::Taylor1{T},num_vars::Int64) | ||
dim_a = get_nested_numvars(a) | ||
ord = a.order | ||
|
||
for nest in 1:(num_vars-dim_a) | ||
a = Taylor1([a],ord) | ||
end | ||
|
||
return a | ||
end | ||
|
||
#Shortcut to define an array of independent variables of nested taylors | ||
function set_nested_variables(numvars::Integer,order::Integer,T::Type=Float64) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would suggest to have this as Though it is not urgent at the moment, I think it would be neat to have the possibility of different There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As above, I think there may be type-stability issues here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A possibility, to reduce temporary allocations (and maybe type instability problems too) is to exploit things like |
||
nested = Taylor1([zero(T),one(T)],order) | ||
nested_array = Vector{Number}(numvars) | ||
numvars_nested = 1 | ||
|
||
for i in 1:numvars | ||
nested_array[i] = nest(nested,numvars,numvars_nested) | ||
nested = Taylor1([zero(nested),one(nested)],order) | ||
numvars_nested += 1 | ||
end | ||
|
||
return nested_array | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There may be some type instability in this function, since
a_aux
may change of type. I suggest to do the same but recursively (so call againget_nested_numvars
), which may require to define another method, wherea
is not anAbstractSeries
.