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

Different modes for different parts of array expression #195

Open
richfitz opened this issue Jul 3, 2020 · 1 comment
Open

Different modes for different parts of array expression #195

richfitz opened this issue Jul 3, 2020 · 1 comment

Comments

@richfitz
Copy link
Member

richfitz commented Jul 3, 2020

Following from #194 it should be possible to split parts of an array expression over different stages (constant, user, time) subject to the condition that we evaluate them in the same order, so an equations stage is equal to the maximum stage observed so far.

So if we have:

M[, ] <- 1
M[2,3] <- x * t
M[1,4] <- 2

these would be stage constant, time, time.

@GBarnsley
Copy link

In case I'm misreading this issue, Odin currently includes this feature right?
This seems to work like this for vectors at least:

model <- odin::odin({
    C_0[] <- user()
    dim(C_0) <- 3

    dim(C) <- 3
    initial(C[]) <- C_0[i]
    deriv(C[]) <- C[i] * 0.1
    deriv(C[2]) <- C[i] * 0.2
    deriv(C[3]) <- C[i] * 0.3
})
model$new(user = list(C_0 = c(1, 1, 1)))$run(c(0, 1))

Which shows the later update dates to C[2] and C[3] take preference over the C[] assignment.

This is useful, but I think its unintuitive given that you can't reassign non-array variables in odin.
I was writing a model with more complex indexing and since this isn't documented anywhere I assumed that odin would throw an error if assignment indexes are overlapping, which made my debugging much harder.
The documentation could make it clear that this is possible?

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

No branches or pull requests

2 participants