I have a void function x2y
that updates x
to y
through their addresses.
The Rcpp
code is like this
#include <RcppArmadillo.h>
#include <iostream>
//[[Rcpp::export]]
void x2y(const Rcpp::NumericVector& x,
Rcpp::NumericVector& y)
{
y = 1.0 / (1.0 + Rcpp::exp(-x));
std::cout << "output(0)= " << y(0) << std::endl;
}
If y
is initialized with NA
s it is not updated:
x <- c(-1, 0, 2)
y <- c(NA, NA, NA)
x2y(x, y)
print(y)
[1] NA NA NA
But if
y <- c(NaN, NaN, NaN)
x2y(x, y)
print(y)
[1] 0.2689414 0.5000000 0.8807971
or if
y <- c(-99, -99, -99)
x2y(x, y)
print(y)
[1] 0.2689414 0.5000000 0.8807971
This doesn't make sense to me. Can somebody explain why this happens?