matmul and matinv 2nd order test + fix 'optimize' issue