Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
tianlh
LightGBM-DCU
Commits
84bdf257
Unverified
Commit
84bdf257
authored
Apr 01, 2020
by
James Lamb
Committed by
GitHub
Apr 01, 2020
Browse files
[R-package] adding routine registration in R package (fixes #1910) (#2911)
parent
6ba84d54
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
84 additions
and
27 deletions
+84
-27
.ci/test_r_package.sh
.ci/test_r_package.sh
+1
-1
CMakeLists.txt
CMakeLists.txt
+9
-2
R-package/.Rbuildignore
R-package/.Rbuildignore
+8
-6
R-package/src/install.libs.R
R-package/src/install.libs.R
+13
-6
src/lightgbm_R.cpp
src/lightgbm_R.cpp
+53
-0
windows/LightGBM.vcxproj
windows/LightGBM.vcxproj
+0
-3
windows/LightGBM.vcxproj.filters
windows/LightGBM.vcxproj.filters
+0
-9
No files found.
.ci/test_r_package.sh
View file @
84bdf257
...
...
@@ -91,7 +91,7 @@ if grep -q -R "WARNING" "$LOG_FILE_NAME"; then
exit
-1
fi
ALLOWED_CHECK_NOTES
=
3
ALLOWED_CHECK_NOTES
=
2
NUM_CHECK_NOTES
=
$(
cat
${
LOG_FILE_NAME
}
\
|
grep
-e
'^Status: .* NOTE.*'
\
...
...
CMakeLists.txt
View file @
84bdf257
...
...
@@ -235,7 +235,15 @@ file(GLOB SOURCES
)
add_executable
(
lightgbm src/main.cpp
${
SOURCES
}
)
add_library
(
_lightgbm SHARED src/c_api.cpp src/lightgbm_R.cpp
${
SOURCES
}
)
list
(
APPEND SOURCES
"src/c_api.cpp"
)
# Only build the R part of the library if building for
# use with the R package
if
(
BUILD_FOR_R
)
list
(
APPEND SOURCES
"src/lightgbm_R.cpp"
)
endif
(
BUILD_FOR_R
)
add_library
(
_lightgbm SHARED
${
SOURCES
}
)
if
(
MSVC
)
set_target_properties
(
_lightgbm PROPERTIES OUTPUT_NAME
"lib_lightgbm"
)
...
...
@@ -308,7 +316,6 @@ if(WIN32 AND (MINGW OR CYGWIN))
endif
()
if
(
BUILD_FOR_R
)
TARGET_LINK_LIBRARIES
(
lightgbm
${
LIBR_CORE_LIBRARY
}
)
TARGET_LINK_LIBRARIES
(
_lightgbm
${
LIBR_CORE_LIBRARY
}
)
endif
(
BUILD_FOR_R
)
...
...
R-package/.Rbuildignore
View file @
84bdf257
...
...
@@ -4,20 +4,22 @@
^pkgdown$
# Objects created by compilation
\.o
$
\.so
$
\.dll
$
\.out
$
\.bin
$
^.*
\.o
^.*
\.so
^.*
\.dll
^.*
\.out
^.*
\.bin
# Code copied in at build time
^src/CMakeLists.txt$
^Makefile$
^src/build/.*$
# unnecessary files from submodules
^src/compute/.appveyor.yml$
^src/compute/.coveralls.yml$
^src/compute/.travis.yml$
^src/compute/test/$
^src/compute/test/
.*
$
^src/compute/index.html$
^src/compute/.git$
^src/compute/.gitignore$
...
...
R-package/src/install.libs.R
View file @
84bdf257
...
...
@@ -43,7 +43,7 @@ if (!use_precompile) {
# Prepare installation steps
cmake_cmd
<-
"cmake "
build_cmd
<-
"make _lightgbm"
lib_folder
<-
file.path
(
R_PACKAGE_SOURCE
,
"src"
,
fsep
=
"/"
)
lib_folder
<-
file.path
(
source_dir
,
fsep
=
"/"
)
if
(
use_gpu
)
{
cmake_cmd
<-
paste0
(
cmake_cmd
,
" -DUSE_GPU=ON "
)
...
...
@@ -98,7 +98,7 @@ if (!use_precompile) {
}
else
{
cmake_cmd
<-
paste0
(
cmake_cmd
,
local_vs_def
)
build_cmd
<-
"cmake --build . --target _lightgbm --config Release"
lib_folder
<-
file.path
(
R_PACKAGE_SOURCE
,
"src/
Release"
,
fsep
=
"/"
)
lib_folder
<-
file.path
(
source_dir
,
"
Release"
,
fsep
=
"/"
)
}
}
}
...
...
@@ -110,9 +110,7 @@ if (!use_precompile) {
# Makefile. We don't need it here anyway since targets are built serially, so trying
# to remove it with this hack
generated_makefile
<-
file.path
(
R_PACKAGE_SOURCE
,
"src"
,
"build"
build_dir
,
"Makefile"
)
if
(
file.exists
(
generated_makefile
))
{
...
...
@@ -163,12 +161,21 @@ if (!use_precompile) {
}
}
# Check installation correctness
# Packages with install.libs.R need to copy some artifacts into the
# expected places in the package structure.
# see https://cran.r-project.org/doc/manuals/r-devel/R-exts.html#Package-subdirectories,
# especially the paragraph on install.libs.R
dest
<-
file.path
(
R_PACKAGE_DIR
,
paste0
(
"libs"
,
R_ARCH
),
fsep
=
"/"
)
dir.create
(
dest
,
recursive
=
TRUE
,
showWarnings
=
FALSE
)
if
(
file.exists
(
src
))
{
print
(
paste0
(
"Found library file: "
,
src
,
" to move to "
,
dest
))
file.copy
(
src
,
dest
,
overwrite
=
TRUE
)
symbols_file
<-
file.path
(
source_dir
,
"symbols.rds"
)
if
(
file.exists
(
symbols_file
))
{
file.copy
(
symbols_file
,
dest
,
overwrite
=
TRUE
)
}
}
else
{
stop
(
paste0
(
"Cannot find lib_lightgbm"
,
SHLIB_EXT
))
}
...
...
src/lightgbm_R.cpp
View file @
84bdf257
...
...
@@ -16,6 +16,8 @@
#include <utility>
#include <vector>
#include <R_ext/Rdynload.h>
#define COL_MAJOR (0)
#define R_API_BEGIN() \
...
...
@@ -656,3 +658,54 @@ LGBM_SE LGBM_BoosterDumpModel_R(LGBM_SE handle,
EncodeChar
(
out_str
,
inner_char_buf
.
data
(),
buffer_len
,
actual_len
,
static_cast
<
size_t
>
(
out_len
));
R_API_END
();
}
// .Call() calls
static
const
R_CallMethodDef
CallEntries
[]
=
{
{
"LGBM_GetLastError_R"
,
(
DL_FUNC
)
&
LGBM_GetLastError_R
,
3
},
{
"LGBM_DatasetCreateFromFile_R"
,
(
DL_FUNC
)
&
LGBM_DatasetCreateFromFile_R
,
5
},
{
"LGBM_DatasetCreateFromCSC_R"
,
(
DL_FUNC
)
&
LGBM_DatasetCreateFromCSC_R
,
10
},
{
"LGBM_DatasetCreateFromMat_R"
,
(
DL_FUNC
)
&
LGBM_DatasetCreateFromMat_R
,
7
},
{
"LGBM_DatasetGetSubset_R"
,
(
DL_FUNC
)
&
LGBM_DatasetGetSubset_R
,
6
},
{
"LGBM_DatasetSetFeatureNames_R"
,
(
DL_FUNC
)
&
LGBM_DatasetSetFeatureNames_R
,
3
},
{
"LGBM_DatasetGetFeatureNames_R"
,
(
DL_FUNC
)
&
LGBM_DatasetGetFeatureNames_R
,
5
},
{
"LGBM_DatasetSaveBinary_R"
,
(
DL_FUNC
)
&
LGBM_DatasetSaveBinary_R
,
3
},
{
"LGBM_DatasetFree_R"
,
(
DL_FUNC
)
&
LGBM_DatasetFree_R
,
2
},
{
"LGBM_DatasetSetField_R"
,
(
DL_FUNC
)
&
LGBM_DatasetSetField_R
,
5
},
{
"LGBM_DatasetGetFieldSize_R"
,
(
DL_FUNC
)
&
LGBM_DatasetGetFieldSize_R
,
4
},
{
"LGBM_DatasetGetField_R"
,
(
DL_FUNC
)
&
LGBM_DatasetGetField_R
,
4
},
{
"LGBM_DatasetUpdateParamChecking_R"
,
(
DL_FUNC
)
&
LGBM_DatasetUpdateParamChecking_R
,
3
},
{
"LGBM_DatasetGetNumData_R"
,
(
DL_FUNC
)
&
LGBM_DatasetGetNumData_R
,
3
},
{
"LGBM_DatasetGetNumFeature_R"
,
(
DL_FUNC
)
&
LGBM_DatasetGetNumFeature_R
,
3
},
{
"LGBM_BoosterCreate_R"
,
(
DL_FUNC
)
&
LGBM_BoosterCreate_R
,
4
},
{
"LGBM_BoosterFree_R"
,
(
DL_FUNC
)
&
LGBM_BoosterFree_R
,
2
},
{
"LGBM_BoosterCreateFromModelfile_R"
,
(
DL_FUNC
)
&
LGBM_BoosterCreateFromModelfile_R
,
3
},
{
"LGBM_BoosterLoadModelFromString_R"
,
(
DL_FUNC
)
&
LGBM_BoosterLoadModelFromString_R
,
3
},
{
"LGBM_BoosterMerge_R"
,
(
DL_FUNC
)
&
LGBM_BoosterMerge_R
,
3
},
{
"LGBM_BoosterAddValidData_R"
,
(
DL_FUNC
)
&
LGBM_BoosterAddValidData_R
,
3
},
{
"LGBM_BoosterResetTrainingData_R"
,
(
DL_FUNC
)
&
LGBM_BoosterResetTrainingData_R
,
3
},
{
"LGBM_BoosterResetParameter_R"
,
(
DL_FUNC
)
&
LGBM_BoosterResetParameter_R
,
3
},
{
"LGBM_BoosterGetNumClasses_R"
,
(
DL_FUNC
)
&
LGBM_BoosterGetNumClasses_R
,
3
},
{
"LGBM_BoosterUpdateOneIter_R"
,
(
DL_FUNC
)
&
LGBM_BoosterUpdateOneIter_R
,
2
},
{
"LGBM_BoosterUpdateOneIterCustom_R"
,
(
DL_FUNC
)
&
LGBM_BoosterUpdateOneIterCustom_R
,
5
},
{
"LGBM_BoosterRollbackOneIter_R"
,
(
DL_FUNC
)
&
LGBM_BoosterRollbackOneIter_R
,
2
},
{
"LGBM_BoosterGetCurrentIteration_R"
,
(
DL_FUNC
)
&
LGBM_BoosterGetCurrentIteration_R
,
3
},
{
"LGBM_BoosterGetUpperBoundValue_R"
,
(
DL_FUNC
)
&
LGBM_BoosterGetUpperBoundValue_R
,
3
},
{
"LGBM_BoosterGetLowerBoundValue_R"
,
(
DL_FUNC
)
&
LGBM_BoosterGetLowerBoundValue_R
,
3
},
{
"LGBM_BoosterGetEvalNames_R"
,
(
DL_FUNC
)
&
LGBM_BoosterGetEvalNames_R
,
5
},
{
"LGBM_BoosterGetEval_R"
,
(
DL_FUNC
)
&
LGBM_BoosterGetEval_R
,
4
},
{
"LGBM_BoosterGetNumPredict_R"
,
(
DL_FUNC
)
&
LGBM_BoosterGetNumPredict_R
,
4
},
{
"LGBM_BoosterGetPredict_R"
,
(
DL_FUNC
)
&
LGBM_BoosterGetPredict_R
,
4
},
{
"LGBM_BoosterPredictForFile_R"
,
(
DL_FUNC
)
&
LGBM_BoosterPredictForFile_R
,
10
},
{
"LGBM_BoosterCalcNumPredict_R"
,
(
DL_FUNC
)
&
LGBM_BoosterCalcNumPredict_R
,
8
},
{
"LGBM_BoosterPredictForCSC_R"
,
(
DL_FUNC
)
&
LGBM_BoosterPredictForCSC_R
,
14
},
{
"LGBM_BoosterPredictForMat_R"
,
(
DL_FUNC
)
&
LGBM_BoosterPredictForMat_R
,
11
},
{
"LGBM_BoosterSaveModel_R"
,
(
DL_FUNC
)
&
LGBM_BoosterSaveModel_R
,
4
},
{
"LGBM_BoosterSaveModelToString_R"
,
(
DL_FUNC
)
&
LGBM_BoosterSaveModelToString_R
,
6
},
{
"LGBM_BoosterDumpModel_R"
,
(
DL_FUNC
)
&
LGBM_BoosterDumpModel_R
,
6
},
{
NULL
,
NULL
,
0
}
};
void
R_init_lightgbm
(
DllInfo
*
dll
)
{
R_registerRoutines
(
dll
,
NULL
,
CallEntries
,
NULL
,
NULL
);
R_useDynamicSymbols
(
dll
,
FALSE
);
}
windows/LightGBM.vcxproj
View file @
84bdf257
...
...
@@ -237,13 +237,11 @@
<ClInclude
Include=
"..\include\LightGBM\dataset.h"
/>
<ClInclude
Include=
"..\include\LightGBM\dataset_loader.h"
/>
<ClInclude
Include=
"..\include\LightGBM\feature_group.h"
/>
<ClInclude
Include=
"..\include\LightGBM\lightgbm_R.h"
/>
<ClInclude
Include=
"..\include\LightGBM\meta.h"
/>
<ClInclude
Include=
"..\include\LightGBM\metric.h"
/>
<ClInclude
Include=
"..\include\LightGBM\network.h"
/>
<ClInclude
Include=
"..\include\LightGBM\objective_function.h"
/>
<ClInclude
Include=
"..\include\LightGBM\prediction_early_stop.h"
/>
<ClInclude
Include=
"..\include\LightGBM\R_object_helper.h"
/>
<ClInclude
Include=
"..\include\LightGBM\tree.h"
/>
<ClInclude
Include=
"..\include\LightGBM\tree_learner.h"
/>
<ClInclude
Include=
"..\include\LightGBM\utils\array_args.h"
/>
...
...
@@ -308,7 +306,6 @@
<ClCompile
Include=
"..\src\io\metadata.cpp"
/>
<ClCompile
Include=
"..\src\io\parser.cpp"
/>
<ClCompile
Include=
"..\src\io\tree.cpp"
/>
<ClCompile
Include=
"..\src\lightgbm_R.cpp"
/>
<ClCompile
Include=
"..\src\metric\dcg_calculator.cpp"
/>
<ClCompile
Include=
"..\src\metric\metric.cpp"
/>
<ClCompile
Include=
"..\src\network\network.cpp"
/>
...
...
windows/LightGBM.vcxproj.filters
View file @
84bdf257
...
...
@@ -183,12 +183,6 @@
<ClInclude
Include=
"..\src\metric\map_metric.hpp"
>
<Filter>
src\metric
</Filter>
</ClInclude>
<ClInclude
Include=
"..\include\LightGBM\lightgbm_R.h"
>
<Filter>
include\LightGBM
</Filter>
</ClInclude>
<ClInclude
Include=
"..\include\LightGBM\R_object_helper.h"
>
<Filter>
include\LightGBM
</Filter>
</ClInclude>
<ClInclude
Include=
"..\src\boosting\rf.hpp"
>
<Filter>
src\boosting
</Filter>
</ClInclude>
...
...
@@ -296,9 +290,6 @@
<ClCompile
Include=
"..\src\boosting\prediction_early_stop.cpp"
>
<Filter>
src\boosting
</Filter>
</ClCompile>
<ClCompile
Include=
"..\src\lightgbm_R.cpp"
>
<Filter>
src
</Filter>
</ClCompile>
<ClCompile
Include=
"..\src\boosting\gbdt_model_text.cpp"
>
<Filter>
src\boosting
</Filter>
</ClCompile>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment