ds604

ds604

Use Nx operators in Livebook?

I’m relatively new to Elixir, but have been reading about translating to Nx from Numpy/PyTorch:
From Python to Elixir Machine Learning
Matrix multiplication from foundations

I was thinking that it would be helpful to be able to play around with Nx in Livebook. What I want is to be able to have the operators available, in the manner that they are available to defn functions, so that I can write in Livebook in a straightforward mathematical style (like Matlab). This is possible by having the module definition in a cell, with import Nx.Defn at the top:

But I am limited to working within this one cell. If I go outside of this cell, then I have to revert to using the pipeline style:

The way I can think to get what I want would be to wrap multiple cells in a module definition:

Then within this context, I’m working in “Matlab mode”. I’m wondering if this is currently possible by some means in Livebook? Or if not, maybe there’s some metaprogramming means of achieving this? I’m still reading up on Elixir basics, so it’s certainly possible I’m missing some fundamental understanding about how things work…

Thanks!

Most Liked

jonatanklosko

jonatanklosko

Creator of Livebook

Hey @ds604, you can do use Nx.Defn.Kernel at the top of your notebook, this is going to replace default imports, such as +, as it would within defn. We don’t recommend this in the docs or elsewhere, but it can be neat for experimentation, like in your case : )

jonatanklosko

jonatanklosko

Creator of Livebook

There is a view configuration in the bottom-right corner:

Code zen only shows dense code cells. You can also use “Custom” and show both Markdown and Code cells, it is going to hide the insert buttons, so things will be more dense. In those modes, you can still insert cells using the keyboard shortcuts : )

03juan

03juan

Are you referring to the various smart cells you can add to the livebook?

Those are kino components and because of the modular nature of the design they are each a self-contained library comparable to micro-frontends, so each manages its own style, e.g. kino_bumblebee css, kino_explorer css, kino_db css

Also, welcome to the community!

Where Next?

Popular in Questions Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
Tee
can someone please explain to me how Enum.reduce works with maps
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
Kurisu
For example for a current url like http://localhost:4000/cosmetic/products?_utf8=✓&query=perfume&page=2, I would like to get: ...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

Other popular topics Top

malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 41539 114
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 52341 488
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

Latest on Elixir Forum

We're in Beta

About us Mission Statement