It would not be safe to simply decided to raise the gear in response to an engine failure, as you would have already lost performance, and gear retraction is often a high drag sequence.
Ahhh, I'm confused now.
Gear is ALWAYS raised in a response to an engine failure. That is what the first segment is there for.
Takeoff calculations only deal with engine failures at ONE specific point in time: V1.
If your engine fails before V1, you stop obviously. If it happens AFTER V1, you have
gained performance - not lost performance.
If my engine fails at 200 feet altitude, I had 200 feet more altitude gain with all engines operating. If I forgot to retract the gear for some reason, obviously I would do it at this point to
prevent carrying a loss of performance further into the departure (now my engine failure contingency procedure, not the SID).