fixed issue for user module

dev
Bill 2 years ago
parent d5382c36e9
commit 5549706443

1
.gitignore vendored

@ -51,6 +51,7 @@ k
**/Debug
**/Release
test*.c*
data/benchmark
*.csv
!test.csv
!test2.csv

@ -4,11 +4,12 @@ MonetDB_INC =
Threading =
CXXFLAGS = --std=c++1z
ifeq ($(AQ_DEBUG), 1)
OPTFLAGS = -g3
OPTFLAGS = -g3 -fsanitize=address -fsanitize=leak
LINKFLAGS =
else
OPTFLAGS = -O3 -DNDEBUG -fno-stack-protector
LINKFLAGS = -flto
endif
LINKFLAGS = -flto # + $(AQ_LINK_FLAG)
SHAREDFLAGS = -shared
FPIC = -fPIC
COMPILER = $(shell $(CXX) --version | grep -q clang && echo clang|| echo gcc)

@ -343,7 +343,7 @@ class projection(ast_node):
)
else:
# for funcs evaluate f_i(x, ...)
self.context.emitc(f'{self.out_table.contextname_cpp}->get_col<{key}>() = {val[1]};')
self.context.emitc(f'{self.out_table.contextname_cpp}->get_col<{key}>().initfrom({val[1]}, "{cols[i].name}");')
# print out col_is
if 'into' not in node:
self.context.emitc(f'print(*{self.out_table.contextname_cpp});')
@ -990,7 +990,7 @@ class load(ast_node):
self.context.queries.append(f'F{fname}')
ret_type = VoidT
if 'ret_type' in f:
ret_type = Types.decode(f['ret_type'])
ret_type = Types.decode(f['ret_type'], vector_type='vector_type')
nargs = 0
arglist = ''
if 'vars' in f:
@ -1000,7 +1000,7 @@ class load(ast_node):
nargs = len(arglist)
arglist = ', '.join(arglist)
# create c++ stub
cpp_stub = f'{ret_type.cname} (*{fname})({arglist}) = nullptr;'
cpp_stub = f'{"vectortype_cstorage" if isinstance(ret_type, VectorT) else ret_type.cname} (*{fname})({arglist}) = nullptr;'
self.context.module_stubs += cpp_stub + '\n'
self.context.module_map[fname] = cpp_stub
#registration for parser

@ -1,5 +1,11 @@
OPT_FLASG =
ifneq ($(DEBUG), 1)
OPT_FLAGS = -Ofast -march=native -flto -DNDEBUG
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
irf:
$(CXX) -shared -fPIC RF.cpp irf.cpp incrementalDecisionTree.cpp aquery_mem.cpp Evaluation.cpp -fno-semantic-interposition -Ofast -march=native -flto --std=c++1z -o ../libirf.so
$(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

@ -36,19 +36,32 @@ __AQEXPORT__(bool) additem(ColRef<double>X, long y, long size){
pt ++;
return 1;
}
__AQEXPORT__(bool) fit(){
if(pt<=0)return 0;
dt->fit(data, result, pt);
return 1;
__AQEXPORT__(bool) fit(vector_type<vector_type<double>> v, vector_type<long> res){
double** data = (double**)malloc(v.size*sizeof(double*));
for(int i = 0; i < v.size; ++i)
data[i] = v.container[i].container;
dt->fit(data, res.container, v.size);
return true;
}
__AQEXPORT__(ColRef_storage) predict(){
int* result = (int*)malloc(pt*sizeof(int));
for(long i=0; i<pt; i++){
result[i]=dt->Test(data[i], dt->DTree);
}
__AQEXPORT__(vectortype_cstorage) predict(vector_type<vector_type<double>> v){
int* result = (int*)malloc(v.size*sizeof(int));
return ColRef_storage(new ColRef_storage(result, pt, 0, "prediction", 0), 1, 0, "prediction", 0);
for(long i=0; i<v.size; i++){
result[i]=dt->Test(v.container[i].container, dt->DTree);
//printf("%d ", result[i]);
}
auto container = (vector_type<int>*)malloc(sizeof(vector_type<int>));
container->size = v.size;
container->capacity = 0;
container->container = result;
// container->out(10);
// ColRef<vector_type<int>>* col = (ColRef<vector_type<int>>*)malloc(sizeof(ColRef<vector_type<int>>));
auto ret = vectortype_cstorage{.container = container, .size = 1, .capacity = 0};
// col->initfrom(ret, "sibal");
// print(*col);
return ret;
//return true;
}

@ -74,7 +74,7 @@ public:
this->container = (_Ty*)container;
this->name = name;
}
template<template <typename ...> class VT, typename T>
template<template <typename> class VT, typename T>
void initfrom(const VT<T>& v, const char* name = "") {
ty = types::Types<_Ty>::getType();
this->size = v.size;
@ -82,6 +82,21 @@ public:
this->container = (_Ty*)(v.container);
this->name = name;
}
void initfrom(vectortype_cstorage v, const char* name = "") {
ty = types::Types<_Ty>::getType();
this->size = v.size;
this->capacity = v.capacity;
this->container = (_Ty*)v.container;
this->name = name;
}
template<typename T>
void initfrom(const T& v, const char* name = "") {
ty = types::Types<_Ty>::getType();
this->size = 0;
this->capacity = 0;
this->emplace_back(v);
this->name = name;
}
template <class T>
ColRef<_Ty>& operator =(ColRef<T>&& vt) {
this->container = (_Ty*)vt.container;

@ -77,6 +77,9 @@ public:
constexpr vector_type(vector_type<_Ty>&& vt) noexcept : capacity(0) {
_move(std::move(vt));
}
vector_type(vectortype_cstorage vt) noexcept : capacity(vt.capacity), size(vt.size), container((_Ty*)vt.container) {
out(10);
};
// size >= capacity ==> readonly vector
constexpr vector_type(const uint32_t size, void* data) :
size(size), capacity(0), container(static_cast<_Ty*>(data)) {}

@ -1,21 +1,21 @@
LOAD MODULE FROM "./libirf.so"
FUNCTIONS (
newtree(height:int, f:int64, sparse:vecint, forget:double, maxf:int64, noclasses:int64, e:int, r:int64, rb:int64) -> bool,
additem(X:vecdouble, y:int64, size:int64) -> bool,
fit() -> bool,
predict() -> vecint
);
create table tb(x int);
create table tb2(x double, y double, z double);
insert into tb values (0);
insert into tb values (0);
insert into tb values (0);
select newtree(5, 3, tb.x, 0, 3, 2, 0, 100, 1) from tb;
insert into tb2 values (1, 0, 1);
insert into tb2 values (0, 1, 1);
insert into tb2 values (1, 1, 1);
select additem(tb2.x, 1, 3) from tb2;
select additem(tb2.y, 0, -1) from tb2;
select additem(tb2.z, 1, -1) from tb2;
select fit();
select predict();
FUNCTIONS (
newtree(height:int, f:int64, sparse:vecint, forget:double, maxf:int64, noclasses:int64, e:int, r:int64, rb:int64) -> bool,
additem(X:vecdouble, y:int64, size:int64) -> bool,
fit() -> bool,
predict() -> vecint
);
create table tb(x int);
create table tb2(x double, y double, z double);
insert into tb values (0);
insert into tb values (0);
insert into tb values (0);
select newtree(5, 3, tb.x, 0, 3, 2, 0, 100, 1) from tb;
insert into tb2 values (1, 0, 1);
insert into tb2 values (0, 1, 1);
insert into tb2 values (1, 1, 1);
select additem(tb2.x, 1, 3) from tb2;
select additem(tb2.y, 0, -1) from tb2;
select additem(tb2.z, 1, -1) from tb2;
select fit();
select predict();

@ -1,26 +1,22 @@
LOAD MODULE FROM "./libirf.so"
FUNCTIONS (
newtree(height:int, f:int64, sparse:vecint64, forget:double, maxf:int64, noclasses:int64, e:int, r:int64, rb:int64) -> bool,
fit(X:vecvecdouble, y:vecint64) -> bool,
predict(X:vecvecdouble) -> vecint64
);
FUNCTIONS (
newtree(height:int, f:int64, sparse:vecint, forget:double, maxf:int64, noclasses:int64, e:int, r:int64, rb:int64) -> bool,
fit(X:vecvecdouble, y:vecint64) -> bool,
predict(X:vecvecdouble) -> vecint
);
create table source(x1 double, x2 double, x3 double, x4 double, x5 int64);
load data infile "data/benchmark" into table source fields terminated by ",";
create table source(x1 double, x2 double, x3 double, x4 double, x5 int64);
load data infile "data/benchmark" into table source fields terminated by ",";
create table sparse(x int64);
insert into sparse values (1);
insert into sparse values (1);
insert into sparse values (1);
insert into sparse values (1);
create table sparse(x int);
insert into sparse values (1);
insert into sparse values (1);
insert into sparse values (1);
insert into sparse values (1);
select * from source;
select newtree(6, 4, sparse.x, 0, 4, 2, 0, 400, 2147483647) from sparse
select newtree(6, 4, sparse.x, 0, 4, 2, 0, 400, 2147483647) from sparse;
select fit(pack(x1, x2, x3, x4), x5) from source
select fit(pack(x1, x2, x3, x4), x5) from source limit 100;
select fit(pack(x1, x2, x3, x4), x5) from source limit 100;
select fit(pack(x1, x2, x3, x4), x5) from source limit 100;
select fit(pack(x1, x2, x3, x4), x5) from source limit 100;
select predict(pack(x1, x2, x3, x4)) from source limit 100;
-- select pack(x1, x2, x3, x4) from source
select predict(pack(x1, x2, x3, x4)) from source

@ -8,5 +8,3 @@ SELECT sum(c), b, d
FROM testq1
group by a,b,d
order by d DESC, b ASC;
-- aaaa
Loading…
Cancel
Save