Skip to content

Add np.may_share_memory / np.shares_memory / np.byte_bounds to _PASSTHROUGH_NAMES #72

@spMohanty

Description

@spMohanty

Identified in #67 — flagged as cleanup in the "Explicitly out of scope" section.

Current state

_PASSTHROUGH_NAMES (in src/whest/_ndarray.py) holds the original numpy callables that should bypass __array_function__ entirely because they're zero-FLOP queries. Today the set covers shape / type queries:

_PASSTHROUGH_NAMES = (
    "ndim", "shape", "size",
    "result_type", "can_cast", "min_scalar_type",
    "promote_types", "find_common_type", "mintypecode",
    "array_equal",
)

Missing: may_share_memory, shares_memory, byte_bounds. They're zero-FLOP memory-layout queries that currently work because the protocol path strips inputs and dispatches; routing them through the strip path is wasteful.

Reproducer

import numpy as np, whest as we
A = we.random.randn(3, 3)
np.may_share_memory(A, A)   # works, but enters __array_function__ unnecessarily

Suggested fix

Add the three names to _PASSTHROUGH_NAMES and update the eager _INITIAL_PASSTHROUGH = _build_passthrough() capture. One-line addition each. Add a short test in tests/test_array_protocols.py that asserts these calls no longer enter __array_function__ (e.g. by patching _get_array_function_dispatch and asserting it's not called).

Acceptance criteria

  • The three names added to _PASSTHROUGH_NAMES.
  • Test pinning that they don't dispatch through __array_function__.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:coreCore whest API, counting, ndarray, and dispatch/wrapping pathspriority:p3Someday / aspirationalrefactorCode restructuring without behavior change

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions