On Fri, Mar 13, 2009 at 2:39 PM, Stefan Behnel <stefan...@behnel.de> wrote: >> >> comm = MPI.Comm(MPI.COMM_WORLD) >> assert comm is MPI.COMM_WORLD >> >> and the assertion will succeed... > > Am I right in guessing that Comm is an extension type here and that > COMM_WORLD is an instance? >
Yes, you are right... > So you want to use Comm as both a class and a factory, right? So, what was > your use case again? > MPI.COMM_WORLD is a predefined, immutable, live-forever instance of a class 'Intracomm', a derived class of 'Comm'. Comm should be seen as an abstract base class in C++ terms... Comm is a class, but it is also a factory in the sense that if you call Comm(comm) it returns a new Comm instance referencing the underlying C handle... in mpi4py, all cdef classes are actually proxies to C handles.... I would like to maintain if possible this invariant... if the C handle is MPI_COMM_WORLD (the C side name), then the Python-level instance is always MPI.COMM_WORLD .... > >> Moreover, any cdef class whose instances are intended to be immutable >> (like int, str, float, tuple) could benefit from this feature, such in >> the same way that core CPython does. > > Here, I assume you are hinting towards singletons and caching, right? lxml > actually does this with dedicated factories, but I can see that some APIs > may benefit from such a behaviour. > At least singletons... In all the above discussion, MPI.COMM_WORLD is similar to a singleton, I do not really know how to call it :-) > So, can't we just require that ExtType.__new__() returns an instance of > ExtType (or its subtypes)? As a first approach, it could be like that... ? Or is there a use case that would benefit from > returning arbitrary things? > Well, Python supports this, we could in case it is possible.... > Stefan > > _______________________________________________ > Cython-dev mailing list > Cython-dev@codespeak.net > http://codespeak.net/mailman/listinfo/cython-dev > -- Lisandro Dalcín --------------- Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC) Instituto de Desarrollo Tecnológico para la Industria Química (INTEC) Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET) PTLC - Güemes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 _______________________________________________ Cython-dev mailing list Cython-dev@codespeak.net http://codespeak.net/mailman/listinfo/cython-dev