Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 72b05c0

Browse files
committed
ENH: [5/5] Move dispatch-able umath fast-loops to the new dispatcher
update umath generator and use attribute `dispatch` instead of `simd`.
1 parent 7c64954 commit 72b05c0

File tree

1 file changed

+28
-22
lines changed

1 file changed

+28
-22
lines changed

numpy/core/code_generators/generate_umath.py

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,8 @@ def english_upper(s):
288288
Ufunc(2, 1, Zero,
289289
docstrings.get('numpy.core.umath.add'),
290290
'PyUFunc_AdditionTypeResolver',
291-
TD(notimes_or_obj, simd=[('avx512f', cmplxvec),('avx2', ints)]),
291+
TD(notimes_or_obj, simd=[('avx512f', cmplxvec)],
292+
dispatch=[('loops_fast', ints)]),
292293
[TypeDescription('M', FullTypeDescr, 'Mm', 'M'),
293294
TypeDescription('m', FullTypeDescr, 'mm', 'm'),
294295
TypeDescription('M', FullTypeDescr, 'mM', 'M'),
@@ -299,7 +300,8 @@ def english_upper(s):
299300
Ufunc(2, 1, None, # Zero is only a unit to the right, not the left
300301
docstrings.get('numpy.core.umath.subtract'),
301302
'PyUFunc_SubtractionTypeResolver',
302-
TD(ints + inexact, simd=[('avx512f', cmplxvec),('avx2', ints)]),
303+
TD(ints + inexact, simd=[('avx512f', cmplxvec)],
304+
dispatch=[('loops_fast', ints)]),
303305
[TypeDescription('M', FullTypeDescr, 'Mm', 'M'),
304306
TypeDescription('m', FullTypeDescr, 'mm', 'm'),
305307
TypeDescription('M', FullTypeDescr, 'MM', 'm'),
@@ -310,7 +312,8 @@ def english_upper(s):
310312
Ufunc(2, 1, One,
311313
docstrings.get('numpy.core.umath.multiply'),
312314
'PyUFunc_MultiplicationTypeResolver',
313-
TD(notimes_or_obj, simd=[('avx512f', cmplxvec),('avx2', ints)]),
315+
TD(notimes_or_obj, simd=[('avx512f', cmplxvec)],
316+
dispatch=[('loops_fast', ints)]),
314317
[TypeDescription('m', FullTypeDescr, 'mq', 'm'),
315318
TypeDescription('m', FullTypeDescr, 'qm', 'm'),
316319
TypeDescription('m', FullTypeDescr, 'md', 'm'),
@@ -345,7 +348,8 @@ def english_upper(s):
345348
Ufunc(1, 1, None,
346349
docstrings.get('numpy.core.umath.conjugate'),
347350
None,
348-
TD(ints+flts+cmplx, simd=[('avx2', ints), ('avx512f', cmplxvec)]),
351+
TD(ints+flts+cmplx, simd=[('avx512f', cmplxvec)],
352+
dispatch=[('loops_fast', ints)]),
349353
TD(P, f='conjugate'),
350354
),
351355
'fmod':
@@ -360,14 +364,16 @@ def english_upper(s):
360364
Ufunc(1, 1, None,
361365
docstrings.get('numpy.core.umath.square'),
362366
None,
363-
TD(ints+inexact, simd=[('avx2', ints), ('fma', 'fd'), ('avx512f', 'FDfd')]),
367+
TD(ints+inexact, simd=[('fma', 'fd'), ('avx512f', 'FDfd')],
368+
dispatch=[('loops_fast', ints)]),
364369
TD(O, f='Py_square'),
365370
),
366371
'reciprocal':
367372
Ufunc(1, 1, None,
368373
docstrings.get('numpy.core.umath.reciprocal'),
369374
None,
370-
TD(ints+inexact, simd=[('avx2', ints), ('fma', 'fd'), ('avx512f','fd')]),
375+
TD(ints+inexact, simd=[('fma', 'fd'), ('avx512f','fd')],
376+
dispatch=[('loops_fast', ints)]),
371377
TD(O, f='Py_reciprocal'),
372378
),
373379
# This is no longer used as numpy.ones_like, however it is
@@ -411,7 +417,7 @@ def english_upper(s):
411417
Ufunc(1, 1, None,
412418
docstrings.get('numpy.core.umath.negative'),
413419
'PyUFunc_NegativeTypeResolver',
414-
TD(ints+flts+timedeltaonly, simd=[('avx2', ints)]),
420+
TD(ints+flts+timedeltaonly, dispatch=[('loops_fast', ints)]),
415421
TD(cmplx, f='neg'),
416422
TD(O, f='PyNumber_Negative'),
417423
),
@@ -433,71 +439,71 @@ def english_upper(s):
433439
Ufunc(2, 1, None,
434440
docstrings.get('numpy.core.umath.greater'),
435441
'PyUFunc_SimpleBinaryComparisonTypeResolver',
436-
TD(all, out='?', simd=[('avx2', ints)]),
442+
TD(all, out='?', dispatch=[('loops_fast', ints)]),
437443
[TypeDescription('O', FullTypeDescr, 'OO', 'O')],
438444
TD('O', out='?'),
439445
),
440446
'greater_equal':
441447
Ufunc(2, 1, None,
442448
docstrings.get('numpy.core.umath.greater_equal'),
443449
'PyUFunc_SimpleBinaryComparisonTypeResolver',
444-
TD(all, out='?', simd=[('avx2', ints)]),
450+
TD(all, out='?', dispatch=[('loops_fast', ints)]),
445451
[TypeDescription('O', FullTypeDescr, 'OO', 'O')],
446452
TD('O', out='?'),
447453
),
448454
'less':
449455
Ufunc(2, 1, None,
450456
docstrings.get('numpy.core.umath.less'),
451457
'PyUFunc_SimpleBinaryComparisonTypeResolver',
452-
TD(all, out='?', simd=[('avx2', ints)]),
458+
TD(all, out='?', dispatch=[('loops_fast', ints)]),
453459
[TypeDescription('O', FullTypeDescr, 'OO', 'O')],
454460
TD('O', out='?'),
455461
),
456462
'less_equal':
457463
Ufunc(2, 1, None,
458464
docstrings.get('numpy.core.umath.less_equal'),
459465
'PyUFunc_SimpleBinaryComparisonTypeResolver',
460-
TD(all, out='?', simd=[('avx2', ints)]),
466+
TD(all, out='?', dispatch=[('loops_fast', ints)]),
461467
[TypeDescription('O', FullTypeDescr, 'OO', 'O')],
462468
TD('O', out='?'),
463469
),
464470
'equal':
465471
Ufunc(2, 1, None,
466472
docstrings.get('numpy.core.umath.equal'),
467473
'PyUFunc_SimpleBinaryComparisonTypeResolver',
468-
TD(all, out='?', simd=[('avx2', ints)]),
474+
TD(all, out='?', dispatch=[('loops_fast', ints)]),
469475
[TypeDescription('O', FullTypeDescr, 'OO', 'O')],
470476
TD('O', out='?'),
471477
),
472478
'not_equal':
473479
Ufunc(2, 1, None,
474480
docstrings.get('numpy.core.umath.not_equal'),
475481
'PyUFunc_SimpleBinaryComparisonTypeResolver',
476-
TD(all, out='?', simd=[('avx2', ints)]),
482+
TD(all, out='?', dispatch=[('loops_fast', ints)]),
477483
[TypeDescription('O', FullTypeDescr, 'OO', 'O')],
478484
TD('O', out='?'),
479485
),
480486
'logical_and':
481487
Ufunc(2, 1, True_,
482488
docstrings.get('numpy.core.umath.logical_and'),
483489
'PyUFunc_SimpleBinaryComparisonTypeResolver',
484-
TD(nodatetime_or_obj, out='?', simd=[('avx2', ints)]),
490+
TD(nodatetime_or_obj, out='?', dispatch=[('loops_fast', ints)]),
485491
TD(O, f='npy_ObjectLogicalAnd'),
486492
TD(O, f='npy_ObjectLogicalAnd', out='?'),
487493
),
488494
'logical_not':
489495
Ufunc(1, 1, None,
490496
docstrings.get('numpy.core.umath.logical_not'),
491497
None,
492-
TD(nodatetime_or_obj, out='?', simd=[('avx2', ints)]),
498+
TD(nodatetime_or_obj, out='?', dispatch=[('loops_fast', ints)]),
493499
TD(O, f='npy_ObjectLogicalNot'),
494500
TD(O, f='npy_ObjectLogicalNot', out='?'),
495501
),
496502
'logical_or':
497503
Ufunc(2, 1, False_,
498504
docstrings.get('numpy.core.umath.logical_or'),
499505
'PyUFunc_SimpleBinaryComparisonTypeResolver',
500-
TD(nodatetime_or_obj, out='?', simd=[('avx2', ints)]),
506+
TD(nodatetime_or_obj, out='?', dispatch=[('loops_fast', ints)]),
501507
TD(O, f='npy_ObjectLogicalOr'),
502508
TD(O, f='npy_ObjectLogicalOr', out='?'),
503509
),
@@ -559,42 +565,42 @@ def english_upper(s):
559565
Ufunc(2, 1, AllOnes,
560566
docstrings.get('numpy.core.umath.bitwise_and'),
561567
None,
562-
TD(bints, simd=[('avx2', ints)]),
568+
TD(bints, dispatch=[('loops_fast', ints)]),
563569
TD(O, f='PyNumber_And'),
564570
),
565571
'bitwise_or':
566572
Ufunc(2, 1, Zero,
567573
docstrings.get('numpy.core.umath.bitwise_or'),
568574
None,
569-
TD(bints, simd=[('avx2', ints)]),
575+
TD(bints, dispatch=[('loops_fast', ints)]),
570576
TD(O, f='PyNumber_Or'),
571577
),
572578
'bitwise_xor':
573579
Ufunc(2, 1, Zero,
574580
docstrings.get('numpy.core.umath.bitwise_xor'),
575581
None,
576-
TD(bints, simd=[('avx2', ints)]),
582+
TD(bints, dispatch=[('loops_fast', ints)]),
577583
TD(O, f='PyNumber_Xor'),
578584
),
579585
'invert':
580586
Ufunc(1, 1, None,
581587
docstrings.get('numpy.core.umath.invert'),
582588
None,
583-
TD(bints, simd=[('avx2', ints)]),
589+
TD(bints, dispatch=[('loops_fast', ints)]),
584590
TD(O, f='PyNumber_Invert'),
585591
),
586592
'left_shift':
587593
Ufunc(2, 1, None,
588594
docstrings.get('numpy.core.umath.left_shift'),
589595
None,
590-
TD(ints, simd=[('avx2', ints)]),
596+
TD(ints, dispatch=[('loops_fast', ints)]),
591597
TD(O, f='PyNumber_Lshift'),
592598
),
593599
'right_shift':
594600
Ufunc(2, 1, None,
595601
docstrings.get('numpy.core.umath.right_shift'),
596602
None,
597-
TD(ints, simd=[('avx2', ints)]),
603+
TD(ints, dispatch=[('loops_fast', ints)]),
598604
TD(O, f='PyNumber_Rshift'),
599605
),
600606
'heaviside':

0 commit comments

Comments
 (0)