Skip to content

Commit

Permalink
Added generic global constant getter/setter
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsignorelli committed Mar 1, 2024
1 parent 62a8d05 commit f0cbc77
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/GTPSA.jl
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ export
translate,
par,
scalar,
setGTPSA!,
getGTPSA,

# Temporaries:
@FastGTPSA,
Expand Down Expand Up @@ -166,6 +168,42 @@ show_eps::Float64 = 0.0 # Print epsilon
show_sparse::Bool = false # Use sparse monomial print
show_header::Bool = false # Print a header above each TPS

"""
setGTPSA!(a::AbstractString, val)
Function to set global variables in GTPSA. Options for `a` are:
- `desc_current::Descriptor` -- defines the `Descriptor` to use when that information is not explicitly (or implicitly in a TPS copy constructor) available, e.g. when calling `TPS(a)` where `a` is not a TPS. This is set each time a new `Descriptor` is defined
- `show_eps::Float64` -- defines the value below which the absolute value of a monomial coefficient is NOT printed
- `show_sparse::Bool` -- specifies whether the sparse monomial format is used for printing. This is useful for GTPSAs containing a large number of variables and parameters
- `show_header::Bool` -- specifies whether or not to print the GTPSA `Descriptor` information above each TPS output
"""
function setGTPSA!(a::AbstractString, val)
a == "desc_current" && (GTPSA.desc_current = val; return)
a == "show_eps" && (GTPSA.show_eps = val; return)
a == "show_sparse" && (GTPSA.show_sparse = val; return)
a == "show_header" && (GTPSA.show_header = val; return)
error("Global variable \"$(a)\" does not exist!")
end

"""
setGTPSA!(a::AbstractString, val)
Function to set global variables in GTPSA. Options for `a` are:
- `desc_current::Descriptor` -- defines the `Descriptor` to use when that information is not explicitly (or implicitly in a TPS copy constructor) available, e.g. when calling `TPS(a)` where `a` is not a TPS. This is set each time a new `Descriptor` is defined
- `show_eps::Float64` -- defines the value below which the absolute value of a monomial coefficient is NOT printed
- `show_sparse::Bool` -- specifies whether the sparse monomial format is used for printing. This is useful for GTPSAs containing a large number of variables and parameters
- `show_header::Bool` -- specifies whether or not to print the GTPSA `Descriptor` information above each TPS output
"""
function getGTPSA(a::AbstractString)
a == "desc_current" && (return GTPSA.desc_current)
a == "show_eps" && (return GTPSA.show_eps)
a == "show_sparse" && (return GTPSA.show_sparse)
a == "show_header" && (return GTPSA.show_header)
error("Global variable \"$(a)\" does not exist!")
end

# Descriptor outer constructors
"""
Descriptor(nv::Integer, vo::Integer)::Descriptor
Expand Down
1 change: 1 addition & 0 deletions src/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ end
function show(io::IO, d::Descriptor)
println(io, "GTPSA Descriptor")
println(io, "-----------------------")
d.desc == C_NULL && (println(io, "Null"); return)
desc = unsafe_load(d.desc)
show_GTPSA_info(io, desc)
end
Expand Down

0 comments on commit f0cbc77

Please sign in to comment.