Convex and Non-convex Optimization Under Generalized Smoothness