Skip to content

Commit

Permalink
Full agreement between MAD and TPSA.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsignorelli committed Oct 11, 2023
1 parent a0e34f1 commit 34b1d7d
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 59 deletions.
37 changes: 15 additions & 22 deletions check_MAD.jl → src/check_MAD.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,8 @@
# mad_desc_del: Extra multiply-dispatched implementation in Julia for C_NULL parameter
# mad_ctpsa_equt: tol_ in TPSA.jl is correct vs tol in mad_ctpsa.H
# mad_ctpsa_unit: C code has two equivalent function declarations with x and t. TPSA.jl correct

# To-do:
# mad_tpsa_ordv
# mad_tpsa_setval
# mad_ctpsa_ordv
# mad_ctpsa_setval
# mad_ctpsa_setval_r
# mad_ctpsa_pown_r
# mad_ctpsa_conj
# mad_tpsa_ordv: Splats in Julia have names, C they do not, so script will show disagreements
# mad_ctpsa_ordv: Same as for mad_tpsa_ordv

using Downloads

Expand Down Expand Up @@ -217,15 +210,15 @@ function get_jl_function_declarations(str)
i = start_index + 1
end

# Remove multiline comments
i = 1
while occursin("#=", str)
len = length(str)
start_index = findnext("#=", str, i)[1] - 1
end_index = findnext("=#", str, i)[2] + 1
str = str[1:start_index] * str[end_index:len]
i = start_index + 1
end
# Remove multiline comments
i = 1
while occursin("#=", str)
len = length(str)
start_index = findnext("#=", str, i)[1] - 1
end_index = findnext("=#", str, i)[2] + 1
str = str[1:start_index] * str[end_index:len]
i = start_index + 1
end

# Remove single line comments
i = 1
Expand Down Expand Up @@ -334,7 +327,7 @@ end
str = String(take!(io))
fun_decs_c = get_c_function_declarations(str)

str = read("src/mono.jl", String)
str = read("mono.jl", String)
fun_decs_jl = get_jl_function_declarations(str)
println("Comparing mad_mono.h to mono.jl...")
compare(fun_decs_c, fun_decs_jl)
Expand All @@ -351,7 +344,7 @@ end
str = String(take!(io))
fun_decs_c = get_c_function_declarations(str)

str = read("src/desc.jl", String)
str = read("desc.jl", String)
fun_decs_jl = get_jl_function_declarations(str)
println("Comparing mad_desc.h to desc.jl...")
compare(fun_decs_c, fun_decs_jl)
Expand All @@ -368,7 +361,7 @@ end
str = String(take!(io))
fun_decs_c = get_c_function_declarations(str)

str = read("src/rtpsa.jl", String)
str = read("rtpsa.jl", String)
fun_decs_jl = get_jl_function_declarations(str)
println("Comparing mad_tpsa.h to rtpsa.jl...")
compare(fun_decs_c, fun_decs_jl)
Expand All @@ -384,7 +377,7 @@ end
str = String(take!(io))
fun_decs_c = get_c_function_declarations(str)

str = read("src/ctpsa.jl", String)
str = read("ctpsa.jl", String)
fun_decs_jl = get_jl_function_declarations(str)
println("Comparing mad_ctpsa.h to ctpsa.jl...")
compare(fun_decs_c, fun_decs_jl)
Expand Down
51 changes: 47 additions & 4 deletions src/ctpsa.jl
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ function mad_ctpsa_ord(t::Ptr{CTPSA{Desc}})::Cuchar
ret = @ccall MAD_TPSA.mad_ctpsa_ord(t::Ptr{CTPSA{Desc}})::Cuchar
return ret
end
#=

