Skip to content

feat: Graph.Nearest_Neighbor_Graph() #851

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

szhorvat
Copy link
Member

@szhorvat szhorvat commented Aug 14, 2025

@Zepeacedust, this is an example of exposing a new graph generator in python-igraph, that you can later use as a model to expose the Delaunay generator.

This is not my comfort zone so let's wait for comments from @ntamas.

@ntamas, do you prefer Nearest_Neighbor_Graph or Nearest_Neighbor here? Since this term is used in other contexts as well, I vote for keeping the Graph suffix.

@szhorvat szhorvat requested review from ntamas and Copilot August 14, 2025 21:30
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a new graph generator function Graph.Nearest_Neighbor_Graph() to python-igraph, which creates k-nearest neighbor graphs from spatial point data. The implementation serves as an example for exposing additional graph generators, specifically to guide the future implementation of a Delaunay generator.

Key changes:

  • Adds C implementation of the nearest neighbor graph generator with support for different metrics (euclidean, manhattan) and configurable parameters
  • Includes Python binding and method registration for the new graph generator
  • Adds basic test coverage for the new functionality

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
src/_igraph/graphobject.c Implements the C function and registers the Python method for nearest neighbor graph generation
src/_igraph/convert.h Declares the metric conversion function for parameter parsing
src/_igraph/convert.c Implements conversion from Python objects to igraph metric types
tests/test_generators.py Adds basic test case for the new graph generator
Comments suppressed due to low confidence (2)

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

@szhorvat szhorvat force-pushed the feat/nearest-neighbor branch from 9ea8ead to 4b09056 Compare August 14, 2025 21:33
@szhorvat szhorvat force-pushed the feat/nearest-neighbor branch from 4b09056 to fb6f407 Compare August 14, 2025 21:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant