Skip to content

Commit

Permalink
Restructing of package, added examples 0-3
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsignorelli committed Sep 15, 2023
1 parent 2dbaf31 commit 9e305c3
Show file tree
Hide file tree
Showing 20 changed files with 216 additions and 5,739 deletions.
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ authors = ["Matt Signorelli"]
version = "1.0.0-DEV"

[deps]
ExportAll = "ad2082ca-a69e-11e9-38fa-e96309a31fe4"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"

[compat]
Expand Down
25 changes: 25 additions & 0 deletions examples/gtpsa_ex0.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
include("../src/TPSA.jl")
using .TPSA

d = mad_desc_newv(Int32(1), 0x1)

# two TPSAs, t1 has maximum order, t2 is same as t1
t1 = mad_tpsa_newd(d, MAD_TPSA_DEFAULT)
t2 = mad_tpsa_new(t1, MAD_TPSA_SAME)

# set order 0 to pi/6 and order 1 to 0 (scalar-like)
mad_tpsa_setv!(t1, Int32(0), Int32(1), Base.unsafe_convert(Ptr{Float64}, [pi/6])) # Need to convert from Vector{Float64} to Ptr{Float64} for C
mad_tpsa_print(t1, Base.unsafe_convert(Cstring, "ini"), 0.,Int32(0),C_NULL) # Similiar conversion here for Ptr

# t2=sin(t1)
mad_tpsa_sin!(t1, t2)
mad_tpsa_print(t2, Base.unsafe_convert(Cstring, "sin"), 0.,Int32(0),C_NULL)
mad_tpsa_del!(t1)

# tpsa functions and operators support aliasing (i.e. src == dst)
mad_tpsa_asin!(t2, t2); # asin(x) = -i*ln(i*x + sqrt(1-x^2))
mad_tpsa_print(t2, Base.unsafe_convert(Cstring, "asin"), 0.,Int32(0),C_NULL) # see the accuracy of asin(sin)
mad_tpsa_del!(t2)

# destroy all created descriptors (optional cleanup)
mad_desc_del!(C_NULL)
25 changes: 25 additions & 0 deletions examples/gtpsa_ex1.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
include("../src/TPSA.jl")
using .TPSA

d = mad_desc_newv(Int32(6), 0x4)

# two TPSAs, t1 has maximum order, t2 is same as t1
t1 = mad_tpsa_newd(d, MAD_TPSA_DEFAULT)
t2 = mad_tpsa_new(t1, MAD_TPSA_SAME)

# set order 0 and 1 (quick and dirty!)
mad_tpsa_setv!(t1, Int32(0), Int32(1+6), Base.unsafe_convert(Ptr{Float64}, [pi/6,1,1,1,1,1,1])) # Need to convert from Vector{Float64} to Ptr{Float64} for C
mad_tpsa_print(t1, Base.unsafe_convert(Cstring, "ini"), 0.,Int32(0),C_NULL) # Similiar conversion here for Ptr

# t2=sin(t1)
mad_tpsa_sin!(t1, t2)
mad_tpsa_print(t2, Base.unsafe_convert(Cstring, "sin"), 0.,Int32(0),C_NULL)
mad_tpsa_del!(t1)

# tpsa functions and operators support aliasing (i.e. src == dst)
mad_tpsa_asin!(t2, t2); # asin(x) = -i*ln(i*x + sqrt(1-x^2))
mad_tpsa_print(t2, Base.unsafe_convert(Cstring, "asin"), 0.,Int32(0),C_NULL) # see the accuracy of asin(sin)
mad_tpsa_del!(t2)

# destroy all created descriptors (optional cleanup)
mad_desc_del!(C_NULL)
27 changes: 27 additions & 0 deletions examples/gtpsa_ex2.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
include("../src/TPSA.jl")
using .TPSA

# descriptor for TPSA with 4 variables of order 4 and
# 2 parameters of order 3
d = mad_desc_newvp(Int32(4), 0x4, Int32(2), 0x3)

# two TPSAs, t1 has maximum order, t2 is same as t1
t1 = mad_tpsa_newd(d, MAD_TPSA_DEFAULT)
t2 = mad_tpsa_new(t1, MAD_TPSA_SAME)

# set order 0 and 1 (quick and dirty!)
mad_tpsa_setv!(t1, Int32(0), Int32(1+6), Base.unsafe_convert(Ptr{Float64}, [pi/6,1,1,1,1,1,1])) # Need to convert from Vector{Float64} to Ptr{Float64} for C
mad_tpsa_print(t1, Base.unsafe_convert(Cstring, "ini"), 0.,Int32(0),C_NULL) # Similiar conversion here for Ptr

# t2=sin(t1)
mad_tpsa_sin!(t1, t2)
mad_tpsa_print(t2, Base.unsafe_convert(Cstring, "sin"), 0.,Int32(0),C_NULL)
mad_tpsa_del!(t1)

# tpsa functions and operators support aliasing (i.e. src == dst)
mad_tpsa_asin!(t2, t2); # asin(x) = -i*ln(i*x + sqrt(1-x^2))
mad_tpsa_print(t2, Base.unsafe_convert(Cstring, "asin"), 0.,Int32(0),C_NULL) # see the accuracy of asin(sin)
mad_tpsa_del!(t2)

# destroy all created descriptors (optional cleanup)
mad_desc_del!(C_NULL)
26 changes: 26 additions & 0 deletions examples/gtpsa_ex3.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
include("../src/TPSA.jl")
using .TPSA

# descriptor for TPSA with 6 variables of order 3,3,2,2,1,1
d = mad_desc_newvpo(Int32(6), 0x0, Int32(0), 0x0, Base.unsafe_convert(Ptr{UInt8}, [0x3, 0x3, 0x2, 0x2, 0x1, 0x1]))

# two TPSAs, t1 has maximum order, t2 is same as t1
t1 = mad_tpsa_newd(d, MAD_TPSA_DEFAULT)
t2 = mad_tpsa_new(t1, MAD_TPSA_SAME)

# set order 0 and 1 (quick and dirty!)
mad_tpsa_setv!(t1, Int32(0), Int32(1+6), Base.unsafe_convert(Ptr{Float64}, [pi/6,1,1,1,1,1,1])) # Need to convert from Vector{Float64} to Ptr{Float64} for C
mad_tpsa_print(t1, Base.unsafe_convert(Cstring, "ini"), 0.,Int32(0),C_NULL) # Similiar conversion here for Ptr

# t2=sin(t1)
mad_tpsa_sin!(t1, t2)
mad_tpsa_print(t2, Base.unsafe_convert(Cstring, "sin"), 0.,Int32(0),C_NULL)
mad_tpsa_del!(t1)

# tpsa functions and operators support aliasing (i.e. src == dst)
mad_tpsa_asin!(t2, t2); # asin(x) = -i*ln(i*x + sqrt(1-x^2))
mad_tpsa_print(t2, Base.unsafe_convert(Cstring, "asin"), 0.,Int32(0),C_NULL) # see the accuracy of asin(sin)
mad_tpsa_del!(t2)

# destroy all created descriptors (optional cleanup)
mad_desc_del!(C_NULL)
33 changes: 33 additions & 0 deletions examples/gtpsa_ex4.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
include("../src/TPSA.jl")
using .TPSA
using Printf

# descriptor for TPSA with 6 variables of order 10,10,10,10,10,10 without parameters
d10 = mad_desc_newvpo(Int32(6), 0x0, Int32(0), 0x0, Base.unsafe_convert(Ptr{UInt8}, [0xa, 0xa, 0xa, 0xa, 0xa, 0xa]))
@printf("d10 length=%4d coefs\n", mad_desc_maxlen(d10, MAD_TPSA_DEFAULT))
mad_desc_del!(d10)

# descriptor for TPSA of order 12 with 6 variables of order 2,2,2,2,1,10 without parameters
d = mad_desc_newvpo(Int32(6), 0xc, Int32(0), 0x0, Base.unsafe_convert(Ptr{UInt8}, [0x2, 0x2, 0x2, 0x2, 0x1, 0xa]))
@printf("d length=%4d coefs\n", mad_desc_maxlen(d, MAD_TPSA_DEFAULT))

# two TPSAs, t2 is same as t1
t1 = mad_tpsa_newd(d, MAD_TPSA_DEFAULT)
t2 = mad_tpsa_new(t1, MAD_TPSA_SAME)

# set order 0 and 1 (quick and dirty!)
mad_tpsa_setv!(t1, Int32(0), Int32(1+6), Base.unsafe_convert(Ptr{Float64}, [pi/6,1,1,1,1,1,1])) # Need to convert from Vector{Float64} to Ptr{Float64} for C
mad_tpsa_print(t1, Base.unsafe_convert(Cstring, "ini"), 0.,Int32(0),C_NULL) # Similiar conversion here for Ptr

# t2=sin(t1)
mad_tpsa_sin!(t1, t2)
mad_tpsa_print(t2, Base.unsafe_convert(Cstring, "sin"), 0.,Int32(0),C_NULL)
mad_tpsa_del!(t1)

# tpsa functions and operators support aliasing (i.e. src == dst)
mad_tpsa_asin!(t2, t2); # asin(x) = -i*ln(i*x + sqrt(1-x^2))
mad_tpsa_print(t2, Base.unsafe_convert(Cstring, "asin"), 0.,Int32(0),C_NULL) # see the accuracy of asin(sin)
mad_tpsa_del!(t2)

# destroy all created descriptors (optional cleanup)
mad_desc_del!(C_NULL)
9 changes: 0 additions & 9 deletions firsttest.txt

This file was deleted.

62 changes: 0 additions & 62 deletions src/Structs.jl

This file was deleted.

Loading

0 comments on commit 9e305c3

Please sign in to comment.