473,729 Members | 2,353 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Pyrex and numarray

Hi

I have tried to include numarray in Pyrex but I get allways
this error:

Traceback (most recent call last):
File "gears.py", line 9, in ?
import gl
File "/home/marco/projects/test_pyrex/gl.pyx", line 40, in gl
ctypedef class numarray.NumArr ay [object PyArrayObject]:
ValueError: numarray.NumArr ay does not appear to be the correct type object

The code is:

cdef extern from "numarray/numarray.h":
struct PyArray_Descr:
int type_num, elsize
char type
ctypedef class numarray.NumArr ay [object PyArrayObject]:
cdef char *data
cdef int nd
cdef int *dimensions, *strides
cdef object base
cdef PyArray_Descr *descr
cdef int flags
cdef object _data
cdef object _shadows
cdef long int nstrides
cdef long byteoffset
cdef long bytestride
cdef long itemsize
cdef char byteorder
cdef char _aligned
cdef char _contiguous
cdef char *wptr
def materialfv(GLen um face, GLenum pname, NumArray params):
"""
Set the material.

materialfv(enum face, enum pname, params)

params - should be a tuple

"""
assert (len(params) == 4 and pname in \
(AMBIENT, DIFFUSE, SPECULAR, EMISSION, AMBIENT_AND_DIF FUSE))\
or (len(params) == 1 and pname == SHININESS) \
or (len(param) == 1 and pname == COLOR_INDEXES), \
"arguments are not right"
str_params = params.tostring ()
print str_params
cdef float* flat_params
flat_params = <float*>str_par ams
glMaterialfv(fa ce, pname, flat_params)

I write a little OpenGL wrapper of my own(I know PyOpenGL but it doesn't fit
to me). Now I try to get the numarray to this function and cast it to a
float pointer(ugly hack, will be cleaned later).

regards

Marco

Jul 18 '05 #1
4 1985
On Mon, 19 Jan 2004 19:33:28 +0100, Marco Bubke wrote:
Hi

I have tried to include numarray in Pyrex but I get allways this error:

Traceback (most recent call last):
File "gears.py", line 9, in ?
import gl
File "/home/marco/projects/test_pyrex/gl.pyx", line 40, in gl
ctypedef class numarray.NumArr ay [object PyArrayObject]:
ValueError: numarray.NumArr ay does not appear to be the correct type
object


Yes, i had that problem. Here is what I'm using now:

ctypedef class numarray._numar ray._numarray [object PyArrayObject]:
# Compatibility with Numeric
cdef char *data
cdef int nd
#cdef int dimensions[MAXDIM], strides[MAXDIM]
cdef int *dimensions, *strides
cdef object base
cdef PyArray_Descr *descr
cdef int flags
# New attributes for numarray objects
cdef object _data # object must meet buffer API
cdef object _shadows # ill-behaved original array.
cdef int nstrides # elements in strides array
cdef long byteoffset # offset into buffer where array data begins
cdef long bytestride # basic seperation of elements in bytes
cdef long itemsize # length of 1 element in bytes
cdef char byteorder # NUM_BIG_ENDIAN, NUM_LITTLE_ENDI AN
cdef char _aligned # test override flag
cdef char _contiguous # test override flag

cdef extern from "numarray/libnumarray.h":
void import_libnumar ray()
object NA_NewAll(
int ndim, maybelong* shape, NumarrayType type, void* buffer,
maybelong byteoffset, maybelong bytestride, int byteorder, int aligned, int writeable )
object NA_NewAllStride s(
int ndim, maybelong* shape, maybelong* strides, NumarrayType type, void* buffer,
int byteorder, int byteoffset, int aligned, int writeable )
object NA_New( void* buffer, NumarrayType type, int ndim,... )
object NA_Empty( int ndim, maybelong* shape, NumarrayType type )
object NA_NewArray( void* buffer, NumarrayType type, int ndim, ... )
object NA_vNewArray( void* buffer, NumarrayType type, int ndim, maybelong *shape )

object NA_InputArray (object, NumarrayType, int)
object NA_OutputArray (object, NumarrayType, int)
object NA_IoArray (object, NumarrayType, int)
object PyArray_FromDim s(int nd, int *d, int type)
object NA_updateDataPt r(object)
object NA_getPythonSca lar(object, long)
object NA_setFromPytho nScalar(object, int, object)
#object NA_getPythonSca lar(PyArrayObje ct, long)
#object NA_setFromPytho nScalar(PyArray Object, int, PyArrayObject)

object PyArray_Contigu ousFromObject(o bject op, int type,
int min_dim, int max_dim)
#cdef void*NA_OFFSETD ATA(object)
void*NA_OFFSETD ATA(_numarray)
int NA_nameToTypeNo (char*)
Simon.

--
Simon Burton, B.Sc.
Licensed PO Box A66
ANU Canberra 2601
Australia
Ph. 02 6249 6940
http://arrowtheory.com

Jul 18 '05 #2
thx

but I need to extract the array to a float*.

I do NA_OFFSETDATA(N A_InputArray(od ata, tFloat64, C_ARRAY)) but this isn't
working because Pyrex says he can't storage it. There is a unknown size. I
only need the pointer tp a C array of floats. Thats all.

ragards

Marco
Jul 18 '05 #3
On Tue, 20 Jan 2004 13:48:42 +0100, Marco Bubke wrote:
thx

but I need to extract the array to a float*.

I do NA_OFFSETDATA(N A_InputArray(od ata, tFloat64, C_ARRAY)) but this isn't
working because Pyrex says he can't storage it. There is a unknown size. I
only need the pointer tp a C array of floats. Thats all.

ragards

Marco


Use a variable?

cdef float* data
array = NA_InputArray( array, natype, C_ARRAY )
data = <float *>NA_OFFSETDATA (array)

Simon.

Jul 18 '05 #4
In article <bu**********@g raf.cs.uni-magdeburg.de>, Marco Bubke wrote:
[snip]

I tried using the set-up with Pyrex, but I'm having trouble
referencing some of the symbols. (I actually put all of it inside the
cdef extern declaration -- maybe I shouldn't have? I couldn't make it
compile otherwise...)

I manage to reference some of the symbols (such as maybelong) but
others trip me up... If I try to define a variable of type
PyArray_Descr gcc crashes, and I'm not sure why. The only thing that
isn't a warning is

na_wrap.c:43: storage size of `__pyx_v_x' isn't known

If I run import_libnumar ray(), Python can't find the symbol. (It does
find libnumarray.so, though.) The same happens when I try to use
NA_InputArray:

symbol NA_InputArray: referenced symbol not found

Why, oh why? :]

--
Magnus Lie Hetland "The mind is not a vessel to be filled,
http://hetland.org but a fire to be lighted." [Plutarch]
Jul 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2991
by: RJS | last post by:
Hi all, I can't get a py2exe compiled app to run with numarray (numarray-0.5.win32- py2.2). Also wxPythonWIN32-2.3.3.1-Py22 and ActivePython-2.2.1-222. In the sample below, commenting out "import numarray" allows the exe to run. Left in, I get "4.exe has generated errors" etc. I'm going around and around and there isn't much on Google. py2exe output is last.
3
1830
by: Alexander Schwaigkofler | last post by:
Hi! I have the following problem with numarray. I read the install.txt manual, but it doesn't already work. OS: Microsoft Windows 2000 python: Python 2.2.3 (#42, May 30 2003, 18:12:08) on win32 numarray: Version 0.7 the output from the installation (by hand) you can see below:
10
2037
by: Kyler Laird | last post by:
I need to submit C/C++ code for a class. (It's not a programming class. The choice of language is inertial. I think that it mostly serves to distract students from the course subject.) I'm fairly fluent with C but it hurts to think about writing in C when Python is *so* much more appropriate for these operations. I'd like to keep my sanity and satisfy the course requirements by programming in Python and converting the code to C. It...
3
1558
by: Mizrandir | last post by:
I'd like to subclass numarray's array. I'd like to add some methods and override others like __init__. I don't know how to do this and haven't found help searching the manual or the web, can someone help? For example imagine I just want to do something as simple as making a subclass "NewClass" with the __init__ method overridden so that the behaviour would be: >>> a = NewClass(2) >>> print a
0
2835
by: Chris Lambacher | last post by:
Hi, I have to do some data manipulation that needs to be fast. I had a generator approach (that was faster than a list approch) which was taking approximately 5 seconds to run both encode and decode. I have done a conversion to pyrex and have gotten it down to about 2 seconds to run both encode and decode. An an excerpt from the pyrex code is included below. My question is, is there a better way to allocate the memory for the...
0
1246
by: andrewfelch | last post by:
Below is the code to/from Boolean arrays and Unsigned integers. On my Pentium 4, functions such as "bitwise_and" are 32 times faster when run on 32-bit integers instead of the entire-byte-consuming-Boolean. Good luck all:-) uint32Mask = numarray.array(, numarray.UInt32) uint32MaskInner = numarray.copy.deepcopy(uint32Mask) uint32MaskInner.shape =
27
3976
by: Julien Fiore | last post by:
Do you wand to install Pyrex on Windows ? Here is a step-by-step guide explaining: A) how to install Pyrex on Windows XP. B) how to compile a Pyrex module. Julien Fiore, U. of Geneva
11
1997
by: Jim Lewis | last post by:
Has anyone found a good link on exactly how to speed up code using pyrex? I found various info but the focus is usually not on code speedup.
0
1996
by: robert | last post by:
just a note - some speed comparisons : 0.60627370238398726 0.42836673376223189 0.36965815487747022 0.016557970357098384 0.15692469294117473 0.01951756438393204
0
8917
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8761
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9426
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9281
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9142
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8148
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4795
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2680
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.