---
title: "ClikaRT::ops::sub"
sidebar_label: "sub"
description: "Subtracts other (scaled) from input elementwise. \\[ out = act(a - \\alpha \\cdot other) \\] Broadcasts and promotes as add; alpha (default 1.0) scales other before the subtract, and activation is the sam…"
---

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

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

2 overloads.

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

<div class="api-signature">

[`Tensor`](../Tensor.md) **`sub`**(<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>

Subtracts `other` (scaled) from `input` elementwise.

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

Broadcasts and promotes as [`add`](./add.md#add); `alpha` (default `1.0`) scales `other` before the subtract, and `activation` is the same fused float-only epilogue (default [`Activation::Identity`](./index.md#Activation)).

**Returns:** the broadcast-shaped difference 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.

<div class="api-declared">

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

</div>

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

<div class="api-signature">

[`Tensor`](../Tensor.md) **`sub`**(<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 (see [`Scalar`](../Scalar.md)). 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 1608

</div>
