Repository navigation
0.2.0: float and numpy sizes run in C++ - #2
Merged
Merged
Conversation
Sizes given as Python float, numpy.float64 or numpy.int64, in any mix with int, now stay on the native path. Results match rectpack in value and in type. This covers the way gdsfactory calls rectpack (int rectangles in a numpy.float64 bin), which 0.1.0 handed to the original Python code. - _native.cpp: the algorithm is one template, instantiated for int64 and for a tagged double (Num) that tracks the Python type of each value. - CMake: -ffp-contract=off / /fp:precise so float results match Python. - tests: test_mixed_types.py; snapshots now record the type of every number. - bench/run_mixed.py and results/mixed.*: 284x at 300 rectangles and 1193x at 1,000 for gdsfactory-style input on the reference laptop. - The "fallback is 2x slower" known issue was a measurement artifact: research/fallback_slowdown.py, results/fallback_slowdown.txt. - mutation_check.py: five new mutations, one stale mutation repaired. Co-Authored-By: Claude <[email protected]>
Co-Authored-By: Claude <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes
Sizes given as Python
float,numpy.float64ornumpy.int64, in any mix withint, now run in C++. Results matchrectpackin value and in type. In 0.1.0 these fell back to the original Python code.This covers how gdsfactory calls rectpack: integer rectangle sizes in a
numpy.float64bin.MaxRectsBlsf, no rotation)numpy.float64binnumpy.float64binfloatrectangles and binnumpy.int64rectangles, int binOne Windows laptop, best of interleaved rounds; details in
BENCHMARKS.md. The integer path shows the same ratios as before.How
int64and for a tagged double that records which Python type each value has. See "The mixed path" indocs/DESIGN.md.-ffp-contract=off(GCC, Clang) and/fp:precise(MSVC) so float results match Python bit for bit.The "fallback is 2x slower" known issue
It was a measurement artifact, not a defect. The fallback makes 0.007% more Python function calls than rectpack and takes the same time when the two are timed in alternation. Evidence:
research/fallback_slowdown.py,results/fallback_slowdown.txt.Checks
ruffandclang-formatpass.What this PR needs from CI
The float path has not run on Linux or macOS yet. macOS arm64 is the one to watch, because Clang there can fuse multiply-adds. If the mixed-type tests fail on that platform only, that is the cause.
Still falling back
Decimal,Fraction,bool,numpy.float32, numpy integers other thannumpy.int64, and sizes above 2^30 (2^26 forMaxRectsBafwith floats).A substantial part of this change was written with an AI assistant.
🤖 Generated with Claude Code