Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions python/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
## Numba Implementation

A high-performance Numba JIT-compiled implementation is available in `medcouple_numba.py`.

### Installation
```bash
pip install numba
```
Example usage:
```python
from medcouple_numba import medcouple_matrix_full
result = medcouple_matrix_full(data)
```
### Performance:

The Numba implementation with parallel execution achieves sensitive speedup compared to the pure NumPy implementation.

I have also added more descriptive tests, `test_df.py` and `test_numba.py`, that require pandas and tqdm.

If you want to print the table in markdown format, you need to install `tabulate` and `print(summary.to_markdown())`.

#### Numba implementation:

**Summary of the results ordered by mean timings:**

| Test case | mean_results | mean_timings | min_timings | max_timings | all_passed |
|:-----------------------------------------|---------------:|---------------:|--------------:|--------------:|:-------------|
| naive_loop_kernel_same_partial_False_1 | 0.246938 | 0.00855717 | 0.000555452 | 0.034805 | True |
| naive_loop_kernel_same_partial_True_0 | 0.246938 | 0.00961762 | 0.000663259 | 0.0375037 | True |
| naive_loop_kernel_same_partial_False_0 | 0.246938 | 0.0102791 | 0.000552418 | 0.0488931 | True |
| naive_loop_kernel_same_partial_True_1 | 0.246938 | 0.0105872 | 0.000536229 | 0.045166 | True |
| naive_loop_kernel_same_monotonic_False_0 | 0.246938 | 0.0164787 | 0.000534889 | 0.0921133 | True |
| naive_loop_kernel_same_full_True_1 | 0.246938 | 0.0167137 | 0.000599015 | 0.0928224 | True |
| naive_loop_kernel_same_full_False_0 | 0.246938 | 0.0169012 | 0.000556725 | 0.0990537 | True |
| naive_loop_kernel_same_full_True_0 | 0.246938 | 0.017097 | 0.000521972 | 0.0945251 | True |
| naive_loop_kernel_same_monotonic_True_0 | 0.246938 | 0.0174738 | 0.00050252 | 0.0996008 | True |
| naive_loop_kernel_same_monotonic_False_1 | 0.246938 | 0.0178723 | 0.000503608 | 0.0993816 | True |
| naive_loop_kernel_same_monotonic_True_1 | 0.246938 | 0.0181392 | 0.000615125 | 0.10721 | True |
| naive_loop_kernel_same_full_False_1 | 0.246938 | 0.0183009 | 0.000682849 | 0.10718 | True |
| naive_matrix_gen_matrix_same_partial | 0.246938 | 0.0484474 | 0.000206347 | 0.256039 | True |
| statsmodels_medcouple | 0.246938 | 0.0578549 | 0.0058599 | 0.27967 | True |
| naive_matrix_gen_matrix_same_full | 0.246938 | 0.0579054 | 0.000199287 | 0.300115 | True |
| naive_matrix_gen_matrix_same_monotonic | 0.246938 | 0.0595919 | 0.000248522 | 0.304371 | True |

Group averages:

Statsmodels: 0.057855s\
naive_loop average: 0.014835s\
naive_matrix average: 0.055315s\
Matrix is 3.73x slower than loop\
Loop is 3.90x faster than statsmodels\
Matrix is 1.05x faster than statsmodels

#### Numpy implementation:

**Summary of the results ordered by mean timings:**

| Test case | mean_results | mean_timings | min_timings | max_timings | all_passed |
|:-----------------------------------------|---------------:|---------------:|--------------:|--------------:|:-------------|
| statsmodels_medcouple | 0.246938 | 0.0661967 | 0.00758035 | 0.332696 | True |
| naive_matrix_gen_matrix_same_partial | 0.246938 | 0.0706036 | 0.00720444 | 0.345422 | True |
| naive_matrix_gen_matrix_same_full | 0.246938 | 0.0778316 | 0.00530281 | 0.426505 | True |
| naive_matrix_gen_matrix_same_monotonic | 0.246938 | 0.0892744 | 0.00724118 | 0.507823 | True |
| naive_loop_kernel_same_full_True_1 | 0.246938 | 0.714831 | 0.00451493 | 2.38954 | True |
| naive_loop_kernel_same_partial_False_0 | 0.246938 | 0.734988 | 0.0053756 | 2.49929 | True |
| naive_loop_kernel_same_monotonic_False_1 | 0.246938 | 0.746236 | 0.00525514 | 2.64932 | True |
| naive_loop_kernel_same_partial_True_1 | 0.246938 | 0.747932 | 0.00583358 | 2.52636 | True |
| naive_loop_kernel_same_full_False_0 | 0.246938 | 0.750571 | 0.00578721 | 2.48884 | True |
| naive_loop_kernel_same_monotonic_True_1 | 0.246938 | 0.755513 | 0.0054866 | 2.6988 | True |
| naive_loop_kernel_same_partial_True_0 | 0.246938 | 0.759996 | 0.00592637 | 2.65849 | True |
| naive_loop_kernel_same_full_False_1 | 0.246938 | 0.772812 | 0.00591261 | 2.73194 | True |
| naive_loop_kernel_same_monotonic_False_0 | 0.246938 | 0.77304 | 0.00468273 | 2.93801 | True |
| naive_loop_kernel_same_partial_False_1 | 0.246938 | 0.778947 | 0.00507722 | 2.84921 | True |
| naive_loop_kernel_same_monotonic_True_0 | 0.246938 | 0.782877 | 0.0050175 | 2.94109 | True |
| naive_loop_kernel_same_full_True_0 | 0.246938 | 0.792352 | 0.00480242 | 2.97309 | True |

Group averages:

Statsmodels: 0.066197s\
naive_loop average: 0.759175s\
naive_matrix average: 0.079237s\
Matrix is 9.58x faster than loop\
Loop is 11.47x slower than statsmodels\
Matrix is 1.20x slower than statsmodels

#### Numpy vs Numba

Naive Loop is **51.17x** faster in Numba.\
Matrix is 1.43x faster in Numba.

**Loops are extremely fast in Numba!**
Loading