Fix (#682 #679) macOS ARM64 crash and logic error with Numpy 2.x #690
+5
−6
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.
This PR resolves two critical issues observed on macOS Apple Silicon (M1/M2/M3) when building with Numpy 2.x:
SIGBUS (Bus Error) Crash:
Issue: The Node structures in
src/annoylib.hrely on a memory layout where children and v (vector data) are contiguous. On ARM64, strict alignment requirements caused SIGBUS crashes when accessing these potentially unaligned structures.Fix: Added
__attribute__((__packed__))to the Node structs inAngular,DotProduct,Hamming, andMinkowskidefinitions. This ensures the compiler generates safe code for unaligned memory access.Incorrect Neighbor Count (Logic Error):
Issue: Queries were returning only 1 neighbor even when k=10 was requested. This was traced to the
-ffast-mathcompiler flag, which enables non-IEEE 754 compliant optimizations. These optimizations likely interfered with Infinity or NaN handling in the priority queue comparisons or distance calculations.Fix: Removed
-ffast-mathfrom the default compiler arguments insetup.py.This solves the error in #682 #679 and would help some packages YingfanWang/PaCMAP#94