Re: [Cython] Non-type template parameters

2015-07-28 Thread Robert Bradshaw
Sorry for not getting back sooner... responses below.

On Mon, Jul 20, 2015 at 2:06 PM, Ian Henriksen
 wrote:
> Hi all,
> I've spent a little time working on adding support for non-type
> template parameters. In doing this, it has been very easy to add
> support for doing something like the following:
>
> cdef extern from "add_const.hpp" nogil:
> int myfunc1[i](int)
> def test():
> print myfunc1[2](a)
>
> The downside of this is that it does not let the Cython compiler
> distinguish between different kinds of template parameters.
>
> Stricter checking could be added using a syntax like this:
>
> cdef extern from "add_const.hpp" nogil:
> int myfunc1[int i](int)
> def test():
> print myfunc1[2](a)
>
> The downsides here are that the syntax doesn't really match the
> existing template syntax. It will also complicate the Cython codebase
> since we'll have to go to greater lengths to allow or disallow all the
> different special cases for templates.
>
> Which version would be preferable?

I think I'd prefer the [int i] syntax. Hopefully it shouldn't
complicate things too much.

> On a similar note, for variadic templates, would we prefer something
> like
>
> cdef extern from "my_variadic.hpp" nogil:
> T myfunc2[T,...](T, ...)
>
> or something like:
>
> cdef extern from "my_variadic.hpp" nogil:
> T myfunc2[T, Types...](T, Types... args)
>
> Again, the latter syntax is more explicit, but it will require much more
> complicated code in Cython. It also doesn't match the existing syntax
> very well. The former syntax matches the existing syntax for templates
> better, but will make it hard for Cython to raise errors early on in
> compilation.

Hmm... this is a tougher call. Let's go with the former for now.

> I'd greatly appreciate any input on the best syntax for either use-case.
>
> Regards,
>
> -Ian Henriksen
>
> ___
> cython-devel mailing list
> cython-devel@python.org
> https://mail.python.org/mailman/listinfo/cython-devel
>
___
cython-devel mailing list
cython-devel@python.org
https://mail.python.org/mailman/listinfo/cython-devel


Re: [Cython] [RFE] Add dummy compiler directive decorators for pure python mode

2015-07-28 Thread Robert Bradshaw
On Sat, Jul 25, 2015 at 6:23 AM, Carlos Pita  wrote:
>> > Not sure, but would it be desirable for the decorators to be less dummy and
>> > for RuntimeCompiledFunction to take the flags into account when compiling
>> > on the fly?
>>
>> Can you provide a pull request, including tests?
>
> I don't have much time these days but I gave some thoughts to this and I
> would like to hear your opinion about the following proposal before start
> coding:
>
> 1. The compiler-directives, locals, etc. decorators will be less dummy in
> two ways:
>   - They will know how to print a repr of themselves.
>   - They will register themselves under some "private" attribute (say
> _cython_decorators, do you have any preference here?) of the decorated 
> function.
>
> 2. Besides get_body(f), RuntimeCompiledFunction will use a new function
> get_cython_decorators(f), which returns the concatenated repr of the
> registered decorators.
>
> 3. This block of code will be passed as a new argument (say
> cython_decorators) to cython_inline. The module code template will now be:
>
> module_code = """
> %(module_body)s
> %(cimports)s
> %(cython_decorators)s
> def __invoke(%(params)s):
> %(func_body)s
> """
>
> What do you think?

+1
___
cython-devel mailing list
cython-devel@python.org
https://mail.python.org/mailman/listinfo/cython-devel


Re: [Cython] Non-type template parameters

2015-07-28 Thread Ian Henriksen
On Tue, Jul 28, 2015 at 1:36 AM Robert Bradshaw  wrote:

> Sorry for not getting back sooner... responses below.
>
> On Mon, Jul 20, 2015 at 2:06 PM, Ian Henriksen
>  wrote:
> > Hi all,
> > I've spent a little time working on adding support for non-type
> > template parameters. In doing this, it has been very easy to add
> > support for doing something like the following:
> >
> > cdef extern from "add_const.hpp" nogil:
> > int myfunc1[i](int)
> > def test():
> > print myfunc1[2](a)
> >
> > The downside of this is that it does not let the Cython compiler
> > distinguish between different kinds of template parameters.
> >
> > Stricter checking could be added using a syntax like this:
> >
> > cdef extern from "add_const.hpp" nogil:
> > int myfunc1[int i](int)
> > def test():
> > print myfunc1[2](a)
> >
> > The downsides here are that the syntax doesn't really match the
> > existing template syntax. It will also complicate the Cython codebase
> > since we'll have to go to greater lengths to allow or disallow all the
> > different special cases for templates.
> >
> > Which version would be preferable?
>
> I think I'd prefer the [int i] syntax. Hopefully it shouldn't
> complicate things too much.
>

Okay, I think I see a way to make that work. On the other hand, since there
weren't any replies here, I've already nearly finished implementing the
first
syntax. I'll spend another hour or two finishing it off later today and
submit a PR
so you can look it over. I originally favored the first syntax because it
minimizes
the number of fancy template features (SFINAE, for example) we have to worry
about on the Cython end. I'm still open to discuss it though.


>
> > On a similar note, for variadic templates, would we prefer something
> > like
> >
> > cdef extern from "my_variadic.hpp" nogil:
> > T myfunc2[T,...](T, ...)
> >
> > or something like:
> >
> > cdef extern from "my_variadic.hpp" nogil:
> > T myfunc2[T, Types...](T, Types... args)
> >
> > Again, the latter syntax is more explicit, but it will require much more
> > complicated code in Cython. It also doesn't match the existing syntax
> > very well. The former syntax matches the existing syntax for templates
> > better, but will make it hard for Cython to raise errors early on in
> > compilation.
>
> Hmm... this is a tougher call. Let's go with the former for now.
>

I like the former a lot more. It will keep the syntax simpler on our end
and I
haven't been able to find any case that it doesn't cover. This will also be
significantly easier to implement. I'll take a look at it soon.
Thanks!
-Ian Henriksen


>
> > I'd greatly appreciate any input on the best syntax for either use-case.
> >
> > Regards,
> >
> > -Ian Henriksen
> >
> > ___
> > cython-devel mailing list
> > cython-devel@python.org
> > https://mail.python.org/mailman/listinfo/cython-devel
> >
> ___
> cython-devel mailing list
> cython-devel@python.org
> https://mail.python.org/mailman/listinfo/cython-devel
>
___
cython-devel mailing list
cython-devel@python.org
https://mail.python.org/mailman/listinfo/cython-devel


Re: [Cython] Non-type template parameters

2015-07-28 Thread Robert Bradshaw
On Tue, Jul 28, 2015 at 11:18 AM, Ian Henriksen
 wrote:
>
> On Tue, Jul 28, 2015 at 1:36 AM Robert Bradshaw  wrote:
>>
>> Sorry for not getting back sooner... responses below.
>>
>> On Mon, Jul 20, 2015 at 2:06 PM, Ian Henriksen
>>  wrote:
>> > Hi all,
>> > I've spent a little time working on adding support for non-type
>> > template parameters. In doing this, it has been very easy to add
>> > support for doing something like the following:
>> >
>> > cdef extern from "add_const.hpp" nogil:
>> > int myfunc1[i](int)
>> > def test():
>> > print myfunc1[2](a)
>> >
>> > The downside of this is that it does not let the Cython compiler
>> > distinguish between different kinds of template parameters.
>> >
>> > Stricter checking could be added using a syntax like this:
>> >
>> > cdef extern from "add_const.hpp" nogil:
>> > int myfunc1[int i](int)
>> > def test():
>> > print myfunc1[2](a)
>> >
>> > The downsides here are that the syntax doesn't really match the
>> > existing template syntax. It will also complicate the Cython codebase
>> > since we'll have to go to greater lengths to allow or disallow all the
>> > different special cases for templates.
>> >
>> > Which version would be preferable?
>>
>> I think I'd prefer the [int i] syntax. Hopefully it shouldn't
>> complicate things too much.
>
> Okay, I think I see a way to make that work. On the other hand, since there
> weren't any replies here, I've already nearly finished implementing the
> first
> syntax. I'll spend another hour or two finishing it off later today and
> submit a PR
> so you can look it over. I originally favored the first syntax because it
> minimizes
> the number of fancy template features (SFINAE, for example) we have to worry
> about on the Cython end. I'm still open to discuss it though.

I think this falls into the "explicit is better than implicit" bucket.
That and getting obscure template errors that could have been caught
at Cython compile time will be very nice.

>> > On a similar note, for variadic templates, would we prefer something
>> > like
>> >
>> > cdef extern from "my_variadic.hpp" nogil:
>> > T myfunc2[T,...](T, ...)
>> >
>> > or something like:
>> >
>> > cdef extern from "my_variadic.hpp" nogil:
>> > T myfunc2[T, Types...](T, Types... args)
>> >
>> > Again, the latter syntax is more explicit, but it will require much more
>> > complicated code in Cython. It also doesn't match the existing syntax
>> > very well. The former syntax matches the existing syntax for templates
>> > better, but will make it hard for Cython to raise errors early on in
>> > compilation.
>>
>> Hmm... this is a tougher call. Let's go with the former for now.
>
>
> I like the former a lot more. It will keep the syntax simpler on our end and
> I
> haven't been able to find any case that it doesn't cover. This will also be
> significantly easier to implement. I'll take a look at it soon.

Sounds good.

There's also the question of default arguments. Let's adopt the [type
T = *] syntax for that.

>> > I'd greatly appreciate any input on the best syntax for either use-case.
>> >
>> > Regards,
>> >
>> > -Ian Henriksen
>> >
>> > ___
>> > cython-devel mailing list
>> > cython-devel@python.org
>> > https://mail.python.org/mailman/listinfo/cython-devel
>> >
>> ___
>> cython-devel mailing list
>> cython-devel@python.org
>> https://mail.python.org/mailman/listinfo/cython-devel
>
>
> ___
> cython-devel mailing list
> cython-devel@python.org
> https://mail.python.org/mailman/listinfo/cython-devel
>
___
cython-devel mailing list
cython-devel@python.org
https://mail.python.org/mailman/listinfo/cython-devel