BUG: optimize: fix botched test for scalars

Any row-vector or other ndarray with shape[0] == 1 was passed through.
It'd be nice to get back the error about original version of this PR, just to make it clear where the issue lies. @larsmans could you look into this?