Optimized matrix conversion