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

interpolated variables undeclared in delay blocks #130

Closed
OJWatson opened this issue May 16, 2018 · 9 comments
Closed

interpolated variables undeclared in delay blocks #130

OJWatson opened this issue May 16, 2018 · 9 comments
Labels
bug
Projects

Comments

@OJWatson
Copy link

@OJWatson OJWatson commented May 16, 2018

Following is an example of where the interpolated variables are not correctly included within delay blocks. Sorry it's a little long, but tried to remake it with just one delay and couldn't seem to

mod <- odin::odin({
  
  deriv(A) <- 2 * A * cov2 
  initial(A) <- 1  
  lagB <- A * 2
  B <- delay(lagB, 10)
  
  ###
  
  deriv(C) <- C * B
  initial(C) <- 1 
  lagD <- C * cov[1]
  D <- delay(lagD, 12) 

 ###
  
  flux <- interpolate(flux_t, flux_y, "linear")
  dim(cov) <- 2
  cov[1] <- 1 - flux
  cov[2] <- flux
  cov2 <- sum(cov) * D
  
  ###
  
  flux_t[] <- user()
  flux_y[] <- user()
  dim(flux_t) <- user()
  dim(flux_y) <- user()
  
})

which yields

Compiling shared library
c:/Rtools/mingw_64/bin/gcc  -I"C:/PROGRA~1/R/R-35~1.0/include" -DNDEBUG          -O2 -Wall  -std=gnu99 -mtune=generic -c odin.c -o odin.o
odin.c: In function 'odin_deriv':
odin.c:220:86: error: 'interpolate_flux' undeclared (first use in this function)
     double flux = "linear"(odin_p->flux_t, odin_p->flux_y, 0, 1, odin_p->dim_flux_t, interpolate_flux);
                                                                                      ^
odin.c:220:86: note: each undeclared identifier is reported only once for each function it appears in
odin.c:220:19: error: called object is not a function or function pointer
     double flux = "linear"(odin_p->flux_t, odin_p->flux_y, 0, 1, odin_p->dim_flux_t, interpolate_flux);
                   ^
make: *** [odin.o] Error 1

Error in handle_compiler_output(output, verbose, compiler_warnings) : 
  Error compiling source

and the compiled c code (as file):

odin.c.txt

@OJWatson
Copy link
Author

@OJWatson OJWatson commented Jul 30, 2018

@richfitz am just checking in on this.

richfitz added a commit that referenced this issue Aug 1, 2018
This is really a WIP towards #130 but gets some of the worst of this
dealt with.  However, it will fail if an interpolated function is both
delayed and used without delay!  And vector delays will still simply not
compile
@richfitz
Copy link
Member

@richfitz richfitz commented Aug 1, 2018

Fix for this on the i130 branch now

richfitz added a commit that referenced this issue Sep 19, 2018
This is really a WIP towards #130 but gets some of the worst of this
dealt with.  However, it will fail if an interpolated function is both
delayed and used without delay!  And vector delays will still simply not
compile
@richfitz richfitz added this to To Do in development via automation Sep 19, 2018
@richfitz richfitz moved this from To Do to Awaiting merge in development Sep 19, 2018
@richfitz
Copy link
Member

@richfitz richfitz commented Nov 28, 2018

this is fixed!

@richfitz richfitz closed this Nov 28, 2018
development automation moved this from Awaiting merge to Done Nov 28, 2018
@OJWatson
Copy link
Author

@OJWatson OJWatson commented Feb 25, 2019

@richfitz think i've found something similar when trying to use an interpolated matrix. For example this works fine:

mod <- odin::odin({
  
  deriv(A) <- 2 * A * D
  initial(A) <- 1  
  lagB <- A * 2
  B <- delay(lagB, 10)
  
  ###
  
  deriv(C) <- C * B
  initial(C) <- 1 
  lagD <- C * cov_interp
  D <- delay(lagD, 12)

  ###
  
  int_times[] <- user()
  dim(int_times) <- user()
  cov_vec[] <- user()
  dim(cov_vec) <- length(int_times)
  cov_interp <- interpolate(int_times, cov_vec, "constant")

})

