Skip to content

Commit

Permalink
tests passing:
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsignorelli committed Apr 22, 2024
1 parent c61706c commit a6b0ba0
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 52 deletions.
36 changes: 18 additions & 18 deletions src/fast_gtpsa.jl
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ end
function ±(t1::TPS, a::Real)::Ptr{RTPSA}
tpsa = get_rtemp!(t1)
mad_tpsa_copy!(t1.tpsa, tpsa)
mad_tpsa_set0!(tpsa, 1., convert(Float64,a))
mad_tpsa_seti!(tpsa, Cint(0),1., convert(Float64,a))
return tpsa
end

Expand All @@ -258,7 +258,7 @@ function ±(tpsa1::Ptr{RTPSA},t1::TPS)::Ptr{RTPSA}
end

function ±(tpsa1::Ptr{RTPSA}, a::Real)::Ptr{RTPSA}
mad_tpsa_set0!(tpsa1, 1., convert(Float64,a))
mad_tpsa_seti!(tpsa1, Cint(0), 1., convert(Float64,a))
return tpsa1
end

Expand All @@ -276,7 +276,7 @@ end
function ±(ct1::ComplexTPS, a::Number)::Ptr{CTPSA}
ctpsa = get_ctemp!(ct1)
mad_ctpsa_copy!(ct1.tpsa, ctpsa)
mad_ctpsa_set0!(ctpsa, convert(ComplexF64,1), convert(ComplexF64,a))
mad_ctpsa_seti!(ctpsa, Cint(0), convert(ComplexF64,1), convert(ComplexF64,a))
return ctpsa
end

Expand All @@ -300,7 +300,7 @@ function ±(ctpsa1::Ptr{CTPSA}, ct1::ComplexTPS)::Ptr{CTPSA}
end

function ±(ctpsa1::Ptr{CTPSA}, a::Number)::Ptr{CTPSA}
mad_ctpsa_set0!(ctpsa1, convert(ComplexF64,1), convert(ComplexF64,a))
mad_ctpsa_seti!(ctpsa1, Cint(0), convert(ComplexF64,1), convert(ComplexF64,a))
return ctpsa1
end

Expand All @@ -323,7 +323,7 @@ end
function ±(t1::TPS, a::Complex)::Ptr{CTPSA}
ctpsa = get_ctemp!(t1)
mad_ctpsa_cplx!(t1.tpsa, Base.unsafe_convert(Ptr{RTPSA}, C_NULL), ctpsa)
mad_ctpsa_set0!(ctpsa, convert(ComplexF64, 1), convert(ComplexF64, a))
mad_ctpsa_seti!(ctpsa, Cint(0),convert(ComplexF64, 1), convert(ComplexF64, a))
return ctpsa
end

Expand All @@ -334,7 +334,7 @@ end
function ±(tpsa1::Ptr{RTPSA}, a::Complex)::Ptr{CTPSA}
ctpsa = get_ctemp_low!(tpsa1)
mad_ctpsa_cplx!(tpsa1, Base.unsafe_convert(Ptr{RTPSA}, C_NULL), ctpsa)
mad_ctpsa_set0!(ctpsa, convert(ComplexF64, 1), convert(ComplexF64, a))
mad_ctpsa_seti!(ctpsa, Cint(0),convert(ComplexF64, 1), convert(ComplexF64, a))
rel_rtemp!(tpsa1)
return ctpsa
end
Expand Down Expand Up @@ -378,14 +378,14 @@ end
function (t1::TPS, a::Real)::Ptr{RTPSA}
tpsa = get_rtemp!(t1)
mad_tpsa_copy!(t1.tpsa, tpsa)
mad_tpsa_set0!(tpsa, 1., convert(Float64, -a))
mad_tpsa_seti!(tpsa, Cint(0), 1., convert(Float64, -a))
return tpsa
end

function (a::Real, t1::TPS)::Ptr{RTPSA}
tpsa = get_rtemp!(t1)
mad_tpsa_scl!(t1.tpsa, -1., tpsa)
mad_tpsa_set0!(tpsa, 1., convert(Float64, a))
mad_tpsa_seti!(tpsa, Cint(0), 1., convert(Float64, a))
return tpsa
end

Expand All @@ -406,13 +406,13 @@ function ∓(tpsa1::Ptr{RTPSA}, t1::TPS)::Ptr{RTPSA}
end

function (tpsa1::Ptr{RTPSA}, a::Real)::Ptr{RTPSA}
mad_tpsa_set0!(tpsa1, 1., convert(Float64, -a))
mad_tpsa_seti!(tpsa1, Cint(0), 1., convert(Float64, -a))
return tpsa1
end

function (a::Real, tpsa1::Ptr{RTPSA})::Ptr{RTPSA}
mad_tpsa_scl!(tpsa1, -1., tpsa1)
mad_tpsa_set0!(tpsa1, 1., convert(Float64, a))
mad_tpsa_seti!(tpsa1, Cint(0), 1., convert(Float64, a))
return tpsa1
end

Expand All @@ -426,14 +426,14 @@ end
function (ct1::ComplexTPS, a::Number)::Ptr{CTPSA}
ctpsa = get_ctemp!(ct1)
mad_ctpsa_copy!(ct1.tpsa, ctpsa)
mad_ctpsa_set0!(ctpsa, convert(ComplexF64, 1.), convert(ComplexF64, -a))
mad_ctpsa_seti!(ctpsa, Cint(0), convert(ComplexF64, 1.), convert(ComplexF64, -a))
return ctpsa
end

function (a::Number, ct1::ComplexTPS)::Ptr{CTPSA}
ctpsa = get_ctemp!(ct1)
mad_ctpsa_scl!(ct1.tpsa, convert(ComplexF64,-1.), ctpsa)
mad_ctpsa_set0!(ctpsa, convert(ComplexF64,1.), convert(ComplexF64, a))
mad_ctpsa_seti!(ctpsa, Cint(0), convert(ComplexF64,1.), convert(ComplexF64, a))
return ctpsa
end

Expand All @@ -454,13 +454,13 @@ function ∓(ctpsa1::Ptr{CTPSA}, ct1::ComplexTPS)::Ptr{CTPSA}
end

function (ctpsa1::Ptr{CTPSA}, a::Number)::Ptr{CTPSA}
mad_ctpsa_set0!(ctpsa1, convert(ComplexF64,1.), convert(ComplexF64, -a))
mad_ctpsa_seti!(ctpsa1, Cint(0), convert(ComplexF64,1.), convert(ComplexF64, -a))
return ctpsa1
end

function (a::Number, ctpsa1::Ptr{CTPSA})::Ptr{CTPSA}
mad_ctpsa_scl!(ctpsa1, convert(ComplexF64, -1.), ctpsa1)
mad_ctpsa_set0!(ctpsa1, convert(ComplexF64, 1.), convert(ComplexF64, a))
mad_ctpsa_seti!(ctpsa1, Cint(0), convert(ComplexF64, 1.), convert(ComplexF64, a))
return ctpsa1
end

Expand All @@ -480,15 +480,15 @@ end
function (t1::TPS, a::Complex)::Ptr{CTPSA}
ctpsa = get_ctemp!(t1)
mad_ctpsa_cplx!(t1.tpsa, Base.unsafe_convert(Ptr{RTPSA}, C_NULL), ctpsa)
mad_ctpsa_set0!(ctpsa, convert(ComplexF64, 1), convert(ComplexF64, -a))
mad_ctpsa_seti!(ctpsa, Cint(0), convert(ComplexF64, 1), convert(ComplexF64, -a))
return ctpsa
end

function (a::Complex, t1::TPS)::Ptr{CTPSA}
ctpsa = get_ctemp!(t1)
mad_ctpsa_cplx!(t1.tpsa, Base.unsafe_convert(Ptr{RTPSA}, C_NULL), ctpsa)
mad_ctpsa_scl!(ctpsa, convert(ComplexF64, -1), ctpsa)
mad_ctpsa_set0!(ctpsa, convert(ComplexF64, 1), convert(ComplexF64,a))
mad_ctpsa_seti!(ctpsa,Cint(0), convert(ComplexF64, 1), convert(ComplexF64,a))
return ctpsa
end

Expand All @@ -508,7 +508,7 @@ function ∓(tpsa1::Ptr{RTPSA}, a::Complex)::Ptr{CTPSA}
ctpsa = get_ctemp_low!(tpsa1)
mad_ctpsa_cplx!(tpsa1, Base.unsafe_convert(Ptr{RTPSA}, C_NULL), ctpsa)
rel_temp!(tpsa1)
mad_ctpsa_set0!(ctpsa, convert(ComplexF64, 1), convert(ComplexF64, -a))
mad_ctpsa_seti!(ctpsa, Cint(0), convert(ComplexF64, 1), convert(ComplexF64, -a))
return ctpsa
end

Expand All @@ -517,7 +517,7 @@ function ∓(a::Complex, tpsa1::Ptr{RTPSA})::Ptr{CTPSA}
mad_ctpsa_cplx!(tpsa1, Base.unsafe_convert(Ptr{RTPSA}, C_NULL), ctpsa)
rel_temp!(tpsa1)
mad_ctpsa_scl!(ctpsa, convert(ComplexF64, -1), ctpsa)
mad_ctpsa_set0!(ctpsa, convert(ComplexF64, 1), convert(ComplexF64,a))
mad_ctpsa_seti!(ctpsa, Cint(0), convert(ComplexF64, 1), convert(ComplexF64,a))
return ctpsa
end
function (ctpsa1::Ptr{CTPSA}, t1::TPS)::Ptr{CTPSA}
Expand Down
40 changes: 19 additions & 21 deletions src/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ end
# --- one ---
function one(t1::TPS)::TPS
t = TPS(mad_tpsa_new(t1.tpsa, MAD_TPSA_SAME))
mad_tpsa_set0!(t.tpsa, 0.0, 1.0)
mad_tpsa_seti!(t.tpsa, Cint(0), 0.0, 1.0)
return t
end

function one(ct1::ComplexTPS)::ComplexTPS
ct = ComplexTPS(mad_ctpsa_new(ct1.tpsa, MAD_TPSA_SAME))
mad_ctpsa_set0!(ct.tpsa, ComplexF64(0.0), ComplexF64(1.0))
mad_ctpsa_seti!(ct.tpsa, Cint(0), ComplexF64(0.0), ComplexF64(1.0))
return ct
end

Expand Down Expand Up @@ -108,15 +108,15 @@ end
# isequal, just as Dual Numbers.

function <(t1::TPS, t2::TPS)::Bool
return mad_tpsa_get0(t1.tpsa) < mad_tpsa_get0(t2.tpsa)
return mad_tpsa_geti(t1.tpsa, Cint(0)) < mad_tpsa_geti(t2.tpsa, Cint(0))
end

function <(t1::TPS, a::Real)::Bool
return mad_tpsa_get0(t1.tpsa) < a
return mad_tpsa_geti(t1.tpsa, Cint(0)) < a
end

function <(a::Real, t1::TPS)::Bool
return a < mad_tpsa_get0(t1.tpsa)
return a < mad_tpsa_geti(t1.tpsa, Cint(0))
end

function >(t1::TPS, t2::TPS)::Bool
Expand All @@ -132,15 +132,15 @@ function >(a::Real, t1::TPS)::Bool
end

function <=(t1::TPS, t2::TPS)::Bool
return mad_tpsa_get0(t1.tpsa) <= mad_tpsa_get0(t2.tpsa)
return mad_tpsa_geti(t1.tpsa, Cint(0)) <= mad_tpsa_geti(t2.tpsa, Cint(0))
end

