[Pyrex] help with structs and arrays

Tom Jenkins tjenkins at devis.com
Fri Oct 1 00:03:01 CEST 2004


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

hello all,
this is my first attempt at using pyrex beyond wrapping simple function
calls.  I have a struct that is passed around and filled up by a couple
of functions and used by another.

#define MAXPARTCLASSES	500
#define MAXSTRING 120
<snip>
struct genpsd_params {
	char psdkernel[MAXSTRING];
	float res;
	int xsyssize;
	int ysyssize;
	int zsyssize;
	int numdiams;
	float frac[MAXPARTCLASSES+1];
	float dval[MAXPARTCLASSES+1];
	float bias;
};

long int diam2vol(float diameter);
void process_psd(struct genpsd_params *params);
<snip>

======
Here is what I've done:

MAXSTRING = 120
MAXPARTCLASSES = 500

cdef extern from "genpsdpage.h":
	cdef struct genpsd_params:
		char psdkernel[MAXSTRING]
		float res
		int xsyssize
		int ysyssize
		int zsyssize
		int numdiams
		float frac[MAXPARTCLASSES+1]
		float dval[MAXPARTCLASSES+1]
		float bias

	long int diam2vol(float diameter)
	void process_psd(genpsd_params *params)


def diam_to_vol(diameter):
	vol = diam2vol(diameter)
	return vol


class PSD:
	def __init__(self, psdkernel=None, syssize=None, resolution=None):
	<snip setting up>

	def generate():
		<snip some checking code>

		cdef genpsd_params *params
		cdef float curr_dval
		cdef float curr_frac

		params.psdkernel = self.psdkernel
		params.xsyssize = self.syssize
		params.ysyssize = self.syssize
		params.zsyssize = self.syssize
		params.res = self.resolution

		process_psd(params)

		self.numdiams = params.numdiams
		self.dval = []
		for i in range(params.dval):
			curr_dval = params.dval[i]
			self.dval.append(curr_dval)

		self.frac = []
		for i in range(params.frac):
			curr_frac = params.frac[i]
			self.frac.append(curr_frac)

		self.bias = self.bias
		self.generated = 1

========

what i get when running setup is:
running build
running build_ext
building 'genpsdpage' extension
genpsdpage.pyx:10:17: Not allowed in a constant expression
genpsdpage.pyx:10:17: Array dimension not integer
genpsdpage.pyx:16:13: Not allowed in a constant expression
genpsdpage.pyx:16:28: Not allowed in a constant expression
genpsdpage.pyx:16:27: Array dimension not integer
genpsdpage.pyx:17:13: Not allowed in a constant expression
genpsdpage.pyx:17:28: Not allowed in a constant expression
genpsdpage.pyx:17:27: Array dimension not integer
genpsdpage.pyx:46:25: Obtaining char * from temporary Python value
genpsdpage.pyx:56:23: Cannot convert 'float (*)' to Python object
genpsdpage.pyx:61:23: Cannot convert 'float (*)' to Python object


the lines correspond to:
10: char psdkernel[MAXSTRING]
16: float frac[MAXPARTCLASSES+1]
17: float dval[MAXPARTCLASSES+1]
46: params.psdkernel = self.psdkernel
56: for i in range(params.dval):
61: for i in range(params.frac):

If someone could point me in the right direction, I'd really appreciate it.

- --
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

iD8DBQFBXIKVV7Yk9/McDYURAoJ8AJ9fsN8LxFjEwDNp2sxPs9ZzQrqZQACfYfZB
FeoBU/I9Mz2V8XTonfdErY4=
=KR3G
-----END PGP SIGNATURE-----




More information about the Pyrex mailing list