Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
rustdef: Rust on Jupyter Notebook
Search
Ryosuke Kamesawa
March 24, 2020
Programming
0
30
rustdef: Rust on Jupyter Notebook
Jupyter notebook上でRustを実行できる拡張機能rustdefの紹介です。
Ryosuke Kamesawa
March 24, 2020
Tweet
Share
More Decks by Ryosuke Kamesawa
See All by Ryosuke Kamesawa
推論エンジンMAXの紹介
emakryo
1
460
ニューラルネットワークの量子化手法の紹介
emakryo
3
2.6k
MediaPipeの紹介
emakryo
0
41
Customizing Cargo for Cross Compiling
emakryo
0
27
Feature Store in DRIVE CHART
emakryo
0
36
Feature StoreをRustで実装した話
emakryo
0
36
なぜRustか?
emakryo
0
32
Cargo-makeを使ってみた
emakryo
0
260
Machine Learning on Graph Data @ICML2019
emakryo
0
16
Other Decks in Programming
See All in Programming
Spring gRPC について / About Spring gRPC
mackey0225
0
220
『GO』アプリ データ基盤のログ収集システムコスト削減
mot_techtalk
0
110
データの整合性を保つ非同期処理アーキテクチャパターン / Async Architecture Patterns
mokuo
41
15k
Introduction to kotlinx.rpc
arawn
0
630
CI改善もDatadogとともに
taumu
0
110
chibiccをCILに移植した結果 (NGK2025S版)
kekyo
PRO
0
210
Amazon Bedrock Multi Agentsを試してきた
tm2
1
280
WebDriver BiDiとは何なのか
yotahada3
1
140
Formの複雑さに立ち向かう
bmthd
1
720
Kubernetes History Inspector(KHI)を触ってみた
bells17
0
200
なぜイベント駆動が必要なのか - CQRS/ESで解く複雑系システムの課題 -
j5ik2o
7
2.5k
Pythonでもちょっとリッチな見た目のアプリを設計してみる
ueponx
1
480
Featured
See All Featured
Code Reviewing Like a Champion
maltzj
521
39k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
45
2.3k
Building Your Own Lightsaber
phodgson
104
6.2k
Music & Morning Musume
bryan
46
6.3k
Raft: Consensus for Rubyists
vanstee
137
6.8k
How to train your dragon (web standard)
notwaldorf
90
5.8k
Why Our Code Smells
bkeepers
PRO
335
57k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.4k
Embracing the Ebb and Flow
colly
84
4.6k
For a Future-Friendly Web
brad_frost
176
9.5k
Designing for Performance
lara
604
68k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
49
2.3k
Transcript
rustdef: Rust on Jupyter notebook @Shinjuku.rs 2020/03/24 Ryosuke Kamesawa
自己紹介 亀澤諒亮 Ryosuke Kamesawa - Twitter: @cruelturtle - Rust 歴
1年 - 仕事で使い始めて半年 - エッジデバイス向けの機械学習モデルの開発 - 趣味 - ボルダリング - 競プロ
Rust on Jupyter notebook??? Jupyter notebook - Pythonのブラウザベースの実行環境 - 画像やグラフ、表の表示が簡単で
機械学習やデータ解析に使われる - 普段Jupyterしか触らないPythonエンジニアにも Rustを普及させたい! → Jupyter上で簡単にRustを動かしたい! (Rust ライブラリのPython wrapperを書くのが面倒)
rustdef 作った https://github.com/emakryo/rustdef - Jupyter の拡張機能として実装 - Jupyter の magic
cellを使ってRustの関数を定義 - 定義した関数をPythonから実行 - ユースケース - Pythonで遅い場合のピンポイントでの高速化 - Rustのライブラリを手軽に Python binding
デモ - 手元にPython環境, Rust環境 (nightly) (Linux or Mac) がある人は $
pip install jupyter rustdef $ jupyter notebook - https://github.com/emakryo/rustdef/blob/master/examples/Get%20started.ipynb
使い方 - %%rustdefで始まるセル内でRustの関数、構造体などが定義できる - #[pyfunction] マクロのついた関数がpythonから呼び出せるようになる - 型の対応 (Python :
Rust) (PyO3に準拠) - int : {i32, i64, isize, u32, u64, usize} - float : {f32, f64} - str : {&str, String} - list : {Vec<_>, &[_]} - dict : HashMap<_, _>
How does it work? 1. magic cell 1つにつきセル内のコードが埋め込まれたcrateを1つ生成 2. maturinを使ってpython
package (wheel) を生成 3. python packageをインストール 4. pyfunction マクロのついた関数をpythonの名前空間にインポート
最後に - rustdef - Jupyter notebook上でRustの関数を定義、実行できる拡張機能 - TODO - Rustの構造体をPythonのクラスとしてexport
- rustdef cell内での実行 - 依存クレートの指定オプションの追加 - ぜひ使ってみてください - Issue/PR お待ちしています
PyO3 / Maturin PyO3 https://github.com/PyO3/pyo3 - PythonのC FFI向けにRustをコンパイルするための便利ライブラリ - 型変換やexternな関数の生成をやってくれる
Maturin https://github.com/PyO3/maturin - PyO3を使って書かれたcrateをpython package(wheel)にビルドするツール
類似ツール Evcxr https://github.com/google/evcxr - Jupyter notebookのkernel (実行エンジン) をRustにする - Rust
only rust-magic https://pypi.org/project/rust-magic - magic cellを使ってRustを実行 - Pythonとの連携はできない