optimize: handle matrix objects as initial guess (ticket #1770)

TNC and MINPACK solvers do not handle `numpy.matrix` objects as initial guess correctly.
- updated the tests to introduce `matrix` here and there
- use `flatten()` as it is done in other solvers.