cpp-pd-code-simplify-interface 0.1.10__tar.gz → 0.1.11__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cpp-pd-code-simplify-interface
3
- Version: 0.1.10
3
+ Version: 0.1.11
4
4
  Summary: Python interface for cpp-pd-code-simplify with runtime C++ compilation.
5
5
  License-Expression: MIT
6
6
  Author: GGN_2015
@@ -60,9 +60,10 @@ print(result["final_pd_code"])
60
60
  ```
61
61
 
62
62
  Returned `final_pd_code` strings are normalized for display: each crossing is
63
- written from the under-incoming edge and labels are renumbered along oriented
64
- components from `1`. This is applied only at the final JSON boundary; the C++
65
- backend keeps its internal numbering unchanged while simplifying.
63
+ written from the under-incoming edge, labels are renumbered along oriented
64
+ components from `1`, and crossing rows are sorted lexicographically. This is
65
+ applied only at the final JSON boundary; the C++ backend keeps its internal
66
+ numbering unchanged while simplifying.
66
67
 
67
68
  The default `max_paths=-1` uses deterministic heuristic green-path sampling in
68
69
  the C++ backend. Use `ban_heuristic=True` to request exhaustive green-path
@@ -40,9 +40,10 @@ print(result["final_pd_code"])
40
40
  ```
41
41
 
42
42
  Returned `final_pd_code` strings are normalized for display: each crossing is
43
- written from the under-incoming edge and labels are renumbered along oriented
44
- components from `1`. This is applied only at the final JSON boundary; the C++
45
- backend keeps its internal numbering unchanged while simplifying.
43
+ written from the under-incoming edge, labels are renumbered along oriented
44
+ components from `1`, and crossing rows are sorted lexicographically. This is
45
+ applied only at the final JSON boundary; the C++ backend keeps its internal
46
+ numbering unchanged while simplifying.
46
47
 
47
48
  The default `max_paths=-1` uses deterministic heuristic green-path sampling in
48
49
  the C++ backend. Use `ban_heuristic=True` to request exhaustive green-path
@@ -510,8 +510,10 @@ std::vector<std::vector<int>> raw_faces_from_pd_code(const PDCode& code) {
510
510
  struct Diagram {
511
511
  PDCode code;
512
512
  std::vector<CrossingState> crossings;
513
+ std::vector<int> rotations;
513
514
 
514
- explicit Diagram(PDCode input) : code(std::move(input)), crossings(code.size()) {
515
+ explicit Diagram(PDCode input)
516
+ : code(std::move(input)), crossings(code.size()), rotations(code.size(), 0) {
515
517
  build_adjacency();
516
518
  auto starts = component_starts_from_pd();
517
519
  orient_crossings(starts);
@@ -533,6 +535,10 @@ struct Diagram {
533
535
  return Endpoint{endpoint.crossing, positive_mod(endpoint.strand + offset, 4)};
534
536
  }
535
537
 
538
+ int label_at(int crossing, int strand) const {
539
+ return code.at(crossing).at(positive_mod(strand + rotations.at(crossing), 4));
540
+ }
541
+
536
542
  std::vector<Endpoint> crossing_entries() const {
537
543
  std::vector<Endpoint> entries;
538
544
  entries.reserve(crossings.size() * 2);
@@ -715,6 +721,7 @@ private:
715
721
 
716
722
  void rotate_crossing_180(int crossing) {
717
723
  auto old_adjacent = crossings[crossing].adjacent;
724
+ rotations[crossing] = positive_mod(rotations[crossing] + 2, 4);
718
725
  bool old_directions[4][4]{};
719
726
  for (int a = 0; a < 4; ++a) {
720
727
  for (int b = 0; b < 4; ++b) {
@@ -1878,14 +1885,9 @@ std::string format_final_pd_code(const PDCode& code) {
1878
1885
  std::set<int> labels;
1879
1886
  std::map<int, int> next_label;
1880
1887
 
1881
- auto label_at = [&](int crossing, int strand) {
1882
- const Endpoint other = diagram.crossings[crossing].adjacent[strand];
1883
- return diagram.code[other.crossing][other.strand];
1884
- };
1885
-
1886
1888
  for (int crossing = 0; crossing < static_cast<int>(code.size()); ++crossing) {
1887
1889
  for (int strand = 0; strand < 4; ++strand) {
1888
- const int label = label_at(crossing, strand);
1890
+ const int label = diagram.label_at(crossing, strand);
1889
1891
  oriented[crossing][strand] = label;
1890
1892
  labels.insert(label);
1891
1893
  }
@@ -1898,8 +1900,8 @@ std::string format_final_pd_code(const PDCode& code) {
1898
1900
  if (!diagram.crossings[crossing].directions[tail][head]) {
1899
1901
  continue;
1900
1902
  }
1901
- const int in_label = label_at(crossing, tail);
1902
- const int out_label = label_at(crossing, head);
1903
+ const int in_label = diagram.label_at(crossing, tail);
1904
+ const int out_label = diagram.label_at(crossing, head);
1903
1905
  const auto inserted = next_label.insert(std::make_pair(in_label, out_label));
1904
1906
  if (!inserted.second && inserted.first->second != out_label) {
1905
1907
  throw std::invalid_argument("Final PD component orientation is inconsistent");
@@ -1934,6 +1936,7 @@ std::string format_final_pd_code(const PDCode& code) {
1934
1936
  label = relabel.at(label);
1935
1937
  }
1936
1938
  }
1939
+ std::sort(oriented.begin(), oriented.end());
1937
1940
  return format_pd_code(oriented);
1938
1941
  }
1939
1942
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "cpp-pd-code-simplify-interface"
3
- version = "0.1.10"
3
+ version = "0.1.11"
4
4
  description = "Python interface for cpp-pd-code-simplify with runtime C++ compilation."
5
5
  authors = [
6
6
  {name = "GGN_2015", email = "neko@jlulug.org"}