44import numpy as np
55
66from ..downsampling_interface import AbstractDownsampler
7+ from abc import ABC
78
89
910def _get_bin_idxs (x : np .ndarray , nb_bins : int ) -> np .ndarray :
@@ -258,7 +259,59 @@ def _downsample(
258259 return np .array (sorted (rel_idxs ))
259260
260261
261- class FPCS_py (AbstractDownsampler ):
262+ class _MinMaxLTTB_py (AbstractDownsampler , ABC ):
263+ def __init__ (
264+ self , check_contiguous = True , x_dtype_regex_list = None , y_dtype_regex_list = None
265+ ):
266+ super ().__init__ (check_contiguous , x_dtype_regex_list , y_dtype_regex_list )
267+ self .minmax_downsampler : AbstractDownsampler = None
268+ self .lttb_downsampler : AbstractDownsampler = None
269+
270+ def _downsample (self , x , y , n_out , ** kwargs ):
271+ minmax_ratio = kwargs .get ("minmax_ratio" , 4 )
272+ kwargs .pop ("minmax_ratio" , None ) # remove the minmax_ratio from kwargs
273+
274+ # Is fine for this implementation as this is only used for testing
275+ if x is None :
276+ x = np .arange (y .shape [0 ])
277+
278+ n_1 = len (x ) - 1
279+ idxs = self .minmax_downsampler .downsample (
280+ x [1 :n_1 ], y [1 :n_1 ], n_out = n_out * minmax_ratio , ** kwargs
281+ )
282+ idxs += 1
283+ idxs = np .concat (([0 ], idxs , [len (y ) - 1 ])).ravel ()
284+ print ("idxs" , idxs )
285+ return idxs [
286+ self .lttb_downsampler .downsample (x [idxs ], y [idxs ], n_out = n_out , ** kwargs )
287+ ]
288+
289+
290+ class MinMaxLTTB_py (_MinMaxLTTB_py ):
291+ def __init__ (
292+ self , check_contiguous = True , x_dtype_regex_list = None , y_dtype_regex_list = None
293+ ):
294+ super ().__init__ (check_contiguous , x_dtype_regex_list , y_dtype_regex_list )
295+ self .minmax_downsampler = MinMax_py ()
296+ self .lttb_downsampler = LTTB_py ()
297+
298+
299+ class NaNMinMaxLTTB_py (_MinMaxLTTB_py ):
300+ def __init__ (
301+ self , check_contiguous = True , x_dtype_regex_list = None , y_dtype_regex_list = None
302+ ):
303+ super ().__init__ (check_contiguous , x_dtype_regex_list , y_dtype_regex_list )
304+ self .minmax_downsampler = NaNMinMax_py ()
305+ self .lttb_downsampler = LTTB_py ()
306+
307+
308+ class _FPCS_py (AbstractDownsampler , ABC ):
309+ def __init__ (
310+ self , check_contiguous = True , x_dtype_regex_list = None , y_dtype_regex_list = None
311+ ):
312+ super ().__init__ (check_contiguous , x_dtype_regex_list , y_dtype_regex_list )
313+ self .minmax_downsampler : AbstractDownsampler = None
314+
262315 def _downsample (
263316 self , x : Union [np .ndarray , None ], y : np .ndarray , n_out : int , ** kwargs
264317 ) -> np .ndarray :
@@ -272,11 +325,16 @@ class Flag(Enum):
272325 Point = NamedTuple ("point" , [("x" , int ), ("val" , y .dtype )])
273326 # ------------------------------------------------------------------------
274327
328+ # NOTE: is fine for this implementation as this is only used for testing
329+ if x is None :
330+ # Is fine for this implementation as this is only used for testing
331+ x = np .arange (y .shape [0 ])
332+
275333 # 0. Downsample the data using the MinMax algorithm
276334 MINMAX_FACTOR = 2
277335 n_1 = len (x ) - 1
278336 # NOTE: as we include the first and last point, we reduce the number of points
279- downsampled_idxs = MinMax_py () .downsample (
337+ downsampled_idxs = self . minmax_downsampler .downsample (
280338 x [1 :n_1 ], y [1 :n_1 ], n_out = (n_out - 2 ) * MINMAX_FACTOR
281339 )
282340 downsampled_idxs += 1
@@ -329,3 +387,19 @@ class Flag(Enum):
329387 sampled_indices .append (len (y ) - 1 ) # append the last point
330388 # fmt: on
331389 return np .array (sampled_indices , dtype = np .int64 )
390+
391+
392+ class FPCS_py (_FPCS_py ):
393+ def __init__ (
394+ self , check_contiguous = True , x_dtype_regex_list = None , y_dtype_regex_list = None
395+ ):
396+ super ().__init__ (check_contiguous , x_dtype_regex_list , y_dtype_regex_list )
397+ self .minmax_downsampler = MinMax_py ()
398+
399+
400+ class NaNFPCS_py (_FPCS_py ):
401+ def __init__ (
402+ self , check_contiguous = True , x_dtype_regex_list = None , y_dtype_regex_list = None
403+ ):
404+ super ().__init__ (check_contiguous , x_dtype_regex_list , y_dtype_regex_list )
405+ self .minmax_downsampler = NaNMinMax_py ()
0 commit comments