Skip to content
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

Install mlpack and cereal headers in R package #3488

Merged
merged 7 commits into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

* Add `serialize` method to `GaussianInitialization`, `KathirvalavakumarSubavathiInitialization`, `KathirvalavakumarSubavathiInitialization`, `NguyenWidrowInitialization`, and `OrthogonalInitialization` (#3483).

* Install mlpack and cereal headers as part of R package (#3488).

### mlpack 4.1.0
###### 2023-04-26

Expand Down
12 changes: 6 additions & 6 deletions src/mlpack/bindings/R/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ macro (post_r_setup)
# First we have to create that directory though.
execute_process(
COMMAND ${CMAKE_COMMAND} -E
make_directory ${CMAKE_BINARY_DIR}/src/mlpack/bindings/R/mlpack/src/mlpack
make_directory ${CMAKE_BINARY_DIR}/src/mlpack/bindings/R/mlpack/inst/include/mlpack
rcurtin marked this conversation as resolved.
Show resolved Hide resolved
)

# Then copy each of the header and source files over to that directory.
Expand All @@ -432,7 +432,7 @@ macro (post_r_setup)
execute_process(
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${mlpack_sources}
${CMAKE_BINARY_DIR}/src/mlpack/bindings/R/mlpack/src/mlpack
${CMAKE_BINARY_DIR}/src/mlpack/bindings/R/mlpack/inst/include/mlpack
)
endforeach()

Expand All @@ -443,7 +443,7 @@ macro (post_r_setup)
execute_process(
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${CMAKE_CURRENT_SOURCE_DIR}/${r_src_file}
${CMAKE_BINARY_DIR}/src/mlpack/bindings/R/mlpack/src/mlpack/${r_src_file}
${CMAKE_BINARY_DIR}/src/mlpack/bindings/R/mlpack/inst/include/mlpack/${r_src_file}
)

# Collect path of all source files and append to ${R_SRC}.
Expand All @@ -460,19 +460,19 @@ macro (post_r_setup)
execute_process(
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${CEREAL_INCLUDE_DIR}/${rcereal_src_file}
${CMAKE_BINARY_DIR}/src/mlpack/bindings/R/mlpack/src/${rcereal_src_file}
${CMAKE_BINARY_DIR}/src/mlpack/bindings/R/mlpack/inst/include/${rcereal_src_file}
)
endforeach()

# Resolve gcc Warnings.
file(READ ${CMAKE_BINARY_DIR}/src/mlpack/bindings/R/mlpack/src/cereal/external/base64.hpp CEREAL_BASE64)
file(READ ${CMAKE_BINARY_DIR}/src/mlpack/bindings/R/mlpack/inst/include/cereal/external/base64.hpp CEREAL_BASE64)
string(REGEX REPLACE
"\n#ifdef __GNUC__\n#pragma GCC diagnostic push\n#pragma GCC diagnostic ignored \"-Wconversion\"\n#endif\n"
"" CEREAL_BASE64 "${CEREAL_BASE64}")
string(REGEX REPLACE
"#ifdef __GNUC__\n#pragma GCC diagnostic pop\n#endif"
"" CEREAL_BASE64 "${CEREAL_BASE64}")
file(WRITE ${CMAKE_BINARY_DIR}/src/mlpack/bindings/R/mlpack/src/cereal/external/base64.hpp "${CEREAL_BASE64}")
file(WRITE ${CMAKE_BINARY_DIR}/src/mlpack/bindings/R/mlpack/inst/include/cereal/external/base64.hpp "${CEREAL_BASE64}")

# Then configure 'mlpack.h.in' using ${R_SRC}.
configure_file(
Expand Down
2 changes: 1 addition & 1 deletion src/mlpack/bindings/R/mlpack/src/Makevars
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
PKG_CXXFLAGS = -DBOOST_MATH_PROMOTE_DOUBLE_POLICY=false -I. $(SHLIB_OPENMP_CXXFLAGS)
PKG_CXXFLAGS = -I. -I../inst/include $(SHLIB_OPENMP_CXXFLAGS)
PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS) $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
rcurtin marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion src/mlpack/bindings/R/mlpack/src/Makevars.win
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
PKG_CXXFLAGS = -DBOOST_MATH_PROMOTE_DOUBLE_POLICY=false -I. $(SHLIB_OPENMP_CXXFLAGS) -ftrack-macro-expansion=0 -pipe --param ggc-min-expand=10 --param ggc-min-heapsize=8192
PKG_CXXFLAGS = -I. -I../inst/include $(SHLIB_OPENMP_CXXFLAGS) -ftrack-macro-expansion=0 -pipe --param ggc-min-expand=10 --param ggc-min-heapsize=8192
PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS) $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
CXX_STD = CXX17
17 changes: 10 additions & 7 deletions src/mlpack/tests/nmf_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ TEST_CASE("SparseNMFALSTest", "[NMFTest]")
{
// We have to ensure that the residues aren't NaNs. This can happen when a
// matrix is created with all zeros in a column or row.
double denseResidue = std::numeric_limits<double>::quiet_NaN();
double sparseResidue = std::numeric_limits<double>::quiet_NaN();
double denseResidue;
double sparseResidue;

mat vp, dvp; // Resulting matrices.

Expand All @@ -194,17 +194,20 @@ TEST_CASE("SparseNMFALSTest", "[NMFTest]")
const size_t trials = 8;
for (size_t trial = 0; trial < trials; ++trial)
{
denseResidue = std::numeric_limits<double>::quiet_NaN();
sparseResidue = std::numeric_limits<double>::quiet_NaN();

while (sparseResidue != sparseResidue && denseResidue != denseResidue)
{
mat w, h;
sp_mat v;
v.sprandu(10, 10, 0.3);
v.sprandu(20, 20, 0.3);
// Ensure there is at least one nonzero element in every row and column.
for (size_t i = 0; i < 10; ++i)
v(i, i) += 1e-5;
for (size_t i = 0; i < 20; ++i)
v(i, i) += 0.01;
mat dv(v); // Make a dense copy.
mat dw, dh;
size_t r = 5;
size_t r = 10;

// Get an initialization.
arma::mat iw, ih;
Expand All @@ -227,7 +230,7 @@ TEST_CASE("SparseNMFALSTest", "[NMFTest]")

// Make sure the results are about equal for the W and H matrices.
const double relDiff = arma::norm(vp - dvp, "fro") / arma::norm(vp, "fro");
if (relDiff < 1e-5)
if (relDiff < 1e-4)
{
success = true;
break;
Expand Down