def start_python_console(namespace=None, noipython=False, banner=''): """Start Python console binded to the given namespace. If IPython is available, an IPython console will be started instead, unless `noipython` is True. Also, tab completion will be used on Unix systems. """ if namespace is None: namespace = {} try: try: # use IPython if available if noipython: raise ImportError() try: try: from IPython.terminal import embed except ImportError: from IPython.frontend.terminal import embed sh = embed.InteractiveShellEmbed(banner1=banner) except ImportError: from IPython.Shell import IPShellEmbed sh = IPShellEmbed(banner=banner) sh(global_ns={}, local_ns=namespace) except ImportError: import code try: # readline module is only available on unix systems import readline except ImportError: pass else: import rlcompleter readline.parse_and_bind("tab:complete") code.interact(banner=banner, local=namespace) except SystemExit: # raised when using exit() in python code.interact pass
def main(): _ipython_shell = _ipython.InteractiveShellEmbed() _ipython_shell.banner1 = '' _ipython_shell.confirm_exit = False app = App() _ipython_shell() app.__exit__()
def _Main(): options = _ParseArguments() _ConfigureLogging(options.loglevel) self = ControllerClient(options.url, options.username, options.password) from IPython.terminal import embed ipshell = embed.InteractiveShellEmbed(config=embed.load_default_config())(local_ns=locals())
def draw(self): fig, ax = plt.subplots() ax.axis('equal') #ax.set_aspect('equal', adjustable='box') patch = PolygonPatch(self.poly, facecolor='#6699cc', linewidth=2) ax.add_patch(patch) ax.add_collection(mc.LineCollection(self.ridges, linewidths=1)) from IPython.terminal import embed ipshell = embed.InteractiveShellEmbed( config=embed.load_default_config())(local_ns=locals()) #ax.autoscale() ax.margins(0.1) plt.show()
def start_shell(local_ns: Dict = None, banner: str = ''): """Create and immediately drop into a Python shell. If IPython version 5 or greater is available it will be used instead of the built-in python shell. :param local_ns: An optional dict containing the global namespace of the newly created shell. :param banner: An optional banner to render when terminal starts. """ if IPYTHON_SHELL_AVAILABLE: # Don't try to stop IPython from displaying its banner, since # it's different in every major version terminal = embed.InteractiveShellEmbed(user_ns={}) terminal.mainloop(local_ns=local_ns) else: code.interact(banner=banner, local=local_ns)
def _compute_A(self, ts, knots): n = len(ts) - 1 A = np.zeros([n + 3, n + 3]) for i in range(1, n + 2): for j in range(i - 1, i + 2): try: A[i, j] = self._basis_func(j, ts[i - 1], knots) except Exception as e: from IPython.terminal import embed ipshell = embed.InteractiveShellEmbed( config=embed.load_default_config())(local_ns=locals()) for j in range(0, 3): A[0, j] = self._basis_func_2diff(j, ts[0], knots) for j in range(n, n + 3): A[n + 2, j] = self._basis_func_2diff(j, ts[n], knots) return A
def Shell(user_session): # This should bring back the old autocall behaviour. e.g.: # In [1]: pslist cfg = Config() cfg.InteractiveShellEmbed.autocall = 2 cfg.PromptManager.in_template = ( r'{color.LightCyan}' r'{session.state.base_filename}' r'{color.LightBlue}{color.Green} \T> ') cfg.PromptManager.in2_template = ( r'{color.Green}|{color.LightGreen}\D{color.Green}> ') cfg.PromptManager.out_template = r'Out<\#> ' cfg.InteractiveShell.separate_in = '' cfg.InteractiveShell.separate_out = '' cfg.InteractiveShell.separate_out2 = '' shell = embed.InteractiveShellEmbed( config=cfg, user_ns=user_session._locals) shell.Completer.merge_completions = False shell.banner = constants.BANNER shell.exit_msg = constants.GetQuote() shell.set_custom_completer(RekallCompleter, 0) # Do we need to pre-run something? if user_session.run is not None: execfile(user_session.run, user_session._locals) # Workaround for completer bug. import IPython.core.completerlib IPython.core.completerlib.get_ipython = lambda: shell # Set known delimeters for the completer. This varies by OS so we need to # set it to ensure consistency. readline.set_completer_delims(' \t\n`!@#$^&*()=+[{]}\\|;:\'",<>?') shell(local_ns=user_session._locals) return True
import sympy u = sympy.symbols('u') u0, u1, u2, u3, u4 = sympy.symbols('u:5') expr0 = (u - u0)**3 / ((u1 - u0) * (u2 - u0) * (u3 - u0)) expr1 = ((u - u0)**2 * (u2 - u)) / ((u2 - u1)*(u3 - u0)*(u2 - u0)) \ + ((u3 - u) * (u - u0) * (u - u1)) / ((u2 - u1)*(u3 - u1)*(u3 - u0)) \ + (u4 - u) * (u - u1)**2 / ((u2 - u1)*(u4 - u1)*(u3 - u1)) expr2 = ((u - u0) * (u3 - u)**2) / ((u3 - u2)*(u3 - u1)*(u3 - u1)) \ + ((u4 - u) * (u3 - u) * (u - u1)) / ((u3 - u2)*(u4 - u1)*(u3 - u1)) \ + (u4 - u)**2 * (u - u2) / ((u3 - u2)*(u4 - u2)*(u4 - u1)) expr3 = (u4 - u)**3 / ((u4 - u3) * (u4 - u2) * (u4 - u1)) print(sympy.simplify(expr0.diff(u).diff(u))) print(sympy.simplify(expr1.diff(u).diff(u))) print(sympy.simplify(expr2.diff(u).diff(u))) print(sympy.simplify(expr3.diff(u).diff(u))) # 6*(-u + u0)/((u0 - u1)*(u0 - u2)*(u0 - u3)) # 2*((u0 - u2)*(u0 - u3)*(3*u - 2*u1 - u4) + (u0 - u2)*(u1 - u4)*(3*u - u0 - u1 - u3) + (u1 - u3)*(u1 - u4)*(3*u - 2*u0 - u2))/((u0 - u2)*(u0 - u3)*(u1 - u2)*(u1 - u3)*(u1 - u4)) # 2*((u1 - u3)**2*(-3*u + u2 + 2*u4) + (u1 - u3)*(u2 - u4)*(-3*u + u1 + u3 + u4) + (u1 - u4)*(u2 - u4)*(-3*u + u0 + 2*u3))/((u1 - u3)**2*(u1 - u4)*(u2 - u3)*(u2 - u4)) # 6*(u - u4)/((u1 - u4)*(u2 - u4)*(u3 - u4)) from IPython.terminal import embed ipshell = embed.InteractiveShellEmbed(config=embed.load_default_config())( local_ns=locals())
"area": torch.tensor(area), "iscrowd": torch.tensor(is_crowd) } # img, target = self.transforms(img, target) return img, target if __name__ == '__main__': #import transforms as T #transforms = [] #transforms.append(T.ToTensor()) #transforms.append(T.RandomHorizontalFlip(0.5)) #transforms = T.Compose(transforms) import albumentations from albumentations.pytorch.transforms import ToTensorV2 data_transforms = albumentations.Compose([ albumentations.Flip(), #albumentations.RandomBrightness(0.2), albumentations.ShiftScaleRotate(rotate_limit=90, scale_limit=0.10), #albumentations.Normalize(), #albumentations.Resize(512, 512), #ToTensorV2() ], bbox_params=albumentations.BboxParams(format='pascal_voc', label_fields=['class_labels'])) # min_visibility=0.2 #self = DSB('/home/leus/3rdparty/github.com/ompugao/dm6190/2_segmentationreview/data-science-bowl-2018/', image_set="stage1_train", transforms=data_transforms) import preprocess preprocessfn = preprocess.ImagePreProcessor1('./kmeans.pkl') self = DSB('/home/leus/3rdparty/github.com/ompugao/dm6190/2_segmentationreview/data-science-bowl-2018/', image_set="stage1_train", transforms=data_transforms, preprocessfn=preprocessfn) from IPython.terminal import embed; ipshell=embed.InteractiveShellEmbed(config=embed.load_default_config())(local_ns=locals())