optimize matrix inverse