Python and generic programming
someone at microsoft.com
Sun Nov 21 01:25:03 CET 2004
I take it the ampersand is a neologism in 2.4?
jdadson at yahoo dott com
"Ian Bicking" <ianb at colorstudy.com> wrote in message
news:mailman.6643.1100939117.5135.python-list at python.org...
> Jive Dadson wrote:
> > If you have, for example, several data-types for matrices, how do you
> > write code that will automatically find the right routine for quickly
> > multiplying a vector by a diagonal matrix represented as a vector, and
> > automatically call the right code for multiplying by a sparse matrix
> > represented by some sparse coding, etc?
> I haven't been following this thread, but Phillip Eby's recent
> implementation of generic functions should be mentioned if it hasn't
> been already:
> It might look something like this:
> @dispatch.on('m1', 'm2')
> def matrix_mul(m1, m2):
> "Multiply two matrices"
> @matrix_mul.when(VectorMatrix, SparseMatrix)
> def matrix_mul_sparse(m1, m2):
> "Special implementation"
> Ian Bicking / ianb at colorstudy.com / http://blog.ianbicking.org
More information about the Python-list