Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Overloaded function
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Ian Bell  
View profile  
 More options Aug 6 2012, 11:55 pm
From: Ian Bell <ian.h.b...@gmail.com>
Date: Mon, 6 Aug 2012 23:55:36 -0400
Local: Mon, Aug 6 2012 11:55 pm
Subject: Overloaded function

Is there any way to do overloaded functions in cython?  I have a PXD file
that demonstrates what I am trying to do:

cdef extern from "CoolProp.h":

    double _Props "Props"(char *Output,char Name1, double Prop1, char
Name2, double Prop2, char * Ref)
    double _Props1 "Props"(char * Ref, char *Output)

#Function prototypes
cpdef double Props(bytes Parameter, bytes param1, float value1, bytes
param2, float value2, bytes Fluid)
cpdef double Props(bytes Fluid, bytes Parameter)

I would then write my implementation in a PYX file and all should be well.

I can get this to work with SWIG without problems, but I am getting
progressively more annoyed with SWIG in general and am hoping to move all
my SWIG code to cython and get rid of SWIG entirely throughout all my
projects.

Thanks,
Ian


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Stefan Behnel  
View profile  
 More options Aug 7 2012, 3:45 am
From: Stefan Behnel <stefan...@behnel.de>
Date: Tue, 07 Aug 2012 09:45:57 +0200
Local: Tues, Aug 7 2012 3:45 am
Subject: Re: [cython-users] Overloaded function
Ian Bell, 07.08.2012 05:55:

> Is there any way to do overloaded functions in cython?  I have a PXD file
> that demonstrates what I am trying to do:

> cdef extern from "CoolProp.h":

>     double _Props "Props"(char *Output,char Name1, double Prop1, char
> Name2, double Prop2, char * Ref)
>     double _Props1 "Props"(char * Ref, char *Output)

> #Function prototypes
> cpdef double Props(bytes Parameter, bytes param1, float value1, bytes
> param2, float value2, bytes Fluid)
> cpdef double Props(bytes Fluid, bytes Parameter)

> I would then write my implementation in a PYX file and all should be well.

Hmm, you mean that you want to implement these in Cython and export them to
other modules? This is not about wrapping C++ implemented code, right?

Cython doesn't currently support this. You can use optional arguments in
cdef functions, though.

Such a feature can't be hard to add, given that we have already support for
C++ types anyway. You wouldn't declare a cname though (your "Props" string
above), Cython would mangle the internal names for you. However, exporting
them so that other modules can use them might turn out to be tricky because
all Cython versions you use would have to come up with the same mangled
public name.

Stefan


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
mark florisson  
View profile  
 More options Aug 7 2012, 5:27 am
From: mark florisson <markflorisso...@gmail.com>
Date: Tue, 7 Aug 2012 10:27:23 +0100
Local: Tues, Aug 7 2012 5:27 am
Subject: Re: [cython-users] Overloaded function
On 7 August 2012 04:55, Ian Bell <ian.h.b...@gmail.com> wrote:

Maybe you just want to use default values?

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ian Bell  
View profile  
 More options Aug 7 2012, 12:39 pm
From: Ian Bell <ian.h.b...@gmail.com>
Date: Tue, 7 Aug 2012 12:39:45 -0400
Local: Tues, Aug 7 2012 12:39 pm
Subject: Re: [cython-users] Overloaded function

exporting them, but if I compile a file as a PYX file, I lose the ability
to do something like::

    Props(*args)

and then select the right function signature based on the form of args.
Also this will take a significant speed penalty since I need to be doing
type comparison, and this is a function that gets called quite a few
million times, so performance is of the utmost importance.

> Cython doesn't currently support this. You can use optional arguments in
> cdef functions, though.

Optional, yes, but so far as I am aware, no way to do something like

    cpdef double Props(*args):


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ian Bell  
View profile  
 More options Aug 8 2012, 12:42 pm
From: Ian Bell <ian.h.b...@gmail.com>
Date: Wed, 8 Aug 2012 12:42:49 -0400
Local: Wed, Aug 8 2012 12:42 pm
Subject: Re: [cython-users] Overloaded function

function with the signature::

    Props(bytes in1, bytes in2, in3 = None, in4 = None, in5 = None, in6 =
None)

and then called the correct function from the CoolProp header as needed.
Thanks for the idea about default parameters.

Ian


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »