Skip to content

Commit

Permalink
Remove unneccsary promote functions
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsignorelli committed Feb 12, 2024
1 parent d44d01a commit 5a14648
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 62 deletions.
2 changes: 1 addition & 1 deletion src/methods.jl
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ TPS:
```
"""
function pb(f::Union{TPS, ComplexTPS}, g::Union{TPS, ComplexTPS})
t = zero_promote(f,g)
t = promote_type(typeof(f),typeof(g))(use=f)
desc = unsafe_load(Base.unsafe_convert(Ptr{Desc}, unsafe_load(f.tpsa).d))
poisbra!(f.tpsa,g.tpsa,t.tpsa, desc.nv)
return t
Expand Down
61 changes: 0 additions & 61 deletions src/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,67 +7,6 @@ function zero(ct::ComplexTPS)::ComplexTPS
return ComplexTPS(mad_ctpsa_new(ct.tpsa, MAD_TPSA_SAME))
end

# --- special zero with promotion ---
#= Using standard "promote" + zero is expensive for methods with
defined internal real to complex conversion (e.g. mad_tpsa_poisbrat)
so zero_promote will give back a zero TPS/ComplexTPS with the highest type
of the two passed. Currently this is only used in methods.jl
to simplify the code (one written function for all types). It technically could have
been used throughout operators.jl too, but was not.
=#
function zero_promote(t1::TPS, t2::TPS)::TPS
return TPS(mad_tpsa_new(t1.tpsa, MAD_TPSA_SAME))
end

function zero_promote(t1::TPS, ct1::ComplexTPS)::ComplexTPS
return ComplexTPS(mad_ctpsa_new(ct1.tpsa, MAD_TPSA_SAME))
end

function zero_promote(ct1::ComplexTPS, t1::TPS)::ComplexTPS
return ComplexTPS(mad_ctpsa_new(ct1.tpsa, MAD_TPSA_SAME))
end

function zero_promote(ct1::ComplexTPS, ct2::ComplexTPS)::ComplexTPS
return ComplexTPS(mad_ctpsa_new(ct1.tpsa, MAD_TPSA_SAME))
end

# Vectorized zero_promote, output length is same as m1
function zero_promote(m1::Vector{TPS}, m2::Vector{TPS})::Tuple{Vector{TPS}, Cint}
na = Cint(length(m1))
m = Vector{TPS}(undef, na)
for i in eachindex(m)
m[i] = zero(m1[1])
end
return m, na
end

function zero_promote(m1::Vector{TPS}, m2::Vector{ComplexTPS})::Tuple{Vector{ComplexTPS}, Cint}
na = Cint(length(m1))
m = Vector{ComplexTPS}(undef, na)
for i in eachindex(m)
m[i] = zero(m2[1])
end
return m, na
end

function zero_promote(m1::Vector{ComplexTPS}, m2::Vector{TPS})::Tuple{Vector{ComplexTPS}, Cint}
na = Cint(length(m1))
m = Vector{ComplexTPS}(undef, na)
for i in eachindex(m)
m[i] = zero(m1[1])
end
return m, na
end

function zero_promote(m1::Vector{ComplexTPS}, m2::Vector{ComplexTPS})::Tuple{Vector{ComplexTPS}, Cint}
na = Cint(length(m1))
m = Vector{ComplexTPS}(undef, na)
for i in eachindex(m)
m[i] = zero(m1[1])
end
return m, na
end

# --- Unary ---
# TPS:
function +(t1::TPS)::TPS
Expand Down

0 comments on commit 5a14648

Please sign in to comment.