                             {
                                 elina_double_interval_mul_expr_coeff(&tmp1, &tmp2, prev_inf_coeff, prev_sup_coeff, -aux_coeffs[c], aux_coeffs[c]);
 
-                                maxRes = fmax(fabs(inf_coeff), fabs(sup_coeff));
+                                maxRes = fmax(fabs(res_inf_coeff[b]), fabs(res_sup_coeff[b]));
                                 maxMul = fmax(fabs(tmp1), fabs(tmp2));
 
-                                inf_coeff = inf_coeff + tmp1 + (maxRes + maxMul)*ulp;
-                                sup_coeff = sup_coeff + tmp2 + (maxRes + maxMul)*ulp;
+                                res_inf_coeff[b] = res_inf_coeff[b] + tmp1 + (maxRes + maxMul)*ulp;
+                                res_sup_coeff[b] = res_sup_coeff[b] + tmp2 + (maxRes + maxMul)*ulp;
                             }
                         }
                     }
                 }
-
-                res_inf_coeff[b] = inf_coeff;
-                res_sup_coeff[b] = sup_coeff;
+            }
+        }
+    }
+}
+
+
+__global__
+void coeffs_from_previous_layer_conv_sparse(const float_type* __restrict__ expr_inf_coeff, const float_type* __restrict__ expr_sup_coeff, float_type* __restrict__ res_inf_coeff, float_type* __restrict__ res_sup_coeff, const float_type* __restrict__ aux_coeffs, const size_t output_size_x, const size_t output_size_y, const size_t output_size_z, const size_t input_size_x, const size_t input_size_y, const size_t input_size_z, long int offset_x, long int offset_y, long int length_x, long int length_y, long int shift_x, long int shift_y, const size_t filter_size_x, const size_t filter_size_y, const size_t stride_x, const size_t stride_y, const size_t pad_x, const size_t pad_y)
+{
+    const size_t last_x = blockIdx.x;
+    const size_t last_y = blockIdx.y;
+    const size_t last_z = blockIdx.z;
+
+    const size_t n = last_x*gridDim.y*gridDim.z + last_y*gridDim.z + last_z;
+
+    const long int min_out_x = offset_x + last_x*shift_x;
+    const long int min_out_y = offset_y + last_y*shift_y;
+
+    const long int max_out_x = min_out_x + length_x;
+    const long int max_out_y = min_out_y + length_y;
+
+    float_type tmp1, tmp2;
+    float_type maxRes, maxMul;
+
+    for(long int out_x = min_out_x; out_x < max_out_x; out_x++)
+    {
+        if(out_x < 0 || out_x >= output_size_x)
+        {
+            continue;
+        }
+
+        for(long int out_y = min_out_y; out_y < max_out_y; out_y++)
+        {
+            if(out_y < 0 || out_y >= output_size_y)
+            {
+                continue;
+            }
+
+            for(size_t out_z = 0; out_z < output_size_z; out_z++)
+            {
+                const size_t i = out_x*output_size_y*output_size_z + out_y*output_size_z + out_z;
+
+                const size_t a = n*output_size_x*output_size_y*output_size_z + i;
+
+                for(size_t inp_x = 0; inp_x < input_size_x; inp_x++)
+                {
+                    for(size_t inp_y = 0; inp_y < input_size_y; inp_y++)
+                    {
+                        for(size_t inp_z = 0; inp_z < input_size_z; inp_z++)
+                        {
+                            const size_t j = inp_x*input_size_y*input_size_z + inp_y*input_size_z + inp_z;
+
+                            const size_t b = n*input_size_x*input_size_y*input_size_z + j;
+                            const size_t c = i*input_size_x*input_size_y*input_size_z + j;
+
+                            const float_type prev_inf_coeff = expr_inf_coeff[a];
+                            const float_type prev_sup_coeff = expr_sup_coeff[a];
+
+                            if((prev_inf_coeff != 0) || (prev_sup_coeff != 0))
+                            {
+                                elina_double_interval_mul_expr_coeff(&tmp1, &tmp2, prev_inf_coeff, prev_sup_coeff, -aux_coeffs[c], aux_coeffs[c]);
+
+                                maxRes = fmax(fabs(res_inf_coeff[b]), fabs(res_sup_coeff[b]));
+                                maxMul = fmax(fabs(tmp1), fabs(tmp2));
+
+                                res_inf_coeff[b] = res_inf_coeff[b] + tmp1 + (maxRes + maxMul)*ulp;
+                                res_sup_coeff[b] = res_sup_coeff[b] + tmp2 + (maxRes + maxMul)*ulp;
+                            }
+                        }
+                    }
+                }
             }
         }
     }

        cudaMalloc((void**) &csts, num_out_neurons_last_layer*sizeof(float_type));

        sparse_to_dense(fp->layers[layerno], coeffs, csts);
    }
    else
    {

        cudaMalloc((void**) &linf_coeff_tmp, num_out_neurons_last_layer*num_in_neurons_current_layer*sizeof(float_type));
        cudaMalloc((void**) &lsup_coeff_tmp, num_out_neurons_last_layer*num_in_neurons_current_layer*sizeof(float_type));

        cudaMemset(linf_coeff_tmp, 0, num_out_neurons_last_layer*num_in_neurons_current_layer*sizeof(float_type));
        cudaMemset(lsup_coeff_tmp, 0, num_out_neurons_last_layer*num_in_neurons_current_layer*sizeof(float_type));

        if(fp->layers[k]->type == CONV)
        {
            coeffs_from_previous_layer_conv<<<num_out_neurons_last_layer, 1>>>(linf_coeff, lsup_coeff, linf_coeff_tmp, lsup_coeff_tmp, aux_coeffs, fp->layers[k]->output_size[0], fp->layers[k]->output_size[1], fp->layers[k]->output_size[2], fp->layers[k]->input_size[0], fp->layers[k]->input_size[1], fp->layers[k]->input_size[2], fp->layers[k]->filter_size[0], fp->layers[k]->filter_size[1], fp->layers[k]->strides[0], fp->layers[k]->strides[1], fp->layers[k]->pad[0], fp->layers[k]->pad[1]);

            csts_from_previous_layer_conv<<<num_out_neurons_last_layer, 1>>>(linf_coeff, lsup_coeff, linf_cst, lsup_cst, linf_cst_tmp, lsup_cst_tmp, fp->layers[k]->filter_bias, num_out_neurons_last_layer, fp->layers[k]->output_size[0], fp->layers[k]->output_size[1], fp->layers[k]->output_size[2]);
        }
        else
        {
            coeffs_from_previous_layer<<<num_blocks_linear, num_threads>>>(linf_coeff, lsup_coeff, linf_coeff_tmp, lsup_coeff_tmp, aux_coeffs, num_out_neurons_current_layer, num_in_neurons_current_layer);

            csts_from_previous_layer<<<num_out_neurons_last_layer, 1>>>(linf_coeff, lsup_coeff, linf_cst, lsup_cst, linf_cst_tmp, lsup_cst_tmp, aux_csts, num_out_neurons_last_layer, num_out_neurons_current_layer);
        }
