Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
179 lines (153 loc) · 6.66 KB
/
Copy pathscript.js
File metadata and controls
179 lines (153 loc) · 6.66 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
// Create Tensor
let variable = document.getElementById("variable");
let value = document.getElementById("value");
let datatype = document.editor.datatype;
let rank = document.getElementById("rank");
const tensor = stat => {
if (variable.value === "") {
return alert("Please enter a variable name in the 'variable' field, in the 'Create Tensor' section.");
} else if (value.value === "") {
return alert("Please enter a comma separated list of integers, floats, or Booleans in the 'value' field, in the 'Create Tensor' section.");
} else {
let keepOne = "";
let keepTwo = "";
let degree = Math.floor(rank.value);
let array = [];
let string = value.value;
let bracket = 0;
if (value.value.includes(",")) {
let trim = value.value.split(/\s*,\s*/);
array = trim.map(el => el.trim());
if (degree > 1) {
let average = array.length / degree;
if (parseInt(average) - average !== 0) {
return alert("Please enter more values in the 'value' field for the selected 'rank' in the 'Create Tensor' section.");
}
let nest = [];
if (average > 0) {
let counter = 0;
while (counter < array.length) {
let string = array.slice(counter, average + counter);
if (datatype.value === "string") {
let join = string.slice();
nest += join.join(",").replaceAll(/\s*,\s*/g, '", "') + '"], ["';
} else {
let join = string.slice();
nest += join.join(",").replaceAll(/\s*,\s*/g, ', ') + '], [';
}
counter += average
}
if (datatype.value === "string") {
string = nest.slice(0, -5).replace(/\s*,\s*/, ", ");
} else {
string = nest.slice(0, -4).replace(/\s*,\s*/, ", ");
}
} else {
return alert("Please enter more values in the 'value' field for the selected 'rank' in the 'Create Tensor' section.");
}
}
}
if (datatype.value === "string") {
if (array.length === 0) {
keepTwo = '"';
}
keepOne = '"';
} else if (datatype.value === "float64" || datatype.value === "int32" || datatype.value === "int16") {
if (Number(value.value) >= 0) {
} else if (array.length > 0) {
if (array.every(el => Number(el))) {
} else {
return alert("Please enter a number for the 'value' field in the 'Create Tensor' section.");
}
}
}
document.editor.textbox.value+= '\n' + variable.value + ' = tf.' + stat + '(' + '['.repeat(degree) + keepOne + string + keepTwo + ']'.repeat(degree) + ', dtype=tf.' + datatype.value + ')';
}
}
// Data at a glance
const data = (stat) => {
if (variable.value === "") {
return alert("Please enter a variable name in the 'Create Tensor' section.");
} else {
document.editor.textbox.value+= '\ntf.' + stat.slice(0, -2) + '(' + document.editor.variable.value + ')';
}
}
const shape = (stat) => {
if (variable.value === "") {
return alert("Please enter a variable name in the 'Create Tensor' section.");
} else {
document.editor.textbox.value+= '\n' + document.editor.variable.value + '.' + stat;
}
}
// Tensor functions
let batch = document.getElementById("batch");
let row = document.getElementById("row");
let column = document.getElementById("column");
const onesZerosFunc = (arg) => {
if (variable.value === "") {
return alert("Please enter a variable name in the 'Create Tensor' section.");
} else if (batch.value === "") {
return alert("Please enter a number in the 'batch' field in the 'Tensor functions' section.");
} else if (row.value === "") {
return alert("Please enter a number in the 'row' field in the 'Tensor functions' section.");
} else if (column.value === "") {
return alert("Please enter a number in the 'column' field in the 'Tensor functions' section.");
} else {
document.editor.textbox.value+="\n" + variable.value + " = tf." + arg + "([" + batch.value + ", " + row.value + ", " + column.value + "])";
}
}
const reshape = (arg) => {
if (variable.value === "") {
return alert("Please enter a variable name in the 'Create Tensor' section.");
} else if (batch.value === "") {
return alert("Please enter a number in the 'batch' field in the 'Tensor functions' section.");
} else if (row.value === "") {
return alert("Please enter a number in the 'row' field in the 'Tensor functions' section.");
} else {
let keep = "";
if (column.value) {
keep = ", " + column.value;
}
document.editor.textbox.value+="\n" + variable.value + "_1 = tf." + arg + "(" + variable.value + ", [" + batch.value + ", " + row.value + keep + "])";
}
}
// Select
let rows = document.getElementById("rows");
let columns = document.getElementById("columns");
const access = () => {
if (variable.value === "") {
return alert("Please enter a variable name in the 'Create Tensor' section.");
} else if (row.value === "") {
return alert("Please enter a number in the 'row' field in the 'Tensor functions' section.");
} else {
let keep = "";
if (column.value) {
keep = ", " + column.value;
}
document.editor.textbox.value+="\n" + variable.value + "_select = " + variable.value + "[" + row.value + keep + "]";
}
}
const accessRows = () => {
if (variable.value === "") {
return alert("Please enter a variable name in the 'Create Tensor' section");
} else if (row.value === "") {
return alert("Please enter a number in the 'row' field in the 'Tensor functions' section.");
} else if (rows.value === "") {
return alert("Please enter a number in the 'rows' field in the 'Select' section.");
} else {
document.editor.textbox.value+="\n" + variable.value + "_rows = " + variable.value + "[" + row.value + "::" + rows.value + "]";
}
}
const accessColumn = () => {
if (variable.value === "") {
return alert("Please enter a variable name in the 'Create Tensor' section");
} else if (row.value === "") {
return alert("Please enter a number in the 'row' field in the 'Tensor functions' section.");
} else if (rows.value === "") {
return alert("Please enter a number in the 'rows' field in the 'Select' section.");
} else if (columns.value === "") {
return alert("Please enter a number in the 'columns' field in the 'Select' section.");
} else {
document.editor.textbox.value+="\n" + variable.value + "_column = " + variable.value + "[" + row.value + ":" + rows.value + ", " + columns.value + "]";
}
}