Hi everyone,<div>I would like to be able to provide optimizations for my library based on how it&#39;s used, but don&#39;t know how to go about doing it.</div><div><br></div><div>I have a function called (matrix-multiply A B)</div>
<div>and another function called (matrix-transpose A)</div><div>which are fundamental linear algebra operations.</div><div><br></div><div>A very common usage is:</div><div>(matrix-multiply (matrix-transpose A) B)</div><div>
<br></div><div>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.</div>
<div><br></div><div>So one solution is to create another function:</div><div>(matrix-transpose-multiply A B)    which is equivalent to   (matrix-multiply (matrix-transpose A) B)</div><div><br></div><div>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)?</div>
<div><br></div><div>and (let ([AT (matrix-transpose A)) (matrix-multiply AT B))   with  (matrix-transpose-multiply* A B)</div><div><br></div><div>What I&#39;m essentially looking for is an organized way of providing these small specific optimizations to the user.</div>
<div><div>I would like to know if such a feature exists and what it&#39;s called if it does. If it doesn&#39;t exist, do people think it *could* possibly exist or is it theoretically inconsistent?</div></div><div><br></div>
<div>Thanks for the help</div><div>  -Patrick</div>