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

WIP: Nested Taylors #126

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
d2438b9
Created nested_taylor.jl
blas-ko Sep 23, 2017
5d2793b
Added functions to create independent variables via nested taylors.
blas-ko Sep 23, 2017
9ada5a9
Exported nested_taylor file and functions.
blas-ko Sep 23, 2017
3b68fb3
Add function-like behavior for Taylor1, TaylorN, HomogeneousPolynomia…
PerezHz Sep 29, 2017
2111846
norm methods for AbstractSeries (#128)
blas-ko Oct 6, 2017
909689b
taylor_expand function for Taylor1 and TaylorN (#121)
blas-ko Oct 8, 2017
d2eedd7
Use new syntax of Julia 0.6 (#115)
lbenet Oct 9, 2017
cde8874
Mutating functions (#129)
lbenet Oct 27, 2017
88c73c4
Declared new method for get_variables. (#131)
blas-ko Nov 7, 2017
dc6f100
Change indexing to start from zero (#135)
lbenet Nov 14, 2017
8a8d3fb
Integration of TaylorN series (#136)
lbenet Nov 22, 2017
8c385c7
RFC: Return n-th derivative of a Taylor1 as a Taylor1 (#137)
PerezHz Nov 24, 2017
5d9794f
Add displayBigO to set/unset printing the bigO notation (#139)
lbenet Nov 27, 2017
c00bae7
Use `a[i0:i1]` or `a[:]` to iterate over Taylor1/TaylorNs (#141)
lbenet Dec 5, 2017
008b67d
RFC: Add `rad2deg`, `deg2rad` for Taylor1 and TaylorN (#142)
PerezHz Dec 5, 2017
10ab42c
Avoid irrelevant checks in getindex and setindex! (#143)
lbenet Dec 5, 2017
34f7a48
Matrix evaluation for Taylor1 and TaylorN polynomials (#144)
blas-ko Jan 12, 2018
4a1eed0
Correct the returned series when factorizing, with tests (#145)
lbenet Feb 19, 2018
c6b45d2
Fix integrate for several variables and add simple tests (#149)
dpsanders Feb 21, 2018
54ad15d
Add symbols for variables to params (#150)
dpsanders Feb 22, 2018
ffc2436
Revert "Add symbols for variables to params (#150)" (#153)
dpsanders Feb 22, 2018
1c32f7c
Variable symbols (#154)
dpsanders Feb 22, 2018
5007129
Diferentiate, integrate and evaluate with symbols (#155)
lbenet Feb 23, 2018
21d786c
Deprecations related to Julia0.7 (#157)
lbenet Feb 27, 2018
c5f366c
Evaluate with tuples (#159)
lbenet Mar 1, 2018
cb16e09
Solve deprecations that break tests in Julia 0.7 (#160)
lbenet Mar 12, 2018
8efe0f1
Fixes related to deprecations in Julia 0.7 (#161)
lbenet Mar 18, 2018
23c0657
Type-stable mutating functions (#162)
lbenet Apr 4, 2018
81b4649
Partial derivatives of TaylorN (#164)
lbenet Apr 17, 2018
3035cde
Separate methods for ^ to use power_by_squaring or pow! (#165)
lbenet Apr 20, 2018
3aa1073
Created nested_taylor.jl
blas-ko Sep 23, 2017
b1e12bd
Added functions to create independent variables via nested taylors.
blas-ko Sep 23, 2017
b2b85ed
Exported nested_taylor file and functions.
blas-ko Sep 23, 2017
43cb5f0
Merge branch 'nested_taylor' of https://github.com/blas-ko/TaylorSeri…
blas-ko May 14, 2018
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
4 changes: 3 additions & 1 deletion src/TaylorSeries.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ export get_coeff, derivative, integrate,
show_params_TaylorN,
get_order, get_numvars,
set_variables, get_variables,
∇, jacobian, jacobian!, hessian, hessian!
∇, jacobian, jacobian!, hessian, hessian!,
get_nested_numvars, set_nested_variables

include("parameters.jl")
include("hash_tables.jl")
Expand All @@ -59,5 +60,6 @@ include("other_functions.jl")
include("evaluate.jl")
include("calculus.jl")
include("printing.jl")
include("nested_taylor.jl")

end # module
56 changes: 56 additions & 0 deletions src/nested_taylor.jl
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})
Copy link
Member

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 again get_nested_numvars), which may require to define another method, where a is not an AbstractSeries.

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again here, a is changing type, which may affect the performance.

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to have this as set_nested_variables(T::Type, numvars::Integer, order::Integer) which follows the convention we have, for example, to define Taylor1, and then define a specific method without it, which corresponds to the default Float64.

Though it is not urgent at the moment, I think it would be neat to have the possibility of different orders for the different variables, which in this case could be done by passing a Tuple of Int's of the correct length (numvars).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above, I think there may be type-stability issues here.

Copy link
Member

Choose a reason for hiding this comment

The 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 Taylor(T, order). In the loop in the function, T would be updated (but it would always be a DataType!) to get the nesting of the types.

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