File size: 1,864 Bytes
a24af46 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | #include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <math.h>
#if defined(_WIN32)
#define SCE_API __declspec(dllexport)
#else
#define SCE_API __attribute__((visibility("default")))
#endif
#ifdef __cplusplus
extern "C" {
#endif
static inline uint64_t fmix64(uint64_t k) {
k ^= k >> 33;
k *= 0xff51afd7ed558ccdULL;
k ^= k >> 33;
k *= 0xc4ceb9fe1a85ec53ULL;
k ^= k >> 33;
return k;
}
SCE_API void sce_holographic_hash(const char* data, size_t len, char* out_hex) {
uint64_t h = 0x100000001b3ULL;
const uint8_t* ptr = (const uint8_t*)data;
for (size_t i = 0; i < len; ++i) {
h = (h ^ ptr[i]) * 0xCBF29CE484222325ULL;
}
h = fmix64(h);
snprintf(out_hex, 17, "%016llx", (unsigned long long)h);
}
SCE_API void sce_symplectic_step(double* z, double* z_dot, const double* u, int n, double omega, double dt) {
double omega_sq = omega * omega;
double two_omega = 2.0 * omega;
for (int i = 0; i < n; ++i) {
double acc = omega_sq * (u[i] - z[i]) - two_omega * z_dot[i];
z_dot[i] += acc * dt;
z[i] += z_dot[i] * dt;
}
}
SCE_API double sce_lyapunov_eval(const double* x, const double* P, int dim) {
double v = 0.0;
for (int i = 0; i < dim; ++i) {
double row_sum = 0.0;
for (int j = 0; j < dim; ++j) {
row_sum += P[i * dim + j] * x[j];
}
v += x[i] * row_sum;
}
return v;
}
SCE_API int sce_ucb_prune(const double* v_mean, const double* v_std, double kappa, double tau, int* out_mask, int n) {
int pruned_count = 0;
for (int i = 0; i < n; ++i) {
double ucb = v_mean[i] + kappa * v_std[i];
if (ucb < tau) {
out_mask[i] = 0;
pruned_count++;
} else {
out_mask[i] = 1;
}
}
return pruned_count;
}
#ifdef __cplusplus
}
#endif
|