Skip to content

Commit

Permalink
Implement elementwise complex value division (halide#7848)
Browse files Browse the repository at this point in the history
Implement the logic: (a + bj) / (c + dj) as an inline operator/()
function.

Use case: direct FFT method to solve linear least square problem,
namely:

```math
\begin{align}
 f(x) &=\Vert F^T D F x - b \Vert_2^2 \\
\arg \min_{x \in \mathbb{R}} f(x)
&= F^T \left[ D^{-1} F b \right]
\end{align}
```
where `D` is a diagonal complex-valued matrix representing image blur
kernel, `b` is an ordinary image in vectorized form.
  • Loading branch information
antonysigma authored and ardier committed Mar 3, 2024
1 parent 541d2a7 commit 25c812f
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions apps/fft/complex.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,15 @@ inline ComplexExpr operator*(Halide::Expr a, ComplexExpr b) {
inline ComplexExpr operator/(ComplexExpr a, Halide::Expr b) {
return ComplexExpr(re(a) / b, im(a) / b);
}
inline ComplexExpr
operator/(ComplexExpr z1, ComplexExpr z2) {
const auto a = re(z1);
const auto b = im(z1);
const auto c = re(z2);
const auto d = im(z2);

return ComplexExpr{(a * c + b * d) / (c * c + d * d), (b * c - a * d) / (c * c + d * d)};
}

// Compute exp(j*x)
inline ComplexExpr expj(Halide::Expr x) {
Expand Down

0 comments on commit 25c812f

Please sign in to comment.