Skip to content

Fix self-initialized degree_type in cugraph_k_core - #5718

Open
morristai wants to merge 3 commits into
rapidsai:mainfrom
algeon-dev:fix-k-core-degree-type
Open

morristai wants to merge 3 commits into
rapidsai:mainfrom
algeon-dev:fix-k-core-degree-type

Conversation

@morristai

Copy link
Copy Markdown
Contributor

Closes #5714

Same self-initialization as #4734, in k_core.cpp instead of core_number.cpp: the local degree_type was initialized from itself and the member degree_type_ was never read. The member has the C enum type cugraph_k_core_degree_type_t and the target is the C++ enum cugraph::k_core_degree_type_t, hence a static_cast.

The C API test always precomputed core numbers, which left the core_result == NULL path untested. generic_k_core_test now takes the degree type and a flag for precomputing, checks the return code of cugraph_k_core, and has new cases with core_result == NULL for IN (k = 3) and INOUT (k = 6).

🤖 Generated with Claude Code

cugraph_k_core ignores its degree_type argument. When the caller
passes core_result == NULL, which core_algorithms.h documents as "call
core_number inside this function call", core numbers are computed with
an indeterminate degree type. Depending on the value, core_number
rejects it with "degree_type should be IN, OUT, or INOUT" or computes
core numbers for a degree type the caller did not request.

In cpp/src/c_api/k_core.cpp, k_core_functor::operator() declares

    auto degree_type =
      reinterpret_cast<cugraph::k_core_degree_type_t>(degree_type);

at line 111. The name on the right refers to the local being declared,
so the local is initialized from itself and the member degree_type_
(line 27, set in the constructor at line 42) is never read. The value
reaches cugraph::k_core as std::make_optional(degree_type) at line 119
and, when core_numbers is not given, cugraph::core_number, which checks
it in cpp/src/cores/core_number_impl.cuh lines 73-76.

cpp/src/c_api/core_number.cpp had the same defect, reported in rapidsai#4734
and fixed in rapidsai#4755; the k_core C API was not changed at that time.

Read degree_type_ instead. The member has the C enum type
cugraph_k_core_degree_type_t and the target is the unrelated C++ enum
cugraph::k_core_degree_type_t, so the conversion is a static_cast.

The C API test previously always passed a precomputed core result, so
the NULL path had no coverage. generic_k_core_test now takes the degree
type and whether to precompute core numbers, and checks the return
code of cugraph_k_core. Two new cases pass core_result == NULL:
K_CORE_DEGREE_TYPE_IN with k = 3, and K_CORE_DEGREE_TYPE_INOUT with
k = 6. On a symmetric graph INOUT core numbers are twice the IN core
numbers, so both select the same 12 edges. Using two degree types
keeps the test meaningful if the indeterminate value happens to equal
one enumerator.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@morristai
morristai requested a review from a team as a code owner October 21, 2026 03:33
@copy-pr-bot

copy-pr-bot Bot commented Oct 21, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

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.

[BUG]: cugraph_k_core ignores degree_type when core_result is NULL

1 participant