Skip to content

Commit

Permalink
Compiles
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsignorelli committed Aug 14, 2023
1 parent fefa834 commit 9342f29
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 3,093 deletions.
77 changes: 33 additions & 44 deletions src/ComplexTPSA.jl
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
module ComplexTPSA
export CTPSA
const NAMSZ::Int = 16

mutable struct CTPSA{T}
d::Ptr{T} # Ptr to ctpsa descriptor
uid::Cint # Special user field for external use (and padding)
mo::Cuchar # max ord (allocated)
lo::Cuchar # lowest used ord
hi::Cuchar # highest used ord
nz::Culonglong # zero/nonzero homogenous polynomials. Int64 if 64 bit else 32 bit
nam::NTuple{NAMSZ,Cuchar} # tpsa name
coef::Ptr{ComplexF64} # warning: must be identical to ctpsa up to coef excluded
end
include("Structs.jl")
using .Structs


"""
Expand Down Expand Up @@ -113,7 +102,7 @@ end
- `ret` -- Monomials in CTPSA
"""
function mad_ctpsa_len(t::Ptr{CTPSA{Desc}})::Cint
ret = @ccall MAD_TPSA.mad_ctpsa_len(t::Ptr{CTPSA,CTPSA})::Cint
ret = @ccall MAD_TPSA.mad_ctpsa_len(t::Ptr{CTPSA{Desc}})::Cint
return ret
end

Expand Down Expand Up @@ -163,10 +152,10 @@ end
### Output
- `mo` -- Order
"""
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
return mo
end
#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
# return mo
#end


"""
Expand Down Expand Up @@ -360,7 +349,7 @@ end


"""
mad_ctpsa_cplx!(re_:Ptr{RTPSA{Desc}}, im_::Ptr{RTPSA{Desc}}, r::Ptr{CTPSA{Desc}})
mad_ctpsa_cplx!(re_::Ptr{RTPSA{Desc}}, im_::Ptr{RTPSA{Desc}}, r::Ptr{CTPSA{Desc}})
Creates a CTPSA with real and imaginary parts from the RTPSAs re_ and im_ respectively.
Expand All @@ -369,105 +358,105 @@ Creates a CTPSA with real and imaginary parts from the RTPSAs re_ and im_ respec
- `im_` -- Imaginary part of CTPSA to make
- `r` -- Destination CTPSA with r = re_ + im*im_
"""
function mad_ctpsa_cplx!(re_:Ptr{RTPSA{Desc}}, im_::Ptr{RTPSA{Desc}}, r::Ptr{CTPSA{Desc}})
@ccall MAD_TPSA.mad_ctpsa_cplx(re_:Ptr{RTPSA{Desc}}, im_::Ptr{RTPSA{Desc}}, r::Ptr{CTPSA{Desc}})::Cvoid
function mad_ctpsa_cplx!(re_::Ptr{RTPSA{Desc}}, im_::Ptr{RTPSA{Desc}}, r::Ptr{CTPSA{Desc}})
@ccall MAD_TPSA.mad_ctpsa_cplx(re_::Ptr{RTPSA{Desc}}, im_::Ptr{RTPSA{Desc}}, r::Ptr{CTPSA{Desc}})::Cvoid
end


"""
mad_ctpsa_real!(t:Ptr{CTPSA{Desc}}, r::Ptr{RTPSA{Desc}})
mad_ctpsa_real!(t::Ptr{CTPSA{Desc}}, r::Ptr{RTPSA{Desc}})
Sets the RTPSA r equal to the real part of CTPSA t.
### Input
- `t` -- Source CTPSA
- `r` -- Destination RTPSA with r = Re(t)
"""
function mad_ctpsa_real!(t:Ptr{CTPSA{Desc}}, r::Ptr{RTPSA{Desc}})
@ccall MAD_TPSA.mad_ctpsa_real(t:Ptr{CTPSA{Desc}}, r::Ptr{RTPSA{Desc}})::Cvoid
function mad_ctpsa_real!(t::Ptr{CTPSA{Desc}}, r::Ptr{RTPSA{Desc}})
@ccall MAD_TPSA.mad_ctpsa_real(t::Ptr{CTPSA{Desc}}, r::Ptr{RTPSA{Desc}})::Cvoid
end


"""
mad_ctpsa_imag!(t:Ptr{CTPSA{Desc}}, r::Ptr{RTPSA{Desc}})
mad_ctpsa_imag!(t::Ptr{CTPSA{Desc}}, r::Ptr{RTPSA{Desc}})
Sets the RTPSA r equal to the imaginary part of CTPSA t.
### Input
- `t` -- Source CTPSA
- `r` -- Destination RTPSA with r = Im(t)
"""
function mad_ctpsa_imag!(t:Ptr{CTPSA{Desc}}, r::Ptr{RTPSA{Desc}})
@ccall MAD_TPSA.mad_ctpsa_imag(t:Ptr{CTPSA{Desc}}, r::Ptr{RTPSA{Desc}})::Cvoid
function mad_ctpsa_imag!(t::Ptr{CTPSA{Desc}}, r::Ptr{RTPSA{Desc}})
@ccall MAD_TPSA.mad_ctpsa_imag(t::Ptr{CTPSA{Desc}}, r::Ptr{RTPSA{Desc}})::Cvoid
end

"""
mad_ctpsa_cabs!(t:Ptr{CTPSA{Desc}}, r::Ptr{RTPSA{Desc}})
mad_ctpsa_cabs!(t::Ptr{CTPSA{Desc}}, r::Ptr{RTPSA{Desc}})
Sets the RTPSA r equal to the aboslute value of CTPSA t
### Input
- `t` -- Source CTPSA
- `r` -- Destination RTPSA with r = |t|
"""
function mad_ctpsa_cabs!(t:Ptr{CTPSA{Desc}}, r::Ptr{RTPSA{Desc}})
@ccall MAD_TPSA.mad_ctpsa_cabs(t:Ptr{CTPSA{Desc}}, r::Ptr{RTPSA{Desc}})::Cvoid
function mad_ctpsa_cabs!(t::Ptr{CTPSA{Desc}}, r::Ptr{RTPSA{Desc}})
@ccall MAD_TPSA.mad_ctpsa_cabs(t::Ptr{CTPSA{Desc}}, r::Ptr{RTPSA{Desc}})::Cvoid
end


"""
mad_ctpsa_carg!(t:Ptr{CTPSA{Desc}}, r::Ptr{RTPSA{Desc}})
mad_ctpsa_carg!(t::Ptr{CTPSA{Desc}}, r::Ptr{RTPSA{Desc}})
Sets the RTPSA r equal to the argument (phase) of CTPSA t
### Input
- `t` -- Source CTPSA
- `r` -- Destination RTPSA with r = carg(t)
"""
function mad_ctpsa_carg!(t:Ptr{CTPSA{Desc}}, r::Ptr{RTPSA{Desc}})
@ccall MAD_TPSA.mad_ctpsa_carg(t:Ptr{CTPSA{Desc}}, r::Ptr{RTPSA{Desc}})::Cvoid
function mad_ctpsa_carg!(t::Ptr{CTPSA{Desc}}, r::Ptr{RTPSA{Desc}})
@ccall MAD_TPSA.mad_ctpsa_carg(t::Ptr{CTPSA{Desc}}, r::Ptr{RTPSA{Desc}})::Cvoid
end


"""
mad_ctpsa_unit!(t:Ptr{CTPSA{Desc}}, r::Ptr{CTPSA{Desc}})
mad_ctpsa_unit!(t::Ptr{CTPSA{Desc}}, r::Ptr{CTPSA{Desc}})
???
### Input
- `t` -- Source CTPSA
- `r` -- Destination CTPSA
"""
function mad_ctpsa_unit!(t:Ptr{CTPSA{Desc}}, r::Ptr{CTPSA{Desc}})
@ccall MAD_TPSA.mad_ctpsa_unit(t:Ptr{CTPSA{Desc}}, r::Ptr{CTPSA{Desc}})::Cvoid
function mad_ctpsa_unit!(t::Ptr{CTPSA{Desc}}, r::Ptr{CTPSA{Desc}})
@ccall MAD_TPSA.mad_ctpsa_unit(t::Ptr{CTPSA{Desc}}, r::Ptr{CTPSA{Desc}})::Cvoid
end


"""
mad_ctpsa_rect!(t:Ptr{CTPSA{Desc}}, r::Ptr{CTPSA{Desc}})
mad_ctpsa_rect!(t::Ptr{CTPSA{Desc}}, r::Ptr{CTPSA{Desc}})
???
### Input
- `t` -- Source CTPSA
- `r` -- Destination CTPSA
"""
function mad_ctpsa_rect!(t:Ptr{CTPSA{Desc}}, r::Ptr{CTPSA{Desc}})
@ccall MAD_TPSA.mad_ctpsa_rect(t:Ptr{CTPSA{Desc}}, r::Ptr{CTPSA{Desc}})::Cvoid
function mad_ctpsa_rect!(t::Ptr{CTPSA{Desc}}, r::Ptr{CTPSA{Desc}})
@ccall MAD_TPSA.mad_ctpsa_rect(t::Ptr{CTPSA{Desc}}, r::Ptr{CTPSA{Desc}})::Cvoid
end


"""
mad_ctpsa_polar!(t:Ptr{CTPSA{Desc}}, r::Ptr{CTPSA{Desc}})
mad_ctpsa_polar!(t::Ptr{CTPSA{Desc}}, r::Ptr{CTPSA{Desc}})
???
### Input
- `t` -- Source CTPSA
- `r` -- Destination CTPSA
"""
function mad_ctpsa_polar!(t:Ptr{CTPSA{Desc}}, r::Ptr{CTPSA{Desc}})
@ccall MAD_TPSA.mad_ctpsa_polar(t:Ptr{CTPSA{Desc}}, r::Ptr{CTPSA{Desc}})::Cvoid
function mad_ctpsa_polar!(t::Ptr{CTPSA{Desc}}, r::Ptr{CTPSA{Desc}})
@ccall MAD_TPSA.mad_ctpsa_polar(t::Ptr{CTPSA{Desc}}, r::Ptr{CTPSA{Desc}})::Cvoid
end


Expand Down Expand Up @@ -871,7 +860,7 @@ end
- `a`
- `b`
"""
function mad_ctpsa_sets_r!(t::Ptr{CTPSA{Desc}}, n::Cint, s::Cstring, a_re::Cdouble, a_im::Cdouble, b_re::Cdouble, b_im::Cdouble))
function mad_ctpsa_sets_r!(t::Ptr{CTPSA{Desc}}, n::Cint, s::Cstring, a_re::Cdouble, a_im::Cdouble, b_re::Cdouble, b_im::Cdouble)
@ccall MAD_TPSA.mad_ctpsa_sets_r(t::Ptr{CTPSA{Desc}}, n::Cint, s::Cstring, a_re::Cdouble, a_im::Cdouble, b_re::Cdouble, b_im::Cdouble)::Cvoid
end

Expand Down Expand Up @@ -943,7 +932,7 @@ end
- `v`
"""
function mad_ctpsa_setv!(t::Ptr{CTPSA{Desc}}, i::Cint, n::Cint, v::Ptr{ComplexF64})
@ccall MAD_TPSA.mad_ctpsa_setv(t::Ptr{CTPSA{Desc}}, i::Cint, n::Cint, v::PtrComplexF64})::Cvoid
@ccall MAD_TPSA.mad_ctpsa_setv(t::Ptr{CTPSA{Desc}}, i::Cint, n::Cint, v::Ptr{ComplexF64})::Cvoid
end


Expand Down
39 changes: 3 additions & 36 deletions src/Descriptor.jl
Original file line number Diff line number Diff line change
@@ -1,41 +1,8 @@
# TPSA Structures Module implementation
module Descriptor
export Desc, new

struct Desc{T,C}
id::Cint # index in list of registered descriptors
nn::Cint # nn = nv+np <= 100000
nv::Cint # nv = number of variables
np::Cint # np = number of parameters
mo::Cuchar # max orders of vars
po::Cuchar # max orders of params
to::Cuchar # global order of truncation. Note ord_t in mad_tpsa is typedef for unsigned char (Cuchar)
no::Ptr{Cuchar} # orders of each vars and params, no[nn]. In C this is const

uno::Cint # user provided no
nth::Cint # max #threads or 1
nc::Cuint # number of coefs (max length of TPSA)

monos::Ptr{Cuchar} # 'matrix' storing the monomials (sorted by var)
ords::Ptr{Cuchar} # Order of each mono of To
To::Ptr{Ptr{Cuchar}} # Table by orders -- pointers to monos, sorted by order
Tv::Ptr{Ptr{Cuchar}} # Table by vars -- pointers to monos, sorted by vars
ocs::Ptr{Ptr{Cuchar}} # ocs[t,i] -> o; in mul, compute o on thread t; 3 <= o <= mo; terminated with 0

ord2idx::Ptr{Cint} # order to polynomial start index in To (i.e. in TPSA coef[])
tv2to::Ptr{Cint} # lookup tv->to
to2tv::Ptr{Cint} # lookup to->tv
H::Ptr{Cint} # indexing matrix in Tv
L::Ptr{Ptr{Cint}} # multiplication indexes L[oa,ob]->L_ord; L_ord[ia,ib]->ic
L_idx::Ptr{Ptr{Ptr{Cint}}} # L_idx[oa,ob]->[start] [split] [end] idxs in L

size::Culonglong # bytes used by desc. Unsigned Long Int, ikn 32 bit system is int32 but 64 bit int64. Using Culonglong assuming 64 bit

t::Ptr{Ptr{T}} # tmp for tpsa
ct::Ptr{Ptr{C}} # tmp for ctpsa
ti::Ptr{Cint} # idx of tmp ised
cti::Ptr{Cint} # idx of tmp used
end
include("Structs.jl")
using .Structs


"""
mad_desc_newv(nv::Cint, mo::Cuchar)::Ptr{Desc{RTPSA,CTPSA}}
Expand Down
3 changes: 2 additions & 1 deletion src/Monomial.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module Monomial

include("Structs.jl")
using .Structs

"""
mad_mono_str(n::Cint, a::Ptr{Cuchar}, s::Cstring)::Cint
Expand Down
27 changes: 8 additions & 19 deletions src/RealTPSA.jl
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
module RealTPSA
export RTPSA
const NAMSZ::Int = 16

mutable struct RTPSA{T}
d::Ptr{T} # Ptr to tpsa descriptor
uid::Cint # Special user field for external use (and padding)
mo::Cuchar # max ord (allocated)
lo::Cuchar # lowest used ord
hi::Cuchar # highest used ord
nz::Culonglong # zero/nonzero homogenous polynomials. Int64 if 64 bit else 32 bit
nam::NTuple{NAMSZ,Cuchar} # tpsa name max string length 16 NAMSZ
coef::Ptr{Cdouble} # warning: must be identical to ctpsa up to coef excluded
end
include("Structs.jl")
using .Structs


"""
Expand Down Expand Up @@ -113,7 +102,7 @@ end
- `ret` -- Monomials in RTPSA
"""
function mad_tpsa_len(t::Ptr{RTPSA{Desc}})::Cint
ret = @ccall MAD_TPSA.mad_tpsa_len(t::Ptr{RTPSA,CTPSA})::Cint
ret = @ccall MAD_TPSA.mad_tpsa_len(t::Ptr{RTPSA{Desc}})::Cint
return ret
end

Expand Down Expand Up @@ -152,7 +141,7 @@ function mad_tpsa_ord(t::Ptr{RTPSA{Desc}})::Cuchar
end

"""
mad_tpsa_ordv(t::Ptr{RTPSA{Desc}}, ts::Ptr{RTPSA{Desc}}...)::Cuchar
mad_tpsa_ordv(t::Ptr{RTPSA{Desc}}, ts::Vector{Ptr{RTPSA{Desc}}}...)::Cuchar
???
Expand All @@ -163,10 +152,10 @@ end
### Output
- `mo` -- Order
"""
function mad_tpsa_ordv(t::Ptr{RTPSA{Desc}}, ts::Ptr{RTPSA{Desc}}...)::Cuchar
mo = @ccall MAD_TPSA.mad_tpsa_ordv(t::Ptr{RTPSA{Desc}}, ts::Ptr{RTPSA{Desc}}..., 0::Cint)::Cuchar # null pointer after args for safe use
return mo
end
#function mad_tpsa_ordv(t::Ptr{RTPSA{Desc}}, ts::Vector{Ptr{RTPSA{Desc}}}...)::Cuchar
# mo = @ccall MAD_TPSA.mad_tpsa_ordv(t::Ptr{RTPSA{Desc}}, ts::Vector{Ptr{RTPSA{Desc}}}..., 0::Cint)::Cuchar # null pointer after args for safe use
# return mo
#end


"""
Expand Down
62 changes: 62 additions & 0 deletions src/Structs.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
module Structs
export RTPSA, CTPSA, Desc
const NAMSZ::Int = 16

mutable struct RTPSA{T}
d::Ptr{T} # Ptr to tpsa descriptor
uid::Cint # Special user field for external use (and padding)
mo::Cuchar # max ord (allocated)
lo::Cuchar # lowest used ord
hi::Cuchar # highest used ord
nz::Culonglong # zero/nonzero homogenous polynomials. Int64 if 64 bit else 32 bit
nam::NTuple{NAMSZ,Cuchar} # tpsa name max string length 16 NAMSZ
coef::Ptr{Cdouble} # warning: must be identical to ctpsa up to coef excluded
end

mutable struct CTPSA{T}
d::Ptr{T} # Ptr to ctpsa descriptor
uid::Cint # Special user field for external use (and padding)
mo::Cuchar # max ord (allocated)
lo::Cuchar # lowest used ord
hi::Cuchar # highest used ord
nz::Culonglong # zero/nonzero homogenous polynomials. Int64 if 64 bit else 32 bit
nam::NTuple{NAMSZ,Cuchar} # tpsa name
coef::Ptr{ComplexF64} # warning: must be identical to ctpsa up to coef excluded
end

struct Desc{T,C}
id::Cint # index in list of registered descriptors
nn::Cint # nn = nv+np <= 100000
nv::Cint # nv = number of variables
np::Cint # np = number of parameters
mo::Cuchar # max orders of vars
po::Cuchar # max orders of params
to::Cuchar # global order of truncation. Note ord_t in mad_tpsa is typedef for unsigned char (Cuchar)
no::Ptr{Cuchar} # orders of each vars and params, no[nn]. In C this is const

uno::Cint # user provided no
nth::Cint # max #threads or 1
nc::Cuint # number of coefs (max length of TPSA)

monos::Ptr{Cuchar} # 'matrix' storing the monomials (sorted by var)
ords::Ptr{Cuchar} # Order of each mono of To
To::Ptr{Ptr{Cuchar}} # Table by orders -- pointers to monos, sorted by order
Tv::Ptr{Ptr{Cuchar}} # Table by vars -- pointers to monos, sorted by vars
ocs::Ptr{Ptr{Cuchar}} # ocs[t,i] -> o; in mul, compute o on thread t; 3 <= o <= mo; terminated with 0

ord2idx::Ptr{Cint} # order to polynomial start index in To (i.e. in TPSA coef[])
tv2to::Ptr{Cint} # lookup tv->to
to2tv::Ptr{Cint} # lookup to->tv
H::Ptr{Cint} # indexing matrix in Tv
L::Ptr{Ptr{Cint}} # multiplication indexes L[oa,ob]->L_ord; L_ord[ia,ib]->ic
L_idx::Ptr{Ptr{Ptr{Cint}}} # L_idx[oa,ob]->[start] [split] [end] idxs in L

size::Culonglong # bytes used by desc. Unsigned Long Int, ikn 32 bit system is int32 but 64 bit int64. Using Culonglong assuming 64 bit

t::Ptr{Ptr{T}} # tmp for tpsa
ct::Ptr{Ptr{C}} # tmp for ctpsa
ti::Ptr{Cint} # idx of tmp ised
cti::Ptr{Cint} # idx of tmp used
end

end
Loading

0 comments on commit 9342f29

Please sign in to comment.