Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data Structure Overhaul #58

Merged
merged 125 commits into from
Sep 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
125 commits
Select commit Hold shift + click to select a range
cf9ed02
Initial new data structure setup
pulsipher Apr 13, 2020
deb07cd
minor update
pulsipher Apr 13, 2020
864aa36
Added parameter object tracking
pulsipher Apr 15, 2020
1f8fb94
Restructured variable files
pulsipher Apr 16, 2020
9a0cc83
infinite_set change
wzhangw Apr 16, 2020
12064fa
Merge branch 'data-struct-overhall' of https://github.com/pulsipher/I…
wzhangw Apr 16, 2020
0b5bd3c
parameter_changes
pulsipher Apr 16, 2020
7f5e82b
Updated infinite set methods and dependent parameter creation
pulsipher Apr 18, 2020
6693565
build_independent_parameter in progress
wzhangw Apr 18, 2020
d40292b
Merge branch 'data-struct-overhall' of https://github.com/pulsipher/I…
wzhangw Apr 18, 2020
b25dae4
update add_parameter
wzhangw Apr 18, 2020
b0edbb0
made @dependent_parameters
pulsipher Apr 19, 2020
2751b12
fix tests
wzhangw Apr 20, 2020
aa766cc
modify docstrings
wzhangw Apr 20, 2020
ab1160b
query function changes
wzhangw Apr 20, 2020
f9d0931
Merge branch 'data-struct-overhall' of https://github.com/pulsipher/I…
wzhangw Apr 20, 2020
682d159
macro changes
wzhangw Apr 20, 2020
5c5c65c
minor updates
pulsipher Apr 20, 2020
6217bf1
Merge branch 'data-struct-overhall' of https://github.com/pulsipher/I…
pulsipher Apr 20, 2020
fab0341
Minor function fixes
pulsipher Apr 20, 2020
b6bb006
@independent_parameter minor fixes
wzhangw Apr 20, 2020
a760322
Completed dependent parameter definition
pulsipher Apr 21, 2020
ccce20f
Merge branch 'data-struct-overhall' of https://github.com/pulsipher/I…
pulsipher Apr 21, 2020
a54d03b
start @finite_parameter
wzhangw Apr 21, 2020
607d166
Merge branch 'data-struct-overhall' of https://github.com/pulsipher/I…
wzhangw Apr 21, 2020
1e9b15f
@infinite_parameter done and minor scalar param fixes
pulsipher Apr 21, 2020
54e3eb7
Merge branch 'data-struct-overhall' of https://github.com/pulsipher/I…
wzhangw Apr 21, 2020
4454e96
More progress on the dependent parameter methods.
pulsipher Apr 22, 2020
864572b
More tests and bug fixes
pulsipher Apr 23, 2020
4249cd8
added more tests
pulsipher Apr 23, 2020
b09cd51
@independent_parameter and @finite_parameter tests
wzhangw Apr 23, 2020
4ebe02b
Merge branch 'data-struct-overhall' of https://github.com/pulsipher/I…
wzhangw Apr 23, 2020
ca3fa76
finishing most scalar_parameter functions tests
wzhangw Apr 24, 2020
502683e
generate_support_value keyword fix
wzhangw Apr 24, 2020
f27e213
Progress on variables, constraints, printing, and more.
pulsipher Apr 26, 2020
7285663
Merge branch 'data-struct-overhall' of https://github.com/pulsipher/I…
pulsipher Apr 26, 2020
545b2ed
Parameter fixes
pulsipher Apr 27, 2020
2465e9a
finish parameter functions and add fallback tests
wzhangw Apr 28, 2020
04ef589
Variable, constraint, objective, printing progress.
pulsipher Apr 29, 2020
46b9fe6
Merge branch 'data-struct-overhall' of https://github.com/pulsipher/I…
pulsipher Apr 29, 2020
9894fba
Reworked parameter queries and updated printing
pulsipher Apr 29, 2020
88d0a3e
Variable progress and preped measures for rebuild
pulsipher May 1, 2020
507bf1a
Added point variable test, plus minor bugs fixes
pulsipher May 2, 2020
fbe3193
Resolved sig_figs, support uniqueness, and added more tests
pulsipher May 5, 2020
dbcdf9a
initial measure work
wzhangw May 5, 2020
7ebbe54
Merge branch 'data-struct-overhall' of https://github.com/pulsipher/I…
wzhangw May 5, 2020
9e8985d
Added many more tests and fixed bugs along the way
pulsipher May 6, 2020
e10d936
measure work
wzhangw May 6, 2020
723f33c
Merge branch 'data-struct-overhall' of https://github.com/pulsipher/I…
wzhangw May 6, 2020
a1de0ab
Added more tests
pulsipher May 7, 2020
c06149b
finish functions relevant to measure function
wzhangw May 8, 2020
63c1a12
Merge branch 'data-struct-overhall' of https://github.com/pulsipher/I…
wzhangw May 8, 2020
de25352
Reworked distribution printing, progress on docs and measure expansion
pulsipher May 8, 2020
323d2e7
Updated measure expansion
pulsipher May 10, 2020
49125d3
measure tests work
wzhangw May 10, 2020
bf0aa85
Merge branch 'data-struct-overhall' of https://github.com/pulsipher/I…
wzhangw May 10, 2020
bd8da94
more measure tests
wzhangw May 10, 2020
32e0f80
more measure tests
wzhangw May 11, 2020
522fecd
measure macro with tests
wzhangw May 11, 2020
e62864b
Safe attribute retrieval and progress on new TranscriptionOpt
pulsipher May 14, 2020
3992eb5
finish measure
wzhangw May 14, 2020
7f616e5
Merge branch 'data-struct-overhall' of https://github.com/pulsipher/I…
wzhangw May 14, 2020
4c2784a
Updated measures
pulsipher May 15, 2020
c543b01
Added measure printing and fixed some minor bugs.
pulsipher May 17, 2020
b986f6e
complete functions in integral.jl
wzhangw May 17, 2020
d057c6f
minor fixes
wzhangw May 17, 2020
6fe79e0
Updated user measure methods and printing
pulsipher May 19, 2020
64a891a
Finished draft of TranscriptionOpt and minor bug fixes
pulsipher May 20, 2020
8e69345
Finalized programmatic draft and doc strings
pulsipher May 20, 2020
9083799
Added expression result queries and improved parameter_refs
pulsipher May 21, 2020
0b486f5
minor revisions
pulsipher May 21, 2020
670f218
measure tests in progress
wzhangw May 22, 2020
19b4553
Finalized new infinite start value functions and improved general vars
pulsipher May 22, 2020
93fb34a
Merge branch 'data-struct-overhall' of https://github.com/pulsipher/I…
wzhangw May 22, 2020
f7b9811
tests for measure and MeasureToolbox
wzhangw May 23, 2020
db32ce6
add generate_support_values for label All & finish measure tests
wzhangw May 23, 2020
4328adf
Resolved internal Julia errors
pulsipher May 24, 2020
aeae203
Merge branch 'data-struct-overhall' of https://github.com/pulsipher/I…
pulsipher May 24, 2020
e85be2b
test measure deletion
wzhangw May 25, 2020
40fb327
fill measure test coverage
wzhangw May 25, 2020
514fcf3
add parameter docs
wzhangw May 31, 2020
da902b3
Finalized deletion and resolved minor bugs
pulsipher Jun 4, 2020
7917fc9
Finalized measure expansions
pulsipher Jun 17, 2020
d6520bc
More efficient variable naming
pulsipher Jun 23, 2020
7abce73
Added basic TranscriptionOpt tests and fixed minor bugs.
pulsipher Aug 6, 2020
f05309b
32bit test revisions
pulsipher Aug 18, 2020
ab4da17
Added more tests
pulsipher Aug 20, 2020
0e0d5c8
Merge branch 'data-struct-overhall' of https://github.com/pulsipher/I…
wzhangw Aug 24, 2020
7f7b655
Added more tests
wzhangw Aug 25, 2020
4037313
Added full set of transcriptionopt tests
pulsipher Sep 9, 2020
eef96d3
Minor test fixes
pulsipher Sep 10, 2020
6e0f7ce
Added optimizer tests
pulsipher Sep 10, 2020
5b69e80
Added results tests
pulsipher Sep 10, 2020
0e8b2de
Minor measure expansion fixes
pulsipher Sep 11, 2020
5188108
Minor coverage patch
pulsipher Sep 11, 2020
acf398e
add tests for nan check in is_analytic
wzhangw Sep 11, 2020
0777193
update infinite set extensions
wzhangw Sep 11, 2020
ae33424
Added optimizer model extension info
pulsipher Sep 11, 2020
f76cb68
update measure data extensions
wzhangw Sep 11, 2020
4c36a54
Merge branch 'data-struct-overhall' of https://github.com/pulsipher/I…
wzhangw Sep 11, 2020
6444b1b
Started Doc Fixes
pulsipher Sep 11, 2020
db90e27
update measure_eval extensions
wzhangw Sep 11, 2020
565ab43
Merge branch 'data-struct-overhall' of https://github.com/pulsipher/I…
wzhangw Sep 11, 2020
2f8bf4e
Added more docs
pulsipher Sep 11, 2020
845e93f
Fixed breaking changes with JuMP 0.21.4
pulsipher Sep 14, 2020
8c15f2c
Fix extension bug for Julia 1.0
wzhangw Sep 14, 2020
8a25598
Merge branch 'data-struct-overhall' of https://github.com/pulsipher/I…
wzhangw Sep 14, 2020
cb6fcde
Minor MOI version fix
pulsipher Sep 14, 2020
5880bf9
Merge branch 'data-struct-overhall' of https://github.com/pulsipher/I…
pulsipher Sep 14, 2020
360e210
add set and parameter docs
wzhangw Sep 14, 2020
65f1f5f
Merge branch 'data-struct-overhall' of https://github.com/pulsipher/I…
wzhangw Sep 14, 2020
7ebbc8d
Added JuMP 0.21.4 features
pulsipher Sep 15, 2020
d074202
Finish sets docs
wzhangw Sep 15, 2020
87444a3
Merge branch 'data-struct-overhall' of https://github.com/pulsipher/I…
wzhangw Sep 15, 2020
30f8dae
fix sets and parameter docs
wzhangw Sep 15, 2020
37f2a86
More docs and bug fixes
pulsipher Sep 16, 2020
1f76e64
Fixed macro errors and docs errors
pulsipher Sep 16, 2020
ef6324e
Add measure and extension docs
wzhangw Sep 16, 2020
92c79dc
Merge branch 'data-struct-overhall' of https://github.com/pulsipher/I…
wzhangw Sep 16, 2020
da92acf
finish measure and set extension text
wzhangw Sep 16, 2020
975cfd4
fix measure and set extension doc errors
wzhangw Sep 16, 2020
ceaad9c
minor doc updates
pulsipher Sep 17, 2020
7869997
Merge branch 'data-struct-overhall' of https://github.com/pulsipher/I…
pulsipher Sep 17, 2020
1de8b53
Finalizing edits
pulsipher Sep 17, 2020
e60232b
Minor update to tests
pulsipher Sep 17, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ os:
- linux
julia:
- 1.0
- 1.1
- 1.2
- 1.3
- 1.4
- 1.5
- nightly
notifications:
email: false
Expand All @@ -16,8 +14,8 @@ after_success:
jobs:
include:
- os: osx
julia: 1.4
name: "Julia: 1.4"
julia: 1.5
name: "Julia: 1.5"
# - os: windows
# # arch: x64
# julia: 1.3
Expand Down
15 changes: 7 additions & 8 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
name = "InfiniteOpt"
uuid = "20393b10-9daf-11e9-18c9-8db751c92c57"
authors = ["Joshua Pulsipher and Weiqi Zhang"]
version = "0.1.1"
version = "0.2.0"

