Skip to content

Commit

Permalink
Raise exception when empty list is passed
Browse files Browse the repository at this point in the history
  • Loading branch information
3nthusia5t committed May 18, 2024
1 parent fc48e97 commit 2a7341f
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions entro.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 2a7341f

Please sign in to comment.