[Python] Cython: specify typed memoryview as template type for C++ map

Discussão em 'Python' iniciado por Stack, Março 27, 2025.

  1. Stack

    Stack Membro Participativo

    I'd like to use C++ typed maps instead of Python dicts, where the map's keys are integers and values are typed Cython memoryviews. A minimal (non)working example is:

    # distutils: language=c++

    from libcpp.unordered_map cimport unordered_map as Map

    cdef Map[int, int[:,:]] P;


    where I get the compilation error

    test.pyx:5:8: Reference-counted type 'int[:, :]' cannot be used as a template argument


    Is there any way to specify objects of this type? I'd like to take full advantage of Cython's speed advantages, and that means using typed containers!

    Continue reading...

Compartilhe esta Página