"""
mad_ctpsa_ordv(t::Ptr{CTPSA{Desc}}, ts::Ptr{CTPSA{Desc}}...)::Cuchar
Expand All @@ -148,10 +148,11 @@ Returns maximum order of all TPSAs provided.
- `mo` -- Maximum order of all TPSAs provided
"""
function mad_ctpsa_ordv(t::Ptr{CTPSA{Desc}}, ts::Ptr{CTPSA{Desc}}...)::Cuchar
mo = @ccall MAD_TPSA.mad_ctpsa_ordv(t::Ptr{CTPSA{Desc}}, ts::Ptr{CTPSA{Desc}}..., 0::Cint)::Cuchar # null pointer after args for safe use
# mo = @ccall MAD_TPSA.mad_ctpsa_ordv(t::Ptr{CTPSA{Desc}}, ts::Ptr{CTPSA{Desc}}..., 0::Cint)::Cuchar # null pointer after args for safe use
ccall((:mad_tpsa_ordv, MAD_TPSA), Cuchar, (Ptr{CTPSA{Desc}}, Ptr{CTPSA{Desc}}...), t, ts...)
return mo
end
=#


"""
mad_ctpsa_ordn(n::Cint, t::Ptr{Ptr{CTPSA{Desc}}})::Cuchar
Expand Down Expand Up @@ -312,6 +313,33 @@ function mad_ctpsa_setvar_r!(t::Ptr{CTPSA{Desc}}, v_re::Cdouble, v_im::Cdouble,
@ccall MAD_TPSA.mad_ctpsa_setvar_r(t::Ptr{CTPSA{Desc}}, v_re::Cdouble, v_im::Cdouble, iv_::Cint, scl_re_::Cdouble, scl_im_::Cdouble)::Cvoid
end

"""
mad_ctpsa_setval!(t::Ptr{CTPSA{Desc}}, v::ComplexF64)
Sets the scalar part of the TPSA to v and all other values to 0 (sets the TPSA order to 0).
### Input
- `t` -- TPSA to set to scalar
- `v` -- Scalar value to set TPSA
"""
function mad_ctpsa_setval!(t::Ptr{CTPSA{Desc}}, v::ComplexF64)
@ccall MAD_TPSA.mad_ctpsa_setval(t::Ptr{CTPSA{Desc}}, v::ComplexF64)::Cvoid
end

"""
mad_ctpsa_setval_r!(t::Ptr{CTPSA{Desc}}, v_re::Cdouble, v_im::Cdouble)
Sets the scalar part of the TPSA to v and all other values to 0 (sets the TPSA order to 0).
Equivalent to mad_ctpsa_setval but without complex-by-value arguments.
### Input
- `t` -- TPSA to set to scalar
- `v_re` -- Real part of scalar value to set TPSA
- `v_im` -- Imaginary part of scalar value to set TPSA
"""
function mad_ctpsa_setval_r!(t::Ptr{CTPSA{Desc}}, v_re::Cdouble, v_im::Cdouble)
@ccall MAD_TPSA.mad_ctpsa_setval_r(t::Ptr{CTPSA{Desc}}, v_re::Cdouble, v_im::Cdouble)::Cvoid
end

"""
mad_ctpsa_setnam!(t::Ptr{CTPSA{Desc}}, nam::Cstring)
Expand Down Expand Up @@ -1149,7 +1177,7 @@ end
"""
mad_ctpsa_pown_r!(a::Ptr{CTPSA{Desc}}, v_re::Cdouble, v_im::Cdouble, c::Ptr{CTPSA{Desc}})
Sets the destination TPSA c = a ^ v where v is of double precision. Without complex-by-power arguments.
Sets the destination TPSA c = a ^ v where v is of double precision. Without complex-by-value arguments.
### Input
- `a` -- Source TPSA a
Expand Down Expand Up @@ -1376,6 +1404,21 @@ function mad_ctpsa_nrm(a::Ptr{CTPSA{Desc}})::Cdouble
return nrm
end

"""
mad_ctpsa_conj(a::Ptr{CTPSA{Desc}}, c::Ptr{CTPSA{Desc}})
Calculates the complex conjugate of of TPSA a.
### Input
- `a` -- Source TPSA a
### Output
- `c` -- Destination TPSA c = conj(a)
"""
function mad_ctpsa_conj!(a::Ptr{CTPSA{Desc}}, c::Ptr{CTPSA{Desc}})
@ccall MAD_TPSA.mad_ctpsa_conj(a::Ptr{CTPSA{Desc}}, c::Ptr{CTPSA{Desc}})::Cvoid
end


#= Old
"""
Expand Down
Loading

0 comments on commit 34b1d7d

Please sign in to comment.