Skip to content
This repository was archived by the owner on Jun 27, 2025. It is now read-only.

Commit 9fab759

Browse files
committed
Merge branch 'master' into 10/get-many
2 parents 6788a72 + 0af6e98 commit 9fab759

File tree

1 file changed

+126
-34
lines changed

1 file changed

+126
-34
lines changed

doc/articles/npy-opt.py

Lines changed: 126 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -342,37 +342,112 @@ def get_array(size: int) -> np.ndarray:
342342
return array
343343

344344

345-
class FFString(FixtureFactory):
346-
NAME = "string"
345+
def get_string_array(size: int, char_count: int, kind: str) -> str:
346+
fmt = f'-<{char_count}'
347+
array = np.array(
348+
[f'{hex(e) * (char_count // 8)}'.format(fmt) for e in range(INT_START, INT_START + size)],
349+
dtype=f'{kind}{char_count}')
350+
array.flags.writeable = False
351+
return array
352+
353+
class FFU8(FixtureFactory):
354+
NAME = "U8"
347355
SORT = 6
348356

349357
@staticmethod
350358
def get_array(size: int) -> np.ndarray:
351-
array = np.array([hex(e) for e in range(size)])
352-
array.flags.writeable = False
353-
return array
359+
return get_string_array(size, 8, 'U')
354360

355-
356-
class FFString4x(FixtureFactory):
357-
NAME = "string 4x"
361+
class FFU16(FixtureFactory):
362+
NAME = "U16"
358363
SORT = 7
359364

360365
@staticmethod
361366
def get_array(size: int) -> np.ndarray:
362-
array = np.array([hex(e) * 4 for e in range(size)])
363-
array.flags.writeable = False
364-
return array
367+
return get_string_array(size, 16, 'U')
365368

366369

367-
class FFBytes(FixtureFactory):
368-
NAME = "bytes"
370+
class FFU32(FixtureFactory):
371+
NAME = "U32"
369372
SORT = 8
370373

371374
@staticmethod
372375
def get_array(size: int) -> np.ndarray:
373-
array = np.array([bytes(hex(e), encoding="utf-8") for e in range(size)])
374-
array.flags.writeable = False
375-
return array
376+
return get_string_array(size, 32, 'U')
377+
378+
379+
class FFU64(FixtureFactory):
380+
NAME = "U64"
381+
SORT = 9
382+
383+
@staticmethod
384+
def get_array(size: int) -> np.ndarray:
385+
return get_string_array(size, 64, 'U')
386+
387+
388+
class FFU128(FixtureFactory):
389+
NAME = "U128"
390+
SORT = 10
391+
392+
@staticmethod
393+
def get_array(size: int) -> np.ndarray:
394+
return get_string_array(size, 128, 'U')
395+
396+
397+
class FFS8(FixtureFactory):
398+
NAME = "S8"
399+
SORT = 11
400+
401+
@staticmethod
402+
def get_array(size: int) -> np.ndarray:
403+
return get_string_array(size, 8, 'S')
404+
405+
class FFS16(FixtureFactory):
406+
NAME = "S16"
407+
SORT = 12
408+
409+
@staticmethod
410+
def get_array(size: int) -> np.ndarray:
411+
return get_string_array(size, 16, 'S')
412+
413+
414+
class FFS32(FixtureFactory):
415+
NAME = "S32"
416+
SORT = 13
417+
418+
@staticmethod
419+
def get_array(size: int) -> np.ndarray:
420+
return get_string_array(size, 32, 'S')
421+
422+
423+
class FFS64(FixtureFactory):
424+
NAME = "S64"
425+
SORT = 14
426+
427+
@staticmethod
428+
def get_array(size: int) -> np.ndarray:
429+
return get_string_array(size, 64, 'S')
430+
431+
class FFS128(FixtureFactory):
432+
NAME = "S128"
433+
SORT = 15
434+
435+
@staticmethod
436+
def get_array(size: int) -> np.ndarray:
437+
return get_string_array(size, 128, 'S')
438+
439+
440+
441+
442+
# class FFBytes(FixtureFactory):
443+
# NAME = "bytes"
444+
# SORT = 8
445+
446+
# @staticmethod
447+
# def get_array(size: int) -> np.ndarray:
448+
# array = np.array([bytes(hex(e), encoding="utf-8") for e in range(INT_START, INT_START + size)])
449+
# array.flags.writeable = False
450+
# return array
376451

377452

378453
class FFObject(FixtureFactory):
@@ -401,14 +476,22 @@ def get_versions() -> str:
401476

402477

403478
CLS_FF = (
404-
FFInt32,
405-
FFInt64,
406-
FFUInt32,
407-
FFUInt64,
408-
FFFloat64,
409-
FFString,
410-
# FFString4x,
411-
FFBytes,
479+
# FFInt32,
480+
# FFInt64,
481+
# FFUInt32,
482+
# FFUInt64,
483+
# FFFloat64,
484+
FFU8,
485+
FFU16,
486+
FFU32,
487+
FFU64,
488+
FFU128,
489+
490+
FFS8,
491+
FFS16,
492+
FFS32,
493+
FFS64,
494+
FFS128,
412495
# FFObject,
413496
)
414497
FF_ORDER = [f.NAME for f in sorted(CLS_FF, key=lambda ff: ff.SORT)]
@@ -464,24 +547,33 @@ def plot_performance(frame, suffix: str = ""):
464547
ax.set_title(title, fontsize=6)
465548
ax.set_box_aspect(0.8)
466549
time_max = fixture["time"].max()
467-
ax.set_yticks([0, time_max * 0.5, time_max])
468-
ax.set_yticklabels(
469-
[
550+
time_min = fixture["time"].min()
551+
y_ticks = [0, time_min, time_max * 0.5, time_max]
552+
y_labels = [
470553
"",
554+
seconds_to_display(time_min),
471555
seconds_to_display(time_max * 0.5),
472556
seconds_to_display(time_max),
473-
],
474-
fontsize=6,
475-
)
557+
]
558+
if time_min > time_max * 0.25:
559+
# remove the min if it is greater than quarter
560+
y_ticks.pop(1)
561+
y_labels.pop(1)
562+
563+
ax.set_yticks(y_ticks)
564+
ax.set_yticklabels(y_labels, fontsize=4)
476565
# ax.set_xticks(x, names_display, rotation='vertical')
477566
ax.tick_params(
478567
axis="x",
479-
which="both",
480568
bottom=False,
481-
top=False,
482569
labelbottom=False,
483570
)
484-
571+
ax.tick_params(
572+
axis="y",
573+
length=2,
574+
width=.5,
575+
pad=1,
576+
)
485577
fig.set_size_inches(9, 3) # width, height
486578
fig.legend(post, names_display, loc="center right", fontsize=6)
487579
# horizontal, vertical
@@ -495,7 +587,7 @@ def plot_performance(frame, suffix: str = ""):
495587
right=0.85,
496588
top=0.80,
497589
wspace=1.0, # width
498-
hspace=0.2,
590+
hspace=0.4,
499591
)
500592
# plt.rcParams.update({'font.size': 22})
501593
plt.savefig(fp, dpi=300)

0 commit comments

Comments
 (0)