###################################
## EDIT HERE, NOT AUTOGENERATED! ## 
###################################
#------------------------------------
# Python

import math, itertools, functools, copy, asyncio, time, importlib, datetime, importlib, \
        os, dataclasses, platform, sys, subprocess, pathlib, ast, weakref, enum, abc, \
        typing, random

from datetime import datetime
from PIL import Image
from dataclasses import dataclass, asdict, is_dataclass
from typing import Union, Optional, TypeVar, Callable, Any, List, Tuple, Iterable, Sequence


import numpy as np
np.set_printoptions(edgeitems=40, linewidth=200, formatter=dict(float=lambda x: "%.3g" % x))

import scipy
import matplotlib.pyplot as plt

#------------------------------------
# PyTorch

import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.utils.data import DataLoader, TensorDataset

torch.set_printoptions(linewidth=200)

#------------------------------------
# Runtime

def in_colab():
    "Check if the code is running in Google Colaboratory"
    try:
        from google import colab
        return True
    except: return False

def in_notebook():
    "Check if the code is running in a jupyter notebook"
    if in_colab(): return True
    try:
        shell = get_ipython().__class__.__name__
        if shell == 'ZMQInteractiveShell': # Jupyter notebook, Spyder or qtconsole
            import IPython
            #IPython version lower then 6.0.0 don't work with output you update
            return IPython.__version__ >= '6.0.0'
        elif shell == 'TerminalInteractiveShell': return False  # Terminal running IPython
        else: return False  # Other type (?)
    except NameError: return False      # Probably standard Python interpreter

IN_NOTEBOOK = in_notebook()

if IN_NOTEBOOK: 
    from tqdm.notebook import trange, tqdm
else: 
    from tqdm import trange, tqdm

#------------------------------------
# Python commons

from inspect import isfunction, ismethod

def exists(val): 
    return val is not None

def not_exists(val): 
    return val is None

def default(val, default_value):
    if exists(val): 
        return val
    return default_value() if isfunction(default_value) else default_value

#------------------------------------
# Fail-safe

if not IN_NOTEBOOK:
    def display(*args, **kwargs):
        pass

