@graphty/webgpu-graph-algorithms 0.4.1 → 0.5.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/README.md +27 -21
- package/dist/browser.js +1 -1
- package/dist/chunks/{context-CRbw2Wyo.js → context-BR7fx3vR.js} +47 -5
- package/dist/chunks/context-BR7fx3vR.js.map +1 -0
- package/dist/node.js +1 -1
- package/dist/src/accelerator.d.ts +15 -12
- package/dist/src/accelerator.d.ts.map +1 -1
- package/dist/src/accelerator.js +35 -12
- package/dist/src/accelerator.js.map +1 -1
- package/dist/src/constants.d.ts +47 -0
- package/dist/src/constants.d.ts.map +1 -1
- package/dist/src/constants.js +47 -0
- package/dist/src/constants.js.map +1 -1
- package/dist/src/index.d.ts +8 -5
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +9 -5
- package/dist/src/index.js.map +1 -1
- package/dist/src/kernel/prelude.d.ts.map +1 -1
- package/dist/src/kernel/prelude.js +4 -1
- package/dist/src/kernel/prelude.js.map +1 -1
- package/dist/src/kernels.d.ts +3 -3
- package/dist/src/kernels.d.ts.map +1 -1
- package/dist/src/kernels.js +27 -11
- package/dist/src/kernels.js.map +1 -1
- package/dist/src/layouts/force-simulation.d.ts +3 -1
- package/dist/src/layouts/force-simulation.d.ts.map +1 -1
- package/dist/src/layouts/force-simulation.js +13 -3
- package/dist/src/layouts/force-simulation.js.map +1 -1
- package/dist/src/layouts/forceatlas2.d.ts +1 -3
- package/dist/src/layouts/forceatlas2.d.ts.map +1 -1
- package/dist/src/layouts/forceatlas2.js +2 -191
- package/dist/src/layouts/forceatlas2.js.map +1 -1
- package/dist/src/layouts/fruchterman-reingold.d.ts +195 -0
- package/dist/src/layouts/fruchterman-reingold.d.ts.map +1 -0
- package/dist/src/layouts/fruchterman-reingold.js +579 -0
- package/dist/src/layouts/fruchterman-reingold.js.map +1 -0
- package/dist/src/layouts/model-common.d.ts +102 -0
- package/dist/src/layouts/model-common.d.ts.map +1 -0
- package/dist/src/layouts/model-common.js +198 -0
- package/dist/src/layouts/model-common.js.map +1 -0
- package/dist/src/layouts/spring-electrical.d.ts +179 -0
- package/dist/src/layouts/spring-electrical.d.ts.map +1 -0
- package/dist/src/layouts/spring-electrical.js +508 -0
- package/dist/src/layouts/spring-electrical.js.map +1 -0
- package/dist/src/types/accelerator.d.ts +14 -157
- package/dist/src/types/accelerator.d.ts.map +1 -1
- package/dist/src/types/accelerator.js +4 -5
- package/dist/src/types/accelerator.js.map +1 -1
- package/dist/src/types/algorithms.d.ts +1 -1
- package/dist/src/types/algorithms.js +1 -1
- package/dist/src/types/layout.d.ts +32 -0
- package/dist/src/types/layout.d.ts.map +1 -1
- package/dist/src/types/options.d.ts +43 -1
- package/dist/src/types/options.d.ts.map +1 -1
- package/dist/src/wgsl/fa2-attraction.wgsl.d.ts +5 -2
- package/dist/src/wgsl/fa2-attraction.wgsl.d.ts.map +1 -1
- package/dist/src/wgsl/fa2-attraction.wgsl.js +6 -1
- package/dist/src/wgsl/fa2-attraction.wgsl.js.map +1 -1
- package/dist/src/wgsl/fa2-integrate.wgsl.d.ts +7 -2
- package/dist/src/wgsl/fa2-integrate.wgsl.d.ts.map +1 -1
- package/dist/src/wgsl/fa2-integrate.wgsl.js +28 -2
- package/dist/src/wgsl/fa2-integrate.wgsl.js.map +1 -1
- package/dist/src/wgsl/fa2-repulsion-exact.wgsl.d.ts +4 -2
- package/dist/src/wgsl/fa2-repulsion-exact.wgsl.d.ts.map +1 -1
- package/dist/src/wgsl/fa2-repulsion-exact.wgsl.js +14 -5
- package/dist/src/wgsl/fa2-repulsion-exact.wgsl.js.map +1 -1
- package/dist/src/wgsl/fa2-stats-finalize.wgsl.d.ts +8 -1
- package/dist/src/wgsl/fa2-stats-finalize.wgsl.d.ts.map +1 -1
- package/dist/src/wgsl/fa2-stats-finalize.wgsl.js +33 -0
- package/dist/src/wgsl/fa2-stats-finalize.wgsl.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/webgpu-graph-algorithms.js +1358 -284
- package/dist/webgpu-graph-algorithms.js.map +1 -1
- package/package.json +6 -3
- package/src/accelerator.ts +49 -14
- package/src/constants.ts +70 -0
- package/src/index.ts +19 -8
- package/src/kernel/prelude.ts +6 -0
- package/src/kernels.ts +27 -11
- package/src/layouts/force-simulation.ts +20 -3
- package/src/layouts/forceatlas2.ts +17 -220
- package/src/layouts/fruchterman-reingold.ts +737 -0
- package/src/layouts/model-common.ts +228 -0
- package/src/layouts/spring-electrical.ts +666 -0
- package/src/types/accelerator.ts +58 -174
- package/src/types/algorithms.ts +1 -1
- package/src/types/layout.ts +36 -0
- package/src/types/options.ts +45 -1
- package/src/wgsl/fa2-attraction.wgsl.ts +6 -1
- package/src/wgsl/fa2-integrate.wgsl.ts +28 -2
- package/src/wgsl/fa2-repulsion-exact.wgsl.ts +14 -5
- package/src/wgsl/fa2-stats-finalize.wgsl.ts +33 -0
- package/dist/chunks/context-CRbw2Wyo.js.map +0 -1
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The option and value helpers every force model's resolver and stats decoder share (PD-7): moved verbatim from
|
|
3
|
+
* src/layouts/forceatlas2.ts (P3-T2) so the Fruchterman-Reingold and spring-electrical models of P5 neither copy
|
|
4
|
+
* them nor import a sibling model. Layout zone; imports errors.ts only.
|
|
5
|
+
*/
|
|
6
|
+
import { WebGpuGraphError } from "../errors.js";
|
|
7
|
+
import { type UniformValues } from "../kernel/struct-block.js";
|
|
8
|
+
/** An override record as the kernel layer takes it. */
|
|
9
|
+
export type Overrides = Readonly<Record<string, number | boolean>>;
|
|
10
|
+
/** Bytes of the stride-3 f32 force arrays per node. */
|
|
11
|
+
export declare const FORCE_BYTES_PER_NODE = 12;
|
|
12
|
+
/** The name of the model-owned FillParams buffer (a BufferSpec, reached through ModelResources.buffer). */
|
|
13
|
+
export declare const FILL_PARAMS_BUFFER = "fillParams";
|
|
14
|
+
/**
|
|
15
|
+
* A short, safe rendering of an argument value for error messages (never String() on an object).
|
|
16
|
+
* @param value - the value
|
|
17
|
+
* @returns the rendering
|
|
18
|
+
*/
|
|
19
|
+
export declare function describeValue(value: unknown): string;
|
|
20
|
+
/**
|
|
21
|
+
* The E_INVALID_ARGUMENT error of an option check (contract 3.1: { argument, value, expected }).
|
|
22
|
+
* @param argument - the option name
|
|
23
|
+
* @param value - the value given
|
|
24
|
+
* @param expected - what was expected
|
|
25
|
+
* @returns the error (not thrown here)
|
|
26
|
+
*/
|
|
27
|
+
export declare function invalid(argument: string, value: unknown, expected: string): WebGpuGraphError;
|
|
28
|
+
/**
|
|
29
|
+
* A numeric option: the given value when defined, else the fallback; validated by `check` (the value is checked as
|
|
30
|
+
* `unknown` so a JS caller's string or object is E_INVALID_ARGUMENT too).
|
|
31
|
+
* @param name - the option name
|
|
32
|
+
* @param given - the value given (undefined = absent)
|
|
33
|
+
* @param fallback - the previous record's value or the default
|
|
34
|
+
* @param check - the range predicate over a finite number
|
|
35
|
+
* @param expected - the range in words (the error message)
|
|
36
|
+
* @returns the value
|
|
37
|
+
*/
|
|
38
|
+
export declare function pickNumber(name: string, given: number | undefined, fallback: number, check: (value: number) => boolean, expected: string): number;
|
|
39
|
+
/**
|
|
40
|
+
* A boolean option: the given value when defined, else the fallback; a non-boolean is E_INVALID_ARGUMENT.
|
|
41
|
+
* @param name - the option name
|
|
42
|
+
* @param given - the value given (undefined = absent)
|
|
43
|
+
* @param fallback - the previous record's value or the default
|
|
44
|
+
* @returns the value
|
|
45
|
+
*/
|
|
46
|
+
export declare function pickBoolean(name: string, given: boolean | undefined, fallback: boolean): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* The layout dimension: 2 or 3.
|
|
49
|
+
* @param given - the value given (undefined = absent)
|
|
50
|
+
* @param fallback - the previous record's value or the default
|
|
51
|
+
* @returns 2 or 3
|
|
52
|
+
*/
|
|
53
|
+
export declare function pickDim(given: 2 | 3 | undefined, fallback: 2 | 3): 2 | 3;
|
|
54
|
+
/**
|
|
55
|
+
* The scene-unit center: an array-like of 2 (z = 0) or 3 finite numbers.
|
|
56
|
+
* @param given - the value given (undefined = absent)
|
|
57
|
+
* @param fallback - the previous record's value or the default
|
|
58
|
+
* @returns the three components
|
|
59
|
+
*/
|
|
60
|
+
export declare function pickCenter(given: ArrayLike<number> | undefined, fallback: readonly [number, number, number]): readonly [number, number, number];
|
|
61
|
+
/**
|
|
62
|
+
* The seed: a finite number, or null (unseeded; 0 keeps the port's "0 = unseeded" quirk through the Lcg).
|
|
63
|
+
* @param given - the value given (undefined = absent)
|
|
64
|
+
* @param fallback - the previous record's value or the default
|
|
65
|
+
* @returns the seed or null
|
|
66
|
+
*/
|
|
67
|
+
export declare function pickSeed(given: number | null | undefined, fallback: number | null): number | null;
|
|
68
|
+
/**
|
|
69
|
+
* Integer >= 1.
|
|
70
|
+
* @param value - a finite number
|
|
71
|
+
* @returns whether it is a positive integer
|
|
72
|
+
*/
|
|
73
|
+
export declare function isPositiveInteger(value: number): boolean;
|
|
74
|
+
/**
|
|
75
|
+
* The u32 word written into Fa2Params.seed: 0 for null, else floor(|seed|) mod 2^32.
|
|
76
|
+
* @param seed - the resolved seed
|
|
77
|
+
* @returns the u32 value
|
|
78
|
+
*/
|
|
79
|
+
export declare function seedWord(seed: number | null): number;
|
|
80
|
+
/**
|
|
81
|
+
* A scalar field of a block's read() result.
|
|
82
|
+
* @param values - the values read
|
|
83
|
+
* @param name - the field name
|
|
84
|
+
* @returns the number
|
|
85
|
+
*/
|
|
86
|
+
export declare function scalar(values: UniformValues, name: string): number;
|
|
87
|
+
/**
|
|
88
|
+
* A vector field of a block's read() result.
|
|
89
|
+
* @param values - the values read
|
|
90
|
+
* @param name - the field name
|
|
91
|
+
* @returns the components
|
|
92
|
+
*/
|
|
93
|
+
export declare function vector(values: UniformValues, name: string): readonly number[];
|
|
94
|
+
/**
|
|
95
|
+
* The override record a kernel gets: its defaults overlaid with the values present in the merged set (contract 3.9:
|
|
96
|
+
* a name a spec does not declare is rejected at compose time, so nothing else is passed through).
|
|
97
|
+
* @param merged - the merged override set of the model (plus USE_PERM / HAS_WEIGHTS from the simulation)
|
|
98
|
+
* @param defaults - the kernel's accepted names with their defaults
|
|
99
|
+
* @returns the kernel's override record, every accepted name explicit
|
|
100
|
+
*/
|
|
101
|
+
export declare function subset(merged: Overrides, defaults: Overrides): Overrides;
|
|
102
|
+
//# sourceMappingURL=model-common.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-common.d.ts","sourceRoot":"","sources":["../../../src/layouts/model-common.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE/D,uDAAuD;AACvD,MAAM,MAAM,SAAS,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;AAEnE,uDAAuD;AACvD,eAAO,MAAM,oBAAoB,KAAK,CAAC;AAEvC,2GAA2G;AAC3G,eAAO,MAAM,kBAAkB,eAAe,CAAC;AAK/C;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAcpD;AAED;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,gBAAgB,CAM5F;AAED;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CACtB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,GAAG,SAAS,EACzB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,EACjC,QAAQ,EAAE,MAAM,GACjB,MAAM,CAMR;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,SAAS,EAAE,QAAQ,EAAE,OAAO,GAAG,OAAO,CAMhG;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,GAAG,SAAS,EAAE,QAAQ,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAMxE;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CACtB,KAAK,EAAE,SAAS,CAAC,MAAM,CAAC,GAAG,SAAS,EACpC,QAAQ,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,GAC5C,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CA2BnC;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,GAAG,IAAI,CASjG;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAExD;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAKpD;AAED;;;;;GAKG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAMlE;AAED;;;;;GAKG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAM7E;AAED;;;;;;GAMG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,GAAG,SAAS,CAMxE"}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The option and value helpers every force model's resolver and stats decoder share (PD-7): moved verbatim from
|
|
3
|
+
* src/layouts/forceatlas2.ts (P3-T2) so the Fruchterman-Reingold and spring-electrical models of P5 neither copy
|
|
4
|
+
* them nor import a sibling model. Layout zone; imports errors.ts only.
|
|
5
|
+
*/
|
|
6
|
+
import { WebGpuGraphError } from "../errors.js";
|
|
7
|
+
/** Bytes of the stride-3 f32 force arrays per node. */
|
|
8
|
+
export const FORCE_BYTES_PER_NODE = 12;
|
|
9
|
+
/** The name of the model-owned FillParams buffer (a BufferSpec, reached through ModelResources.buffer). */
|
|
10
|
+
export const FILL_PARAMS_BUFFER = "fillParams";
|
|
11
|
+
/** 2^32, the modulus of the u32 seed word (computed with `%`, never a bitwise operator). */
|
|
12
|
+
const U32_MODULUS = 4294967296;
|
|
13
|
+
/**
|
|
14
|
+
* A short, safe rendering of an argument value for error messages (never String() on an object).
|
|
15
|
+
* @param value - the value
|
|
16
|
+
* @returns the rendering
|
|
17
|
+
*/
|
|
18
|
+
export function describeValue(value) {
|
|
19
|
+
if (value === null) {
|
|
20
|
+
return "null";
|
|
21
|
+
}
|
|
22
|
+
if (typeof value === "number" || typeof value === "boolean" || typeof value === "string") {
|
|
23
|
+
return String(value);
|
|
24
|
+
}
|
|
25
|
+
if (typeof value === "undefined") {
|
|
26
|
+
return "undefined";
|
|
27
|
+
}
|
|
28
|
+
if (typeof value === "object" && "length" in value && typeof value.length === "number") {
|
|
29
|
+
return `[${value.length} values]`;
|
|
30
|
+
}
|
|
31
|
+
return typeof value;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The E_INVALID_ARGUMENT error of an option check (contract 3.1: { argument, value, expected }).
|
|
35
|
+
* @param argument - the option name
|
|
36
|
+
* @param value - the value given
|
|
37
|
+
* @param expected - what was expected
|
|
38
|
+
* @returns the error (not thrown here)
|
|
39
|
+
*/
|
|
40
|
+
export function invalid(argument, value, expected) {
|
|
41
|
+
return new WebGpuGraphError("E_INVALID_ARGUMENT", `${argument} must be ${expected}; got ${describeValue(value)}`, {
|
|
42
|
+
argument,
|
|
43
|
+
value,
|
|
44
|
+
expected,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* A numeric option: the given value when defined, else the fallback; validated by `check` (the value is checked as
|
|
49
|
+
* `unknown` so a JS caller's string or object is E_INVALID_ARGUMENT too).
|
|
50
|
+
* @param name - the option name
|
|
51
|
+
* @param given - the value given (undefined = absent)
|
|
52
|
+
* @param fallback - the previous record's value or the default
|
|
53
|
+
* @param check - the range predicate over a finite number
|
|
54
|
+
* @param expected - the range in words (the error message)
|
|
55
|
+
* @returns the value
|
|
56
|
+
*/
|
|
57
|
+
export function pickNumber(name, given, fallback, check, expected) {
|
|
58
|
+
const value = given === undefined ? fallback : given;
|
|
59
|
+
if (typeof value !== "number" || !Number.isFinite(value) || !check(value)) {
|
|
60
|
+
throw invalid(name, value, expected);
|
|
61
|
+
}
|
|
62
|
+
return value;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* A boolean option: the given value when defined, else the fallback; a non-boolean is E_INVALID_ARGUMENT.
|
|
66
|
+
* @param name - the option name
|
|
67
|
+
* @param given - the value given (undefined = absent)
|
|
68
|
+
* @param fallback - the previous record's value or the default
|
|
69
|
+
* @returns the value
|
|
70
|
+
*/
|
|
71
|
+
export function pickBoolean(name, given, fallback) {
|
|
72
|
+
const value = given === undefined ? fallback : given;
|
|
73
|
+
if (typeof value !== "boolean") {
|
|
74
|
+
throw invalid(name, value, "a boolean");
|
|
75
|
+
}
|
|
76
|
+
return value;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* The layout dimension: 2 or 3.
|
|
80
|
+
* @param given - the value given (undefined = absent)
|
|
81
|
+
* @param fallback - the previous record's value or the default
|
|
82
|
+
* @returns 2 or 3
|
|
83
|
+
*/
|
|
84
|
+
export function pickDim(given, fallback) {
|
|
85
|
+
const value = given === undefined ? fallback : given;
|
|
86
|
+
if (value !== 2 && value !== 3) {
|
|
87
|
+
throw invalid("dim", value, "2 or 3");
|
|
88
|
+
}
|
|
89
|
+
return value;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* The scene-unit center: an array-like of 2 (z = 0) or 3 finite numbers.
|
|
93
|
+
* @param given - the value given (undefined = absent)
|
|
94
|
+
* @param fallback - the previous record's value or the default
|
|
95
|
+
* @returns the three components
|
|
96
|
+
*/
|
|
97
|
+
export function pickCenter(given, fallback) {
|
|
98
|
+
if (given === undefined) {
|
|
99
|
+
return fallback;
|
|
100
|
+
}
|
|
101
|
+
const expected = "an array of 2 or 3 finite numbers";
|
|
102
|
+
const value = given;
|
|
103
|
+
if (typeof value !== "object" || value === null || !("length" in value)) {
|
|
104
|
+
throw invalid("center", given, expected);
|
|
105
|
+
}
|
|
106
|
+
const { length } = value;
|
|
107
|
+
if (length !== 2 && length !== 3) {
|
|
108
|
+
throw invalid("center", given, expected);
|
|
109
|
+
}
|
|
110
|
+
const x = given[0];
|
|
111
|
+
const y = given[1];
|
|
112
|
+
const z = length === 3 ? given[2] : 0;
|
|
113
|
+
if (typeof x !== "number" ||
|
|
114
|
+
typeof y !== "number" ||
|
|
115
|
+
typeof z !== "number" ||
|
|
116
|
+
!Number.isFinite(x) ||
|
|
117
|
+
!Number.isFinite(y) ||
|
|
118
|
+
!Number.isFinite(z)) {
|
|
119
|
+
throw invalid("center", given, expected);
|
|
120
|
+
}
|
|
121
|
+
return [x, y, z];
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* The seed: a finite number, or null (unseeded; 0 keeps the port's "0 = unseeded" quirk through the Lcg).
|
|
125
|
+
* @param given - the value given (undefined = absent)
|
|
126
|
+
* @param fallback - the previous record's value or the default
|
|
127
|
+
* @returns the seed or null
|
|
128
|
+
*/
|
|
129
|
+
export function pickSeed(given, fallback) {
|
|
130
|
+
if (given === undefined) {
|
|
131
|
+
return fallback;
|
|
132
|
+
}
|
|
133
|
+
const value = given;
|
|
134
|
+
if (value !== null && (typeof value !== "number" || !Number.isFinite(value))) {
|
|
135
|
+
throw invalid("seed", given, "a finite number or null");
|
|
136
|
+
}
|
|
137
|
+
return value;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Integer >= 1.
|
|
141
|
+
* @param value - a finite number
|
|
142
|
+
* @returns whether it is a positive integer
|
|
143
|
+
*/
|
|
144
|
+
export function isPositiveInteger(value) {
|
|
145
|
+
return Number.isInteger(value) && value >= 1;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* The u32 word written into Fa2Params.seed: 0 for null, else floor(|seed|) mod 2^32.
|
|
149
|
+
* @param seed - the resolved seed
|
|
150
|
+
* @returns the u32 value
|
|
151
|
+
*/
|
|
152
|
+
export function seedWord(seed) {
|
|
153
|
+
if (seed === null) {
|
|
154
|
+
return 0;
|
|
155
|
+
}
|
|
156
|
+
return Math.floor(Math.abs(seed)) % U32_MODULUS;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* A scalar field of a block's read() result.
|
|
160
|
+
* @param values - the values read
|
|
161
|
+
* @param name - the field name
|
|
162
|
+
* @returns the number
|
|
163
|
+
*/
|
|
164
|
+
export function scalar(values, name) {
|
|
165
|
+
const value = values[name];
|
|
166
|
+
if (typeof value !== "number") {
|
|
167
|
+
throw invalid(name, value, "a scalar field");
|
|
168
|
+
}
|
|
169
|
+
return value;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* A vector field of a block's read() result.
|
|
173
|
+
* @param values - the values read
|
|
174
|
+
* @param name - the field name
|
|
175
|
+
* @returns the components
|
|
176
|
+
*/
|
|
177
|
+
export function vector(values, name) {
|
|
178
|
+
const value = values[name];
|
|
179
|
+
if (typeof value === "number") {
|
|
180
|
+
throw invalid(name, value, "a vector field");
|
|
181
|
+
}
|
|
182
|
+
return value;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* The override record a kernel gets: its defaults overlaid with the values present in the merged set (contract 3.9:
|
|
186
|
+
* a name a spec does not declare is rejected at compose time, so nothing else is passed through).
|
|
187
|
+
* @param merged - the merged override set of the model (plus USE_PERM / HAS_WEIGHTS from the simulation)
|
|
188
|
+
* @param defaults - the kernel's accepted names with their defaults
|
|
189
|
+
* @returns the kernel's override record, every accepted name explicit
|
|
190
|
+
*/
|
|
191
|
+
export function subset(merged, defaults) {
|
|
192
|
+
const out = {};
|
|
193
|
+
for (const name of Object.keys(defaults)) {
|
|
194
|
+
out[name] = name in merged ? merged[name] : defaults[name];
|
|
195
|
+
}
|
|
196
|
+
return out;
|
|
197
|
+
}
|
|
198
|
+
//# sourceMappingURL=model-common.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-common.js","sourceRoot":"","sources":["../../../src/layouts/model-common.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAMhD,uDAAuD;AACvD,MAAM,CAAC,MAAM,oBAAoB,GAAG,EAAE,CAAC;AAEvC,2GAA2G;AAC3G,MAAM,CAAC,MAAM,kBAAkB,GAAG,YAAY,CAAC;AAE/C,4FAA4F;AAC5F,MAAM,WAAW,GAAG,UAAU,CAAC;AAE/B;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,KAAc;IACxC,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACjB,OAAO,MAAM,CAAC;IAClB,CAAC;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,SAAS,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACvF,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;IACzB,CAAC;IACD,IAAI,OAAO,KAAK,KAAK,WAAW,EAAE,CAAC;QAC/B,OAAO,WAAW,CAAC;IACvB,CAAC;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,QAAQ,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;QACrF,OAAO,IAAI,KAAK,CAAC,MAAM,UAAU,CAAC;IACtC,CAAC;IACD,OAAO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I,EAAE,KAAK,EAAE,gBAAgB,CAAC,CAAC;IACjD,CAAC;IACD,OAAO,KAAK,CAAC;AACjB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,MAAM,CAAC,MAAqB,EAAE,IAAY;IACtD,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;IAC3B,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC5B,MAAM,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE,gBAAgB,CAAC,CAAC;IACjD,CAAC;IACD,OAAO,KAAK,CAAC;AACjB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,MAAM,CAAC,MAAiB,EAAE,QAAmB;IACzD,MAAM,GAAG,GAAqC,EAAE,CAAC;IACjD,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;QACvC,GAAG,CAAC,IAAI,CAAC,GAAG,IAAI,IAAI,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC/D,CAAC;IACD,OAAO,GAAG,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The spring-electrical preset on the exact repulsion tier (spec 7.20 "the preset"; contract 3.13): ngraph.forcelayout's
|
|
3
|
+
* physics under ngraph's option names and defaults -- Coulomb repulsion `-g m_i m_j / d^2` (K3, LAW 2), Hooke springs
|
|
4
|
+
* `k_s (d - L)` (K2, LAW 2), drag and the semi-implicit Euler step with the unit speed clamp over a per-node velocity
|
|
5
|
+
* (K5, APPLY 2), the kinetic energy folded into the trace (K1, STATS_MODE 2; PD-4) -- as the ForceModel that
|
|
6
|
+
* ForceSimulation drives over the four FA2 kernels K1 K2 K3 K5 per iteration and toScene per batch. No K4: there is no
|
|
7
|
+
* speed controller. The velocity is the model's `velocity` buffer bound into the `oldForce` slot of K3 and K5 (PD-2),
|
|
8
|
+
* left alone by the FA2 text because the model compiles `SWING_MODE = 1` (PD-20). Mass is `1 + degree / 3` and the
|
|
9
|
+
* weights are ignored (PD-11); `SpringElectricalOptions.gravity` is ngraph's Coulomb constant, written into
|
|
10
|
+
* `Fa2Params.coulomb` while FA2's centre gravity is 0 (PD-12). Settlement is the shared rule of spec 7.17
|
|
11
|
+
* (DEP-P5-A); `reheat()` leaves the velocities alone (ngraph has no reheat).
|
|
12
|
+
*
|
|
13
|
+
* Model decisions this file shares with forceatlas2.ts: the K1-K5 dispatches of one batch share ONE compute pass and
|
|
14
|
+
* toScene runs in a second pass that ends it; the fill kernel takes its FillParams from a model-owned 256-byte uniform
|
|
15
|
+
* buffer; `repulsion: "grid"` is E_UNSUPPORTED at load() (the simulation's tier rule).
|
|
16
|
+
*/
|
|
17
|
+
import { type GraphSnapshot } from "@graphty/graph-format";
|
|
18
|
+
import { type GpuContext } from "../context.js";
|
|
19
|
+
import { type CommandBatch } from "../kernel/batch.js";
|
|
20
|
+
import { type UniformBlock, type UniformValues } from "../kernel/struct-block.js";
|
|
21
|
+
import { type WgslModuleSpec } from "../kernel/wgsl.js";
|
|
22
|
+
import { type GpuLayoutSimulation, type GpuLayoutTuning, type ResolvedLayoutTuning, type SpringElectricalStats } from "../types/layout.js";
|
|
23
|
+
import { type ResolvedSpringElectricalOptions, type SpringElectricalOptions } from "../types/options.js";
|
|
24
|
+
import { type BufferSpec, type ForceModel, type ModelInputs, type ModelResources, type StateWriter } from "./force-simulation.js";
|
|
25
|
+
import { type Overrides } from "./model-common.js";
|
|
26
|
+
/**
|
|
27
|
+
* The size factor of the default force constants: 1 up to SE_SCALE_REFERENCE_NODES nodes (ngraph's constants as
|
|
28
|
+
* they are), then SE_SCALE_REFERENCE_NODES / n, so the per-node force stays at the level ngraph's constants were
|
|
29
|
+
* tuned for instead of pinning every node at the unit speed clamp.
|
|
30
|
+
* @param n - the node count
|
|
31
|
+
* @returns the factor in (0, 1]
|
|
32
|
+
*/
|
|
33
|
+
export declare function springSizeFactor(n: number): number;
|
|
34
|
+
/**
|
|
35
|
+
* Applies SE_DEFAULTS to the option record; validates ranges (spec 7.20; ngraph's constraints): `springLength` > 0,
|
|
36
|
+
* `springCoefficient` > 0, `dragCoefficient` >= 0, `timeStep` > 0, `gravity` any finite number (negative repels; ngraph's
|
|
37
|
+
* comment: "if you make it positive nodes start attract each other"). `gravity` and `springCoefficient` left out (or
|
|
38
|
+
* null) resolve to null: ngraph's constant times springSizeFactor(n), applied in paramsFor once n is known. With `previous` the record is a PATCH over it and
|
|
39
|
+
* `maxInFlight` may not change (the uniform ring is sized by it at construction).
|
|
40
|
+
* @param options - the caller's options (or a setParams patch)
|
|
41
|
+
* @param previous - the current resolved record when resolving a patch
|
|
42
|
+
* @returns the frozen resolved record
|
|
43
|
+
*/
|
|
44
|
+
export declare function resolveSpringElectricalOptions(options: SpringElectricalOptions | undefined, previous?: ResolvedSpringElectricalOptions): ResolvedSpringElectricalOptions;
|
|
45
|
+
/** The spring-electrical model (spec 7.20: K1 K2 K3 K5 per iteration; toScene once per batch). Stages: ["K1", "K2", "K3", "K5", "toScene"]. */
|
|
46
|
+
export declare class SpringElectricalModel implements ForceModel<SpringElectricalOptions, SpringElectricalStats> {
|
|
47
|
+
/** The model kind of spec 7.19. */
|
|
48
|
+
readonly kind = "springElectrical";
|
|
49
|
+
/** The stage names in dispatch order (the `upTo` vocabulary of recordIteration and debugRunStages). */
|
|
50
|
+
readonly stages: readonly ["K1", "K2", "K3", "K5", "toScene"];
|
|
51
|
+
/** Fa2Params: the per-iteration uniform block (the simulation writes the shared fields into it). */
|
|
52
|
+
readonly params: UniformBlock;
|
|
53
|
+
/** Fa2State: the state header block. */
|
|
54
|
+
readonly state: UniformBlock;
|
|
55
|
+
/** Fa2Trace: one record per iteration of a batch. */
|
|
56
|
+
readonly trace: UniformBlock;
|
|
57
|
+
/** The resolved GPU-only tuning this model was created with (only `repulsion` / `exactMaxNodes` / `nearMax` / `extentFactor` matter here). */
|
|
58
|
+
readonly tuning: ResolvedLayoutTuning;
|
|
59
|
+
/** The option record the model holds: the constructor's record, replaced by onSetParams() ONLY (the query hooks never assign it). */
|
|
60
|
+
private current;
|
|
61
|
+
/** The resources of the last bind(), or null before the first. */
|
|
62
|
+
private resources;
|
|
63
|
+
/** The kernels and bind groups of the last bind(), or null before it (and for n === 0). */
|
|
64
|
+
private bound;
|
|
65
|
+
/** The K1-K5 compute pass of the batch being recorded, keyed by CommandBatch.id; null between batches. */
|
|
66
|
+
private openPass;
|
|
67
|
+
/**
|
|
68
|
+
* Creates the model for one simulation.
|
|
69
|
+
* @param tuning - the resolved GPU-only tuning
|
|
70
|
+
* @param resolved - the resolved option record at creation
|
|
71
|
+
*/
|
|
72
|
+
constructor(tuning: ResolvedLayoutTuning, resolved: ResolvedSpringElectricalOptions);
|
|
73
|
+
/**
|
|
74
|
+
* force 12n (zeroed), velocity 12n (zeroed: every load() starts at rest, `allocate()` / `clearKept()` honour
|
|
75
|
+
* `zero`) and the 256-byte FillParams uniform buffer. n = 0 reports one node's worth of bytes so no zero-length
|
|
76
|
+
* buffer is ever created.
|
|
77
|
+
* @param n - the node count
|
|
78
|
+
* @param _dim - the layout dimension (the arrays are stride 3 in both)
|
|
79
|
+
* @returns the three model-owned buffer specs
|
|
80
|
+
*/
|
|
81
|
+
buffers(n: number, _dim: 2 | 3): readonly BufferSpec[];
|
|
82
|
+
/**
|
|
83
|
+
* { mass: 1 + degree / 3, weights: none } (PD-11): the preset has no mass or weight option, and K2 compiles
|
|
84
|
+
* HAS_WEIGHTS = false. No `fixed` (setFixed is the live API). The tier rule is the simulation's (load() throws
|
|
85
|
+
* E_UNSUPPORTED for the grid tier before calling this).
|
|
86
|
+
* @param s - the snapshot being loaded
|
|
87
|
+
* @param _options - the simulation's current option record (unused: nothing in it affects the inputs)
|
|
88
|
+
* @returns the per-load inputs
|
|
89
|
+
*/
|
|
90
|
+
inputs(s: GraphSnapshot, _options: SpringElectricalOptions): ModelInputs;
|
|
91
|
+
/**
|
|
92
|
+
* The constant SE_OVERRIDES (PD-1): no option changes a law, so setParams never recompiles.
|
|
93
|
+
* @param _options - an option record (unused)
|
|
94
|
+
* @returns the model's own override set
|
|
95
|
+
*/
|
|
96
|
+
overrides(_options: SpringElectricalOptions): Overrides;
|
|
97
|
+
/**
|
|
98
|
+
* The six module specs of an override set in dispatch order -- K1, K2, K3, K5, toScene, fill -- each with only the
|
|
99
|
+
* override names its entry declares (K2 also USE_PERM / HAS_WEIGHTS), for warm() and the compile matrix.
|
|
100
|
+
* @param overrides - the merged override set (the model's plus USE_PERM / HAS_WEIGHTS)
|
|
101
|
+
* @param _subgroups - accepted for the ForceModel interface and unused (the composer picks the twin from caps)
|
|
102
|
+
* @returns the specs
|
|
103
|
+
*/
|
|
104
|
+
specs(overrides: Overrides, _subgroups: boolean): readonly WgslModuleSpec[];
|
|
105
|
+
/**
|
|
106
|
+
* Compiles (through the cache) and binds every kernel against the buffers of this load(): K1, K2 (or the fill of
|
|
107
|
+
* force when arcCount === 0), K3 and K5 with the velocity in their `oldForce` slot (PD-2), toScene; writes the
|
|
108
|
+
* FillParams { count: 3n, value: 0, mode: 0 } into the model's uniform buffer. With n === 0 nothing is bound.
|
|
109
|
+
* @param resources - the graph, the shared and model buffers, the ring and the cache
|
|
110
|
+
* @param overrides - the merged override set
|
|
111
|
+
*/
|
|
112
|
+
bind(resources: ModelResources, overrides: Overrides): Promise<void>;
|
|
113
|
+
/**
|
|
114
|
+
* The Fa2Params values of one iteration: the shared fields, the FA2 fields at 0 (no centre gravity, PD-12; no
|
|
115
|
+
* FR temperature) and ngraph's five constants with `gravity` in `coulomb`.
|
|
116
|
+
* @param iteration - the global iteration index
|
|
117
|
+
* @param options - the simulation's current option record
|
|
118
|
+
* @returns the uniform values
|
|
119
|
+
*/
|
|
120
|
+
paramsFor(iteration: number, options: SpringElectricalOptions): UniformValues;
|
|
121
|
+
/**
|
|
122
|
+
* Records one iteration into the batch: K1, K2 (or the fill of force when arcCount === 0), K3, K5 in the batch's
|
|
123
|
+
* ONE K1-K5 compute pass, then toScene in a second pass that ends it, stopping after stage `upTo` when given.
|
|
124
|
+
* With n === 0 nothing is recorded; a call before bind() completed is E_NOT_LOADED.
|
|
125
|
+
* @param batch - the batch being recorded
|
|
126
|
+
* @param slot - the UniformRing slot holding this iteration's Fa2Params
|
|
127
|
+
* @param tier - "exact" (the grid tier is E_UNSUPPORTED; the simulation never passes "grid")
|
|
128
|
+
* @param upTo - a stage name to stop after; undefined records every stage including toScene
|
|
129
|
+
*/
|
|
130
|
+
recordIteration(batch: CommandBatch, slot: number, tier: "exact" | "grid", upTo?: string): void;
|
|
131
|
+
/**
|
|
132
|
+
* kineticEnergy = 0 and temperature = 0 in the header (the velocities start at 0 through the buffer's `zero`).
|
|
133
|
+
* @param state - the state writer of the simulation
|
|
134
|
+
*/
|
|
135
|
+
onLoad(state: StateWriter): void;
|
|
136
|
+
/**
|
|
137
|
+
* Nothing: the velocities carry on (ngraph has no reheat; a drag lands in the next batch through the override
|
|
138
|
+
* list, spec 7.12).
|
|
139
|
+
* @param _state - the state writer of the simulation (unused)
|
|
140
|
+
*/
|
|
141
|
+
onReheat(_state: StateWriter): void;
|
|
142
|
+
/**
|
|
143
|
+
* Replaces the record with the patch applied (every option is a numeric tweak; nothing recompiles, no reset).
|
|
144
|
+
* @param patch - the setParams patch
|
|
145
|
+
* @param _state - the state writer of the simulation (unused)
|
|
146
|
+
*/
|
|
147
|
+
onSetParams(patch: Partial<SpringElectricalOptions>, _state: StateWriter): void;
|
|
148
|
+
/**
|
|
149
|
+
* Decodes the state header and the k trace records of a completed batch into SpringElectricalStats: the exact
|
|
150
|
+
* tier with null grid fields; msPerIteration null (the simulation owns the clock); `kineticEnergy` is the last
|
|
151
|
+
* folded value (one iteration behind the last integrate, PD-4).
|
|
152
|
+
* @param state - a DataView over the 256-byte state header
|
|
153
|
+
* @param trace - a DataView over the k Fa2Trace records of the batch
|
|
154
|
+
* @returns the stats
|
|
155
|
+
*/
|
|
156
|
+
readStats(state: DataView, trace: DataView): SpringElectricalStats;
|
|
157
|
+
/**
|
|
158
|
+
* The resources of the last bind(), or E_NOT_LOADED before it.
|
|
159
|
+
* @returns the resources
|
|
160
|
+
*/
|
|
161
|
+
private requireResources;
|
|
162
|
+
/**
|
|
163
|
+
* The index of a stage name in SE_STAGES, or E_INVALID_ARGUMENT.
|
|
164
|
+
* @param upTo - the stage name
|
|
165
|
+
* @returns its index
|
|
166
|
+
*/
|
|
167
|
+
private stageIndex;
|
|
168
|
+
/** Drops the bind groups of the previous bind() (the buffers changed) and forgets the pass of a batch recorded before the rebind. */
|
|
169
|
+
private dropBound;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Spec 3.3 createSpringElectrical, verbatim: a GpuLayoutSimulation running ngraph's spring-electrical model on the
|
|
173
|
+
* exact repulsion tier with ngraph's defaults (spec 7.20) and the GPU-only tuning of GpuLayoutTuning.
|
|
174
|
+
* @param ctx - the context (E_DISPOSED / E_DEVICE_LOST through assertReady)
|
|
175
|
+
* @param options - the spring-electrical options and the GPU-only tuning knobs in one record
|
|
176
|
+
* @returns the simulation in state "created"; load() next
|
|
177
|
+
*/
|
|
178
|
+
export declare function createSpringElectrical(ctx: GpuContext, options?: SpringElectricalOptions & GpuLayoutTuning): GpuLayoutSimulation<SpringElectricalOptions, SpringElectricalStats>;
|
|
179
|
+
//# sourceMappingURL=spring-electrical.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spring-electrical.d.ts","sourceRoot":"","sources":["../../../src/layouts/spring-electrical.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAS3D,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,eAAe,CAAC;AAGhD,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGv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