Skip to content

Commit 2cd65d8

Browse files
committed
More minor fixes reducing use of memory
1 parent 487b510 commit 2cd65d8

File tree

3 files changed

+44
-29
lines changed

3 files changed

+44
-29
lines changed

src/arithmetic.jl

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ For many variables, the ordering includes a lexicographical convention in order
163163
total. We have opted for the simplest one: the *larger* variable appears *before*
164164
for the `TaylorN` variables are defined (e.g., through [`set_variables`](@ref)).
165165
166-
For nested `Taylor1`, i.e. `Taylor1{Taylor1{...}}`s, the variables are compared
167-
wrt to the output of `get_numvars`
166+
For nested `Taylor1{Taylor1{...}}`s, the ordering is established by which one
167+
is a `constant_term` of the other.
168168
169169
Refs:
170170
- M. Berz, AIP Conference Proceedings 177, 275 (1988); https://doi.org/10.1063/1.37800
@@ -749,7 +749,7 @@ end
749749
function mul_scalar!(c::Taylor1{Taylor1{T}}, scalar::NumberNotSeries,
750750
a::Taylor1{Taylor1{T}}, b::Taylor1{Taylor1{T}}, k::Int) where {T<:Number}
751751
mul!(c, a, b, k)
752-
# c[k] = scalar * c[k]
752+
# c[k] <- scalar * c[k]
753753
for ord in eachindex(c[k])
754754
mul!(c[k], c[k], scalar, ord)
755755
end
@@ -781,7 +781,7 @@ function mul!(a::TaylorN{T}, b::TaylorN{T}) where {T<:Number}
781781
end
782782
return nothing
783783
end
784-
function mul!(a::Taylor1{T}, b::Taylor1{T}) where {T<:NumberNotSeriesN}
784+
function mul!(a::Taylor1{T}, b::Taylor1{T}) where {T<:NumberNotSeries}
785785
@inbounds for k in reverse(eachindex(a))
786786
# a[k] <- a[k]*b[0]
787787
mul!(a, a, b[0], k)
@@ -1218,9 +1218,9 @@ function div!(c::Taylor1{Taylor1{T}}, a::Taylor1{Taylor1{T}},
12181218
zero!(c, k)
12191219
iszero(a) && !iszero(b) && return nothing
12201220
# order and coefficient of first factorized term
1221-
ordfact, cdivfact = divfactorization(a, b)
1221+
ordfact, aux = divfactorization(a, b)
12221222
if k == 0
1223-
identity!(c, cdivfact, k)
1223+
identity!(c, aux, k)
12241224
return nothing
12251225
end
12261226
imin = max(0, k+ordfact-b.order)
@@ -1232,20 +1232,22 @@ function div!(c::Taylor1{Taylor1{T}}, a::Taylor1{Taylor1{T}},
12321232
muladd!(c[k], c[i], b[k+ordfact-i], ord)
12331233
end
12341234
end
1235-
aux = zero(c[k])
1235+
zero!(aux)
12361236
if k+ordfact b.order
1237-
# @inbounds aux = a[k+ordfact] - c[k]
1237+
# @inbounds aux <- a[k+ordfact] - c[k]
12381238
for ord in eachindex(minlength(aux, a[k+ordfact]))
12391239
subst!(aux, a[k+ordfact], c[k], ord)
12401240
end
12411241
else
1242-
# @inbounds aux = - c[k]
1242+
# @inbounds aux <- - c[k]
12431243
for ord in eachindex(minlength(aux, a[k+ordfact]))
12441244
subst!(aux, c[k], ord)
12451245
end
12461246
end
1247-
# TODO: optimize next line
1248-
c[k] = aux / b[ordfact]
1247+
# c[k] <- aux / b[ordfact]
1248+
for ord in eachindex(c[k])
1249+
div!(c[k], aux, b[ordfact], ord)
1250+
end
12491251
return nothing
12501252
end
12511253

src/functions.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,13 @@ end
380380
zero!(aux, j)
381381
end
382382
end
383-
div!(c, c, k, k)
383+
# div!(c, c, k, k)
384+
for i in eachindex(c[k])
385+
identity!(aux, c[k], i)
386+
end
387+
for i in eachindex(c[k])
388+
div!(c[k], aux, k, i)
389+
end
384390
return nothing
385391
end
386392

src/power.jl

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -360,14 +360,14 @@ end
360360
end
361361
end
362362
# @inbounds c[k] = c[k] / (kprime * a[l0])
363-
aux2 = zero(c[k])
364-
for j in eachindex(a[l0])
365-
zero!(aux[k], j)
366-
mul!(aux[k], kprime, a[l0], j)
367-
identity!(aux2, c[k], j)
363+
@inbounds for j in eachindex(c[k])
364+
identity!(aux[k], c[k], j)
368365
end
369-
for j in eachindex(a[l0])
370-
div!(c[k], aux2, aux[k], j)
366+
@inbounds for j in eachindex(a[l0])
367+
div!(c[k], aux[k], a[l0], j)
368+
end
369+
@inbounds for j in eachindex(a[l0])
370+
div!(c[k], c[k], kprime, j)
371371
end
372372
return nothing
373373
end
@@ -432,8 +432,8 @@ end
432432
end
433433
return nothing
434434
end
435-
@inline function sqr_orderzero!(c::Taylor1{T}, a::Taylor1{T}) where
436-
{T<:AbstractSeries}
435+
@inline function sqr_orderzero!(c::Taylor1{Taylor1{T}}, a::Taylor1{Taylor1{T}}) where
436+
{T<:Number}
437437
@inbounds for ord in eachindex(c[0])
438438
sqr!(c[0], a[0], ord)
439439
end
@@ -553,8 +553,8 @@ end
553553
return nothing
554554
end
555555

556-
@inline function sqr!(c::Taylor1{Taylor1{T}}, a::Taylor1{Taylor1{T}}, k::Int) where
557-
{T<:NumberNotSeriesN}
556+
@inline function sqr!(c::Taylor1{Taylor1{T}}, a::Taylor1{Taylor1{T}},
557+
k::Int) where {T<:NumberNotSeriesN}
558558
if k == 0
559559
sqr_orderzero!(c, a)
560560
return nothing
@@ -702,7 +702,8 @@ coefficient, which must be even.
702702
703703
""" sqrt!
704704

705-
@inline function sqrt!(c::Taylor1{T}, a::Taylor1{T}, k::Int, k0::Int=0) where {T<:Number}
705+
@inline function sqrt!(c::Taylor1{T}, a::Taylor1{T}, k::Int, k0::Int=0) where
706+
{T<:NumberNotSeries}
706707
k < k0 && return nothing
707708
if k == k0
708709
@inbounds c[k] = sqrt(a[2*k0])
@@ -728,7 +729,8 @@ coefficient, which must be even.
728729
return nothing
729730
end
730731

731-
@inline function sqrt!(c::TaylorN{T}, a::TaylorN{T}, k::Int) where {T<:NumberNotSeriesN}
732+
@inline function sqrt!(c::TaylorN{T}, a::TaylorN{T}, k::Int) where
733+
{T<:NumberNotSeriesN}
732734

733735
if k == 0
734736
@inbounds c[0][1] = sqrt( constant_term(a) )
@@ -800,7 +802,8 @@ end
800802
return nothing
801803
end
802804

803-
@inline function sqrt!(c::Taylor1{Taylor1{T}}, a::Taylor1{Taylor1{T}}, k::Int, k0::Int=0) where {T<:Number}
805+
@inline function sqrt!(c::Taylor1{Taylor1{T}}, a::Taylor1{Taylor1{T}}, k::Int,
806+
k0::Int=0) where {T<:Number}
804807
k < k0 && return nothing
805808
if k == k0
806809
@inbounds c[k] = sqrt(a[2*k0])
@@ -834,10 +837,14 @@ end
834837
end
835838
end
836839
# @inbounds c[k] = c[k] / (2*c[k0])
840+
@inbounds for j in eachindex(c[k])
841+
identity!(aux, c[k], j)
842+
end
837843
@inbounds for j in eachindex(c[k0])
838-
zero!(aux, j)
839-
mul!(aux, 2, c[k0], j)
844+
div!(c[k], aux, c[k0], j)
845+
end
846+
@inbounds for j in eachindex(c[k0])
847+
div!(c[k], c[k], 2, j)
840848
end
841-
c[k] = c[k] / aux
842849
return nothing
843850
end

0 commit comments

Comments
 (0)