Dag Sverre Seljebotn wrote:
> [a couple of unnecessary words stripped]
> Robert Bradshaw wrote:
>> OK, how about we get the feature with the less controversial syntax,
>> and then re-open the discussion if desired.
>
> Assuming you mean "simd[int, (stridespecs)]" is less controversial here:
>
> My main issue with this solution is what precendence it creates for how
> project issues are settled. I don't like having a project culture where
> stamina in these long threads is what counts in the end -- I'd much
> rather have a clear, open voting process.
>
> But hear this: If both Robert and Stefan agrees about a syntax, whatever
> the conclusion is, I won't say another word.
Note that I raised a problem that you didn't solve so far, either. We
currently have a syntax for an array type (basically the C syntax) and a
syntax for the proposed SIMD type (int[:,:]). What we do not have is a
syntax for a memory view that does not have SIMD semantics, especially not
one that works in pure Python mode also. I assume that would use
cdef MemoryView[int,int] v
in the original setup, which I would call inconsistent with all other
syntax we have for this.
> (That is, you need to get the stridespecs in, and I'll state now that
> I'd really, really prefer a Python-grammar-compatible syntax, unlike the
> alternative proposals until now. Getting SIMD in pure Python mode with
> the same type syntax is one of the neatest point in the whole int[:,:]
> syntax.)
Ok, so what about changing the template syntax then. Here's an idea. As I
said before, I'm a big fan of keyword arguments.
A template type (or generic type if you prefer) is a type that is
specialised by providing specific types for template parameters. These were
proposed to be specified as in
cdef SomeTemplateType[int] x
Now, if we change that into allowing (something that looks like) a compile
time function call to return the type, we can do
cdef SomeTemplateType(int, some_kw=True, other_kw=False) x
or, for better readability,
ctypedef SomeTemplateType(int, some_kw=True, other_kw=False) SpecialType
cdef SpecialType x
This will complicate the parser a bit in that we cannot easily distinguish
between a C function definition and a type declaration before having parsed
the signature and seeing a ':' or not. So I don't expect everyone to be
happy with this. However, if the goal is to provide a nicely readable way
for specialising types that also works in plain Python, then this is pretty
much as good as it can get. Because in plain Python, you can obviously do
SpecialType = cython.typedef(
SomeTemplateType(int, some_kw=True, other_kw=False))
x = SpecialType(1,2,3)
Note also that the parser grammar can easily be disambiguated by requiring
a typedef for specialised types, just as in the Python code.
How does this impact the SIMD syntax then? Well, simple. You could do
cdef mymethod(y):
cdef SIMD(int, int, strides=[5,4]) x = y
or, if typedefs are required,
ctypedef SIMD(int, int, strides=[5,4]) My2dSimdType
cdef mymethod(y):
cdef My2dSimdType x = y
Just an idea.
Stefan
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev