-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
[R-package] Use R standard routines to access numeric and integer array data in C++ #4247
Conversation
expect_true(abs(mae - expected_mae) < TOLERANCE) | ||
} | ||
}) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks to @david-cortes for providing the write-up in #4216, which included the reproducible example that inspired this unit test.
I tested this unit test tonight on my Mac, with R 3.6 and {lightgbm}
3.2.1 installed from CRAN, and confirmed that it failed in exactly the way described in #4216. So I'm confident that this test passing means the changes in this PR fix #4216.
/gha run r-solaris Workflow Solaris CRAN check has been triggered! 🚀 solaris-x86-patched: https://builder.r-hub.io/status/lightgbm_3.2.1.99.tar.gz-c0227bf93bb84b58be157cf6186f1119 |
/gha run r-valgrind Workflow R valgrind tests has been triggered! 🚀 Status: success ✔️. |
/gha run r-valgrind Workflow R valgrind tests has been triggered! 🚀 Status: success ✔️. |
/gha run r-solaris Workflow Solaris CRAN check has been triggered! 🚀 solaris-x86-patched: https://builder.r-hub.io/status/lightgbm_3.2.1.99.tar.gz-3701ffb1819540bf98d77218c211cd5c |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much for the iterative improvement!
This pull request has been automatically locked since there has not been any recent activity since it was closed. To start a new related discussion, open a new issue at https://github.com/microsoft/LightGBM/issues including a reference to this. |
Another step towards #3016.
Fixes #4216.
Changes in this PR:
R_REAL_PTR()
,R_INT_PTR()
) with the standard equivalents fromRinternals.h
(REAL()
,INTEGER()
)LGBM_SE
toSEXP
Description
R is a dynamically-typed language. You can run code like
x <- c(1, 2, 3)
without declaring thatx
is a numeric array, and R will just figure it out.R makes this possible by storing data for an object in a structure called a
SEXPREC
. That structure will contain different data based on the R class (integer, character, function, etc.). Libraries can reference that data in C code using a type,SEXP
, provided byRinternals.h
. Libraries can also get a pointer to a particular type of data within aSEXPREC
using other functions provided byRinternals.h
, for exampleREAL()
to get a pointer to its numeric data.As described in #4216, the internal details of the
SEXPREC
struct can change between different versions of R.SEXP
is the official R API into that struct, and by using it libraries can reliably stay compatible with multiple R versions.This PR's changes fix a bug that currently exists when using
{lightgbm}
with R 3.6, and protects{lightgbm}
from similar bugs in the future.For more details on this, see https://cran.r-project.org/doc/manuals/r-release/R-ints.html#SEXPs.
Notes for Reviewers
This PR does not depend on #4242 or #4247