---
title: "ClikaRT::ops::constant_pad"
sidebar_label: "constant_pad"
description: "pad with a constant fill. Pads each axis by interleaved (lo, hi) pairs in layout order: pair i pads axis i; fewer pairs than the rank pads only the leading axes; a negative width crops that side."
---

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

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

## constant\_pad() {#constant_pad}

<div class="api-signature">

[`Tensor`](../Tensor.md) **`constant_pad`**(<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`Tensor`](../Tensor.md) `input`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`ClikaRT::Span`](../Span.md)`<const` [`ScalarOrTensor`](../ScalarOrTensor.md)`>` `pad`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`std::optional<`[`ScalarOrTensor`](../ScalarOrTensor.md)`>` `value` `=` `std::nullopt`<br />
)

</div>

[`pad`](./pad.md#pad) with a constant fill.

Pads each axis by interleaved `(lo, hi)` pairs in layout order: pair `i` pads axis `i`; fewer pairs than the rank pads only the leading axes; a negative width crops that side. Widths are literals or 0-D integer Tensors. Copies.

**Parameters**

- `value`: the fill; absent = 0. Default: absent.

**Throws**

- `ClikaRT::Error`: (`INVALID_ARGUMENT`) when the pair list exceeds the rank or a crop exceeds the extent (`code_name()` carries the reason).

**Returns:** a new tensor with each padded axis grown by `lo + hi`.

```cpp
auto padded = ClikaRT::ops::constant_pad(img, {0,0, 1,1, 1,1});  // H and W by 1
```

<div class="api-declared">

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

</div>
