Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!
Tips and Traps¶
- rustimport is a Python library which allows you to import Rust source files directly from Python! It is similar to rustdef @ GitHub but targeting use cases in Python code instead of in Jupyter/Lab notebooks.
In [ ]:
!pip3 install --user rustdef
In [16]:
import os
os.environ["PIP_USER"] = "yes"
os.environ["PIP_USER"]
Out[16]:
In [3]:
%load_ext rustdef
In [4]:
%rustdef deps add itertools@0.10.5
In [5]:
%%rustdef --release
use itertools::Itertools;
#[pyfunction]
fn build_combs3() -> [usize; 230300] {
let mut combs = [0; 230300];
let mut i = 0;
(3usize..50).for_each(|j| {
(0..j).combinations(3).for_each(|comb| {
combs[i] = (comb[2] << 8 | comb[1]) << 8 | comb[0];
i += 1;
});
});
combs
}
#[pyfunction]
fn build_combs3_index() -> [usize; 51] {
let mut indexes = [0; 51];
(3usize..50).for_each(|i| {
indexes[i + 1] = indexes[i] + i * (i - 1) * (i - 2) / 6;
});
indexes
}
In [6]:
combs3 = build_combs3()
In [7]:
len(combs3)
Out[7]:
In [8]:
combs3[:5]
Out[8]:
References¶
In [ ]: