This repository contains the materials for tutorial proposal. Some of the provided code is intentionally removed, allowing tutorial attendees to implement missing parts and learn how to use functions written in Cython and C++ within their Python libraries.
-
utils.py- contains implementation of python baselines and auxilarity functions -
utils_cython.pyx- contains naive implementation of$X^tX$ and$X^ty$ functions in Cython and dispatcher between different implementations in Cython -
utils_pybind.cpp- contains naive implementation of$X^tX$ and$X^ty$ functions and dispatcher between other different implementations in C++ -
benchmarks.py- contains benchmarks to compare performance of different methods -
setup.py- script used to build the modules -
solutions/- folder containing solutions to tutorial and implementations of helper functions. Files there should not be modified and should be used for reference only. Please don't look to solutions before the end of respective practice session not to spoil the fun!
-
Install conda/mamba through the miniforge installer:
- Windows:
start /wait "" Miniforge3-Windows-x86_64.exe /InstallationType=JustMe /RegisterPython=0 /S /D=%UserProfile%\Miniforge3
Source conda:
Miniforge3\Scripts\activate.bat
- Linux and macOS:
curl -L -O "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-$(uname)-$(uname -m).sh"Source conda (e.g. like this in bash, use other scripts for other shells like zsh):
eval "$(miniforge3/bin/conda shell.bash hook)"
-
Create an environment with Python, compiler toolchain, and PyData stack:
conda create -n linreg_env -c conda-forge python numpy scipy cython pybind11 setuptools scikit-learn threadpoolctl cxx-compiler
Activate environment:
conda activate linreg_env- Build the extension modules for this tutorial
python setup.py build_ext --inplace --force
- Set the environment variable
PRACTICE_NUMwith correct practice session number
On Linux/MacOS:
export PRACTICE_NUM=1
On Windows:
set PRACTICE_NUM=1
- Runtime benchmarks
python benchmarks.py
- You can also run the tests for your functions using
python tests.py
