-
Notifications
You must be signed in to change notification settings - Fork 0
/
dist.js
55 lines (42 loc) · 3.07 KB
/
dist.js
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
'use strict';
var bytes = new Uint8Array([0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x08, 0x01, 0x60, 0x03, 0x7f, 0x7f, 0x7f, 0x01, 0x7f, 0x03, 0x02, 0x01, 0x00, 0x05, 0x04, 0x01, 0x00, 0x80, 0x02, 0x07, 0x0d, 0x02, 0x03, 0x6d, 0x65, 0x6d, 0x02, 0x00, 0x03, 0x73, 0x61, 0x64, 0x00, 0x00, 0x0a, 0x86, 0x02, 0x01, 0x83, 0x02, 0x01, 0x04, 0x7f, 0x02, 0x7f, 0x20, 0x00, 0x20, 0x02, 0x6a, 0x22, 0x05, 0x20, 0x05, 0x41, 0x04, 0x70, 0x6b, 0x21, 0x06, 0x02, 0x40, 0x03, 0x40, 0x20, 0x00, 0x20, 0x06, 0x46, 0x0d, 0x01, 0x20, 0x04, 0x20, 0x00, 0x2d, 0x00, 0x00, 0x20, 0x01, 0x2d, 0x00, 0x00, 0x6b, 0x22, 0x02, 0x41, 0x1f, 0x75, 0x22, 0x03, 0x20, 0x02, 0x73, 0x20, 0x03, 0x6b, 0x6a, 0x20, 0x00, 0x41, 0x01, 0x6a, 0x22, 0x00, 0x2d, 0x00, 0x00, 0x20, 0x01, 0x41, 0x01, 0x6a, 0x22, 0x01, 0x2d, 0x00, 0x00, 0x6b, 0x22, 0x02, 0x41, 0x1f, 0x75, 0x22, 0x03, 0x20, 0x02, 0x73, 0x20, 0x03, 0x6b, 0x6a, 0x20, 0x00, 0x41, 0x01, 0x6a, 0x22, 0x00, 0x2d, 0x00, 0x00, 0x20, 0x01, 0x41, 0x01, 0x6a, 0x22, 0x01, 0x2d, 0x00, 0x00, 0x6b, 0x22, 0x02, 0x41, 0x1f, 0x75, 0x22, 0x03, 0x20, 0x02, 0x73, 0x20, 0x03, 0x6b, 0x6a, 0x21, 0x04, 0x20, 0x00, 0x41, 0x01, 0x6a, 0x22, 0x00, 0x2d, 0x00, 0x00, 0x20, 0x01, 0x41, 0x01, 0x6a, 0x22, 0x01, 0x2d, 0x00, 0x00, 0x6b, 0x22, 0x02, 0x41, 0x1f, 0x75, 0x22, 0x03, 0x20, 0x02, 0x73, 0x20, 0x03, 0x6b, 0x21, 0x02, 0x20, 0x00, 0x41, 0x01, 0x6a, 0x21, 0x00, 0x20, 0x01, 0x41, 0x01, 0x6a, 0x21, 0x01, 0x20, 0x04, 0x20, 0x02, 0x6a, 0x21, 0x04, 0x0c, 0x00, 0x0b, 0x00, 0x0b, 0x02, 0x40, 0x03, 0x40, 0x20, 0x00, 0x20, 0x05, 0x46, 0x0d, 0x01, 0x20, 0x00, 0x2d, 0x00, 0x00, 0x20, 0x01, 0x2d, 0x00, 0x00, 0x6b, 0x22, 0x02, 0x41, 0x1f, 0x75, 0x22, 0x03, 0x20, 0x02, 0x73, 0x20, 0x03, 0x6b, 0x21, 0x02, 0x20, 0x00, 0x41, 0x01, 0x6a, 0x21, 0x00, 0x20, 0x01, 0x41, 0x01, 0x6a, 0x21, 0x01, 0x20, 0x04, 0x20, 0x02, 0x6a, 0x21, 0x04, 0x0c, 0x00, 0x0b, 0x00, 0x0b, 0x20, 0x04, 0x0b, 0x0b]);
var wasmSad = null;
function jsSad(A, B) {
var sum = 0;
for (var i = 0; i < A.length; i += 1) {
sum += Math.abs(A[i] - B[i]);
}
return sum;
}
if ('WebAssembly' in global) {
var env = {
memoryBase: 0,
tableBase: 0,
memory: new WebAssembly.Memory({ initial: 256 }),
table: new WebAssembly.Table({ initial: 0, element: 'anyfunc' })
};
var _module = new WebAssembly.Module(bytes);
var instance = new WebAssembly.Instance(_module, { env: env });
var data = new Uint8ClampedArray(instance.exports.mem.buffer);
wasmSad = function wasmSad(A, B) {
var l = A.length;
data.set(A, 0);
data.set(B, l);
return instance.exports.sad(0, l, l);
};
}
module.exports = function (A, B) {
var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
_ref$normalize = _ref.normalize,
normalize = _ref$normalize === undefined ? false : _ref$normalize,
_ref$useJS = _ref.useJS,
useJS = _ref$useJS === undefined ? false : _ref$useJS;
if (A.length !== B.length) {
throw new Error('Arrays must be same dimension');
}
var diff = wasmSad === null || useJS ? jsSad(A, B) : wasmSad(A, B);
if (normalize) {
return diff / A.length;
}
return diff;
};