# AUTOGENERATED! DO NOT EDIT! File to edit: 02_utils.ipynb (unless otherwise specified).

__all__ = ['DATA_DIRECTORY', 'CUT_LENGTH', 'DEVICE', 'text_to_id', 'id_to_text']

# Cell
from pathlib import Path
import torch

# Cell
try:
    ROOT = (Path(__file__) / "..").resolve()
except NameError: # in a jupyter notebook
    ROOT = Path("./nnsplit").resolve()

DATA_DIRECTORY = ROOT / "data"

# Cell
CUT_LENGTH = 100
DEVICE = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")

# Cell
def text_to_id(char):
    x = ord(char)
    return x + 2 if x <= 127 else 1

def id_to_text(x):
    return chr(x - 2) if (x - 2) <= 127 and x > 1 else "X"