def apply_list(self, zmin, zmax, ns, evaluation): 'RandomComplex[{zmin_, zmax_}, ns_]' expr = Expression('RandomComplex', Expression('List', zmin, zmax), ns) if Expression('RealNumberQ', zmin).evaluate(evaluation): zmin = Complex(zmin, 0.0) if Expression('RealNumberQ', zmax).evaluate(evaluation): zmax = Complex(zmax, 0.0) if not (isinstance(zmin, Complex) and isinstance(zmax, Complex)): return evaluation.message('RandomComplex', 'unifr', Expression('List', zmin, zmax)) min_value, max_value = zmin.to_python(), zmax.to_python() py_ns = ns.to_python() if not isinstance(py_ns, list): py_ns = [py_ns] if not all([isinstance(i, int) and i >= 0 for i in py_ns]): return evaluation.message('RandomComplex', 'array', ns, expr) with RandomEnv(evaluation) as rand: def search_product(i): if i == len(py_ns) - 1: return Expression('List', *[ Complex( rand.randreal(min_value.real, max_value.real), rand.randreal(min_value.imag, max_value.imag) ) for j in range(py_ns[i])]) else: return Expression('List', *[ search_product(i + 1) for j in range(py_ns[i])]) return search_product(0)
def apply_list(self, zmin, zmax, ns, evaluation): 'RandomComplex[{zmin_, zmax_}, ns_]' expr = Expression('RandomComplex', Expression('List', zmin, zmax), ns) if Expression('RealNumberQ', zmin).evaluate(evaluation): zmin = Complex(zmin, 0.0) if Expression('RealNumberQ', zmax).evaluate(evaluation): zmax = Complex(zmax, 0.0) if not (isinstance(zmin, Complex) and isinstance(zmax, Complex)): return evaluation.message('RandomComplex', 'unifr', Expression('List', zmin, zmax)) min_value, max_value = zmin.to_python(), zmax.to_python() py_ns = ns.to_python() if not isinstance(py_ns, list): py_ns = [py_ns] if not all([isinstance(i, int) and i >= 0 for i in py_ns]): return evaluation.message('RandomComplex', 'array', ns, expr) with RandomEnv(evaluation) as rand: real = rand.randreal(min_value.real, max_value.real, py_ns) imag = rand.randreal(min_value.imag, max_value.imag, py_ns) return instantiate_elements(stack_along_inner_axis([real, imag]), lambda c: Complex(*c), d=2)
def apply_list(self, zmin, zmax, ns, evaluation): 'RandomComplex[{zmin_, zmax_}, ns_]' expr = Expression('RandomComplex', Expression('List', zmin, zmax), ns) if Expression('RealNumberQ', zmin).evaluate(evaluation): zmin = Complex(zmin, 0.0) if Expression('RealNumberQ', zmax).evaluate(evaluation): zmax = Complex(zmax, 0.0) if not (isinstance(zmin, Complex) and isinstance(zmax, Complex)): return evaluation.message('RandomComplex', 'unifr', Expression('List', zmin, zmax)) min_value, max_value = zmin.to_python(), zmax.to_python() py_ns = ns.to_python() if not isinstance(py_ns, list): py_ns = [py_ns] if not all([isinstance(i, int) and i >= 0 for i in py_ns]): return evaluation.message('RandomComplex', 'array', ns, expr) with RandomEnv(evaluation) as rand: def search_product(i): if i == len(py_ns) - 1: return Expression('List', *[ Complex( rand.randreal(min_value.real, max_value.real), rand.randreal(min_value.imag, max_value.imag) ) for j in range(py_ns[i])]) else: return Expression('List', *[ search_product(i + 1) for j in range(py_ns[i])]) return search_product(0)
def apply(self, zmin, zmax, evaluation): "RandomComplex[{zmin_, zmax_}]" if Expression("RealNumberQ", zmin).evaluate(evaluation): zmin = Complex(zmin, 0.0) if Expression("RealNumberQ", zmax).evaluate(evaluation): zmax = Complex(zmax, 0.0) if not (isinstance(zmin, Complex) and isinstance(zmax, Complex)): return evaluation.message("RandomComplex", "unifr", Expression("List", zmin, zmax)) min_value, max_value = zmin.to_python(), zmax.to_python() with RandomEnv(evaluation) as rand: return Complex(rand.randreal(min_value.real, max_value.real), rand.randreal(min_value.imag, max_value.imag))
def apply(self, zmin, zmax, evaluation): 'RandomComplex[{zmin_, zmax_}]' if Expression('RealNumberQ', zmin).evaluate(evaluation): zmin = Complex(zmin, 0.0) if Expression('RealNumberQ', zmax).evaluate(evaluation): zmax = Complex(zmax, 0.0) if not (isinstance(zmin, Complex) and isinstance(zmax, Complex)): return evaluation.message('RandomComplex', 'unifr', Expression('List', zmin, zmax)) min_value, max_value = zmin.to_python(), zmax.to_python() with RandomEnv(evaluation) as rand: return Complex(rand.randreal(min_value.real, max_value.real), rand.randreal(min_value.imag, max_value.imag))