Skip to content

Commit 846596b

Browse files
rootQiang Kou
authored andcommitted
Fix #18 and for cran
1 parent 56edfed commit 846596b

5 files changed

Lines changed: 18 additions & 39 deletions

File tree

inst/include/RcppMLPACK.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
11
#ifndef RcppMLPACK__RcppMLPACK__h
22
#define RcppMLPACK__RcppMLPACK__h
33

4-
#if _WIN64
5-
#ifndef ARMA_64BIT_WORD
6-
#define ARMA_64BIT_WORD
7-
#endif
8-
#endif
9-
104
#include <mlpack/core.hpp>
11-
125
#include <mlpack/core/kernels/cosine_distance.hpp>
136
#include <mlpack/core/kernels/epanechnikov_kernel.hpp>
147
#include <mlpack/core/kernels/gaussian_kernel.hpp>
@@ -66,10 +59,10 @@
6659
#include <mlpack/methods/lsh/lsh_search.hpp>
6760
#include <mlpack/methods/local_coordinate_coding/lcc.hpp>
6861
#include <mlpack/methods/mvu/mvu.hpp>
69-
//#include <mlpack/methods/naive_bayes/naive_bayes_classifier.hpp>
7062
#include <mlpack/methods/nca/nca.hpp>
7163
#include <mlpack/methods/neighbor_search/neighbor_search.hpp>
7264
#include <mlpack/methods/neighbor_search/unmap.hpp>
65+
#include <mlpack/methods/neighbor_search/typedef.hpp>
7366
#include <mlpack/methods/nystroem_method/ordered_selection.hpp>
7467
#include <mlpack/methods/nystroem_method/random_selection.hpp>
7568
#include <mlpack/methods/nystroem_method/kmeans_selection.hpp>

man/mlKmeans.Rd

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ mlKmeans(X, y)
2424
For MLPACK: Ryan Curtin
2525
}
2626
\examples{
27-
\dontrun{
2827
data(trees, package="datasets")
2928
mlKmeans(t(trees),3)
3029
}
31-
}

src/RcppExports.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,14 @@
44
using namespace Rcpp;
55

66
// kmeans
7-
List kmeans(const arma::mat& data, const int& clusters);
7+
List kmeans(SEXP data, const int& clusters);
88
RcppExport SEXP RcppMLPACK_kmeans(SEXP dataSEXP, SEXP clustersSEXP) {
99
BEGIN_RCPP
10-
SEXP __sexp_result;
11-
{
12-
Rcpp::RNGScope __rngScope;
13-
Rcpp::traits::input_parameter< const arma::mat& >::type data(dataSEXP );
14-
Rcpp::traits::input_parameter< const int& >::type clusters(clustersSEXP );
15-
List __result = kmeans(data, clusters);
16-
PROTECT(__sexp_result = Rcpp::wrap(__result));
17-
}
18-
UNPROTECT(1);
19-
return __sexp_result;
10+
Rcpp::RObject rcpp_result_gen;
11+
Rcpp::RNGScope rcpp_rngScope_gen;
12+
Rcpp::traits::input_parameter< SEXP >::type data(dataSEXP);
13+
Rcpp::traits::input_parameter< const int& >::type clusters(clustersSEXP);
14+
rcpp_result_gen = Rcpp::wrap(kmeans(data, clusters));
15+
return rcpp_result_gen;
2016
END_RCPP
2117
}

src/RcppMLPACK.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
11
#ifndef RcppMLPACK__RcppMLPACK__h
22
#define RcppMLPACK__RcppMLPACK__h
33

4-
#if _WIN64
5-
#ifndef ARMA_64BIT_WORD
6-
#define ARMA_64BIT_WORD
7-
#endif
8-
#endif
9-
10-
#if defined(__MINGW32__)
11-
#define ARMA_DONT_USE_CXX11
12-
#endif
13-
144
#include <mlpack/core.hpp>
155
#include <mlpack/core/kernels/cosine_distance.hpp>
166
#include <mlpack/core/kernels/epanechnikov_kernel.hpp>

src/kmeans.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@ using namespace mlpack::kmeans;
44
using namespace Rcpp;
55

66
// [[Rcpp::export]]
7-
List kmeans(const arma::mat& data, const int& clusters) {
8-
9-
arma::Col<size_t> assignments;
7+
List kmeans(SEXP data, const int& clusters) {
108

11-
// Initialize with the default arguments.
12-
KMeans<> k;
9+
NumericMatrix Xr(data);
10+
arma::mat X(Xr.begin(), Xr.nrow(), Xr.ncol(), false);
11+
arma::Col<size_t> assignments;
1312

14-
k.Cluster(data, clusters, assignments);
13+
// Initialize with the default arguments.
14+
KMeans<> k;
1515

16-
return List::create(_["clusters"] = clusters,
17-
_["result"] = assignments);
16+
k.Cluster(X, clusters, assignments);
17+
18+
return List::create(_["clusters"] = clusters,
19+
_["result"] = assignments);
1820
}

0 commit comments

Comments
 (0)