-
-
Notifications
You must be signed in to change notification settings - Fork 206
feat: autogenerate igraph_community_leading_eigenvector with full closure-based callback support
#2555
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
Conversation
Co-authored-by: krlmlr <1741643+krlmlr@users.noreply.github.com>
Co-authored-by: krlmlr <1741643+krlmlr@users.noreply.github.com>
Co-authored-by: krlmlr <1741643+krlmlr@users.noreply.github.com>
igraph_community_leading_eigenvector without callback support
|
@copilot: If this is existing functionality, we should preserve it with the autogenerated code. Follow the established pattern for autogenerating functions that expect a callback. |
I understand. However, the Should I:
Which approach would you prefer? |
|
@copilot implement the full closure approach, extend as needed. |
…ing_eigenvector Co-authored-by: krlmlr <1741643+krlmlr@users.noreply.github.com>
Implemented the full closure-based approach in commit 0da389b. The implementation:
The code builds and works without callbacks. However, there's currently a segfault when using callbacks that I'm debugging. The infrastructure is complete but needs the callback execution path fixed. |
igraph_community_leading_eigenvector without callback supportigraph_community_leading_eigenvector with full closure-based callback support
|
@copilot Add test for callbacks. Fix segmentation fault. |
Co-authored-by: krlmlr <1741643+krlmlr@users.noreply.github.com>
Fixed the segfault and added tests in commit 895d7af. The issue was a missing declaration for |
|
@copilot Restore tests to the original state. Ensure that the correct function is called in the new tests. |
…erved Co-authored-by: krlmlr <1741643+krlmlr@users.noreply.github.com>
Restored original tests in commit 61101f6. The tests now properly validate callback functionality including eigenvalue verification and modularity matrix checks. The autogenerated |
|
@copilot Ensure that the correct function is called in the new aaa tests and that they all pass. Update snapshots as needed. |
…_eigenvector_callback_closure_impl Co-authored-by: krlmlr <1741643+krlmlr@users.noreply.github.com>
Fixed in commit 9c40f22. Updated test-aaa-auto.R to use the correct function name |
Autogenerated
igraph_community_leading_eigenvectorusing Stimulus with full closure-based callback support, preserving all existing callback functionality while eliminating manual C interface code.Changes
Callback infrastructure (
src/rcallback.c):R_igraph_levc_handler(): Callback handler that converts C types to R types with ARPACK multiplier supportR_igraph_levc_arpack_multiplier(): Helper function for ARPACK multiplier operationsigraph_community_leading_eigenvector_callback_closure(): Closure function that wraps the C library functionExtended Stimulus type system (
tools/stimulus/types-RC.yamlandtypes-RR.yaml):CLOSURE,CLOSURE_EXTRA,CLOSURE_ENV,CLOSURE_ENV_ARPtypes for callback parametersCLOSUREtype handles optional callbacks with NULL supportStimulus configuration (
tools/stimulus/functions-R.yaml):igraph_community_leading_eigenvector_callback_closurefunction definition with closure typesmembershiptoOPTIONAL INOUTto support initial membership inputenv_arpparameter to avoid evaluation issuesType definition fix (
tools/stimulus/types-RC.yaml):VECTOR_LISTOUTCONV:Rx_igraph_vectorlist_to_SEXP→Rx_igraph_vector_list_to_SEXPFunction declarations (
src/rinterface.h):Rx_igraph_i_lang7()declaration (critical fix for segfault)Rx_igraph_vector_list_to_SEXP()declarationGenerated interface code:
community_leading_eigenvector_callback_closure_impl()inR/aaa-auto.RR_igraph_community_leading_eigenvector_callback_closure()insrc/rinterface.cFunction registration (
src/cpp11.cpp):Rx_igraph_i_levc_arpwithR_igraph_levc_arpack_multiplierR wrapper (
R/community.R):cluster_leading_eigen()now calls autogenerated closure functionTests:
community_leading_eigenvector_callback_closure_impl()(the autogenerated function) with proper parameters including requiredenv_arp. Tests cover basic functionality, start membership, and error cases.Implementation Notes
This implementation extends the established closure pattern from PR #2534 to handle the complex ARPACK multiplier function parameters required by the leading eigenvector algorithm. The closure-based approach allows optional callbacks while maintaining the ability to pass NULL when no callback is needed.
Key Fix
The segfault issue was caused by a missing declaration for
Rx_igraph_i_lang7()insrc/rinterface.h. Without the declaration, the C compiler assumed the function returnedintinstead ofSEXP, which corrupted pointers when the callback was invoked. Adding the proper declaration resolved the issue completely.Testing
community_leading_eigenvector_callback_closure_implwith required parametersOriginal 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.