[deps]
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
FastGaussQuadrature = "442a2c76-b920-505d-bb47-c5924d526838"
MutableArithmetics = "d8a4904e-b15c-11e9-3269-09a3773c0cb0"
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"

[compat]
julia = "1"
JuMP = "~0.21"
JuMP = "~0.21.4"
FastGaussQuadrature = "^0.3.2, ~0.4"
Distributions = "~0.19, ~0.20, ~0.21, ~0.22, ~0.23"
MathOptInterface = "~0.9.11"
MutableArithmetics = "~0.2"
MathOptInterface = "=0.9.14"
DataStructures = "^0.14.2, ~0.15, ~0.16, ~0.17, ~0.18"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"

[targets]
test = ["Test"]
test = ["Test", "Random"]
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Comments, suggestions and improvements are welcome and appreciated.
following in the package manager.

```julia
(v1.4) pkg> add InfiniteOpt
(v1.5) pkg> add InfiniteOpt
```

## Documentation
Expand All @@ -60,7 +60,7 @@ Please visit our [documentation pages](https://pulsipher.github.io/InfiniteOpt.j
tutorials, examples, and more!

## Project Status
The package is tested against Julia `1.0`, `1.1`, `1.2`, `1.3`, `1.4`, and nightly on Linux, macOS, and Windows.
The package is tested against Julia `1.0`, `1.4`, `1.5`, and nightly on Linux, macOS, and Windows.

## Contributing
`InfiniteOpt` is being actively developed and suggestions or other forms of contribution are encouraged.
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
environment:
matrix:
- julia_version: 1.4
- julia_version: 1.5

platform:
- x86 # 32-bit
Expand Down
3 changes: 2 additions & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
Ipopt = "b6b21f68-93f8-5de0-b562-5493be1d77c9"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"

[compat]
Documenter = "≥ 0.24.2"
Documenter = "~0.25"
15 changes: 15 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Documentation Builds
InfiniteOpt.jl's documentation is written with [Documenter.jl](https://github.com/JuliaDocs/Documenter.jl).
To install it, run the following command in a Julia session:

```julia
julia> ]

(v1.5) pkg> add Documenter
```

Once you have Documenter installed you can build the documentation via:
```julia
julia --project=. --color=yes make.jl
```
The compiled documents can then be viewed at `build/index.html`.
15 changes: 12 additions & 3 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,28 @@ makedocs(;
"Constraints" => "guide/constraint.md",
"Model Transcription" => "guide/transcribe.md",
"Optimization" => "guide/optimize.md",
"Results" => "guide/result.md"],
"Results" => "guide/result.md"
]
,
"Examples" => "examples.md",
"Extensions" => "extensions.md",
"Development" => "develop.md",
"Library" => "library.md",
hide("JuMP Docs" => "JuMP.md")],
hide("JuMP Docs" => "JuMP.md")
],
repo = "https://github.com/pulsipher/InfiniteOpt.jl/blob/{commit}{path}#L{line}",
sitename = "InfiniteOpt.jl",
authors = "Joshua Pulsipher and Weiqi Zhang",
doctest = true,
linkcheck = true
linkcheck = true,
format = Documenter.HTML(
# See https://github.com/JuliaDocs/Documenter.jl/issues/868
prettyurls = get(ENV, "CI", nothing) == "true",
analytics = "UA-178297470-1",
)
)

deploydocs(;
repo = "github.com/pulsipher/InfiniteOpt.jl",
)

104 changes: 104 additions & 0 deletions docs/src/JuMP.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ JuMP.Model()
JuMP.Model(::Any)
JuMP.NoOptimizer
JuMP.optimizer_with_attributes(::Any, ::Pair)
JuMP.direct_model
```

## Variables
Expand Down Expand Up @@ -57,6 +58,12 @@ JuMP.IntegerRef(::JuMP.VariableRef)
JuMP.unset_integer(::JuMP.VariableRef)
```

## Containers
```@docs
JuMP.Containers.SparseAxisArray
JuMP.Containers.DenseAxisArray
```

## Expressions
```@docs
JuMP.@expression
Expand Down Expand Up @@ -113,6 +120,7 @@ JuMP.set_optimizer_attribute(::JuMP.Model, ::MOI.AbstractOptimizerAttribute, ::A
JuMP.set_optimizer_attributes(::JuMP.Model, ::Pair)
JuMP.get_optimizer_attribute(::JuMP.Model, ::String)
JuMP.get_optimizer_attribute(::JuMP.Model, ::MOI.AbstractOptimizerAttribute)
JuMP.set_optimizer(::JuMP.Model, ::Any)
JuMP.result_count(::JuMP.Model)
```

