Skip to content

Symbolic indexing of vectors of pairs - #1142

Closed
lamorton wants to merge 3 commits into
SciML:masterfrom
lamorton:patch-4
Closed

lamorton wants to merge 3 commits into
SciML:masterfrom
lamorton:patch-4

Conversation

@lamorton

Copy link
Copy Markdown
Contributor

This is a hack that lets you do things like ps[E] where E is a parameter and ps is a vector of pairs mapping parameters to values.

This is a hack that lets you do things like `ps[E]` where `E` is a parameter and `ps` is a vector of pairs mapping parameters to values.
@lamorton
lamorton marked this pull request as draft July 23, 2021 20:27
…flict with symbolic access to `ODESolution`.
@lamorton
lamorton marked this pull request as ready for review July 23, 2021 21:00
Comment thread docs/src/basics/FAQ.md
```
Further, you can support symbolic lookup/update of parameter values using:
```julia
Base.getindex(A::AbstractArray{Pair{S,T}},sym::S) where {T,S<:Union{Num,Symbol}} = A[findfirst(x->isequal(sym,x.first),A)].second

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we want to be telling people to do this 😅

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's poor form for sure. Maybe do something like get(ps,sym) &put(ps,sym,x) instead?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or just make a Dict?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that'd be preferable. I feel like there was some reason I wasn't doing that, but maybe it was only #1101 (can't remake with Dict) which is common to vector{pair} anyway (#472).

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.

2 participants