Skip to content

Commit

Permalink
Breakout common changes in fourier_gaussian (#45)
Browse files Browse the repository at this point in the history
In all cases `sigma` is squared, the result is divided by `2`, and the
negative of the result taken. These can be factored out into a common
change to just `sigma` that is reused in all of the other computations.
Admittedly Dask is smart enough to capture the reused computation of
`sigma` squared, but it is not a symbolic algebra library. So it won't
be able to pick up on the other changes, but we can. This should
simplify the resulting graph and make it easy to reuse some common
changes to `sigma` before `tensordot` is computed over multiple arrays
and these changes applied.
  • Loading branch information
jakirkham authored Sep 1, 2018
1 parent 1540adf commit d5b0a4e
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion dask_image/ndfourier/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ def fourier_gaussian(input, sigma, n=-1, axis=-1):
)

# Compute Fourier transformed Gaussian
scale = - (sigma ** 2) / 2
gaussian = dask.array.exp(
- dask.array.tensordot(sigma ** 2, ang_freq_grid ** 2, axes=1) / 2
dask.array.tensordot(scale, ang_freq_grid ** 2, axes=1)
)

result = input * gaussian
Expand Down

0 comments on commit d5b0a4e

Please sign in to comment.