[Pyrex] Convert tuple/list in primitive*
Tom Jenkins
tjenkins at devis.com
Thu Dec 16 23:39:54 CET 2004
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Charles Moad wrote:
| On Dec 16, 2004, at 4:52 PM, Lenard Lindstrom wrote:
|>>
|>> cdef extern c_setParam3fv "setParam3fv"(int param, float *value)
|>>
|>> def setParam3fv(param, value):
|>> cdef float args[3]
|>> cdef int i
|>>
|>> i = 0
|>> for val in value:
|>> args[i] = val
|>> c_setParam3fv(param, args)
|>>
|>> This works fine and all, but I don't think this is my preferred way
|>> given a large list of floats since the python looping contruct is slow.
|>>
|
| I found the PySequence_Fast method along with related access functions,
| but I have been unable to make it work in pyrex. Is there a example of
| this out there anywhere that uses the better "for i from 0 <= i < n"
| construct?
|
I've successfully used the "for i from 0..." to do something similar to
what the OP wants to do.
in my case i have a structure that has int (partnum) and float (dval)
arrays. this works
...
(cnt is figured out beforehand, _partnum and _dval are python lists)
...
~ for i from 0 <= i <= cnt:
~ params.partnum[i] = _partnum[i]
~ params.dval[i] = _dval[i]
works fine
- --
Tom Jenkins
DevIS - Development Infostructure
http://www.devis.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.0-nr2 (Windows XP)
Comment: Using GnuPG with MultiZilla - http://enigmail.mozdev.org
iD8DBQFBwg66V7Yk9/McDYURAsSTAKCzYCujCS8i2QAQd9FVOSlzo1RA4QCgy5n7
0cevTlxTbdxLna4x53nijaU=
=OfAx
-----END PGP SIGNATURE-----
More information about the Pyrex
mailing list