From dc8a89c3dfc896c0c1b57415b0d20ba7b9bc6229 Mon Sep 17 00:00:00 2001 From: Relintai Date: Thu, 27 Apr 2023 18:37:59 +0200 Subject: [PATCH] Fix build when both tests and old classes are disabled. --- mlpp/data/data.cpp | 56 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 2 deletions(-) diff --git a/mlpp/data/data.cpp b/mlpp/data/data.cpp index 3d37659..63342b2 100644 --- a/mlpp/data/data.cpp +++ b/mlpp/data/data.cpp @@ -10,10 +10,13 @@ #include "core/os/file_access.h" #include "../lin_alg/lin_alg.h" +#include "../stat/stat.h" + +#ifdef OLD_CLASSES_ENABLED #include "../lin_alg/lin_alg_old.h" #include "../softmax_net/softmax_net_old.h" -#include "../stat/stat.h" #include "../stat/stat_old.h" +#endif #include #include @@ -515,6 +518,7 @@ std::tuple>, std::vector>, s // MULTIVARIATE SUPERVISED void MLPPData::setData(int k, std::string fileName, std::vector> &inputSet, std::vector &outputSet) { +#ifdef OLD_CLASSES_ENABLED MLPPLinAlgOld alg; std::string inputTemp; std::string outputTemp; @@ -540,9 +544,11 @@ void MLPPData::setData(int k, std::string fileName, std::vector inputName, std::string outputName, std::vector> inputSet, std::vector outputSet) { +#ifdef OLD_CLASSES_ENABLED MLPPLinAlgOld alg; inputSet = alg.transpose(inputSet); for (uint32_t i = 0; i < inputSet.size(); i++) { @@ -556,11 +562,13 @@ void MLPPData::printData(std::vector inputName, std::string outputN for (uint32_t i = 0; i < outputSet.size(); i++) { std::cout << outputSet[i] << std::endl; } +#endif } // UNSUPERVISED void MLPPData::setData(int k, std::string fileName, std::vector> &inputSet) { +#ifdef OLD_CLASSES_ENABLED MLPPLinAlgOld alg; std::string inputTemp; @@ -582,9 +590,11 @@ void MLPPData::setData(int k, std::string fileName, std::vector inputName, std::vector> inputSet) { +#ifdef OLD_CLASSES_ENABLED MLPPLinAlgOld alg; inputSet = alg.transpose(inputSet); for (uint32_t i = 0; i < inputSet.size(); i++) { @@ -593,6 +603,7 @@ void MLPPData::printData(std::vector inputName, std::vector> MLPPData::rgb2gray(std::vector>> MLPPData::rgb2ycbcr(std::vector>> input) { +#ifdef OLD_CLASSES_ENABLED MLPPLinAlgOld alg; std::vector>> YCbCr; YCbCr = alg.resize(YCbCr, input); @@ -659,11 +671,15 @@ std::vector>> MLPPData::rgb2ycbcr(std::vector>>(); +#endif } // Conversion formulas available here: // https://www.rapidtables.com/convert/color/rgb-to-hsv.html std::vector>> MLPPData::rgb2hsv(std::vector>> input) { +#ifdef OLD_CLASSES_ENABLED MLPPLinAlgOld alg; std::vector>> HSV; HSV = alg.resize(HSV, input); @@ -702,23 +718,34 @@ std::vector>> MLPPData::rgb2hsv(std::vector>>(); +#endif } // http://machinethatsees.blogspot.com/2013/07/how-to-convert-rgb-to-xyz-or-vice-versa.html std::vector>> MLPPData::rgb2xyz(std::vector>> input) { +#ifdef OLD_CLASSES_ENABLED MLPPLinAlgOld alg; std::vector>> XYZ; XYZ = alg.resize(XYZ, input); std::vector> RGB2XYZ = { { 0.4124564, 0.3575761, 0.1804375 }, { 0.2126726, 0.7151522, 0.0721750 }, { 0.0193339, 0.1191920, 0.9503041 } }; return alg.vector_wise_tensor_product(input, RGB2XYZ); +#else + return std::vector>>(); +#endif } std::vector>> MLPPData::xyz2rgb(std::vector>> input) { +#ifdef OLD_CLASSES_ENABLED MLPPLinAlgOld alg; std::vector>> XYZ; XYZ = alg.resize(XYZ, input); std::vector> RGB2XYZ = alg.inverse({ { 0.4124564, 0.3575761, 0.1804375 }, { 0.2126726, 0.7151522, 0.0721750 }, { 0.0193339, 0.1191920, 0.9503041 } }); return alg.vector_wise_tensor_product(input, RGB2XYZ); +#else + return std::vector>>(); +#endif } // TEXT-BASED & NLP @@ -909,6 +936,7 @@ std::vector> MLPPData::BOW(std::vector sentence } std::vector> MLPPData::TFIDF(std::vector sentences) { +#ifdef OLD_CLASSES_ENABLED MLPPLinAlgOld alg; std::vector wordList = removeNullByte(removeStopWords(createWordList(sentences))); @@ -962,9 +990,13 @@ std::vector> MLPPData::TFIDF(std::vector senten } return TFIDF; +#else + return std::vector>(); +#endif } std::tuple>, std::vector> MLPPData::word2Vec(std::vector sentences, std::string type, int windowSize, int dimension, real_t learning_rate, int max_epoch) { +#ifdef OLD_CLASSES_ENABLED std::vector wordList = removeNullByte(removeStopWords(createWordList(sentences))); std::vector> segmented_sentences; @@ -1023,6 +1055,9 @@ std::tuple>, std::vector> MLPPData: std::vector> wordEmbeddings = model->getEmbeddings(); delete model; return { wordEmbeddings, wordList }; +#else + return std::tuple>, std::vector>(); +#endif } struct WordsToVecResult { @@ -1033,6 +1068,7 @@ struct WordsToVecResult { MLPPData::WordsToVecResult MLPPData::word_to_vec(std::vector sentences, std::string type, int windowSize, int dimension, real_t learning_rate, int max_epoch) { WordsToVecResult res; +#ifdef OLD_CLASSES_ENABLED res.word_list = removeNullByte(removeStopWords(createWordList(sentences))); std::vector> segmented_sentences; @@ -1090,11 +1126,13 @@ MLPPData::WordsToVecResult MLPPData::word_to_vec(std::vector senten res.word_embeddings = model->getEmbeddings(); delete model; +#endif return res; } std::vector> MLPPData::LSA(std::vector sentences, int dim) { +#ifdef OLD_CLASSES_ENABLED MLPPLinAlgOld alg; std::vector> docWordData = BOW(sentences, "Binary"); @@ -1108,6 +1146,9 @@ std::vector> MLPPData::LSA(std::vector sentence std::vector> embeddings = alg.matmult(S_trunc, Vt_trunc); return embeddings; +#else + return std::vector>(); +#endif } std::vector MLPPData::createWordList(std::vector sentences) { @@ -1138,6 +1179,7 @@ void MLPPData::setInputNames(std::string fileName, std::vector &inp } std::vector> MLPPData::featureScaling(std::vector> X) { +#ifdef OLD_CLASSES_ENABLED MLPPLinAlgOld alg; X = alg.transpose(X); std::vector max_elements, min_elements; @@ -1155,9 +1197,13 @@ std::vector> MLPPData::featureScaling(std::vector>(); +#endif } std::vector> MLPPData::meanNormalization(std::vector> X) { +#ifdef OLD_CLASSES_ENABLED MLPPLinAlgOld alg; MLPPStatOld stat; // (X_j - mu_j) / std_j, for every j @@ -1167,9 +1213,13 @@ std::vector> MLPPData::meanNormalization(std::vector>(); +#endif } std::vector> MLPPData::meanCentering(std::vector> X) { +#ifdef OLD_CLASSES_ENABLED MLPPStatOld stat; for (uint32_t i = 0; i < X.size(); i++) { real_t mean_i = stat.mean(X[i]); @@ -1178,6 +1228,9 @@ std::vector> MLPPData::meanCentering(std::vector>(); +#endif } std::vector> MLPPData::oneHotRep(std::vector tempOutputSet, int n_class) { @@ -1263,7 +1316,6 @@ Ref MLPPData::one_hot_rep(const Ref &temp_output_set, in return output_set; } - void MLPPData::_bind_methods() { ClassDB::bind_method(D_METHOD("load_breast_cancer", "path"), &MLPPData::load_breast_cancer); ClassDB::bind_method(D_METHOD("load_breast_cancer_svc", "path"), &MLPPData::load_breast_cancer_svc);