#include "stdio.h"
#include "gbt_global.h"
#include "akima.hpp"

#include <iostream>
#include <stdexcept>
#include <string>
#include <sstream>
#include <cmath>
#include <algorithm>

CUDA_DEVICE
int binary_search(const float* x, float target, int start, int stop)
{
    int left = start;
    int right = stop - 1;
    
    while (left <= right) {
        int mid = (left + right) / 2;
        if (mid >= stop - 1) {
            return stop - 2;
        }
        if (x[mid] <= target && target < x[mid + 1]) {
            return mid;
        } else if (target < x[mid]) {
            right = mid - 1;
        } else {
            left = mid + 1;
        }
    }
    
    return stop - 2;
}

CUDA_KERNEL
void precompute_slopes_kernel()