@vizcrush/transform 1.0.0

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.
@@ -0,0 +1,425 @@
1
+ /* @ts-self-types="./vizcrush_transform.d.ts" */
2
+
3
+ /**
4
+ * Extract a viewport slice of paired x/y data without copying the full array.
5
+ *
6
+ * Returns only the points where x is within [x_min, x_max].
7
+ *
8
+ * # Returns
9
+ * Interleaved [x0, y0, x1, y1, ...] of matching points.
10
+ * @param {Float64Array} x
11
+ * @param {Float64Array} y
12
+ * @param {number} x_min
13
+ * @param {number} x_max
14
+ * @returns {Float64Array}
15
+ */
16
+ export function filter_range(x, y, x_min, x_max) {
17
+ try {
18
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
19
+ const ptr0 = passArrayF64ToWasm0(x, wasm.__wbindgen_export);
20
+ const len0 = WASM_VECTOR_LEN;
21
+ const ptr1 = passArrayF64ToWasm0(y, wasm.__wbindgen_export);
22
+ const len1 = WASM_VECTOR_LEN;
23
+ wasm.filter_range(retptr, ptr0, len0, ptr1, len1, x_min, x_max);
24
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
25
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
26
+ var v3 = getArrayF64FromWasm0(r0, r1).slice();
27
+ wasm.__wbindgen_export2(r0, r1 * 8, 8);
28
+ return v3;
29
+ } finally {
30
+ wasm.__wbindgen_add_to_stack_pointer(16);
31
+ }
32
+ }
33
+
34
+ /**
35
+ * Binary search-based filter for sorted x arrays. Much faster for large datasets.
36
+ * @param {Float64Array} x
37
+ * @param {Float64Array} y
38
+ * @param {number} x_min
39
+ * @param {number} x_max
40
+ * @returns {Float64Array}
41
+ */
42
+ export function filter_range_sorted(x, y, x_min, x_max) {
43
+ try {
44
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
45
+ const ptr0 = passArrayF64ToWasm0(x, wasm.__wbindgen_export);
46
+ const len0 = WASM_VECTOR_LEN;
47
+ const ptr1 = passArrayF64ToWasm0(y, wasm.__wbindgen_export);
48
+ const len1 = WASM_VECTOR_LEN;
49
+ wasm.filter_range_sorted(retptr, ptr0, len0, ptr1, len1, x_min, x_max);
50
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
51
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
52
+ var v3 = getArrayF64FromWasm0(r0, r1).slice();
53
+ wasm.__wbindgen_export2(r0, r1 * 8, 8);
54
+ return v3;
55
+ } finally {
56
+ wasm.__wbindgen_add_to_stack_pointer(16);
57
+ }
58
+ }
59
+
60
+ /**
61
+ * Natural logarithm transform.
62
+ *
63
+ * Computes ln(v) for each element. Non-finite values and
64
+ * values <= 0 produce NaN.
65
+ *
66
+ * # Arguments
67
+ * * `data` - Input array.
68
+ *
69
+ * # Returns
70
+ * Transformed array.
71
+ * @param {Float64Array} data
72
+ * @returns {Float64Array}
73
+ */
74
+ export function ln_transform(data) {
75
+ try {
76
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
77
+ const ptr0 = passArrayF64ToWasm0(data, wasm.__wbindgen_export);
78
+ const len0 = WASM_VECTOR_LEN;
79
+ wasm.ln_transform(retptr, ptr0, len0);
80
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
81
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
82
+ var v2 = getArrayF64FromWasm0(r0, r1).slice();
83
+ wasm.__wbindgen_export2(r0, r1 * 8, 8);
84
+ return v2;
85
+ } finally {
86
+ wasm.__wbindgen_add_to_stack_pointer(16);
87
+ }
88
+ }
89
+
90
+ /**
91
+ * Base-10 logarithm transform.
92
+ *
93
+ * Computes log10(v) for each element. Non-finite values and
94
+ * values <= 0 produce NaN.
95
+ *
96
+ * # Arguments
97
+ * * `data` - Input array.
98
+ *
99
+ * # Returns
100
+ * Transformed array.
101
+ * @param {Float64Array} data
102
+ * @returns {Float64Array}
103
+ */
104
+ export function log10_transform(data) {
105
+ try {
106
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
107
+ const ptr0 = passArrayF64ToWasm0(data, wasm.__wbindgen_export);
108
+ const len0 = WASM_VECTOR_LEN;
109
+ wasm.log10_transform(retptr, ptr0, len0);
110
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
111
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
112
+ var v2 = getArrayF64FromWasm0(r0, r1).slice();
113
+ wasm.__wbindgen_export2(r0, r1 * 8, 8);
114
+ return v2;
115
+ } finally {
116
+ wasm.__wbindgen_add_to_stack_pointer(16);
117
+ }
118
+ }
119
+
120
+ /**
121
+ * Logarithm transform with arbitrary base.
122
+ *
123
+ * Computes log_base(v) for each element. Non-finite values and
124
+ * values <= 0 produce NaN.
125
+ *
126
+ * # Arguments
127
+ * * `data` - Input array.
128
+ * * `base` - Logarithm base (e.g. 2.0, 10.0, E).
129
+ *
130
+ * # Returns
131
+ * Transformed array.
132
+ * @param {Float64Array} data
133
+ * @param {number} base
134
+ * @returns {Float64Array}
135
+ */
136
+ export function log_transform(data, base) {
137
+ try {
138
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
139
+ const ptr0 = passArrayF64ToWasm0(data, wasm.__wbindgen_export);
140
+ const len0 = WASM_VECTOR_LEN;
141
+ wasm.log_transform(retptr, ptr0, len0, base);
142
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
143
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
144
+ var v2 = getArrayF64FromWasm0(r0, r1).slice();
145
+ wasm.__wbindgen_export2(r0, r1 * 8, 8);
146
+ return v2;
147
+ } finally {
148
+ wasm.__wbindgen_add_to_stack_pointer(16);
149
+ }
150
+ }
151
+
152
+ /**
153
+ * Min-max normalization of `data` to \[0, 1\], optionally with a custom range.
154
+ * NaN / Infinity values are preserved as NaN.
155
+ * @param {Float64Array} data
156
+ * @param {number} range_min
157
+ * @param {number} range_max
158
+ * @returns {Float64Array}
159
+ */
160
+ export function normalize(data, range_min, range_max) {
161
+ try {
162
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
163
+ const ptr0 = passArrayF64ToWasm0(data, wasm.__wbindgen_export);
164
+ const len0 = WASM_VECTOR_LEN;
165
+ wasm.normalize(retptr, ptr0, len0, range_min, range_max);
166
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
167
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
168
+ var v2 = getArrayF64FromWasm0(r0, r1).slice();
169
+ wasm.__wbindgen_export2(r0, r1 * 8, 8);
170
+ return v2;
171
+ } finally {
172
+ wasm.__wbindgen_add_to_stack_pointer(16);
173
+ }
174
+ }
175
+
176
+ /**
177
+ * Power transform.
178
+ *
179
+ * Computes v^exponent for each element. Non-finite values produce NaN.
180
+ *
181
+ * # Arguments
182
+ * * `data` - Input array.
183
+ * * `exponent` - The power to raise each element to.
184
+ *
185
+ * # Returns
186
+ * Transformed array.
187
+ * @param {Float64Array} data
188
+ * @param {number} exponent
189
+ * @returns {Float64Array}
190
+ */
191
+ export function power_transform(data, exponent) {
192
+ try {
193
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
194
+ const ptr0 = passArrayF64ToWasm0(data, wasm.__wbindgen_export);
195
+ const len0 = WASM_VECTOR_LEN;
196
+ wasm.power_transform(retptr, ptr0, len0, exponent);
197
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
198
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
199
+ var v2 = getArrayF64FromWasm0(r0, r1).slice();
200
+ wasm.__wbindgen_export2(r0, r1 * 8, 8);
201
+ return v2;
202
+ } finally {
203
+ wasm.__wbindgen_add_to_stack_pointer(16);
204
+ }
205
+ }
206
+
207
+ /**
208
+ * Quantile normalize a flat row-major matrix (n_rows x n_cols).
209
+ *
210
+ * Each column is a distribution. After normalization, all columns
211
+ * share the same distribution (the average distribution).
212
+ *
213
+ * # Arguments
214
+ * * `data` - Flat row-major matrix of size n_rows * n_cols.
215
+ * * `n_cols` - Number of columns.
216
+ *
217
+ * # Returns
218
+ * Quantile-normalized matrix in flat row-major layout.
219
+ * @param {Float64Array} data
220
+ * @param {number} n_cols
221
+ * @returns {Float64Array}
222
+ */
223
+ export function quantile_normalize(data, n_cols) {
224
+ try {
225
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
226
+ const ptr0 = passArrayF64ToWasm0(data, wasm.__wbindgen_export);
227
+ const len0 = WASM_VECTOR_LEN;
228
+ wasm.quantile_normalize(retptr, ptr0, len0, n_cols);
229
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
230
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
231
+ var v2 = getArrayF64FromWasm0(r0, r1).slice();
232
+ wasm.__wbindgen_export2(r0, r1 * 8, 8);
233
+ return v2;
234
+ } finally {
235
+ wasm.__wbindgen_add_to_stack_pointer(16);
236
+ }
237
+ }
238
+
239
+ /**
240
+ * Radix sort on Float64 arrays.
241
+ *
242
+ * Converts f64 to sortable u64 representation, performs radix sort,
243
+ * then converts back. O(n) time complexity.
244
+ *
245
+ * # Arguments
246
+ * * `data` - Input array to sort.
247
+ * * `descending` - If true, sort in descending order.
248
+ *
249
+ * # Returns
250
+ * Sorted array.
251
+ * @param {Float64Array} data
252
+ * @param {boolean} descending
253
+ * @returns {Float64Array}
254
+ */
255
+ export function radix_sort(data, descending) {
256
+ try {
257
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
258
+ const ptr0 = passArrayF64ToWasm0(data, wasm.__wbindgen_export);
259
+ const len0 = WASM_VECTOR_LEN;
260
+ wasm.radix_sort(retptr, ptr0, len0, descending);
261
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
262
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
263
+ var v2 = getArrayF64FromWasm0(r0, r1).slice();
264
+ wasm.__wbindgen_export2(r0, r1 * 8, 8);
265
+ return v2;
266
+ } finally {
267
+ wasm.__wbindgen_add_to_stack_pointer(16);
268
+ }
269
+ }
270
+
271
+ /**
272
+ * Sort by key array: reorders `data` according to sorted order of `keys`.
273
+ * @param {Float64Array} data
274
+ * @param {Float64Array} keys
275
+ * @returns {Float64Array}
276
+ */
277
+ export function sort_by_keys(data, keys) {
278
+ try {
279
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
280
+ const ptr0 = passArrayF64ToWasm0(data, wasm.__wbindgen_export);
281
+ const len0 = WASM_VECTOR_LEN;
282
+ const ptr1 = passArrayF64ToWasm0(keys, wasm.__wbindgen_export);
283
+ const len1 = WASM_VECTOR_LEN;
284
+ wasm.sort_by_keys(retptr, ptr0, len0, ptr1, len1);
285
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
286
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
287
+ var v3 = getArrayF64FromWasm0(r0, r1).slice();
288
+ wasm.__wbindgen_export2(r0, r1 * 8, 8);
289
+ return v3;
290
+ } finally {
291
+ wasm.__wbindgen_add_to_stack_pointer(16);
292
+ }
293
+ }
294
+
295
+ function __wbg_get_imports() {
296
+ const import0 = {
297
+ __proto__: null,
298
+ };
299
+ return {
300
+ __proto__: null,
301
+ "./vizcrush_transform_bg.js": import0,
302
+ };
303
+ }
304
+
305
+ function getArrayF64FromWasm0(ptr, len) {
306
+ ptr = ptr >>> 0;
307
+ return getFloat64ArrayMemory0().subarray(ptr / 8, ptr / 8 + len);
308
+ }
309
+
310
+ let cachedDataViewMemory0 = null;
311
+ function getDataViewMemory0() {
312
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
313
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
314
+ }
315
+ return cachedDataViewMemory0;
316
+ }
317
+
318
+ let cachedFloat64ArrayMemory0 = null;
319
+ function getFloat64ArrayMemory0() {
320
+ if (cachedFloat64ArrayMemory0 === null || cachedFloat64ArrayMemory0.byteLength === 0) {
321
+ cachedFloat64ArrayMemory0 = new Float64Array(wasm.memory.buffer);
322
+ }
323
+ return cachedFloat64ArrayMemory0;
324
+ }
325
+
326
+ function passArrayF64ToWasm0(arg, malloc) {
327
+ const ptr = malloc(arg.length * 8, 8) >>> 0;
328
+ getFloat64ArrayMemory0().set(arg, ptr / 8);
329
+ WASM_VECTOR_LEN = arg.length;
330
+ return ptr;
331
+ }
332
+
333
+ let WASM_VECTOR_LEN = 0;
334
+
335
+ let wasmModule, wasm;
336
+ function __wbg_finalize_init(instance, module) {
337
+ wasm = instance.exports;
338
+ wasmModule = module;
339
+ cachedDataViewMemory0 = null;
340
+ cachedFloat64ArrayMemory0 = null;
341
+ return wasm;
342
+ }
343
+
344
+ async function __wbg_load(module, imports) {
345
+ if (typeof Response === 'function' && module instanceof Response) {
346
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
347
+ try {
348
+ return await WebAssembly.instantiateStreaming(module, imports);
349
+ } catch (e) {
350
+ const validResponse = module.ok && expectedResponseType(module.type);
351
+
352
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
353
+ 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);
354
+
355
+ } else { throw e; }
356
+ }
357
+ }
358
+
359
+ const bytes = await module.arrayBuffer();
360
+ return await WebAssembly.instantiate(bytes, imports);
361
+ } else {
362
+ const instance = await WebAssembly.instantiate(module, imports);
363
+
364
+ if (instance instanceof WebAssembly.Instance) {
365
+ return { instance, module };
366
+ } else {
367
+ return instance;
368
+ }
369
+ }
370
+
371
+ function expectedResponseType(type) {
372
+ switch (type) {
373
+ case 'basic': case 'cors': case 'default': return true;
374
+ }
375
+ return false;
376
+ }
377
+ }
378
+
379
+ function initSync(module) {
380
+ if (wasm !== undefined) return wasm;
381
+
382
+
383
+ if (module !== undefined) {
384
+ if (Object.getPrototypeOf(module) === Object.prototype) {
385
+ ({module} = module)
386
+ } else {
387
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
388
+ }
389
+ }
390
+
391
+ const imports = __wbg_get_imports();
392
+ if (!(module instanceof WebAssembly.Module)) {
393
+ module = new WebAssembly.Module(module);
394
+ }
395
+ const instance = new WebAssembly.Instance(module, imports);
396
+ return __wbg_finalize_init(instance, module);
397
+ }
398
+
399
+ async function __wbg_init(module_or_path) {
400
+ if (wasm !== undefined) return wasm;
401
+
402
+
403
+ if (module_or_path !== undefined) {
404
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
405
+ ({module_or_path} = module_or_path)
406
+ } else {
407
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
408
+ }
409
+ }
410
+
411
+ if (module_or_path === undefined) {
412
+ module_or_path = new URL('vizcrush_transform_bg.wasm', import.meta.url);
413
+ }
414
+ const imports = __wbg_get_imports();
415
+
416
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
417
+ module_or_path = fetch(module_or_path);
418
+ }
419
+
420
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
421
+
422
+ return __wbg_finalize_init(instance, module);
423
+ }
424
+
425
+ export { initSync, __wbg_init as default };
Binary file
@@ -0,0 +1,16 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const filter_range: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
5
+ export const filter_range_sorted: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
6
+ export const ln_transform: (a: number, b: number, c: number) => void;
7
+ export const log10_transform: (a: number, b: number, c: number) => void;
8
+ export const log_transform: (a: number, b: number, c: number, d: number) => void;
9
+ export const normalize: (a: number, b: number, c: number, d: number, e: number) => void;
10
+ export const power_transform: (a: number, b: number, c: number, d: number) => void;
11
+ export const quantile_normalize: (a: number, b: number, c: number, d: number) => void;
12
+ export const radix_sort: (a: number, b: number, c: number, d: number) => void;
13
+ export const sort_by_keys: (a: number, b: number, c: number, d: number, e: number) => void;
14
+ export const __wbindgen_add_to_stack_pointer: (a: number) => number;
15
+ export const __wbindgen_export: (a: number, b: number) => number;
16
+ export const __wbindgen_export2: (a: number, b: number, c: number) => void;