#include #include #include /* Read the dtype/strides verified by forest.py; never assume an sklearn C struct layout. The table contains pointers to non-owning array views pinned by the Python plan. f32 inputs, f64 comparisons and tree-order f64 sums match sklearn's serial path. */ static intptr_t read_index(uintptr_t p) { intptr_t out; memcpy(&out, (const void *)p, sizeof out); return out; } static double read_double(uintptr_t p) { double out; memcpy(&out, (const void *)p, sizeof out); return out; } #ifdef _WIN32 __declspec(dllexport) #endif void wisp_forest(const float *x, intptr_t n, intptr_t d, const uintptr_t *specs, intptr_t nt, intptr_t k, double *out) { for (intptr_t t = 0; t < nt; ++t) { const uintptr_t *tree = specs + 8 * t; const uintptr_t stride = tree[6]; for (intptr_t i = 0; i < n; ++i) { intptr_t node = 0, left; uintptr_t off = 0; while ((left = read_index(tree[0] + off)) != -1) { const float val = x[i*d + read_index(tree[2]+off)]; const int go_left = isnan(val) ? *(const uint8_t *)(tree[5]+off) : (double)val <= read_double(tree[3]+off); node = go_left ? left : read_index(tree[1]+off); off = (uintptr_t)node * stride; } const double *leaf = (const double *)(tree[4] + (uintptr_t)node * tree[7]); for (intptr_t j = 0; j < k; ++j) out[i*k+j] += leaf[j]; } } }