-
Notifications
You must be signed in to change notification settings - Fork 1
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
incorrect use of NaN #4
Comments
Hi guys, coming in here without too much context but the main take away is that R use the standard IEEE approach for NaN on We do have documentation (a little scattered, I admit) on how to do withing the R context via Rcpp and hence RcppArmadillo. |
To the point @conradsnicta was making, a more C++-standards compliant way is > x <- c(3, NA, NaN, 5)
> x == NA
[1] NA NA NA NA
> sapply(x, is.finite)
[1] TRUE FALSE FALSE TRUE
> |
@conradsnicta,
thank you very much for inspecting my code. I was surprised that someone
even looks at it :) I will try to fix that hopefully at the weekend. Also
thanks for the helpful links. And of course thumbs up for this awesome
library that has helped me with many problems :) Armadillo with Rcpp runs
like a charm.
Best,
Simon
Am Mo., 10. Jan. 2022 um 04:10 Uhr schrieb Conrad Sanderson <
***@***.***>:
… @simonsays1980 <https://github.com/simonsays1980> This bit of code in
optimize.h is not likely to work correctly:
https://github.com/simonsays1980/finmix/blob/d853be4b4b208a391b32a160d6b90afecb5d62b0/src/optimize.h#L67-L70
Extract from cppreference.com: "NaN values never compare equal to
themselves or to other NaN values".
https://en.cppreference.com/w/cpp/numeric/math/isnan
Suggest to use arma::replace()
<http://arma.sourceforge.net/docs.html#replace> instead, in order to
replace NaN values with zeros.
CC: @eddelbuettel <https://github.com/eddelbuettel>
—
Reply to this email directly, view it on GitHub
<#4>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AANWKR5IQLSTLRPP4QU3NU3UVJEZ7ANCNFSM5LSUT4MA>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Dirk,
thank you for clarifying Conrad's point. Given your answer and the one of
Conrad, would you yourself rather go with std::infinite or with
arma::replace(datum::nan, 0)?
Best,
Simon
Am Mo., 10. Jan. 2022 um 04:41 Uhr schrieb Dirk Eddelbuettel <
***@***.***>:
… To the point @conradsnicta <https://github.com/conradsnicta> was making,
a more C++-standards compliant way is std::isfinite -- see
https://en.cppreference.com/w/cpp/numeric/math/isfinite. But yes the ==
comparison will not work, just how it does not in R either:
> x <- c(3, NA, NaN, 5)> x == NA
[1] NA NA NA NA> sapply(x, is.finite)
[1] TRUE FALSE FALSE TRUE>
—
Reply to this email directly, view it on GitHub
<#4 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AANWKRZ5OVMNQQQRAMRZB6DUVJIQDANCNFSM5LSUT4MA>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Hi Simon, This hit me out of context per Conrad's tag but I think he is right on that you cannot do What is nice about the Rcpp(Armadillo) integration is that you can test that oneliners immediately. And Rcpp helps with a few of the vectorised functions. > Rcpp::cppFunction("LogicalVector foo(NumericVector x) { return is_finite(x); }")
> foo(c(2, 3, NA, 5, NaN, 7, Inf, 9))
[1] TRUE TRUE FALSE TRUE FALSE TRUE FALSE TRUE
> |
@simonsays1980 This bit of code in optimize.h is not likely to work correctly:
finmix/src/optimize.h
Lines 67 to 70 in d853be4
Extract from cppreference.com: "NaN values never compare equal to themselves or to other NaN values".
https://en.cppreference.com/w/cpp/numeric/math/isnan
Suggest to use arma::replace() instead, in order to replace NaN values with zeros.
CC: @eddelbuettel
The text was updated successfully, but these errors were encountered: