stan icon indicating copy to clipboard operation
stan copied to clipboard

support NaN and inf input/output

Open bob-carpenter opened this issue 11 years ago • 1 comments

Our input mechanisms for data and inits should handle NaN and +inf and -inf values.

The new JSON reader handles them for input. But the current R dump format reader, which is the one we're currently using, doesn't. So the dump format should get updated if it's not just eliminated.

bob-carpenter avatar May 05 '14 17:05 bob-carpenter

See http://stackoverflow.com/questions/11420263/is-it-possible-to-read-infinity-or-nan-values-using-input-streams

Right now, with this program

data {
  real a;
  real b;
  real c;
}
parameters {
  real y;
}
model {
  print("a=", a, "  b=", b, "   c=", c);
  y ~ normal(0, 1);
}

And input dump file

a <- NaN
b <- -inf
c <- 3

it will break reading b because it causes an exception in problem for the initial integer reading pass

> ./is sample data file=is.R

Exception: data b value  beyond int range
Diagnostic information: 
stan/src/stan/io/dump.hpp(518): Throw in function bool stan::io::dump_reader::next()
Dynamic exception type: boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<std::invalid_argument> >
.

bob-carpenter avatar Nov 24 '16 05:11 bob-carpenter

included as part of #3142

bob-carpenter avatar Sep 23 '22 12:09 bob-carpenter