|
|
|
|
|
by ptfoobar
4377 days ago
|
|
Second example say you want to compute (x + y) * z - w where each of them are long vectors but want to keep the look of the code readable and explicit. Naive way to do it will create lots of temporaries and unnecessary loops. Every binary operation is going to create a temporary (and entail a loop). But if you have laziness you just need one loop. Can you elaborate on this? Why can laziness provide better code here? |
|
A better way to do all that would be to allocate a single result vector and populate it with the full computed expression for each element. This can be much faster for large vectors. Python's numexpr (among others) is designed to do just this.