def format(x): """List of vertices. Then convex or not. Then integer for sizes.""" # flatten vertices, then reshape into points temp = [np.reshape(clip(flatten(x[0]), float), (-1, 2))] + \ clip(x[1:3], int, 0, [1, 500]) if len(temp[0]) < 3: return [] return temp
def apply(self, coords): """Compute polar/spherical coordinate arrays and apply function.""" formula, ind = self.update(self.params) dim = len(coords[0]) cylindrical = ind < 0 skip = range(dim) if dim == 3: # north pole direction for spherical/cylindrical coordinates north = clip(abs(ind), int, 1, 3)-1 del skip[north] # r and theta dimensions as complex rtheta = coords[:, skip[0]] + coords[:, skip[1]] * 1j theta = np.angle(rtheta) r = np.absolute(rtheta) eta = 0 if dim == 3: h = coords[:, north] eta = np.arctan2(r, h) if cylindrical: eta = h else: r = np.sqrt(r**2+h**2) if cylindrical: coords[:, skip] = np.nan_to_num(np.transpose( np.transpose(coords[:, skip]) * formula(r, theta, eta))) else: coords = np.nan_to_num(np.transpose(np.transpose(coords) * formula(r, theta, eta))) return coords
def format(x): """Up to 4, or 9 floats.""" x = flatten(x) if len(x) < 9: x = x[:4] else: x = x[:9] return clip(x, float)
def format(x): """Function, then an integer. """ print x radius = "lambda theta: {}".format(x[0]) try: evaluate(radius)[0](0) evaluate(radius)[0](np.pi) except: return [] return [radius] + clip(np.fabs(x[1:2]), int, 1, 1000)
def format(x): """Two floats. Then at least one function. Finally an integer. """ x = flatten(x) if len(x) < 3: return [] domain = sorted(clip(x[:2], float)) import re var = 'x' if re.search(r'\bx\b', ''.join(x[2:4])) else 'y' top = "lambda {}: {}".format(var, x[2]) if len(x) == 3: bottom = "lambda {}: -({})".format(var, x[2]) else: bottom = "lambda {}: {}".format(var, x[3]) try: evaluate(top)[0](domain[0]) evaluate(bottom)[0](domain[0]) except: return [] return domain + [top, bottom, var] + clip(np.fabs(x[4:5]), int, 1, 1000)
def format(x): """One integer with a lower bound. Then a positive float up to 0.99. """ return clip(np.fabs(x[:1]), int, 3) + \ clip(np.fabs(x[1:2]), float, 0.001, 0.999)
def format(x): """Two nonnegative integers. Then integer between 0 and 2.""" return clip(x[:2], int, 1) + clip(x[2:3], int, 0, 2)
def format(x): """Based on kites.""" return [1] + clip(abs(tan(x[0] / 2)), float, 0.001)
def format(x): """Based on the general triangle.""" return [1] + clip(abs(tan(x[0])), float, 0.001, 1)
def format(x): """Two positive floats, then three ints.""" return clip(np.fabs(x[:2]), float, 0.0001) + clip(x[2:4], int, 1) + \ clip(x[4:5], int, 0, 2)
def format(x): """Two integers with lower bounds.""" return clip(x[:2], int, [3, 2])
def format(x): """Three positive integers.""" return clip(x[:3], int, 1)
def format(x): """Which pair. Then which one of the two. The two floats for angles.""" return clip(x[:2], int, [-1, 0], [4, 1]) + clip(x[2:4], float, 2.001)
def format(x): """One float. Then positive float.""" return clip(x[:1], float) + clip(np.fabs(x[1:2]), float, 0.0001)
def format(x): """Two lists of floats.""" return [clip(x[0], float), clip(x[1], float)]
def format(x): """Three positive floats. Then three positive integers.""" return clip(x[:3], float, 0.0001) + clip(x[3:6], int, 1)
def format(x): """Free function input. Then an integer.""" return [x[0]] + clip(x[1:2], int, 1, 3)
def format(x): """One positive float.""" return clip(x[:1], int, 1, 30)
def format(x): """One integer with a lower bound.""" return clip(x[:1], int, 3)
def format(x): """Positive integer. The positive float. Then two floats.""" return clip(x[:1], int, 1) + clip(np.fabs(x[1:2]), float, 0.0001) + \ clip(x[2:4], float)
def format(x): """Five floats. Second and fifth positive.""" return clip(x[:1], float) + clip(np.fabs(x[1:2]), float, 0.0001) + \ clip(x[2:4], float) + clip(np.fabs(x[4:5]), float, 0.0001)
def format(x): """One positive float.""" return clip(np.fabs(x[:1]), float, 0.003)
def format(x): """Three floats.""" return clip(x[:3], float)
def format(x): """Two positive floats. Then integer from 1,2,3.""" return clip(np.fabs(x[:2]), float, 0.01) + clip(x[2:3], int, 1, 3)
def format(x): """Four floats.""" return clip(x[:4], float)