stan
stan copied to clipboard
support NaN and inf input/output
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.
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> >
.
included as part of #3142