odin icon indicating copy to clipboard operation
odin copied to clipboard

Different modes for different parts of array expression

Open richfitz opened this issue 5 years ago • 1 comments

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.

richfitz avatar Jul 03 '20 15:07 richfitz

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?

GBarnsley avatar Jan 18 '24 14:01 GBarnsley