Skip to content

[M4] NumPy zero-copy and type stubs #27

Description

@tetsuh

Summary

Implement zero-copy NumPy reads (get_array) and ship type stubs.

References

  • docs/05_api_python.md §1 (type mapping), §2.2 (get_array), §4 (stubs)
  • docs/01_requirements.md P02

Scope

  • python/bindings/numpy.cpp: ParamCache.get_array(key, dtype=...)
    returning a read-only ndarray over the cached buffer
    (buffer protocol; writeable=False; keepalive holds the
    shared_ptr<const ParamValue>)
  • Size/dtype mismatch raises TypeMismatchError
  • ndarray put: C-contiguous arrays accepted via buffer protocol
    (one copy at encode time)
  • python/sitos/py.typed + .pyi stubs for the whole public API;
    mypy runs in CI
  • tests/python/test_numpy_zero_copy.py: base-pointer identity
    (no copy), writeable flag, keepalive under value overwrite
    (Python-side SpanHandleSurvivesOverwrite equivalent)

Out of scope

  • dtype/shape metadata in the payload (not part of wire v1)

Acceptance Criteria

  1. get_array returns a view (no copy — verified via base pointer) with
    writeable == False
  2. Array stays valid after the key is overwritten (keepalive)
  3. mypy is green against the stubs

Dependencies

For the implementer

  • Copy the checklist above into your PR description and tick items as you
    complete them. Do not edit the checklist in this issue.
  • Follow docs/development_workflow.md (branch issue/27-numpy-zero-copy,
    Conventional Commits per §2.1, TDD RED first).
  • This issue is closed automatically by the PR via Closes #27.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:pythonPython bindings and packagingtype:featNew feature or capability

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions