From 24b6fc39a472ea86f08d6a3aa95bb9813ffd3ff7 Mon Sep 17 00:00:00 2001 From: Edward Liu Date: Mon, 7 Oct 2024 11:21:03 -0400 Subject: [PATCH] Set CXX_USE_NO_REMAP flag to True --- src/Makevars | 2 +- src/Makevars.win | 4 +- src/matching.cc | 104 ++++++++++++++++++++++---------------------- src/scythematrix.cc | 94 +++++++++++++++++++-------------------- src/scythematrix.h | 4 +- 5 files changed, 104 insertions(+), 104 deletions(-) diff --git a/src/Makevars b/src/Makevars index cae5bc2..ca46c07 100644 --- a/src/Makevars +++ b/src/Makevars @@ -1,3 +1,3 @@ ## Set package flags rather than creating a file PKG_CFLAGS = -DR_BUILD -PKG_CPPFLAGS = -DR_BUILD +PKG_CPPFLAGS = -DR_BUILD -DR_NO_REMAP diff --git a/src/Makevars.win b/src/Makevars.win index 9548d03..1834213 100644 --- a/src/Makevars.win +++ b/src/Makevars.win @@ -1,3 +1,3 @@ PKG_CFLAGS = -O3 -finline-functions -funswitch-loops -fgcse-after-reload -funroll-loops -PKG_CXXFLAGS = -O3 -finline-functions -funswitch-loops -fgcse-after-reload -funroll-loops -PKG_LIBS = $(BLAS_LIBS) +PKG_CXXFLAGS = -O3 -finline-functions -funswitch-loops -fgcse-after-reload -funroll-loops -DR_NO_REMAP +PKG_LIBS = $(BLAS_LIBS) \ No newline at end of file diff --git a/src/matching.cc b/src/matching.cc index ad65f73..a588c93 100644 --- a/src/matching.cc +++ b/src/matching.cc @@ -199,9 +199,9 @@ extern "C" SumFoo = 0;//Initialize sumFoo to make sure it is initialized when we branch - N = asInteger(I_N); - All = asInteger(I_All); - length = asInteger(I_length); + N = Rf_asInteger(I_N); + All = Rf_asInteger(I_All); + length = Rf_asInteger(I_length); // In vars Matrix Tr = Matrix(N, 1); @@ -300,7 +300,7 @@ extern "C" }// end of master N loop - PROTECT(ret=allocMatrix(REALSXP, N, 3)); + PROTECT(ret=Rf_allocMatrix(REALSXP, N, 3)); // stack up cbind(YCAUS, Kcount, KKcount) k = 0; @@ -374,11 +374,11 @@ extern "C" long i, j, k; - N = asInteger(I_N); - xvars = asInteger(I_xvars); - All = asInteger(I_All); - M = asInteger(I_M); - cdd = asReal(I_cdd); + N = Rf_asInteger(I_N); + xvars = Rf_asInteger(I_xvars); + All = Rf_asInteger(I_All); + M = Rf_asInteger(I_M); + cdd = Rf_asReal(I_cdd); Matrix ww = Matrix(xvars, xvars); Matrix Tr = Matrix(N, 1); @@ -534,7 +534,7 @@ extern "C" { Rprintf("Increasing memory because of ties: allocating a matrix of size 3 times %d doubles.\n", NM); Rprintf("I would be faster with the ties=FALSE option.\n"); - warning("Increasing memory because of ties. I would be faster with the ties=FALSE option."); + Rf_warning("Increasing memory because of ties. I would be faster with the ties=FALSE option."); } int OldMatchCount = MatchCount - (int) Mi; @@ -653,7 +653,7 @@ extern "C" } */ - PROTECT(ret=allocMatrix(REALSXP, MatchCount, 3)); + PROTECT(ret=Rf_allocMatrix(REALSXP, MatchCount, 3)); /* Loop through the data and display the same in matrix format */ k = 0; for( j = 0; j < MatchCount; j++, k++) @@ -726,11 +726,11 @@ extern "C" long i, j, k; - N = asInteger(I_N); - xvars = asInteger(I_xvars); - All = asInteger(I_All); - M = asInteger(I_M); - cdd = asReal(I_cdd); + N = Rf_asInteger(I_N); + xvars = Rf_asInteger(I_xvars); + All = Rf_asInteger(I_All); + M = Rf_asInteger(I_M); + cdd = Rf_asReal(I_cdd); Matrix ww = Matrix(xvars, xvars); @@ -969,7 +969,7 @@ extern "C" free(order_DistPot); i = I.rowsize; - PROTECT(ret=allocMatrix(REALSXP, i, 3)); + PROTECT(ret=Rf_allocMatrix(REALSXP, i, 3)); /* Loop through the data and display the same in matrix format */ k = 0; for( j = 0; j < i; j++, k++) @@ -1061,17 +1061,17 @@ extern "C" long i, j, k, r, c; - N = asInteger(I_N); - xvars = asInteger(I_xvars); - All = asInteger(I_All); - M = asInteger(I_M); - cdd = asReal(I_cdd); - caliper = (long) asReal(I_caliper); - replace = asInteger(I_replace); - ties = asInteger(I_ties); - restrict_nrow = asInteger(I_restrict_nrow); - restrict_trigger = asInteger(I_restrict_trigger); - DiagWeightMatrixFlag = asInteger(I_DiagWeightMatrixFlag); + N = Rf_asInteger(I_N); + xvars = Rf_asInteger(I_xvars); + All = Rf_asInteger(I_All); + M = Rf_asInteger(I_M); + cdd = Rf_asReal(I_cdd); + caliper = (long) Rf_asReal(I_caliper); + replace = Rf_asInteger(I_replace); + ties = Rf_asInteger(I_ties); + restrict_nrow = Rf_asInteger(I_restrict_nrow); + restrict_trigger = Rf_asInteger(I_restrict_trigger); + DiagWeightMatrixFlag = Rf_asInteger(I_DiagWeightMatrixFlag); Matrix ww = Matrix(xvars, xvars); Matrix Tr = Matrix(N, 1); @@ -1581,7 +1581,7 @@ extern "C" r = rows(rr); c = cols(rr); - PROTECT(ret=allocMatrix(REALSXP, r, c)); + PROTECT(ret=Rf_allocMatrix(REALSXP, r, c)); /* Loop through the data and display the same in matrix format */ k = 0; for( i = 0; i < c; i++ ) @@ -1671,17 +1671,17 @@ extern "C" long i, j, k, r, c; - N = asInteger(I_N); - xvars = asInteger(I_xvars); - All = asInteger(I_All); - M = asInteger(I_M); - cdd = asReal(I_cdd); - caliper = (long) asReal(I_caliper); - replace = asInteger(I_replace); - ties = asInteger(I_ties); - restrict_nrow = asInteger(I_restrict_nrow); - restrict_trigger = asInteger(I_restrict_trigger); - DiagWeightMatrixFlag = asInteger(I_DiagWeightMatrixFlag); + N = Rf_asInteger(I_N); + xvars = Rf_asInteger(I_xvars); + All = Rf_asInteger(I_All); + M = Rf_asInteger(I_M); + cdd = Rf_asReal(I_cdd); + caliper = (long) Rf_asReal(I_caliper); + replace = Rf_asInteger(I_replace); + ties = Rf_asInteger(I_ties); + restrict_nrow = Rf_asInteger(I_restrict_nrow); + restrict_trigger = Rf_asInteger(I_restrict_trigger); + DiagWeightMatrixFlag = Rf_asInteger(I_DiagWeightMatrixFlag); Matrix ww = Matrix(xvars, xvars); Matrix Tr = Matrix(N, 1); @@ -2072,7 +2072,7 @@ extern "C" { Rprintf("Increasing memory because of ties: allocating a matrix of size 3 times %d doubles.\n", NM); Rprintf("I would be faster with the ties=FALSE option.\n"); - warning("Increasing memory because of ties. I would be faster with the ties=FALSE option."); + Rf_warning("Increasing memory because of ties. I would be faster with the ties=FALSE option."); } else { @@ -2208,7 +2208,7 @@ extern "C" r = rows(rr); c = cols(rr); - PROTECT(ret=allocMatrix(REALSXP, r, c)); + PROTECT(ret=Rf_allocMatrix(REALSXP, r, c)); /* Loop through the data and display the same in matrix format */ k = 0; for( i = 0; i < c; i++ ) @@ -2288,14 +2288,14 @@ extern "C" long i, j, k; - N = asInteger(I_N); - xvars = asInteger(I_xvars); - M = asInteger(I_M); - cdd = asReal(I_cdd); - caliper = (long) asReal(I_caliper); - restrict_nrow = asInteger(I_restrict_nrow); - restrict_trigger = asInteger(I_restrict_trigger); - DiagWeightMatrixFlag = asInteger(I_DiagWeightMatrixFlag); + N = Rf_asInteger(I_N); + xvars = Rf_asInteger(I_xvars); + M = Rf_asInteger(I_M); + cdd = Rf_asReal(I_cdd); + caliper = (long) Rf_asReal(I_caliper); + restrict_nrow = Rf_asInteger(I_restrict_nrow); + restrict_trigger = Rf_asInteger(I_restrict_trigger); + DiagWeightMatrixFlag = Rf_asInteger(I_DiagWeightMatrixFlag); Matrix ww = Matrix(xvars, xvars); Matrix Tr = Matrix(N, 1); @@ -2379,7 +2379,7 @@ extern "C" } Matrix weight, weightPot, tt, weightPot_sort, weightPot_sum, foo1, foo2; - int weightFlag = asInteger(I_weightFlag); + int weightFlag = Rf_asInteger(I_weightFlag); if(weightFlag==1) { weight = Matrix::zeros(N, 1); @@ -2705,7 +2705,7 @@ extern "C" free(S); free(order_DistPot); - PROTECT(ret=allocMatrix(REALSXP, N, 1)); + PROTECT(ret=Rf_allocMatrix(REALSXP, N, 1)); /* Loop through the data and display the same in matrix format */ for( j = 0; j < N; j++ ) { diff --git a/src/scythematrix.cc b/src/scythematrix.cc index 789e844..fa1b340 100644 --- a/src/scythematrix.cc +++ b/src/scythematrix.cc @@ -79,7 +79,7 @@ namespace SCYTHE { // #ifdef __NATE__ Matrix::Matrix (const int& rows, const int& cols) { if (rows < 1 || cols < 1) { - error("Improper row or column dimension in Matrix constructor"); + Rf_error("Improper row or column dimension in Matrix constructor"); } rowsize = rows; // assign Matrix rowsize colsize = cols; // assign Matrix colsize @@ -101,7 +101,7 @@ namespace SCYTHE { Matrix::Matrix (const double *inputarray, const int& rows, const int& cols) { if (rows < 1 || cols < 1) { - error("Improper row or column dimension in Matrix constructor"); + Rf_error("Improper row or column dimension in Matrix constructor"); } rowsize = rows; // assign Matrix rowsize colsize = cols; // assign Matrix colsize @@ -177,7 +177,7 @@ namespace SCYTHE { Matrix::operator () (const int& i, const all_elements& a) { if (i >= rowsize || i < 0) { - error("Index out of range in () operator"); + Rf_error("Index out of range in () operator"); } int newrowsize = 1; @@ -208,7 +208,7 @@ namespace SCYTHE { Matrix::operator () (const all_elements& a, const int& j) { if (j >= colsize || j < 0) { - error("Index out of range in () operator"); + Rf_error("Index out of range in () operator"); } int newrowsize = rowsize; @@ -239,11 +239,11 @@ namespace SCYTHE { { if (i >= rowsize || i < 0) { - error("Index out of range in () operator"); + Rf_error("Index out of range in () operator"); } if (J.colsize != 1 && J.rowsize != 1) { - error("Either rows or cols of J != 1 in () operator"); + Rf_error("Either rows or cols of J != 1 in () operator"); } int newrowsize = 1; @@ -254,7 +254,7 @@ namespace SCYTHE { for (int j = 0; j < newcolsize; ++j) { int index = static_cast < int >(J.data[j]); if (index >= colsize || index < 0) { - error("Index out of range in () operator"); + Rf_error("Index out of range in () operator"); } index = index + i * colsize; newdata.data[j] = data[index]; @@ -279,11 +279,11 @@ namespace SCYTHE { { if (j >= colsize || j < 0) { - error("Index out of range in () operator"); + Rf_error("Index out of range in () operator"); } if (I.colsize != 1 && I.rowsize != 1) { - error("Either rows or cols of I != 1 in () operator"); + Rf_error("Either rows or cols of I != 1 in () operator"); } int newrowsize = I.size; @@ -293,7 +293,7 @@ namespace SCYTHE { for (int i = 0; i < newrowsize; ++i) { int index = static_cast < int >(I.data[i]); if (index >= rowsize || index < 0) { - error("Index out of range in () operator"); + Rf_error("Index out of range in () operator"); } index = j + index * colsize; newdata.data[i] = data[index]; @@ -321,16 +321,16 @@ namespace SCYTHE { Matrix Matrix::operator () (const Matrix& I, const Matrix& J){ if (I.colsize != 1 && I.rowsize != 1) { - error("Either Rows or Cols of I != 1 in () operator"); + Rf_error("Either Rows or Cols of I != 1 in () operator"); } if (J.colsize != 1 && J.rowsize != 1) { - error("Either rows or cols of J != 1 in () operator"); + Rf_error("Either rows or cols of J != 1 in () operator"); } if (I.size > rowsize){ - error("size(I) > rowsize of Matrix in Matrix operator ()"); + Rf_error("size(I) > rowsize of Matrix in Matrix operator ()"); } if (J.size > colsize){ - error("size(J) > colsize of Matrix in Matrix operator ()"); + Rf_error("size(J) > colsize of Matrix in Matrix operator ()"); } int place = 0; @@ -342,10 +342,10 @@ namespace SCYTHE { indexi = static_cast < int > (I.data[i]); indexj = static_cast < int > (J.data[j]); if (indexi >= rowsize || indexi < 0) { - error("Row index out of range in () operator"); + Rf_error("Row index out of range in () operator"); } if (indexj >= colsize || indexj < 0) { - error("Column index out of range in () operator"); + Rf_error("Column index out of range in () operator"); } newdata.data[place] = data[indexi * colsize + indexj]; place++; @@ -1038,7 +1038,7 @@ Matrix t (const Matrix & old_matrix) Matrix Matrix::ones (const int& rows, const int& cols) { if (rows < 1 || cols < 1) { - error("improper row or column dimension in ones()"); + Rf_error("improper row or column dimension in ones()"); } Matrix newdata(rows, cols); int size = rows * cols; @@ -1061,7 +1061,7 @@ Matrix t (const Matrix & old_matrix) Matrix Matrix::zeros (const int& rows, const int& cols) { if (rows < 1 || cols < 1) { - error("Error 0018: improper row or column dimension in ones()"); + Rf_error("Error 0018: improper row or column dimension in ones()"); } Matrix temp(rows, cols); // ctor zeros data return temp; @@ -1197,10 +1197,10 @@ Matrix Matrix::seqa (const double& start, const double& incr, const int& size) Matrix PA = A; Matrix p = pp; if (p.colsize != 1){ - error("Vector p not a column vector in row_interchange()"); + Rf_error("Vector p not a column vector in row_interchange()"); } if ( (p.rowsize +1) != A.rowsize){ - error("Matrices A and p not of consistent sizes in row_interchange()"); + Rf_error("Matrices A and p not of consistent sizes in row_interchange()"); } for (int i=0; i<(A.rowsize-1); ++i){ @@ -1228,7 +1228,7 @@ Matrix Matrix::seqa (const double& start, const double& incr, const int& size) Matrix inv (const Matrix & AA) { if (AA.rowsize != AA.colsize){ - error("Matrix A not square in SCYTHE::inv()"); + Rf_error("Matrix A not square in SCYTHE::inv()"); } Matrix b = Matrix (AA.rowsize, 1); @@ -1255,7 +1255,7 @@ Matrix Matrix::seqa (const double& start, const double& incr, const int& size) } if(A(pivot,k) == 0.0){ - error("Matrix A is singular in SCYTHE::inv()"); + Rf_error("Matrix A is singular in SCYTHE::inv()"); } // permute @@ -1334,7 +1334,7 @@ Matrix Matrix::seqa (const double& start, const double& incr, const int& size) Matrix A = AA; if (A.rowsize != A.colsize){ - error("Matrix A not square in SCYTHE::det()"); + Rf_error("Matrix A not square in SCYTHE::det()"); } if(A.rowsize == 1) @@ -1390,7 +1390,7 @@ Matrix Matrix::seqa (const double& start, const double& incr, const int& size) Matrix cbind (const Matrix & A, const Matrix & B) { if (A.rowsize != B.rowsize) { - error("Matrices A and B do not have some number of rows in SCYTHE::cbind()"); + Rf_error("Matrices A and B do not have some number of rows in SCYTHE::cbind()"); } int totalcols = A.colsize + B.colsize; @@ -1419,7 +1419,7 @@ Matrix Matrix::seqa (const double& start, const double& incr, const int& size) Matrix rbind (const Matrix & A, const Matrix & B) { if (A.colsize != B.colsize) { - error("Matrices A and B do not have some number of cols in SCYTHE::rbind()"); + Rf_error("Matrices A and B do not have some number of cols in SCYTHE::rbind()"); } int totalrows = A.rowsize + B.rowsize; @@ -1793,7 +1793,7 @@ Matrix sumc (const Matrix & A) */ Matrix order(const Matrix& A){ if (A.colsize != 1){ - error("Matrix A not a column vector in SCYTHE::order()"); + Rf_error("Matrix A not a column vector in SCYTHE::order()"); } Matrix newdata(A.rowsize, 1); @@ -1817,12 +1817,12 @@ Matrix sumc (const Matrix & A) // check to see if rowsize matches if (A.rowsize != e.rowsize){ - error("Matrices not conformable in SCYTHE::selif()"); + Rf_error("Matrices not conformable in SCYTHE::selif()"); } // check to see if e is a column vector if (e.colsize > 1){ - error("Not a column vector in SCYTHE::selif()"); + Rf_error("Not a column vector in SCYTHE::selif()"); } // loop to check if e contains binary data, and count number @@ -1830,7 +1830,7 @@ Matrix sumc (const Matrix & A) int N = 0; for (int i=0; i(0.5*(A.size - A.rowsize) + A.rowsize); @@ -1958,7 +1958,7 @@ Matrix sumc (const Matrix & A) Matrix xpnd(const Matrix& A){ double newrowsize_d = -.5 + .5*std::sqrt(1+8*A.size); if (fmod(newrowsize_d,1.0) != 0.0){ - error("Not possible to make square Matrix out of input Matrix to SCYTHE::xpnd()"); + Rf_error("Not possible to make square Matrix out of input Matrix to SCYTHE::xpnd()"); } int newrowsize = static_cast(newrowsize_d); Matrix newdata(newrowsize, newrowsize); @@ -1982,7 +1982,7 @@ Matrix sumc (const Matrix & A) */ Matrix diag(const Matrix& A){ if (A.rowsize != A.colsize){ - error("Matrix is not square in SCYTHE::diag()"); + Rf_error("Matrix is not square in SCYTHE::diag()"); } Matrix newdata(A.rowsize, 1); for (int i=0; i> (const Matrix& A, const Matrix& B){ if (A.rowsize != B.rowsize && A.colsize != B.colsize && (B.size > 1)){ - error("Matrices not conformable for >> operator"); + Rf_error("Matrices not conformable for >> operator"); } if (A.rowsize == B.rowsize && A.colsize == B.colsize){ @@ -2479,7 +2479,7 @@ Matrix sumc (const Matrix & A) } return newdata; } else { - error("Matrices not conformable for >> operator"); + Rf_error("Matrices not conformable for >> operator"); } } @@ -2505,7 +2505,7 @@ Matrix sumc (const Matrix & A) */ Matrix operator << (const Matrix& A, const Matrix& B){ if (A.rowsize != B.rowsize && A.colsize != B.colsize && (B.size > 1)){ - error("Matrices not conformable for << operator"); + Rf_error("Matrices not conformable for << operator"); } if (A.rowsize == B.rowsize && A.colsize == B.colsize){ @@ -2545,7 +2545,7 @@ Matrix sumc (const Matrix & A) } else { - error("Matrices not conformable for << operator"); + Rf_error("Matrices not conformable for << operator"); } } @@ -2573,7 +2573,7 @@ Matrix sumc (const Matrix & A) */ Matrix operator ^= (const Matrix& A, const Matrix& B){ if (A.rowsize != B.rowsize && A.colsize != B.colsize && (B.size > 1)){ - error("Matrices not conformable for ^= operator"); + Rf_error("Matrices not conformable for ^= operator"); } if (A.rowsize == B.rowsize && A.colsize == B.colsize){ @@ -2613,7 +2613,7 @@ Matrix sumc (const Matrix & A) } else { - error("Matrices not conformable for ^= operator"); + Rf_error("Matrices not conformable for ^= operator"); } } diff --git a/src/scythematrix.h b/src/scythematrix.h index 675ac48..a4b0c27 100644 --- a/src/scythematrix.h +++ b/src/scythematrix.h @@ -163,7 +163,7 @@ class Matrix inline double &operator[] (const int& i) { if (i >= size || i < 0) { - error("Index out of range in [] operator"); + Rf_error("Index out of range in [] operator"); } return (data[i]); } @@ -181,7 +181,7 @@ class Matrix inline double &operator () (const int& i, const int& j) { if (rowsize < i || colsize < j || i < 0 || j < 0) { - error("Index out of range in () operator"); + Rf_error("Index out of range in () operator"); } return data[i * colsize + j]; }