Nx Tip of the Week #14 – Slicing and Indexing

Often times you want to slice and index into specific parts of a tensor. Nx offers a few different slicing and indexing routines which allow you to accomplish most of what you would want to do. Slicing can be a bit tricky given static shape requirements, but you usually can work around limitations. First, you … Continue reading Nx Tip of the Week #14 – Slicing and Indexing

Nx Tip of the Week #13 – Hooks

Part of the restrictiveness of defn is the inability to debug in the same way you would debug a normal Elixir function. I'm personally a big fan of plain old IO.inspect debugging. Because of how defn works, it's not possible to inspect intermediate tensor values in the same way you would inspect intermediate values in … Continue reading Nx Tip of the Week #13 – Hooks

Nx Tip of the Week #12 – Nx.to_heatmap

Sometimes you want to quickly visualize the contents of a tensor. For example, when working with the MNIST dataset, you might want to make sure you've sliced it up correctly. A quick way to visualize images across a single color channel is with Nx.to_heatmap: Nx.to_heatmap(img) When inspecting the result of Nx.to_heatmap, you'll get a nice … Continue reading Nx Tip of the Week #12 – Nx.to_heatmap

Nx Tip of the Week #11 – While Loops

Some numeric algorithms require sequential operations. In TOTW #9, we talked about one operation you can use to avoid while-loops in specific situations. Unfortunately, you won't always be able to avoid a while-loop. Nx has a while construct which is implemented as an Elixir macro. The while construct takes an initial state, a condition, and … Continue reading Nx Tip of the Week #11 – While Loops

Nx Tip of the Week #10 – Using Nx.select

Nx's API can seem a little more restrictive due to some of it's static shape requirements. For example, boolean indexing is not currently supported because it would be impossible to know the shape at runtime. For those who don't know boolean indexing selects values of an array based on some boolean mask. For example, let's … Continue reading Nx Tip of the Week #10 – Using Nx.select