[SciPy-user] Fastest dtype for matrix multiplication
David Cournapeau
david at ar.media.kyoto-u.ac.jp
Sun Oct 21 00:47:31 EDT 2007
Tom Johnson wrote:
> Hi,
>
> I am interested in doing matrix multiplication, but all I really care
> about is if the elements are nonzero or not (after all the
> multiplication is done).
>
> Which dtype should I use to accomplish this in the fastest manner?
>
> I did some quick tests...and it seemed like dtype=bool was quite slow
> (contrary to my expectations). Could someone explain this and
> recommend the best dtype? So far, it seems like float64 is the best.
>
>
When you are using dot (and I guess most of the matrix multiplication
routines), internally, the function can only work on float. BLAS, for
example, only deal with float. For some routines such as multiplication,
it makes sense to use integer, but the implementation would have to be
totally different (for example handling overflow would be quite
different than with float).
So basically, as far as I am aware, all linear algebra only deal with
floating point, and for those, float32 is the fastest, generally. But
then, nonzero is ill defined with floating points (what you want
generally is really near 0), so you will have to take care of that, too.
cheers,
David
More information about the SciPy-User
mailing list