Skip to content

Commit 52f1ffc

Browse files
committed
deploy: 5c874c6
0 parents  commit 52f1ffc

4 files changed

Lines changed: 385 additions & 0 deletions

File tree

.nojekyll

Whitespace-only changes.

index.html

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<title>Lang Shift</title>
6+
<link rel="modulepreload" href="/langshift-54d88d2bf8e58495.js" crossorigin="anonymous" integrity="sha384-giUBHKbPxnZdmDCP/B+2Bobd2nIuQAQDj6RqzafFShXc2yM9I/+FArUMMz9CXSfo"><link rel="preload" href="/langshift-54d88d2bf8e58495_bg.wasm" crossorigin="anonymous" integrity="sha384-S9jfvZULOGhGbkHJ3MvxP/fhiNZANKxCmBISG4tkuj5Dup/vMuIt4dIIkK3frfvw" as="fetch" type="application/wasm"></head>
7+
<body>
8+
<div id="abrams"></div>
9+
<div id="diaz"></div>
10+
11+
<script type="module">
12+
import init, { solve_abrams_strogatz, solve_diaz_switkes } from './pkg/langshift.js';
13+
import "https://cdn.plot.ly/plotly-3.1.0-rc.0.min.js"
14+
15+
async function run() {
16+
await init();
17+
18+
Plotly.newPlot('abrams', [
19+
{
20+
"y": solve_abrams_strogatz(80, 20, 0.2, 1.31, 0.33, 200),
21+
"name": "Monolingual 1",
22+
"line": {
23+
"color": "red"
24+
}
25+
},
26+
{
27+
"y": solve_abrams_strogatz(80, 20, 0.2, 1.31, 0.33, 200).map(y => 100 - y),
28+
"name": "Monolingual 2",
29+
"line": {
30+
"color": "blue"
31+
}
32+
}
33+
]);
34+
35+
Plotly.newPlot('diaz', [
36+
{
37+
"y": solve_diaz_switkes(
38+
[33, 34, 33], [0.4, 0.6], [0.6, 0.01], 0.01, 0.2, 300, 0
39+
),
40+
"name": "Monolingual 1",
41+
"line": {
42+
"color": "red"
43+
}
44+
},
45+
{
46+
"y": solve_diaz_switkes(
47+
[33, 34, 33], [0.4, 0.6], [0.6, 0.01], 0.01, 0.2, 300, 1
48+
),
49+
"name": "Bilingual",
50+
"line": {
51+
"color": "blue"
52+
}
53+
},
54+
{
55+
"y": solve_diaz_switkes(
56+
[33, 34, 33], [0.4, 0.6], [0.6, 0.01], 0.01, 0.2, 300, 2
57+
),
58+
"name": "Monolingual 2",
59+
"line": {
60+
"color": "green"
61+
}
62+
}
63+
]);
64+
}
65+
66+
run();
67+
</script>
68+
69+
<script type="module">
70+
import init, * as bindings from '/langshift-54d88d2bf8e58495.js';
71+
const wasm = await init({ module_or_path: '/langshift-54d88d2bf8e58495_bg.wasm' });
72+
73+
74+
window.wasmBindings = bindings;
75+
76+
77+
dispatchEvent(new CustomEvent("TrunkApplicationStarted", {detail: {wasm}}));
78+
79+
</script></body>
80+
</html>

langshift-54d88d2bf8e58495.js

