                 size_t* dim = (size_t*) malloc(num_coeff*sizeof(size_t));
                 size_t i = 0;
 
-                for(size_t inp_z = 0; inp_z < input_size[2]; inp_z++)
+                for(size_t x_shift = 0; x_shift < filter_size[0]; x_shift++)
                 {
-                    for(size_t x_shift = 0; x_shift < filter_size[0]; x_shift++)
+                    for(size_t y_shift = 0; y_shift < filter_size[1]; y_shift++)
                     {
-                        for(size_t y_shift = 0; y_shift < filter_size[1]; y_shift++)
+                        for(size_t inp_z = 0; inp_z < input_size[2]; inp_z++)
                         {
                             const long int x_val = out_x*strides[0] + x_shift - pad_top;
                             const long int y_val = out_y*strides[1] + y_shift - pad_left;

    const size_t size = filter_size[0]*filter_size[1]*input_size[2]*output_size[2];

    double* filter_weights_tmp = (double*) malloc(size*sizeof(double));
    double* filter_bias_tmp = (double*) malloc(output_size[2]*sizeof(double));

    size_t* input_size_tmp = (size_t*) malloc(3*sizeof(size_t));
    size_t* output_size_tmp = (size_t*) malloc(3*sizeof(size_t));

                    }
                }

                const double cst = filter_bias[out_z];

                double* dense_coeff = (double*) calloc(num_pixels, sizeof(double));

                for(size_t i = 0; i < actual_coeff; i++)
                {
                    dense_coeff[dim[i]] = coeff[i];
                }

                expr_t* res = (expr_t*) malloc(sizeof(expr_t));
