[racket] Optimizations at the library level.

From: Patrick Li (patrickli.2001 at gmail.com)
Date: Tue Aug 31 11:22:43 EDT 2010

Hi everyone,
I would like to be able to provide optimizations for my library based on how
it's used, but don't know how to go about doing it.

I have a function called (matrix-multiply A B)
and another function called (matrix-transpose A)
which are fundamental linear algebra operations.

A very common usage is:
(matrix-multiply (matrix-transpose A) B)

However, to take the transpose of a matrix first, and then perform the
multiplication is inefficient. It unnecessarily reorders the matrix A, when
in fact it could just iterate over the elements of A in a different order
during the multiplication.

So one solution is to create another function:
(matrix-transpose-multiply A B)    which is equivalent to   (matrix-multiply
(matrix-transpose A) B)

But this starts to clutter up the library. Is it possible to provide this
optimization at the library level for the users? eg. somehow recognize that
whenever the user writes (matrix-transpose-multiply A B)  I can replace it
with the internal function (matrix-transpose-multiply* A B)?

and (let ([AT (matrix-transpose A)) (matrix-multiply AT B))   with
 (matrix-transpose-multiply* A B)

What I'm essentially looking for is an organized way of providing these
small specific optimizations to the user.
I would like to know if such a feature exists and what it's called if it
does. If it doesn't exist, do people think it *could* possibly exist or is
it theoretically inconsistent?

Thanks for the help
  -Patrick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20100831/d6d5fb52/attachment.html>

Posted on the users mailing list.