Lines changed: 305 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,305 @@
1+
let wasm;
2+
3+
const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );
4+
5+
if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); };
6+
7+
let cachedUint8ArrayMemory0 = null;
8+
9+
function getUint8ArrayMemory0() {
10+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
11+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
12+
}
13+
return cachedUint8ArrayMemory0;
14+
}
15+
16+
function getStringFromWasm0(ptr, len) {
17+
ptr = ptr >>> 0;
18+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
19+
}
20+
21+
let WASM_VECTOR_LEN = 0;
22+
23+
const cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder('utf-8') : { encode: () => { throw Error('TextEncoder not available') } } );
24+
25+
const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
26+
? function (arg, view) {
27+
return cachedTextEncoder.encodeInto(arg, view);
28+
}
29+
: function (arg, view) {
30+
const buf = cachedTextEncoder.encode(arg);
31+
view.set(buf);
32+
return {
33+
read: arg.length,
34+
written: buf.length
35+
};
36+
});
37+
38+
function passStringToWasm0(arg, malloc, realloc) {
39+
40+
if (realloc === undefined) {
41+
const buf = cachedTextEncoder.encode(arg);
42+
const ptr = malloc(buf.length, 1) >>> 0;
43+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
44+
WASM_VECTOR_LEN = buf.length;
45+
return ptr;
46+
}
47+
48+
let len = arg.length;
49+
let ptr = malloc(len, 1) >>> 0;
50+
51+
const mem = getUint8ArrayMemory0();
52+
53+
let offset = 0;
54+
55+
for (; offset < len; offset++) {
56+
const code = arg.charCodeAt(offset);
57+
if (code > 0x7F) break;
58+
mem[ptr + offset] = code;
59+
}
60+
61+
if (offset !== len) {
62+
if (offset !== 0) {
63+
arg = arg.slice(offset);
64+
}
65+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
66+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
67+
const ret = encodeString(arg, view);
68+
69+
offset += ret.written;
70+
ptr = realloc(ptr, len, offset, 1) >>> 0;
71+
}
72+
73+
WASM_VECTOR_LEN = offset;
74+
return ptr;
75+
}
76+
77+
let cachedDataViewMemory0 = null;
78+
79+
function getDataViewMemory0() {
80+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
81+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
82+
}
83+
return cachedDataViewMemory0;
84+
}
85+
86+
export function run() {
87+
wasm.run();
88+
}
89+
90+
let cachedFloat64ArrayMemory0 = null;
91+
92+
function getFloat64ArrayMemory0() {
93+
if (cachedFloat64ArrayMemory0 === null || cachedFloat64ArrayMemory0.byteLength === 0) {
94+
cachedFloat64ArrayMemory0 = new Float64Array(wasm.memory.buffer);
95+
}
96+
return cachedFloat64ArrayMemory0;
97+
}
98+
99+
function getArrayF64FromWasm0(ptr, len) {
100+
ptr = ptr >>> 0;
101+
return getFloat64ArrayMemory0().subarray(ptr / 8, ptr / 8 + len);
102+
}
103+
/**
104+
* @param {number} x
105+
* @param {number} y
106+
* @param {number} c
107+
* @param {number} a
108+
* @param {number} s
109+
* @param {number} t
110+
* @returns {Float64Array}
111+
*/
112+
export function solve_abrams_strogatz(x, y, c, a, s, t) {
113+
const ret = wasm.solve_abrams_strogatz(x, y, c, a, s, t);
114+
var v1 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
115+
wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
116+
return v1;
117+
}
118+
119+
let cachedUint32ArrayMemory0 = null;
120+
121+
function getUint32ArrayMemory0() {
122+
if (cachedUint32ArrayMemory0 === null || cachedUint32ArrayMemory0.byteLength === 0) {
123+
cachedUint32ArrayMemory0 = new Uint32Array(wasm.memory.buffer);
124+
}
125+
return cachedUint32ArrayMemory0;
126+
}
127+
128+
function passArray32ToWasm0(arg, malloc) {
129+
const ptr = malloc(arg.length * 4, 4) >>> 0;
130+
getUint32ArrayMemory0().set(arg, ptr / 4);
131+
WASM_VECTOR_LEN = arg.length;
132+
return ptr;
133+
}
134+
135+
function passArrayF64ToWasm0(arg, malloc) {
136+
const ptr = malloc(arg.length * 8, 8) >>> 0;
137+
getFloat64ArrayMemory0().set(arg, ptr / 8);
138+
WASM_VECTOR_LEN = arg.length;
139+
return ptr;
140+
}
141+
/**
142+
* @param {Uint32Array} x
143+
* @param {Float64Array} m
144+
* @param {Float64Array} g
145+
* @param {number} alpha
146+
* @param {number} beta
147+
* @param {number} t
148+
* @param {number} i
149+
* @returns {Float64Array}
150+
*/
151+
export function solve_diaz_switkes(x, m, g, alpha, beta, t, i) {
152+
const ptr0 = passArray32ToWasm0(x, wasm.__wbindgen_malloc);
153+
const len0 = WASM_VECTOR_LEN;
154+
const ptr1 = passArrayF64ToWasm0(m, wasm.__wbindgen_malloc);
155+
const len1 = WASM_VECTOR_LEN;
156+
const ptr2 = passArrayF64ToWasm0(g, wasm.__wbindgen_malloc);
157+
const len2 = WASM_VECTOR_LEN;
158+
const ret = wasm.solve_diaz_switkes(ptr0, len0, ptr1, len1, ptr2, len2, alpha, beta, t, i);
159+
var v4 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
160+
wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
161+
return v4;
162+
}
163+
164+
async function __wbg_load(module, imports) {
165+
if (typeof Response === 'function' && module instanceof Response) {
166+
if (typeof WebAssembly.instantiateStreaming === 'function') {
167+
try {
168+
return await WebAssembly.instantiateStreaming(module, imports);
169+
170+
} catch (e) {
171+
if (module.headers.get('Content-Type') != 'application/wasm') {
172+
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
173+
174+
} else {
175+
throw e;
176+
}
177+
}
178+
}
179+
180+
const bytes = await module.arrayBuffer();
181+
return await WebAssembly.instantiate(bytes, imports);
182+
183+
} else {
184+
const instance = await WebAssembly.instantiate(module, imports);
185+
186+
if (instance instanceof WebAssembly.Instance) {
187+
return { instance, module };
188+
189+
} else {
190+
return instance;
191+
}
192+
}
193+
}
194+
195+
function __wbg_get_imports() {
196+
const imports = {};
197+
imports.wbg = {};
198+
imports.wbg.__wbg_error_7534b8e9a36f1ab4 = function(arg0, arg1) {
199+
let deferred0_0;
200+
let deferred0_1;
201+
try {
202+
deferred0_0 = arg0;
203+
deferred0_1 = arg1;
204+
console.error(getStringFromWasm0(arg0, arg1));
205+
} finally {
206+
wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
207+
}
208+
};
209+
imports.wbg.__wbg_new_8a6f238a6ece86ea = function() {
210+
const ret = new Error();
211+
return ret;
212+
};
213+
imports.wbg.__wbg_stack_0ed75d68575b0f3c = function(arg0, arg1) {
214+
const ret = arg1.stack;
215+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
216+
const len1 = WASM_VECTOR_LEN;
217+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
218+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
219+
};
220+
imports.wbg.__wbindgen_init_externref_table = function() {
221+
const table = wasm.__wbindgen_export_3;
222+
const offset = table.grow(4);
223+
table.set(0, undefined);
224+
table.set(offset + 0, undefined);
225+
table.set(offset + 1, null);
226+
table.set(offset + 2, true);
227+
table.set(offset + 3, false);
228+
;
229+
};
230+
231+
return imports;
232+
}
233+
234+
function __wbg_init_memory(imports, memory) {
235+
236+
}
237+
238+
function __wbg_finalize_init(instance, module) {
239+
wasm = instance.exports;
240+
__wbg_init.__wbindgen_wasm_module = module;
241+
cachedDataViewMemory0 = null;
242+
cachedFloat64ArrayMemory0 = null;
243+
cachedUint32ArrayMemory0 = null;
244+
cachedUint8ArrayMemory0 = null;
245+
246+
247+
wasm.__wbindgen_start();
248+
return wasm;
249+
}
250+
251+
function initSync(module) {
252+
if (wasm !== undefined) return wasm;
253+
254+
255+
if (typeof module !== 'undefined') {
256+
if (Object.getPrototypeOf(module) === Object.prototype) {
257+
({module} = module)
258+
} else {
259+
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
260+
}
261+
}
262+
263+
const imports = __wbg_get_imports();
264+
265+
__wbg_init_memory(imports);
266+
267+
if (!(module instanceof WebAssembly.Module)) {
268+
module = new WebAssembly.Module(module);
269+
}
270+
271+
const instance = new WebAssembly.Instance(module, imports);
272+
273+
return __wbg_finalize_init(instance, module);
274+
}
275+
276+
async function __wbg_init(module_or_path) {
277+
if (wasm !== undefined) return wasm;
278+
279+
280+
if (typeof module_or_path !== 'undefined') {
281+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
282+
({module_or_path} = module_or_path)
283+
} else {
284+
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
285+
}
286+
}
287+
288+
if (typeof module_or_path === 'undefined') {
289+
module_or_path = new URL('langshift_bg.wasm', import.meta.url);
290+
}
291+
const imports = __wbg_get_imports();
292+
293+
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
294+
module_or_path = fetch(module_or_path);
295+
}
296+
297+
__wbg_init_memory(imports);
298+
299+
const { instance, module } = await __wbg_load(await module_or_path, imports);
300+
301+
return __wbg_finalize_init(instance, module);
302+
}
303+
304+
export { initSync };
305+
export default __wbg_init;

langshift-54d88d2bf8e58495_bg.wasm

200 KB
Binary file not shown.

0 commit comments

Comments
 (0)