@climateriskcommons/crc-framework 0.0.0-stage → 0.5.3-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +619 -0
- package/README.md +75 -2
- package/THIRD_PARTY_NOTICES.md +70 -0
- package/package.json +28 -4
- package/src/index.d.ts +75 -0
- package/src/index.js +213 -0
- package/wasm/crc_framework.d.ts +77 -0
- package/wasm/crc_framework.js +357 -0
- package/wasm/crc_framework_bg.wasm +0 -0
- package/wasm/crc_framework_bg.wasm.d.ts +18 -0
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
/* @ts-self-types="./crc_framework.d.ts" */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* An explicitly owned, validated curve; call free() when finished.
|
|
5
|
+
*/
|
|
6
|
+
export class PreparedCurve {
|
|
7
|
+
static __wrap(ptr) {
|
|
8
|
+
const obj = Object.create(PreparedCurve.prototype);
|
|
9
|
+
obj.__wbg_ptr = ptr;
|
|
10
|
+
PreparedCurveFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
11
|
+
return obj;
|
|
12
|
+
}
|
|
13
|
+
__destroy_into_raw() {
|
|
14
|
+
const ptr = this.__wbg_ptr;
|
|
15
|
+
this.__wbg_ptr = 0;
|
|
16
|
+
PreparedCurveFinalization.unregister(this);
|
|
17
|
+
return ptr;
|
|
18
|
+
}
|
|
19
|
+
free() {
|
|
20
|
+
const ptr = this.__destroy_into_raw();
|
|
21
|
+
wasm.__wbg_preparedcurve_free(ptr, 0);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* @param {number} q
|
|
25
|
+
* @returns {any}
|
|
26
|
+
*/
|
|
27
|
+
evaluate(q) {
|
|
28
|
+
const ret = wasm.preparedcurve_evaluate(this.__wbg_ptr, q);
|
|
29
|
+
if (ret[2]) {
|
|
30
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
31
|
+
}
|
|
32
|
+
return takeFromExternrefTable0(ret[0]);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* @param {Float64Array} row
|
|
36
|
+
* @param {Float64Array} knots
|
|
37
|
+
* @returns {PreparedCurve}
|
|
38
|
+
*/
|
|
39
|
+
static fromPacked(row, knots) {
|
|
40
|
+
const ptr0 = passArrayF64ToWasm0(row, wasm.__wbindgen_malloc);
|
|
41
|
+
const len0 = WASM_VECTOR_LEN;
|
|
42
|
+
const ptr1 = passArrayF64ToWasm0(knots, wasm.__wbindgen_malloc);
|
|
43
|
+
const len1 = WASM_VECTOR_LEN;
|
|
44
|
+
const ret = wasm.preparedcurve_fromPacked(ptr0, len0, ptr1, len1);
|
|
45
|
+
if (ret[2]) {
|
|
46
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
47
|
+
}
|
|
48
|
+
return PreparedCurve.__wrap(ret[0]);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Multiple queries without reparsing the same record.
|
|
52
|
+
* @param {Float64Array} probabilities
|
|
53
|
+
* @returns {Array<any>}
|
|
54
|
+
*/
|
|
55
|
+
quantiles(probabilities) {
|
|
56
|
+
const ptr0 = passArrayF64ToWasm0(probabilities, wasm.__wbindgen_malloc);
|
|
57
|
+
const len0 = WASM_VECTOR_LEN;
|
|
58
|
+
const ret = wasm.preparedcurve_quantiles(this.__wbg_ptr, ptr0, len0);
|
|
59
|
+
if (ret[2]) {
|
|
60
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
61
|
+
}
|
|
62
|
+
return takeFromExternrefTable0(ret[0]);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (Symbol.dispose) PreparedCurve.prototype[Symbol.dispose] = PreparedCurve.prototype.free;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* A tile-sized collection reconstructed once and evaluated in one WASM call.
|
|
69
|
+
*/
|
|
70
|
+
export class PreparedCurves {
|
|
71
|
+
static __wrap(ptr) {
|
|
72
|
+
const obj = Object.create(PreparedCurves.prototype);
|
|
73
|
+
obj.__wbg_ptr = ptr;
|
|
74
|
+
PreparedCurvesFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
75
|
+
return obj;
|
|
76
|
+
}
|
|
77
|
+
__destroy_into_raw() {
|
|
78
|
+
const ptr = this.__wbg_ptr;
|
|
79
|
+
this.__wbg_ptr = 0;
|
|
80
|
+
PreparedCurvesFinalization.unregister(this);
|
|
81
|
+
return ptr;
|
|
82
|
+
}
|
|
83
|
+
free() {
|
|
84
|
+
const ptr = this.__destroy_into_raw();
|
|
85
|
+
wasm.__wbg_preparedcurves_free(ptr, 0);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* @param {number} q
|
|
89
|
+
* @returns {Float64Array}
|
|
90
|
+
*/
|
|
91
|
+
evaluate(q) {
|
|
92
|
+
const ret = wasm.preparedcurves_evaluate(this.__wbg_ptr, q);
|
|
93
|
+
if (ret[3]) {
|
|
94
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
95
|
+
}
|
|
96
|
+
var v1 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
|
|
97
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
|
|
98
|
+
return v1;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* @param {Float64Array} rows
|
|
102
|
+
* @param {Float64Array} knots
|
|
103
|
+
* @returns {PreparedCurves}
|
|
104
|
+
*/
|
|
105
|
+
static fromPacked(rows, knots) {
|
|
106
|
+
const ptr0 = passArrayF64ToWasm0(rows, wasm.__wbindgen_malloc);
|
|
107
|
+
const len0 = WASM_VECTOR_LEN;
|
|
108
|
+
const ptr1 = passArrayF64ToWasm0(knots, wasm.__wbindgen_malloc);
|
|
109
|
+
const len1 = WASM_VECTOR_LEN;
|
|
110
|
+
const ret = wasm.preparedcurves_fromPacked(ptr0, len0, ptr1, len1);
|
|
111
|
+
if (ret[2]) {
|
|
112
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
113
|
+
}
|
|
114
|
+
return PreparedCurves.__wrap(ret[0]);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (Symbol.dispose) PreparedCurves.prototype[Symbol.dispose] = PreparedCurves.prototype.free;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* @returns {Array<any>}
|
|
121
|
+
*/
|
|
122
|
+
export function curveKindNames() {
|
|
123
|
+
const ret = wasm.curveKindNames();
|
|
124
|
+
return ret;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* @returns {Array<any>}
|
|
129
|
+
*/
|
|
130
|
+
export function curveTypeNames() {
|
|
131
|
+
const ret = wasm.curveTypeNames();
|
|
132
|
+
return ret;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* @param {Float64Array} row
|
|
137
|
+
* @param {Float64Array} knots
|
|
138
|
+
* @param {number} q
|
|
139
|
+
* @returns {any}
|
|
140
|
+
*/
|
|
141
|
+
export function evaluateCurvePacked(row, knots, q) {
|
|
142
|
+
const ptr0 = passArrayF64ToWasm0(row, wasm.__wbindgen_malloc);
|
|
143
|
+
const len0 = WASM_VECTOR_LEN;
|
|
144
|
+
const ptr1 = passArrayF64ToWasm0(knots, wasm.__wbindgen_malloc);
|
|
145
|
+
const len1 = WASM_VECTOR_LEN;
|
|
146
|
+
const ret = wasm.evaluateCurvePacked(ptr0, len0, ptr1, len1, q);
|
|
147
|
+
if (ret[2]) {
|
|
148
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
149
|
+
}
|
|
150
|
+
return takeFromExternrefTable0(ret[0]);
|
|
151
|
+
}
|
|
152
|
+
function __wbg_get_imports() {
|
|
153
|
+
const import0 = {
|
|
154
|
+
__proto__: null,
|
|
155
|
+
__wbg___wbindgen_throw_41e9ee4f547fc59a: function(arg0, arg1) {
|
|
156
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
157
|
+
},
|
|
158
|
+
__wbg_new_2bdcdfcebdfc34d2: function(arg0, arg1) {
|
|
159
|
+
const ret = new TypeError(getStringFromWasm0(arg0, arg1));
|
|
160
|
+
return ret;
|
|
161
|
+
},
|
|
162
|
+
__wbg_new_6ab88fbe741af6b5: function(arg0, arg1) {
|
|
163
|
+
const ret = new RangeError(getStringFromWasm0(arg0, arg1));
|
|
164
|
+
return ret;
|
|
165
|
+
},
|
|
166
|
+
__wbg_new_ee2291f50781bf1d: function() {
|
|
167
|
+
const ret = new Array();
|
|
168
|
+
return ret;
|
|
169
|
+
},
|
|
170
|
+
__wbg_push_2baf45db356cf468: function(arg0, arg1) {
|
|
171
|
+
const ret = arg0.push(arg1);
|
|
172
|
+
return ret;
|
|
173
|
+
},
|
|
174
|
+
__wbindgen_generic_0000000000000001: function(arg0) {
|
|
175
|
+
// Cast intrinsic for `F64 -> Externref`.
|
|
176
|
+
const ret = arg0;
|
|
177
|
+
return ret;
|
|
178
|
+
},
|
|
179
|
+
__wbindgen_generic_0000000000000002: function(arg0, arg1) {
|
|
180
|
+
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
181
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
182
|
+
return ret;
|
|
183
|
+
},
|
|
184
|
+
__wbindgen_init_externref_table: function() {
|
|
185
|
+
const table = wasm.__wbindgen_externrefs;
|
|
186
|
+
const offset = table.grow(4);
|
|
187
|
+
table.set(0, undefined);
|
|
188
|
+
table.set(offset + 0, undefined);
|
|
189
|
+
table.set(offset + 1, null);
|
|
190
|
+
table.set(offset + 2, true);
|
|
191
|
+
table.set(offset + 3, false);
|
|
192
|
+
},
|
|
193
|
+
};
|
|
194
|
+
return {
|
|
195
|
+
__proto__: null,
|
|
196
|
+
"./crc_framework_bg.js": import0,
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const PreparedCurveFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
201
|
+
? { register: () => {}, unregister: () => {} }
|
|
202
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_preparedcurve_free(ptr, 1));
|
|
203
|
+
const PreparedCurvesFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
204
|
+
? { register: () => {}, unregister: () => {} }
|
|
205
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_preparedcurves_free(ptr, 1));
|
|
206
|
+
|
|
207
|
+
function getArrayF64FromWasm0(ptr, len) {
|
|
208
|
+
ptr = ptr >>> 0;
|
|
209
|
+
return getFloat64ArrayMemory0().subarray(ptr / 8, ptr / 8 + len);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
let cachedFloat64ArrayMemory0 = null;
|
|
213
|
+
function getFloat64ArrayMemory0() {
|
|
214
|
+
if (cachedFloat64ArrayMemory0 === null || cachedFloat64ArrayMemory0.byteLength === 0) {
|
|
215
|
+
cachedFloat64ArrayMemory0 = new Float64Array(wasm.memory.buffer);
|
|
216
|
+
}
|
|
217
|
+
return cachedFloat64ArrayMemory0;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function getStringFromWasm0(ptr, len) {
|
|
221
|
+
return decodeText(ptr >>> 0, len);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
let cachedUint8ArrayMemory0 = null;
|
|
225
|
+
function getUint8ArrayMemory0() {
|
|
226
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
227
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
228
|
+
}
|
|
229
|
+
return cachedUint8ArrayMemory0;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function passArrayF64ToWasm0(arg, malloc) {
|
|
233
|
+
const ptr = malloc(arg.length * 8, 8) >>> 0;
|
|
234
|
+
getFloat64ArrayMemory0().set(arg, ptr / 8);
|
|
235
|
+
WASM_VECTOR_LEN = arg.length;
|
|
236
|
+
return ptr;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function takeFromExternrefTable0(idx) {
|
|
240
|
+
const value = wasm.__wbindgen_externrefs.get(idx);
|
|
241
|
+
wasm.__externref_table_dealloc(idx);
|
|
242
|
+
return value;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
246
|
+
cachedTextDecoder.decode();
|
|
247
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
248
|
+
let numBytesDecoded = 0;
|
|
249
|
+
function decodeText(ptr, len) {
|
|
250
|
+
numBytesDecoded += len;
|
|
251
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
252
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
253
|
+
cachedTextDecoder.decode();
|
|
254
|
+
numBytesDecoded = len;
|
|
255
|
+
}
|
|
256
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
let WASM_VECTOR_LEN = 0;
|
|
260
|
+
|
|
261
|
+
let wasmModule, wasmInstance, wasm;
|
|
262
|
+
function __wbg_finalize_init(instance, module) {
|
|
263
|
+
wasmInstance = instance;
|
|
264
|
+
wasm = instance.exports;
|
|
265
|
+
wasmModule = module;
|
|
266
|
+
cachedFloat64ArrayMemory0 = null;
|
|
267
|
+
cachedUint8ArrayMemory0 = null;
|
|
268
|
+
wasm.__wbindgen_start();
|
|
269
|
+
return wasm;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
async function __wbg_load(module, imports) {
|
|
273
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
274
|
+
if (!module.ok) {
|
|
275
|
+
throw new Error(`failed to fetch Wasm: ${module.status} ${module.statusText} fetching '${module.url}'`);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
279
|
+
try {
|
|
280
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
281
|
+
} catch (e) {
|
|
282
|
+
const validResponse = expectedResponseType(module.type);
|
|
283
|
+
|
|
284
|
+
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
285
|
+
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);
|
|
286
|
+
|
|
287
|
+
} else { throw e; }
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
const bytes = await module.arrayBuffer();
|
|
292
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
293
|
+
} else {
|
|
294
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
295
|
+
|
|
296
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
297
|
+
return { instance, module };
|
|
298
|
+
} else {
|
|
299
|
+
return instance;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
function expectedResponseType(type) {
|
|
304
|
+
switch (type) {
|
|
305
|
+
case 'basic': case 'cors': case 'default': return true;
|
|
306
|
+
}
|
|
307
|
+
return false;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
function initSync(module) {
|
|
312
|
+
if (wasm !== undefined) return wasm;
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
if (module !== undefined) {
|
|
316
|
+
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
317
|
+
({module} = module)
|
|
318
|
+
} else {
|
|
319
|
+
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
const imports = __wbg_get_imports();
|
|
324
|
+
if (!(module instanceof WebAssembly.Module)) {
|
|
325
|
+
module = new WebAssembly.Module(module);
|
|
326
|
+
}
|
|
327
|
+
const instance = new WebAssembly.Instance(module, imports);
|
|
328
|
+
return __wbg_finalize_init(instance, module);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
async function __wbg_init(module_or_path) {
|
|
332
|
+
if (wasm !== undefined) return wasm;
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
if (module_or_path !== undefined) {
|
|
336
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
337
|
+
({module_or_path} = module_or_path)
|
|
338
|
+
} else {
|
|
339
|
+
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
if (module_or_path === undefined) {
|
|
344
|
+
module_or_path = new URL('crc_framework_bg.wasm', import.meta.url);
|
|
345
|
+
}
|
|
346
|
+
const imports = __wbg_get_imports();
|
|
347
|
+
|
|
348
|
+
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
349
|
+
module_or_path = fetch(module_or_path);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
353
|
+
|
|
354
|
+
return __wbg_finalize_init(instance, module);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
export { initSync, __wbg_init as default };
|
|
Binary file
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
export const memory: WebAssembly.Memory;
|
|
4
|
+
export const __wbg_preparedcurve_free: (a: number, b: number) => void;
|
|
5
|
+
export const __wbg_preparedcurves_free: (a: number, b: number) => void;
|
|
6
|
+
export const curveKindNames: () => any;
|
|
7
|
+
export const curveTypeNames: () => any;
|
|
8
|
+
export const evaluateCurvePacked: (a: number, b: number, c: number, d: number, e: number) => [number, number, number];
|
|
9
|
+
export const preparedcurve_evaluate: (a: number, b: number) => [number, number, number];
|
|
10
|
+
export const preparedcurve_fromPacked: (a: number, b: number, c: number, d: number) => [number, number, number];
|
|
11
|
+
export const preparedcurve_quantiles: (a: number, b: number, c: number) => [number, number, number];
|
|
12
|
+
export const preparedcurves_evaluate: (a: number, b: number) => [number, number, number, number];
|
|
13
|
+
export const preparedcurves_fromPacked: (a: number, b: number, c: number, d: number) => [number, number, number];
|
|
14
|
+
export const __wbindgen_externrefs: WebAssembly.Table;
|
|
15
|
+
export const __wbindgen_malloc: (a: number, b: number) => number;
|
|
16
|
+
export const __externref_table_dealloc: (a: number) => void;
|
|
17
|
+
export const __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
18
|
+
export const __wbindgen_start: () => void;
|