Skip to content

Commit b20fafe

Browse files
committed
fixed cran comments
1 parent 9afdae7 commit b20fafe

7 files changed

Lines changed: 19 additions & 46 deletions

File tree

R/RcppExports.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ predict_iForest_sparse_nodes <- function(x, Model) {
1313
.Call('_isofor_predict_iForest_sparse_nodes', PACKAGE = 'isofor', x, Model)
1414
}
1515

16-
predict_iForest_pathlength_cpp <- function(df, Model, n_cores) {
17-
.Call('_isofor_predict_iForest_pathlength_cpp', PACKAGE = 'isofor', df, Model, n_cores)
16+
predict_iForest_pathlength_cpp <- function(df, Model) {
17+
.Call('_isofor_predict_iForest_pathlength_cpp', PACKAGE = 'isofor', df, Model)
1818
}
1919

R/predict.R

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
#'
88
#' @param newdata a data.frame to predict
99
#' @param ... optional arguments not used.
10-
#' @param n.cores number of cores to use for prediction of anomaly score. Must
11-
#' be compiled with openmp. Defaults to 1.
1210
#' @param nodes if true return nobs x ntrees dim matrix with terminal node ids
1311
#' @param sparse if true return sparse Matrix of dimension nobs x nTerminalNodes.
1412
#' Each column represents a terminal node. There are as many ones in each row
@@ -23,14 +21,14 @@
2321
#' correspond to more isolated observations. If sparse or nodes are set to TRUE,
2422
#' a matrix of the requested type is returned.
2523
#' @examples
26-
#' \donttest{
2724
#' mod <- iForest(iris, phi=16, nt=5)
2825
#' score <- predict(mod, newdata = iris)
29-
#' }
26+
#' @return A numeric vector of length \code{nrow(newdata)} containing values between zero and one.
27+
#' Values closer to zero are less likely to be anomalous.
3028
#' @import Matrix
3129
#' @importFrom parallel detectCores
3230
#' @export
33-
predict.iForest <- function(object, newdata, ..., n.cores=1, nodes = FALSE, sparse = FALSE, replace_missing=TRUE, sentinel=-9999999999) {
31+
predict.iForest <- function(object, newdata, ..., nodes = FALSE, sparse = FALSE, replace_missing=TRUE, sentinel=-9999999999) {
3432

3533
if (!is.data.frame(newdata)) newdata <- as.data.frame(newdata)
3634

@@ -71,7 +69,6 @@ predict.iForest <- function(object, newdata, ..., n.cores=1, nodes = FALSE, spar
7169
} else if (nodes) {
7270
predict_iForest_nodes_cpp(newdata, object)
7371
} else {
74-
num_cores = as.integer(max(1, min(n.cores, detectCores())))
75-
predict_iForest_pathlength_cpp(newdata, object, num_cores)
72+
predict_iForest_pathlength_cpp(newdata, object)
7673
}
7774
}

README.md

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,5 @@
11
[![Build Status](https://travis-ci.org/Zelazny7/isofor.svg?branch=master)](https://travis-ci.org/Zelazny7/isofor)
22

3-
Installation with openmp on osx
4-
-------------------
5-
6-
```
7-
brew install llvm
8-
```
9-
10-
And then edit your ~/.R/Makevars file to look like so:
11-
12-
```
13-
CXX = /usr/local/opt/llvm/bin/clang
14-
CXXFLAGS = -I/usr/local/opt/llvm/include -fopenmp
15-
LDFLAGS = -L/usr/local/opt/llvm/lib -fopenmp=libiomp5
16-
```
173

184
Isolation Forest
195
----------------

cran-comments.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@ There were no ERRORs or WARNINGs or NOTEs.
1515
* removed dontrun directive in predict method examples
1616
* added donttest directive per CRAN suggestion -- passes windows now
1717
* fixed typo in DESCRIPTION - "implemenation -> implementation"
18+
* added return value description for predict method
19+
* removed OMP so examples pass on i386
1820

man/predict.iForest.Rd

Lines changed: 6 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/RcppExports.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,14 @@ BEGIN_RCPP
4444
END_RCPP
4545
}
4646
// predict_iForest_pathlength_cpp
47-
SEXP predict_iForest_pathlength_cpp(SEXP df, List Model, SEXP n_cores);
48-
RcppExport SEXP _isofor_predict_iForest_pathlength_cpp(SEXP dfSEXP, SEXP ModelSEXP, SEXP n_coresSEXP) {
47+
SEXP predict_iForest_pathlength_cpp(SEXP df, List Model);
48+
RcppExport SEXP _isofor_predict_iForest_pathlength_cpp(SEXP dfSEXP, SEXP ModelSEXP) {
4949
BEGIN_RCPP
5050
Rcpp::RObject rcpp_result_gen;
5151
Rcpp::RNGScope rcpp_rngScope_gen;
5252
Rcpp::traits::input_parameter< SEXP >::type df(dfSEXP);
5353
Rcpp::traits::input_parameter< List >::type Model(ModelSEXP);
54-
Rcpp::traits::input_parameter< SEXP >::type n_cores(n_coresSEXP);
55-
rcpp_result_gen = Rcpp::wrap(predict_iForest_pathlength_cpp(df, Model, n_cores));
54+
rcpp_result_gen = Rcpp::wrap(predict_iForest_pathlength_cpp(df, Model));
5655
return rcpp_result_gen;
5756
END_RCPP
5857
}
@@ -61,7 +60,7 @@ static const R_CallMethodDef CallEntries[] = {
6160
{"_isofor_nodes_cpp", (DL_FUNC) &_isofor_nodes_cpp, 4},
6261
{"_isofor_predict_iForest_nodes_cpp", (DL_FUNC) &_isofor_predict_iForest_nodes_cpp, 2},
6362
{"_isofor_predict_iForest_sparse_nodes", (DL_FUNC) &_isofor_predict_iForest_sparse_nodes, 2},
64-
{"_isofor_predict_iForest_pathlength_cpp", (DL_FUNC) &_isofor_predict_iForest_pathlength_cpp, 3},
63+
{"_isofor_predict_iForest_pathlength_cpp", (DL_FUNC) &_isofor_predict_iForest_pathlength_cpp, 2},
6564
{NULL, NULL, 0}
6665
};
6766

src/predict_omp.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55
#include <math.h>
66
#include "predict.h"
77

8-
#ifdef _OPENMP
9-
#include <omp.h>
10-
#endif
11-
128
using namespace Rcpp;
139

1410
// Enumeration helpers corresponding to matrix columns or list indices
@@ -123,7 +119,6 @@ void predict_pathlength_cpp(SEXP df, SEXP Tree, double * out, int * current_node
123119
}
124120
} while(!all_terminal);
125121

126-
#pragma omp critical
127122
for (int i = 0; i < df_nrows; i++) {
128123
double size = GET_TREE_ATTR(Tree, Size, current_node[i], nrows);
129124
out[i] += (depth[i] + cn(size)) / n_trees;
@@ -141,25 +136,22 @@ void predict_pathlength_cpp(SEXP df, SEXP Tree, double * out, int * current_node
141136
*/
142137

143138
// [[Rcpp::export]]
144-
SEXP predict_iForest_pathlength_cpp(SEXP df, List Model, SEXP n_cores) {
139+
SEXP predict_iForest_pathlength_cpp(SEXP df, List Model) {
145140

146141
int df_nrows = LENGTH(VECTOR_ELT(df, 0));
147142
int n_trees = INTEGER(Model[NTREES])[0];
148143

149144
double * pl = (double *) calloc(df_nrows, sizeof pl);
150145

151-
#pragma omp parallel num_threads(INTEGER(n_cores)[0])
152146
{
153147

154148
int * current_node = (int *) calloc(df_nrows, sizeof current_node);
155149
int * depth = (int *) calloc(df_nrows, sizeof depth);
156150

157-
#pragma omp for
158151
for (int i = 0; i < n_trees; i++) {
159152
predict_pathlength_cpp(df, VECTOR_ELT(Model[FOREST], i), pl, current_node, depth, n_trees);
160153
}
161154

162-
#pragma omp critical
163155
free(current_node);
164156
free(depth);
165157
}
@@ -169,7 +161,6 @@ SEXP predict_iForest_pathlength_cpp(SEXP df, List Model, SEXP n_cores) {
169161

170162
double avg = cn(INTEGER(Model[PHI])[0]);
171163

172-
#pragma omp parallel for
173164
for( int i = 0; i < df_nrows; i++ ) {
174165
REAL(res)[i] = pow(2, -1 * pl[i] / avg);
175166
}

0 commit comments

Comments
 (0)