Decomposition fix

This fixes a memory error in decomposition AND adds a whole load of tests to make sure this never happens again.

@ja310 I don't have Matlab, maybe you could cross reference a couple of the results? I have to admit that for the features > samples cases I just copied whatever was output as the result!