function <=(t1::TPS, a::Real)::Bool
return mad_tpsa_get0(t1.tpsa) <= a
return mad_tpsa_geti(t1.tpsa, Cint(0)) <= a
end

function <=(a::Real, t1::TPS)::Bool
return a <= mad_tpsa_get0(t1.tpsa)
return a <= mad_tpsa_geti(t1.tpsa, Cint(0))
end

function >=(t1::TPS, t2::TPS)::Bool
Expand All @@ -158,44 +158,44 @@ end
# Note Complex numbers/TPSs have no defined >, <

function ==(t1::TPS, t2::TPS)::Bool
return mad_tpsa_get0(t1.tpsa) == mad_tpsa_get0(t2.tpsa)
return mad_tpsa_geti(t1.tpsa, Cint(0)) == mad_tpsa_geti(t2.tpsa, Cint(0))
end

function ==(t1::TPS, a::Number)::Bool
return mad_tpsa_get0(t1.tpsa) == a
return mad_tpsa_geti(t1.tpsa, Cint(0)) == a
end

function ==(a::Number,t1::TPS)::Bool
return mad_tpsa_get0(t1.tpsa) == a
return mad_tpsa_geti(t1.tpsa, Cint(0)) == a
end

# ---

function ==(t1::TPS, a::Complex)::Bool
return mad_tpsa_get0(t1.tpsa) == a
return mad_tpsa_geti(t1.tpsa, Cint(0)) == a
end

function ==(a::Complex,t1::TPS)::Bool
return mad_tpsa_get0(t1.tpsa) == a
return mad_tpsa_geti(t1.tpsa, Cint(0)) == a
end

# ---


function ==(ct1::ComplexTPS, ct2::ComplexTPS)::Bool
return mad_ctpsa_get0(ct1.tpsa) == mad_ctpsa_get0(ct2.tpsa)
return mad_ctpsa_geti(ct1.tpsa, Cint(0)) == mad_ctpsa_geti(ct2.tpsa, Cint(0))
end

function ==(ct1::ComplexTPS, a::Number)::Bool
return mad_ctpsa_get0(ct1.tpsa) == a
return mad_ctpsa_geti(ct1.tpsa, Cint(0)) == a
end

function ==(a::Number, ct1::ComplexTPS)::Bool
return mad_ctpsa_get0(ct1.tpsa) == a
return mad_ctpsa_geti(ct1.tpsa, Cint(0)) == a
end

function ==(ct1::ComplexTPS, t1::TPS)::Bool
return mad_ctpsa_get0(ct1.tpsa) == mad_tpsa_get0(t1.tpsa)
return mad_ctpsa_geti(ct1.tpsa, Cint(0)) == mad_tpsa_geti(t1.tpsa, Cint(0))
end

function ==(t1::TPS, ct1::ComplexTPS)::Bool
Expand Down Expand Up @@ -263,12 +263,10 @@ add!(a::Ptr{CTPSA}, b::Ptr{RTPSA}, c::Ptr{CTPSA}) = mad_ctpsa_addt!(a, b, c)
add!(t::Union{TPS,ComplexTPS}, t1::Union{TPS,ComplexTPS}, t2::Union{TPS,ComplexTPS}) = add!(t1.tpsa, t2.tpsa, t.tpsa)

# TPS, scalar:
set0!(t::Ptr{RTPSA}, a::Float64, b::Float64) = mad_tpsa_set0!(t, a, b)
set0!(t::Ptr{CTPSA}, a::ComplexF64, b::ComplexF64) = mad_ctpsa_set0!(t, a, b)

function add!(t::Union{TPS,ComplexTPS}, t1::Union{TPS,ComplexTPS}, a::Number)
copy!(t, t1)
set0!(t.tpsa, convert(numtype(t), 1), convert(numtype(t), a))
seti!(t.tpsa, Cint(0), convert(numtype(t), 1), convert(numtype(t), a))
end

add!(t::Union{TPS,ComplexTPS}, a::Number, t1::Union{TPS,ComplexTPS}) = add!(t, t1, a)
Expand Down Expand Up @@ -306,7 +304,7 @@ sub!(t::Union{TPS,ComplexTPS}, t1::Union{TPS,ComplexTPS}, a::Number) = add!(t, t

function sub!(t::Union{TPS,ComplexTPS}, a::Number, t1::Union{TPS,ComplexTPS})
scl!(t1.tpsa, convert(numtype(t), -1.), t.tpsa)
set0!(t.tpsa, convert(numtype(t), 1.), convert(numtype(t), a))
seti!(t.tpsa, Cint(0), convert(numtype(t), 1.), convert(numtype(t), a))
end

for t = ((TPS,TPS),(TPS,Real),(Real,TPS),(TPS,Complex),(Complex,TPS),(ComplexTPS,TPS),(TPS,ComplexTPS),(ComplexTPS,ComplexTPS),(ComplexTPS, Number), (Number, ComplexTPS))
Expand Down
26 changes: 13 additions & 13 deletions src/tps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,19 @@ end
# --- promote real to TPS ---
function low_TPS(a::Real, use::Nothing)
t = TPS(mad_tpsa_newd(GTPSA.desc_current.desc, MAD_TPSA_DEFAULT))
mad_tpsa_set0!(t.tpsa, convert(Float64, 0), convert(Float64,a))
mad_tpsa_seti!(t.tpsa, Cint(0), convert(Float64, 0), convert(Float64,a))
return t
end

function low_TPS(a::Real, use::Union{TPS,ComplexTPS})
t = TPS(mad_tpsa_new(Base.unsafe_convert(Ptr{RTPSA}, use.tpsa), MAD_TPSA_SAME))
mad_tpsa_set0!(t.tpsa, 0.0, convert(Float64,a))
mad_tpsa_seti!(t.tpsa, Cint(0), 0.0, convert(Float64,a))
return t
end

function low_TPS(a::Real, use::Descriptor)
t = TPS(mad_tpsa_newd(use.desc, MAD_TPSA_DEFAULT))
mad_tpsa_set0!(t.tpsa, 0.0, convert(Float64,a))
mad_tpsa_seti!(t.tpsa, Cint(0), 0.0, convert(Float64,a))
return t
end

Expand Down Expand Up @@ -156,19 +156,19 @@ end
# --- promote number to ComplexTPS ---
function low_ComplexTPS(a::Union{Real,Complex}, use::Nothing)
ct = ComplexTPS(mad_ctpsa_newd(GTPSA.desc_current.desc, MAD_TPSA_DEFAULT))
mad_ctpsa_set0!(ct.tpsa, convert(ComplexF64, 0), convert(ComplexF64,a))
mad_ctpsa_seti!(ct.tpsa, Cint(0), convert(ComplexF64, 0), convert(ComplexF64,a))
return ct
end

function low_ComplexTPS(a::Union{Real,Complex}, use::Union{TPS,ComplexTPS})
ct = ComplexTPS(mad_ctpsa_new(Base.unsafe_convert(Ptr{CTPSA}, use.tpsa), MAD_TPSA_SAME))
mad_ctpsa_set0!(ct.tpsa, convert(ComplexF64, 0), convert(ComplexF64,a))
mad_ctpsa_seti!(ct.tpsa, Cint(0), convert(ComplexF64, 0), convert(ComplexF64,a))
return ct
end

function low_ComplexTPS(a::Union{Real,Complex}, use::Descriptor)
ct = ComplexTPS(mad_ctpsa_newd(use.desc, MAD_TPSA_DEFAULT))
mad_ctpsa_set0!(ct.tpsa, convert(ComplexF64, 0), convert(ComplexF64,a))
mad_ctpsa_seti!(ct.tpsa, Cint(0), convert(ComplexF64, 0), convert(ComplexF64,a))
return ct
end

Expand All @@ -188,32 +188,32 @@ end
function low_ComplexTPS(t1::TPS, a::Real, use::Nothing)
ct = ComplexTPS(mad_ctpsa_new(Base.unsafe_convert(Ptr{CTPSA}, t1.tpsa), MAD_TPSA_SAME))
mad_ctpsa_cplx!(t1.tpsa, Base.unsafe_convert(Ptr{RTPSA}, C_NULL), ct.tpsa)
mad_ctpsa_set0!(ct.tpsa, convert(ComplexF64, 1), convert(ComplexF64, complex(0,a)))
mad_ctpsa_seti!(ct.tpsa, Cint(0), convert(ComplexF64, 1), convert(ComplexF64, complex(0,a)))
return ct
end

function low_ComplexTPS(a::Real, t1::TPS, use::Nothing)
ct = ComplexTPS(mad_ctpsa_new(Base.unsafe_convert(Ptr{CTPSA}, t1.tpsa), MAD_TPSA_SAME))
mad_ctpsa_cplx!(Base.unsafe_convert(Ptr{RTPSA}, C_NULL), t1.tpsa, ct.tpsa)
mad_ctpsa_set0!(ct.tpsa, convert(ComplexF64, 1), convert(ComplexF64, a))
mad_ctpsa_seti!(ct.tpsa, Cint(0), convert(ComplexF64, 1), convert(ComplexF64, a))
return ct
end

function low_ComplexTPS(a::Real, b::Real, use::Nothing)
ct = ComplexTPS(mad_ctpsa_newd(GTPSA.desc_current.desc, MAD_TPSA_DEFAULT))
mad_ctpsa_set0!(ct.tpsa, convert(ComplexF64, 0), convert(ComplexF64, complex(a,b)))
mad_ctpsa_seti!(ct.tpsa, Cint(0), convert(ComplexF64, 0), convert(ComplexF64, complex(a,b)))
return ct
end

function low_ComplexTPS(a::Real, b::Real, use::Descriptor)
ct = ComplexTPS(mad_ctpsa_newd(use.desc, MAD_TPSA_DEFAULT))
mad_ctpsa_set0!(ct.tpsa, convert(ComplexF64, 0), convert(ComplexF64, complex(a,b)))
mad_ctpsa_seti!(ct.tpsa, Cint(0), convert(ComplexF64, 0), convert(ComplexF64, complex(a,b)))
return ct
end

function low_ComplexTPS(a::Real, b::Real, use::Union{TPS,ComplexTPS})
ct = ComplexTPS(mad_ctpsa_new(Base.unsafe_convert(Ptr{CTPSA}, use.tpsa), MAD_TPSA_SAME))
mad_ctpsa_set0!(ct.tpsa, convert(ComplexF64, 0), convert(ComplexF64, complex(a,b)))
mad_ctpsa_seti!(ct.tpsa, Cint(0), convert(ComplexF64, 0), convert(ComplexF64, complex(a,b)))
return ct
end

Expand All @@ -225,13 +225,13 @@ end

function low_ComplexTPS(ta::TPS, b::Real, use::Descriptor)
ct = change(ta, use, type=ComplexTPS)
mad_ctpsa_set0!(ct.tpsa, convert(ComplexF64, 1), convert(ComplexF64, complex(0,b)))
mad_ctpsa_seti!(ct.tpsa, Cint(0), convert(ComplexF64, 1), convert(ComplexF64, complex(0,b)))
return ct
end

function low_ComplexTPS(a::Real, tb::TPS, use::Descriptor)
ct = change(tb, use, type=ComplexTPS, scl2=im)
mad_ctpsa_set0!(ct.tpsa, convert(ComplexF64, 1), convert(ComplexF64, a))
mad_ctpsa_seti!(ct.tpsa, Cint(0), convert(ComplexF64, 1), convert(ComplexF64, a))
return ct
end

Expand Down

0 comments on commit a6b0ba0

Please sign in to comment.