deads / scipy-cluster

Automatically exported from code.google.com/p/scipy-cluster
Other
0 stars 0 forks source link

"built-in" functions don't work with pdist() #34

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
When you give pdist() a function (instead of a string), it confirms this by 
checking that it's a "types.FunctionType". However, it is useful to be able to 
provide a c-compiled function, which has type "types.BuiltinFunctionType".
Therefore, I suggest that

    if mtype is types.FunctionType:

(on line 1079 in distance.py in revision 132) should be changed to :

    if mtype in (types.FunctionType, types.BuiltinFunctionType):

or even

    if hasattr(metric, '__call__'):

so as to allow any callable.

Original issue reported on code.google.com by jos...@hoersport.de on 10 Feb 2011 at 4:17