Optimize matrix constructor to avoid extra array allocation

Mikio I was noodling around the matrix code to see if I could optimize a bit the parts used in Spark MLlib. I found one non-trivial optimization that avoids an extra array allocation. I couldn't help fiddling with a few other things, which you can reject.

I'm also checking the appetite for some other optimizations that might involve adding a few more methods to the API (like an "increment value" method, and "self times transpose") but that's for another time.