[WIP] Introduce query_pairs method for index pairs#46
Closed
Conversation
Copilot stopped work on behalf of
atksh due to an error
November 2, 2025 15:01
atksh
pushed a commit
that referenced
this pull request
Nov 3, 2025
Implements a new query_intersections() method that efficiently finds all pairs of intersecting bounding boxes in the tree, addressing the feature request in issue #46. Key features: - Returns numpy array of shape (n_pairs, 2) with index pairs (i, j) where i < j - Parallel processing using std::thread for improved performance - Automatic double-precision refinement when exact coordinates are available - No duplicate pairs or self-pairs - Similar to scipy.spatial.cKDTree.query_pairs but for AABBs This eliminates the need for manual post-processing of batch_query results using np.vectorize, np.repeat, and np.concatenate, which previously canceled out the performance gains from C++ parallelization. Changes: - cpp/prtree.h: Added query_intersections() method to PRTree class - cpp/main.cc: Added Python bindings for all dimensions (2D, 3D, 4D) - tests/test_PRTree.py: Added comprehensive tests including edge cases - README.md: Updated documentation with usage examples All tests pass (45 new tests + existing tests). Resolves #46
atksh
added a commit
that referenced
this pull request
Nov 3, 2025
* Add query_intersections() method for efficient AABB pair detection Implements a new query_intersections() method that efficiently finds all pairs of intersecting bounding boxes in the tree, addressing the feature request in issue #46. Key features: - Returns numpy array of shape (n_pairs, 2) with index pairs (i, j) where i < j - Parallel processing using std::thread for improved performance - Automatic double-precision refinement when exact coordinates are available - No duplicate pairs or self-pairs - Similar to scipy.spatial.cKDTree.query_pairs but for AABBs This eliminates the need for manual post-processing of batch_query results using np.vectorize, np.repeat, and np.concatenate, which previously canceled out the performance gains from C++ parallelization. Changes: - cpp/prtree.h: Added query_intersections() method to PRTree class - cpp/main.cc: Added Python bindings for all dimensions (2D, 3D, 4D) - tests/test_PRTree.py: Added comprehensive tests including edge cases - README.md: Updated documentation with usage examples All tests pass (45 new tests + existing tests). Resolves #46 * Add comprehensive Makefile and development documentation Adds a complete development workflow automation through Make commands, making it easier for developers to build, test, and contribute to the project. Key additions: - Makefile: Comprehensive build automation with 30+ commands - Build: build, build-release, rebuild, debug-build - Test: test, test-verbose, test-fast, test-coverage, test-one - Packaging: wheel, sdist, release - Maintenance: clean, clean-all, format, lint - Development: init, dev, install-deps, check - CONTRIBUTING.md: Complete developer guide - Development setup instructions - Workflow documentation - Coding standards - Troubleshooting guide - Enhanced .gitignore: Additional patterns for build artifacts, coverage reports, and temporary files All content is in English and designed to be generic and reusable for any feature development, not specific to any particular functionality. Benefits: - Streamlined development workflow - Consistent build and test procedures - Easy onboarding for new contributors - CI-compatible check commands * Add Makefile usage reference guide * Format C++ code with clang-format Apply clang-format to all C++ source files for consistent code style. This is an automatic formatting change with no functional modifications. Files affected: - cpp/main.cc: Brace positioning and line wrapping - cpp/parallel.h: Formatting improvements - cpp/prtree.h: Consistent formatting throughout - cpp/small_vector.h: Style consistency updates These changes were generated by running 'make format'. * Fix: Guard against zero hardware_concurrency in query_intersections When std::thread::hardware_concurrency() returns 0 (which is permitted when the runtime cannot detect the CPU count), n_threads was set to zero. This caused undefined behavior: - In single-threaded path: writes to thread_pairs[0] on empty vector - In parallel path: loops never execute, returning no intersections Apply the same guard used in find_all() to ensure at least one thread. This fixes a critical bug that could cause crashes or incorrect results on systems where hardware_concurrency() returns 0. Fixes: P1 Badge Guard against zero hardware_concurrency Reported-by: User feedback --------- Co-authored-by: Claude <noreply@anthropic.com>
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.
Thanks for assigning this issue to me. I'm starting to work on it and will keep this PR's description up to date as I form a plan and make progress.
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.