Contextual Inverse Optimization: Offline and Online Learning