-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtasks.py
More file actions
40 lines (32 loc) · 828 Bytes
/
Copy pathtasks.py
File metadata and controls
40 lines (32 loc) · 828 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from __future__ import unicode_literals, print_function, division
from io import open
import unicodedata
import string
import re
import random
from random import shuffle
import torch
import torch.nn as nn
from torch.autograd import Variable
from torch import optim
import torch.nn.functional as F
import sys
import os
import time
import math
import pickle
# Provide the predefined digit sequence tasks
def interleaved(sequence):
if len(sequence) <= 1:
return list(sequence)
else:
return [sequence[0], sequence[-1]] + interleaved(sequence[1:-1])
def transform(sequence, task):
if task == "auto":
return sequence
if task == "rev":
return sequence[::-1]
if task == "sort":
return sorted(sequence)
if task == "interleave":
return interleaved(sequence)