osdir.com
mailing list archive

Subject: error in ctypes [example from the numpy book]? - msg#00073

List: python.ctypes

Date: Prev Next Index Thread: Prev Next Index
i am attempting to reproduce a portion of the example on using ctypes from the current version of the numpy book (the example can be found on pps 313-16). 
 
here is what i am trying to do: 
 
>>>import numpy 
>>>import interface 
 
>>>x = numpy.array(range(1,1)) 
>>>y = numpy.ones_like(x) 
>>>z = interface.add(a,b) 
 
prints the following error: 
BEGIN ERROR>> 
26 b = N.require(b, dtype, requires) 
27 c = N.empty_like(a) 
---> 28 func(a,b,c,a.size) 
29 return c 
30 
 
ArgumentError: argument 1: exceptions.TypeError: Don't know how to convert parameter 1 
<<END ERROR 
 
Here are the relevant bits of code I am using (since I have not just copied the entire text from the example): 
 
BEGIN testAddInt.c >> 
/* Add arrays of contiguous data */ 
typedef struct {double real;} cdouble; 
typedef struct {float real;} cfloat; 
 
void dadd(double *a, double *b, double *c, long n) 

while (n--) { 
*c++ = *a++ + *b++; 


void sadd(float *a, float *b, float *c, long n) 

while (n--) { 
*c++ = *a++ + *b++; 


 
<<END testAddInt.c 

i then compiled testAddInt.c with "gcc -o testAddInt.so -shared testAddInt.c" and wrote the following interface code: 
BEGIN interface.py>> 
 
__all__ = ['add'] 
 
import numpy as N 
from ctypes import * 
import os 
 
_path = os.path.dirname('__file__') 
 
lib = N.ctypeslib.ctypes_load_library('testAddInt', _path) 
 
for name in ['sadd','dadd']: 
getattr(lib,name).restype=None 
 
def select(dtype): 
if dtype.char in['?bBhHf']: 
return lib.sadd, single 
else: 
return lib.dadd, float 
return func, ntype 
 
def add(a,b): 
requires = ['CONTIGUOUS','ALIGNED'] 
a = N.asanyarray(a) 
func, dtype = select(a.dtype) 
a = N.require(a, dtype, requires) 
b = N.require(b, dtype, requires) 
c = N.empty_like(a) 
func(a,b,c,a.size) 
return c 
<<END interface.py

any hints/clues/suggestions as to what i am doing wrong here? since i am so new at this, i am assuming there is a simple mistake in what i am doing, but i cannot find it! thanks so much, 
 
bryan -------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642_______________________________________________
ctypes-users mailing list
ctypes-users@xxxxxxxxxxxxxxxxxxxxx
https://lists.sourceforge.net/lists/listinfo/ctypes-users
Was this page helpful?
Yes No
Thread at a glance:

Previous Message by Date: click to view message preview

Re: ctypes and ARM

As Luke said, I'm sure you mean non-WinCE ARM devices. ;) We are looking at developing on the Maemo[1] platform using a Nokia 770[2] device. It's a pretty neat embedded development platform. You basically have virtualized linux installations on a development box, and they can either run natively, or you can run them on a virtualized processor using Qemu. The really nice part is that you can switch between them easily. It's a slick device. :) .. _1: http://maemo.org/ .. _2: http://www.nokiausa.com/770/ On Aug 25, 2006, at 05:41, Thomas Heller wrote: > ctypes doesn't yet support ARM which has been mentioned several > times. I'm wondering > what would be needed to port ctypes to the ARM architecture: > > A sharp zaurus? If so, which device should I get? Is a SL-5500 > sufficient? How > does one develop on/for such a device? Can one compile Python ob > such a thing, > or does one cross compile under Linux? > > Are there emulators which can emulate an ARM/Linux platform? Does > one use Linux > at all, or a BSD variant? > > Thanks, > Thomas ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642

Next Message by Date: click to view message preview

Re: subclassing c_long?

thanks, i will look into _as_parameter_ and from_param! http://docs.python.org/dev/lib/ctypes-return-types.htmland for restype i could use a callable like described here at the bottom? On 8/28/06, Mark McMahon <mark.mcmahon@xxxxxxxxxxxxxxxx> wrote: Hi Horace,   would using _as_parameter_ work for you?   So you would create a class whose instances will have an _as_parameter_ member variable.   Not sure when you would assign the value to this member, but once you do it - it will be used for passing to functions by ctypes.   Mark From: ctypes-users-bounces@xxxxxxxxxxxxxxxxxxxxx [mailto:ctypes-users-bounces@xxxxxxxxxxxxxxxxxxxxx] On Behalf Of horaceSent: Saturday, August 26, 2006 6:20 AMTo: ctypes-users@xxxxxxxxxxxxxxxxxxxxxSubject: [ctypes-users] subclassing c_long? hi,i work on a wrapper for a 3d engine which uses fixed point variables.so far i have a lot fixed<->long conversions at a lot of places in my script.for example int to fixed: i<<10fixed to int: i>>10 ...i think a lot more elegant solution would be to subclass c_long and add the conversion there somehow. is this possible? how would i do this? could someone please give me a short code snippet? ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642_______________________________________________ ctypes-users mailing list ctypes-users@xxxxxxxxxxxxxxxxxxxxx https://lists.sourceforge.net/lists/listinfo/ctypes-users

Previous Message by Thread: click to view message preview

variable lenght structures

Hello Thomas Just an idea that occured to me yesterday regarding variable length structures. Maybe it's stupid, maybe not. As far as I remember the first thing I was looking for when having to deal with these types of structures was something like Structure.addressof('field-name'). class V(Structure): _filds_ = [('a', POINT*1)] v = V() arr = (POINT*N).from_address(v.addressof('a')) arr = (POINT*10)() arr2 = (POINT*2).from_address(arr.addressof(5)) Looks nice and clean somehow... Jürgen ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642

Next Message by Thread: click to view message preview

Re: error in ctypes [example from the numpy book]?

W. Bryan Smith schrieb: > i am attempting to reproduce a portion of the example on using ctypes from > the current version of the numpy book (the example can be found on pps > 313-16). I do not really understand your code, and my numpy-book only has 297 pages (Guide to NumPy, June 15, 2006). Have you asked on the numpy list? Thomas ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
Sign up for updates to this mailing list. email:
Loading Comments...
Home | News | Patents | Sitemap | FAQ | advertise

Advertising by