#ifndef EXPRFUNCTIONS_HPP_
#define EXPRFUNCTIONS_HPP_
#include <stdio.h>
#include <stdlib.h>
#include
#include <gle/engine/cpplib/headers.hpp>
#include
#include
#include
#include
#include <math.h>
#include
/** XXX Warning!! Put self-defined struct in ExprUtil.hpp **
- No user defined struct, helper functions (that will not be directly called
- in the GQuery scripts) etc. are allowed in this file. This file only
- contains user-defined expression functionâs signature and body.
- Please put user defined structs, helper functions etc. in ExprUtil.hpp
*/
#include âExprUtil.hppâ
namespace UDIMPL {
typedef std::string string; //XXX DONâT REMOVE
/****** BIULT-IN FUNCTIONS ********/
/ XXX DONâT REMOVE ****************/
inline int64_t str_to_int (string str) {
return atoll(str.c_str());
}
inline int64_t float_to_int (float val) {
return (int64_t) val;
}
inline string to_string (double val) {
char result[200];
sprintf(result, â%gâ, val);
return string(result);
}
inline ListAccum tg_extract_list(string weights){
ListAccum wghts;
string current_weight;
std::stringstream s_stream(weights);
while (s_stream.good()) {
std::getline(s_stream, current_weight, â,â);
wghts.data_.push_back(std::stof(current_weight));
}
return wghts;
}
inline float tg_fastrp_rand_func(int64_t v_id, int64_t emb_idx, int64_t seed, int64_t s){
std::hashstd::string hasher;
auto hash = hasher(std::to_string(v_id) + â,â + std::to_string(emb_idx) + â,â + std::to_string(seed));
std::mt19937 gen(hash);
std::uniform_real_distribution distribution(0.0, 1.0);
float p1 = 0.5 / s, p2 = p1, p3 = 1 - 1.0 / s;
float v1 = sqrt(s), v2 = -v1, v3 = 0.0;
float random_value = distribution(gen);
if (random_value <= p1)
return v1;
else if (random_value <= p1 + p2)
return v2;
else
return v3;
}
}
/****************************************/
#endif /* EXPRFUNCTIONS_HPP_ */