[Pyrex] array/list of extension type

Robert Kern robert.kern at gmail.com
Mon Nov 19 10:20:24 CET 2007


Tomas Sirny wrote:
> 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?

cdef object matrix

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco




More information about the Pyrex mailing list