@luma.gl/graph 10.0.0-beta.2 → 10.0.0-beta.3
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/dist/arrow/gpu/arrow-gpu-analytics-adapters.cjs +22 -9
- package/dist/arrow/gpu/arrow-gpu-analytics-adapters.d.ts +11 -2
- package/dist/arrow/gpu/arrow-gpu-analytics-adapters.d.ts.map +1 -1
- package/dist/arrow/gpu/arrow-gpu-analytics-adapters.js +27 -10
- package/dist/arrow/gpu/arrow-gpu-analytics-adapters.js.map +1 -1
- package/dist/arrow/gpu/arrow-gpu-analytics-readback.cjs +24 -13
- package/dist/arrow/gpu/arrow-gpu-analytics-readback.d.ts +9 -1
- package/dist/arrow/gpu/arrow-gpu-analytics-readback.d.ts.map +1 -1
- package/dist/arrow/gpu/arrow-gpu-analytics-readback.js +41 -14
- package/dist/arrow/gpu/arrow-gpu-analytics-readback.js.map +1 -1
- package/dist/arrow/gpu/arrow-gpu-table-conversion.cjs +24 -1
- package/dist/arrow/gpu/arrow-gpu-table-conversion.d.ts +10 -1
- package/dist/arrow/gpu/arrow-gpu-table-conversion.d.ts.map +1 -1
- package/dist/arrow/gpu/arrow-gpu-table-conversion.js +29 -1
- package/dist/arrow/gpu/arrow-gpu-table-conversion.js.map +1 -1
- package/dist/arrow/index.cjs +2 -0
- package/dist/arrow/index.cjs.map +3 -3
- package/dist/arrow/index.d.ts +1 -1
- package/dist/arrow/index.d.ts.map +1 -1
- package/dist/arrow/index.js +1 -1
- package/dist/arrow/index.js.map +1 -1
- package/dist/gpu-core/gpu-bvh-bounds.cjs +63 -0
- package/dist/gpu-core/gpu-bvh-bounds.d.ts +32 -0
- package/dist/gpu-core/gpu-bvh-bounds.d.ts.map +1 -0
- package/dist/gpu-core/gpu-bvh-bounds.js +56 -0
- package/dist/gpu-core/gpu-bvh-bounds.js.map +1 -0
- package/dist/gpu-core/gpu-command-graph-submission-pacer.cjs +92 -0
- package/dist/gpu-core/gpu-command-graph-submission-pacer.d.ts +41 -0
- package/dist/gpu-core/gpu-command-graph-submission-pacer.d.ts.map +1 -0
- package/dist/gpu-core/gpu-command-graph-submission-pacer.js +85 -0
- package/dist/gpu-core/gpu-command-graph-submission-pacer.js.map +1 -0
- package/dist/gpu-core/index.cjs +6 -0
- package/dist/gpu-core/index.cjs.map +3 -3
- package/dist/gpu-core/index.d.ts +4 -0
- package/dist/gpu-core/index.d.ts.map +1 -1
- package/dist/gpu-core/index.js +2 -0
- package/dist/gpu-core/index.js.map +1 -1
- package/dist/gpu-dataframe/gpu-analytics-compiler-utils.cjs +6 -6
- package/dist/gpu-dataframe/gpu-analytics-compiler-utils.d.ts +1 -1
- package/dist/gpu-dataframe/gpu-analytics-compiler-utils.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-analytics-compiler-utils.js +6 -6
- package/dist/gpu-dataframe/gpu-analytics-compiler-utils.js.map +1 -1
- package/dist/gpu-dataframe/gpu-data-frame-query.cjs +55 -14
- package/dist/gpu-dataframe/gpu-data-frame-query.d.ts +13 -2
- package/dist/gpu-dataframe/gpu-data-frame-query.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-data-frame-query.js +58 -17
- package/dist/gpu-dataframe/gpu-data-frame-query.js.map +1 -1
- package/dist/gpu-dataframe/gpu-data-frame.cjs +1 -3
- package/dist/gpu-dataframe/gpu-data-frame.d.ts +10 -0
- package/dist/gpu-dataframe/gpu-data-frame.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-data-frame.js +1 -3
- package/dist/gpu-dataframe/gpu-data-frame.js.map +1 -1
- package/dist/gpu-dataframe/gpu-expression-shader.cjs +94 -44
- package/dist/gpu-dataframe/gpu-expression-shader.d.ts +8 -5
- package/dist/gpu-dataframe/gpu-expression-shader.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-expression-shader.js +110 -47
- package/dist/gpu-dataframe/gpu-expression-shader.js.map +1 -1
- package/dist/gpu-dataframe/gpu-expression.cjs +14 -8
- package/dist/gpu-dataframe/gpu-expression.d.ts +12 -1
- package/dist/gpu-dataframe/gpu-expression.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-expression.js +11 -6
- package/dist/gpu-dataframe/gpu-expression.js.map +1 -1
- package/dist/gpu-dataframe/gpu-global-aggregation-compiler.cjs +2 -2
- package/dist/gpu-dataframe/gpu-global-aggregation-compiler.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-global-aggregation-compiler.js +4 -2
- package/dist/gpu-dataframe/gpu-global-aggregation-compiler.js.map +1 -1
- package/dist/gpu-dataframe/gpu-global-aggregation-query.cjs +2 -2
- package/dist/gpu-dataframe/gpu-global-aggregation-query.d.ts +5 -1
- package/dist/gpu-dataframe/gpu-global-aggregation-query.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-global-aggregation-query.js +6 -2
- package/dist/gpu-dataframe/gpu-global-aggregation-query.js.map +1 -1
- package/dist/gpu-dataframe/gpu-global-sort-compiler.cjs +113 -88
- package/dist/gpu-dataframe/gpu-global-sort-compiler.d.ts +6 -1
- package/dist/gpu-dataframe/gpu-global-sort-compiler.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-global-sort-compiler.js +111 -85
- package/dist/gpu-dataframe/gpu-global-sort-compiler.js.map +1 -1
- package/dist/gpu-dataframe/gpu-group-aggregation-compiler.cjs +286 -48
- package/dist/gpu-dataframe/gpu-group-aggregation-compiler.d.ts +17 -2
- package/dist/gpu-dataframe/gpu-group-aggregation-compiler.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-group-aggregation-compiler.js +290 -39
- package/dist/gpu-dataframe/gpu-group-aggregation-compiler.js.map +1 -1
- package/dist/gpu-dataframe/gpu-group-by-query.cjs +8 -6
- package/dist/gpu-dataframe/gpu-group-by-query.d.ts +7 -1
- package/dist/gpu-dataframe/gpu-group-by-query.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-group-by-query.js +9 -5
- package/dist/gpu-dataframe/gpu-group-by-query.js.map +1 -1
- package/dist/gpu-dataframe/gpu-join-compiler.cjs +8 -6
- package/dist/gpu-dataframe/gpu-join-compiler.d.ts +1 -1
- package/dist/gpu-dataframe/gpu-join-compiler.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-join-compiler.js +9 -7
- package/dist/gpu-dataframe/gpu-join-compiler.js.map +1 -1
- package/dist/gpu-dataframe/gpu-query-compiler.cjs +37 -11
- package/dist/gpu-dataframe/gpu-query-compiler.d.ts +3 -1
- package/dist/gpu-dataframe/gpu-query-compiler.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-query-compiler.js +36 -10
- package/dist/gpu-dataframe/gpu-query-compiler.js.map +1 -1
- package/dist/gpu-dataframe/index.cjs +4 -2
- package/dist/gpu-dataframe/index.cjs.map +3 -3
- package/dist/gpu-dataframe/index.d.ts +1 -1
- package/dist/gpu-dataframe/index.d.ts.map +1 -1
- package/dist/gpu-dataframe/index.js +1 -1
- package/dist/gpu-dataframe/index.js.map +1 -1
- package/dist/gpu-physics/gpu-physics-batch.cjs +11 -10
- package/dist/gpu-physics/gpu-physics-batch.d.ts +1 -0
- package/dist/gpu-physics/gpu-physics-batch.d.ts.map +1 -1
- package/dist/gpu-physics/gpu-physics-batch.js +14 -10
- package/dist/gpu-physics/gpu-physics-batch.js.map +1 -1
- package/dist/gpu-physics/gpu-physics-ensemble.cjs +9 -4
- package/dist/gpu-physics/gpu-physics-ensemble.d.ts +10 -1
- package/dist/gpu-physics/gpu-physics-ensemble.d.ts.map +1 -1
- package/dist/gpu-physics/gpu-physics-ensemble.js +11 -4
- package/dist/gpu-physics/gpu-physics-ensemble.js.map +1 -1
- package/dist/gpu-physics/gpu-rigid-body-world.cjs +261 -68
- package/dist/gpu-physics/gpu-rigid-body-world.d.ts +47 -2
- package/dist/gpu-physics/gpu-rigid-body-world.d.ts.map +1 -1
- package/dist/gpu-physics/gpu-rigid-body-world.js +324 -75
- package/dist/gpu-physics/gpu-rigid-body-world.js.map +1 -1
- package/dist/gpu-physics/index.cjs.map +3 -3
- package/dist/gpu-physics/index.d.ts +2 -1
- package/dist/gpu-physics/index.d.ts.map +1 -1
- package/dist/gpu-physics/index.js.map +1 -1
- package/dist/gpu-physics/rigid-body-cache-shaders.cjs +10 -6
- package/dist/gpu-physics/rigid-body-cache-shaders.d.ts +2 -1
- package/dist/gpu-physics/rigid-body-cache-shaders.d.ts.map +1 -1
- package/dist/gpu-physics/rigid-body-cache-shaders.js +15 -6
- package/dist/gpu-physics/rigid-body-cache-shaders.js.map +1 -1
- package/dist/gpu-physics/rigid-body-capacity.cjs +15 -2
- package/dist/gpu-physics/rigid-body-capacity.d.ts +3 -1
- package/dist/gpu-physics/rigid-body-capacity.d.ts.map +1 -1
- package/dist/gpu-physics/rigid-body-capacity.js +21 -2
- package/dist/gpu-physics/rigid-body-capacity.js.map +1 -1
- package/dist/gpu-physics/rigid-body-cast-index.cjs +192 -0
- package/dist/gpu-physics/rigid-body-cast-index.d.ts +44 -0
- package/dist/gpu-physics/rigid-body-cast-index.d.ts.map +1 -0
- package/dist/gpu-physics/rigid-body-cast-index.js +194 -0
- package/dist/gpu-physics/rigid-body-cast-index.js.map +1 -0
- package/dist/gpu-physics/rigid-body-ensemble-layout.cjs +4 -2
- package/dist/gpu-physics/rigid-body-ensemble-layout.d.ts +2 -1
- package/dist/gpu-physics/rigid-body-ensemble-layout.d.ts.map +1 -1
- package/dist/gpu-physics/rigid-body-ensemble-layout.js +5 -2
- package/dist/gpu-physics/rigid-body-ensemble-layout.js.map +1 -1
- package/dist/gpu-physics/rigid-body-ensemble-reset.cjs +11 -9
- package/dist/gpu-physics/rigid-body-ensemble-reset.d.ts +1 -1
- package/dist/gpu-physics/rigid-body-ensemble-reset.d.ts.map +1 -1
- package/dist/gpu-physics/rigid-body-ensemble-reset.js +13 -9
- package/dist/gpu-physics/rigid-body-ensemble-reset.js.map +1 -1
- package/dist/gpu-physics/rigid-body-ensemble-shaders.cjs +14 -7
- package/dist/gpu-physics/rigid-body-ensemble-shaders.d.ts +5 -0
- package/dist/gpu-physics/rigid-body-ensemble-shaders.d.ts.map +1 -1
- package/dist/gpu-physics/rigid-body-ensemble-shaders.js +17 -7
- package/dist/gpu-physics/rigid-body-ensemble-shaders.js.map +1 -1
- package/dist/gpu-physics/rigid-body-ensemble-transaction.cjs +21 -11
- package/dist/gpu-physics/rigid-body-ensemble-transaction.d.ts +2 -2
- package/dist/gpu-physics/rigid-body-ensemble-transaction.d.ts.map +1 -1
- package/dist/gpu-physics/rigid-body-ensemble-transaction.js +28 -12
- package/dist/gpu-physics/rigid-body-ensemble-transaction.js.map +1 -1
- package/dist/gpu-physics/rigid-body-event-compaction.cjs +184 -0
- package/dist/gpu-physics/rigid-body-event-compaction.d.ts +35 -0
- package/dist/gpu-physics/rigid-body-event-compaction.d.ts.map +1 -0
- package/dist/gpu-physics/rigid-body-event-compaction.js +168 -0
- package/dist/gpu-physics/rigid-body-event-compaction.js.map +1 -0
- package/dist/gpu-physics/rigid-body-event-snapshot.cjs +51 -0
- package/dist/gpu-physics/rigid-body-event-snapshot.d.ts +33 -0
- package/dist/gpu-physics/rigid-body-event-snapshot.d.ts.map +1 -0
- package/dist/gpu-physics/rigid-body-event-snapshot.js +34 -0
- package/dist/gpu-physics/rigid-body-event-snapshot.js.map +1 -0
- package/dist/gpu-physics/rigid-body-events.cjs +57 -25
- package/dist/gpu-physics/rigid-body-events.d.ts +2 -1
- package/dist/gpu-physics/rigid-body-events.d.ts.map +1 -1
- package/dist/gpu-physics/rigid-body-events.js +60 -25
- package/dist/gpu-physics/rigid-body-events.js.map +1 -1
- package/dist/gpu-physics/rigid-body-joints.cjs +8 -3
- package/dist/gpu-physics/rigid-body-joints.d.ts.map +1 -1
- package/dist/gpu-physics/rigid-body-joints.js +10 -6
- package/dist/gpu-physics/rigid-body-joints.js.map +1 -1
- package/dist/gpu-physics/rigid-body-queries.cjs +159 -16
- package/dist/gpu-physics/rigid-body-queries.d.ts +24 -1
- package/dist/gpu-physics/rigid-body-queries.d.ts.map +1 -1
- package/dist/gpu-physics/rigid-body-queries.js +166 -14
- package/dist/gpu-physics/rigid-body-queries.js.map +1 -1
- package/dist/gpu-physics/rigid-body-shaders.cjs +3 -3
- package/dist/gpu-physics/rigid-body-shaders.d.ts +1 -1
- package/dist/gpu-physics/rigid-body-shaders.d.ts.map +1 -1
- package/dist/gpu-physics/rigid-body-shaders.js +3 -3
- package/dist/gpu-physics/rigid-body-shaders.js.map +1 -1
- package/dist/gpu-physics/rigid-body-triggers.cjs +53 -15
- package/dist/gpu-physics/rigid-body-triggers.d.ts +1 -0
- package/dist/gpu-physics/rigid-body-triggers.d.ts.map +1 -1
- package/dist/gpu-physics/rigid-body-triggers.js +55 -15
- package/dist/gpu-physics/rigid-body-triggers.js.map +1 -1
- package/dist/gpu-physics/sphere-world-shaders.cjs +48 -20
- package/dist/gpu-physics/sphere-world-shaders.d.ts.map +1 -1
- package/dist/gpu-physics/sphere-world-shaders.js +51 -21
- package/dist/gpu-physics/sphere-world-shaders.js.map +1 -1
- package/dist/gpu-project/benchmarks.cjs.map +2 -2
- package/dist/gpu-project/crs.cjs.map +2 -2
- package/dist/gpu-project/index.cjs.map +2 -2
- package/dist/gpu-project/projection-program.cjs +2 -9
- package/dist/gpu-project/projection-program.d.ts.map +1 -1
- package/dist/gpu-project/projection-program.js +1 -8
- package/dist/gpu-project/projection-program.js.map +1 -1
- package/dist/gpu-sql/gpu-sql.cjs +203 -59
- package/dist/gpu-sql/gpu-sql.d.ts +36 -1
- package/dist/gpu-sql/gpu-sql.d.ts.map +1 -1
- package/dist/gpu-sql/gpu-sql.js +225 -62
- package/dist/gpu-sql/gpu-sql.js.map +1 -1
- package/dist/gpu-sql/index.cjs.map +3 -3
- package/dist/gpu-sql/index.d.ts +1 -1
- package/dist/gpu-sql/index.d.ts.map +1 -1
- package/dist/utils/float32.cjs +35 -0
- package/dist/utils/float32.d.ts +3 -0
- package/dist/utils/float32.d.ts.map +1 -0
- package/dist/utils/float32.js +16 -0
- package/dist/utils/float32.js.map +1 -0
- package/package.json +4 -4
- package/src/arrow/gpu/arrow-gpu-analytics-adapters.ts +77 -25
- package/src/arrow/gpu/arrow-gpu-analytics-readback.ts +52 -16
- package/src/arrow/gpu/arrow-gpu-table-conversion.ts +46 -1
- package/src/arrow/index.ts +1 -0
- package/src/gpu-core/gpu-bvh-bounds.ts +84 -0
- package/src/gpu-core/gpu-command-graph-submission-pacer.ts +102 -0
- package/src/gpu-core/index.ts +5 -0
- package/src/gpu-dataframe/gpu-analytics-compiler-utils.ts +7 -10
- package/src/gpu-dataframe/gpu-data-frame-query.ts +106 -25
- package/src/gpu-dataframe/gpu-data-frame.ts +35 -2
- package/src/gpu-dataframe/gpu-expression-shader.ts +172 -58
- package/src/gpu-dataframe/gpu-expression.ts +62 -9
- package/src/gpu-dataframe/gpu-global-aggregation-compiler.ts +6 -2
- package/src/gpu-dataframe/gpu-global-aggregation-query.ts +12 -3
- package/src/gpu-dataframe/gpu-global-sort-compiler.ts +151 -93
- package/src/gpu-dataframe/gpu-group-aggregation-compiler.ts +469 -52
- package/src/gpu-dataframe/gpu-group-by-query.ts +24 -10
- package/src/gpu-dataframe/gpu-join-compiler.ts +12 -6
- package/src/gpu-dataframe/gpu-query-compiler.ts +60 -18
- package/src/gpu-dataframe/index.ts +1 -1
- package/src/gpu-physics/gpu-physics-batch.ts +19 -13
- package/src/gpu-physics/gpu-physics-ensemble.ts +20 -4
- package/src/gpu-physics/gpu-rigid-body-world.ts +421 -93
- package/src/gpu-physics/index.ts +9 -0
- package/src/gpu-physics/rigid-body-cache-shaders.ts +18 -6
- package/src/gpu-physics/rigid-body-capacity.ts +25 -4
- package/src/gpu-physics/rigid-body-cast-index.ts +277 -0
- package/src/gpu-physics/rigid-body-ensemble-layout.ts +6 -2
- package/src/gpu-physics/rigid-body-ensemble-reset.ts +21 -9
- package/src/gpu-physics/rigid-body-ensemble-shaders.ts +18 -7
- package/src/gpu-physics/rigid-body-ensemble-transaction.ts +31 -13
- package/src/gpu-physics/rigid-body-event-compaction.ts +252 -0
- package/src/gpu-physics/rigid-body-event-snapshot.ts +76 -0
- package/src/gpu-physics/rigid-body-events.ts +63 -25
- package/src/gpu-physics/rigid-body-joints.ts +9 -11
- package/src/gpu-physics/rigid-body-queries.ts +202 -14
- package/src/gpu-physics/rigid-body-shaders.ts +4 -3
- package/src/gpu-physics/rigid-body-triggers.ts +64 -20
- package/src/gpu-physics/sphere-world-shaders.ts +53 -21
- package/src/gpu-project/projection-program.ts +1 -9
- package/src/gpu-sql/gpu-sql.ts +405 -91
- package/src/gpu-sql/index.ts +1 -1
- package/src/utils/float32.ts +16 -0
|
@@ -3,9 +3,13 @@
|
|
|
3
3
|
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
4
|
// SPDX-FileComment: Independently implemented for WebGPU; inspired by NVIDIA RAPIDS cuDF.
|
|
5
5
|
|
|
6
|
+
import {
|
|
7
|
+
getGPUVectorWGSLLayout,
|
|
8
|
+
type GPUVectorWGSLFormat as GPUExpressionNumericFormat
|
|
9
|
+
} from '@luma.gl/graph/gpu-data';
|
|
10
|
+
import {getGPUExpressionCastWGSL, GPU_EXPRESSION_CAST_WGSL} from '../gpu-core/gpu-expression-cast';
|
|
6
11
|
import type {GPUTypeMap} from '@luma.gl/graph/gpu-tables';
|
|
7
12
|
import type {GPUDataFrame} from './gpu-data-frame';
|
|
8
|
-
import {getGPUExpressionCastWGSL} from '../gpu-core/gpu-expression-cast';
|
|
9
13
|
import type {GPUDataFrameDerivedColumn} from './gpu-data-frame-query';
|
|
10
14
|
import {isGPUScalarFunction, type GPUExpressionUnaryOperator} from './gpu-expression';
|
|
11
15
|
import type {
|
|
@@ -25,7 +29,7 @@ export type GPUQueryScalarFormat = 'float32' | 'sint32' | 'uint32';
|
|
|
25
29
|
/** One deduplicated source vector and optional validity sidecar consumed by a predicate. @internal */
|
|
26
30
|
export type GPUQueryExpressionColumn = {
|
|
27
31
|
name: string;
|
|
28
|
-
format:
|
|
32
|
+
format: GPUExpressionNumericFormat;
|
|
29
33
|
nullable: boolean;
|
|
30
34
|
index: number;
|
|
31
35
|
};
|
|
@@ -33,6 +37,7 @@ export type GPUQueryExpressionColumn = {
|
|
|
33
37
|
/** One fixed-size literal or caller-controlled parameter stored outside shader source. @internal */
|
|
34
38
|
export type GPUQueryExpressionControl = {
|
|
35
39
|
name?: string;
|
|
40
|
+
convertInteger?: boolean;
|
|
36
41
|
value: GPUExpressionValue;
|
|
37
42
|
format: GPUQueryScalarFormat | 'boolean';
|
|
38
43
|
index: number;
|
|
@@ -41,7 +46,7 @@ export type GPUQueryExpressionControl = {
|
|
|
41
46
|
/** One selected numeric expression materialized into a source-aligned GPU vector. @internal */
|
|
42
47
|
export type GPUQueryExpressionOutput = {
|
|
43
48
|
name: string;
|
|
44
|
-
format:
|
|
49
|
+
format: GPUExpressionNumericFormat;
|
|
45
50
|
nullable: boolean;
|
|
46
51
|
value: string;
|
|
47
52
|
valid: string;
|
|
@@ -54,11 +59,12 @@ export type GPUQueryExpressionShaderPlan = {
|
|
|
54
59
|
controls: readonly GPUQueryExpressionControl[];
|
|
55
60
|
outputs: readonly GPUQueryExpressionOutput[];
|
|
56
61
|
statements: readonly string[];
|
|
57
|
-
|
|
62
|
+
helpers: readonly string[];
|
|
58
63
|
condition: string;
|
|
59
64
|
};
|
|
60
65
|
|
|
61
|
-
|
|
66
|
+
/** The WGSL value formats accepted by DataFrame expression lowering. */
|
|
67
|
+
type GPUQueryValueFormat = GPUExpressionNumericFormat | 'boolean';
|
|
62
68
|
|
|
63
69
|
type GPUQueryExpressionShaderValue = {
|
|
64
70
|
format: GPUQueryValueFormat;
|
|
@@ -116,7 +122,7 @@ export function makeGPUQueryExpressionShaderPlan<T extends GPUTypeMap>(
|
|
|
116
122
|
controls: planner.controls,
|
|
117
123
|
outputs,
|
|
118
124
|
statements: planner.statements,
|
|
119
|
-
|
|
125
|
+
helpers: planner.helpers,
|
|
120
126
|
condition: conditions.join(' && ') || 'true'
|
|
121
127
|
};
|
|
122
128
|
}
|
|
@@ -130,7 +136,7 @@ export function encodeGPUQueryExpressionControls(
|
|
|
130
136
|
const floatingPointWords = new Float32Array(words.buffer);
|
|
131
137
|
|
|
132
138
|
for (const control of controls) {
|
|
133
|
-
|
|
139
|
+
let value =
|
|
134
140
|
control.name !== undefined && Object.prototype.hasOwnProperty.call(parameters, control.name)
|
|
135
141
|
? parameters[control.name]
|
|
136
142
|
: control.value;
|
|
@@ -161,6 +167,7 @@ export function encodeGPUQueryExpressionControls(
|
|
|
161
167
|
} else {
|
|
162
168
|
const minimum = control.format === 'sint32' ? MINIMUM_SINT32 : 0;
|
|
163
169
|
const maximum = control.format === 'sint32' ? MAXIMUM_SINT32 : MAXIMUM_UINT32;
|
|
170
|
+
if (control.convertInteger) value = Math.min(maximum, Math.max(minimum, Math.trunc(value)));
|
|
164
171
|
if (!Number.isInteger(value) || value < minimum || value > maximum) {
|
|
165
172
|
throw new Error('GPUDataFrame numeric parameters must fit their integer column');
|
|
166
173
|
}
|
|
@@ -177,7 +184,7 @@ class GPUQueryExpressionShaderPlanner<T extends GPUTypeMap> {
|
|
|
177
184
|
readonly columns: GPUQueryExpressionColumn[] = [];
|
|
178
185
|
readonly controls: GPUQueryExpressionControl[] = [];
|
|
179
186
|
readonly statements: string[] = [];
|
|
180
|
-
|
|
187
|
+
readonly helpers: string[] = [];
|
|
181
188
|
|
|
182
189
|
private readonly source: GPUDataFrame<T>;
|
|
183
190
|
private readonly columnsByName = new Map<string, GPUQueryExpressionColumn>();
|
|
@@ -225,34 +232,16 @@ class GPUQueryExpressionShaderPlanner<T extends GPUTypeMap> {
|
|
|
225
232
|
|
|
226
233
|
emit(node: GPUExpressionNode, expected?: GPUQueryValueFormat): GPUQueryExpressionShaderValue {
|
|
227
234
|
switch (node.kind) {
|
|
235
|
+
case 'vector':
|
|
236
|
+
return this.emitVector(node);
|
|
237
|
+
case 'cast':
|
|
238
|
+
return this.emitCast(node);
|
|
228
239
|
case 'column':
|
|
229
240
|
return this.emitColumn(node.name, expected);
|
|
230
241
|
case 'literal':
|
|
231
242
|
return this.emitControl(node.value, undefined, expected);
|
|
232
243
|
case 'parameter':
|
|
233
244
|
return this.emitControl(node.value, node.name, expected);
|
|
234
|
-
case 'cast': {
|
|
235
|
-
const format = node.format;
|
|
236
|
-
if (format !== 'float32' && format !== 'sint32' && format !== 'uint32') {
|
|
237
|
-
throw new Error('GPUDataFrame casts require scalar 32-bit formats');
|
|
238
|
-
}
|
|
239
|
-
const operand = this.emit(node.operand, this.inferFormat(node.operand) ?? 'float32');
|
|
240
|
-
if (operand.format === 'boolean') {
|
|
241
|
-
throw new Error('GPUDataFrame casts require numeric expressions');
|
|
242
|
-
}
|
|
243
|
-
const floatToInteger = operand.format === 'float32' && format !== 'float32';
|
|
244
|
-
const valid = floatToInteger
|
|
245
|
-
? `(${operand.valid} && (bitcast<u32>(${operand.value}) & 0x7fffffffu) < 0x7f800000u)`
|
|
246
|
-
: operand.valid;
|
|
247
|
-
const input = floatToInteger ? `select(0.0, ${operand.value}, ${valid})` : operand.value;
|
|
248
|
-
this.usesCasts ||= floatToInteger;
|
|
249
|
-
return this.addValue(
|
|
250
|
-
format,
|
|
251
|
-
getGPUExpressionCastWGSL(input, operand.format, format, 'truncate'),
|
|
252
|
-
valid,
|
|
253
|
-
operand.nullable || floatToInteger
|
|
254
|
-
);
|
|
255
|
-
}
|
|
256
245
|
case 'conditional': {
|
|
257
246
|
const condition = this.emit(node.condition, 'boolean');
|
|
258
247
|
this.assertBoolean(condition);
|
|
@@ -297,26 +286,141 @@ class GPUQueryExpressionShaderPlanner<T extends GPUTypeMap> {
|
|
|
297
286
|
if (expected && expected !== column.format && expected !== 'boolean') {
|
|
298
287
|
throw new Error('GPUDataFrame expression combines incompatible scalar column formats');
|
|
299
288
|
}
|
|
300
|
-
const value = `
|
|
289
|
+
const value = `readInput${column.index}(index)`;
|
|
301
290
|
const valid = column.nullable
|
|
302
291
|
? `validity${column.index}[VALIDITY_${column.index}_OFFSET + index] != 0u`
|
|
303
292
|
: 'true';
|
|
304
293
|
return this.addValue(column.format, value, valid, column.nullable);
|
|
305
294
|
}
|
|
306
295
|
|
|
296
|
+
/** Constructs a vector and combines validity across all of its components. */
|
|
297
|
+
private emitVector(
|
|
298
|
+
node: Extract<GPUExpressionNode, {kind: 'vector'}>
|
|
299
|
+
): GPUQueryExpressionShaderValue {
|
|
300
|
+
const layout = getGPUVectorWGSLLayout(node.format);
|
|
301
|
+
if (layout.components === 1 || node.components.length !== layout.components)
|
|
302
|
+
throw new Error('Vector width must match its format');
|
|
303
|
+
const components = node.components.map(component =>
|
|
304
|
+
this.emitConversion(component, layout.componentType)
|
|
305
|
+
);
|
|
306
|
+
return this.addValue(
|
|
307
|
+
node.format,
|
|
308
|
+
`${layout.shaderType}(${components.map(component => component.value).join(', ')})`,
|
|
309
|
+
components.map(component => component.valid).join(' && '),
|
|
310
|
+
components.some(component => component.nullable)
|
|
311
|
+
);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/** Lowers a width-preserving numeric cast. */
|
|
315
|
+
private emitCast(
|
|
316
|
+
node: Extract<GPUExpressionNode, {kind: 'cast'}>
|
|
317
|
+
): GPUQueryExpressionShaderValue {
|
|
318
|
+
if (getGPUVectorWGSLLayout(node.format).components > 1) {
|
|
319
|
+
return this.emitConversion(node.operand, node.format);
|
|
320
|
+
}
|
|
321
|
+
const format = node.format;
|
|
322
|
+
if (format !== 'float32' && format !== 'sint32' && format !== 'uint32') {
|
|
323
|
+
throw new Error('GPUDataFrame casts require scalar 32-bit formats');
|
|
324
|
+
}
|
|
325
|
+
const operand = this.emit(node.operand, this.inferFormat(node.operand) ?? 'float32');
|
|
326
|
+
if (
|
|
327
|
+
operand.format !== 'float32' &&
|
|
328
|
+
operand.format !== 'uint32' &&
|
|
329
|
+
operand.format !== 'sint32'
|
|
330
|
+
) {
|
|
331
|
+
throw new Error('GPUDataFrame scalar casts require scalar numeric expressions');
|
|
332
|
+
}
|
|
333
|
+
const floatToInteger = operand.format === 'float32' && format !== 'float32';
|
|
334
|
+
const valid = floatToInteger
|
|
335
|
+
? `(${operand.valid} && (bitcast<u32>(${operand.value}) & 0x7fffffffu) < 0x7f800000u)`
|
|
336
|
+
: operand.valid;
|
|
337
|
+
const input = floatToInteger ? `select(0.0, ${operand.value}, ${valid})` : operand.value;
|
|
338
|
+
if (floatToInteger && !this.helpers.includes(GPU_EXPRESSION_CAST_WGSL))
|
|
339
|
+
this.helpers.push(GPU_EXPRESSION_CAST_WGSL);
|
|
340
|
+
return this.addValue(
|
|
341
|
+
format,
|
|
342
|
+
getGPUExpressionCastWGSL(input, operand.format, format, 'truncate'),
|
|
343
|
+
valid,
|
|
344
|
+
operand.nullable || floatToInteger
|
|
345
|
+
);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/** Encodes integer controls directly and lowers other conversions into WGSL. */
|
|
349
|
+
private emitConversion(
|
|
350
|
+
node: GPUExpressionNode,
|
|
351
|
+
target: GPUExpressionNumericFormat
|
|
352
|
+
): GPUQueryExpressionShaderValue {
|
|
353
|
+
if (
|
|
354
|
+
(target === 'sint32' || target === 'uint32') &&
|
|
355
|
+
(node.kind === 'literal' || node.kind === 'parameter') &&
|
|
356
|
+
(node.value === null || typeof node.value === 'number')
|
|
357
|
+
) {
|
|
358
|
+
// Convert controls before upload to retain values above f32 integer precision.
|
|
359
|
+
return this.emitControl(
|
|
360
|
+
node.value,
|
|
361
|
+
node.kind === 'parameter' ? node.name : undefined,
|
|
362
|
+
target,
|
|
363
|
+
true
|
|
364
|
+
);
|
|
365
|
+
}
|
|
366
|
+
return this.convertValue(this.emit(node, this.inferFormat(node) ?? 'float32'), target);
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/** Converts each component while preserving width and row validity. */
|
|
370
|
+
private convertValue(
|
|
371
|
+
source: GPUQueryExpressionShaderValue,
|
|
372
|
+
target: GPUExpressionNumericFormat
|
|
373
|
+
): GPUQueryExpressionShaderValue {
|
|
374
|
+
if (source.format === 'boolean') throw new Error('Numeric casts require numeric inputs');
|
|
375
|
+
const sourceLayout = getGPUVectorWGSLLayout(source.format);
|
|
376
|
+
const targetLayout = getGPUVectorWGSLLayout(target);
|
|
377
|
+
if (sourceLayout.components !== targetLayout.components)
|
|
378
|
+
throw new Error('Numeric casts must preserve width');
|
|
379
|
+
if (source.format === target) return source;
|
|
380
|
+
if (!this.helpers.includes(GPU_EXPRESSION_CAST_WGSL))
|
|
381
|
+
this.helpers.push(GPU_EXPRESSION_CAST_WGSL);
|
|
382
|
+
const components = Array.from({length: sourceLayout.components}, (_, index) => {
|
|
383
|
+
const value = sourceLayout.components === 1 ? source.value : `${source.value}[${index}]`;
|
|
384
|
+
return getGPUExpressionCastWGSL(
|
|
385
|
+
value,
|
|
386
|
+
sourceLayout.componentType,
|
|
387
|
+
targetLayout.componentType,
|
|
388
|
+
'truncate'
|
|
389
|
+
);
|
|
390
|
+
});
|
|
391
|
+
// Float NaN/Inf has no portable integer value: mark the entire row invalid.
|
|
392
|
+
const finite =
|
|
393
|
+
sourceLayout.componentType === 'float32' && targetLayout.componentType !== 'float32';
|
|
394
|
+
const valid = finite
|
|
395
|
+
? `${source.valid} && ${sourceLayout.components === 1 ? `abs(${source.value}) <= 3.4028234663852886e38f` : `all(abs(${source.value}) <= ${sourceLayout.shaderType}(3.4028234663852886e38f))`}`
|
|
396
|
+
: source.valid;
|
|
397
|
+
return this.addValue(
|
|
398
|
+
target,
|
|
399
|
+
targetLayout.components === 1
|
|
400
|
+
? components[0]
|
|
401
|
+
: `${targetLayout.shaderType}(${components.join(', ')})`,
|
|
402
|
+
valid,
|
|
403
|
+
source.nullable || finite
|
|
404
|
+
);
|
|
405
|
+
}
|
|
406
|
+
|
|
307
407
|
private emitControl(
|
|
308
408
|
value: GPUExpressionValue,
|
|
309
409
|
name: string | undefined,
|
|
310
|
-
expected?: GPUQueryValueFormat
|
|
410
|
+
expected?: GPUQueryValueFormat,
|
|
411
|
+
convertInteger = false
|
|
311
412
|
): GPUQueryExpressionShaderValue {
|
|
312
413
|
const inferred = typeof value === 'boolean' ? 'boolean' : (expected ?? 'float32');
|
|
414
|
+
if (inferred !== 'boolean' && getGPUVectorWGSLLayout(inferred).components !== 1)
|
|
415
|
+
throw new Error('Scalar literals cannot broadcast to vectors');
|
|
313
416
|
if (value !== null && (typeof value === 'boolean') !== (inferred === 'boolean')) {
|
|
314
417
|
throw new Error('GPUDataFrame expression combines incompatible literal and column formats');
|
|
315
418
|
}
|
|
316
419
|
const control: GPUQueryExpressionControl = {
|
|
317
420
|
...(name !== undefined ? {name} : {}),
|
|
318
421
|
value,
|
|
319
|
-
|
|
422
|
+
...(convertInteger ? {convertInteger} : {}),
|
|
423
|
+
format: inferred as GPUQueryScalarFormat | 'boolean',
|
|
320
424
|
index: this.controls.length
|
|
321
425
|
};
|
|
322
426
|
this.controls.push(control);
|
|
@@ -382,7 +486,10 @@ class GPUQueryExpressionShaderPlanner<T extends GPUTypeMap> {
|
|
|
382
486
|
case 'round':
|
|
383
487
|
case 'trunc': {
|
|
384
488
|
const format = this.inferFormat(operandNode) ?? 'float32';
|
|
385
|
-
if (
|
|
489
|
+
if (
|
|
490
|
+
(format !== 'float32' && format !== 'sint32' && format !== 'uint32') ||
|
|
491
|
+
(operator === 'abs' && format === 'sint32')
|
|
492
|
+
) {
|
|
386
493
|
throw new Error('GPUDataFrame scalar function requires a supported numeric format');
|
|
387
494
|
}
|
|
388
495
|
const operand = this.emit(operandNode, format);
|
|
@@ -400,7 +507,7 @@ class GPUQueryExpressionShaderPlanner<T extends GPUTypeMap> {
|
|
|
400
507
|
}
|
|
401
508
|
case 'negate': {
|
|
402
509
|
const format = this.inferFormat(operandNode) ?? expected ?? 'float32';
|
|
403
|
-
if (format === 'boolean' || format === 'uint32') {
|
|
510
|
+
if (format === 'boolean' || getGPUVectorWGSLLayout(format).componentType === 'uint32') {
|
|
404
511
|
throw new Error('GPUDataFrame negation requires a signed numeric expression');
|
|
405
512
|
}
|
|
406
513
|
const operand = this.emit(operandNode, format);
|
|
@@ -460,16 +567,23 @@ class GPUQueryExpressionShaderPlanner<T extends GPUTypeMap> {
|
|
|
460
567
|
left.nullable && right.nullable
|
|
461
568
|
);
|
|
462
569
|
}
|
|
570
|
+
const vector = format !== 'boolean' && getGPUVectorWGSLLayout(format).components > 1;
|
|
463
571
|
if (operator === 'nullif') {
|
|
572
|
+
const equals = `(${left.value} == ${right.value})`;
|
|
464
573
|
return this.addValue(
|
|
465
574
|
format,
|
|
466
575
|
left.value,
|
|
467
|
-
`(${left.valid} && !(${right.valid} && ${
|
|
576
|
+
`(${left.valid} && !(${right.valid} && ${vector ? `all(${equals})` : equals}))`,
|
|
468
577
|
true
|
|
469
578
|
);
|
|
470
579
|
}
|
|
471
580
|
const symbol = getGPUQueryBinaryOperator(operator);
|
|
472
|
-
|
|
581
|
+
let value = `(${left.value} ${symbol} ${right.value})`;
|
|
582
|
+
if (vector && !arithmetic) {
|
|
583
|
+
if (operator !== 'equal' && operator !== 'not-equal')
|
|
584
|
+
throw new Error('Vector ordering is unsupported');
|
|
585
|
+
value = `${operator === 'equal' ? 'all' : 'any'}(${value})`;
|
|
586
|
+
}
|
|
473
587
|
const valid = `${left.valid} && ${right.valid}`;
|
|
474
588
|
return this.addValue(
|
|
475
589
|
arithmetic ? format : 'boolean',
|
|
@@ -481,6 +595,9 @@ class GPUQueryExpressionShaderPlanner<T extends GPUTypeMap> {
|
|
|
481
595
|
|
|
482
596
|
private inferFormat(node: GPUExpressionNode): GPUQueryValueFormat | undefined {
|
|
483
597
|
switch (node.kind) {
|
|
598
|
+
case 'vector':
|
|
599
|
+
case 'cast':
|
|
600
|
+
return node.format;
|
|
484
601
|
case 'column':
|
|
485
602
|
return this.derivedByName.has(node.name)
|
|
486
603
|
? this.emitDerived(this.derivedByName.get(node.name)!).format
|
|
@@ -488,11 +605,6 @@ class GPUQueryExpressionShaderPlanner<T extends GPUTypeMap> {
|
|
|
488
605
|
case 'literal':
|
|
489
606
|
case 'parameter':
|
|
490
607
|
return typeof node.value === 'boolean' ? 'boolean' : undefined;
|
|
491
|
-
case 'cast':
|
|
492
|
-
if (node.format === 'float32' || node.format === 'sint32' || node.format === 'uint32') {
|
|
493
|
-
return node.format;
|
|
494
|
-
}
|
|
495
|
-
throw new Error('GPUDataFrame casts require scalar 32-bit formats');
|
|
496
608
|
case 'conditional': {
|
|
497
609
|
const whenTrue = this.inferFormat(node.whenTrue);
|
|
498
610
|
const otherwise = this.inferFormat(node.otherwise);
|
|
@@ -571,14 +683,27 @@ class GPUQueryExpressionShaderPlanner<T extends GPUTypeMap> {
|
|
|
571
683
|
throw new Error(`GPUDataFrame expression column "${name}" is not a GPU vector`);
|
|
572
684
|
}
|
|
573
685
|
const format = vector?.format ?? field.format;
|
|
574
|
-
|
|
575
|
-
|
|
686
|
+
const layout = getGPUVectorWGSLLayout(format as GPUExpressionNumericFormat);
|
|
687
|
+
if (
|
|
688
|
+
vector?.data.some(
|
|
689
|
+
chunk =>
|
|
690
|
+
chunk.byteStride !== layout.packedByteStride ||
|
|
691
|
+
chunk.rowByteLength !== layout.byteLength ||
|
|
692
|
+
chunk.byteOffset % 4 !== 0
|
|
693
|
+
)
|
|
694
|
+
) {
|
|
695
|
+
throw new Error('GPUDataFrame expressions require packed, 32-bit-aligned numeric columns');
|
|
576
696
|
}
|
|
577
697
|
const nullable = field.nullable === true;
|
|
578
698
|
if (nullable && this.source.numRows > 0 && !this.source.validity[name as keyof T & string]) {
|
|
579
699
|
throw new Error(`GPUDataFrame nullable column "${name}" requires an explicit validity mask`);
|
|
580
700
|
}
|
|
581
|
-
const column = {
|
|
701
|
+
const column = {
|
|
702
|
+
name,
|
|
703
|
+
format: format as GPUExpressionNumericFormat,
|
|
704
|
+
nullable,
|
|
705
|
+
index: this.columns.length
|
|
706
|
+
};
|
|
582
707
|
this.columns.push(column);
|
|
583
708
|
this.columnsByName.set(name, column);
|
|
584
709
|
return column;
|
|
@@ -607,19 +732,8 @@ class GPUQueryExpressionShaderPlanner<T extends GPUTypeMap> {
|
|
|
607
732
|
}
|
|
608
733
|
|
|
609
734
|
/** Converts a closed scalar format to the corresponding native WGSL scalar type. @internal */
|
|
610
|
-
export function getGPUQueryShaderType(format: GPUQueryValueFormat):
|
|
611
|
-
|
|
612
|
-
case 'float32':
|
|
613
|
-
return 'f32';
|
|
614
|
-
case 'sint32':
|
|
615
|
-
return 'i32';
|
|
616
|
-
case 'uint32':
|
|
617
|
-
return 'u32';
|
|
618
|
-
case 'boolean':
|
|
619
|
-
return 'bool';
|
|
620
|
-
default:
|
|
621
|
-
throw new Error('GPUDataFrame expression contains an unsupported scalar format');
|
|
622
|
-
}
|
|
735
|
+
export function getGPUQueryShaderType(format: GPUQueryValueFormat): string {
|
|
736
|
+
return format === 'boolean' ? 'bool' : getGPUVectorWGSLLayout(format).shaderType;
|
|
623
737
|
}
|
|
624
738
|
|
|
625
739
|
/** Maps only known discriminants to WGSL operators without accepting application shader text. */
|
|
@@ -120,7 +120,15 @@ export class GPUExpression<Value = unknown, Columns extends string = string> {
|
|
|
120
120
|
add<OtherColumns extends string>(
|
|
121
121
|
this: GPUExpression<number | null, Columns>,
|
|
122
122
|
expression: GPUExpression<number | null, OtherColumns>
|
|
123
|
-
): GPUExpression<number | null, Columns | OtherColumns
|
|
123
|
+
): GPUExpression<number | null, Columns | OtherColumns>;
|
|
124
|
+
add<OtherColumns extends string>(
|
|
125
|
+
this: GPUExpression<readonly number[] | null, Columns>,
|
|
126
|
+
expression: GPUExpression<readonly number[] | null, OtherColumns>
|
|
127
|
+
): GPUExpression<readonly number[] | null, Columns | OtherColumns>;
|
|
128
|
+
add<OtherColumns extends string>(
|
|
129
|
+
this: GPUExpression<GPUExpressionNumericValue, Columns>,
|
|
130
|
+
expression: GPUExpression<GPUExpressionNumericValue, OtherColumns>
|
|
131
|
+
): GPUExpression<GPUExpressionNumericValue, Columns | OtherColumns> {
|
|
124
132
|
return makeBinaryExpression('add', this, expression);
|
|
125
133
|
}
|
|
126
134
|
|
|
@@ -128,7 +136,15 @@ export class GPUExpression<Value = unknown, Columns extends string = string> {
|
|
|
128
136
|
subtract<OtherColumns extends string>(
|
|
129
137
|
this: GPUExpression<number | null, Columns>,
|
|
130
138
|
expression: GPUExpression<number | null, OtherColumns>
|
|
131
|
-
): GPUExpression<number | null, Columns | OtherColumns
|
|
139
|
+
): GPUExpression<number | null, Columns | OtherColumns>;
|
|
140
|
+
subtract<OtherColumns extends string>(
|
|
141
|
+
this: GPUExpression<readonly number[] | null, Columns>,
|
|
142
|
+
expression: GPUExpression<readonly number[] | null, OtherColumns>
|
|
143
|
+
): GPUExpression<readonly number[] | null, Columns | OtherColumns>;
|
|
144
|
+
subtract<OtherColumns extends string>(
|
|
145
|
+
this: GPUExpression<GPUExpressionNumericValue, Columns>,
|
|
146
|
+
expression: GPUExpression<GPUExpressionNumericValue, OtherColumns>
|
|
147
|
+
): GPUExpression<GPUExpressionNumericValue, Columns | OtherColumns> {
|
|
132
148
|
return makeBinaryExpression('subtract', this, expression);
|
|
133
149
|
}
|
|
134
150
|
|
|
@@ -136,7 +152,15 @@ export class GPUExpression<Value = unknown, Columns extends string = string> {
|
|
|
136
152
|
multiply<OtherColumns extends string>(
|
|
137
153
|
this: GPUExpression<number | null, Columns>,
|
|
138
154
|
expression: GPUExpression<number | null, OtherColumns>
|
|
139
|
-
): GPUExpression<number | null, Columns | OtherColumns
|
|
155
|
+
): GPUExpression<number | null, Columns | OtherColumns>;
|
|
156
|
+
multiply<OtherColumns extends string>(
|
|
157
|
+
this: GPUExpression<readonly number[] | null, Columns>,
|
|
158
|
+
expression: GPUExpression<readonly number[] | null, OtherColumns>
|
|
159
|
+
): GPUExpression<readonly number[] | null, Columns | OtherColumns>;
|
|
160
|
+
multiply<OtherColumns extends string>(
|
|
161
|
+
this: GPUExpression<GPUExpressionNumericValue, Columns>,
|
|
162
|
+
expression: GPUExpression<GPUExpressionNumericValue, OtherColumns>
|
|
163
|
+
): GPUExpression<GPUExpressionNumericValue, Columns | OtherColumns> {
|
|
140
164
|
return makeBinaryExpression('multiply', this, expression);
|
|
141
165
|
}
|
|
142
166
|
|
|
@@ -144,7 +168,15 @@ export class GPUExpression<Value = unknown, Columns extends string = string> {
|
|
|
144
168
|
divide<OtherColumns extends string>(
|
|
145
169
|
this: GPUExpression<number | null, Columns>,
|
|
146
170
|
expression: GPUExpression<number | null, OtherColumns>
|
|
147
|
-
): GPUExpression<number | null, Columns | OtherColumns
|
|
171
|
+
): GPUExpression<number | null, Columns | OtherColumns>;
|
|
172
|
+
divide<OtherColumns extends string>(
|
|
173
|
+
this: GPUExpression<readonly number[] | null, Columns>,
|
|
174
|
+
expression: GPUExpression<readonly number[] | null, OtherColumns>
|
|
175
|
+
): GPUExpression<readonly number[] | null, Columns | OtherColumns>;
|
|
176
|
+
divide<OtherColumns extends string>(
|
|
177
|
+
this: GPUExpression<GPUExpressionNumericValue, Columns>,
|
|
178
|
+
expression: GPUExpression<GPUExpressionNumericValue, OtherColumns>
|
|
179
|
+
): GPUExpression<GPUExpressionNumericValue, Columns | OtherColumns> {
|
|
148
180
|
return makeBinaryExpression('divide', this, expression);
|
|
149
181
|
}
|
|
150
182
|
|
|
@@ -233,10 +265,21 @@ export class GPUExpression<Value = unknown, Columns extends string = string> {
|
|
|
233
265
|
|
|
234
266
|
/** References a named source column without accessing GPU storage. */
|
|
235
267
|
export function column<Name extends string>(name: Name): GPUExpression<number | null, Name> {
|
|
268
|
+
return new GPUExpression(makeColumnNode(name));
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/** References a packed vector column. The query planner resolves its format from the schema. */
|
|
272
|
+
export function vectorColumn<Name extends string>(
|
|
273
|
+
name: Name
|
|
274
|
+
): GPUExpression<readonly number[] | null, Name> {
|
|
275
|
+
return new GPUExpression(makeColumnNode(name));
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
function makeColumnNode(name: string): GPUExpressionNode {
|
|
236
279
|
if (typeof name !== 'string' || name.length === 0) {
|
|
237
280
|
throw new Error('GPUDataFrame expression columns require a nonempty name');
|
|
238
281
|
}
|
|
239
|
-
return
|
|
282
|
+
return {kind: 'column', name};
|
|
240
283
|
}
|
|
241
284
|
|
|
242
285
|
/** Creates one immutable portable scalar literal without embedding it in generated WGSL. */
|
|
@@ -299,6 +342,7 @@ export function getGPUExpressionResultFormats(
|
|
|
299
342
|
case 'column':
|
|
300
343
|
formats.add(columns.get(node.name));
|
|
301
344
|
break;
|
|
345
|
+
case 'vector':
|
|
302
346
|
case 'cast':
|
|
303
347
|
formats.add(node.format);
|
|
304
348
|
break;
|
|
@@ -459,11 +503,20 @@ export function vector<Columns extends string>(
|
|
|
459
503
|
* const floatPosition = cast(position, 'float32x2');
|
|
460
504
|
* ```
|
|
461
505
|
*/
|
|
462
|
-
export function cast<
|
|
506
|
+
export function cast<
|
|
507
|
+
Value extends GPUExpressionNumericValue,
|
|
508
|
+
Columns extends string,
|
|
509
|
+
Format extends GPUExpressionNumericFormat
|
|
510
|
+
>(
|
|
463
511
|
expression: GPUExpression<Value, Columns>,
|
|
464
|
-
format:
|
|
465
|
-
): GPUExpression<Value, Columns> {
|
|
466
|
-
|
|
512
|
+
format: Format
|
|
513
|
+
): GPUExpression<Value, Columns> & {
|
|
514
|
+
readonly node: {readonly kind: 'cast'; readonly format: Format};
|
|
515
|
+
} {
|
|
516
|
+
const result = new GPUExpression<Value, Columns>(makeGPUCastNode(expression.node, format));
|
|
517
|
+
return result as GPUExpression<Value, Columns> & {
|
|
518
|
+
readonly node: {readonly kind: 'cast'; readonly format: Format};
|
|
519
|
+
};
|
|
467
520
|
}
|
|
468
521
|
|
|
469
522
|
export function makeGPUCastNode<Format extends GPUExpressionNumericFormat>(
|
|
@@ -66,7 +66,9 @@ export function compileGPUDataFrameAggregation<
|
|
|
66
66
|
): CompiledGPUDataFrameAggregation<Result> {
|
|
67
67
|
validateGPUAnalyticsSource(
|
|
68
68
|
source,
|
|
69
|
-
definitions.flatMap(definition =>
|
|
69
|
+
definitions.flatMap(definition =>
|
|
70
|
+
definition.operation !== 'count' && definition.column ? [definition.column] : []
|
|
71
|
+
)
|
|
70
72
|
);
|
|
71
73
|
return compileGPUDataFrameQuery<
|
|
72
74
|
Source,
|
|
@@ -108,7 +110,9 @@ function addGPUGlobalAggregationsToGraph<Selection extends GPUTypeMap, Result ex
|
|
|
108
110
|
context.graph.add(
|
|
109
111
|
new GPUReduction({
|
|
110
112
|
id,
|
|
111
|
-
input:
|
|
113
|
+
input: definition.column
|
|
114
|
+
? getGPUAnalyticsSelectionMask(context, definition.column, id)
|
|
115
|
+
: context.selectionMask,
|
|
112
116
|
output: context.graph.importGPUVector(`${id}-output`, output).data[0],
|
|
113
117
|
operation: 'sum'
|
|
114
118
|
})
|
|
@@ -31,6 +31,7 @@ export type GPUDataFrameGlobalAggregationValue<
|
|
|
31
31
|
SelectedColumns extends keyof T & string
|
|
32
32
|
> =
|
|
33
33
|
| 'count'
|
|
34
|
+
| Readonly<{count: SelectedColumns}>
|
|
34
35
|
| Readonly<{sum: GPUDataFrameScalarColumnNames<T, SelectedColumns>}>
|
|
35
36
|
| Readonly<{min: GPUDataFrameScalarColumnNames<T, SelectedColumns>}>
|
|
36
37
|
| Readonly<{max: GPUDataFrameScalarColumnNames<T, SelectedColumns>}>
|
|
@@ -43,7 +44,9 @@ export type GPUDataFrameGlobalAggregationDefinitions<
|
|
|
43
44
|
> = Readonly<Record<string, GPUDataFrameGlobalAggregationValue<T, SelectedColumns>>>;
|
|
44
45
|
|
|
45
46
|
/** Exact result scalar format retained for one requested global statistic. */
|
|
46
|
-
type GPUDataFrameGlobalAggregationValueFormat<T extends GPUTypeMap, Value> = Value extends
|
|
47
|
+
type GPUDataFrameGlobalAggregationValueFormat<T extends GPUTypeMap, Value> = Value extends
|
|
48
|
+
| 'count'
|
|
49
|
+
| {count: string}
|
|
47
50
|
? 'uint32'
|
|
48
51
|
: Value extends {mean: string}
|
|
49
52
|
? 'float32'
|
|
@@ -168,13 +171,19 @@ function normalizeGPUDataFrameGlobalAggregations<
|
|
|
168
171
|
throw new Error(`GPUDataFrame global aggregation "${name}" requires exactly one operation`);
|
|
169
172
|
}
|
|
170
173
|
const [operation, column] = entries[0];
|
|
171
|
-
if (
|
|
174
|
+
if (
|
|
175
|
+
operation !== 'count' &&
|
|
176
|
+
operation !== 'sum' &&
|
|
177
|
+
operation !== 'min' &&
|
|
178
|
+
operation !== 'max' &&
|
|
179
|
+
operation !== 'mean'
|
|
180
|
+
) {
|
|
172
181
|
throw new Error(`GPUDataFrame global aggregation "${name}" has an unsupported operation`);
|
|
173
182
|
}
|
|
174
183
|
if (typeof column !== 'string' || !query.selectedColumns.includes(column as SelectedColumns)) {
|
|
175
184
|
throw new Error(`GPUDataFrame global aggregation "${name}" requires a selected input column`);
|
|
176
185
|
}
|
|
177
|
-
if (!getGPUDataFrameAnalyticColumnFormat(query, column)) {
|
|
186
|
+
if (operation !== 'count' && !getGPUDataFrameAnalyticColumnFormat(query, column)) {
|
|
178
187
|
throw new Error(`GPUDataFrame global aggregation "${name}" requires a scalar GPU column`);
|
|
179
188
|
}
|
|
180
189
|
normalized.push(Object.freeze({name, operation, column}));
|