Skip to content

Commit

Permalink
Fix #563
Browse files Browse the repository at this point in the history
Additionally fixed tset dataset
  • Loading branch information
kudkudak committed Aug 31, 2015
1 parent c7f7c64 commit d907801
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 49 deletions.
Binary file modified data/cec.tset.RData
Binary file not shown.
85 changes: 45 additions & 40 deletions inst/include/cec/cluster_params.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,56 +5,61 @@

#ifdef RCPP_INTERFACE
#include <RcppArmadillo.h>
using namespace Rcpp;
using namespace arma;
#else
#include <armadillo>
using namespace arma;
#endif

namespace gmum {

enum ClusterType {
kstandard, kfixed_covariance, kdiagonal, kfixed_spherical, kspherical, kno_type, kmix, kcustom
};
enum ClusterType {
kstandard, kfixed_covariance, kdiagonal, kfixed_spherical, kspherical, kno_type, kmix, kcustom
};

/**
* You need to store somewhere data about cluster. Each type can have its own.
*/
struct ClusterParams {
ClusterType type;
ClusterParams(ClusterType _type) :
type(_type) {
}
virtual ~ClusterParams() { };
};

struct ClusterFixedCovarianceParams : public ClusterParams {
bool cov_mat_set;
arma::mat cov_mat;
ClusterFixedCovarianceParams(arma::mat _cov_mat) :
ClusterParams(kfixed_covariance), cov_mat_set(true), cov_mat(_cov_mat) {
}
ClusterFixedCovarianceParams() :
ClusterParams(kfixed_covariance), cov_mat_set(false) {
}
virtual ~ClusterFixedCovarianceParams() { }
};

struct ClusterSphericalFixedRParams : public ClusterParams {
bool radius_set;
double radius;
ClusterSphericalFixedRParams(double _radius) :
ClusterParams(kfixed_spherical), radius_set(true), radius(_radius) {
}
ClusterSphericalFixedRParams() :
ClusterParams(kfixed_spherical), radius_set(false) {
}
virtual ~ClusterSphericalFixedRParams() { }
};
struct ClusterParams {
ClusterType type;
ClusterParams(ClusterType _type) :
type(_type) {
}
virtual ~ClusterParams() { };
};

struct ClusterFixedCovarianceParams : public ClusterParams {
bool cov_mat_set;
mat cov_mat;
ClusterFixedCovarianceParams(mat _cov_mat) :
ClusterParams(kfixed_covariance), cov_mat_set(true), cov_mat(_cov_mat) {
}
ClusterFixedCovarianceParams() :
ClusterParams(kfixed_covariance), cov_mat_set(false) {
}
virtual ~ClusterFixedCovarianceParams() { }
};

struct ClusterSphericalFixedRParams : public ClusterParams {
bool radius_set;
double radius;
ClusterSphericalFixedRParams(double _radius) :
ClusterParams(kfixed_spherical), radius_set(true), radius(_radius) {
}
ClusterSphericalFixedRParams() :
ClusterParams(kfixed_spherical), radius_set(false) {
}
virtual ~ClusterSphericalFixedRParams() { }
};

#ifdef RCPP_INTERFACE
struct ClusterCustomParams: public ClusterParams {
boost::shared_ptr<Rcpp::Function> function;
ClusterCustomParams(boost::shared_ptr<Rcpp::Function> _function) : ClusterParams(kcustom), function(_function) {}
ClusterCustomParams() : ClusterParams(kcustom) {}
virtual ~ClusterCustomParams() { }
};
struct ClusterCustomParams: public ClusterParams {
boost::shared_ptr<Rcpp::Function> function;
ClusterCustomParams(boost::shared_ptr<Rcpp::Function> _function) : ClusterParams(kcustom), function(_function) {}
ClusterCustomParams() : ClusterParams(kcustom) {}
virtual ~ClusterCustomParams() { }
};
#endif

}
Expand Down
8 changes: 4 additions & 4 deletions inst/include/utils/cutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
#define C_FPRINTF(stream, string, ...)
#define C_PRINTF(string, ...)
#else
#define C_EXIT(x) exit(x);
#define C_FFLUSH(stream) fflush(stream);
#define C_FPRINTF(stream, string, ...) fprintf(stream, string, __VA_ARGS__);
#define C_PRINTF(string, ...) printf(string, __VA_ARGS__);
#define C_EXIT(x)
#define C_FFLUSH(stream)
#define C_FPRINTF(stream, string, ...)
#define C_PRINTF(string, ...)
#endif

#endif
6 changes: 5 additions & 1 deletion inst/include/utils/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@
#include <iostream>
#include <string>
#include <sstream>
#include "threading.h"

#ifdef RCPP_INTERFACE
#include <RcppArmadillo.h>
#include "threading.h"
// TODO: remove it
using namespace Rcpp;
#define COUT(x) Rcpp::Rcout<<(x)<<std::endl<<std::flush;
#define CERR(x) Rcpp::Rcerr<<(x)<<std::endl<<std::flush;
#else
#include <armadillo>
// TODO: remove it
using namespace arma;
#define COUT(x) std::cout<<(x)<<std::endl<<std::flush;
#define CERR(x) std::cerr<<(x)<<std::endl<<std::flush;
#endif
Expand Down
5 changes: 3 additions & 2 deletions src/Makevars
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# NOTE: R is overwriting all optimization flags, if you are a dev you can change flags in ~/.R/Makevars
# NOTE: R package should use POSIX Makefile
# TODO: How to do wildcard in POSIX Makefile?

CPP_SOURCES = svm/libsvm_runner.cpp svm/svm_client.cpp svm/svmlight_runner.cpp svm/svm_wrapper_module.cpp svm/two_e_svm_pre.cpp svm/svm_basic.cpp svm/svm.cpp svm/svm_utils.cpp svm/two_e_svm_post.cpp svm/validator_runner.cpp cec/assignment.cpp cec/cec.cpp cec/centroids_assignment.cpp cec/cluster_custom_function.cpp cec/kmeanspp_assignment.cpp cec/cec_configuration.cpp cec/cec_module.cpp cec/cluster.cpp cec/hartigan.cpp cec/random_assignment.cpp utils/threading.cpp utils/tinythread.cpp utils/utils.cpp gng/gng_algorithm.cpp gng/gng_configuration.cpp gng/gng_module.cpp gng/gng_server.cpp
SOURCES = $(CPP_SOURCES) svmlight/svm_common.c svmlight/svm_hideo.c svmlight/svm_learn.c

Expand All @@ -17,6 +17,7 @@ R_LIBS = `$(R_HOME)/bin/R CMD config --ldflags`
LAPACK_LIBS = `$(R_HOME)/bin/R CMD config LAPACK_LIBS`
BLAS_LIBS = `$(R_HOME)/bin/R CMD config BLAS_LIBS`

PKG_CPPFLAGS = $(GCC_STD) $(PREPROCESS) $(R_CPPFLAGS) $(INCLUDES) -pthread
# Do not delete R_CPPFLAGS, it will break tests
PKG_CPPFLAGS = $(GCC_STD) $(PREPROCESS) $(R_CPPFLAGS) $(INCLUDES) -pthread
PKG_CXXFLAGS = --std=c++0x
PKG_LIBS = $(LAPACK_LIBS) $(BLAS_LIBS) $(R_LIBS) $(FLIBS)
5 changes: 5 additions & 0 deletions src/cec/cec_module.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef CEC_MODULE_H
#define CEC_MODULE_H

#ifdef RCPP_INTERFACE

#include <RcppArmadillo.h>
using namespace Rcpp;

Expand Down Expand Up @@ -48,4 +50,7 @@ RCPP_MODULE(cec) {
.method("log.iters", &CecModel::iters)
.method("getDataset", &CecModel::get_points);
}

#endif

#endif
4 changes: 4 additions & 0 deletions src/svm/svm_wrapper_module.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef SVM_WRAPPER_MODULE_H
#define SVM_WRAPPER_MODULE_H

#ifdef RCPP_INTERFACE

#include "svm_basic.h"
#include "svm_client.h"
using namespace Rcpp;
Expand Down Expand Up @@ -104,3 +106,5 @@ RCPP_MODULE(svm_wrapper) {
}

#endif

#endif
2 changes: 2 additions & 0 deletions src/utils/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,11 @@ char** free_argv(int argc, char** argv) {
return NULL;
}

#ifdef RCPP_INTERFACE
int rcpp_c_rand() {
return int(Rcpp::runif(1)[0] * INT_MAX);
}
#endif

int ed_c_rand() {
#ifdef RCPP_INTERFACE
Expand Down
9 changes: 7 additions & 2 deletions tests/cpp/GNUmakefile → tests/cpp/Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
$(warning Remember to make sure to delete all R package objects, you can run "make clean" to do it)

R_HOME=$(shell R RHOME)
R_CPPFLAGS = $(shell $(R_HOME)/bin/R CMD config --cppflags) $(shell $(R_HOME)/bin/Rscript -e "RcppArmadillo:::CxxFlags()") $(shell $(R_HOME)/bin/Rscript -e "Rcpp:::CxxFlags()")

include ../../src/Makevars

# Explicit Makevars inheritances adn overrides
CXX := $(CXX)
CPPFLAGS := $(PKG_CPPFLAGS) -O2 -g -s --std=c++0x
PREPROCESS = $(DEBUG) -DNRCPP_INTERFACE -DARMA_64BIT_WORD -DBOOST_DISABLE_ASSERTS
PKG_CPPFLAGS = $(GCC_STD) $(PREPROCESS) $(R_CPPFLAGS) $(INCLUDES) -pthread
CPPFLAGS := $(PKG_CPPFLAGS) -O2 -g -s --std=c++0x
LDLIBS := $(PKG_LIBS) -lpthread -lgtest -lgtest_main

###
Expand Down Expand Up @@ -89,7 +93,7 @@ INCLUDES := $(ROOT_INCLUDE) $(BRANCH_INCLUDES) $(COMPILED_LIBRARIES_INCLUDES)
# Compilation rules
###

CPPFLAGS := $(CPPFLAGS) $(INCLUDES)
CPPFLAGS := $(CPPFLAGS) $(INCLUDES) -DNRCPP_INTERFACE
CFLAGS := $(CPPFLAGS)

all: $(TEST_MAIN_BIN) helper_scripts
Expand All @@ -98,6 +102,7 @@ all: $(TEST_MAIN_BIN) helper_scripts
@echo or use helper scripts: $(PRIMARY_TESTS_SCRIPT) $(SECONDARY_TESTS_SCRIPT)

clean:
rm $(OBJECTS)
rm -f $(TEST_MAIN_BIN) $(TEST_OBJECTS) $(COMPILED_LIBRARIES_OBJECTS)\
$(PRIMARY_TESTS_SCRIPT) $(SECONDARY_TESTS_SCRIPT) $(ADDITIONAL_CLEANING)

Expand Down

0 comments on commit d907801

Please sign in to comment.