 
             for(size_t out_z = 0; out_z < output_size_z; out_z++)
             {
-                size_t mat_out = n*output_size_x*output_size_y*output_size_z + (out_x + min_out_x)*output_size_y*output_size_z + (out_y + min_out_y)*output_size_z + out_z;
+                size_t mat_out = n*length_x*length_y*output_size_z + out_x*length_y*output_size_z + out_y*output_size_z + out_z;
 
                 const float_type prev_inf_coeff = expr_inf_coeff[mat_out];
                 const float_type prev_sup_coeff = expr_sup_coeff[mat_out];

                {
                    if(!((y_val < 0) || (y_val >= (long int)input_size_y)))
                    {
                        const size_t mat_in = (out_x*stride_x + x_shift + min_out_x*stride_x - pad_x)*input_size_y*input_size_z + (out_y*stride_y + y_shift + min_out_y*stride_y - pad_y)*input_size_z + inp_z;
                        const size_t b = n*input_size_x*input_size_y*input_size_z + mat_in;

                        float_type inf_coeff = res_inf_coeff[b];
                        float_type sup_coeff = res_sup_coeff[b];

                        for(size_t out_z = 0; out_z < output_size_z; out_z++)
                        {
                            const size_t mat_out = (out_x + min_out_x)*output_size_y*output_size_z + (out_y + min_out_y)*output_size_z + out_z;
                            const size_t a = n*output_size_x*output_size_y*output_size_z + mat_out;

                            const float_type prev_inf_coeff = expr_inf_coeff[a];
                            const float_type prev_sup_coeff = expr_sup_coeff[a];

    float_type* linf_cst;
    float_type* lsup_cst;

    if(fp->layers[layerno]->type == CONV)
    {
        cudaMalloc((void**) &linf_coeff, num_out_neurons_last_layer*length_x*length_y*fp->layers[layerno]->input_size[2]*sizeof(float_type));
        cudaMalloc((void**) &lsup_coeff, num_out_neurons_last_layer*length_x*length_y*fp->layers[layerno]->input_size[2]*sizeof(float_type));
    }
    else
    {
        cudaMalloc((void**) &linf_coeff, num_out_neurons_last_layer*num_in_neurons_last_layer*sizeof(float_type));
        cudaMalloc((void**) &lsup_coeff, num_out_neurons_last_layer*num_in_neurons_last_layer*sizeof(float_type));
    }

    cudaMalloc((void**) &linf_cst, num_out_neurons_last_layer*sizeof(float_type));
    cudaMalloc((void**) &lsup_cst, num_out_neurons_last_layer*sizeof(float_type));

