Replace numpy with math for scalar functions and remove Dfun from ellipse residuals for speedup