BUG: Fix/test invalid lwork param in qr

Fixes `lwork` parameter in qr being overwritten by `lwork=-1`. Adds tests for valid and invalid `lwork` parameters.

See issue #4100.