torchgear.math¶
- torchgear.math.abs2(x: Tensor) Tensor[source]¶
Computes the squared magnitude of a tensor.
- Parameters:
x (Tensor) – Input tensor (real or complex).
- Returns:
Squared magnitude for complex input, or square for real input.
- Return type:
Tensor
- torchgear.math.expi(x: Tensor) Tensor[source]¶
Computes the complex exponential of a real-valued tensor:
\[y=\text{e}^{\text{i} x}\]- Parameters:
x – A real-valued tensor.
- Returns:
Complex exponential of
x.- Return type:
Tensor
- torchgear.math.polynomial(x, coefficients: Sequence)[source]¶
Computes the value of a polynomial:
\[f(x)=a_0+a_1x+a_2x^2+\ldots+a_nx^n\]- Parameters:
x – Value of \(x\).
coefficients (Sequence) – Coefficients \(a_0,\ldots,a_n\).
Noneincoefficientsis interpreted as zero but the last coefficient (i.e. the coefficient of the highest-order-term) cannot beNone.
- Returns:
Value of \(f(x)\).
- torchgear.math.ssqrt(x: Tensor) tuple[Tensor, Tensor][source]¶
Secure version of
torch.sqrt(). Negative values are treated as zero to avoid NaNs in result.- Parameters:
x (Tensor) – Input tensor.
- Returns:
A 2-tuple of tensor. The first is
torch.sqrt(x.relu())and the second is a bool tensor representing non-negative values inx.