[Pyrex] array/list of extension type
Tomas Sirny
junckritter at matfyz.net
Tue Nov 20 15:44:50 CET 2007
Hello, thanks for answers.
Defining matrix as object works, but everytime I want to call method of
Neuron as matrix[i], I must explicitly cast it with <Neuron>. So, how
can I make it c array? To be concrete, how to define it? All methods of
Neuron are c functions(cdef ...).
Tomas
On Mon, Nov 19, 2007 at 03:20:24AM -0600, Robert Kern wrote:
> 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
>
>
> _______________________________________________
> Pyrex mailing list
> Pyrex at lists.copyleft.no
> http://lists.copyleft.no/mailman/listinfo/pyrex
More information about the Pyrex
mailing list