You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: nx/lib/nx.ex
+26-9Lines changed: 26 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -13007,24 +13007,41 @@ defmodule Nx do
13007
13007
13008
13008
> #### Convolution vs Correlation {: .tip}
13009
13009
>
13010
-
> `conv/3` does not perform reversion nor conjugation of the kernel.
13010
+
> `conv/3` does not perform reversion of the kernel.
13011
13011
> This means that if you come from a Signal Processing background,
13012
-
> you might call this operation "correlation" instead of convolution.
13012
+
> you might treat it as a cross-correlation operation instead of a convolution.
13013
13013
>
13014
-
> If you need the proper Signal Processing convolution, you can use
13015
-
> `reverse/2` and `conjugate/1`, like in the example:
13014
+
> This function is not exactly a cross-correlation function, as it does not
13015
+
> perform conjugation of the kernel, as is done in [scipy.signal.correlate](https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.correlate.html).
13016
+
> This can be remedied via `Nx.conjugate/1`, as seen below:
13016
13017
>
13017
13018
> ```elixir
13018
-
> axes = Nx.axes(kernel) |> Enum.drop(2)
13019
-
>
13020
13019
> kernel =
13021
13020
> if Nx.Type.complex?(Nx.type(kernel)) do
13022
-
> Nx.conjugate(Nx.reverse(kernel, axes: axes))
13021
+
> Nx.conjugate(kernel)
13023
13022
> else
13024
-
> Nx.reverse(kernel, axes: axes)
13023
+
> kernel
13024
+
> end
13025
+
>
13026
+
> Nx.conv(tensor, kernel)
13027
+
> ```
13028
+
>
13029
+
> If you need the proper Signal Processing convolution, such as the one in
0 commit comments