@@ -711,51 +711,21 @@ def disable_tqdm():
711711 """Set the logger for verbosity messages."""
712712 return (True if (logger .getEffectiveLevel ()>= 30 ) else False )
713713
714- # def _make_unique(arr: np.ndarray):
715- # """Method iterates through elements of the input array to ensure all values are unique.
716- # Duplicate values are reduced by the smallest possible increment for the given data type.
717- # """
718- # logger.debug('Making values unique')
719- # res = np.empty_like(arr)
720- # it = np.nditer([arr, res], [], [['readonly'], ['writeonly', 'allocate']])
721- # seen = set()
722- # with it:
723- # while not it.finished:
724- # a = it[0].item()
725- # while a in seen and np.isfinite(a):
726- # a = np.nextafter(a, -np.inf)
727- # it[1] = a
728- # if a not in seen:
729- # seen.add(a)
730- # it.iternext()
731- # return res
732-
733- def _make_unique (arr : np .ndarray ) -> np .ndarray :
734- """Return array where duplicate finite values are slightly perturbed to make all values unique."""
735- # Convert to float64 if needed
736- if not np .issubdtype (arr .dtype , np .floating ):
737- arr = arr .astype (np .float64 )
738- dtype = arr .dtype
739-
740- arr_flat = arr .ravel ()
741- res = arr_flat .copy ()
742- is_finite = np .isfinite (res )
743- finite_vals = res [is_finite ]
744- unique , counts = np .unique (finite_vals , return_counts = True )
745- dupes = unique [counts > 1 ]
746- if dupes .size == 0 :
747- return arr .copy ()
748-
749- seen = {}
750- mask = np .isin (finite_vals , dupes )
751- indices = np .where (mask )[0 ]
752- values = finite_vals [mask ]
753-
754- for i , val in tqdm (zip (indices , values ), total = len (values ), disable = disable_tqdm (), desc = logger .info ("Making values unique" )):
755- count = seen .get (val , 0 )
756- perturbed = np .nextafter (val , - np .inf , dtype = dtype ) - count * np .finfo (dtype ).eps
757- finite_vals [i ] = perturbed
758- seen [val ] = count + 1
759-
760- res [is_finite ] = finite_vals
761- return res .reshape (arr .shape )
714+ def _make_unique (arr : np .ndarray ):
715+ """Method iterates through elements of the input array to ensure all values are unique.
716+ Duplicate values are reduced by the smallest possible increment for the given data type.
717+ """
718+ logger .debug ('Making values unique' )
719+ res = np .empty_like (arr )
720+ it = np .nditer ([arr , res ], [], [['readonly' ], ['writeonly' , 'allocate' ]])
721+ seen = set ()
722+ with it :
723+ while not it .finished :
724+ a = it [0 ].item ()
725+ while a in seen and np .isfinite (a ):
726+ a = np .nextafter (a , - np .inf )
727+ it [1 ] = a
728+ if a not in seen :
729+ seen .add (a )
730+ it .iternext ()
731+ return res
0 commit comments