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
keepsref_strided(discontiguous_buf) # allowed
keepsref(discontiguous_buf.copy()) # allowed
where I envision the copy method as being a way of manually creating a
contiguous copy.
As for pure Python syntax for in/out/inout modifiers, I'm thinking
something like this:
@cython.locals(arr=cython.inout & cython.int[:])
def foo(arr):
...
or in time
def foo(arr: cython.inout & cython.int[:]):
...
(The point here is: Relying on modifiers is not scary, we can use "&" in
pure Python mode to get it across.)
--
Dag Sverre
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev