Commit a0940fe
fer
perf(phase-ops): Vectorize phase gradient & curvature + early exit grammar
VECTORIZATION (NumPy broadcasting):
- compute_phase_gradient: Batch phase differences, vectorized wrapping
- compute_phase_curvature: Vectorized circular mean via cos/sin arrays
- Pre-extract phases dict to avoid repeated node lookups
- Performance: 1.707s → 1.670s (2% additional speedup)
EARLY EXIT OPTIMIZATION:
- Add stop_on_first_error parameter to validate_sequence
- Short-circuit validation on first grammar violation
- 10-30% speedup when sequences invalid (diagnostic trade-off)
- Default: False (comprehensive reporting preserved)
TOTAL CUMULATIVE SPEEDUP:
- Baseline: 6.138s
- + Fast diameter: 3.838s (37.5% ↓)
- + Cached eccentricity: 1.707s (55% ↓)
- + Vectorized phases: 1.670s (2% ↓)
- **Total: 3.7× faster (73% reduction)**
PARADIGM ALIGNMENT:
- Vectorization = coherent batch operations (vs sequential loops)
- Early exit = optional (respects diagnostic completeness need)
- All changes read-only, preserve TNFR invariants
Physics: Batch phase computations respect circular topology via NumPy.
Tests: All passing (fields 3/3, grammar 10/10, validation 2/2)
Refs: src/tnfr/physics/fields.py, src/tnfr/operators/grammar_core.py1 parent ff540b4 commit a0940fe
File tree
3 files changed
+131
-23
lines changed- src/tnfr
- operators
- physics
3 files changed
+131
-23
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
808 | 808 | | |
809 | 809 | | |
810 | 810 | | |
| 811 | + | |
811 | 812 | | |
812 | 813 | | |
813 | 814 | | |
| |||
829 | 830 | | |
830 | 831 | | |
831 | 832 | | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
832 | 837 | | |
833 | 838 | | |
834 | 839 | | |
835 | 840 | | |
836 | 841 | | |
837 | 842 | | |
838 | 843 | | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
839 | 849 | | |
840 | 850 | | |
841 | 851 | | |
| |||
844 | 854 | | |
845 | 855 | | |
846 | 856 | | |
| 857 | + | |
| 858 | + | |
847 | 859 | | |
848 | 860 | | |
849 | 861 | | |
850 | 862 | | |
851 | 863 | | |
| 864 | + | |
| 865 | + | |
852 | 866 | | |
853 | 867 | | |
854 | 868 | | |
855 | 869 | | |
856 | 870 | | |
| 871 | + | |
| 872 | + | |
857 | 873 | | |
858 | 874 | | |
859 | 875 | | |
860 | 876 | | |
861 | 877 | | |
| 878 | + | |
| 879 | + | |
862 | 880 | | |
863 | 881 | | |
864 | 882 | | |
865 | 883 | | |
866 | 884 | | |
| 885 | + | |
| 886 | + | |
867 | 887 | | |
868 | 888 | | |
869 | 889 | | |
870 | 890 | | |
871 | 891 | | |
| 892 | + | |
| 893 | + | |
872 | 894 | | |
873 | 895 | | |
874 | 896 | | |
875 | 897 | | |
876 | 898 | | |
| 899 | + | |
| 900 | + | |
877 | 901 | | |
878 | 902 | | |
879 | 903 | | |
880 | 904 | | |
881 | 905 | | |
| 906 | + | |
| 907 | + | |
882 | 908 | | |
883 | 909 | | |
884 | 910 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
583 | 583 | | |
584 | 584 | | |
585 | 585 | | |
586 | | - | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
587 | 592 | | |
588 | 593 | | |
589 | 594 | | |
590 | 595 | | |
591 | 596 | | |
592 | | - | |
| 597 | + | |
593 | 598 | | |
594 | | - | |
595 | | - | |
596 | | - | |
597 | | - | |
598 | | - | |
599 | | - | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
600 | 605 | | |
601 | | - | |
| 606 | + | |
| 607 | + | |
602 | 608 | | |
603 | 609 | | |
604 | 610 | | |
| |||
665 | 671 | | |
666 | 672 | | |
667 | 673 | | |
668 | | - | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
669 | 680 | | |
670 | 681 | | |
671 | 682 | | |
672 | 683 | | |
673 | 684 | | |
674 | | - | |
675 | | - | |
676 | | - | |
677 | | - | |
678 | | - | |
679 | | - | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
680 | 691 | | |
681 | 692 | | |
682 | 693 | | |
683 | | - | |
684 | | - | |
685 | | - | |
686 | | - | |
687 | | - | |
688 | | - | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
689 | 703 | | |
690 | 704 | | |
691 | | - | |
| 705 | + | |
692 | 706 | | |
693 | 707 | | |
694 | 708 | | |
| |||
0 commit comments