Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cuda_core/cuda/core/graph/_adjacency_set_proxy.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ from cuda.core._rt cimport (
graph_node_get_graph,
)
from cuda.core._utils.cuda_utils cimport HANDLE_RETURN
import cython
from collections.abc import Iterable, Iterator, MutableSet, Set
from typing import Any, TypeVar

Expand Down Expand Up @@ -59,6 +60,7 @@ class AdjacencySetProxy(MutableSet[GraphNode]):
return
(<_AdjacencySetCore>self._core).add_edge(<GraphNode>value)

@cython.annotation_typing(False)
def discard(self, value: GraphNode) -> None:
(<_AdjacencySetCore>self._core).check_owner_mutable()
if value not in self:
Expand Down
5 changes: 5 additions & 0 deletions cuda_core/docs/source/release/1.3.0-notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,8 @@ Fixes and enhancements
device is now revoked with its own request, so no single device can block
the others.
(`#2807 <https://github.com/NVIDIA/cuda-python/issues/2807>`__)

- Calling ``discard()`` on the set-like :attr:`graph.GraphNode.pred` and
:attr:`graph.GraphNode.succ` views with an object that is not a
:class:`~graph.GraphNode` is now a no-op instead of raising ``TypeError``,
consistent with :class:`collections.abc.MutableSet` semantics.
14 changes: 14 additions & 0 deletions cuda_core/tests/graph/test_graph_definition_mutation.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,20 @@ def test_add_wrong_type(init_cuda):
node.succ.add(42)


@pytest.mark.agent_authored(model="gpt-5.6-sol")
def test_discard_wrong_type_is_noop(init_cuda):
"""Discarding a non-GraphNode is a no-op, matching MutableSet semantics."""
g = GraphDefinition()
owner = g.empty()
neighbor = g.empty()
owner.succ.add(neighbor)

owner.succ.discard("not a node")
owner.succ.discard(42)

assert owner.succ == {neighbor}


@pytest.mark.agent_authored(model="gpt-5.6")
def test_discard_absent_invalid_value_is_noop(init_cuda):
graph = GraphDefinition()
Expand Down
Loading