Skip to content

Commit c436fa6

Browse files
committed
Switched all dtypes to 32-bit unsigned integers instead of 64-bit
Reasons: - np.bincount can't work with uint64 safely open issues: numpy/numpy#17760 numpy/numpy#823 numpy/numpy#4384 - Not easy to exceed the largest 32-bit uint: 4294967295 - UTF-8 can have 4 bytes or 32 bits max - Platform-independence is not the goal since other parts of the module have 64-bit floats
1 parent 4b6b8c5 commit c436fa6

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

‎entropy/entropy.py‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -659,11 +659,15 @@ def sample_entropy(x, order=2, metric='chebyshev'):
659659
return -np.log(np.divide(phi[1], phi[0]))
660660

661661

662+
<<<<<<< HEAD
662663
<<<<<<< HEAD
663664
@jit("uint32(uint32[:])", nopython=True)
664665
=======
665666
@jit("uint64(uint64[:])", nopython=True)
666667
>>>>>>> 7c30753 (Updated LZ complexity estimation with speed bump and integer typing)
668+
=======
669+
@jit("uint32(uint32[:])", nopython=True)
670+
>>>>>>> 59584bb (Switched all dtypes to 32-bit unsigned integers instead of 64-bit)
667671
def _lz_complexity(binary_string):
668672
"""Internal Numba implementation of the Lempel-Ziv (LZ) complexity.
669673
@@ -805,6 +809,7 @@ def lziv_complexity(sequence, normalize=False):
805809
sequence = np.asarray(sequence)
806810
if sequence.dtype.kind in 'bfi':
807811
# Convert [True, False] or [1., 0.] to [1, 0]
812+
<<<<<<< HEAD
808813
<<<<<<< HEAD
809814
s = sequence.astype("uint32")
810815
else:
@@ -816,14 +821,21 @@ def lziv_complexity(sequence, normalize=False):
816821
s = np.fromiter(map(ord, sequence), dtype="uint32")
817822
=======
818823
s = sequence.astype("uint64")
824+
=======
825+
s = sequence.astype("uint32")
826+
>>>>>>> 59584bb (Switched all dtypes to 32-bit unsigned integers instead of 64-bit)
819827
else:
820828
# Treat as numpy array of strings
821829
# Map string characters to utf-8 integer representation
822-
s = np.fromiter(map(ord, "".join(sequence.astype(str))), dtype="uint64")
823-
# Can't preallocate length (by specifying ocunt) due to string concatenation
830+
s = np.fromiter(map(ord, "".join(sequence.astype(str))), dtype="uint32")
831+
# Can't preallocate length (by specifying count) due to string concatenation
824832
else:
833+
<<<<<<< HEAD
825834
s = np.fromiter(map(ord, sequence), dtype="uint64")
826835
>>>>>>> 7c30753 (Updated LZ complexity estimation with speed bump and integer typing)
836+
=======
837+
s = np.fromiter(map(ord, sequence), dtype="uint32")
838+
>>>>>>> 59584bb (Switched all dtypes to 32-bit unsigned integers instead of 64-bit)
827839

828840
if normalize:
829841
# 1) Timmermann et al. 2019
@@ -838,11 +850,15 @@ def lziv_complexity(sequence, normalize=False):
838850
# return _lz_complexity(s) / _lz_complexity(s_shuffled)
839851
# 2) Zhang et al. 2009
840852
n = len(s)
853+
<<<<<<< HEAD
841854
<<<<<<< HEAD
842855
base = sum(np.bincount(s) > 0) # Number of unique characters
843856
=======
844857
base = len(set(s)) # Number of unique characters
845858
>>>>>>> 7c30753 (Updated LZ complexity estimation with speed bump and integer typing)
859+
=======
860+
base = len(np.bincount(s) > 0) # Number of unique characters
861+
>>>>>>> 59584bb (Switched all dtypes to 32-bit unsigned integers instead of 64-bit)
846862
base = 2 if base < 2 else base
847863
return _lz_complexity(s) / (n / log(n, base))
848864
else:

0 commit comments

Comments
 (0)