Skip to content

Commit d070d18

Browse files
committed
update configure + add field docs
1 parent 1d43f06 commit d070d18

18 files changed

+751
-382
lines changed

CRAN-SUBMISSION

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
Version: 0.4.0
2-
Date: 2024-12-13 03:42:45 UTC
3-
SHA: cbbae9289938119dea67ccc7afb66ee04d6aad15
1+
Version: 0.4.1
2+
Date: 2024-12-17 20:54:48 UTC
3+
SHA: 1d43f069e1f90dd7c99c71e8ff9bb7990f122182

NEWS.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# cpp11armadillo 0.4.1
22

3-
* Modified configure file. It used `--cppflags` for compiling against `libR`,
4-
which not everyone has. Now it uses `--cflags` to solve build issues with
5-
MacPorts and Fedora.
3+
* Modified configure file to fix Fedora errors.
64
* Includes parts of the official Armadillo documentation in the vignettes but
75
adapted to working with R.
86
* Thanks a lot to @barracuda156 and @bastistician for reporting the issue.

configure

+8-18
Original file line numberDiff line numberDiff line change
@@ -2,55 +2,45 @@
22

33
# We make sure that the R and Armadillo bindings are compatible (i.e., messages)
44
# this is why we add the R and cpp11 path
5-
CXX=`${R_HOME}/bin/R CMD config CXX`
6-
R_INCLUDE_PATH=`${R_HOME}/bin/R CMD config --cppflags`
7-
R_LDFLAGS=`${R_HOME}/bin/R CMD config --ldflags`
85
CPP11_INCLUDE_PATH=`${R_HOME}/bin/Rscript -e "cat(system.file('include', package = 'cpp11'))"`
6+
INST_INCLUDE_PATH="./inst/include"
97

108
# Check if CPP11_INCLUDE_PATH is empty
119
if [ -z "$CPP11_INCLUDE_PATH" ]; then
1210
echo "Error: cpp11 include path is empty. Please ensure the cpp11 package is installed."
1311
exit 1
1412
fi
1513

16-
# Get the absolute path to the inst/include directory
17-
INST_INCLUDE_PATH=$(cd "$(dirname "$0")/inst/include" && pwd)
18-
19-
PKG_CFLAGS="${R_INCLUDE_PATH} -I${CPP11_INCLUDE_PATH} -I${INST_INCLUDE_PATH}"
20-
PKG_LDFLAGS="${R_LDFLAGS}"
14+
PKG_CPPFLAGS="-I${INST_INCLUDE_PATH} -I${CPP11_INCLUDE_PATH}"
2115

2216
# Debugging: Print the values of the variables
2317
echo "=================================="
2418
echo " Compiler Configuration Variables "
2519
echo " "
26-
echo "CXX: ${CXX}"
27-
echo "R_INCLUDE_PATH: ${R_INCLUDE_PATH}"
28-
echo "R_LDFLAGS: ${R_LDFLAGS}"
2920
echo "CPP11_INCLUDE_PATH: ${CPP11_INCLUDE_PATH}"
3021
echo "INST_INCLUDE_PATH: ${INST_INCLUDE_PATH}"
31-
echo "PKG_CFLAGS: ${PKG_CFLAGS}"
32-
echo "PKG_LDFLAGS: ${PKG_LDFLAGS}"
22+
echo "PKG_CPPFLAGS: ${PKG_CPPFLAGS}"
3323

3424
# Create a temporary C++ file to test the compatibility with Armadillo
3525
cat <<EOF> conftest.cpp
36-
#include <armadillo.hpp>
26+
#include <armadillo>
3727
using namespace arma;
3828
int main() {
3929
Mat<int> A(2, 2, fill::ones);
4030
return 0;
4131
}
4232
EOF
4333
44-
# Test Armadillo using g++
34+
# Test Armadillo using R CMD SHLIB
4535
echo "==================================="
4636
echo " Testing minimal Armadillo example "
4737
echo " "
48-
if ! ${CXX} ${PKG_CFLAGS} conftest.cpp ${PKG_LDFLAGS} -o conftest
38+
if ! PKG_CPPFLAGS="${PKG_CPPFLAGS}" "${R_HOME}/bin/R" CMD SHLIB conftest.cpp
4939
then
5040
echo "Armadillo is not compatible with the C++ compiler used by R."
51-
rm -f conftest.cpp conftest.o conftest
41+
rm -f conftest.cpp conftest.o conftest.so
5242
exit 1
5343
else
5444
echo "Armadillo is compatible with the C++ compiler used by R."
55-
rm -f conftest.cpp conftest.o conftest
45+
rm -f conftest.cpp conftest.o conftest.so
5646
fi

cpp11armadillotest/R/cpp11.R

+8
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,11 @@ column_fun1_ <- function(x, y) {
9595
row_fun1_ <- function(x, y) {
9696
.Call(`_cpp11armadillotest_row_fun1_`, x, y)
9797
}
98+
99+
cube_fun1_ <- function(a, b) {
100+
.Call(`_cpp11armadillotest_cube_fun1_`, a, b)
101+
}
102+
103+
field_fun1_ <- function(a, b) {
104+
.Call(`_cpp11armadillotest_field_fun1_`, a, b)
105+
}

cpp11armadillotest/src/08_official_documentation_adapted.cpp

+32
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,35 @@
6767

6868
return as_doubles(res); // convert from C++ to R
6969
}
70+
71+
[[cpp11::register]] doubles_matrix<> cube_fun1_(const doubles_matrix<>& a,
72+
const doubles_matrix<>& b) {
73+
mat A = as_Mat(a); // convert from R to C++
74+
mat B = as_Mat(b);
75+
76+
cube X(A.n_rows, A.n_cols, 2); // create a cube with 2 slices
77+
X.slice(0) = A; // copy A into first slice
78+
X.slice(1) = B; // copy B into second slice
79+
80+
cube Y = X + X; // cube addition
81+
cube Z = X % X; // element-wise cube multiplication
82+
83+
mat res = Y.slice(0) + Z.slice(1);
84+
85+
return as_doubles_matrix(res); // convert from C++ to R
86+
}
87+
88+
[[cpp11::register]] doubles_matrix<> field_fun1_(const doubles_matrix<>& a,
89+
const doubles_matrix<>& b) {
90+
mat A = as_Mat(a); // convert from R to C++
91+
mat B = as_Mat(b);
92+
93+
field<mat> F(A.n_rows, A.n_cols, 3); // create a field with 2 matrices
94+
F(0) = A; // copy A into first location
95+
F(1) = B; // copy B into second location
96+
F(2) = F(0) + F(1); // matrix addition
97+
98+
mat res = F(0) + F(1) + F(2).t();
99+
100+
return as_doubles_matrix(res); // convert from C++ to R
101+
}

cpp11armadillotest/src/cpp11.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -173,18 +173,34 @@ extern "C" SEXP _cpp11armadillotest_row_fun1_(SEXP x, SEXP y) {
173173
return cpp11::as_sexp(row_fun1_(cpp11::as_cpp<cpp11::decay_t<const doubles&>>(x), cpp11::as_cpp<cpp11::decay_t<const doubles&>>(y)));
174174
END_CPP11
175175
}
176+
// 08_official_documentation_adapted.cpp
177+
doubles_matrix<> cube_fun1_(const doubles_matrix<>& a, const doubles_matrix<>& b);
178+
extern "C" SEXP _cpp11armadillotest_cube_fun1_(SEXP a, SEXP b) {
179+
BEGIN_CPP11
180+
return cpp11::as_sexp(cube_fun1_(cpp11::as_cpp<cpp11::decay_t<const doubles_matrix<>&>>(a), cpp11::as_cpp<cpp11::decay_t<const doubles_matrix<>&>>(b)));
181+
END_CPP11
182+
}
183+
// 08_official_documentation_adapted.cpp
184+
doubles_matrix<> field_fun1_(const doubles_matrix<>& a, const doubles_matrix<>& b);
185+
extern "C" SEXP _cpp11armadillotest_field_fun1_(SEXP a, SEXP b) {
186+
BEGIN_CPP11
187+
return cpp11::as_sexp(field_fun1_(cpp11::as_cpp<cpp11::decay_t<const doubles_matrix<>&>>(a), cpp11::as_cpp<cpp11::decay_t<const doubles_matrix<>&>>(b)));
188+
END_CPP11
189+
}
176190

