Giter VIP home page Giter VIP logo

numeric-rust-python-tutorial's Introduction

The Rust and the Python

A tutorial for writing numerical Python extensions with Rust and ndarray

This session is a special technical session that features a tutorial and introduction on coding machine learning algorithms and other computationally extensive software. Python is the de-facto standard in Machine Learning and Data Science, and Rust is a very modern, and fast systems programming language that has been elected the most beloved programming the last 5 years in a row on stackoverflow. " .. but written in Rust" became a common news headline. Let's explore how both languages can benefit from each other!

The session covers the evolution of a (simple but complete) machine learning algorithm from scratch. We start with the translation of formulas into clean, modern and efficient code, modern packaging ready for upload to a package registry, and the successive translation of parts of the algorithms to a compiled language for performance gains. A performance analysis will reveal whether the Python's reputation for being slow is justified and may hold some surprise. There are many tutorials out there for connecting Rust with Python but only few focus on numeric computation and numpy compatibility like this one. All code is published on GitHub and may be used as a template for your own projects.

AI-generated image about a dark cult of the crab

Setup the Python package

$ # Python packaging and dependency management
$ curl -sSL https://install.python-poetry.org | python3 -
$ # Get the code
$ git clone [email protected]:StefanUlbrich/numeric-rust-python-tutorial.git tutorial
$ cd tutorial && git checkout python-skeleton
tutorial$ # Create virtual environment and install dependencies
tutorial$ poetry env use python3.11 # Optional
tutorial$ poetry install

Setup the Rust benchmark

$ # Installation
$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
$ rustup update # Optional: Update the tool chain
$ cd tutorial && git checkout rust-examples
tutorial$ # git checkout rust-implementation # spoiler alert!
tutorial$ (cd data; poetry run data) # we need data for the experiments
tutorial$ cargo run --example read_data
tutorial$ # cargo bench # run benchmarks later

Setup the extension

tutorial$ git checkout extension-skeleton
tutorial$ # git checkout extension-final # spoiler alert!
tutorial$ maturin develop -r --strip # Builds the extensions and adds it to the venv
tutorial$ maturin build -r --strip # Creates a binary wheel

numeric-rust-python-tutorial's People

Contributors

stefanulbrich avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

svmldon

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.