fuzzer.alg.nn.preprocess.line_to_tensor()   A
last analyzed

Complexity

Conditions 2

Size

Total Lines 5
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 2
nop 1
1
import string
2
import torch
3
4
5
all_letters = string.ascii_letters + " .,;'"
6
n_letters = len(all_letters)
7
8
9
def letter_to_index(letter):
10
    return all_letters.find(letter)
11
12
13
def letter_to_tensor(letter):
14
    tensor = torch.zeros(1, n_letters)
15
    tensor[0][letter_to_index(letter)] = 1
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable letter_to_index does not seem to be defined.
Loading history...
16
    return tensor
17
18
19
def line_to_tensor(line):
20
    tensor = torch.zeros(len(line), 1, n_letters)
21
    for li, letter in enumerate(line):
22
        tensor[li][0][letter_to_index(letter)] = 1
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable letter_to_index does not seem to be defined.
Loading history...
23
    return tensor
24