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

sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
tduccuong
Hi, is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
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
earth10
Hi, I’m just starting to build a side-project with Elixir and Phoenix and doing some basic test with Elixir alone. What strikes me is th...
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New

Other popular topics Top

danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 29603 241
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
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
Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 127089 1222
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
jaysoifer
Is there a way to rollback a specific migration and only that one (“skipping” all the other ones)? Would mix ecto.rollback -v 200809061...
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement