---
title: "ClikaRT::ops::fold"
sidebar_label: "fold"
description: "col2im: the inverse of unfold; it sums overlapping windows back into a channels-last image."
---

<!-- Generated by tools/doxygen2mdx from Doxygen XML. Do not edit. -->

<span class="api-kind api-kind--function">function</span>

## fold() {#fold}

<div class="api-signature">

[`Tensor`](../Tensor.md) **`fold`**(<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`Tensor`](../Tensor.md) `input`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`ClikaRT::Span`](../Span.md)`<const std::int64_t>` `output_size`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`ClikaRT::Span`](../Span.md)`<const std::int64_t>` `kernel_size`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`ClikaRT::Span`](../Span.md)`<const std::int64_t>` `dilation` `=` `{}`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`ClikaRT::Span`](../Span.md)`<const std::int64_t>` `padding` `=` `{}`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`ClikaRT::Span`](../Span.md)`<const std::int64_t>` `stride` `=` `{}`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`PadMode`](./index.md#PadMode) `mode` `=` [`PadMode::Constant`](./index.md#PadMode),<br />
&nbsp;&nbsp;&nbsp;&nbsp;`std::optional<double>` `value` `=` `std::nullopt`<br />
)

</div>

col2im: the inverse of [`unfold`](./unfold.md#unfold); it sums overlapping windows back into a channels-last image.

Input `[N, L, prod(kernel_size), C]`; overlapping window contributions ADD (so `fold(unfold(x))` multiplies overlapped elements by their coverage count).

**Parameters**

- `input`: `[N, L, prod(kernel_size), C]`.
- `output_size`: the spatial extents of the reconstructed image.
- `kernel_size`: per-dim window extents.
- `dilation`: per-dim window dilation; empty (the default) is 1 per dim.
- `padding`: the `(low, high)` zero-padding pairs per spatial axis; empty (the default) pads nothing.
- `stride`: per-dim window step; empty (the default) is 1 per dim.

**Throws**

- `ClikaRT::Error`: when the input's dtype/shape is not served for this operation (the machine-readable reason rides `code_name()`).

**Returns:** channels-last `[N, output_size.., C]`.

<div class="api-declared">

Declared in `ClikaRT/compute/ops.h`, line 2003

</div>
