[Pyrex] array/list of extension type

Tomas Sirny junckritter at matfyz.net
Mon Nov 19 10:06:19 CET 2007


Hello, 
I have class Neuron defined in .pxd and .pyx files. In another pyrex
class Network, i want to have an 'matrix' attribute of Network as list or array of Neurons. Problem is, that when I define Network with cdef, i must define Network's attributes also with cdef and I don't know how to do it with matrix.

cdef class Neuron:
    cdef int y, victories 
    cdef double *wx
    cdef double *wy

    def alfaDistance(self, a): ...
    def betaDistance(self, b): ...

cdef class Network:
    cdef double Alfa, Beta, Gama
    
    def __init__(self, rows, columns, a, b, c):
        self.Alfa = a
	self.Beta = b
	self.Gama = c
	self.matrix = []
	cdef Neuron n
	for i from 0 <= i < self.count:
	    n = Neuron(self.count, size)
	    self.matrix.append(n)

Matrix attribute is used only in methods of Network.
Compilation with pyrex is ok, but when I try to use it from python,
raises error: "AttributeError: 'Network' object has no
attribute 'matrix'", on line whit self.matrix = []. 
Does somebody know how to do this?

Tomas




More information about the Pyrex mailing list