Skip to content

Commit

Permalink
Performance improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
RJDennis committed May 4, 2021
1 parent 107de85 commit d8f9ce0
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 76 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ChebyshevApprox"
uuid = "17a596ad-87cd-578c-9b6d-01108c31dc04"
authors = ["Richard Dennis <richard.dennis@glasgow.ac.uk>"]
version = "0.1.6"
version = "0.1.7"


[deps]
Expand Down
4 changes: 2 additions & 2 deletions src/chebyshev_derivative.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function chebyshev_derivative(weights::Array{T,N},x::Array{T,1},pos::S,order::Ar
end
end

derivative = 0.0
derivative = zero(T)
@inbounds for i in CartesianIndices(weights)
poly_product = poly[1][i[1]]
@inbounds for j = 2:N
Expand All @@ -37,7 +37,7 @@ function chebyshev_derivative(weights::Array{T,N},x::Array{T,1},pos::S,order::S,
end
end

derivative = 0.0
derivative = zero(T)
@inbounds for i in CartesianIndices(weights)
if sum(Tuple(i)) <= order+N
poly_product = poly[1][i[1]]
Expand Down
4 changes: 2 additions & 2 deletions src/chebyshev_evaluate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function chebyshev_evaluate(weights::Array{T,N},x::Array{T,1},order::Array{S,1},
poly[i] = chebyshev_polynomial(order[i],normalize_node(x[i],domain[:,i]))
end

yhat = 0.0
yhat = zero(T)
@inbounds for i in CartesianIndices(weights)
poly_product = poly[1][i[1]]
@inbounds for j = 2:N
Expand All @@ -27,7 +27,7 @@ function chebyshev_evaluate(weights::Array{T,N},x::Array{T,1},order::S,domain=[o
poly[i] = chebyshev_polynomial(order,normalize_node(x[i],domain[:,i]))
end

yhat = 0.0
yhat = zero(T)
@inbounds for i in CartesianIndices(weights)
if sum(Tuple(i)) <= order+N
poly_product = poly[1][i[1]]
Expand Down
134 changes: 63 additions & 71 deletions src/chebyshev_weights.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@ function chebyshev_weights(f::AbstractArray{T,N},nodes::NTuple{N,Array{T,1}},ord

@inbounds for s in CartesianIndices(f)

num = f[s]
den = one(T)
product = one(T)
@inbounds for j = 1:N
num *= poly[j][s[j],i[j]]
den *= poly[j][s[j],i[j]]
product *= poly[j][s[j],i[j]]
end

numerator += num
denominator += den^2
numerator += f[s]*product
denominator += product^2

end

Expand Down Expand Up @@ -57,9 +55,10 @@ function chebyshev_weights_extrema(f::AbstractArray{T,N},nodes::NTuple{N,Array{T
num = f[s]
den = one(T)
@inbounds for j = 1:N
scale = 1.0
if s[j] == 1 || s[j] == n[j]
scale *= 0.5
if s[j] === 1 || s[j] === n[j]
scale = 0.5
else
scale = 1.0
end
temp = poly[j][s[j],i[j]]
num *= temp*scale
Expand Down Expand Up @@ -90,15 +89,13 @@ function chebyshev_weights(f::AbstractArray{T,N},poly::NTuple{N,Array{T,2}},orde

@inbounds for s in CartesianIndices(f)

num = f[s]
den = one(T)
product = one(T)
@inbounds for j = 1:N
num *= poly[j][s[j],i[j]]
den *= poly[j][s[j],i[j]]
product *= poly[j][s[j],i[j]]
end

numerator += num
denominator += den^2
numerator += f[s]*product
denominator += product^2

end

Expand Down Expand Up @@ -126,9 +123,10 @@ function chebyshev_weights_extrema(f::AbstractArray{T,N},poly::NTuple{N,Array{T,
num = f[s]
den = one(T)
@inbounds for j = 1:N
scale = 1.0
if s[j] == 1 || s[j] == n[j]
scale *= 0.5
scale = 0.5
else
scale = 1.0
end
temp = poly[j][s[j],i[j]]
num *= temp*scale
Expand Down Expand Up @@ -171,16 +169,14 @@ function chebyshev_weights(f::AbstractArray{T,N},nodes::NTuple{N,Array{T,1}},ord

@inbounds for s in CartesianIndices(f)

num = f[s]
den = one(T)
product = one(T)
@inbounds for j = 1:N
num *= poly[j][s[j],i[j]]
den *= poly[j][s[j],i[j]]
product *= poly[j][s[j],i[j]]
end

numerator += num
denominator += den^2

numerator += f[s]*product
denominator += product^2
end

weights[i] = numerator/denominator
Expand Down Expand Up @@ -223,9 +219,10 @@ function chebyshev_weights_extrema(f::AbstractArray{T,N},nodes::NTuple{N,Array{T
num = f[s]
den = one(T)
@inbounds for j = 1:N
scale = 1.0
if s[j] == 1 || s[j] == n[j]
scale *= 0.5
scale = 0.5
else
scale = 1.0
end
temp = poly[j][s[j],i[j]]
num *= temp*scale
Expand Down Expand Up @@ -258,24 +255,22 @@ function chebyshev_weights(f::AbstractArray{T,N},poly::NTuple{N,Array{T,2}},orde

weights = Array{T,N}(undef,ord.+1)

@inbounds @sync @qthreads for i in CartesianIndices(weights)
@inbounds for i in CartesianIndices(weights)
if sum(Tuple(i)) <= order+N

numerator = zero(T)
denominator = zero(T)

@inbounds for s in CartesianIndices(f)

num = f[s]
den = one(T)
product = one(T)
@inbounds for j = 1:N
num *= poly[j][s[j],i[j]]
den *= poly[j][s[j],i[j]]
product *= poly[j][s[j],i[j]]
end

numerator += num
denominator += den^2

numerator += f[s]*product
denominator += product^2
end

weights[i] = numerator/denominator
Expand Down Expand Up @@ -312,9 +307,10 @@ function chebyshev_weights_extrema(f::AbstractArray{T,N},poly::NTuple{N,Array{T,
num = f[s]
den = one(T)
@inbounds for j = 1:N
scale = 1.0
if s[j] == 1 || s[j] == n[j]
scale *= 0.5
scale = 0.5
else
scale = 1.0
end
temp = poly[j][s[j],i[j]]
num *= temp*scale
Expand Down Expand Up @@ -355,15 +351,13 @@ function chebyshev_weights_threaded(f::AbstractArray{T,N},nodes::NTuple{N,Array{

@inbounds for s in CartesianIndices(f)

num = f[s]
den = one(T)
product = one(T)
@inbounds for j = 1:N
num *= poly[j][s[j],i[j]]
den *= poly[j][s[j],i[j]]
product *= poly[j][s[j],i[j]]
end

numerator += num
denominator += den^2
numerator += f[s]*product
denominator += product^2

end

Expand Down Expand Up @@ -397,9 +391,10 @@ function chebyshev_weights_extrema_threaded(f::AbstractArray{T,N},nodes::NTuple{
num = f[s]
den = one(T)
@inbounds for j = 1:N
scale = 1.0
if s[j] == 1 || s[j] == n[j]
scale *= 0.5
scale = 0.5
else
scale = 1.0
end
temp = poly[j][s[j],i[j]]
num *= temp*scale
Expand Down Expand Up @@ -430,15 +425,13 @@ function chebyshev_weights_threaded(f::AbstractArray{T,N},poly::NTuple{N,Array{T

@inbounds for s in CartesianIndices(f)

num = f[s]
den = one(T)
product = one(T)
@inbounds for j = 1:N
num *= poly[j][s[j],i[j]]
den *= poly[j][s[j],i[j]]
product *= poly[j][s[j],i[j]]
end

numerator += num
denominator += den^2
numerator += f[s]*product
denominator += product^2

end

Expand Down Expand Up @@ -466,9 +459,10 @@ function chebyshev_weights_extrema_threaded(f::AbstractArray{T,N},poly::NTuple{N
num = f[s]
den = one(T)
@inbounds for j = 1:N
scale = 1.0
if s[j] == 1 || s[j] == n[j]
scale *= 0.5
scale = 0.5
else
scale = 1.0
end
temp = poly[j][s[j],i[j]]
num *= temp*scale
Expand Down Expand Up @@ -511,16 +505,14 @@ function chebyshev_weights_threaded(f::AbstractArray{T,N},nodes::NTuple{N,Array{

@inbounds for s in CartesianIndices(f)

num = f[s]
den = one(T)
product = one(T)
@inbounds for j = 1:N
num *= poly[j][s[j],i[j]]
den *= poly[j][s[j],i[j]]
product *= poly[j][s[j],i[j]]
end

numerator += num
denominator += den^2

numerator += f[s]*product
denominator += product^2
end

weights[i] = numerator/denominator
Expand Down Expand Up @@ -563,9 +555,10 @@ function chebyshev_weights_extrema_threaded(f::AbstractArray{T,N},nodes::NTuple{
num = f[s]
den = one(T)
@inbounds for j = 1:N
scale = 1.0
if s[j] == 1 || s[j] == n[j]
scale *= 0.5
scale = 0.5
else
scale = 1.0
end
temp = poly[j][s[j],i[j]]
num *= temp*scale
Expand Down Expand Up @@ -606,16 +599,14 @@ function chebyshev_weights_threaded(f::AbstractArray{T,N},poly::NTuple{N,Array{T

@inbounds for s in CartesianIndices(f)

num = f[s]
den = one(T)
product = one(T)
@inbounds for j = 1:N
num *= poly[j][s[j],i[j]]
den *= poly[j][s[j],i[j]]
product *= poly[j][s[j],i[j]]
end

numerator += num
denominator += den^2

numerator += f[s]*product
denominator += product^2
end

weights[i] = numerator/denominator
Expand Down Expand Up @@ -652,9 +643,10 @@ function chebyshev_weights_extrema_threaded(f::AbstractArray{T,N},poly::NTuple{N
num = f[s]
den = one(T)
@inbounds for j = 1:N
scale = 1.0
if s[j] == 1 || s[j] == n[j]
scale *= 0.5
scale = 0.5
else
scale = 1.0
end
temp = poly[j][s[j],i[j]]
num *= temp*scale
Expand Down

0 comments on commit d8f9ce0

Please sign in to comment.