generated from JuliaSmoothOptimizers/JSOTemplate.jl
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add structure to define default parameters
- Loading branch information
Showing
3 changed files
with
53 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
export DefaultParameter | ||
|
||
""" | ||
DefaultParameter{Dflt} | ||
Structure used to simplify declaring default parameters in solvers and docstrings. | ||
- `default::Dflt`: is the default value, it can be a Number, a Symbol or even a function. | ||
- `str::String`: message to be printed or used in docstrings. | ||
Constructors | ||
DefaultParameter(default) | ||
DefaultParameter(default, str) | ||
""" | ||
struct DefaultParameter{Dflt} | ||
default::Dflt | ||
str::String | ||
end | ||
DefaultParameter(default) = DefaultParameter(default, string(default)) | ||
|
||
function Base.show(io::IO, default_parameter::DefaultParameter) # Use this instead of [2] | ||
return print(io, default_parameter.str) | ||
end | ||
|
||
function Base.get(default_parameter::DefaultParameter, args...) | ||
default_parameter.default(args...) | ||
end | ||
function Base.get(default_parameter::DefaultParameter{<:Union{Number,Symbol}}, args...) | ||
default_parameter.default | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters