1414
1515
1616class ArrayProcessor :
17- NAME = ""
17+ NAME = ''
1818 SORT = - 1
1919
2020 def __init__ (self , array : np .ndarray ):
@@ -23,15 +23,15 @@ def __init__(self, array: np.ndarray):
2323
2424# -------------------------------------------------------------------------------
2525class AKArray2D1D (ArrayProcessor ):
26- NAME = " ak.array_to_tuple_array()"
26+ NAME = ' ak.array_to_tuple_array()'
2727 SORT = 0
2828
2929 def __call__ (self ):
3030 _ = array_to_tuple_array (self .array )
3131
3232
3333class PyArray2D1D (ArrayProcessor ):
34- NAME = " Python construction"
34+ NAME = ' Python construction'
3535 SORT = 1
3636
3737 def __call__ (self ):
@@ -52,83 +52,81 @@ def __call__(self):
5252def seconds_to_display (seconds : float ) -> str :
5353 seconds /= NUMBER
5454 if seconds < 1e-4 :
55- return f" { seconds * 1e6 : .1f} (µs)"
55+ return f' { seconds * 1e6 : .1f} (µs)'
5656 if seconds < 1e-1 :
57- return f" { seconds * 1e3 : .1f} (ms)"
58- return f" { seconds : .1f} (s)"
57+ return f' { seconds * 1e3 : .1f} (ms)'
58+ return f' { seconds : .1f} (s)'
5959
6060
6161def plot_performance (frame ):
62- fixture_total = len (frame [" fixture" ].unique ())
63- cat_total = len (frame [" size" ].unique ())
64- processor_total = len (frame [" cls_processor" ].unique ())
62+ fixture_total = len (frame [' fixture' ].unique ())
63+ cat_total = len (frame [' size' ].unique ())
64+ processor_total = len (frame [' cls_processor' ].unique ())
6565 fig , axes = plt .subplots (cat_total , fixture_total )
6666
6767 # cmap = plt.get_cmap('terrain')
68- cmap = plt .get_cmap (" plasma" )
68+ cmap = plt .get_cmap (' plasma' )
6969
7070 color = cmap (np .arange (processor_total ) / max (processor_total , 3 ))
7171
7272 # category is the size of the array
73- for cat_count , (cat_label , cat ) in enumerate (frame .groupby (" size" )):
73+ for cat_count , (cat_label , cat ) in enumerate (frame .groupby (' size' )):
7474 # each fixture is a collection of tests for one display
7575 fixtures = {
76- fixture_label : fixture for fixture_label , fixture in cat .groupby (" fixture" )
76+ fixture_label : fixture for fixture_label , fixture in cat .groupby (' fixture' )
7777 }
7878 for fixture_count , (fixture_label , fixture ) in enumerate (
7979 (k , fixtures [k ]) for k in FixtureFactory .DENSITY_TO_DISPLAY
8080 ):
8181 ax = axes [cat_count ][fixture_count ]
8282
8383 # set order
84- fixture [" sort" ] = [f .SORT for f in fixture [" cls_processor" ]]
85- fixture = fixture .sort_values (" sort" )
84+ fixture [' sort' ] = [f .SORT for f in fixture [' cls_processor' ]]
85+ fixture = fixture .sort_values (' sort' )
8686
87- results = fixture [" time" ].values .tolist ()
88- names = [cls .NAME for cls in fixture [" cls_processor" ]]
87+ results = fixture [' time' ].values .tolist ()
88+ names = [cls .NAME for cls in fixture [' cls_processor' ]]
8989 # x = np.arange(len(results))
9090 names_display = names
9191 post = ax .bar (names_display , results , color = color )
9292
9393 # density, position = fixture_label.split('-')
9494 # cat_label is the size of the array
95- title = (
96- f"{ cat_label :.0e} \n { FixtureFactory .DENSITY_TO_DISPLAY [fixture_label ]} "
97- )
95+ title = f'{ cat_label :.0e} \n { FixtureFactory .DENSITY_TO_DISPLAY [fixture_label ]} '
9896
9997 ax .set_title (title , fontsize = 6 )
10098 ax .set_box_aspect (0.75 ) # makes taller than wide
101- time_max = fixture [" time" ].max ()
99+ time_max = fixture [' time' ].max ()
102100 ax .set_yticks ([0 , time_max * 0.5 , time_max ])
103101 ax .set_yticklabels (
104102 [
105- "" ,
103+ '' ,
106104 seconds_to_display (time_max * 0.5 ),
107105 seconds_to_display (time_max ),
108106 ],
109107 fontsize = 4 ,
110108 )
111109 # ax.set_xticks(x, names_display, rotation='vertical')
112110 ax .tick_params (
113- axis = "x" ,
114- which = " both" ,
111+ axis = 'x' ,
112+ which = ' both' ,
115113 bottom = False ,
116114 top = False ,
117115 labelbottom = False ,
118116 )
119117
120118 fig .set_size_inches (8 , 4 ) # width, height
121- fig .legend (post , names_display , loc = " center right" , fontsize = 6 )
119+ fig .legend (post , names_display , loc = ' center right' , fontsize = 6 )
122120 # horizontal, vertical
123121 fig .text (
124122 0.05 ,
125123 0.96 ,
126- f" array_to_tuple_array() Performance: { NUMBER } Iterations" ,
124+ f' array_to_tuple_array() Performance: { NUMBER } Iterations' ,
127125 fontsize = 10 ,
128126 )
129127 fig .text (0.05 , 0.90 , get_versions (), fontsize = 6 )
130128
131- fp = " /tmp/array_to_tuple_array.png"
129+ fp = ' /tmp/array_to_tuple_array.png'
132130 plt .subplots_adjust (
133131 left = 0.05 ,
134132 bottom = 0.05 ,
@@ -140,17 +138,17 @@ def plot_performance(frame):
140138 # plt.rcParams.update({'font.size': 22})
141139 plt .savefig (fp , dpi = 300 )
142140
143- if sys .platform .startswith (" linux" ):
144- os .system (f" eog { fp } &" )
141+ if sys .platform .startswith (' linux' ):
142+ os .system (f' eog { fp } &' )
145143 else :
146- os .system (f" open { fp } " )
144+ os .system (f' open { fp } ' )
147145
148146
149147# -------------------------------------------------------------------------------
150148
151149
152150class FixtureFactory :
153- NAME = ""
151+ NAME = ''
154152
155153 @staticmethod
156154 def get_array (size : int , width_ratio : int ) -> np .ndarray :
@@ -164,11 +162,11 @@ def get_label_array(cls, size: int) -> tp.Tuple[str, np.ndarray]:
164162 return cls .NAME , array
165163
166164 DENSITY_TO_DISPLAY = {
167- " column-1" : " 1 Column" ,
168- " column-2" : " 2 Column" ,
169- " column-5" : " 5 Column" ,
170- " column-10" : " 10 Column" ,
171- " column-20" : " 20 Column" ,
165+ ' column-1' : ' 1 Column' ,
166+ ' column-2' : ' 2 Column' ,
167+ ' column-5' : ' 5 Column' ,
168+ ' column-10' : ' 10 Column' ,
169+ ' column-20' : ' 20 Column' ,
172170 }
173171
174172 # POSITION_TO_DISPLAY = {
@@ -178,7 +176,7 @@ def get_label_array(cls, size: int) -> tp.Tuple[str, np.ndarray]:
178176
179177
180178class FFC1 (FixtureFactory ):
181- NAME = " column-1"
179+ NAME = ' column-1'
182180
183181 @staticmethod
184182 def get_array (size : int ) -> np .ndarray :
@@ -187,7 +185,7 @@ def get_array(size: int) -> np.ndarray:
187185
188186
189187class FFC2 (FixtureFactory ):
190- NAME = " column-2"
188+ NAME = ' column-2'
191189
192190 @staticmethod
193191 def get_array (size : int ) -> np .ndarray :
@@ -196,7 +194,7 @@ def get_array(size: int) -> np.ndarray:
196194
197195
198196class FFC5 (FixtureFactory ):
199- NAME = " column-5"
197+ NAME = ' column-5'
200198
201199 @staticmethod
202200 def get_array (size : int ) -> np .ndarray :
@@ -205,7 +203,7 @@ def get_array(size: int) -> np.ndarray:
205203
206204
207205class FFC10 (FixtureFactory ):
208- NAME = " column-10"
206+ NAME = ' column-10'
209207
210208 @staticmethod
211209 def get_array (size : int ) -> np .ndarray :
@@ -214,7 +212,7 @@ def get_array(size: int) -> np.ndarray:
214212
215213
216214class FFC20 (FixtureFactory ):
217- NAME = " column-20"
215+ NAME = ' column-20'
218216
219217 @staticmethod
220218 def get_array (size : int ) -> np .ndarray :
@@ -225,7 +223,7 @@ def get_array(size: int) -> np.ndarray:
225223def get_versions () -> str :
226224 import platform
227225
228- return f" OS: { platform .system ()} / ArrayKit: { ak .__version__ } / NumPy: { np .__version__ } \n "
226+ return f' OS: { platform .system ()} / ArrayKit: { ak .__version__ } / NumPy: { np .__version__ } \n '
229227
230228
231229CLS_PROCESSOR = (
@@ -253,7 +251,7 @@ def run_test():
253251 record = [cls , NUMBER , fixture_label , size ]
254252 print (record )
255253 try :
256- result = timeit .timeit (f" runner()" , globals = locals (), number = NUMBER )
254+ result = timeit .timeit (f' runner()' , globals = locals (), number = NUMBER )
257255 except OSError :
258256 result = np .nan
259257 finally :
@@ -262,11 +260,11 @@ def run_test():
262260 records .append (record )
263261
264262 f = pd .DataFrame .from_records (
265- records , columns = (" cls_processor" , " number" , " fixture" , " size" , " time" )
263+ records , columns = (' cls_processor' , ' number' , ' fixture' , ' size' , ' time' )
266264 )
267265 print (f )
268266 plot_performance (f )
269267
270268
271- if __name__ == " __main__" :
269+ if __name__ == ' __main__' :
272270 run_test ()
0 commit comments