Skip to content

Error when assigning a non-const memoryview to the copy of a const memoryview #2134

Closed
@lesteve

Description

@lesteve

I have a const memoryview and I am trying to create a non-const memoryview by copying it. Naively I would expect it to be possible. Here is a snippet that reproduces the problem:

import numpy as np

cdef const double[:] ro = np.ones(3)
cdef double[:] rw = ro.copy()

The error I get:

Memoryview 'const double[::1]' not conformable to memoryview 'double[:]'.

If I read the error correctly it seems like ro.copy() type is still const.

A bit more context: I am trying out cython 0.28b1 and experimenting with const memoryviews in a scikit-learn context.

Side-comment: it is a slight variation of 6704d23 where instead of creating rw and then replacing the values by using rw[:] = ..., I am trying to do it in one line (which feels like the thing you would write in practice).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions