#include "eval_linear.h"

eval_linear::eval_linear(const expression &expr): eval_op(expr),weight(expr.get_op_param_tensor("weight")),bias(expr.get_op_param_tensor("bias")) {
}

void eval_linear::eval(vars_type &variables, const kwargs_type &kwargs) {
    if (inputs_.empty()) {
        throw std::runtime_error("No input tensor for eval_linear.");
    }

    int inputExprId = inputs_[0];
    if (variables.find(inputExprId) == variables.end()) {
        throw std::runtime_error("Input tensor not found in variables map.");
    }

    tensor x = variables.at(inputExprId);

    // Now you have x, weight, and bias available to perform the Linear operation
    tensor linearResult = Linear(weight, x, bias);

    // Process the result...
    variables[expr_id_] = linearResult;
}

std::shared_ptr<eval_op> eval_linear::clone(const expression &expr) {
    return std::make_shared<eval_linear>(expr);
}