But the following where make cov_vec into a matrix to be interpolated errors:

mod <- odin::odin({
  
  deriv(A) <- 2 * A * D
  initial(A) <- 1  
  lagB <- A * 2
  B <- delay(lagB, 10)
  
  ###
  
  deriv(C) <- C * B
  initial(C) <- 1 
  lagD <- C * cov_interp[1]
  D <- delay(lagD, 12)
  
  ###
  
  int_times[] <- user()
  dim(int_times) <- user()

  cov_mat[,] <- user()
  dim(cov_mat) <- c(length(int_times),2)

  cov_interp[] <- interpolate(int_times, cov_mat, "constant")
  dim(cov_interp) <- 2
  

})
gcc -std=gnu99 -I"/usr/share/R/include" -DNDEBUG      -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-i39faS/r-base-3.5.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c odin.c -o odin.o
odin.c: In function ‘odin_deriv’:
odin.c:272:37: error: ‘constant’ undeclared (first use in this function); did you mean ‘long int’?
       odin_p->delay_cov_interp[i] = constant;
                                     ^~~~~~~~
                                     long int
odin.c:272:37: note: each undeclared identifier is reported only once for each function it appears in
/usr/lib/R/etc/Makeconf:162: recipe for target 'odin.o' failed
make: *** [odin.o] Error 1

odin.c.txt

Let me know if there is anything else that would be useful to know

@richfitz
Copy link
Member

@richfitz richfitz commented Feb 25, 2019

can you give initialisation parameters for this model too please?

@richfitz richfitz reopened this Feb 25, 2019
development automation moved this from Done to In progress Feb 25, 2019
@richfitz richfitz added the bug label Feb 25, 2019
@OJWatson
Copy link
Author

@OJWatson OJWatson commented Feb 25, 2019

Sure so for the first model:

mod <- odin::odin({
  
  deriv(A) <- 0.1 * A * D
  initial(A) <- 1  
  lagB <- A * 2
  B <- delay(lagB, 10)
  ###
  
  deriv(C) <- C * B * 0.001
  initial(C) <- 1 
  lagD <- C * cov_interp
  D <- delay(lagD, 12)
  ###
  
  int_times[] <- user()
  dim(int_times) <- user()
  cov_vec[] <- user()
  dim(cov_vec) <- length(int_times)
  cov_interp <- interpolate(int_times, cov_vec, "constant")
  
})

m <- mod(int_times = c(-20,20,40),cov_vec = c(0,0.3,0.6))
m$run(t = 0:60)

and then the second one that doesn't

mod <- odin::odin({
  
  deriv(A) <- 0.1 * A * D
  initial(A) <- 1  
  lagB <- A * 2
  B <- delay(lagB, 10)
  ###
  
  deriv(C) <- C * B * 0.001
  initial(C) <- 1 
  lagD <- C * cov_interp[1]
  D <- delay(lagD, 12)
  ###
  
  int_times[] <- user()
  dim(int_times) <- user()
  
  cov_mat[,] <- user()
  dim(cov_mat) <- c(length(int_times),2)
  
  cov_interp[] <- interpolate(int_times, cov_mat, "constant")
  dim(cov_interp) <- 2
  
  
})

m <- mod(int_times = c(-20,20,40),cov_mat = matrix(rep(c(0,0.3,0.6),2),nrow=3))
m$run(t = 0:60)
@richfitz
Copy link
Member

@richfitz richfitz commented Feb 25, 2019

thanks, very useful. this won't move until I get the new interface working I'm afraid, but I will probably look at rolling this into that work

@OJWatson
Copy link
Author

@OJWatson OJWatson commented Feb 25, 2019

Cool - and yeah no rush from me so that sounds great.

@richfitz
Copy link
Member

@richfitz richfitz commented Mar 15, 2019

This is fixed on the i139_ir branch - please give it a go if you get a chance

@richfitz richfitz mentioned this issue Mar 18, 2019
@richfitz richfitz closed this Apr 8, 2019
development automation moved this from In progress to Done Apr 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
development
  
Done
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.