@photivra/engine 2.9.0 → 2.10.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.
- package/CHANGELOG.md +85 -1
- package/CITATION.cff +1 -1
- package/README.md +6 -6
- package/SECURITY.md +1 -1
- package/THIRD_PARTY.md +2 -0
- package/dist/capture/native-environment-lean.js +89 -5
- package/dist/capture/native-environment-lean.js.map +1 -1
- package/dist/capture/native-environment-tabulated.d.ts +37 -0
- package/dist/capture/native-environment-tabulated.js +42 -6
- package/dist/capture/native-environment-tabulated.js.map +1 -1
- package/dist/core/portable-math.d.ts +13 -0
- package/dist/core/portable-math.js +43 -0
- package/dist/core/portable-math.js.map +1 -1
- package/dist/core/version.d.ts +1 -1
- package/dist/core/version.js +1 -1
- package/dist/core/version.js.map +1 -1
- package/dist/facade/channel-response.d.ts +15 -0
- package/dist/facade/channel-response.js +33 -0
- package/dist/facade/channel-response.js.map +1 -0
- package/dist/facade/diffraction-provider.js +50 -15
- package/dist/facade/diffraction-provider.js.map +1 -1
- package/dist/facade/display-view.d.ts +75 -0
- package/dist/facade/display-view.js +471 -109
- package/dist/facade/display-view.js.map +1 -1
- package/dist/facade/expected-signal-setup.js +2 -1
- package/dist/facade/expected-signal-setup.js.map +1 -1
- package/dist/facade/expected-signal.d.ts +32 -3
- package/dist/facade/expected-signal.js +192 -24
- package/dist/facade/expected-signal.js.map +1 -1
- package/dist/facade/simulate-capture.d.ts +51 -4
- package/dist/facade/simulate-capture.js +130 -31
- package/dist/facade/simulate-capture.js.map +1 -1
- package/dist/facade/simulate-display-view.d.ts +25 -2
- package/dist/facade/simulate-display-view.js +55 -22
- package/dist/facade/simulate-display-view.js.map +1 -1
- package/dist/gpu/image-kernel-execution.d.ts +5 -0
- package/dist/gpu/image-kernel-execution.js +2 -2
- package/dist/gpu/image-kernel-execution.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/optics/irradiance-convolution.d.ts +11 -0
- package/dist/optics/irradiance-convolution.js +64 -24
- package/dist/optics/irradiance-convolution.js.map +1 -1
- package/dist/optics/scene-to-sensor-irradiance.d.ts +13 -0
- package/dist/optics/scene-to-sensor-irradiance.js +58 -24
- package/dist/optics/scene-to-sensor-irradiance.js.map +1 -1
- package/dist/optics/sensor-aperture-rays.js +2 -1
- package/dist/optics/sensor-aperture-rays.js.map +1 -1
- package/dist/optics/sensor-environment-query.js +4 -3
- package/dist/optics/sensor-environment-query.js.map +1 -1
- package/dist/optics/site-diffraction-kernel.d.ts +16 -0
- package/dist/optics/site-diffraction-kernel.js +60 -8
- package/dist/optics/site-diffraction-kernel.js.map +1 -1
- package/dist/processing/demosaic.js +114 -37
- package/dist/processing/demosaic.js.map +1 -1
- package/dist/schema/scene-radiance.d.ts +8 -0
- package/dist/schema/scene-radiance.js +28 -17
- package/dist/schema/scene-radiance.js.map +1 -1
- package/dist/sensor/environment-photo-signal.d.ts +21 -0
- package/dist/sensor/environment-photo-signal.js +68 -2
- package/dist/sensor/environment-photo-signal.js.map +1 -1
- package/docs/API_REFERENCE.md +16 -1
- package/docs/QUICK_START.md +18 -8
- package/docs/USAGE.md +30 -0
- package/docs/api/core-version.md +1 -1
- package/docs/api/exports.json +42 -2
- package/docs/api/facade-display-view.md +50 -0
- package/docs/api/facade-simulate-capture.md +60 -8
- package/docs/api/facade-simulate-display-view.md +23 -1
- package/docs/api/gpu-image-kernel-execution.md +5 -0
- package/package.json +1 -1
|
@@ -13,6 +13,8 @@
|
|
|
13
13
|
* Verification at run time: one site of each CFA phase runs the full chain (planning, the evaluator's callbacks, composition,
|
|
14
14
|
* parsing and `calculateNativeRawSite`). Its readout template must reproduce that site bit for bit, and its tabulated
|
|
15
15
|
* electrons must agree with the chain's within `TABULATED_RELATIVE_TOLERANCE`; otherwise the caller runs the environment task.
|
|
16
|
+
* #453: the chain's photo signal comes from `executeEngineOwnedEnvironmentPhotoSignal`, the same operations and values as
|
|
17
|
+
* `executeEnvironmentSensorPhotoSignal` for these engine-built records, without re-validating records that cannot have changed.
|
|
16
18
|
*/
|
|
17
19
|
import type { EnvironmentRadianceEvaluator } from "../sensor/environment-photo-signal.js";
|
|
18
20
|
import { type SimulateEnvironmentSensorRawFrameInput } from "./environment-raw-producer.js";
|
|
@@ -20,6 +22,20 @@ import { type NativeEnvironmentRawInput } from "./native-environment-raw.js";
|
|
|
20
22
|
import type { NativeRawOutput } from "./native-raw.js";
|
|
21
23
|
/** Largest relative difference between a verification site's tabulated and chain electrons: rounding only (a few ulps of each term). */
|
|
22
24
|
export declare const TABULATED_RELATIVE_TOLERANCE = 1e-9;
|
|
25
|
+
/** Internal counters (tests assert how many verification sites ran the chain per call; four, one per CFA phase). */
|
|
26
|
+
export declare const tabulatedVerificationStatistics: {
|
|
27
|
+
chainExecutions: number;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Internal test hook (never set by the engine): `fullPhoto` also runs each verification site through
|
|
31
|
+
* `executeEnvironmentSensorPhotoSignal` (with the uncounted evaluator) and hands both photo signals to the test;
|
|
32
|
+
* `tabulatedElectrons` replaces the tabulated electrons the gate compares, to show that a wrong fast path is rejected.
|
|
33
|
+
*/
|
|
34
|
+
export interface TabulatedVerificationTestHook {
|
|
35
|
+
fullPhoto?(engineOwned: unknown, full: unknown): void;
|
|
36
|
+
tabulatedElectrons?(value: number, x: number, y: number): number;
|
|
37
|
+
}
|
|
38
|
+
export declare function setTabulatedVerificationTestHook(hook: TabulatedVerificationTestHook | undefined): void;
|
|
23
39
|
/** Disables the tabulated path process-wide (internal; tests of the environment path itself turn it off). */
|
|
24
40
|
export declare function setTabulatedNativeRawEnabled(enabled: boolean): void;
|
|
25
41
|
export interface TabulatedNativeRawInput {
|
|
@@ -54,5 +70,26 @@ export interface TabulatedNativeRawResult {
|
|
|
54
70
|
/** Largest relative difference between tabulated and chain electrons over the verification sites. */
|
|
55
71
|
verificationRelativeDifference: number;
|
|
56
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* #449: the local exposure duration shared by every site of `region`, or undefined when the sampler must run per site. With
|
|
75
|
+
* simultaneous opening and closing boundaries both boundary phases are 0 at every point (exposure-window.ts, boundaryPhase), so
|
|
76
|
+
* each site's duration is the nominal one the sampler gives at the region's first site. The sampler's only other per-point step
|
|
77
|
+
* is its check that the point lies in the active capture rectangle; the region's first and last site centres bound every other
|
|
78
|
+
* centre, so when both pass every site passes. When either throws, the per-site path runs (and throws where it did).
|
|
79
|
+
*/
|
|
80
|
+
export declare function simultaneousExposureDuration(schedule: {
|
|
81
|
+
opening: unknown;
|
|
82
|
+
closing: unknown;
|
|
83
|
+
}, sampler: (point: {
|
|
84
|
+
x: number;
|
|
85
|
+
y: number;
|
|
86
|
+
}) => {
|
|
87
|
+
localExposureDurationSeconds: number;
|
|
88
|
+
}, region: {
|
|
89
|
+
x: number;
|
|
90
|
+
y: number;
|
|
91
|
+
width: number;
|
|
92
|
+
height: number;
|
|
93
|
+
}): number | undefined;
|
|
57
94
|
/** Renders the native RAW from tabulated expected electrons, or returns undefined when verification fails (see the module comment). */
|
|
58
95
|
export declare function renderTabulatedNativeRaw(t: TabulatedNativeRawInput): Promise<TabulatedNativeRawResult | undefined>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
-
import { executeEnvironmentSensorPhotoSignal } from "../sensor/environment-photo-signal.js";
|
|
2
|
+
import { executeEngineOwnedEnvironmentPhotoSignal, executeEnvironmentSensorPhotoSignal } from "../sensor/environment-photo-signal.js";
|
|
3
|
+
import { isInternalSceneRadianceEvaluator } from "../core/internal-radiance-evaluator.js";
|
|
3
4
|
import { calculateCaptureExposureWindows, prepareCaptureExposureWindowSampler } from "../sensor/exposure-window.js";
|
|
4
5
|
import { createEnvironmentRawFrameCanonicalMemo, planEnvironmentRawSite } from "./environment-raw-producer.js";
|
|
5
6
|
import { admitNativeEnvironmentInput } from "./native-environment-raw.js";
|
|
@@ -13,9 +14,32 @@ export const TABULATED_RELATIVE_TOLERANCE = 1e-9;
|
|
|
13
14
|
const BAND_ROWS = 32;
|
|
14
15
|
/** Host-yield budget in milliseconds (the native task's cadence); the task also yields after its last row. */
|
|
15
16
|
const YIELD_MS = 8;
|
|
17
|
+
/** Internal counters (tests assert how many verification sites ran the chain per call; four, one per CFA phase). */
|
|
18
|
+
export const tabulatedVerificationStatistics = { chainExecutions: 0 };
|
|
19
|
+
let testHook;
|
|
20
|
+
export function setTabulatedVerificationTestHook(hook) { testHook = hook; }
|
|
16
21
|
let tabulatedDisabled = false;
|
|
17
22
|
/** Disables the tabulated path process-wide (internal; tests of the environment path itself turn it off). */
|
|
18
23
|
export function setTabulatedNativeRawEnabled(enabled) { tabulatedDisabled = !enabled; }
|
|
24
|
+
/**
|
|
25
|
+
* #449: the local exposure duration shared by every site of `region`, or undefined when the sampler must run per site. With
|
|
26
|
+
* simultaneous opening and closing boundaries both boundary phases are 0 at every point (exposure-window.ts, boundaryPhase), so
|
|
27
|
+
* each site's duration is the nominal one the sampler gives at the region's first site. The sampler's only other per-point step
|
|
28
|
+
* is its check that the point lies in the active capture rectangle; the region's first and last site centres bound every other
|
|
29
|
+
* centre, so when both pass every site passes. When either throws, the per-site path runs (and throws where it did).
|
|
30
|
+
*/
|
|
31
|
+
export function simultaneousExposureDuration(schedule, sampler, region) {
|
|
32
|
+
if (schedule.opening.kind !== "simultaneous" || schedule.closing.kind !== "simultaneous")
|
|
33
|
+
return undefined;
|
|
34
|
+
try {
|
|
35
|
+
const first = sampler({ x: region.x + 0.5, y: region.y + 0.5 }).localExposureDurationSeconds;
|
|
36
|
+
const last = sampler({ x: region.x + region.width - 0.5, y: region.y + region.height - 0.5 }).localExposureDurationSeconds;
|
|
37
|
+
return Object.is(first, last) ? first : undefined;
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
19
43
|
/** Renders the native RAW from tabulated expected electrons, or returns undefined when verification fails (see the module comment). */
|
|
20
44
|
export async function renderTabulatedNativeRaw(t) {
|
|
21
45
|
if (tabulatedDisabled)
|
|
@@ -30,13 +54,20 @@ export async function renderTabulatedNativeRaw(t) {
|
|
|
30
54
|
const seed = plan.exposure.noise.seedUint32, schedule = plan.exposureWindow, memo = createEnvironmentRawFrameCanonicalMemo(plan.frame, schedule);
|
|
31
55
|
let evaluations = 0;
|
|
32
56
|
const evaluate = (request) => { evaluations++; return t.evaluateRadiance(request); };
|
|
57
|
+
// The counting wrapper returns the evaluator's own results, so they are engine-built exactly when the evaluator is.
|
|
58
|
+
const engineBuiltResults = isInternalSceneRadianceEvaluator(t.evaluateRadiance);
|
|
33
59
|
// Verification: the region's top-left 2 × 2 block, one site per CFA phase, through the full chain.
|
|
34
60
|
const readouts = [];
|
|
35
61
|
let worst = 0;
|
|
36
62
|
for (let k = 0; k < 4; k++) {
|
|
37
63
|
const x = region.x + (k & 1), y = region.y + (k >> 1), index = y * W + x, site = t.siteInput(index);
|
|
38
64
|
const full = planEnvironmentRawSite(site, index, plan.frame, sceneBinding, schedule, "engine-owned", memo, "photo-only");
|
|
39
|
-
|
|
65
|
+
// #453: the chain for these engine-built site records (the same operations and values as executeEnvironmentSensorPhotoSignal,
|
|
66
|
+
// without re-validating records that have not changed; see executeEngineOwnedEnvironmentPhotoSignal).
|
|
67
|
+
const photoResult = executeEngineOwnedEnvironmentPhotoSignal(full, evaluate, engineBuiltResults), photo = photoResult.value.photoSignal;
|
|
68
|
+
tabulatedVerificationStatistics.chainExecutions++;
|
|
69
|
+
if (testHook?.fullPhoto)
|
|
70
|
+
testHook.fullPhoto(photoResult, executeEnvironmentSensorPhotoSignal(full, t.evaluateRadiance, undefined, "photo-only").value.photo);
|
|
40
71
|
const timing = calculateCaptureExposureWindows({ ...schedule, nativeRaster: native, samplePointsNative: [{ x: x + 0.5, y: y + 0.5 }] }).value.samples[0];
|
|
41
72
|
const parsed = parseNativeRawProducerSite(composeNativeEnvironmentSensorSite(site, photo), index, plan.frame, timing);
|
|
42
73
|
const result = calculateNativeRawSite(parsed, seed, index);
|
|
@@ -45,7 +76,7 @@ export async function renderTabulatedNativeRaw(t) {
|
|
|
45
76
|
if (!readout)
|
|
46
77
|
return undefined;
|
|
47
78
|
t.electrons.window(x, y, x + 1, y + 1);
|
|
48
|
-
const chain = photo.expectedGeneratedElectronCount, tabulated = t.electrons.site(x, y);
|
|
79
|
+
const chain = photo.expectedGeneratedElectronCount, tabulated = testHook?.tabulatedElectrons ? testHook.tabulatedElectrons(t.electrons.site(x, y), x, y) : t.electrons.site(x, y);
|
|
49
80
|
const difference = chain === tabulated ? 0 : Math.abs(tabulated - chain) / Math.max(Math.abs(chain), Number.MIN_VALUE);
|
|
50
81
|
if (!(difference <= TABULATED_RELATIVE_TOLERANCE))
|
|
51
82
|
return undefined;
|
|
@@ -57,6 +88,7 @@ export async function renderTabulatedNativeRaw(t) {
|
|
|
57
88
|
saturationFlags: new Uint8Array(length), effectiveSaturationCodes: new Uint16Array(4) };
|
|
58
89
|
const white = createPhaseWhiteLevelAccumulator(W, 2, 2), sampler = prepareCaptureExposureWindowSampler({ ...schedule, nativeRaster: native });
|
|
59
90
|
const tilesPerRow = Math.ceil(region.width / t.tileWidth), point = { x: 0, y: 0 };
|
|
91
|
+
const constantDuration = simultaneousExposureDuration(schedule, sampler, region);
|
|
60
92
|
let last = Date.now();
|
|
61
93
|
for (let y0 = region.y; y0 < region.y + region.height; y0 += BAND_ROWS) {
|
|
62
94
|
const y1 = Math.min(region.y + region.height, y0 + BAND_ROWS);
|
|
@@ -64,9 +96,13 @@ export async function renderTabulatedNativeRaw(t) {
|
|
|
64
96
|
for (let y = y0; y < y1; y++) {
|
|
65
97
|
for (let x = region.x; x < region.x + region.width; x++) {
|
|
66
98
|
const index = y * W + x, at = (y - region.y) * region.width + x - region.x;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
99
|
+
let duration = constantDuration;
|
|
100
|
+
if (duration === undefined) {
|
|
101
|
+
point.x = x + 0.5;
|
|
102
|
+
point.y = y + 0.5;
|
|
103
|
+
duration = sampler(point).localExposureDurationSeconds;
|
|
104
|
+
}
|
|
105
|
+
const o = readouts[(y & 1) * 2 + (x & 1)].compute(t.electrons.site(x, y), duration, x, y, index, seed);
|
|
70
106
|
// A check of the full path failed for this site: let the environment task decide (it throws its own error).
|
|
71
107
|
if (!o)
|
|
72
108
|
return undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"native-environment-tabulated.js","sourceRoot":"","sources":["../../src/capture/native-environment-tabulated.ts"],"names":[],"mappings":"AAAA,sCAAsC;AAoBtC,OAAO,EAAE,mCAAmC,EAAE,MAAM,uCAAuC,CAAC;AAC5F,OAAO,EAAE,+BAA+B,EAAE,mCAAmC,EAAE,MAAM,8BAA8B,CAAC;AACpH,OAAO,EAAE,sCAAsC,EAAE,sBAAsB,EAA+C,MAAM,+BAA+B,CAAC;AAC5J,OAAO,EAAE,2BAA2B,EAAkC,MAAM,6BAA6B,CAAC;AAC1G,OAAO,EAAE,kCAAkC,EAAE,MAAM,uCAAuC,CAAC;AAC3F,OAAO,EAAE,sBAAsB,EAAE,0BAA0B,EAAE,MAAM,0BAA0B,CAAC;AAC9F,OAAO,EAAE,oCAAoC,EAAE,gCAAgC,EAAE,MAAM,sBAAsB,CAAC;AAC9G,OAAO,EAAE,+BAA+B,EAA0B,MAAM,8BAA8B,CAAC;AAGvG,wIAAwI;AACxI,MAAM,CAAC,MAAM,4BAA4B,GAAG,IAAI,CAAC;AACjD,6CAA6C;AAC7C,MAAM,SAAS,GAAG,EAAE,CAAC;AACrB,8GAA8G;AAC9G,MAAM,QAAQ,GAAG,CAAC,CAAC;AAEnB,IAAI,iBAAiB,GAAG,KAAK,CAAC;AAC9B,6GAA6G;AAC7G,MAAM,UAAU,4BAA4B,CAAC,OAAgB,IAAU,iBAAiB,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC;AA2BtG,uIAAuI;AACvI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E,GAAG,IAAI,IAAI,QAAQ,EAAE,CAAC;gBAAC,MAAM,CAAC,CAAC,YAAY,EAAE,CAAC;gBAAC,CAAC,CAAC,UAAU,EAAE,CAAC;gBAAC,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YAAC,CAAC;QACzI,CAAC;IACH,CAAC;IACD,GAAG,CAAC,wBAAwB,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;IAC9E,OAAO,EAAE,GAAG,EAAE,uBAAuB,EAAE,WAAW,GAAG,CAAC,CAAC,SAAS,CAAC,OAAO,EAAE,8BAA8B,EAAE,KAAK,EAAE,CAAC;AACpH,CAAC","sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\n/**\n * Internal (#394 step 2, not exported from the package): the native RAW of an engine-built planar scene (a chart preset or a\n * caller material scene, still camera, rectilinear, no distortion, vignetting, pupil rays or caller PSF) from tabulated\n * expected electrons instead of the per-site environment chain.\n *\n * Each site's expected photo electrons come from the display view's tabulated expected signal (`createDisplayViewExpectedSignal`):\n * the same sum over pixel-aperture nodes, anti-aliasing spots, diffraction taps and spectral nodes as the environment chain,\n * formed in another order, so the value differs from the chain's only in the last bits. The sensor stage is the native one:\n * dark charge, both Poisson draws, read noise and the ADC with the site's own seeds (`createVerifiedNativeSiteReadout`). A\n * site whose expected electrons differ in the last bit can therefore, rarely, draw a different integer; the statistics are\n * unchanged.\n *\n * Verification at run time: one site of each CFA phase runs the full chain (planning, the evaluator's callbacks, composition,\n * parsing and `calculateNativeRawSite`). Its readout template must reproduce that site bit for bit, and its tabulated\n * electrons must agree with the chain's within `TABULATED_RELATIVE_TOLERANCE`; otherwise the caller runs the environment task.\n */\n\nimport type { EnvironmentRadianceEvaluator } from \"../sensor/environment-photo-signal.js\";\nimport { executeEnvironmentSensorPhotoSignal } from \"../sensor/environment-photo-signal.js\";\nimport { calculateCaptureExposureWindows, prepareCaptureExposureWindowSampler } from \"../sensor/exposure-window.js\";\nimport { createEnvironmentRawFrameCanonicalMemo, planEnvironmentRawSite, type SimulateEnvironmentSensorRawFrameInput } from \"./environment-raw-producer.js\";\nimport { admitNativeEnvironmentInput, type NativeEnvironmentRawInput } from \"./native-environment-raw.js\";\nimport { composeNativeEnvironmentSensorSite } from \"./native-environment-optical-stage.js\";\nimport { calculateNativeRawSite, parseNativeRawProducerSite } from \"./sensor-raw-producer.js\";\nimport { calculateSiteEffectiveSaturationCode, createPhaseWhiteLevelAccumulator } from \"./raw-white-level.js\";\nimport { createVerifiedNativeSiteReadout, type NativeSiteReadout } from \"./native-environment-lean.js\";\nimport type { NativeRawOutput } from \"./native-raw.js\";\n\n/** Largest relative difference between a verification site's tabulated and chain electrons: rounding only (a few ulps of each term). */\nexport const TABULATED_RELATIVE_TOLERANCE = 1e-9;\n/** Rows per expected-signal cache window. */\nconst BAND_ROWS = 32;\n/** Host-yield budget in milliseconds (the native task's cadence); the task also yields after its last row. */\nconst YIELD_MS = 8;\n\nlet tabulatedDisabled = false;\n/** Disables the tabulated path process-wide (internal; tests of the environment path itself turn it off). */\nexport function setTabulatedNativeRawEnabled(enabled: boolean): void { tabulatedDisabled = !enabled; }\n\nexport interface TabulatedNativeRawInput {\n input: NativeEnvironmentRawInput;\n /** Native rectangle to render (region rendering); absent: the whole raster. */\n region?: { x: number; y: number; width: number; height: number } | undefined;\n /** The engine-built site record of a native index (the facade's `siteInput`). */\n siteInput(index: number): SimulateEnvironmentSensorRawFrameInput[\"sites\"][number];\n /** The evaluator the environment task would use (for the verification sites). */\n evaluateRadiance: EnvironmentRadianceEvaluator;\n /** Expected photo electrons of native sites (`createDisplayViewExpectedSignal`). */\n electrons: { window(x0: number, y0: number, x1: number, y1: number): void; site(x: number, y: number): number; readonly lookups: number };\n /** Called once per native tile-equivalent (progress), as the environment task reads its tiles. */\n onTile?: () => void;\n tileWidth: number;\n yieldControl(): Promise<void>;\n checkAbort(): void;\n}\n\nexport interface TabulatedNativeRawResult {\n raw: NativeRawOutput;\n /** Evaluator callbacks of the verification sites plus the tabulated signal's scene lookups. */\n providerEvaluationCount: number;\n /** Largest relative difference between tabulated and chain electrons over the verification sites. */\n verificationRelativeDifference: number;\n}\n\n/** Renders the native RAW from tabulated expected electrons, or returns undefined when verification fails (see the module comment). */\nexport async function renderTabulatedNativeRaw(t: TabulatedNativeRawInput): Promise<TabulatedNativeRawResult | undefined> {\n if (tabulatedDisabled) return undefined;\n const { plan, sceneBinding } = admitNativeEnvironmentInput(t.input);\n const native = plan.exposure.geometry.nativeRaster, W = native.pixelWidth, layout = plan.frame.colorSamplingProfile.layout;\n if (layout.kind !== \"periodic-mosaic\" || layout.repeatWidthSites !== 2 || layout.repeatHeightSites !== 2 || !plan.exposureWindow) return undefined;\n const region = t.region ?? { x: 0, y: 0, width: W, height: native.pixelHeight };\n if (region.width < 2 || region.height < 2) return undefined;\n const seed = plan.exposure.noise.seedUint32, schedule = plan.exposureWindow, memo = createEnvironmentRawFrameCanonicalMemo(plan.frame, schedule);\n let evaluations = 0;\n const evaluate: EnvironmentRadianceEvaluator = (request) => { evaluations++; return t.evaluateRadiance(request); };\n // Verification: the region's top-left 2 × 2 block, one site per CFA phase, through the full chain.\n const readouts: NativeSiteReadout[] = [];\n let worst = 0;\n for (let k = 0; k < 4; k++) {\n const x = region.x + (k & 1), y = region.y + (k >> 1), index = y * W + x, site = t.siteInput(index);\n const full = planEnvironmentRawSite(site, index, plan.frame, sceneBinding, schedule, \"engine-owned\", memo, \"photo-only\");\n const photo = executeEnvironmentSensorPhotoSignal(full, evaluate, undefined, \"photo-only\").value.photo.value.photoSignal;\n const timing = calculateCaptureExposureWindows({ ...schedule, nativeRaster: native, samplePointsNative: [{ x: x + 0.5, y: y + 0.5 }] }).value.samples[0];\n const parsed = parseNativeRawProducerSite(composeNativeEnvironmentSensorSite(site, photo), index, plan.frame, timing);\n const result = calculateNativeRawSite(parsed, seed, index);\n const whiteCode = calculateSiteEffectiveSaturationCode(result.readout.value, parsed.readoutProfile, parsed.regimeId);\n const readout = createVerifiedNativeSiteReadout(parsed, result, whiteCode, photo, x, y, index, seed);\n if (!readout) return undefined;\n t.electrons.window(x, y, x + 1, y + 1);\n const chain = photo.expectedGeneratedElectronCount, tabulated = t.electrons.site(x, y);\n const difference = chain === tabulated ? 0 : Math.abs(tabulated - chain) / Math.max(Math.abs(chain), Number.MIN_VALUE);\n if (!(difference <= TABULATED_RELATIVE_TOLERANCE)) return undefined;\n worst = Math.max(worst, difference);\n readouts[(y & 1) * 2 + (x & 1)] = readout;\n }\n const length = region.width * region.height;\n const raw: NativeRawOutput = { plan, codes: new Uint16Array(length), blackLevels: new Uint16Array(length), digitalSaturationCodes: new Uint16Array(length),\n saturationFlags: new Uint8Array(length), effectiveSaturationCodes: new Uint16Array(4) };\n const white = createPhaseWhiteLevelAccumulator(W, 2, 2), sampler = prepareCaptureExposureWindowSampler({ ...schedule, nativeRaster: native });\n const tilesPerRow = Math.ceil(region.width / t.tileWidth), point = { x: 0, y: 0 };\n let last = Date.now();\n for (let y0 = region.y; y0 < region.y + region.height; y0 += BAND_ROWS) {\n const y1 = Math.min(region.y + region.height, y0 + BAND_ROWS);\n t.electrons.window(region.x, y0, region.x + region.width, y1);\n for (let y = y0; y < y1; y++) {\n for (let x = region.x; x < region.x + region.width; x++) {\n const index = y * W + x, at = (y - region.y) * region.width + x - region.x;\n point.x = x + 0.5; point.y = y + 0.5;\n const o = readouts[(y & 1) * 2 + (x & 1)]!.compute(t.electrons.site(x, y), sampler(point).localExposureDurationSeconds, x, y, index, seed);\n // A check of the full path failed for this site: let the environment task decide (it throws its own error).\n if (!o) return undefined;\n raw.codes[at] = o.rawCode; raw.blackLevels[at] = o.blackLevelCode; raw.digitalSaturationCodes[at] = o.digitalSaturationCode; raw.saturationFlags[at] = o.flags;\n white.record(index, o.whiteCode);\n }\n for (let k = 0; k < tilesPerRow; k++) t.onTile?.();\n if (y === region.y + region.height - 1 || Date.now() - last >= YIELD_MS) { await t.yieldControl(); t.checkAbort(); last = Date.now(); }\n }\n }\n raw.effectiveSaturationCodes.set(t.region ? white.partial() : white.finish());\n return { raw, providerEvaluationCount: evaluations + t.electrons.lookups, verificationRelativeDifference: worst };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"native-environment-tabulated.js","sourceRoot":"","sources":["../../src/capture/native-environment-tabulated.ts"],"names":[],"mappings":"AAAA,sCAAsC;AAsBtC,OAAO,EAAE,wCAAwC,EAAE,mCAAmC,EAAE,MAAM,uCAAuC,CAAC;AACtI,OAAO,EAAE,gCAAgC,EAAE,MAAM,wCAAwC,CAAC;AAC1F,OAAO,EAAE,+BAA+B,EAAE,mCAAmC,EAAE,MAAM,8BAA8B,CAAC;AACpH,OAAO,EAAE,sCAAsC,EAAE,sBAAsB,EAA+C,MAAM,+BAA+B,CAAC;AAC5J,OAAO,EAAE,2BAA2B,EAAkC,MAAM,6BAA6B,CAAC;AAC1G,OAAO,EAAE,kCAAkC,EAAE,MAAM,uCAAuC,CAAC;AAC3F,OAAO,EAAE,sBAAsB,EAAE,0BAA0B,EAAE,MAAM,0BAA0B,CAAC;AAC9F,OAAO,EAAE,oCAAoC,EAAE,gCAAgC,EAAE,MAAM,sBAAsB,CAAC;AAC9G,OAAO,EAAE,+BAA+B,EAA0B,MAAM,8BAA8B,CAAC;AAGvG,wIAAwI;AACxI,MAAM,CAAC,MAAM,4BAA4B,GAAG,IAAI,CAAC;AACjD,6CAA6C;AAC7C,MAAM,SAAS,GAAG,EAAE,CAAC;AACrB,8GAA8G;AAC9G,MAAM,QAAQ,GAAG,CAAC,CAAC;AAEnB,oHAAoH;AACpH,MAAM,CAAC,MAAM,+BAA+B,GAAG,EAAE,eAAe,EAAE,CAAC,EAAE,CAAC;AAWtE,IAAI,QAAmD,CAAC;AACxD,MAAM,UAAU,gCAAgC,CAAC,IAA+C,IAAU,QAAQ,GAAG,IAAI,CAAC,CAAC,CAAC;A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;gBAAC,GAAG,CAAC,sBAAsB,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,qBAAqB,CAAC;gBAAC,GAAG,CAAC,eAAe,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC;gBAC/J,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC;YACnC,CAAC;YACD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,WAAW,EAAE,CAAC,EAAE;gBAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC;YACnD,IAAI,CAAC,KAAK,MAAM,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,GAAG,CAAC,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,IAAI,QAAQ,EAAE,CAAC;gBAAC,MAAM,CAAC,CAAC,YAAY,EAAE,CAAC;gBAAC,CAAC,CAAC,UAAU,EAAE,CAAC;gBAAC,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YAAC,CAAC;QACzI,CAAC;IACH,CAAC;IACD,GAAG,CAAC,wBAAwB,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;IAC9E,OAAO,EAAE,GAAG,EAAE,uBAAuB,EAAE,WAAW,GAAG,CAAC,CAAC,SAAS,CAAC,OAAO,EAAE,8BAA8B,EAAE,KAAK,EAAE,CAAC;AACpH,CAAC","sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\n/**\n * Internal (#394 step 2, not exported from the package): the native RAW of an engine-built planar scene (a chart preset or a\n * caller material scene, still camera, rectilinear, no distortion, vignetting, pupil rays or caller PSF) from tabulated\n * expected electrons instead of the per-site environment chain.\n *\n * Each site's expected photo electrons come from the display view's tabulated expected signal (`createDisplayViewExpectedSignal`):\n * the same sum over pixel-aperture nodes, anti-aliasing spots, diffraction taps and spectral nodes as the environment chain,\n * formed in another order, so the value differs from the chain's only in the last bits. The sensor stage is the native one:\n * dark charge, both Poisson draws, read noise and the ADC with the site's own seeds (`createVerifiedNativeSiteReadout`). A\n * site whose expected electrons differ in the last bit can therefore, rarely, draw a different integer; the statistics are\n * unchanged.\n *\n * Verification at run time: one site of each CFA phase runs the full chain (planning, the evaluator's callbacks, composition,\n * parsing and `calculateNativeRawSite`). Its readout template must reproduce that site bit for bit, and its tabulated\n * electrons must agree with the chain's within `TABULATED_RELATIVE_TOLERANCE`; otherwise the caller runs the environment task.\n * #453: the chain's photo signal comes from `executeEngineOwnedEnvironmentPhotoSignal`, the same operations and values as\n * `executeEnvironmentSensorPhotoSignal` for these engine-built records, without re-validating records that cannot have changed.\n */\n\nimport type { EnvironmentRadianceEvaluator } from \"../sensor/environment-photo-signal.js\";\nimport { executeEngineOwnedEnvironmentPhotoSignal, executeEnvironmentSensorPhotoSignal } from \"../sensor/environment-photo-signal.js\";\nimport { isInternalSceneRadianceEvaluator } from \"../core/internal-radiance-evaluator.js\";\nimport { calculateCaptureExposureWindows, prepareCaptureExposureWindowSampler } from \"../sensor/exposure-window.js\";\nimport { createEnvironmentRawFrameCanonicalMemo, planEnvironmentRawSite, type SimulateEnvironmentSensorRawFrameInput } from \"./environment-raw-producer.js\";\nimport { admitNativeEnvironmentInput, type NativeEnvironmentRawInput } from \"./native-environment-raw.js\";\nimport { composeNativeEnvironmentSensorSite } from \"./native-environment-optical-stage.js\";\nimport { calculateNativeRawSite, parseNativeRawProducerSite } from \"./sensor-raw-producer.js\";\nimport { calculateSiteEffectiveSaturationCode, createPhaseWhiteLevelAccumulator } from \"./raw-white-level.js\";\nimport { createVerifiedNativeSiteReadout, type NativeSiteReadout } from \"./native-environment-lean.js\";\nimport type { NativeRawOutput } from \"./native-raw.js\";\n\n/** Largest relative difference between a verification site's tabulated and chain electrons: rounding only (a few ulps of each term). */\nexport const TABULATED_RELATIVE_TOLERANCE = 1e-9;\n/** Rows per expected-signal cache window. */\nconst BAND_ROWS = 32;\n/** Host-yield budget in milliseconds (the native task's cadence); the task also yields after its last row. */\nconst YIELD_MS = 8;\n\n/** Internal counters (tests assert how many verification sites ran the chain per call; four, one per CFA phase). */\nexport const tabulatedVerificationStatistics = { chainExecutions: 0 };\n\n/**\n * Internal test hook (never set by the engine): `fullPhoto` also runs each verification site through\n * `executeEnvironmentSensorPhotoSignal` (with the uncounted evaluator) and hands both photo signals to the test;\n * `tabulatedElectrons` replaces the tabulated electrons the gate compares, to show that a wrong fast path is rejected.\n */\nexport interface TabulatedVerificationTestHook {\n fullPhoto?(engineOwned: unknown, full: unknown): void;\n tabulatedElectrons?(value: number, x: number, y: number): number;\n}\nlet testHook: TabulatedVerificationTestHook | undefined;\nexport function setTabulatedVerificationTestHook(hook: TabulatedVerificationTestHook | undefined): void { testHook = hook; }\n\nlet tabulatedDisabled = false;\n/** Disables the tabulated path process-wide (internal; tests of the environment path itself turn it off). */\nexport function setTabulatedNativeRawEnabled(enabled: boolean): void { tabulatedDisabled = !enabled; }\n\nexport interface TabulatedNativeRawInput {\n input: NativeEnvironmentRawInput;\n /** Native rectangle to render (region rendering); absent: the whole raster. */\n region?: { x: number; y: number; width: number; height: number } | undefined;\n /** The engine-built site record of a native index (the facade's `siteInput`). */\n siteInput(index: number): SimulateEnvironmentSensorRawFrameInput[\"sites\"][number];\n /** The evaluator the environment task would use (for the verification sites). */\n evaluateRadiance: EnvironmentRadianceEvaluator;\n /** Expected photo electrons of native sites (`createDisplayViewExpectedSignal`). */\n electrons: { window(x0: number, y0: number, x1: number, y1: number): void; site(x: number, y: number): number; readonly lookups: number };\n /** Called once per native tile-equivalent (progress), as the environment task reads its tiles. */\n onTile?: () => void;\n tileWidth: number;\n yieldControl(): Promise<void>;\n checkAbort(): void;\n}\n\nexport interface TabulatedNativeRawResult {\n raw: NativeRawOutput;\n /** Evaluator callbacks of the verification sites plus the tabulated signal's scene lookups. */\n providerEvaluationCount: number;\n /** Largest relative difference between tabulated and chain electrons over the verification sites. */\n verificationRelativeDifference: number;\n}\n\n/**\n * #449: the local exposure duration shared by every site of `region`, or undefined when the sampler must run per site. With\n * simultaneous opening and closing boundaries both boundary phases are 0 at every point (exposure-window.ts, boundaryPhase), so\n * each site's duration is the nominal one the sampler gives at the region's first site. The sampler's only other per-point step\n * is its check that the point lies in the active capture rectangle; the region's first and last site centres bound every other\n * centre, so when both pass every site passes. When either throws, the per-site path runs (and throws where it did).\n */\nexport function simultaneousExposureDuration(schedule: { opening: unknown; closing: unknown }, sampler: (point: { x: number; y: number }) => { localExposureDurationSeconds: number },\n region: { x: number; y: number; width: number; height: number }): number | undefined {\n if ((schedule.opening as { kind?: unknown }).kind !== \"simultaneous\" || (schedule.closing as { kind?: unknown }).kind !== \"simultaneous\") return undefined;\n try {\n const first = sampler({ x: region.x + 0.5, y: region.y + 0.5 }).localExposureDurationSeconds;\n const last = sampler({ x: region.x + region.width - 0.5, y: region.y + region.height - 0.5 }).localExposureDurationSeconds;\n return Object.is(first, last) ? first : undefined;\n } catch {\n return undefined;\n }\n}\n\n/** Renders the native RAW from tabulated expected electrons, or returns undefined when verification fails (see the module comment). */\nexport async function renderTabulatedNativeRaw(t: TabulatedNativeRawInput): Promise<TabulatedNativeRawResult | undefined> {\n if (tabulatedDisabled) return undefined;\n const { plan, sceneBinding } = admitNativeEnvironmentInput(t.input);\n const native = plan.exposure.geometry.nativeRaster, W = native.pixelWidth, layout = plan.frame.colorSamplingProfile.layout;\n if (layout.kind !== \"periodic-mosaic\" || layout.repeatWidthSites !== 2 || layout.repeatHeightSites !== 2 || !plan.exposureWindow) return undefined;\n const region = t.region ?? { x: 0, y: 0, width: W, height: native.pixelHeight };\n if (region.width < 2 || region.height < 2) return undefined;\n const seed = plan.exposure.noise.seedUint32, schedule = plan.exposureWindow, memo = createEnvironmentRawFrameCanonicalMemo(plan.frame, schedule);\n let evaluations = 0;\n const evaluate: EnvironmentRadianceEvaluator = (request) => { evaluations++; return t.evaluateRadiance(request); };\n // The counting wrapper returns the evaluator's own results, so they are engine-built exactly when the evaluator is.\n const engineBuiltResults = isInternalSceneRadianceEvaluator(t.evaluateRadiance);\n // Verification: the region's top-left 2 × 2 block, one site per CFA phase, through the full chain.\n const readouts: NativeSiteReadout[] = [];\n let worst = 0;\n for (let k = 0; k < 4; k++) {\n const x = region.x + (k & 1), y = region.y + (k >> 1), index = y * W + x, site = t.siteInput(index);\n const full = planEnvironmentRawSite(site, index, plan.frame, sceneBinding, schedule, \"engine-owned\", memo, \"photo-only\");\n // #453: the chain for these engine-built site records (the same operations and values as executeEnvironmentSensorPhotoSignal,\n // without re-validating records that have not changed; see executeEngineOwnedEnvironmentPhotoSignal).\n const photoResult = executeEngineOwnedEnvironmentPhotoSignal(full, evaluate, engineBuiltResults), photo = photoResult.value.photoSignal;\n tabulatedVerificationStatistics.chainExecutions++;\n if (testHook?.fullPhoto) testHook.fullPhoto(photoResult, executeEnvironmentSensorPhotoSignal(full, t.evaluateRadiance, undefined, \"photo-only\").value.photo);\n const timing = calculateCaptureExposureWindows({ ...schedule, nativeRaster: native, samplePointsNative: [{ x: x + 0.5, y: y + 0.5 }] }).value.samples[0];\n const parsed = parseNativeRawProducerSite(composeNativeEnvironmentSensorSite(site, photo), index, plan.frame, timing);\n const result = calculateNativeRawSite(parsed, seed, index);\n const whiteCode = calculateSiteEffectiveSaturationCode(result.readout.value, parsed.readoutProfile, parsed.regimeId);\n const readout = createVerifiedNativeSiteReadout(parsed, result, whiteCode, photo, x, y, index, seed);\n if (!readout) return undefined;\n t.electrons.window(x, y, x + 1, y + 1);\n const chain = photo.expectedGeneratedElectronCount, tabulated = testHook?.tabulatedElectrons ? testHook.tabulatedElectrons(t.electrons.site(x, y), x, y) : t.electrons.site(x, y);\n const difference = chain === tabulated ? 0 : Math.abs(tabulated - chain) / Math.max(Math.abs(chain), Number.MIN_VALUE);\n if (!(difference <= TABULATED_RELATIVE_TOLERANCE)) return undefined;\n worst = Math.max(worst, difference);\n readouts[(y & 1) * 2 + (x & 1)] = readout;\n }\n const length = region.width * region.height;\n const raw: NativeRawOutput = { plan, codes: new Uint16Array(length), blackLevels: new Uint16Array(length), digitalSaturationCodes: new Uint16Array(length),\n saturationFlags: new Uint8Array(length), effectiveSaturationCodes: new Uint16Array(4) };\n const white = createPhaseWhiteLevelAccumulator(W, 2, 2), sampler = prepareCaptureExposureWindowSampler({ ...schedule, nativeRaster: native });\n const tilesPerRow = Math.ceil(region.width / t.tileWidth), point = { x: 0, y: 0 };\n const constantDuration = simultaneousExposureDuration(schedule, sampler, region);\n let last = Date.now();\n for (let y0 = region.y; y0 < region.y + region.height; y0 += BAND_ROWS) {\n const y1 = Math.min(region.y + region.height, y0 + BAND_ROWS);\n t.electrons.window(region.x, y0, region.x + region.width, y1);\n for (let y = y0; y < y1; y++) {\n for (let x = region.x; x < region.x + region.width; x++) {\n const index = y * W + x, at = (y - region.y) * region.width + x - region.x;\n let duration = constantDuration;\n if (duration === undefined) { point.x = x + 0.5; point.y = y + 0.5; duration = sampler(point).localExposureDurationSeconds; }\n const o = readouts[(y & 1) * 2 + (x & 1)]!.compute(t.electrons.site(x, y), duration, x, y, index, seed);\n // A check of the full path failed for this site: let the environment task decide (it throws its own error).\n if (!o) return undefined;\n raw.codes[at] = o.rawCode; raw.blackLevels[at] = o.blackLevelCode; raw.digitalSaturationCodes[at] = o.digitalSaturationCode; raw.saturationFlags[at] = o.flags;\n white.record(index, o.whiteCode);\n }\n for (let k = 0; k < tilesPerRow; k++) t.onTile?.();\n if (y === region.y + region.height - 1 || Date.now() - last >= YIELD_MS) { await t.yieldControl(); t.checkAbort(); last = Date.now(); }\n }\n }\n raw.effectiveSaturationCodes.set(t.region ? white.partial() : white.finish());\n return { raw, providerEvaluationCount: evaluations + t.electrons.lookups, verificationRelativeDifference: worst };\n}\n"]}
|
|
@@ -7,6 +7,19 @@
|
|
|
7
7
|
* callers validate inputs first.
|
|
8
8
|
*/
|
|
9
9
|
export declare function portableHypot(...values: readonly number[]): number;
|
|
10
|
+
/**
|
|
11
|
+
* V8's three-argument `Math.hypot` as a fixed sequence of correctly rounded operations, so the result has V8's bits in
|
|
12
|
+
* every JavaScript engine. The sequence is V8's `MathHypot` (src/builtins/math.tq; also its three-argument
|
|
13
|
+
* `FastMathHypot`): the largest magnitude, starting from 0, normalises the arguments; their squares are summed in
|
|
14
|
+
* argument order with Kahan compensation; the result is the square root of the sum times the largest magnitude. An
|
|
15
|
+
* infinite argument gives Infinity (even beside NaN), otherwise a NaN argument gives NaN, and all zeros give +0.
|
|
16
|
+
*
|
|
17
|
+
* It is not `portableHypot`: that function rescales by powers of two and sums without compensation, so it is portable
|
|
18
|
+
* too but gives other bits than `Math.hypot`. This one replaces `Math.hypot` where today's V8 bits must be kept (the
|
|
19
|
+
* capture's query arithmetic and the display view's copy of it), and makes the other engines compute them too.
|
|
20
|
+
* @see docs/NUMERICAL_CORRECTNESS.md §Cross-engine determinism
|
|
21
|
+
*/
|
|
22
|
+
export declare function hypot3(a: number, b: number, c: number): number;
|
|
10
23
|
/**
|
|
11
24
|
* True when two finite numbers differ by at most `maximumUlps` ULPs (units in the last place).
|
|
12
25
|
* One ULP here is `Number.EPSILON` times the larger magnitude. Use it to accept an archived value
|
|
@@ -41,6 +41,49 @@ export function portableHypot(...values) {
|
|
|
41
41
|
}
|
|
42
42
|
return Math.sqrt(sum) / scale;
|
|
43
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* V8's three-argument `Math.hypot` as a fixed sequence of correctly rounded operations, so the result has V8's bits in
|
|
46
|
+
* every JavaScript engine. The sequence is V8's `MathHypot` (src/builtins/math.tq; also its three-argument
|
|
47
|
+
* `FastMathHypot`): the largest magnitude, starting from 0, normalises the arguments; their squares are summed in
|
|
48
|
+
* argument order with Kahan compensation; the result is the square root of the sum times the largest magnitude. An
|
|
49
|
+
* infinite argument gives Infinity (even beside NaN), otherwise a NaN argument gives NaN, and all zeros give +0.
|
|
50
|
+
*
|
|
51
|
+
* It is not `portableHypot`: that function rescales by powers of two and sums without compensation, so it is portable
|
|
52
|
+
* too but gives other bits than `Math.hypot`. This one replaces `Math.hypot` where today's V8 bits must be kept (the
|
|
53
|
+
* capture's query arithmetic and the display view's copy of it), and makes the other engines compute them too.
|
|
54
|
+
* @see docs/NUMERICAL_CORRECTNESS.md §Cross-engine determinism
|
|
55
|
+
*/
|
|
56
|
+
export function hypot3(a, b, c) {
|
|
57
|
+
a = Math.abs(a);
|
|
58
|
+
b = Math.abs(b);
|
|
59
|
+
c = Math.abs(c);
|
|
60
|
+
let max = 0;
|
|
61
|
+
if (a > max)
|
|
62
|
+
max = a;
|
|
63
|
+
if (b > max)
|
|
64
|
+
max = b;
|
|
65
|
+
if (c > max)
|
|
66
|
+
max = c;
|
|
67
|
+
if (max === Infinity)
|
|
68
|
+
return Infinity;
|
|
69
|
+
if (a !== a || b !== b || c !== c)
|
|
70
|
+
return NaN;
|
|
71
|
+
if (max === 0)
|
|
72
|
+
return 0;
|
|
73
|
+
let sum = 0, compensation = 0;
|
|
74
|
+
let n = a / max, summand = n * n - compensation, preliminary = sum + summand;
|
|
75
|
+
compensation = (preliminary - sum) - summand;
|
|
76
|
+
sum = preliminary;
|
|
77
|
+
n = b / max;
|
|
78
|
+
summand = n * n - compensation;
|
|
79
|
+
preliminary = sum + summand;
|
|
80
|
+
compensation = (preliminary - sum) - summand;
|
|
81
|
+
sum = preliminary;
|
|
82
|
+
n = c / max;
|
|
83
|
+
summand = n * n - compensation;
|
|
84
|
+
sum = sum + summand;
|
|
85
|
+
return Math.sqrt(sum) * max;
|
|
86
|
+
}
|
|
44
87
|
/**
|
|
45
88
|
* True when two finite numbers differ by at most `maximumUlps` ULPs (units in the last place).
|
|
46
89
|
* One ULP here is `Number.EPSILON` times the larger magnitude. Use it to accept an archived value
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"portable-math.js","sourceRoot":"","sources":["../../src/core/portable-math.ts"],"names":[],"mappings":"AAAA,sCAAsC;AAEtC;;;;;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C,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;AAChJ,CAAC","sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\n/**\n * Floating-point helpers that give bit-identical results in every JavaScript engine.\n *\n * ECMAScript requires `+ - * /` and `Math.sqrt` to be correctly rounded IEEE 754 binary64\n * (double-precision) operations. A fixed sequence of them gives the same bits in every\n * conforming engine. `Math.hypot`, `Math.exp`, `Math.atan`, `Math.cos` and the other\n * transcendental functions are \"implementation-approximated\" (ECMA-262 §21.3.2). They can\n * differ in the last bit between V8, JavaScriptCore and SpiderMonkey.\n *\n * So any value that is stored and later recomputed for an exact identity check must use\n * only the correctly rounded operations.\n * @see docs/NUMERICAL_CORRECTNESS.md §Cross-engine determinism\n */\n\nconst LARGE = 2 ** 500;\nconst SMALL = 2 ** -500;\nconst SCALE_DOWN = 2 ** -600;\nconst SCALE_UP = 2 ** 600;\n\n/**\n * Euclidean norm (vector length) of the components. Unlike `Math.hypot`, it uses only correctly\n * rounded IEEE operations, so the result is bit-identical in every JavaScript engine.\n *\n * Components are summed in argument order. Inputs far from 1 are first rescaled by an exact power\n * of two, so squaring cannot overflow or underflow. Non-finite input gives a non-finite result;\n * callers validate inputs first.\n */\nexport function portableHypot(...values: readonly number[]): number {\n let maximum = 0;\n for (const value of values) {\n const magnitude = Math.abs(value);\n if (!(magnitude <= maximum)) maximum = magnitude;\n }\n if (maximum === 0 || !Number.isFinite(maximum)) return maximum;\n const scale = maximum > LARGE ? SCALE_DOWN : maximum < SMALL ? SCALE_UP : 1;\n let sum = 0;\n for (const value of values) {\n const scaled = value * scale;\n sum += scaled * scaled;\n }\n return Math.sqrt(sum) / scale;\n}\n\n/**\n * True when two finite numbers differ by at most `maximumUlps` ULPs (units in the last place).\n * One ULP here is `Number.EPSILON` times the larger magnitude. Use it to accept an archived value\n * that another engine or an earlier release computed with an implementation-approximated function.\n */\nexport function equalWithinUlps(a: number, b: number, maximumUlps: number): boolean {\n if (!Number.isFinite(a) || !Number.isFinite(b)) return false;\n if (a === b) return true;\n return Math.abs(a - b) <= maximumUlps * Number.EPSILON * Math.max(Math.abs(a), Math.abs(b));\n}\n\n// ---------------------------------------------------------------------------------------------------------------\n// Portable logarithm, exponential, power, cube root and cosine/sine of 2πu.\n//\n// Each function below is a fixed sequence of correctly rounded binary64 operations (+, −, ×, ÷, exact\n// power-of-two scaling through the IEEE 754 bit pattern, Math.round/Math.floor and integer operations), with\n// every constant written as a decimal literal of at most 17 significant digits (ECMAScript converts these\n// exactly to the nearest double). The bits of every result are therefore the same in every conforming\n// JavaScript engine, unlike Math.pow, Math.exp, Math.log, Math.cbrt and Math.cos, which ECMA-262 leaves\n// \"implementation-approximated\" (docs/NUMERICAL_CORRECTNESS.md, \"Cross-engine determinism\").\n//\n// Methods (textbook; no code copied):\n// - Error-free transformations (double-double arithmetic): TwoSum (Knuth, The Art of Computer Programming\n// vol. 2, §4.2.2), FastTwoSum and TwoProduct with Veltkamp's splitting (Dekker, \"A floating-point technique\n// for extending the available precision\", Numerische Mathematik 18, 1971). Exact barring overflow and\n// underflow, which the arguments here cannot reach.\n// - log2(x): x = m·2^e with m in [√½, √2); ln m = 2·atanh(s) = 2(s + s³/3 + s⁵/5 + …), s = (m − 1)/(m + 1),\n// |s| ≤ 0.1716 (J.-M. Muller, Elementary Functions: Algorithms and Implementation, 3rd ed., 2016, ch. 11).\n// s carries a double-double correction; the series runs to s²³ (truncation below 2^-62 relative).\n// - 2^t: t = n + r with n = round(t), |r| ≤ ½; 2^r = e^(r·ln 2) by its Taylor series to degree 14 (truncation\n// below 2^-57 relative), then an exact scaling by 2^n (Muller, ch. 11, \"additive range reduction\").\n// - x^y = 2^(y·log2 x) with log2 x and y·log2 x carried as double-double; e^x = 2^(x·log2 e) and\n// ∛x = 2^(log2 x / 3) likewise; ln x = log2 x · ln 2; e^x − 1 by its Taylor series for |x| < 1.\n// - cos(2πu), sin(2πu): u = q/4 + r with q = round(4u) and |r| ≤ ⅛ (exact), then the Taylor series of cos and\n// sin of 2πr to degrees 18 and 19 (truncation below 2^-66).\n//\n// Error bounds (from the operation counts above): portableExp2, portableExp, portableLog, portableLog2 and\n// portableCbrt within 1 ulp; portableExpm1 within 2 ulps; portablePow within 1 ulp for |y| ≤ 4 (the double-double\n// logarithm has relative error below 2^-56, so the error of y·log2 x adds at most |y|·2^-57·ln 2 relative);\n// portableCosTwoPi and portableSinTwoPi within 2 ulps. Checked against 60-digit decimal references (Python decimal)\n// on 2·10⁵ pseudo-random arguments per function (6·10⁵ for portableLog; |y| ≤ 4 and y = 1/2.4, 1.4 for portablePow):\n// largest errors 0.53 ulp (log, log2), 0.86 (exp2), 0.94 (exp, cbrt, pow), 0.97 (pow with y = 1/2.4), 1.59 (cos,\n// sin of 2πu) and 1.66 (e^x − 1); spot values are in test/portable-math.test.ts. These are accuracy bounds;\n// determinism does not depend on them.\n\n/** Bit access to a double: the high 32-bit word is at index HIGH of the view (detected once, so either byte order works). */\n// The tables and constants below are built by expressions marked pure (/* @__PURE__ */), so a bundler drops them from a\n// bundle that uses none of the functions that read them (a capture-only bundle keeps only portableHypot and equalWithinUlps).\nconst BITS = /* @__PURE__ */ new Float64Array(1), WORDS = /* @__PURE__ */ ((): Uint32Array => new Uint32Array(BITS.buffer))();\nconst HIGH = /* @__PURE__ */ ((): number => (new Uint8Array(new Uint16Array([1]).buffer)[0] === 1 ? 1 : 0))(), LOW = 1 - HIGH;\n/** 2^k for every integer k in [−1074, 1023] at POW2[k + 1074], built by exact halving and doubling. */\nconst POW2 = /* @__PURE__ */ ((): Float64Array => {\n const table = new Float64Array(2098);\n table[1074] = 1;\n for (let k = 1; k <= 1023; k++) table[1074 + k] = table[1073 + k]! * 2;\n for (let k = 1; k <= 1074; k++) table[1074 - k] = table[1075 - k]! / 2;\n return table;\n})();\n/** v·2^k for an integer k in [−1100, 1100]: one exact multiplication (a single rounding only when the result is subnormal). */\nfunction scaleByPowerOfTwo(v: number, k: number): number {\n if (k > 1023) return v * POW2[2097]! * POW2[1074 + k - 1023]!;\n if (k < -1074) return v * POW2[1074 + k + 1074]! * POW2[0]!; // exact first factor (v·2^(k+1074) is normal), one rounding\n return v * POW2[1074 + k]!;\n}\n// Double-double arithmetic, written out inline below (local variables only, which keeps it fast):\n// - FastTwoSum (|a| ≥ |b| or a = 0): s = a + b, err = b − (s − a), so a + b = s + err exactly;\n// - TwoSum (any a, b): s = a + b, b' = s − a, err = (a − (s − b')) + (b − b');\n// - TwoProduct: p = a·b, err = ((ah·bh − p) + ah·bl + al·bh) + al·bl, with Veltkamp's split\n// ah = c − (c − a), al = a − ah, c = (2^27 + 1)·a (and likewise for b), so a·b = p + err exactly.\nconst SPLITTER = 134217729; // 2^27 + 1 (Veltkamp)\nconst LN2_HI = 0.6931471805599453, LN2_LO = 2.3190468138462996e-17;\nconst LOG2E_HI = 1.4426950408889634, LOG2E_LO = 2.0355273740931033e-17;\nconst SQRT2 = 1.4142135623730951, TWO_POW_54 = 18014398509481984, MIN_NORMAL = 2.2250738585072014e-308;\n/** Veltkamp halves of a constant (the same values the split gives at each use). */\nfunction splitHigh(a: number): number { const c = SPLITTER * a; return c - (c - a); }\nconst LN2_HI_H = /* @__PURE__ */ splitHigh(LN2_HI), LN2_HI_L = LN2_HI - LN2_HI_H, LOG2E_HI_H = /* @__PURE__ */ splitHigh(LOG2E_HI), LOG2E_HI_L = LOG2E_HI - LOG2E_HI_H;\n/** The low part of the last double-double result (its high part is the return value). */\nconst LOW_PART = /* @__PURE__ */ new Float64Array(1);\n\n/**\n * log2 m for m in [√½, √2] by the atanh series to s²³ (no table): builds LOG2_TABLE once. Returns the high part, the low\n * part in LOW_PART[0]; relative error below 2^-56.\n */\nfunction log2SeriesDoubleDouble(x: number): number {\n let e = 0;\n if (x < MIN_NORMAL) { x *= TWO_POW_54; e = -54; }\n BITS[0] = x;\n const high = WORDS[HIGH]!;\n e += (high >>> 20) - 1023;\n let m = x * POW2[1074 - ((high >>> 20) - 1023)]!; // exact: m in [1, 2)\n if (m > SQRT2) { m *= 0.5; e += 1; }\n // s = f/(2 + f) with f = m − 1 (exact), as sHi + sLo: 2 + f = dh + dl exactly (FastTwoSum), then the residual\n // f − sHi·(dh + dl) with sHi·dh = p + pe exactly (TwoProduct).\n const f = m - 1, dh = 2 + f, dl = f - (dh - 2), sHi = f / dh, p = sHi * dh;\n let c = SPLITTER * sHi;\n const ah = c - (c - sHi), al = sHi - ah;\n c = SPLITTER * dh;\n const bh = c - (c - dh), bl = dh - bh, pe = ((ah * bh - p) + ah * bl + al * bh) + al * bl;\n const sLo = (((f - p) - pe) - sHi * dl) / dh;\n const z = sHi * sHi;\n const tail = sHi * z * (0.6666666666666666 + z * (0.4 + z * (0.2857142857142857 + z * (0.2222222222222222 + z * (0.18181818181818182 + z * (0.15384615384615385 +\n z * (0.13333333333333333 + z * (0.11764705882352941 + z * (0.10526315789473684 + z * (0.09523809523809523 + z * 0.08695652173913043))))))))));\n // ln m = 2sHi + (2sLo + tail) = lh + ll (FastTwoSum); times log2 e = LOG2E_HI + LOG2E_LO (TwoProduct of the high parts); plus e (TwoSum).\n const a1 = 2 * sHi, b1 = 2 * sLo + tail, lh = a1 + b1, ll = b1 - (lh - a1), q = lh * LOG2E_HI;\n c = SPLITTER * lh;\n const ch = c - (c - lh), cl = lh - ch, qe = ((ch * LOG2E_HI_H - q) + ch * LOG2E_HI_L + cl * LOG2E_HI_H) + cl * LOG2E_HI_L;\n const pl = qe + (lh * LOG2E_LO + ll * LOG2E_HI);\n const t = e + q, tb = t - e, te = (e - (t - tb)) + (q - tb), b2 = te + pl, hi = t + b2;\n LOW_PART[0] = b2 - (hi - t);\n return hi;\n}\n/** log2(k/128) for k = 90 … 182 (the table's range of k = round(128·m), m in [√½, √2]) as double-doubles. */\nconst LOG2_TABLE_LO = /* @__PURE__ */ new Float64Array(183);\nconst LOG2_TABLE_HI = /* @__PURE__ */ ((): Float64Array => {\n const table = new Float64Array(183);\n for (let k = 90; k <= 182; k++) { table[k] = log2SeriesDoubleDouble(k / 128); LOG2_TABLE_LO[k] = LOW_PART[0]!; }\n return table;\n})();\n/**\n * log2 x as a double-double for finite x > 0: returns the high part, the low part in LOW_PART[0]. x = m·2^e with m in\n * [√½, √2]; m = F·(1 + f/F) with F = k/128, k = round(128·m), so log2 m = log2 F (table) + 2·atanh(s)·log2 e with\n * s = f/(m + F), |s| < 2^-8.4, by its series to s⁷ (truncation below 2^-70 relative). Relative error below 2^-56.\n */\nfunction log2DoubleDouble(x: number): number {\n let e = 0;\n if (x < MIN_NORMAL) { x *= TWO_POW_54; e = -54; }\n BITS[0] = x;\n const high = WORDS[HIGH]!;\n e += (high >>> 20) - 1023;\n let m = x * POW2[1074 - ((high >>> 20) - 1023)]!; // exact: m in [1, 2)\n if (m > SQRT2) { m *= 0.5; e += 1; }\n // F = k/128 (exact) and f = m − F (exact, F/2 ≤ m ≤ 2F); m + F = dh + dl exactly (TwoSum); s = f/(dh + dl) as sHi + sLo\n // from the residual f − sHi·(dh + dl), with sHi·dh = p + pe exactly (TwoProduct).\n const k = Math.round(m * 128), F = k / 128, f = m - F, dh = m + F, db = dh - m, dl = (m - (dh - db)) + (F - db);\n const sHi = f / dh, p = sHi * dh;\n let c = SPLITTER * sHi;\n const ah = c - (c - sHi), al = sHi - ah;\n c = SPLITTER * dh;\n const bh = c - (c - dh), bl = dh - bh, pe = ((ah * bh - p) + ah * bl + al * bh) + al * bl;\n const sLo = (((f - p) - pe) - sHi * dl) / dh, z = sHi * sHi;\n const tail = sHi * z * (0.6666666666666666 + z * (0.4 + z * 0.2857142857142857));\n // ln(m/F) = 2sHi + (2sLo + tail) = lh + ll (FastTwoSum); times log2 e = LOG2E_HI + LOG2E_LO (TwoProduct of the high\n // parts); plus log2 F (TwoSum with the table's high part), then plus e (TwoSum).\n const a1 = 2 * sHi, b1 = 2 * sLo + tail, lh = a1 + b1, ll = b1 - (lh - a1), q = lh * LOG2E_HI;\n c = SPLITTER * lh;\n const ch = c - (c - lh), cl = lh - ch, qe = ((ch * LOG2E_HI_H - q) + ch * LOG2E_HI_L + cl * LOG2E_HI_H) + cl * LOG2E_HI_L;\n const pl = qe + (lh * LOG2E_LO + ll * LOG2E_HI), th = LOG2_TABLE_HI[k]!;\n const t = th + q, tb = t - th, low = ((th - (t - tb)) + (q - tb)) + (pl + LOG2_TABLE_LO[k]!);\n const u = e + t, ub = u - e, b2 = ((e - (u - ub)) + (t - ub)) + low, hi = u + b2;\n LOW_PART[0] = b2 - (hi - u);\n return hi;\n}\n/** 2^(th + tl) for a double-double exponent; within 1 ulp (plus the error the exponent carries). */\nfunction exp2DoubleDouble(th: number, tl: number): number {\n if (th !== th) return NaN;\n if (th > 1024) return Infinity;\n if (th < -1080) return 0;\n // th = n + r exactly (|r| ≤ ½); w = r·ln 2 = wh + wl (TwoProduct with LN2_HI, plus r·LN2_LO).\n const n = Math.round(th), r = (th - n) + tl, wh = r * LN2_HI, c = SPLITTER * r, ah = c - (c - r), al = r - ah;\n const wl = (((ah * LN2_HI_H - wh) + ah * LN2_HI_L + al * LN2_HI_H) + al * LN2_HI_L) + r * LN2_LO;\n const q = 0.5 + wh * (0.16666666666666666 + wh * (0.041666666666666664 + wh * (0.008333333333333333 + wh * (0.001388888888888889 + wh * (0.0001984126984126984 +\n wh * (2.48015873015873e-05 + wh * (2.7557319223985893e-06 + wh * (2.755731922398589e-07 + wh * (2.505210838544172e-08 + wh * (2.08767569878681e-09 +\n wh * (1.6059043836821613e-10 + wh * 1.1470745597729725e-11)))))))))));\n return scaleByPowerOfTwo(1 + (wh + (wl + wh * wh * q)), n);\n}\n\n/** log2 x, bit-identical in every JavaScript engine (within 1 ulp). 0 → −∞; negative or NaN → NaN; +∞ → +∞. */\nexport function portableLog2(x: number): number {\n if (!(x > 0)) return x === 0 ? -Infinity : NaN;\n if (x === Infinity) return Infinity;\n const h = log2DoubleDouble(x);\n return h + LOW_PART[0]!;\n}\n/** ln(k/128) for k = 90 … 182 as double-doubles (log2(k/128)·ln 2, TwoProduct with LN2_HI plus the small products). */\nconst LN_TABLE_LO = /* @__PURE__ */ new Float64Array(183);\nconst LN_TABLE_HI = /* @__PURE__ */ ((): Float64Array => {\n const table = new Float64Array(183);\n for (let k = 90; k <= 182; k++) {\n const h = LOG2_TABLE_HI[k]!, l = LOG2_TABLE_LO[k]!, p = h * LN2_HI, c = SPLITTER * h, ah = c - (c - h), al = h - ah;\n const pe = ((ah * LN2_HI_H - p) + ah * LN2_HI_L + al * LN2_HI_H) + al * LN2_HI_L, lo = pe + (h * LN2_LO + l * LN2_HI), hi = p + lo;\n table[k] = hi; LN_TABLE_LO[k] = lo - (hi - p);\n }\n return table;\n})();\n/** ln 2 = LN2_E_HI + LN2_E_LO with the low 32 bits of LN2_E_HI zero, so e·LN2_E_HI is exact for every exponent e here. */\nconst LN2_E_HI = /* @__PURE__ */ ((): number => { BITS[0] = LN2_HI; WORDS[LOW] = 0; return BITS[0]!; })(), LN2_E_LO = (LN2_HI - LN2_E_HI) + LN2_LO;\n/**\n * Natural logarithm, bit-identical in every JavaScript engine (within 1 ulp). 0 → −∞; negative or NaN → NaN; +∞ → +∞.\n * x = m·2^e, m in [√½, √2]; ln x = e·ln 2 + ln F (table, F = k/128, k = round(128·m)) + 2·atanh(s), s = (m − F)/(m + F),\n * with s as a double-double and the three terms added with TwoSum.\n */\nexport function portableLog(x: number): number {\n if (!(x > 0)) return x === 0 ? -Infinity : NaN;\n if (x === Infinity) return Infinity;\n let e = 0;\n if (x < MIN_NORMAL) { x *= TWO_POW_54; e = -54; }\n BITS[0] = x;\n const high = WORDS[HIGH]!;\n e += (high >>> 20) - 1023;\n let m = x * POW2[1074 - ((high >>> 20) - 1023)]!; // exact: m in [1, 2)\n if (m > SQRT2) { m *= 0.5; e += 1; }\n const k = Math.round(m * 128), F = k / 128, f = m - F, dh = m + F, db = dh - m, dl = (m - (dh - db)) + (F - db);\n const sHi = f / dh, p = sHi * dh;\n let c = SPLITTER * sHi;\n const ah = c - (c - sHi), al = sHi - ah;\n c = SPLITTER * dh;\n const bh = c - (c - dh), bl = dh - bh, pe = ((ah * bh - p) + ah * bl + al * bh) + al * bl;\n const sLo = (((f - p) - pe) - sHi * dl) / dh, z = sHi * sHi;\n const tail = sHi * z * (0.6666666666666666 + z * (0.4 + z * 0.2857142857142857));\n // (e·LN2_E_HI + ln F) + 2sHi with TwoSum errors, then the low parts.\n const A = e * LN2_E_HI, B = LN_TABLE_HI[k]!, t = A + B, tb = t - A, te = (A - (t - tb)) + (B - tb);\n const a2 = 2 * sHi, u = t + a2, ub = u - t, ue = (t - (u - ub)) + (a2 - ub);\n return u + ((te + ue) + ((e * LN2_E_LO + LN_TABLE_LO[k]!) + (2 * sLo + tail)));\n}\n/** 2^x, bit-identical in every JavaScript engine (within 1 ulp). */\nexport function portableExp2(x: number): number { return exp2DoubleDouble(x, 0); }\n/** e^x, bit-identical in every JavaScript engine (within 1 ulp). */\nexport function portableExp(x: number): number {\n if (x !== x) return NaN;\n if (x > 710) return Infinity;\n if (x < -746) return 0;\n // x·log2 e = th + tl: x·LOG2E_HI = th + te exactly (TwoProduct), plus x·LOG2E_LO.\n const th = x * LOG2E_HI, c = SPLITTER * x, ah = c - (c - x), al = x - ah;\n const te = ((ah * LOG2E_HI_H - th) + ah * LOG2E_HI_L + al * LOG2E_HI_H) + al * LOG2E_HI_L;\n return exp2DoubleDouble(th, te + x * LOG2E_LO);\n}\n/**\n * e^x − 1, bit-identical in every JavaScript engine (within 2 ulps): the Taylor series to degree 20 for |x| < 1\n * (truncation below 2^-60 relative), else portableExp(x) − 1.\n */\nexport function portableExpm1(x: number): number {\n if (x !== x) return NaN;\n if (x === 0) return x;\n if (!(x > -1 && x < 1)) return portableExp(x) - 1;\n return x + x * x * (0.5 + x * (0.16666666666666666 + x * (0.041666666666666664 + x * (0.008333333333333333 + x * (0.001388888888888889 + x * (0.0001984126984126984 +\n x * (2.48015873015873e-05 + x * (2.7557319223985893e-06 + x * (2.755731922398589e-07 + x * (2.505210838544172e-08 + x * (2.08767569878681e-09 +\n x * (1.6059043836821613e-10 + x * (1.1470745597729725e-11 + x * (7.647163731819816e-13 + x * (4.779477332387385e-14 + x * (2.8114572543455206e-15 +\n x * (1.5619206968586225e-16 + x * (8.22063524662433e-18 + x * 4.110317623312165e-19))))))))))))))))));\n}\n/**\n * x^y for x ≥ 0 and finite y, bit-identical in every JavaScript engine (within 1 ulp for |y| ≤ 4). x = 0 gives 0 for\n * y > 0, 1 for y = 0 and +∞ for y < 0; negative x or a non-finite argument gives NaN (the callers never pass them).\n */\nexport function portablePow(x: number, y: number): number {\n if (!(x >= 0) || !Number.isFinite(x) || !Number.isFinite(y)) return NaN;\n if (y === 0 || x === 1) return 1;\n if (x === 0) return y > 0 ? 0 : Infinity;\n // y·(lh + ll): lh·y = p + pe exactly (TwoProduct), then FastTwoSum(p, pe + ll·y).\n const lh = log2DoubleDouble(x), ll = LOW_PART[0]!, p = lh * y;\n let c = SPLITTER * lh;\n const ah = c - (c - lh), al = lh - ah;\n c = SPLITTER * y;\n const bh = c - (c - y), bl = y - bh, pe = ((ah * bh - p) + ah * bl + al * bh) + al * bl;\n const b = pe + ll * y, th = p + b;\n return exp2DoubleDouble(th, b - (th - p));\n}\n/** ∛(2^r) for r = 0, 1, 2 (only scale the cube root's starting value, so their last bits do not matter). */\nconst CBRT_POWERS_OF_TWO = [1, 1.2599210498948732, 1.5874010519681994];\n/**\n * Cube root, bit-identical in every JavaScript engine (within 1 ulp; exact for ±0, ±∞ and cubes of powers of two).\n * |x| = m·2^(3q + r) with m in [1, 2) and r in {0, 1, 2}, w = m·2^r: a cubic fit to ∛m (within 1.7·10⁻⁴) times ∛(2^r),\n * one Halley step y ← y(y³ + 2w)/(2y³ + w) (cubic convergence: below 10⁻¹¹), then one Newton step y + (w − y³)/(3y²)\n * with w − y³ formed exactly (TwoProduct), which leaves only the final rounding and errors near 10⁻²².\n */\nexport function portableCbrt(x: number): number {\n if (x === 0 || x !== x || !Number.isFinite(x)) return x;\n let a = x < 0 ? -x : x, shift = 0;\n if (a < MIN_NORMAL) { a *= TWO_POW_54; shift = -18; }\n BITS[0] = a;\n const high = WORDS[HIGH]!, e = (high >>> 20) - 1023, q = Math.floor(e / 3), r = e - 3 * q;\n const m = a * POW2[1074 - e]!, w = m * CBRT_SCALE[r]!; // exact: m in [1, 2)\n let y = (0.5561432746078446 + m * (0.5806821751356804 + m * (-0.15894786280039686 + m * 0.022291567104952514))) * CBRT_POWERS_OF_TWO[r]!;\n const y3 = y * y * y;\n y = y * (y3 + 2 * w) / (2 * y3 + w);\n // y² = p + pe exactly; y³ = p·y + pe·y = t + te (TwoProduct of p and y, plus pe·y); w − y³ = (w − t) − te.\n const p = y * y;\n let c = SPLITTER * y;\n const yh = c - (c - y), yl = y - yh, pe = ((yh * yh - p) + yh * yl + yl * yh) + yl * yl, t = p * y;\n c = SPLITTER * p;\n const ph = c - (c - p), pll = p - ph, te = (((ph * yh - t) + ph * yl + pll * yh) + pll * yl) + pe * y;\n const root = scaleByPowerOfTwo(y + ((w - t) - te) / (3 * p), q + shift);\n return x < 0 ? -root : root;\n}\n/** 2^r for r = 0, 1, 2. */\nconst CBRT_SCALE = [1, 2, 4];\n/** cos(2πr) and sin(2πr) for |r| ≤ ⅛ (Taylor series in z = r²). */\nfunction cosTwoPiReduced(r: number): number {\n const z = r * r;\n return 1 + z * (-19.739208802178716 + z * (64.9393940226683 + z * (-85.45681720669373 + z * (60.24464137187666 + z * (-26.4262567833744 + z * (7.903536371318469 +\n z * (-1.714390711088672 + z * (0.28200596845579123 + z * -0.03638284114254567))))))));\n}\nfunction sinTwoPiReduced(r: number): number {\n const z = r * r;\n return r * (6.283185307179586 + z * (-41.34170224039976 + z * (81.60524927607506 + z * (-76.70585975306139 + z * (42.058693944897655 + z * (-15.09464257682299 +\n z * (3.819952584848282 + z * (-0.7181223017785006 + z * (0.10422916220813984 + z * -0.012031585942120627)))))))));\n}\n/** cos(2πu) for finite u (u in turns), bit-identical in every JavaScript engine (within 2 ulps). */\nexport function portableCosTwoPi(u: number): number {\n if (!Number.isFinite(u)) return NaN;\n const t = 4 * u, q = Math.round(t), r = (t - q) / 4, quadrant = ((q % 4) + 4) % 4;\n return quadrant === 0 ? cosTwoPiReduced(r) : quadrant === 1 ? -sinTwoPiReduced(r) : quadrant === 2 ? -cosTwoPiReduced(r) : sinTwoPiReduced(r);\n}\n/** sin(2πu) for finite u (u in turns), bit-identical in every JavaScript engine (within 2 ulps). */\nexport function portableSinTwoPi(u: number): number {\n if (!Number.isFinite(u)) return NaN;\n const t = 4 * u, q = Math.round(t), r = (t - q) / 4, quadrant = ((q % 4) + 4) % 4;\n return quadrant === 0 ? sinTwoPiReduced(r) : quadrant === 1 ? cosTwoPiReduced(r) : quadrant === 2 ? -sinTwoPiReduced(r) : -cosTwoPiReduced(r);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"portable-math.js","sourceRoot":"","sources":["../../src/core/portable-math.ts"],"names":[],"mappings":"AAAA,sCAAsC;AAEtC;;;;;;;;;;;;GAYG;AAEH,MAAM,KAAK,GAAG,CAAC,IAAI,GAAG,CAAC;AACvB,MAAM,KAAK,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC;AACxB,MAAM,UAAU,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC;AAC7B,MAAM,QAAQ,GAAG,CAAC,IAAI,GAAG,CAAC;AAE1B;;;;;;;GAOG;AACH,MAAM,UAAU,aAAa,CAAC,GAAG,MAAyB;IACxD,IAAI,OAAO,GAAG,CAAC,CAAC;IAChB,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAClC,IAAI,CAAC,CAAC,SAAS,IAAI,OAAO,CAAC;YAAE,OAAO,GAAG,SAAS,CAAC;IACnD,CAAC;IACD,IAAI,OAAO,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC;QAA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CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;AAChJ,CAAC;AACD,oGAAoG;AACpG,MAAM,UAAU,gBAAgB,CAAC,CAAS;IACxC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;QAAE,OAAO,GAAG,CAAC;IACpC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,EAAE,QAAQ,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;IAClF,OAAO,QAAQ,KAAK,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,KAAK,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;AAChJ,CAAC","sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\n/**\n * Floating-point helpers that give bit-identical results in every JavaScript engine.\n *\n * ECMAScript requires `+ - * /` and `Math.sqrt` to be correctly rounded IEEE 754 binary64\n * (double-precision) operations. A fixed sequence of them gives the same bits in every\n * conforming engine. `Math.hypot`, `Math.exp`, `Math.atan`, `Math.cos` and the other\n * transcendental functions are \"implementation-approximated\" (ECMA-262 §21.3.2). They can\n * differ in the last bit between V8, JavaScriptCore and SpiderMonkey.\n *\n * So any value that is stored and later recomputed for an exact identity check must use\n * only the correctly rounded operations.\n * @see docs/NUMERICAL_CORRECTNESS.md §Cross-engine determinism\n */\n\nconst LARGE = 2 ** 500;\nconst SMALL = 2 ** -500;\nconst SCALE_DOWN = 2 ** -600;\nconst SCALE_UP = 2 ** 600;\n\n/**\n * Euclidean norm (vector length) of the components. Unlike `Math.hypot`, it uses only correctly\n * rounded IEEE operations, so the result is bit-identical in every JavaScript engine.\n *\n * Components are summed in argument order. Inputs far from 1 are first rescaled by an exact power\n * of two, so squaring cannot overflow or underflow. Non-finite input gives a non-finite result;\n * callers validate inputs first.\n */\nexport function portableHypot(...values: readonly number[]): number {\n let maximum = 0;\n for (const value of values) {\n const magnitude = Math.abs(value);\n if (!(magnitude <= maximum)) maximum = magnitude;\n }\n if (maximum === 0 || !Number.isFinite(maximum)) return maximum;\n const scale = maximum > LARGE ? SCALE_DOWN : maximum < SMALL ? SCALE_UP : 1;\n let sum = 0;\n for (const value of values) {\n const scaled = value * scale;\n sum += scaled * scaled;\n }\n return Math.sqrt(sum) / scale;\n}\n\n/**\n * V8's three-argument `Math.hypot` as a fixed sequence of correctly rounded operations, so the result has V8's bits in\n * every JavaScript engine. The sequence is V8's `MathHypot` (src/builtins/math.tq; also its three-argument\n * `FastMathHypot`): the largest magnitude, starting from 0, normalises the arguments; their squares are summed in\n * argument order with Kahan compensation; the result is the square root of the sum times the largest magnitude. An\n * infinite argument gives Infinity (even beside NaN), otherwise a NaN argument gives NaN, and all zeros give +0.\n *\n * It is not `portableHypot`: that function rescales by powers of two and sums without compensation, so it is portable\n * too but gives other bits than `Math.hypot`. This one replaces `Math.hypot` where today's V8 bits must be kept (the\n * capture's query arithmetic and the display view's copy of it), and makes the other engines compute them too.\n * @see docs/NUMERICAL_CORRECTNESS.md §Cross-engine determinism\n */\nexport function hypot3(a: number, b: number, c: number): number {\n a = Math.abs(a);\n b = Math.abs(b);\n c = Math.abs(c);\n let max = 0;\n if (a > max) max = a;\n if (b > max) max = b;\n if (c > max) max = c;\n if (max === Infinity) return Infinity;\n if (a !== a || b !== b || c !== c) return NaN;\n if (max === 0) return 0;\n let sum = 0, compensation = 0;\n let n = a / max, summand = n * n - compensation, preliminary = sum + summand;\n compensation = (preliminary - sum) - summand;\n sum = preliminary;\n n = b / max;\n summand = n * n - compensation;\n preliminary = sum + summand;\n compensation = (preliminary - sum) - summand;\n sum = preliminary;\n n = c / max;\n summand = n * n - compensation;\n sum = sum + summand;\n return Math.sqrt(sum) * max;\n}\n\n/**\n * True when two finite numbers differ by at most `maximumUlps` ULPs (units in the last place).\n * One ULP here is `Number.EPSILON` times the larger magnitude. Use it to accept an archived value\n * that another engine or an earlier release computed with an implementation-approximated function.\n */\nexport function equalWithinUlps(a: number, b: number, maximumUlps: number): boolean {\n if (!Number.isFinite(a) || !Number.isFinite(b)) return false;\n if (a === b) return true;\n return Math.abs(a - b) <= maximumUlps * Number.EPSILON * Math.max(Math.abs(a), Math.abs(b));\n}\n\n// ---------------------------------------------------------------------------------------------------------------\n// Portable logarithm, exponential, power, cube root and cosine/sine of 2πu.\n//\n// Each function below is a fixed sequence of correctly rounded binary64 operations (+, −, ×, ÷, exact\n// power-of-two scaling through the IEEE 754 bit pattern, Math.round/Math.floor and integer operations), with\n// every constant written as a decimal literal of at most 17 significant digits (ECMAScript converts these\n// exactly to the nearest double). The bits of every result are therefore the same in every conforming\n// JavaScript engine, unlike Math.pow, Math.exp, Math.log, Math.cbrt and Math.cos, which ECMA-262 leaves\n// \"implementation-approximated\" (docs/NUMERICAL_CORRECTNESS.md, \"Cross-engine determinism\").\n//\n// Methods (textbook; no code copied):\n// - Error-free transformations (double-double arithmetic): TwoSum (Knuth, The Art of Computer Programming\n// vol. 2, §4.2.2), FastTwoSum and TwoProduct with Veltkamp's splitting (Dekker, \"A floating-point technique\n// for extending the available precision\", Numerische Mathematik 18, 1971). Exact barring overflow and\n// underflow, which the arguments here cannot reach.\n// - log2(x): x = m·2^e with m in [√½, √2); ln m = 2·atanh(s) = 2(s + s³/3 + s⁵/5 + …), s = (m − 1)/(m + 1),\n// |s| ≤ 0.1716 (J.-M. Muller, Elementary Functions: Algorithms and Implementation, 3rd ed., 2016, ch. 11).\n// s carries a double-double correction; the series runs to s²³ (truncation below 2^-62 relative).\n// - 2^t: t = n + r with n = round(t), |r| ≤ ½; 2^r = e^(r·ln 2) by its Taylor series to degree 14 (truncation\n// below 2^-57 relative), then an exact scaling by 2^n (Muller, ch. 11, \"additive range reduction\").\n// - x^y = 2^(y·log2 x) with log2 x and y·log2 x carried as double-double; e^x = 2^(x·log2 e) and\n// ∛x = 2^(log2 x / 3) likewise; ln x = log2 x · ln 2; e^x − 1 by its Taylor series for |x| < 1.\n// - cos(2πu), sin(2πu): u = q/4 + r with q = round(4u) and |r| ≤ ⅛ (exact), then the Taylor series of cos and\n// sin of 2πr to degrees 18 and 19 (truncation below 2^-66).\n//\n// Error bounds (from the operation counts above): portableExp2, portableExp, portableLog, portableLog2 and\n// portableCbrt within 1 ulp; portableExpm1 within 2 ulps; portablePow within 1 ulp for |y| ≤ 4 (the double-double\n// logarithm has relative error below 2^-56, so the error of y·log2 x adds at most |y|·2^-57·ln 2 relative);\n// portableCosTwoPi and portableSinTwoPi within 2 ulps. Checked against 60-digit decimal references (Python decimal)\n// on 2·10⁵ pseudo-random arguments per function (6·10⁵ for portableLog; |y| ≤ 4 and y = 1/2.4, 1.4 for portablePow):\n// largest errors 0.53 ulp (log, log2), 0.86 (exp2), 0.94 (exp, cbrt, pow), 0.97 (pow with y = 1/2.4), 1.59 (cos,\n// sin of 2πu) and 1.66 (e^x − 1); spot values are in test/portable-math.test.ts. These are accuracy bounds;\n// determinism does not depend on them.\n\n/** Bit access to a double: the high 32-bit word is at index HIGH of the view (detected once, so either byte order works). */\n// The tables and constants below are built by expressions marked pure (/* @__PURE__ */), so a bundler drops them from a\n// bundle that uses none of the functions that read them (a capture-only bundle keeps only portableHypot and equalWithinUlps).\nconst BITS = /* @__PURE__ */ new Float64Array(1), WORDS = /* @__PURE__ */ ((): Uint32Array => new Uint32Array(BITS.buffer))();\nconst HIGH = /* @__PURE__ */ ((): number => (new Uint8Array(new Uint16Array([1]).buffer)[0] === 1 ? 1 : 0))(), LOW = 1 - HIGH;\n/** 2^k for every integer k in [−1074, 1023] at POW2[k + 1074], built by exact halving and doubling. */\nconst POW2 = /* @__PURE__ */ ((): Float64Array => {\n const table = new Float64Array(2098);\n table[1074] = 1;\n for (let k = 1; k <= 1023; k++) table[1074 + k] = table[1073 + k]! * 2;\n for (let k = 1; k <= 1074; k++) table[1074 - k] = table[1075 - k]! / 2;\n return table;\n})();\n/** v·2^k for an integer k in [−1100, 1100]: one exact multiplication (a single rounding only when the result is subnormal). */\nfunction scaleByPowerOfTwo(v: number, k: number): number {\n if (k > 1023) return v * POW2[2097]! * POW2[1074 + k - 1023]!;\n if (k < -1074) return v * POW2[1074 + k + 1074]! * POW2[0]!; // exact first factor (v·2^(k+1074) is normal), one rounding\n return v * POW2[1074 + k]!;\n}\n// Double-double arithmetic, written out inline below (local variables only, which keeps it fast):\n// - FastTwoSum (|a| ≥ |b| or a = 0): s = a + b, err = b − (s − a), so a + b = s + err exactly;\n// - TwoSum (any a, b): s = a + b, b' = s − a, err = (a − (s − b')) + (b − b');\n// - TwoProduct: p = a·b, err = ((ah·bh − p) + ah·bl + al·bh) + al·bl, with Veltkamp's split\n// ah = c − (c − a), al = a − ah, c = (2^27 + 1)·a (and likewise for b), so a·b = p + err exactly.\nconst SPLITTER = 134217729; // 2^27 + 1 (Veltkamp)\nconst LN2_HI = 0.6931471805599453, LN2_LO = 2.3190468138462996e-17;\nconst LOG2E_HI = 1.4426950408889634, LOG2E_LO = 2.0355273740931033e-17;\nconst SQRT2 = 1.4142135623730951, TWO_POW_54 = 18014398509481984, MIN_NORMAL = 2.2250738585072014e-308;\n/** Veltkamp halves of a constant (the same values the split gives at each use). */\nfunction splitHigh(a: number): number { const c = SPLITTER * a; return c - (c - a); }\nconst LN2_HI_H = /* @__PURE__ */ splitHigh(LN2_HI), LN2_HI_L = LN2_HI - LN2_HI_H, LOG2E_HI_H = /* @__PURE__ */ splitHigh(LOG2E_HI), LOG2E_HI_L = LOG2E_HI - LOG2E_HI_H;\n/** The low part of the last double-double result (its high part is the return value). */\nconst LOW_PART = /* @__PURE__ */ new Float64Array(1);\n\n/**\n * log2 m for m in [√½, √2] by the atanh series to s²³ (no table): builds LOG2_TABLE once. Returns the high part, the low\n * part in LOW_PART[0]; relative error below 2^-56.\n */\nfunction log2SeriesDoubleDouble(x: number): number {\n let e = 0;\n if (x < MIN_NORMAL) { x *= TWO_POW_54; e = -54; }\n BITS[0] = x;\n const high = WORDS[HIGH]!;\n e += (high >>> 20) - 1023;\n let m = x * POW2[1074 - ((high >>> 20) - 1023)]!; // exact: m in [1, 2)\n if (m > SQRT2) { m *= 0.5; e += 1; }\n // s = f/(2 + f) with f = m − 1 (exact), as sHi + sLo: 2 + f = dh + dl exactly (FastTwoSum), then the residual\n // f − sHi·(dh + dl) with sHi·dh = p + pe exactly (TwoProduct).\n const f = m - 1, dh = 2 + f, dl = f - (dh - 2), sHi = f / dh, p = sHi * dh;\n let c = SPLITTER * sHi;\n const ah = c - (c - sHi), al = sHi - ah;\n c = SPLITTER * dh;\n const bh = c - (c - dh), bl = dh - bh, pe = ((ah * bh - p) + ah * bl + al * bh) + al * bl;\n const sLo = (((f - p) - pe) - sHi * dl) / dh;\n const z = sHi * sHi;\n const tail = sHi * z * (0.6666666666666666 + z * (0.4 + z * (0.2857142857142857 + z * (0.2222222222222222 + z * (0.18181818181818182 + z * (0.15384615384615385 +\n z * (0.13333333333333333 + z * (0.11764705882352941 + z * (0.10526315789473684 + z * (0.09523809523809523 + z * 0.08695652173913043))))))))));\n // ln m = 2sHi + (2sLo + tail) = lh + ll (FastTwoSum); times log2 e = LOG2E_HI + LOG2E_LO (TwoProduct of the high parts); plus e (TwoSum).\n const a1 = 2 * sHi, b1 = 2 * sLo + tail, lh = a1 + b1, ll = b1 - (lh - a1), q = lh * LOG2E_HI;\n c = SPLITTER * lh;\n const ch = c - (c - lh), cl = lh - ch, qe = ((ch * LOG2E_HI_H - q) + ch * LOG2E_HI_L + cl * LOG2E_HI_H) + cl * LOG2E_HI_L;\n const pl = qe + (lh * LOG2E_LO + ll * LOG2E_HI);\n const t = e + q, tb = t - e, te = (e - (t - tb)) + (q - tb), b2 = te + pl, hi = t + b2;\n LOW_PART[0] = b2 - (hi - t);\n return hi;\n}\n/** log2(k/128) for k = 90 … 182 (the table's range of k = round(128·m), m in [√½, √2]) as double-doubles. */\nconst LOG2_TABLE_LO = /* @__PURE__ */ new Float64Array(183);\nconst LOG2_TABLE_HI = /* @__PURE__ */ ((): Float64Array => {\n const table = new Float64Array(183);\n for (let k = 90; k <= 182; k++) { table[k] = log2SeriesDoubleDouble(k / 128); LOG2_TABLE_LO[k] = LOW_PART[0]!; }\n return table;\n})();\n/**\n * log2 x as a double-double for finite x > 0: returns the high part, the low part in LOW_PART[0]. x = m·2^e with m in\n * [√½, √2]; m = F·(1 + f/F) with F = k/128, k = round(128·m), so log2 m = log2 F (table) + 2·atanh(s)·log2 e with\n * s = f/(m + F), |s| < 2^-8.4, by its series to s⁷ (truncation below 2^-70 relative). Relative error below 2^-56.\n */\nfunction log2DoubleDouble(x: number): number {\n let e = 0;\n if (x < MIN_NORMAL) { x *= TWO_POW_54; e = -54; }\n BITS[0] = x;\n const high = WORDS[HIGH]!;\n e += (high >>> 20) - 1023;\n let m = x * POW2[1074 - ((high >>> 20) - 1023)]!; // exact: m in [1, 2)\n if (m > SQRT2) { m *= 0.5; e += 1; }\n // F = k/128 (exact) and f = m − F (exact, F/2 ≤ m ≤ 2F); m + F = dh + dl exactly (TwoSum); s = f/(dh + dl) as sHi + sLo\n // from the residual f − sHi·(dh + dl), with sHi·dh = p + pe exactly (TwoProduct).\n const k = Math.round(m * 128), F = k / 128, f = m - F, dh = m + F, db = dh - m, dl = (m - (dh - db)) + (F - db);\n const sHi = f / dh, p = sHi * dh;\n let c = SPLITTER * sHi;\n const ah = c - (c - sHi), al = sHi - ah;\n c = SPLITTER * dh;\n const bh = c - (c - dh), bl = dh - bh, pe = ((ah * bh - p) + ah * bl + al * bh) + al * bl;\n const sLo = (((f - p) - pe) - sHi * dl) / dh, z = sHi * sHi;\n const tail = sHi * z * (0.6666666666666666 + z * (0.4 + z * 0.2857142857142857));\n // ln(m/F) = 2sHi + (2sLo + tail) = lh + ll (FastTwoSum); times log2 e = LOG2E_HI + LOG2E_LO (TwoProduct of the high\n // parts); plus log2 F (TwoSum with the table's high part), then plus e (TwoSum).\n const a1 = 2 * sHi, b1 = 2 * sLo + tail, lh = a1 + b1, ll = b1 - (lh - a1), q = lh * LOG2E_HI;\n c = SPLITTER * lh;\n const ch = c - (c - lh), cl = lh - ch, qe = ((ch * LOG2E_HI_H - q) + ch * LOG2E_HI_L + cl * LOG2E_HI_H) + cl * LOG2E_HI_L;\n const pl = qe + (lh * LOG2E_LO + ll * LOG2E_HI), th = LOG2_TABLE_HI[k]!;\n const t = th + q, tb = t - th, low = ((th - (t - tb)) + (q - tb)) + (pl + LOG2_TABLE_LO[k]!);\n const u = e + t, ub = u - e, b2 = ((e - (u - ub)) + (t - ub)) + low, hi = u + b2;\n LOW_PART[0] = b2 - (hi - u);\n return hi;\n}\n/** 2^(th + tl) for a double-double exponent; within 1 ulp (plus the error the exponent carries). */\nfunction exp2DoubleDouble(th: number, tl: number): number {\n if (th !== th) return NaN;\n if (th > 1024) return Infinity;\n if (th < -1080) return 0;\n // th = n + r exactly (|r| ≤ ½); w = r·ln 2 = wh + wl (TwoProduct with LN2_HI, plus r·LN2_LO).\n const n = Math.round(th), r = (th - n) + tl, wh = r * LN2_HI, c = SPLITTER * r, ah = c - (c - r), al = r - ah;\n const wl = (((ah * LN2_HI_H - wh) + ah * LN2_HI_L + al * LN2_HI_H) + al * LN2_HI_L) + r * LN2_LO;\n const q = 0.5 + wh * (0.16666666666666666 + wh * (0.041666666666666664 + wh * (0.008333333333333333 + wh * (0.001388888888888889 + wh * (0.0001984126984126984 +\n wh * (2.48015873015873e-05 + wh * (2.7557319223985893e-06 + wh * (2.755731922398589e-07 + wh * (2.505210838544172e-08 + wh * (2.08767569878681e-09 +\n wh * (1.6059043836821613e-10 + wh * 1.1470745597729725e-11)))))))))));\n return scaleByPowerOfTwo(1 + (wh + (wl + wh * wh * q)), n);\n}\n\n/** log2 x, bit-identical in every JavaScript engine (within 1 ulp). 0 → −∞; negative or NaN → NaN; +∞ → +∞. */\nexport function portableLog2(x: number): number {\n if (!(x > 0)) return x === 0 ? -Infinity : NaN;\n if (x === Infinity) return Infinity;\n const h = log2DoubleDouble(x);\n return h + LOW_PART[0]!;\n}\n/** ln(k/128) for k = 90 … 182 as double-doubles (log2(k/128)·ln 2, TwoProduct with LN2_HI plus the small products). */\nconst LN_TABLE_LO = /* @__PURE__ */ new Float64Array(183);\nconst LN_TABLE_HI = /* @__PURE__ */ ((): Float64Array => {\n const table = new Float64Array(183);\n for (let k = 90; k <= 182; k++) {\n const h = LOG2_TABLE_HI[k]!, l = LOG2_TABLE_LO[k]!, p = h * LN2_HI, c = SPLITTER * h, ah = c - (c - h), al = h - ah;\n const pe = ((ah * LN2_HI_H - p) + ah * LN2_HI_L + al * LN2_HI_H) + al * LN2_HI_L, lo = pe + (h * LN2_LO + l * LN2_HI), hi = p + lo;\n table[k] = hi; LN_TABLE_LO[k] = lo - (hi - p);\n }\n return table;\n})();\n/** ln 2 = LN2_E_HI + LN2_E_LO with the low 32 bits of LN2_E_HI zero, so e·LN2_E_HI is exact for every exponent e here. */\nconst LN2_E_HI = /* @__PURE__ */ ((): number => { BITS[0] = LN2_HI; WORDS[LOW] = 0; return BITS[0]!; })(), LN2_E_LO = (LN2_HI - LN2_E_HI) + LN2_LO;\n/**\n * Natural logarithm, bit-identical in every JavaScript engine (within 1 ulp). 0 → −∞; negative or NaN → NaN; +∞ → +∞.\n * x = m·2^e, m in [√½, √2]; ln x = e·ln 2 + ln F (table, F = k/128, k = round(128·m)) + 2·atanh(s), s = (m − F)/(m + F),\n * with s as a double-double and the three terms added with TwoSum.\n */\nexport function portableLog(x: number): number {\n if (!(x > 0)) return x === 0 ? -Infinity : NaN;\n if (x === Infinity) return Infinity;\n let e = 0;\n if (x < MIN_NORMAL) { x *= TWO_POW_54; e = -54; }\n BITS[0] = x;\n const high = WORDS[HIGH]!;\n e += (high >>> 20) - 1023;\n let m = x * POW2[1074 - ((high >>> 20) - 1023)]!; // exact: m in [1, 2)\n if (m > SQRT2) { m *= 0.5; e += 1; }\n const k = Math.round(m * 128), F = k / 128, f = m - F, dh = m + F, db = dh - m, dl = (m - (dh - db)) + (F - db);\n const sHi = f / dh, p = sHi * dh;\n let c = SPLITTER * sHi;\n const ah = c - (c - sHi), al = sHi - ah;\n c = SPLITTER * dh;\n const bh = c - (c - dh), bl = dh - bh, pe = ((ah * bh - p) + ah * bl + al * bh) + al * bl;\n const sLo = (((f - p) - pe) - sHi * dl) / dh, z = sHi * sHi;\n const tail = sHi * z * (0.6666666666666666 + z * (0.4 + z * 0.2857142857142857));\n // (e·LN2_E_HI + ln F) + 2sHi with TwoSum errors, then the low parts.\n const A = e * LN2_E_HI, B = LN_TABLE_HI[k]!, t = A + B, tb = t - A, te = (A - (t - tb)) + (B - tb);\n const a2 = 2 * sHi, u = t + a2, ub = u - t, ue = (t - (u - ub)) + (a2 - ub);\n return u + ((te + ue) + ((e * LN2_E_LO + LN_TABLE_LO[k]!) + (2 * sLo + tail)));\n}\n/** 2^x, bit-identical in every JavaScript engine (within 1 ulp). */\nexport function portableExp2(x: number): number { return exp2DoubleDouble(x, 0); }\n/** e^x, bit-identical in every JavaScript engine (within 1 ulp). */\nexport function portableExp(x: number): number {\n if (x !== x) return NaN;\n if (x > 710) return Infinity;\n if (x < -746) return 0;\n // x·log2 e = th + tl: x·LOG2E_HI = th + te exactly (TwoProduct), plus x·LOG2E_LO.\n const th = x * LOG2E_HI, c = SPLITTER * x, ah = c - (c - x), al = x - ah;\n const te = ((ah * LOG2E_HI_H - th) + ah * LOG2E_HI_L + al * LOG2E_HI_H) + al * LOG2E_HI_L;\n return exp2DoubleDouble(th, te + x * LOG2E_LO);\n}\n/**\n * e^x − 1, bit-identical in every JavaScript engine (within 2 ulps): the Taylor series to degree 20 for |x| < 1\n * (truncation below 2^-60 relative), else portableExp(x) − 1.\n */\nexport function portableExpm1(x: number): number {\n if (x !== x) return NaN;\n if (x === 0) return x;\n if (!(x > -1 && x < 1)) return portableExp(x) - 1;\n return x + x * x * (0.5 + x * (0.16666666666666666 + x * (0.041666666666666664 + x * (0.008333333333333333 + x * (0.001388888888888889 + x * (0.0001984126984126984 +\n x * (2.48015873015873e-05 + x * (2.7557319223985893e-06 + x * (2.755731922398589e-07 + x * (2.505210838544172e-08 + x * (2.08767569878681e-09 +\n x * (1.6059043836821613e-10 + x * (1.1470745597729725e-11 + x * (7.647163731819816e-13 + x * (4.779477332387385e-14 + x * (2.8114572543455206e-15 +\n x * (1.5619206968586225e-16 + x * (8.22063524662433e-18 + x * 4.110317623312165e-19))))))))))))))))));\n}\n/**\n * x^y for x ≥ 0 and finite y, bit-identical in every JavaScript engine (within 1 ulp for |y| ≤ 4). x = 0 gives 0 for\n * y > 0, 1 for y = 0 and +∞ for y < 0; negative x or a non-finite argument gives NaN (the callers never pass them).\n */\nexport function portablePow(x: number, y: number): number {\n if (!(x >= 0) || !Number.isFinite(x) || !Number.isFinite(y)) return NaN;\n if (y === 0 || x === 1) return 1;\n if (x === 0) return y > 0 ? 0 : Infinity;\n // y·(lh + ll): lh·y = p + pe exactly (TwoProduct), then FastTwoSum(p, pe + ll·y).\n const lh = log2DoubleDouble(x), ll = LOW_PART[0]!, p = lh * y;\n let c = SPLITTER * lh;\n const ah = c - (c - lh), al = lh - ah;\n c = SPLITTER * y;\n const bh = c - (c - y), bl = y - bh, pe = ((ah * bh - p) + ah * bl + al * bh) + al * bl;\n const b = pe + ll * y, th = p + b;\n return exp2DoubleDouble(th, b - (th - p));\n}\n/** ∛(2^r) for r = 0, 1, 2 (only scale the cube root's starting value, so their last bits do not matter). */\nconst CBRT_POWERS_OF_TWO = [1, 1.2599210498948732, 1.5874010519681994];\n/**\n * Cube root, bit-identical in every JavaScript engine (within 1 ulp; exact for ±0, ±∞ and cubes of powers of two).\n * |x| = m·2^(3q + r) with m in [1, 2) and r in {0, 1, 2}, w = m·2^r: a cubic fit to ∛m (within 1.7·10⁻⁴) times ∛(2^r),\n * one Halley step y ← y(y³ + 2w)/(2y³ + w) (cubic convergence: below 10⁻¹¹), then one Newton step y + (w − y³)/(3y²)\n * with w − y³ formed exactly (TwoProduct), which leaves only the final rounding and errors near 10⁻²².\n */\nexport function portableCbrt(x: number): number {\n if (x === 0 || x !== x || !Number.isFinite(x)) return x;\n let a = x < 0 ? -x : x, shift = 0;\n if (a < MIN_NORMAL) { a *= TWO_POW_54; shift = -18; }\n BITS[0] = a;\n const high = WORDS[HIGH]!, e = (high >>> 20) - 1023, q = Math.floor(e / 3), r = e - 3 * q;\n const m = a * POW2[1074 - e]!, w = m * CBRT_SCALE[r]!; // exact: m in [1, 2)\n let y = (0.5561432746078446 + m * (0.5806821751356804 + m * (-0.15894786280039686 + m * 0.022291567104952514))) * CBRT_POWERS_OF_TWO[r]!;\n const y3 = y * y * y;\n y = y * (y3 + 2 * w) / (2 * y3 + w);\n // y² = p + pe exactly; y³ = p·y + pe·y = t + te (TwoProduct of p and y, plus pe·y); w − y³ = (w − t) − te.\n const p = y * y;\n let c = SPLITTER * y;\n const yh = c - (c - y), yl = y - yh, pe = ((yh * yh - p) + yh * yl + yl * yh) + yl * yl, t = p * y;\n c = SPLITTER * p;\n const ph = c - (c - p), pll = p - ph, te = (((ph * yh - t) + ph * yl + pll * yh) + pll * yl) + pe * y;\n const root = scaleByPowerOfTwo(y + ((w - t) - te) / (3 * p), q + shift);\n return x < 0 ? -root : root;\n}\n/** 2^r for r = 0, 1, 2. */\nconst CBRT_SCALE = [1, 2, 4];\n/** cos(2πr) and sin(2πr) for |r| ≤ ⅛ (Taylor series in z = r²). */\nfunction cosTwoPiReduced(r: number): number {\n const z = r * r;\n return 1 + z * (-19.739208802178716 + z * (64.9393940226683 + z * (-85.45681720669373 + z * (60.24464137187666 + z * (-26.4262567833744 + z * (7.903536371318469 +\n z * (-1.714390711088672 + z * (0.28200596845579123 + z * -0.03638284114254567))))))));\n}\nfunction sinTwoPiReduced(r: number): number {\n const z = r * r;\n return r * (6.283185307179586 + z * (-41.34170224039976 + z * (81.60524927607506 + z * (-76.70585975306139 + z * (42.058693944897655 + z * (-15.09464257682299 +\n z * (3.819952584848282 + z * (-0.7181223017785006 + z * (0.10422916220813984 + z * -0.012031585942120627)))))))));\n}\n/** cos(2πu) for finite u (u in turns), bit-identical in every JavaScript engine (within 2 ulps). */\nexport function portableCosTwoPi(u: number): number {\n if (!Number.isFinite(u)) return NaN;\n const t = 4 * u, q = Math.round(t), r = (t - q) / 4, quadrant = ((q % 4) + 4) % 4;\n return quadrant === 0 ? cosTwoPiReduced(r) : quadrant === 1 ? -sinTwoPiReduced(r) : quadrant === 2 ? -cosTwoPiReduced(r) : sinTwoPiReduced(r);\n}\n/** sin(2πu) for finite u (u in turns), bit-identical in every JavaScript engine (within 2 ulps). */\nexport function portableSinTwoPi(u: number): number {\n if (!Number.isFinite(u)) return NaN;\n const t = 4 * u, q = Math.round(t), r = (t - q) / 4, quadrant = ((q % 4) + 4) % 4;\n return quadrant === 0 ? sinTwoPiReduced(r) : quadrant === 1 ? cosTwoPiReduced(r) : quadrant === 2 ? -sinTwoPiReduced(r) : -cosTwoPiReduced(r);\n}\n"]}
|
package/dist/core/version.d.ts
CHANGED
package/dist/core/version.js
CHANGED
package/dist/core/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/core/version.ts"],"names":[],"mappings":"AAAA,sCAAsC;AAEtC;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/core/version.ts"],"names":[],"mappings":"AAAA,sCAAsC;AAEtC;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,QAAiB,CAAC","sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\n/**\n * Version of the engine release. Since 1.0.1 it equals the npm package version.\n *\n * New captures and plans record this version as their creator. Archived records keep the\n * version they were made with. Proof-of-concept (POC), schema and model contracts have their\n * own versions. Release checks confirm it matches package.json and the packed package.\n * @see docs/RELEASE_1_0_1.md\n */\nexport const ENGINE_API_VERSION = \"2.10.0\" as const;\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { SceneRadianceEvaluationRequest, SceneRadianceEvaluationResult } from "../schema/scene-radiance.js";
|
|
2
|
+
/**
|
|
3
|
+
* Electrons per unit spectral radiance at each node, sorted by wavelength, for an environment record with one temporal
|
|
4
|
+
* sample. The chain runs once with radiance 1 at every node; each node's value is its own rate term times the time step.
|
|
5
|
+
*
|
|
6
|
+
* Exact: the spatial reduction and the per-node rate are per spectral node, the spectral sum is a compensated sum of
|
|
7
|
+
* per-node terms and the temporal sum is rate × time step. An execution with radiance 1 at one node and 0 elsewhere (the
|
|
8
|
+
* earlier method, one execution per node) therefore adds +0 terms that leave the compensated sum unchanged and returns
|
|
9
|
+
* exactly `rate_n × integrationMeasureSeconds` (test/channel-response.test.ts compares both with Object.is).
|
|
10
|
+
*
|
|
11
|
+
* The environment record must be the engine's own (built by the caller, never shown to supplied code or changed after):
|
|
12
|
+
* it is planned as engine-owned data without a copy. Retention is photo-only, as on the capture path; photo values are
|
|
13
|
+
* identical for either retention.
|
|
14
|
+
*/
|
|
15
|
+
export declare function calculateChannelElectronsPerRadiance(environment: Record<string, unknown>, evaluateRadiance: (request: Readonly<SceneRadianceEvaluationRequest>) => SceneRadianceEvaluationResult, caller: string): Map<number, number>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
/**
|
|
3
|
+
* Internal (#443): one channel's expected photo electrons per unit spectral radiance at each spectral node, from one
|
|
4
|
+
* execution of the environment photo-signal chain. Used by the facade's `axisChannelResponse` (display view, ideal
|
|
5
|
+
* reference and the capture's tabulated RAW path).
|
|
6
|
+
*/
|
|
7
|
+
import { InvalidConfigurationError } from "../core/configuration-error.js";
|
|
8
|
+
import { executeEnvironmentSensorPhotoSignal, planEnvironmentSensorPhotoSignal } from "../sensor/environment-photo-signal.js";
|
|
9
|
+
/**
|
|
10
|
+
* Electrons per unit spectral radiance at each node, sorted by wavelength, for an environment record with one temporal
|
|
11
|
+
* sample. The chain runs once with radiance 1 at every node; each node's value is its own rate term times the time step.
|
|
12
|
+
*
|
|
13
|
+
* Exact: the spatial reduction and the per-node rate are per spectral node, the spectral sum is a compensated sum of
|
|
14
|
+
* per-node terms and the temporal sum is rate × time step. An execution with radiance 1 at one node and 0 elsewhere (the
|
|
15
|
+
* earlier method, one execution per node) therefore adds +0 terms that leave the compensated sum unchanged and returns
|
|
16
|
+
* exactly `rate_n × integrationMeasureSeconds` (test/channel-response.test.ts compares both with Object.is).
|
|
17
|
+
*
|
|
18
|
+
* The environment record must be the engine's own (built by the caller, never shown to supplied code or changed after):
|
|
19
|
+
* it is planned as engine-owned data without a copy. Retention is photo-only, as on the capture path; photo values are
|
|
20
|
+
* identical for either retention.
|
|
21
|
+
*/
|
|
22
|
+
export function calculateChannelElectronsPerRadiance(environment, evaluateRadiance, caller) {
|
|
23
|
+
const plan = planEnvironmentSensorPhotoSignal(environment, "engine-owned", "photo-only");
|
|
24
|
+
const result = executeEnvironmentSensorPhotoSignal(plan, (request) => ({ ...evaluateRadiance(request), spectralRadianceWattsPerSquareMeterSteradianNanometer: 1 }), undefined, "photo-only");
|
|
25
|
+
const samples = result.value.photo.value.exposure.value.samples;
|
|
26
|
+
if (samples.length !== 1)
|
|
27
|
+
throw new InvalidConfigurationError(caller + ": the channel response expects one temporal sample.");
|
|
28
|
+
const sample = samples[0];
|
|
29
|
+
return new Map(sample.stages.electronRate.value.perWavelength
|
|
30
|
+
.map((node) => [node.wavelengthNanometers, node.expectedGeneratedElectronRatePerSecond * sample.integrationMeasureSeconds])
|
|
31
|
+
.sort((a, b) => a[0] - b[0]));
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=channel-response.js.map
|