#include "eval_maxpool2d.h"

eval_maxpool2d::eval_maxpool2d(const expression &expr): eval_op(expr), kernel_size(expr.get_op_param_int("kernel_size")), stride(expr.get_op_param_int("stride")){
    // Retrieve kernel size and stride from the expression
    //int kernel_size = expr.get_ker_and_str_value("kernel_size");
    //int stride = expr.get_ker_and_str_value("stride");
}

void eval_maxpool2d::eval(vars_type &variables, const kwargs_type &kwargs) {
    // Ensure that there is at least one input (the input tensor)
    if (inputs_.empty()) {
        throw std::runtime_error("No input tensor for eval_maxpool2d.");
    }

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

    // Get the input tensor
    tensor input_tensor = variables.at(inputExprId);

    // Perform the max pooling operation
    tensor pooled_tensor = MaxPool2d(input_tensor, kernel_size, stride);

    // Store the result in the variables map using the expression ID
    variables[expr_id_] = pooled_tensor;
}

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