Skip to content

Add easy possibility to create array of variables - #153

Merged
ChrisRackauckas merged 2 commits into
SciML:masterfrom
saschatimme:st/variable-arrays
Jul 27, 2019
Merged

ChrisRackauckas merged 2 commits into
SciML:masterfrom
saschatimme:st/variable-arrays

Conversation

@saschatimme

@saschatimme saschatimme commented Jul 26, 2019 •

Copy link
Copy Markdown
Contributor

This extends the variable / parameter generation macro to allow easy creation of arrays of variables. Closes #102.

Examples:

julia> @variables x[1:3];
julia> x
3-element Array{Operation,1}:
 x[1]()
 x[2]()
 x[3]()

# support for arbitrary ranges and tensors

julia> @variables y[1:3,1:5:10,1:4];

julia> y
3×2×4 Array{Operation,3}:
[:, :, 1] =
 y[1,1,1]()  y[1,6,1]()
 y[2,1,1]()  y[2,6,1]()
 y[3,1,1]()  y[3,6,1]()

[:, :, 2] =
 y[1,1,2]()  y[1,6,2]()
 y[2,1,2]()  y[2,6,2]()
 y[3,1,2]()  y[3,6,2]()

[:, :, 3] =
 y[1,1,3]()  y[1,6,3]()
 y[2,1,3]()  y[2,6,3]()
 y[3,1,3]()  y[3,6,3]()

[:, :, 4] =
 y[1,1,4]()  y[1,6,4]()
 y[2,1,4]()  y[2,6,4]()
 y[3,1,4]()  y[3,6,4]()

# also works for dependent variables
julia> @parameters t; @variables z[1:3](t);
julia> z
3-element Array{Operation,1}:
 z[1](t())
 z[2](t())
 z[3](t())

If the design is accepted, I will add some documentation to the readme :)

ToDo:

  • Documentation

@codecov

codecov Bot commented Jul 26, 2019 •

Copy link
Copy Markdown

Codecov Report

Merging #153 into master will increase coverage by 0.26%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #153      +/-   ##
==========================================
+ Coverage   94.75%   95.01%   +0.26%     
==========================================
  Files          11       11              
  Lines         381      401      +20     
==========================================
+ Hits          361      381      +20     
  Misses         20       20
Impacted Files Coverage Δ
src/variables.jl 94.54% <100%> (+3.11%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 93fe6bd...769e724. Read the comment docs.

@ChrisRackauckas

Copy link
Copy Markdown
Member

This looks great to me. Docs?

@saschatimme

Copy link
Copy Markdown
Contributor Author

Added the docs. Let me know if something could be improved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow arrays of variables

2 participants