osdir.com
mailing list archive

Subject: Re: array/list of extension type - msg#00078

List: python.pyrex

Date: Prev Next Index Thread: Prev Next Index
Tomas Sirny wrote:
> 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?

You can't. Pyrex doesn't allow object references as elements of
a C array or struct, because it wouldn't be able to keep track
of the reference counts.

You don't need an explict cast, though, if you do something like

cdef Neuron n
n = matrix[i]
...do something with n...

--
Greg


Was this page helpful?
Yes No
Thread at a glance:

Previous Message by Date: click to view message preview

Re: major cimport problems - attachment

I wrote: Here's a very minimal example with the structure you outlined. Sorry, I forgot to attach the file. -- Greg dvedit_example.zip Description: Zip archive _______________________________________________ Pyrex mailing list Pyrex@xxxxxxxxxxxxxxxxx http://lists.copyleft.no/mailman/listinfo/pyrex

Next Message by Date: click to view message preview

Re: extending a builtin type

Robin Becker wrote: > class ObjectList(list): > > I'm wondering how I can convert this to pyrex? You should be able to declare list as an external extension type and then use it as a base class. Something like cdef extern from "listobject.h": ctypedef class __builtin__.list [object PyListObject]: pass cdef class ObjectList(list): ... -- Greg

Previous Message by Thread: click to view message preview

Re: array/list of extension type

Tomas Sirny wrote: > 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 ...). You can do this: cdef Neuron neuron neuron = matrix[i] neuron.doSomething() Stefan

Next Message by Thread: click to view message preview

Re: array/list of extension type

Tomas Sirny wrote: > 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 Network: > cdef double Alfa, Beta, Gama Add this line: cdef object matrix -- Greg
Sign up for updates to this mailing list. email:
Loading Comments...
Home | News | Patents | Sitemap | FAQ | advertise

Advertising by