pyitlib icon indicating copy to clipboard operation
pyitlib copied to clipboard

Windows `int` type issue

Open Kaketo opened this issue 2 years ago • 1 comments

I have a problem running the package on the Windows system (on Mac and Linux it works like a charm).

from pyitlib import discrete_random_variable as drv
drv.entropy(np.array([1.5,1.4,0.2]))

throws

---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
Cell In[7], line 2
      1 from pyitlib import discrete_random_variable as drv
----> 2 drv.entropy(np.array([1.5,1.4,0.2]))

File ~\Envs\multi-label-cs-group-fs\lib\site-packages\pyitlib\discrete_random_variable.py:3843, in entropy(X, base, fill_value, estimator, Alphabet_X, keep_dims)
   3840 if not (np.isscalar(base) and np.isreal(base) and base > 0):
   3841     raise ValueError("arg base not a positive real-valued scalar")
-> 3843 S, fill_value = _map_observations_to_integers((X, Alphabet_X),
   3844                                               (fill_value_X,
   3845                                                fill_value_Alphabet_X))
   3846 X, Alphabet_X = S
   3848 H = np.empty(X.shape[:-1])

File ~\Envs\multi-label-cs-group-fs\lib\site-packages\pyitlib\discrete_random_variable.py:4695, in _map_observations_to_integers(Symbol_matrices, Fill_values)
   4692         assert(not np.any(A == FILL_VALUE))
   4693         A[A == f] = FILL_VALUE
-> 4695 assert(np.all([A.dtype == 'int' for A in Symbol_matrices]))
   4696 return Symbol_matrices, FILL_VALUE

AssertionError:

It seems that the default int on my machine is np.int32 not np.int64, because when I changed the assert in the source code of _map_observations_to_integers function

  • from assert(np.all([A.dtype == 'int' for A in Symbol_matrices]))
  • to assert(np.all([A.dtype in [np.dtype(np.intp), np.dtype(np.int32), np.dtype(np.int64)] for A in Symbol_matrices])) it works.

Maybe You have a suggestion on how to cover this bug in my code?

Kaketo avatar Feb 15 '23 17:02 Kaketo

Ran into the same issue

rzijp avatar Jul 10 '23 12:07 rzijp