From 2a7341f325f9540f75bd259e5da5ac8175c19a63 Mon Sep 17 00:00:00 2001 From: 3nthusia5t <3nthusiast@protonmail.com> Date: Sat, 18 May 2024 22:29:41 +0200 Subject: [PATCH] Raise exception when empty list is passed --- entro.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/entro.py b/entro.py index c728472..8970a36 100644 --- a/entro.py +++ b/entro.py @@ -69,6 +69,10 @@ def sum_array(arr, result): def entropy_with_cuda(data): + # The entropy value for empty set is 0. + # However, the main goal of the function is to calculate file entropy, so raising an exception is more practical in this case. + if not data: + raise ValueError('The list is empty and cannot be processed.') data_size = len(data) data_gpu = cuda.to_device(np.frombuffer(data, dtype=np.uint8))