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

User-defined vectors off by one #136

Closed
ada-w-yan opened this issue Oct 15, 2018 · 4 comments
Closed

User-defined vectors off by one #136

ada-w-yan opened this issue Oct 15, 2018 · 4 comments

Comments

@ada-w-yan
Copy link

@ada-w-yan ada-w-yan commented Oct 15, 2018

I have the following code in a file minimal_example.R:

# vector_length
n_I <- 3

# initial conditions
initial(I[1:n_I]) <- I_0[i]

# equations
deriv(I[1:n_I]) <- 0

dim(I) <- n_I
dim(I_0) <- n_I

# initial values
I_0[1:n_I] <- i

and I run

filename <- "minimal_example.R"
gen <- odin::odin(filename, verbose=FALSE) 
pars <- list()
mod <- gen()
mod$init

As an R user, I expect I_0 to be initialised to 1 2 3, but because C uses zero indexing, I get 0 1 2. Which is fine, I can add 1 to my vector, but I find the behaviour unexpected.

@richfitz
Copy link
Member

@richfitz richfitz commented Oct 18, 2018

Urgh that's horrible. I have a new idea about dealing with indexes (#115) which will make this sort of thing more understandable, but of cause break anything that ends up depending on this behaviour

@richfitz
Copy link
Member

@richfitz richfitz commented Feb 6, 2019

same as #52

@richfitz
Copy link
Member

@richfitz richfitz commented Feb 27, 2019

Looks like #139 will fix this

@richfitz
Copy link
Member

@richfitz richfitz commented Mar 11, 2019

From version 0.2.0 onward the new behaviour will be:

  • indexes on the rhs have R (base-1) behaviour
  • If indexes are used like this (outside of an index expression) then a message will be printed advertising the behaviour change
  • this message can be suppressed by using the argument no_check_naked_index = TRUE or setting the option options(odin.no_check_naked_index = TRUE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.