This commit is contained in:
2023-02-20 20:12:42 +08:00
parent d71fc77006
commit 64d4e3dd9a
15 changed files with 1068 additions and 1016 deletions
+1 -1
View File
@@ -5,7 +5,7 @@ else
OPT_FLAGS = -g3 -D_DEBUG -fsanitize=leak -fsanitize=address
endif
example:
$(CXX) -shared -fPIC example.cpp aquery_mem.cpp -fno-semantic-interposition -Ofast -march=native -flto --std=c++1z -o ../test.so
$(CXX) -shared -fPIC example.cpp aquery_mem.cpp -fno-semantic-interposition -Ofast -march=native -flto --std=c++1z -L.. -laquery -o ../test.so
irf:
$(CXX) -shared -fPIC RF.cpp irf.cpp incrementalDecisionTree.cpp aquery_mem.cpp Evaluation.cpp -fno-semantic-interposition $(OPT_FLAGS) --std=c++1z -o ../libirf.so
all: example
+5 -3
View File
@@ -84,7 +84,9 @@ __AQEXPORT__(void) init_session(Context* cxt);
#ifdef _WIN32
#include <cstring>
#else
void* memcpy(void*, const void*, unsigned long long);
namespace std {
void* memcpy(void*, const void*, unsigned long long);
}
#endif
struct vectortype_storage{
@@ -95,7 +97,7 @@ struct vectortype_storage{
vectortype_storage() = default;
template <class Ty, template <typename> class VT>
vectortype_storage(const VT<Ty>& vt) {
memcpy(this, &vt, sizeof(vectortype_storage));
std::memcpy(this, &vt, sizeof(vectortype_storage));
}
};
struct ColRef_storage {
@@ -108,7 +110,7 @@ struct ColRef_storage {
ColRef_storage() = default;
template <class Ty, template <typename> class VT>
ColRef_storage(const VT<Ty>& vt) {
memcpy(this, &vt, sizeof(ColRef_storage));
std::memcpy(this, &vt, sizeof(ColRef_storage));
}
};
#endif
+1 -1
View File
@@ -1,6 +1,6 @@
#include "aquery.h"
// __AQ_NO_SESSION__
#include "../server/table.h"
#include "aquery.h"
__AQEXPORT__(ColRef_storage) mulvec(int a, ColRef<float> b){
return a * b;
+26 -3
View File
@@ -3,8 +3,15 @@
// __AQ_NO_SESSION__
#include "../server/table.h"
#include "aquery.h"
#include "./server/gc.h"
__AQEXPORT__(void) __AQ_Init_GC__(Context* cxt) {
GC::gc_handle = static_cast<GC*>(cxt->gc);
GC::scratch_space = nullptr;
}
DecisionTree *dt = nullptr;
RandomForest *rf = nullptr;
@@ -20,7 +27,7 @@ newtree(int height, long f, ColRef<int> X, double forget, long maxf, long noclas
if (maxf < 0)
maxf = f;
dt = new DecisionTree(f, X_cpy, forget, maxf, noclasses, e);
rf = new RandomForest(height, f, X_cpy, forget, noclasses, e)
rf = new RandomForest(height, f, X_cpy, forget, noclasses, e);
return true;
}
@@ -42,6 +49,21 @@ newtree(int height, long f, ColRef<int> X, double forget, long maxf, long noclas
// return 1;
// }
__AQEXPORT__(bool)
fit_inc(vector_type<vector_type<double>> v, vector_type<long> res)
{
static uint32_t last_offset = 0;
double **data = (double **)malloc(v.size * sizeof(double *));
if(last_offset >= v.size)
last_offset = 0;
for (int i = last_offset; i < v.size; ++i)
data[i] = v.container[i].container;
rf->fit(data, res.container, v.size);
free(data);
return true;
}
__AQEXPORT__(bool)
fit(vector_type<vector_type<double>> v, vector_type<long> res)
{
@@ -53,14 +75,15 @@ fit(vector_type<vector_type<double>> v, vector_type<long> res)
return true;
}
__AQEXPORT__(vectortype_cstorage)
predict(vector_type<vector_type<double>> v)
{
int *result = (int *)malloc(v.size * sizeof(int));
for (long i = 0; i < v.size; i++)
for (uint32_t i = 0; i < v.size; i++)
//result[i] = dt->Test(v.container[i].container, dt->DTree);
result[i] = rf->Test(v.container, rf->DTrees);
result[i] = int(rf->Test(v[i].container));
auto container = (vector_type<int> *)malloc(sizeof(vector_type<int>));
container->size = v.size;
container->capacity = 0;