Expand All @@ -136,4 +144,100 @@ JuMP.optimizer_index(::JuMP.VariableRef)
JuMP.optimizer_index(::JuMP.ConstraintRef{JuMP.Model})
JuMP.lp_rhs_perturbation_range(::JuMP.ConstraintRef{JuMP.Model, <:JuMP._MOICON})
JuMP.lp_objective_perturbation_range(::JuMP.VariableRef)
JuMP.reduced_cost(::VariableRef)
```

# JuMP Section References
## Containers in macros
The `container` function encodes the logic for how containers are
constructed in JuMP's macros. The `@container` macro is available to create
containers independently of any JuMP model.
```@docs
JuMP.Containers.container
JuMP.Containers.default_container
JuMP.Containers.VectorizedProductIterator
JuMP.Containers.NestedIterator
JuMP.Containers.@container
```

In the [`@variable`](@ref) (resp. [`@constraint`](@ref)) macro, containers of
variables (resp. constraints) can be created with the following syntax:

* `name[index_set_1, index_set_2, ..., index_set_n]` creating an `n`-dimensional
container of name `name`; or
* `[index_set_1, index_set_2, ..., index_set_n]` creating an *anonymous*
`n`-dimensional container.

Each expression `index_set_i` can either be

* of the form `index_set` specifying that the `i`th index set of the container
is `index_set`; or
* of the form `index_name=index_set` specifying that the `i`th index set of the
container is `index_set` and allowing values used in the macro expression and
keyword arguments to be expressions depending on the `index_name`.

The macro then creates the container using the
[`JuMP.Containers.container`](@ref) function with the following
arguments:

1. A function taking as argument the value of the indices and returning the
value to be stored in the container, e.g. a variable for the
[`@variable`](@ref) macro and a constraint for the [`@constraint`](@ref)
macro.
2. An iterator over the indices of the container.
4. The value of the `container` keyword argument if given.

## Variables constrained on creation
!!! info
When using JuMP in Direct mode, it may be required to constrain
variables on creation instead of constraining free variables as the solver
may only support variables constrained on creation. In Automatic and Manual
modes, both ways of adding constraints on variables are equivalent.
Indeed, during the copy of the cache to the optimizer, the choice of the
constraints on variables that are copied as variables constrained on creation
does not depend on how it was added to the cache.

All uses of the `@variable` macro documented so far translate to a separate
call for variable creation and adding of constraints.

For example, `@variable(model, x >= 0, Int)`, is equivalent to:
```julia
@variable(model, x)
set_lower_bound(x, 0.0)
@constraint(model, x in MOI.Integer())
```
Importantly, the bound and integrality constraints are added _after_ the
variable has been created.

However, some solvers require a constraining set _at creation time_.
We say that these variables are _constrained on creation_.

Use `in` within `@variable` to access the special syntax for constraining
variables on creation. For example, the following creates a vector of variables
constrained on creation to belong to the `SecondOrderCone`:
```julia-repl
julia> @variable(model, y[1:3] in SecondOrderCone())
3-element Array{VariableRef,1}:
y[1]
y[2]
y[3]
```

For contrast, the more standard approach is as follows:
```julia-repl
julia> @variable(model, x[1:3])
3-element Array{VariableRef,1}:
x[1]
x[2]
x[3]

julia> @constraint(model, x in SecondOrderCone())
[x[1], x[2], x[3]] ∈ MathOptInterface.SecondOrderCone(3)
```

The technical difference between the former and the latter is that the former
calls `MOI.add_constrained_variables` while the latter calls `MOI.add_variables`
and then `MOI.add_constraint`. This distinction is important only in
Direct mode, depending on the solver being used. It's often not
possible to delete the `SecondOrderCone` constraint if it was specified
at variable creation time.
Binary file modified docs/src/assets/variable_tree.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 8 additions & 9 deletions docs/src/develop.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ through step by step how this should be done.
computer. This needs to be done via the `dev` command in the package manager
so you can edit it. The syntax is as follows:
```julia
(v1.3) pkg> dev https://github.com/username-here/InfiniteOpt.jl
(v1.5) pkg> dev https://github.com/username-here/InfiniteOpt.jl
```
We also recommend you install [`Revise.jl`](https://github.com/timholy/Revise.jl)
which is very useful when developing packages in Julia.
Expand All @@ -65,7 +65,7 @@ through step by step how this should be done.
8. Create a pull request. Go [here](https://github.com/pulsipher/InfiniteOpt.jl)
to `InfiniteOpt`'s main page and create a pull request drawing from your forked
repository. A step by step explanation is provided
[here](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request-from-a-fork).
[here](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request-from-a-fork).
9. Make necessary changes if the tests fail and/or we ask you to make specific
changes. The Codecov tests will ensure every new line of code is tested at least
once with the new test functions and Travis CI will ensure that the tests pass
Expand Down Expand Up @@ -139,7 +139,7 @@ Here we detail the programmatic style used with `InfiniteOpt`. This is done in a
effort to make this package intuitive for new-comers and to ease development. This
style closely follows that of `JuMP.jl` with similar deviations from typical Julia
styles. Please refer to the `JuMP` style guide
[here](http://www.juliaopt.org/JuMP.jl/stable/style/) as this is the style used
[here](https://jump.dev/JuMP.jl/stable/style/) as this is the style used
by `InfiniteOpt`.

In addition, we adopt the following practices:
Expand Down Expand Up @@ -179,7 +179,7 @@ In addition, we adopt the following practices:
end
```
- All function arguments and struct elements should be typed. Also, function
outputs should be typed where possible unless nothing is returned.
outputs should be typed where possible.
This is bad:
```julia
function my_new_function(arg1, arg2)
Expand All @@ -203,7 +203,7 @@ In addition, we adopt the following practices:
- Type dispatch should be used instead of conditional statements based on type:
This is bad:
```julia
function my_new_function(arg::AbstractType)
function my_new_function(arg::AbstractType)::ReturnType
if arg isa Type1
temp = arg + 1
elseif arg isa Type2
Expand All @@ -217,20 +217,19 @@ In addition, we adopt the following practices:
```julia
## Internal dispatch for my_new_function
# Type1
function _my_internal_function(arg::Type1)
function _my_internal_function(arg::Type1)::Int
return arg + 1
end
# Type2
function _my_internal_function(arg::Type1)
function _my_internal_function(arg::Type1)::Int
return 0
end
# Fallback
function _my_internal_function(arg::AbstractType)
error("Unrecognized type...")
return
end
# Main method
function my_new_function(arg::AbstractType)
function my_new_function(arg::AbstractType)::ReturnType
temp = _my_internal_function(arg)
# do more stuff with temp
return temp
Expand Down
Loading