---
title: "ClikaRT::ops::add"
sidebar_label: "add"
description: "Adds other (scaled) to input elementwise. \\[ out = act(a + \\alpha \\cdot other) \\] Broadcasting and type promotion, the contract every binary op on this surface shares: operand shapes broadcast per the…"
---

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

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

2 overloads.

## add(Tensor, ScalarOrTensor, double, Activation) {#add}

<div class="api-signature">

[`Tensor`](../Tensor.md) **`add`**(<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`Tensor`](../Tensor.md) `input`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`ScalarOrTensor`](../ScalarOrTensor.md) `other`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`double` `alpha` `=` `1.0`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`Activation`](./index.md#Activation) `activation` `=` [`Activation::Identity`](./index.md#Activation)<br />
)

</div>

Adds `other` (scaled) to `input` elementwise.

$$
out = act(a + \alpha \cdot other)
$$

Broadcasting and type promotion, the contract every binary op on this surface shares: operand shapes broadcast per the standard rules (trailing dims align; a 1 stretches), and dtypes promote to the dominant operand dtype per the promotion lattice (a scalar `other` keeps its weak kind; an integer literal with an integer tensor stays integral, a double promotes weak-float). The other ops below state "broadcasts and promotes as \`add\`" instead of restating this.

**Parameters**

- `input`: lhs tensor, any shape `[..]`.
- `other`: rhs: a tensor (broadcast against `input`) or a scalar literal (adopts the promoted dtype, stays exact past 2^53 for integers).
- `alpha`: scale on `other` before the add; default `1.0` (plain `a + other`).
- `activation`: fused elementwise epilogue applied to the result in the same kernel pass; default [`Activation::Identity`](./index.md#Activation) (no epilogue). Requires a float dtype; gated activations (SwiGlu/GeGlu/ReGlu) are refused here; apply them via [`ops::glu`](./glu.md#glu)-family calls instead.

**Returns:** the broadcast-shaped result at the promoted dtype.

**Throws**

- `ClikaRT::Error`: (`INVALID_ARGUMENT`) when the operand shapes are not broadcast-compatible. Also raises (`INVALID_ARGUMENT`) for a non-float `activation` operand dtype or a gated activation kind.

  ```cpp
  auto y = ClikaRT::ops::add(x, residual);            // x + residual
  auto z = ClikaRT::ops::add(x, bias, /*alpha=*/0.5); // x + 0.5*bias
  ```

<div class="api-declared">

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

</div>

## add(Scalar, Tensor, double, Activation) {#add-2}

<div class="api-signature">

[`Tensor`](../Tensor.md) **`add`**(<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`Scalar`](../Scalar.md) `input`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`Tensor`](../Tensor.md) `other`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`double` `alpha` `=` `1.0`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`Activation`](./index.md#Activation) `activation` `=` [`Activation::Identity`](./index.md#Activation)<br />
)

</div>

Scalar-LHS $act(a + \alpha \cdot b)$. `input` keeps its kind: an integer scalar with an integer tensor stays integral (weak-int promotion); a double promotes weak-float. The parameter set mirrors the tensor-first form: `alpha` scales the TENSOR operand `other`, `activation` applies to the result.

<div class="api-declared">

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

</div>
