Skip to main content

ClikaRT::ops::add

function

2 overloads.

add(Tensor, ScalarOrTensor, double, Activation)

Tensor add(
    Tensor a,
    ScalarOrTensor other,
    double alpha = 1.0,
    Activation activation = Activation::Identity
)

Adds other (scaled) to a elementwise.

out=act(a+αother)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

  • a: lhs tensor, any shape [..].
  • other: rhs: a tensor (broadcast against a) 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 (no epilogue). Requires a float dtype; gated activations (SwiGlu/GeGlu/ReGlu) are refused here; apply them via ops::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.

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

Declared in ClikaRT/compute/ops.h, line 1337

add(Scalar, Tensor, double, Activation)

Tensor add(
    Scalar a,
    Tensor b,
    double alpha = 1.0,
    Activation activation = Activation::Identity
)

Scalar-LHS act(a+αb)act(a + \alpha \cdot b). a 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 b, activation applies to the result.

Declared in ClikaRT/compute/ops.h, line 1347