Dag Sverre Seljebotn wrote:
> Dag Sverre Seljebotn wrote:
>> Kurt Smith wrote:
>>> Although, what about when we require a contiguous copy (or any mode,
>>> for that matter) of a buffer? Would we set the top-level object
>>> reference to None, as suggested in a previous thread? That would
>>> prevent slicing at the Python API level, though, right?
>> Hmm. I'm still thinking about contiguous copies. Let's deal with that in
>> the next iteration.
>
> OK I've been thinking about copy-making:
>
> This really seems to be linked to in/out/inout specifiers as part of the
> function signature, more than anything else. There's basically two kind
> of functions:
>
> a) The ones that pass in and out data. These can use in/out/inout
> specifiers and copying can happen automatically.
>
> b) The ones that need to hold on to the buffer after returning
> ("obj.set_data_store"). Copying here will cause trouble.
>
> So I propose:
>
> cdef void dataonly(inout int[::1] arr) # requires contiguous
> cdef void keepsref(int[::1] arr) # requires contiguous
> cdef void keepsref_strided(int[:] arr)
>
>
> int[:] discontiguous_buf = ...
>
> dataonly(discontiguous_buf) # allowed, copying happen
> keepsref(discontiguous_buf) # disallowed, compile-time error
Actually, let's keep this a runtime error -- as strided buffers can be
contiguous (it needs to be runtime anyway for passing Python objects).
It could hint to "use the .copy() method".
--
Dag Sverre
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev