From 86c91239a0b43af8449a7843c18ec0d274d846d0 Mon Sep 17 00:00:00 2001 From: Matt Signorelli Date: Wed, 22 Jan 2025 16:02:08 -0500 Subject: [PATCH] docs update --- docs/src/index.md | 33 ++++++++++++--- ext/TPSAInterfaceGTPSAExt.jl | 14 ++++++- src/TPSAInterface.jl | 80 ++++++++++++++++++++++++++++-------- 3 files changed, 103 insertions(+), 24 deletions(-) diff --git a/docs/src/index.md b/docs/src/index.md index 10ddba6..b2340f5 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -6,9 +6,32 @@ CurrentModule = TPSAInterface Documentation for [TPSAInterface](https://github.com/bmad-sim/TPSAInterface.jl). -```@index -``` +```@docs -```@autodocs -Modules = [TPSAInterface] -``` +TPSAInterface.is_tps +TPSAInterface.is_tps_type +TPSAInterface.numtype +TPSAInterface.nvars +TPSAInterface.nparams +TPSAInterface.ndiffs +TPSAInterface.maxord +TPSAInterface.numcoefs +TPSAInterface.scalar +TPSAInterface.norm_tps +TPSAInterface.clear! +TPSAInterface.geti +TPSAInterface.getm +TPSAInterface.seti! +TPSAInterface.setm! +TPSAInterface.copy! +TPSAInterface.add! +TPSAInterface.sub! +TPSAInterface.mul! +TPSAInterface.div! +TPSAInterface.pow! +TPSAInterface.getord! +TPSAInterface.cutord! +TPSAInterface.deriv! +TPSAInterface.inv! +TPSAInterface.compose! +``` \ No newline at end of file diff --git a/ext/TPSAInterfaceGTPSAExt.jl b/ext/TPSAInterfaceGTPSAExt.jl index ff59c1e..3e1dc73 100644 --- a/ext/TPSAInterfaceGTPSAExt.jl +++ b/ext/TPSAInterfaceGTPSAExt.jl @@ -47,8 +47,8 @@ TI.mul!(t::TPS, a, b) = (GTPSA.mul!(t, a, b); return t) TI.div!(t::TPS, a, b) = (GTPSA.div!(t, a, b); return t) TI.pow!(t::TPS, a, b) = (GTPSA.pow!(t, a, b); return t) -TI.getord!(t::TPS, t1::TPS, order) = GTPSA.getord!(t, t1, order) -TI.cutord!(t::TPS, t1::TPS, order) = GTPSA.cutord!(t, t1, order) +TI.getord!(t::TPS, t1::TPS, ord) = GTPSA.getord!(t, t1, ord) +TI.cutord!(t::TPS, t1::TPS, ord) = GTPSA.cutord!(t, t1, ord) TI.deriv!(t::TPS, t1::TPS, i) = GTPSA.deriv!(t, t1, i) @@ -67,4 +67,14 @@ function TI.compose!( return GTPSA.compose!(m, m2, m1) end +TI.fgrad!(g::TPS{T}, F::AbstractArray{TPS{T,D}}, h::TPS{T}) where {T,D} = GTPSA.fgrad!(g, F, h) +TI.liebra!( + G::AbstractArray{TPS{T,DG}}, + F::AbstractArray{TPS{T,DF}}, + H::AbstractArray{TPS{T,DH}} +) where {T,DG,DF,DH} + @assert !(G === F) && !(G === H) "Aliasing any source arguments with the destination in lb! is not allowed" + return GTPSA.liebra!(numvars(F), F, H, G) +end + end \ No newline at end of file diff --git a/src/TPSAInterface.jl b/src/TPSAInterface.jl index b145570..7ee8a35 100644 --- a/src/TPSAInterface.jl +++ b/src/TPSAInterface.jl @@ -10,31 +10,66 @@ abstract type TPSTypeBehavior end struct IsTPSType <: TPSTypeBehavior end struct IsNotTPSType <: TPSTypeBehavior end +"Returns `TPSAInterface.IsTPS() if `t` is a TPS, else `TPSAInterface.IsNotTPS()." is_tps(t) = IsNotTPS() +"Returns `TPSAInterface.IsTPSType() if `t` is a TPS type, else `TPSAInterface.IsNotTPSType()." is_tps_type(t) = IsNotTPSType() -# Returns number type of monomial coefficients +"Returns the number type of the monomial coefficients of the TPS. `t` may be a TPS or TPS `Type`." numtype(t::Number) = typeof(t) numtype(::Type{T}) where {T<:Number} = T -nvars(t) = 0 # Returns number of variables in TPSA -nparams(t) = 0 # Returns number of parameters in TPSA -ndiffs(t) = 0 # Returns number of variables + number of parameters in TPSA -maxord(t) = 0 # Returns the maximum truncation order of the TPSA -numcoefs(t) = 1 # Returns the number of coefficients in the TPSA (1 for regular numbers) +"Returns the number of variables in the TPSA. `t` may be a TPS or TPS `Type`." +nvars(t) = 0 +"Returns the number of parameters in the TPSA. `t` may be a TPS or TPS `Type`." +nparams(t) = 0 +"Returns the number of variables + parameters in the TPSA. `t` may be a TPS or TPS `Type`." +ndiffs(t) = 0 +"Returns the maximum truncation order of the TPSA. `t` may be a TPS or TPS `Type`." +maxord(t) = 0 +"Returns the number of monomial coefficients in the TPSA. `t` may be a TPS or TPS `Type`." +numcoefs(t) = 1 -scalar(t::Number) = t # Returns the zeroth order (scalar) part of a passed TPS -norm_tps(t::Number) = norm(t) # Returns a TPS norm including all monomial coefficients +"Returns the zeroth order (scalar) part of the TPS `t`." +scalar(t::Number) = t -clear!(t) = error("Not implemented!") # Clears the TPS +"Returns a norm of the passed TPS `t` including all monomial coefficients." +norm_tps(t::Number) = norm(t) -# Get/set monomials in the TPS t -geti(t, i::Integer) = error("Not implemented!") # 0-based indexing for TPS so that i=0 is scalar part -getm(t, mono::AbstractArray{<:Integer}) = error("Not implemented!") # Monomial as array of orders +"Sets all monomial coefficients in `t` equal to 0." +clear!(t) = error("Not implemented!") + +""" + geti(t, i::Integer) + +Gets the `i`-th monomial coefficient in the TPS `t`, where `i=0` specifies the +scalar part, and the monomials are sorted by order. +""" +geti(t, i::Integer) = error("Not implemented!") + +""" + getm(t, mono::AbstractArray{<:Integer}) + +Gets the coefficient of the monomial with orders `mono`. +""" +getm(t, mono::AbstractArray{<:Integer}) = error("Not implemented!") + +""" + seti!(t, v, i::Integer) + +Sets the `i`-th monomial coefficient in the TPS `t` to `v`, where `i=0` specifies the +scalar part, and the monomials are sorted by order. +""" seti!(t, v, i::Integer) = error("Not implemented!") + +""" + setm!(t, v, mono::AbstractArray{<:Integer}) + +Sets the coefficient of the monomial with orders `mono` to `v`. +""" setm!(t, v, mono::AbstractArray{<:Integer}) = error("Not implemented!") -# Sets the entire TPS t equal to t1 (where t1 is a TPS or a Number) +"Sets the entire TPS `t` equal to `t1`, where `t1` may be another TPS or a `Number`." copy!(t, t1) = error("Not implemented!") # Arithmetic operators @@ -44,20 +79,31 @@ mul!(t, a, b) = error("Not implemented!") div!(t, a, b) = error("Not implemented!") pow!(t, a, b) = error("Not implemented!") -getord!(t, t1, order) = error("Not implemented!") # Get order as TPS -cutord!(t, t1, order) = error("Not implemented!") # Cuts order from TPS +"Sets `t` equal to the homogenous polynomial of order `ord` in `t1`." +getord!(t, t1, ord) = error("Not implemented!") + +"Sets `t` equal to `t1` with monomials at order `ord` and above removed. Or, if `ord` +is negative, will remove monomials with orders at and below `abs(ord)`." +cutord!(t, t1, ord) = error("Not implemented!") # Defaults for out of place: -getord(t1, order) = (t = zero(t1); getord!(t, t1, order); return t) -cutord(t1, order) = (t = zero(t1); cutord!(t, t1, order); return t) +getord(t1, ord) = (t = zero(t1); getord!(t, t1, ord); return t) +cutord(t1, ord) = (t = zero(t1); cutord!(t, t1, ord); return t) # Derivative wrt the i-th differential +"Sets `t` equal to the derivative of `t1` with respect to the `i`-th differential." deriv!(t, t1, i) = error("Not implemented!") # Inverts the map m1 and puts the result into m +"Sets the map `m` equal to the inverse of the map `m1`, ignoring any scalar part." inv!(m, m1) = error("Not implemented!") # Composes the TPS or vector of TPSs m2 ∘ m1 and puts the result into m +"Sets `m` equal to `m2 ∘ m1` where `m1` and/or `m2` may be TPS types or arrays of TPS types." compose!(m, m2, m1) = error("Not implemented!") +# TO-DO: implement defaults of these (maybe in NNF) +fgrad!(g, F, h) = error("Not implemented!") # computes F dot grad h +liebra!(G, F, H) = error("Not implemented!") # Computes Lie bracket for Hamiltonian vector fields + end