一键导入
python-algorithm-porter
Strict workflow for porting Python algorithms (numpy, pandas, rtree, dict manipulation) to high-performance, zero-allocation C# equivalents.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Strict workflow for porting Python algorithms (numpy, pandas, rtree, dict manipulation) to high-performance, zero-allocation C# equivalents.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | python-algorithm-porter |
| description | Strict workflow for porting Python algorithms (numpy, pandas, rtree, dict manipulation) to high-performance, zero-allocation C# equivalents. |
python-algorithm-porter SkillWhen porting algorithms from upstream Python repositories (e.g., docling, docling-core, docling-ibm-models) to the .NET port, direct translation of syntax often leads to poor performance or subtle bugs. Python relies heavily on dynamic typing, implicit broadcasting (numpy), and C-backed native libraries (rtree, bisect). .NET relies on static typing, explicit memory management (Span<T>, Memory<T>), and JIT inlining.
Use this skill whenever you are tasked with porting a specific algorithm, mathematical function, or complex data transformation from Python to C#.
np.ndarray of float32 with shape [1, 3, 640, 640], or a list of dict objects).bisect, rtree, shapely, scipy).readonly struct for geometric data (BoundingBox, Point) to avoid heap allocation and GC pressure.List<T>, Dictionary<TKey, TValue>). Never use object or dynamic.ArrayPool<T>.Shared.Rent or stackalloc for small allocations.Python:
# Normalize image: (img - mean) / std
img = (img / 255.0 - [0.485, 0.456, 0.406]) / [0.229, 0.224, 0.225]
C# Port:
System.Drawing.Bitmap.GetPixel().unsafe pointers, Span<T>, or MemoryMarshal.Cast to iterate over flat byte arrays of pixel data.R, G, B scalar operations within a tight for loop.bisect (Sorted Intervals) -> C# List<T>.BinarySearchPython:
import bisect
bisect.insort(my_list, new_item)
C# Port:
int index = myList.BinarySearch(newItem);
if (index < 0) index = ~index;
myList.Insert(index, newItem);
rtree / libspatialindex -> C# Spatial IndexPython:
from rtree import index
idx = index.Index()
idx.insert(id, (l, b, r, t))
candidates = idx.intersection((query_l, query_b, query_r, query_t))
C# Port:
List<T> with a brute-force $O(N)$ linear scan is often faster in .NET due to cache locality and zero FFI overhead.DoclingDotNet.Algorithms.Spatial.SpatialIndex<T> (a flat array optimized for zero-allocation intersections).Python:
df.groupby('label').agg({'confidence': 'mean'})
C# Port:
items.GroupBy(x => x.Label)
.Select(g => new { Label = g.Key, MeanConfidence = g.Average(x => x.Confidence) });
dynamic: Everything must be strictly typed.new List<int>()) inside tight inner loops. Reuse buffers.Math.Max, Math.Min, Math.Abs, and Math.Round(..., MidpointRounding.AwayFromZero) strictly. Python's round() behaves differently (Banker's rounding) than standard expectations; verify the exact rounding semantics required.DoclingDotNet.Tests demonstrating that the ported C# algorithm produces the exact same numerical or structural output as the Python original for a given dummy input.Run the one-command Docling upstream upgrade workflow: fetch latest upstream, port local delta, validate, and record baseline metadata.
Keep docs lean: append concise iteration summaries, and only update docs/changelog for milestone or contract/workflow changes.
Recover from hung command sessions using targeted process discovery/termination and add anti-hang guards.
Enforce concise iteration logging: summary entry in docs/operations/progress.md, minimal docs/changelog churn.
Enforce bottom-up vertical-slice completion checks before advancing to higher-layer features.
Break repeated debug loops by enforcing hypothesis-driven attempts, loop budgets, and evidence logging.