177191
extern "C" {
178192
static const R_CallMethodDef CallEntries[] = {
179193
{"_cpp11armadillotest_capm", (DL_FUNC) &_cpp11armadillotest_capm, 3},
180194
{"_cpp11armadillotest_chol_mat", (DL_FUNC) &_cpp11armadillotest_chol_mat, 2},
181195
{"_cpp11armadillotest_column_fun1_", (DL_FUNC) &_cpp11armadillotest_column_fun1_, 2},
196+
{"_cpp11armadillotest_cube_fun1_", (DL_FUNC) &_cpp11armadillotest_cube_fun1_, 2},
182197
{"_cpp11armadillotest_eigen_gen_dbl_complex_wrapper", (DL_FUNC) &_cpp11armadillotest_eigen_gen_dbl_complex_wrapper, 1},
183198
{"_cpp11armadillotest_eigen_gen_mat", (DL_FUNC) &_cpp11armadillotest_eigen_gen_mat, 1},
184199
{"_cpp11armadillotest_eigen_gen_mat_complex_wrapper", (DL_FUNC) &_cpp11armadillotest_eigen_gen_mat_complex_wrapper, 1},
185200
{"_cpp11armadillotest_eigen_gen_no_wrapper", (DL_FUNC) &_cpp11armadillotest_eigen_gen_no_wrapper, 1},
186201
{"_cpp11armadillotest_eigen_sym_dbl", (DL_FUNC) &_cpp11armadillotest_eigen_sym_dbl, 1},
187202
{"_cpp11armadillotest_eigen_sym_mat", (DL_FUNC) &_cpp11armadillotest_eigen_sym_mat, 1},
203+
{"_cpp11armadillotest_field_fun1_", (DL_FUNC) &_cpp11armadillotest_field_fun1_, 2},
188204
{"_cpp11armadillotest_matrix_fun1_", (DL_FUNC) &_cpp11armadillotest_matrix_fun1_, 1},
189205
{"_cpp11armadillotest_matrix_fun2_", (DL_FUNC) &_cpp11armadillotest_matrix_fun2_, 1},
190206
{"_cpp11armadillotest_ols_dbl", (DL_FUNC) &_cpp11armadillotest_ols_dbl, 2},

cpp11armadillotest/tests/testthat/test-official-documentation-adapted.R

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
test_that("examples derived from official documentation", {
22
set.seed(123)
33
a <- matrix(runif(25), nrow = 5, ncol = 5)
4+
b <- matrix(runif(25), nrow = 5, ncol = 5)
45

56
res1 <- matrix_fun1_(a)
67
expect_type(res1, "double")
@@ -21,6 +22,14 @@ test_that("examples derived from official documentation", {
2122
expect_type(res3, "double")
2223
expect_equal(length(res3), 10)
2324

24-
res5 <- row_fun1_(x, y)
25+
res4 <- row_fun1_(x, y)
2526
expect_type(res5, "double")
27+
28+
res5 <- cube_fun1_(a, b)
29+
expect_type(res5, "double")
30+
expect_equal(res5, (2 * a) + (b * b))
31+
32+
res6 <- field_fun1_(a, b)
33+
expect_type(res6, "double")
34+
expect_equal(res6, a + b + t(a) + t(b))
2635
})

cran-comments.md

+2-6
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
0 errors | 0 warnings | 1 note
44

55
* This is a new release.
6-
* The goal is to address the gcc15 issues by upgrading the Armadillo version
7-
from 14.0.02 to 14.2.2 in this release.
8-
* I also added a configure file that checks that a minimal 2x2 matrix can be
9-
built. This is not required for the package, as it is header only, but it
10-
will provide informative error messages if the Armadillo library is not
11-
compatible with the C++ compiler.
6+
* The goal is to address the Fedora errors reported yesterday. This update adds
7+
a new configure file to adhere to the previously requested checks.
128

0 commit comments

Comments
 (0)