@@ -40,15 +40,15 @@ def __call__(self):
40
40
_ = np .nonzero (self .array )[0 ]
41
41
42
42
class NPNonZeroInt64Convert (ArrayProcessor ):
43
- NAME = 'np.nonzero().astype(np.int64)'
43
+ NAME = 'np.nonzero()\n .astype(np.int64)'
44
44
SORT = 3
45
45
46
46
def __call__ (self ):
47
47
_ = np .nonzero (self .array )[0 ].astype (np .int64 )
48
48
49
49
50
50
#-------------------------------------------------------------------------------
51
- NUMBER = 100
51
+ NUMBER = 200
52
52
53
53
def seconds_to_display (seconds : float ) -> str :
54
54
seconds /= NUMBER
@@ -92,13 +92,13 @@ def plot_performance(frame):
92
92
title = f'{ cat_label :.0e} \n { FixtureFactory .DENSITY_TO_DISPLAY [fixture_label ]} '
93
93
94
94
ax .set_title (title , fontsize = 6 )
95
- ax .set_box_aspect (0.75 ) # makes taller tan wide
95
+ ax .set_box_aspect (0.75 ) # makes taller than wide
96
96
time_max = fixture ['time' ].max ()
97
97
ax .set_yticks ([0 , time_max * 0.5 , time_max ])
98
98
ax .set_yticklabels (['' ,
99
99
seconds_to_display (time_max * .5 ),
100
100
seconds_to_display (time_max ),
101
- ], fontsize = 6 )
101
+ ], fontsize = 4 )
102
102
# ax.set_xticks(x, names_display, rotation='vertical')
103
103
ax .tick_params (
104
104
axis = 'x' ,
@@ -108,20 +108,20 @@ def plot_performance(frame):
108
108
labelbottom = False ,
109
109
)
110
110
111
- fig .set_size_inches (9 , 4 ) # width, height
111
+ fig .set_size_inches (10 , 4 ) # width, height
112
112
fig .legend (post , names_display , loc = 'center right' , fontsize = 6 )
113
113
# horizontal, vertical
114
114
fig .text (.05 , .96 , f'nonzero_1d() Performance: { NUMBER } Iterations' , fontsize = 10 )
115
115
fig .text (.05 , .90 , get_versions (), fontsize = 6 )
116
116
117
117
fp = '/tmp/nonzero.png'
118
118
plt .subplots_adjust (
119
- left = 0.075 ,
119
+ left = 0.05 ,
120
120
bottom = 0.05 ,
121
- right = 0.80 ,
121
+ right = 0.85 ,
122
122
top = 0.85 ,
123
123
wspace = 0.9 , # width
124
- hspace = 0.2 ,
124
+ hspace = 0.0 ,
125
125
)
126
126
# plt.rcParams.update({'font.size': 22})
127
127
plt .savefig (fp , dpi = 300 )
@@ -138,15 +138,19 @@ class FixtureFactory:
138
138
NAME = ''
139
139
140
140
@staticmethod
141
- def get_array (size : int ) -> np .ndarray :
142
- return np .full (size , False , dtype = bool )
141
+ def get_array (size : int , contiguous : bool = True ) -> np .ndarray :
142
+ if contiguous :
143
+ return np .full (size , False , dtype = bool )
144
+ # take every other value to force non-contigous data
145
+ return np .full (size * 2 , False , dtype = bool )[::2 ]
143
146
144
147
def _get_array_filled (
145
148
size : int ,
146
149
start_third : int , #0, 1 or 2
147
150
density : float , # less than 1
151
+ contiguous : bool ,
148
152
) -> np .ndarray :
149
- a = FixtureFactory .get_array (size )
153
+ a = FixtureFactory .get_array (size , contiguous )
150
154
count = size * density
151
155
start = int (len (a ) * (start_third / 3 ))
152
156
length = len (a ) - start
@@ -161,10 +165,14 @@ def get_label_array(cls, size: int) -> tp.Tuple[str, np.ndarray]:
161
165
return cls .NAME , array
162
166
163
167
DENSITY_TO_DISPLAY = {
164
- 'single' : '1 True' ,
165
- 'quarter' : '25% True' ,
166
- 'half' : '50% True' ,
167
- 'full' : '100% True' ,
168
+ 'single-c' : '1 True C' ,
169
+ 'quarter-c' : '25% True C' ,
170
+ 'half-c' : '50% True C' ,
171
+ 'full-c' : '100% True C' ,
172
+ 'single-nc' : '1 True NC' ,
173
+ 'quarter-nc' : '25% True NC' ,
174
+ 'half-nc' : '50% True NC' ,
175
+ 'full-nc' : '100% True NC' ,
168
176
}
169
177
170
178
# POSITION_TO_DISPLAY = {
@@ -174,35 +182,68 @@ def get_label_array(cls, size: int) -> tp.Tuple[str, np.ndarray]:
174
182
175
183
176
184
class FFSingle (FixtureFactory ):
177
- NAME = 'single'
185
+ NAME = 'single-c'
186
+
187
+ @staticmethod
188
+ def get_array (size : int ) -> np .ndarray :
189
+ a = FixtureFactory .get_array (size , contiguous = True )
190
+ a [len (a ) // 2 ] = True
191
+ return a
192
+
193
+ class FFSingleNC (FixtureFactory ):
194
+ NAME = 'single-nc'
178
195
179
196
@staticmethod
180
197
def get_array (size : int ) -> np .ndarray :
181
- a = FixtureFactory .get_array (size )
198
+ a = FixtureFactory .get_array (size , contiguous = False )
182
199
a [len (a ) // 2 ] = True
183
200
return a
184
201
185
202
class FFQuarter (FixtureFactory ):
186
- NAME = 'quarter'
203
+ NAME = 'quarter-c'
204
+
205
+ @classmethod
206
+ def get_array (cls , size : int ) -> np .ndarray :
207
+ return cls ._get_array_filled (size , start_third = 0 , density = 0.25 , contiguous = True )
208
+
209
+ class FFQuarterNC (FixtureFactory ):
210
+ NAME = 'quarter-nc'
187
211
188
212
@classmethod
189
213
def get_array (cls , size : int ) -> np .ndarray :
190
- return cls ._get_array_filled (size , start_third = 0 , density = 0.25 )
214
+ return cls ._get_array_filled (size , start_third = 0 , density = 0.25 , contiguous = False )
215
+
191
216
192
217
class FFHalf (FixtureFactory ):
193
- NAME = 'half'
218
+ NAME = 'half-c '
194
219
195
220
@classmethod
196
221
def get_array (cls , size : int ) -> np .ndarray :
197
- return cls ._get_array_filled (size , start_third = 0 , density = 0.5 )
222
+ return cls ._get_array_filled (size , start_third = 0 , density = 0.5 , contiguous = True )
223
+
224
+ class FFHalfNC (FixtureFactory ):
225
+ NAME = 'half-nc'
226
+
227
+ @classmethod
228
+ def get_array (cls , size : int ) -> np .ndarray :
229
+ return cls ._get_array_filled (size , start_third = 0 , density = 0.5 , contiguous = False )
230
+
198
231
199
232
200
233
class FFFull (FixtureFactory ):
201
- NAME = 'full'
234
+ NAME = 'full-c '
202
235
203
236
@classmethod
204
237
def get_array (cls , size : int ) -> np .ndarray :
205
- return cls ._get_array_filled (size , start_third = 0 , density = 1 )
238
+ return cls ._get_array_filled (size , start_third = 0 , density = 1 , contiguous = True )
239
+
240
+
241
+ class FFFullNC (FixtureFactory ):
242
+ NAME = 'full-nc'
243
+
244
+ @classmethod
245
+ def get_array (cls , size : int ) -> np .ndarray :
246
+ return cls ._get_array_filled (size , start_third = 0 , density = 1 , contiguous = False )
206
247
207
248
208
249
def get_versions () -> str :
@@ -218,15 +259,20 @@ def get_versions() -> str:
218
259
219
260
CLS_FF = (
220
261
FFSingle ,
262
+ FFSingleNC ,
221
263
FFQuarter ,
264
+ FFQuarterNC ,
222
265
FFHalf ,
266
+ FFHalfNC ,
223
267
FFFull ,
268
+ FFFullNC ,
269
+
224
270
)
225
271
226
272
227
273
def run_test ():
228
274
records = []
229
- for size in (100_000 , 1_000_000 , 10_000_000 ):
275
+ for size in (10_000 , 100_000 , 1_000_000 , 10_000_000 ):
230
276
for ff in CLS_FF :
231
277
fixture_label , fixture = ff .get_label_array (size )
232
278
for cls in CLS_PROCESSOR :
0 commit comments