Reduce the number of allocation/reuse allocation of ndarray #1943

#1943 
@nouiz 

Hey, Fred, this is my draft idea, is the direction right?

If the direction is right, what I wanna do in the future is fill the details, and optimize it to reduce the "if" inside the loop.
outs == ins, this mean the storage is already the same, as they are the same variable. So this make line 906 useless.

Also line 906 should not have a ==.

Make a test case first, this will help you implement this.