[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] SIP Pointer Confusion
From:       "Jay L." <jlaura () asu ! edu>
Date:       2016-09-30 1:58:14
Message-ID: CA+bfmPu-sOfTzvXW6jmwwOkgTK5U3ENpKzXKgDGTsXwRWCNrMA () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Phil,

Super helpful and gets me rolling again.  I definitely was not groking many
of the annotations so that point is awesome.

Thanks!
J

On Thu, Sep 29, 2016 at 5:58 PM, Phil Thompson <phil@riverbankcomputing.com>
wrote:

> On 30 Sep 2016, at 1:43 am, Jay L. <jlaura@asu.edu> wrote:
> >
> > Just starting to dig into SIP. I have a .h file that contains the
> following public method:
> >
> > void Allocate(int width, int height, int pitch, bool withHost, float
> *devMem = NULL, float* hostMem = NULL);
> >
> >  have created a corresponding .sip file:
> >
> > 1 //SIP wrapper for CUDA Image
> > 2
> > 3 class CudaImage
> > 4 {
> > 5 %TypeHeaderCode
> > 6 #include "cudaImage.h"
> > 7 %End
> > 8
> > 9 public:
> > 10 CudaImage();
> > 11
> > 12 void Allocate(int width, int height, int pitch, bool withHost, float
> *devMem=NULL, float *hostMem=NULL) /KeywordArgs="All"/;
> > 13 double Download();
> > 14
> > 15
> > 16 int width;
> > 17 int height;
> > 18 int pitch;
> > 19 };
> >
> > Using CMake, I have the build working, can import the module into Python
> and can call the constructor (so limited success). I can also call the
> Allocate method. Unfortunately, on the Python side, I can not get the float
> *devMem=NULL or float *hostMem=Nullarguments exposed. I have been over the
> SIP documentation and no Annotations are leaping out as missing.
> >
> > The ultimate goal is to pass a numpy array (.data attribute I believe)
> to the hostMemargument.
> >
> > How does one go about exposing pointers in SIP? What about pointers with
> a default, NULL, argument?
>
> Pointers to fundamental types are (by default) treated as a way to return
> a value from the method and not pass a value to it - see the /In/
> annotation.
>
> You should then hit the problem that you will have to provide hand-written
> code to handle those arguments because SIP doesn't know how to convert them
> to a Python object. You probably need to declare the types as SIP_PYOBJECT
> and handle the conversion in %MethodCode. Alternatively if that is a common
> situation in your API then consider defined a mapped type.
>
> If numpy arrays support the buffer protocol then you should look at
> exploiting that. You should also look at sip.array and sipConvertToArray().
>
> Phil

[Attachment #5 (text/html)]

<div dir="ltr">Phil,  <div><br></div><div>Super helpful and gets me rolling again.   \
I definitely was not groking many of the annotations so that point is \
awesome.</div><div><br></div><div>Thanks!</div><div>J</div></div><div \
class="gmail_extra"><br><div class="gmail_quote">On Thu, Sep 29, 2016 at 5:58 PM, \
Phil Thompson <span dir="ltr">&lt;<a href="mailto:phil@riverbankcomputing.com" \
target="_blank">phil@riverbankcomputing.com</a>&gt;</span> wrote:<br><blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On 30 Sep 2016, at 1:43 \
am, Jay L. &lt;<a href="mailto:jlaura@asu.edu">jlaura@asu.edu</a>&gt; wrote:<br> \
&gt;<br> &gt; Just starting to dig into SIP. I have a .h file that contains the \
following public method:<br> &gt;<br>
&gt; void Allocate(int width, int height, int pitch, bool withHost, float *devMem = \
NULL, float* hostMem = NULL);<br> &gt;<br>
&gt;   have created a corresponding .sip file:<br>
&gt;<br>
&gt; 1 //SIP wrapper for CUDA Image<br>
&gt; 2<br>
&gt; 3 class CudaImage<br>
&gt; 4 {<br>
&gt; 5 %TypeHeaderCode<br>
&gt; 6 #include &quot;cudaImage.h&quot;<br>
&gt; 7 %End<br>
&gt; 8<br>
&gt; 9 public:<br>
&gt; 10 CudaImage();<br>
&gt; 11<br>
&gt; 12 void Allocate(int width, int height, int pitch, bool withHost, float \
*devMem=NULL, float *hostMem=NULL) /KeywordArgs=&quot;All&quot;/;<br> &gt; 13 double \
Download();<br> &gt; 14<br>
&gt; 15<br>
&gt; 16 int width;<br>
&gt; 17 int height;<br>
&gt; 18 int pitch;<br>
&gt; 19 };<br>
&gt;<br>
&gt; Using CMake, I have the build working, can import the module into Python and can \
call the constructor (so limited success). I can also call the Allocate method. \
Unfortunately, on the Python side, I can not get the float *devMem=NULL or float \
*hostMem=Nullarguments exposed. I have been over the SIP documentation and no \
Annotations are leaping out as missing.<br> &gt;<br>
&gt; The ultimate goal is to pass a numpy array (.data attribute I believe) to the \
hostMemargument.<br> &gt;<br>
&gt; How does one go about exposing pointers in SIP? What about pointers with a \
default, NULL, argument?<br> <br>
</div></div>Pointers to fundamental types are (by default) treated as a way to return \
a value from the method and not pass a value to it - see the /In/ annotation.<br> \
<br> You should then hit the problem that you will have to provide hand-written code \
to handle those arguments because SIP doesn&#39;t know how to convert them to a \
Python object. You probably need to declare the types as SIP_PYOBJECT and handle the \
conversion in %MethodCode. Alternatively if that is a common situation in your API \
then consider defined a mapped type.<br> <br>
If numpy arrays support the buffer protocol then you should look at exploiting that. \
You should also look at sip.array and sipConvertToArray().<br> <span \
class="HOEnZb"><font color="#888888"><br> \
Phil</font></span></blockquote></div><br></div>


[Attachment #6 (text/plain)]

_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
https://www.riverbankcomputing.com/mailman/listinfo/pyqt

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic