[Pyrex] Dynamic arrays in Pyrex

Simon Frost sdfrost at ucsd.edu
Wed Jun 4 19:55:11 CEST 2003


Dear Pyrex List,

A quick (probably stupid) question as I'm a newbie. Can anyone let me know 
the syntax for allocating and setting a dynamically sized array? Take, for 
example, the primes example packaged with Pyrex:

def primes(int kmax):
cdef int n, k, i
cdef int p[1000]
result = []
if kmax > 1000:
kmax = 1000
k = 0
n = 2
while k < kmax:
i = 0
while i < k and n % p[i] <> 0:
i = i + 1
if i == k:
p[k] = n
k = k + 1
result.append(n)
n = n + 1
return result

If I want to set the size of p at run-time, what modifications are needed.

TIA
Simon





More information about the Pyrex mailing list