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.
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 againsta) or a scalar literal (adopts the promoted dtype, stays exact past 2^53 for integers).alpha: scale onotherbefore the add; default1.0(plaina + other).activation: fused elementwise epilogue applied to the result in the same kernel pass; defaultActivation::Identity(no epilogue). Requires a float dtype; gated activations (SwiGlu/GeGlu/ReGlu) are refused here; apply them viaops::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-floatactivationoperand dtype or a gated activation kind.auto y = ClikaRT::ops::add(x, residual); // x + residualauto 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 . 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