A bug occurs when trying to compute a key rank approximation when non-finite scores are used.
To Reproduce
from scalib.postprocessing import rank_accuracy
import numpy as np
(rmin,r,rmax) = rank_accuracy(-np.log(np.zeros((1,2))),[0])
Observed behavior
<ipython-input-1-b61ab406b2ff>:3: RuntimeWarning: divide by zero encountered in log
(rmin,r,rmax) = rank_accuracy(-np.log(np.zeros((1,2))),[0])
thread '<unnamed>' panicked at 'Ranking error: Non-finite cost', scalib-py/src/ranking.rs:21:17
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
---------------------------------------------------------------------------
PanicException Traceback (most recent call last)
Cell In[1], line 3
1 from scalib.postprocessing import rank_accuracy
2 import numpy as np
----> 3 (rmin,r,rmax) = rank_accuracy(-np.log(np.zeros((1,2))),[0])
File ~/.pyenv/versions/3.10.13/lib/python3.10/site-packages/scalib/postprocessing/rankestimation.py:136, in rank_accuracy(costs, key, acc_bit, method, max_nb_bin)
100 r"""Estimate the rank of the full keys based on scores based on histograms.
101
102 Parameters
(...)
133 - **rmax** is an upper bound for the key rank.
134 """
135 with scalib.utils.interruptible():
--> 136 return _scalib_ext.rank_accuracy(
137 costs,
138 key,
139 2.0**acc_bit,
140 _choose_merge_value(costs),
141 method,
142 max_nb_bin,
143 get_config(),
144 )
PanicException: Ranking error: Non-finite cost
Expected behavior
Not panicking, handling particular case of non-finite value
Environment (please complete the following information):
OS: Ubuntu 20.04.6 LTS (Focal Fossa)
Python version: Python 3.10.13
numpy version: 1.26.4
SCALib version: 0.5.8
How did you install SCALib? PyPi
What CPU do you use? Intel(R) Xeon(R) Gold 6128 CPU @ 3.40GHz
Describe the bug
A bug occurs when trying to compute a key rank approximation when non-finite scores are used.
To Reproduce
Observed behavior
Expected behavior Not panicking, handling particular case of non-finite value
Environment (please complete the following information):
Additional context Python install from pyenv (https://github.com/pyenv/pyenv)