forked from gpujs/gpu.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinput.js
More file actions
33 lines (30 loc) · 736 Bytes
/
input.js
File metadata and controls
33 lines (30 loc) · 736 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
class Input {
constructor(value, size) {
this.value = value;
this.size = new Int32Array(3);
if (Array.isArray(size)) {
for (let i = 0; i < this.size.length; i++) {
this.size[i] = size[i] || 1;
}
} else {
if (size.z) {
this.size = new Int32Array([size.x, size.y, size.z]);
} else if (size.y) {
this.size = new Int32Array([size.x, size.y, 1]);
} else {
this.size = new Int32Array([size.x, 1, 1]);
}
}
const [h, w, d] = this.size;
if (this.value.length !== (h * w * d)) {
throw new Error(`Input size ${this.value.length} does not match ${w} * ${h} * ${d} = ${(h * w * d)}`);
}
}
}
function input(value, size) {
return new Input(value, size);
}
module.exports = {
Input,
input
};