parent
ece2a6cc9f
commit
5b1bbf0f99
@ -0,0 +1,222 @@
|
|||||||
|
{
|
||||||
|
"stmts": {
|
||||||
|
"udf": {
|
||||||
|
"fname": "covariances2",
|
||||||
|
"params": ["x", "y", "w"],
|
||||||
|
"stmt": [{
|
||||||
|
"assignment": {
|
||||||
|
"var": "xmeans",
|
||||||
|
"op": ":=",
|
||||||
|
"expr": 0.0
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"assignment": {
|
||||||
|
"var": "ymeans",
|
||||||
|
"op": ":=",
|
||||||
|
"expr": 0.0
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"assignment": {
|
||||||
|
"var": "l",
|
||||||
|
"op": ":=",
|
||||||
|
"expr": "_builtin_len"
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"if": {
|
||||||
|
"cond": {
|
||||||
|
"gt": ["w", "l"]
|
||||||
|
},
|
||||||
|
"assignment": {
|
||||||
|
"var": "w",
|
||||||
|
"op": ":=",
|
||||||
|
"expr": "l"
|
||||||
|
},
|
||||||
|
"elif": [{
|
||||||
|
"cond": {
|
||||||
|
"gt": ["w", {
|
||||||
|
"add": ["l", 2]
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
"stmt": [{
|
||||||
|
"assignment": {
|
||||||
|
"var": "l",
|
||||||
|
"op": ":=",
|
||||||
|
"expr": 3
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"assignment": {
|
||||||
|
"var": "w",
|
||||||
|
"op": ":=",
|
||||||
|
"expr": 4
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
}, {
|
||||||
|
"cond": {
|
||||||
|
"lt": ["w", 99]
|
||||||
|
},
|
||||||
|
"stmt": {
|
||||||
|
"assignment": {
|
||||||
|
"var": "l",
|
||||||
|
"op": ":=",
|
||||||
|
"expr": 8
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"cond": {
|
||||||
|
"lt": ["w", 999]
|
||||||
|
},
|
||||||
|
"assignment": {
|
||||||
|
"var": "w",
|
||||||
|
"op": ":=",
|
||||||
|
"expr": 6
|
||||||
|
}
|
||||||
|
}],
|
||||||
|
"else": {
|
||||||
|
"assignment": {
|
||||||
|
"var": "l",
|
||||||
|
"op": ":=",
|
||||||
|
"expr": {
|
||||||
|
"div": ["l", 2]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"for": {
|
||||||
|
"defs": {
|
||||||
|
"var": ["i", "j"],
|
||||||
|
"op": [":=", ":="],
|
||||||
|
"expr": [0, 0]
|
||||||
|
},
|
||||||
|
"cond": {
|
||||||
|
"lt": ["i", "w"]
|
||||||
|
},
|
||||||
|
"tail": {
|
||||||
|
"var": "i",
|
||||||
|
"op": ":=",
|
||||||
|
"expr": {
|
||||||
|
"add": ["i", 1]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"stmt": [{
|
||||||
|
"assignment": {
|
||||||
|
"var": "xmeans",
|
||||||
|
"op": "+=",
|
||||||
|
"expr": {
|
||||||
|
"get": ["x", "i"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"assignment": {
|
||||||
|
"var": "ymeans",
|
||||||
|
"op": "+=",
|
||||||
|
"expr": {
|
||||||
|
"get": ["y", "i"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"assignment": {
|
||||||
|
"var": {
|
||||||
|
"get": ["_builtin_ret", "i"]
|
||||||
|
},
|
||||||
|
"op": ":=",
|
||||||
|
"expr": {
|
||||||
|
"avg": {
|
||||||
|
"mul": [{
|
||||||
|
"sub": [{
|
||||||
|
"x": [{
|
||||||
|
"sub": ["l", "w"]
|
||||||
|
}, "l"]
|
||||||
|
}, "xmeans"]
|
||||||
|
}, {
|
||||||
|
"sub": [{
|
||||||
|
"y": [{
|
||||||
|
"sub": ["l", "w"]
|
||||||
|
}, "l"]
|
||||||
|
}, "ymeans"]
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"for": {
|
||||||
|
"defs": {
|
||||||
|
"var": "i",
|
||||||
|
"op": ":=",
|
||||||
|
"expr": 0
|
||||||
|
},
|
||||||
|
"cond": {
|
||||||
|
"lt": ["i", "l"]
|
||||||
|
},
|
||||||
|
"tail": {
|
||||||
|
"var": "i",
|
||||||
|
"op": "+=",
|
||||||
|
"expr": 1
|
||||||
|
},
|
||||||
|
"stmt": [{
|
||||||
|
"assignment": {
|
||||||
|
"var": "xmeans",
|
||||||
|
"op": "+=",
|
||||||
|
"expr": {
|
||||||
|
"div": [{
|
||||||
|
"sub": [{
|
||||||
|
"get": ["x", "i"]
|
||||||
|
}, {
|
||||||
|
"get": ["x", {
|
||||||
|
"sub": ["i", "w"]
|
||||||
|
}]
|
||||||
|
}]
|
||||||
|
}, "w"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"assignment": {
|
||||||
|
"var": "ymeans",
|
||||||
|
"op": "+=",
|
||||||
|
"expr": {
|
||||||
|
"div": [{
|
||||||
|
"sub": [{
|
||||||
|
"get": ["y", "i"]
|
||||||
|
}, {
|
||||||
|
"get": ["y", {
|
||||||
|
"sub": ["i", "w"]
|
||||||
|
}]
|
||||||
|
}]
|
||||||
|
}, "w"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"assignment": {
|
||||||
|
"var": {
|
||||||
|
"get": ["_builtin_ret", "i"]
|
||||||
|
},
|
||||||
|
"op": ":=",
|
||||||
|
"expr": {
|
||||||
|
"avg": {
|
||||||
|
"mul": [{
|
||||||
|
"sub": [{
|
||||||
|
"x": [{
|
||||||
|
"sub": ["l", "w"]
|
||||||
|
}, "l"]
|
||||||
|
}, "xmeans"]
|
||||||
|
}, {
|
||||||
|
"sub": [{
|
||||||
|
"y": [{
|
||||||
|
"sub": ["l", "w"]
|
||||||
|
}, "l"]
|
||||||
|
}, "ymeans"]
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
}],
|
||||||
|
"ret": {
|
||||||
|
"null": {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,98 +0,0 @@
|
|||||||
# Generated by CMake
|
|
||||||
|
|
||||||
if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" LESS 2.6)
|
|
||||||
message(FATAL_ERROR "CMake >= 2.6.0 required")
|
|
||||||
endif()
|
|
||||||
cmake_policy(PUSH)
|
|
||||||
cmake_policy(VERSION 2.6...3.21)
|
|
||||||
#----------------------------------------------------------------
|
|
||||||
# Generated CMake target import file.
|
|
||||||
#----------------------------------------------------------------
|
|
||||||
|
|
||||||
# Commands may need to know the format version.
|
|
||||||
set(CMAKE_IMPORT_FILE_VERSION 1)
|
|
||||||
|
|
||||||
# Protect against multiple inclusion, which would fail when already imported targets are added once more.
|
|
||||||
set(_targetsDefined)
|
|
||||||
set(_targetsNotDefined)
|
|
||||||
set(_expectedTargets)
|
|
||||||
foreach(_expectedTarget MonetDB::monetdb_config_header)
|
|
||||||
list(APPEND _expectedTargets ${_expectedTarget})
|
|
||||||
if(NOT TARGET ${_expectedTarget})
|
|
||||||
list(APPEND _targetsNotDefined ${_expectedTarget})
|
|
||||||
endif()
|
|
||||||
if(TARGET ${_expectedTarget})
|
|
||||||
list(APPEND _targetsDefined ${_expectedTarget})
|
|
||||||
endif()
|
|
||||||
endforeach()
|
|
||||||
if("${_targetsDefined}" STREQUAL "${_expectedTargets}")
|
|
||||||
unset(_targetsDefined)
|
|
||||||
unset(_targetsNotDefined)
|
|
||||||
unset(_expectedTargets)
|
|
||||||
set(CMAKE_IMPORT_FILE_VERSION)
|
|
||||||
cmake_policy(POP)
|
|
||||||
return()
|
|
||||||
endif()
|
|
||||||
if(NOT "${_targetsDefined}" STREQUAL "")
|
|
||||||
message(FATAL_ERROR "Some (but not all) targets in this export set were already defined.\nTargets Defined: ${_targetsDefined}\nTargets not yet defined: ${_targetsNotDefined}\n")
|
|
||||||
endif()
|
|
||||||
unset(_targetsDefined)
|
|
||||||
unset(_targetsNotDefined)
|
|
||||||
unset(_expectedTargets)
|
|
||||||
|
|
||||||
|
|
||||||
# Compute the installation prefix relative to this file.
|
|
||||||
get_filename_component(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_FILE}" PATH)
|
|
||||||
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
|
|
||||||
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
|
|
||||||
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
|
|
||||||
if(_IMPORT_PREFIX STREQUAL "/")
|
|
||||||
set(_IMPORT_PREFIX "")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Create imported target MonetDB::monetdb_config_header
|
|
||||||
add_library(MonetDB::monetdb_config_header INTERFACE IMPORTED)
|
|
||||||
|
|
||||||
set_target_properties(MonetDB::monetdb_config_header PROPERTIES
|
|
||||||
INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include/monetdb"
|
|
||||||
)
|
|
||||||
|
|
||||||
if(CMAKE_VERSION VERSION_LESS 3.0.0)
|
|
||||||
message(FATAL_ERROR "This file relies on consumers using CMake 3.0.0 or greater.")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Load information for each installed configuration.
|
|
||||||
get_filename_component(_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
|
|
||||||
file(GLOB CONFIG_FILES "${_DIR}/monetdb_config_headerTargets-*.cmake")
|
|
||||||
foreach(f ${CONFIG_FILES})
|
|
||||||
include(${f})
|
|
||||||
endforeach()
|
|
||||||
|
|
||||||
# Cleanup temporary variables.
|
|
||||||
set(_IMPORT_PREFIX)
|
|
||||||
|
|
||||||
# Loop over all imported files and verify that they actually exist
|
|
||||||
foreach(target ${_IMPORT_CHECK_TARGETS} )
|
|
||||||
foreach(file ${_IMPORT_CHECK_FILES_FOR_${target}} )
|
|
||||||
if(NOT EXISTS "${file}" )
|
|
||||||
message(FATAL_ERROR "The imported target \"${target}\" references the file
|
|
||||||
\"${file}\"
|
|
||||||
but this file does not exist. Possible reasons include:
|
|
||||||
* The file was deleted, renamed, or moved to another location.
|
|
||||||
* An install or uninstall procedure did not complete successfully.
|
|
||||||
* The installation package was faulty and contained
|
|
||||||
\"${CMAKE_CURRENT_LIST_FILE}\"
|
|
||||||
but not all the files it references.
|
|
||||||
")
|
|
||||||
endif()
|
|
||||||
endforeach()
|
|
||||||
unset(_IMPORT_CHECK_FILES_FOR_${target})
|
|
||||||
endforeach()
|
|
||||||
unset(_IMPORT_CHECK_TARGETS)
|
|
||||||
|
|
||||||
# This file does not depend on other imported targets which have
|
|
||||||
# been exported from the same project but in a separate export set.
|
|
||||||
|
|
||||||
# Commands beyond this point should not need to know the version.
|
|
||||||
set(CMAKE_IMPORT_FILE_VERSION)
|
|
||||||
cmake_policy(POP)
|
|
@ -0,0 +1,4 @@
|
|||||||
|
LOAD MODULE FROM "test.so"
|
||||||
|
FUNCTIONS (div(a:int, b:int) -> double,
|
||||||
|
mulvec(a:int, b:vecfloat) -> vecfloat
|
||||||
|
);
|
Binary file not shown.
@ -1,21 +1,31 @@
|
|||||||
#include "./server/libaquery.h"
|
#include "./server/aggregations.h"
|
||||||
#include "./udf.hpp"
|
#include "./udf.hpp"
|
||||||
|
#include "./server/hasher.h"
|
||||||
|
#include <unordered_map>
|
||||||
#include "./server/monetdb_conn.h"
|
#include "./server/monetdb_conn.h"
|
||||||
#include "./server/aggregations.h"
|
#include "./server/libaquery.h"
|
||||||
|
|
||||||
extern "C" int __DLLEXPORT__ dllmain(Context* cxt) {
|
extern "C" int __DLLEXPORT__ dllmain(Context* cxt) {
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace types;
|
using namespace types;
|
||||||
auto server = static_cast<Server*>(cxt->alt_server);
|
auto server = static_cast<Server*>(cxt->alt_server);
|
||||||
auto len_6WMRXO = server->cnt;
|
auto len_4fxytV = server->cnt;
|
||||||
auto suma_6BP = ColRef<int64_t>(len_6WMRXO, server->getCol(0));
|
auto b_3pr = ColRef<int>(len_4fxytV, server->getCol(0));
|
||||||
auto b_5Yb = ColRef<int>(len_6WMRXO, server->getCol(1));
|
auto a_65L = ColRef<int>(len_4fxytV, server->getCol(1));
|
||||||
auto c_2Vh = ColRef<int>(len_6WMRXO, server->getCol(2));
|
auto out_2UnEpP = new TableInfo<value_type<decays<decltype(covariances2_gettype(a_65L, b_3pr, 4))>>>("out_2UnEpP");
|
||||||
auto d_1Ma = ColRef<int>(len_6WMRXO, server->getCol(3));
|
auto col_C9QF0Z = out_2UnEpP->get_col<0>();
|
||||||
auto out_2URo7p = new TableInfo<value_type<decays<decltype((paircorr(c_2Vh, b_5Yb) * d_1Ma))>>,int64_t,int>("out_2URo7p");
|
for (uint32_t i41 = 0; i41 < t1K4f4I0.size; ++i41){
|
||||||
out_2URo7p->get_col<0>() = (paircorr(c_2Vh, b_5Yb) * d_1Ma);
|
g1zdpLFa[forward_as_tuple(t1K4f4I0[i41])].emplace_back(i41);
|
||||||
out_2URo7p->get_col<1>().initfrom(suma_6BP);
|
}
|
||||||
out_2URo7p->get_col<2>().initfrom(b_5Yb);
|
for (const auto& i40 : g1zdpLFa){
|
||||||
print(*out_2URo7p);
|
auto &len_5NTOM6m = val_2423Z8E.size;
|
||||||
|
auto &key_6fZPUDS = i4O.first;
|
||||||
|
auto &val_2423Z8E = i4O.second;
|
||||||
|
col_C9QF0Z.emplace_back({len_5NTOM6m});
|
||||||
|
|
||||||
|
covariances2(a_65L[val_2423Z8E], b_3pr[val_2423Z8E], 4, len_5NTOM6m, col_C9QF0Z.back());
|
||||||
|
|
||||||
|
}
|
||||||
|
print(*out_2UnEpP);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
@ -1,32 +0,0 @@
|
|||||||
Exception: STATUS_ACCESS_VIOLATION at rip=005A43E1EE8
|
|
||||||
rax=000000080016C970 rbx=00000000FFFFC2E0 rcx=0000000000000015
|
|
||||||
rdx=00000000FFFFCE00 rsi=0000000000000000 rdi=0000000000000002
|
|
||||||
r8 =00000000000000A8 r9 =000000080016C970 r10=0000000000005150
|
|
||||||
r11=000000080016C970 r12=00000000FFFFFFFF r13=0000000000000000
|
|
||||||
r14=00006FFFFFEBA2F8 r15=00000000FFFFC380
|
|
||||||
rbp=00000000FFFFC210 rsp=00000000FFFFC160
|
|
||||||
program=C:\msys64\usr\bin\python3.exe, pid 821, thread main
|
|
||||||
cs=0033 ds=002B es=002B fs=0053 gs=002B ss=002B
|
|
||||||
Stack trace:
|
|
||||||
Frame Function Args
|
|
||||||
000FFFFC210 005A43E1EE8 (00000000000, 0057B699D00, 00000000050, 000FFFFC2A0)
|
|
||||||
000FFFFC210 00487B249A1 (0000000000A, 000FFFFC2F0, 00000000002, 000FFFFC3A0)
|
|
||||||
000FFFFC2A0 00487B245EE (000FFFC68F0, 00000000002, 6FFFFFEBA2F8, 00000000000)
|
|
||||||
000FFFFC3A0 00487B247B2 (004484CACEA, 00800187A50, 004484CACDA, 000FFFFC2D0)
|
|
||||||
000FFFFC3A0 004484CAE74 (0057B4D31A2, 00500001101, 00000000000, 00800187A50)
|
|
||||||
00000000000 004484C476D (6FFFFFF97DF0, 00000000000, 0057B539C7B, 6FFFFFE9AF40)
|
|
||||||
004484C4660 0057B509F6F (6FFFFFFC68F0, 6FFFFFEA2330, 0057B547BA7, 00000000000)
|
|
||||||
00800048F80 0057B6910D9 (0080016ABE0, 6FFF00000000, 0057B68A0EA, 0057B72B2E0)
|
|
||||||
00000000000 0057B5D0C61 (6FFFFFE9F190, 000FFFFC7F0, 0057B5E3A05, 00000000000)
|
|
||||||
6FFFFFF30220 0057B5D0FD1 (0080016ABF0, 6FFFFFF93D30, 0057B618338, 6FFFFFF34D00)
|
|
||||||
6FFFFFF30220 0057B60C6B0 (6FFFFFE9A0B0, 0080004A920, 6FFFFFE9F190, 6FFFFFEE2610)
|
|
||||||
6FFFFFF30220 0057B60C8B4 (0057B50A49A, 00000000000, 0057B539B2F, 000FFFFCAB8)
|
|
||||||
6FFFFFF30220 0057B60EE21 (00000000000, 000FFFFCAB8, 00000000001, 0057B731792)
|
|
||||||
0057B699678 0057B60F0B6 (0057B618804, 000FFFFCD30, 0057B604F54, 00800049350)
|
|
||||||
000FFFFCD30 0057B60FA20 (00000000000, 000FFFFC968, 000FFFFCD30, 00000000001)
|
|
||||||
000FFFFCD30 0057B62ABDD (001004016D0, 001004016D0, 00000000000, 000FFFFCD30)
|
|
||||||
000FFFFCD30 0057B62AE9D (00180049B25, 00180048A40, 00000000002, 00180326FE0)
|
|
||||||
000FFFFCD30 00180049B91 (00000000000, 00000000000, 00000000000, 00000000000)
|
|
||||||
000FFFFFFF0 00180047716 (00000000000, 00000000000, 00000000000, 00000000000)
|
|
||||||
000FFFFFFF0 001800477C4 (00000000000, 00000000000, 00000000000, 00000000000)
|
|
||||||
End of stack trace
|
|
@ -0,0 +1,11 @@
|
|||||||
|
# TODO:
|
||||||
|
|
||||||
|
## 1. double scans in projections
|
||||||
|
- first for special aggrigations and singular columns
|
||||||
|
- Then in group by node decide if we have special group by aggregations
|
||||||
|
- If sp_gb_agg exists, the entire groupby aggregation is done in C plugin
|
||||||
|
- If not, group by is done in SQL
|
||||||
|
|
||||||
|
## 2. ColRef supports multiple objects
|
||||||
|
- A.a = B.b then in projection A.a B.b will refer to same projection
|
||||||
|
- Colref::ProjEq(ColRef v) => this == v or v in this.proj_eqs
|
@ -0,0 +1,12 @@
|
|||||||
|
#include "../server/libaquery.h"
|
||||||
|
|
||||||
|
|
||||||
|
extern void* Aalloc(size_t sz);
|
||||||
|
extern int Afree(void * mem);
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
size_t register_memory(T* ptr){
|
||||||
|
[](void* m){ auto _m = static_cast<T*>(m); delete _m; };
|
||||||
|
}
|
||||||
|
|
||||||
|
#define EXPORT __DLLEXPORT__
|
@ -0,0 +1,5 @@
|
|||||||
|
#include "aquery.h"
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <stdlib>
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,2 +0,0 @@
|
|||||||
#TargetFrameworkVersion=:PlatformToolSet=v141:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit:WindowsTargetPlatformVersion=10.0.19041.0
|
|
||||||
Release|Win32|d:\gg\AQuery++\server\|
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,14 @@
|
|||||||
|
AGGREGATION FUNCTION covariances(x, y, w){
|
||||||
|
static xmeans := 0., ymeans := 0., cnt := 0;
|
||||||
|
if (cnt < w)
|
||||||
|
{
|
||||||
|
xmeans += x;
|
||||||
|
ymeans += y;
|
||||||
|
cnt+=1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
xmeans += (x - x.vec[cnt - w]) / w;
|
||||||
|
ymeans += (y - y.vec[cnt - w]) / w;
|
||||||
|
}
|
||||||
|
avg (( x.vec(x.len-w, x.len) - xmeans ) * (y.vec(y.len - w, y.len) - ymeans ))
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
AGGREGATION FUNCTION add(a, b){
|
||||||
|
a+b
|
||||||
|
}
|
||||||
|
|
||||||
|
AGGREGATION FUNCTION covariances2(x, y, w){
|
||||||
|
xmeans := 0.;
|
||||||
|
ymeans := 0.;
|
||||||
|
l := _builtin_len;
|
||||||
|
|
||||||
|
if (l > 0)
|
||||||
|
{
|
||||||
|
xmeans := x[0];
|
||||||
|
ymeans := y[0];
|
||||||
|
_builtin_ret[0] := 0.;
|
||||||
|
}
|
||||||
|
if (w > l)
|
||||||
|
w := l;
|
||||||
|
for (i := 1, j:= 0; i < w; i := i+1) {
|
||||||
|
xmeans += x[i];
|
||||||
|
ymeans += y[i];
|
||||||
|
_builtin_ret[i] := avg (( x(0, i) - xmeans/i ) * (y(0, i) - ymeans/i ));
|
||||||
|
}
|
||||||
|
xmeans /= w;
|
||||||
|
ymeans /= w;
|
||||||
|
for (i := w; i < l; i += 1)
|
||||||
|
{
|
||||||
|
xmeans += (x[i] - x[i - w]) / w;
|
||||||
|
ymeans += (y[i] - y[i - w]) / w;
|
||||||
|
_builtin_ret[i] := avg (( x(i-w, i) - xmeans ) * (y(i - w, i) - ymeans ));
|
||||||
|
}
|
||||||
|
Null
|
||||||
|
}
|
||||||
|
|
||||||
|
CREATE TABLE test(a INT, b INT, c INT, d INT)
|
||||||
|
|
||||||
|
LOAD DATA INFILE "test.csv"
|
||||||
|
INTO TABLE test
|
||||||
|
FIELDS TERMINATED BY ","
|
||||||
|
|
||||||
|
select covariances2(a, b, 4) from test group by c;
|
||||||
|
|
@ -0,0 +1,32 @@
|
|||||||
|
AGGREGATION FUNCTION covariances2(x, y, w){
|
||||||
|
xmeans := 0.;
|
||||||
|
ymeans := 0.;
|
||||||
|
l := _builtin_len;
|
||||||
|
if (w > l)
|
||||||
|
w := l;
|
||||||
|
elif (w > l + 2)
|
||||||
|
{
|
||||||
|
l := 3;
|
||||||
|
w := 4;
|
||||||
|
}
|
||||||
|
elif(w < 99){
|
||||||
|
l := 8;
|
||||||
|
}
|
||||||
|
elif(w<999)
|
||||||
|
w := 6;
|
||||||
|
else
|
||||||
|
l := l / 2;
|
||||||
|
|
||||||
|
for (i := 0, j:= 0; i < w; i := i+1) {
|
||||||
|
xmeans += x[i];
|
||||||
|
ymeans += y[i];
|
||||||
|
_builtin_ret[i] := avg (( x(l-w, l) - xmeans ) * (y(l - w, l) - ymeans ));
|
||||||
|
}
|
||||||
|
for (i := 0; i < l; i += 1)
|
||||||
|
{
|
||||||
|
xmeans += (x[i] - x[i - w]) / w;
|
||||||
|
ymeans += (y[i] - y[i - w]) / w;
|
||||||
|
_builtin_ret[i] := avg (( x(l-w, l) - xmeans ) * (y(l - w, l) - ymeans ));
|
||||||
|
}
|
||||||
|
Null
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "./server/libaquery.h"
|
||||||
|
#include "./server/aggregations.h"
|
||||||
|
|
||||||
|
auto covariances = [](auto x, auto y, auto w) {
|
||||||
|
static auto xmeans=0.0;static auto ymeans=0.0; static auto cnt=0;
|
||||||
|
auto reset = [=]() { xmeans=0.0, ymeans=0.0, cnt=0; };
|
||||||
|
auto call = [](decltype(x) x, decltype(y) y, decltype(w) w){
|
||||||
|
if((cnt < w)) {
|
||||||
|
xmeans += x;
|
||||||
|
ymeans += y;
|
||||||
|
cnt += 1;
|
||||||
|
}
|
||||||
|
y = (x - xmeans);
|
||||||
|
return avg(((x.subvec((x - w), x) - xmeans) * (y.subvec((y - w), y) - ymeans)));
|
||||||
|
};
|
||||||
|
return std::make_pair(reset, call);
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,14 @@
|
|||||||
|
#include "udf.hpp"
|
||||||
|
|
||||||
|
int main(){
|
||||||
|
vector_type _a{1,2,3,4};
|
||||||
|
vector_type _b{2,3,3,5};
|
||||||
|
ColRef<int> a("a");
|
||||||
|
ColRef<int> b("b");
|
||||||
|
a.initfrom(_a, "a");
|
||||||
|
b.initfrom(_b, "b");
|
||||||
|
ColRef<decltype(covariances2_gettype(a,b,0))> ret{4};
|
||||||
|
covariances2(a,b,2,4,ret);
|
||||||
|
|
||||||
|
print(ret);
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
#include "udf.hpp"
|
||||||
|
|
||||||
|
int main(){
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in new issue