33import timeit
44import typing as tp
55
6- from arraykit import array2d_tuple_iter
6+ from arraykit import array_to_tuple_iter
77import arraykit as ak
88
99import matplotlib .pyplot as plt
@@ -21,18 +21,18 @@ def __init__(self, array: np.ndarray):
2121
2222#-------------------------------------------------------------------------------
2323class AKArray2DTupleList (ArrayProcessor ):
24- NAME = 'list(ak.array2d_tuple_iter (a2d))'
24+ NAME = 'list(ak.array_to_tuple_iter (a2d))'
2525 SORT = 0
2626
2727 def __call__ (self ):
28- _ = list (array2d_tuple_iter (self .array ))
28+ _ = list (array_to_tuple_iter (self .array ))
2929
3030class AKArray2DTupleNext (ArrayProcessor ):
31- NAME = 'next(ak.array2d_tuple_iter (a2d))'
31+ NAME = 'next(ak.array_to_tuple_iter (a2d))'
3232 SORT = 1
3333
3434 def __call__ (self ):
35- it = array2d_tuple_iter (self .array )
35+ it = array_to_tuple_iter (self .array )
3636 while True :
3737 try :
3838 _ = next (it )
@@ -45,19 +45,31 @@ class PyArray2DTupleMapList(ArrayProcessor):
4545
4646 def __call__ (self ):
4747 array = self .array
48- _ = list (map (tuple , array ))
48+ if array .ndim == 2 :
49+ _ = list (map (tuple , array ))
50+ else :
51+ _ = list (map (lambda e : (e ,), array ))
4952
5053class PyArray2DTupleIterNext (ArrayProcessor ):
5154 NAME = 'tuple(next(iter(a2d)))'
5255 SORT = 3
5356
5457 def __call__ (self ):
55- it = iter (self .array )
56- while True :
57- try :
58- _ = tuple (next (it ))
59- except StopIteration :
60- break
58+ array = self .array
59+ it = iter (array )
60+ if array .ndim == 2 :
61+ while True :
62+ try :
63+ _ = tuple (next (it ))
64+ except StopIteration :
65+ break
66+ else :
67+ while True :
68+ try :
69+ _ = (next (it ),)
70+ except StopIteration :
71+ break
72+
6173
6274
6375
@@ -128,10 +140,10 @@ def plot_performance(frame):
128140 fig .set_size_inches (8 , 4 ) # width, height
129141 fig .legend (post , names_display , loc = 'center right' , fontsize = 6 )
130142 # horizontal, vertical
131- fig .text (.05 , .96 , f'array2d_tuple_iter () Performance: { NUMBER } Iterations' , fontsize = 10 )
143+ fig .text (.05 , .96 , f'array_to_tuple_iter () Performance: { NUMBER } Iterations' , fontsize = 10 )
132144 fig .text (.05 , .90 , get_versions (), fontsize = 6 )
133145
134- fp = '/tmp/array2d_tuple_iter .png'
146+ fp = '/tmp/array_to_tuple_iter .png'
135147 plt .subplots_adjust (
136148 left = 0.05 ,
137149 bottom = 0.05 ,
@@ -156,21 +168,33 @@ class FixtureFactory:
156168
157169 @staticmethod
158170 def get_array (size : int , width_ratio : int ) -> np .ndarray :
159- return np .arange (size ).reshape (size // width_ratio , width_ratio )
171+ if width_ratio > 1 :
172+ return np .arange (size ).reshape (size // width_ratio , width_ratio )
173+ return np .arange (size ) # return 1D array
160174
161175 @classmethod
162176 def get_label_array (cls , size : int ) -> tp .Tuple [str , np .ndarray ]:
163177 array = cls .get_array (size )
164178 return cls .NAME , array
165179
166180 DENSITY_TO_DISPLAY = {
181+ 'column-1' : '1 Column' ,
167182 'column-2' : '2 Column' ,
168183 'column-5' : '5 Column' ,
169184 'column-10' : '10 Column' ,
170185 'column-20' : '20 Column' ,
171186 }
172187
173188
189+ class FFC1 (FixtureFactory ):
190+ NAME = 'column-1'
191+
192+ @staticmethod
193+ def get_array (size : int ) -> np .ndarray :
194+ a = FixtureFactory .get_array (size , 1 )
195+ return a
196+
197+
174198class FFC2 (FixtureFactory ):
175199 NAME = 'column-2'
176200
@@ -217,6 +241,7 @@ def get_versions() -> str:
217241
218242
219243CLS_FF = (
244+ FFC1 ,
220245 FFC2 ,
221246 FFC5 ,
222247 FFC10 ,
0 commit comments