Commit b6db7e23 authored by Rand Xie's avatar Rand Xie Committed by Guolin Ke
Browse files

[R] Use NA_real_ to initialize handle (#1255)

parent 98c6efe3
...@@ -167,7 +167,7 @@ Dataset <- R6Class( ...@@ -167,7 +167,7 @@ Dataset <- R6Class(
if (!is.null(private$reference)) { if (!is.null(private$reference)) {
ref_handle <- private$reference$.__enclos_env__$private$get_handle() ref_handle <- private$reference$.__enclos_env__$private$get_handle()
} }
handle <- 0.0 handle <- NA_real_
# Not subsetting # Not subsetting
if (is.null(private$used_indices)) { if (is.null(private$used_indices)) {
......
...@@ -7,7 +7,7 @@ lgb.is.Dataset <- function(x) { ...@@ -7,7 +7,7 @@ lgb.is.Dataset <- function(x) {
} }
lgb.is.null.handle <- function(x) { lgb.is.null.handle <- function(x) {
is.null(x) || x == 0.0 is.null(x) || is.na(x)
} }
lgb.encode.char <- function(arr, len) { lgb.encode.char <- function(arr, len) {
......
...@@ -26,6 +26,8 @@ test_that("lgb.Dataset: basic construction, saving, loading", { ...@@ -26,6 +26,8 @@ test_that("lgb.Dataset: basic construction, saving, loading", {
test_that("lgb.Dataset: getinfo & setinfo", { test_that("lgb.Dataset: getinfo & setinfo", {
dtest <- lgb.Dataset(test_data) dtest <- lgb.Dataset(test_data)
dtest$construct()
setinfo(dtest, 'label', test_label) setinfo(dtest, 'label', test_label)
labels <- getinfo(dtest, 'label') labels <- getinfo(dtest, 'label')
expect_equal(test_label, getinfo(dtest, 'label')) expect_equal(test_label, getinfo(dtest, 'label'))
...@@ -66,3 +68,17 @@ test_that("lgb.Dataset: nrow is correct for a very sparse matrix", { ...@@ -66,3 +68,17 @@ test_that("lgb.Dataset: nrow is correct for a very sparse matrix", {
dtest <- lgb.Dataset(x) dtest <- lgb.Dataset(x)
expect_equal(dim(dtest), dim(x)) expect_equal(dim(dtest), dim(x))
}) })
test_that("lgb.Dataset: Dataset should be able to construct from matrix and return non-null handle", {
rawData <- matrix(runif(1000),ncol=10)
handle <- NA_real_
ref_handle <- NULL
handle <- lightgbm:::lgb.call("LGBM_DatasetCreateFromMat_R"
, ret = handle
, rawData
, nrow(rawData)
, ncol(rawData)
, lightgbm:::lgb.params2str(params=list())
, ref_handle)
expect_false(is.na(handle))
})
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment