473,395 Members | 1,458 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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.NumArray [object PyArrayObject]:
ValueError: numarray.NumArray 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.NumArray [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(GLenum 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_DIFFUSE))\
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_params
glMaterialfv(face, 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 1969
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.NumArray [object PyArrayObject]:
ValueError: numarray.NumArray does not appear to be the correct type
object


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

ctypedef class numarray._numarray._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_ENDIAN
cdef char _aligned # test override flag
cdef char _contiguous # test override flag

cdef extern from "numarray/libnumarray.h":
void import_libnumarray()
object NA_NewAll(
int ndim, maybelong* shape, NumarrayType type, void* buffer,
maybelong byteoffset, maybelong bytestride, int byteorder, int aligned, int writeable )
object NA_NewAllStrides(
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_FromDims(int nd, int *d, int type)
object NA_updateDataPtr(object)
object NA_getPythonScalar(object, long)
object NA_setFromPythonScalar(object, int, object)
#object NA_getPythonScalar(PyArrayObject, long)
#object NA_setFromPythonScalar(PyArrayObject, int, PyArrayObject)

object PyArray_ContiguousFromObject(object op, int type,
int min_dim, int max_dim)
#cdef void*NA_OFFSETDATA(object)
void*NA_OFFSETDATA(_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(NA_InputArray(odata, 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(NA_InputArray(odata, 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**********@graf.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_libnumarray(), 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
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...
3
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...
10
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...
3
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...
0
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...
0
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...
27
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
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
by: robert | last post by:
just a note - some speed comparisons : 0.60627370238398726 0.42836673376223189 0.36965815487747022 0.016557970357098384 0.15692469294117473 0.01951756438393204
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
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...
0
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...

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.