@pmndrs/vdb 0.1.0 → 0.2.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 +592 -2
- package/README.md +85 -37
- package/THIRD_PARTY_NOTICES.md +197 -29
- package/dist/core/compute/atlas.d.ts +10 -2
- package/dist/core/compute/atlas.js +6 -1
- package/dist/core/compute/atlas.js.map +1 -1
- package/dist/core/compute/index.d.ts +3 -3
- package/dist/core/compute/index.js +2 -2
- package/dist/core/compute/index.js.map +1 -1
- package/dist/core/compute/majorant-build.d.ts +45 -0
- package/dist/core/compute/majorant-build.js +193 -0
- package/dist/core/compute/majorant-build.js.map +1 -0
- package/dist/core/compute/multi-scale.d.ts +155 -0
- package/dist/core/compute/multi-scale.js +684 -0
- package/dist/core/compute/multi-scale.js.map +1 -0
- package/dist/core/compute/pyramid.d.ts +22 -7
- package/dist/core/compute/pyramid.js +22 -9
- package/dist/core/compute/pyramid.js.map +1 -1
- package/dist/core/compute/shared.d.ts +1 -0
- package/dist/core/compute/shared.js.map +1 -1
- package/dist/core/compute/stats.d.ts +10 -3
- package/dist/core/compute/stats.js +6 -1
- package/dist/core/compute/stats.js.map +1 -1
- package/dist/core/compute/value-transform.d.ts +8 -1
- package/dist/core/compute/value-transform.js +9 -3
- package/dist/core/compute/value-transform.js.map +1 -1
- package/dist/core/errors.d.ts +10 -0
- package/dist/core/errors.js +8 -0
- package/dist/core/errors.js.map +1 -1
- package/dist/core/frame/emission.d.ts +85 -0
- package/dist/core/frame/emission.js +422 -0
- package/dist/core/frame/emission.js.map +1 -0
- package/dist/core/frame/environment.d.ts +47 -0
- package/dist/core/frame/environment.js +178 -0
- package/dist/core/frame/environment.js.map +1 -0
- package/dist/core/frame/index.d.ts +39 -0
- package/dist/core/frame/index.js +27 -0
- package/dist/core/frame/index.js.map +1 -0
- package/dist/core/frame/kernels.d.ts +115 -0
- package/dist/core/frame/kernels.js +496 -0
- package/dist/core/frame/kernels.js.map +1 -0
- package/dist/core/frame/limits.d.ts +67 -0
- package/dist/core/frame/limits.js +109 -0
- package/dist/core/frame/limits.js.map +1 -0
- package/dist/core/frame/phase.d.ts +17 -0
- package/dist/core/frame/phase.js +53 -0
- package/dist/core/frame/phase.js.map +1 -0
- package/dist/core/frame/pipelines.d.ts +49 -0
- package/dist/core/frame/pipelines.js +147 -0
- package/dist/core/frame/pipelines.js.map +1 -0
- package/dist/core/frame/renderer.d.ts +122 -0
- package/dist/core/frame/renderer.js +1712 -0
- package/dist/core/frame/renderer.js.map +1 -0
- package/dist/core/frame/resources.d.ts +71 -0
- package/dist/core/frame/resources.js +100 -0
- package/dist/core/frame/resources.js.map +1 -0
- package/dist/core/frame/scattering.d.ts +97 -0
- package/dist/core/frame/scattering.js +332 -0
- package/dist/core/frame/scattering.js.map +1 -0
- package/dist/core/frame/settings.d.ts +243 -0
- package/dist/core/frame/settings.js +67 -0
- package/dist/core/frame/settings.js.map +1 -0
- package/dist/core/frame/shadows.d.ts +55 -0
- package/dist/core/frame/shadows.js +460 -0
- package/dist/core/frame/shadows.js.map +1 -0
- package/dist/core/frame/types.d.ts +415 -0
- package/dist/core/frame/types.js +49 -0
- package/dist/core/frame/types.js.map +1 -0
- package/dist/core/frame/uniforms.d.ts +105 -0
- package/dist/core/frame/uniforms.js +276 -0
- package/dist/core/frame/uniforms.js.map +1 -0
- package/dist/core/frame/wgsl/chunks.d.ts +4 -0
- package/dist/core/frame/wgsl/chunks.js +728 -0
- package/dist/core/frame/wgsl/chunks.js.map +1 -0
- package/dist/core/frame/wgsl/emission.d.ts +82 -0
- package/dist/core/frame/wgsl/emission.js +353 -0
- package/dist/core/frame/wgsl/emission.js.map +1 -0
- package/dist/core/frame/wgsl/environment.d.ts +42 -0
- package/dist/core/frame/wgsl/environment.js +711 -0
- package/dist/core/frame/wgsl/environment.js.map +1 -0
- package/dist/core/frame/wgsl/gather.d.ts +55 -0
- package/dist/core/frame/wgsl/gather.js +850 -0
- package/dist/core/frame/wgsl/gather.js.map +1 -0
- package/dist/core/frame/wgsl/integrate.d.ts +78 -0
- package/dist/core/frame/wgsl/integrate.js +213 -0
- package/dist/core/frame/wgsl/integrate.js.map +1 -0
- package/dist/core/frame/wgsl/lighting.d.ts +103 -0
- package/dist/core/frame/wgsl/lighting.js +1636 -0
- package/dist/core/frame/wgsl/lighting.js.map +1 -0
- package/dist/core/frame/wgsl/occluders.d.ts +20 -0
- package/dist/core/frame/wgsl/occluders.js +95 -0
- package/dist/core/frame/wgsl/occluders.js.map +1 -0
- package/dist/core/frame/wgsl/resolve.d.ts +19 -0
- package/dist/core/frame/wgsl/resolve.js +205 -0
- package/dist/core/frame/wgsl/resolve.js.map +1 -0
- package/dist/core/frame/wgsl/shadows.d.ts +35 -0
- package/dist/core/frame/wgsl/shadows.js +328 -0
- package/dist/core/frame/wgsl/shadows.js.map +1 -0
- package/dist/core/half.d.ts +11 -0
- package/dist/core/half.js +22 -0
- package/dist/core/half.js.map +1 -0
- package/dist/core/index.d.ts +25 -3
- package/dist/core/index.js +23 -4
- package/dist/core/index.js.map +1 -1
- package/dist/core/internal.d.ts +17 -1
- package/dist/core/internal.js +18 -1
- package/dist/core/internal.js.map +1 -1
- package/dist/core/pool/image-header.d.ts +13 -2
- package/dist/core/pool/image-header.js +24 -5
- package/dist/core/pool/image-header.js.map +1 -1
- package/dist/core/pool/layout.d.ts +35 -1
- package/dist/core/pool/layout.js +51 -2
- package/dist/core/pool/layout.js.map +1 -1
- package/dist/core/pool/limits.d.ts +1 -0
- package/dist/core/pool/limits.js +1 -0
- package/dist/core/pool/limits.js.map +1 -1
- package/dist/core/pool/pool.d.ts +120 -15
- package/dist/core/pool/pool.js +255 -24
- package/dist/core/pool/pool.js.map +1 -1
- package/dist/core/reference/index.d.ts +6 -0
- package/dist/core/reference/index.js +7 -0
- package/dist/core/reference/index.js.map +1 -0
- package/dist/core/reference/renderer.d.ts +105 -0
- package/dist/core/reference/renderer.js +474 -0
- package/dist/core/reference/renderer.js.map +1 -0
- package/dist/core/reference/wgsl.d.ts +65 -0
- package/dist/core/reference/wgsl.js +803 -0
- package/dist/core/reference/wgsl.js.map +1 -0
- package/dist/{three → core}/sequence.d.ts +32 -2
- package/dist/{three → core}/sequence.js +24 -2
- package/dist/core/sequence.js.map +1 -0
- package/dist/core/source/brick-cache.d.ts +165 -0
- package/dist/core/source/brick-cache.js +627 -0
- package/dist/core/source/brick-cache.js.map +1 -0
- package/dist/core/source/dense-fill.d.ts +53 -0
- package/dist/core/source/dense-fill.js +377 -0
- package/dist/core/source/dense-fill.js.map +1 -0
- package/dist/core/source/dense.d.ts +33 -2
- package/dist/core/source/dense.js +121 -24
- package/dist/core/source/dense.js.map +1 -1
- package/dist/core/source/sparse-wgsl.d.ts +92 -0
- package/dist/core/source/sparse-wgsl.js +481 -0
- package/dist/core/source/sparse-wgsl.js.map +1 -0
- package/dist/core/source/sparse.d.ts +192 -0
- package/dist/core/source/sparse.js +762 -0
- package/dist/core/source/sparse.js.map +1 -0
- package/dist/core/source/types.d.ts +59 -2
- package/dist/core/source/types.js.map +1 -1
- package/dist/core/surface/index.d.ts +10 -0
- package/dist/core/surface/index.js +9 -0
- package/dist/core/surface/index.js.map +1 -0
- package/dist/core/surface/level-set-pass.d.ts +140 -0
- package/dist/core/surface/level-set-pass.js +291 -0
- package/dist/core/surface/level-set-pass.js.map +1 -0
- package/dist/core/surface/level-set-wgsl.d.ts +46 -0
- package/dist/core/surface/level-set-wgsl.js +99 -0
- package/dist/core/surface/level-set-wgsl.js.map +1 -0
- package/dist/core/surface/points.d.ts +109 -0
- package/dist/core/surface/points.js +226 -0
- package/dist/core/surface/points.js.map +1 -0
- package/dist/core/types.d.ts +12 -3
- package/dist/core/types.js +6 -2
- package/dist/core/types.js.map +1 -1
- package/dist/core/wgsl/api.d.ts +29 -5
- package/dist/core/wgsl/api.js +110 -27
- package/dist/core/wgsl/api.js.map +1 -1
- package/dist/core/wgsl/generate.d.ts +8 -0
- package/dist/core/wgsl/generate.js +195 -22
- package/dist/core/wgsl/generate.js.map +1 -1
- package/dist/core/wgsl/lean.d.ts +50 -0
- package/dist/core/wgsl/lean.js +327 -0
- package/dist/core/wgsl/lean.js.map +1 -0
- package/dist/core/wgsl/level-set.d.ts +5 -1
- package/dist/core/wgsl/level-set.js +11 -5
- package/dist/core/wgsl/level-set.js.map +1 -1
- package/dist/core/wgsl/majorant.d.ts +62 -0
- package/dist/core/wgsl/majorant.js +381 -0
- package/dist/core/wgsl/majorant.js.map +1 -0
- package/dist/core/wgsl/pnanovdb.chunks.generated.d.ts +2 -2
- package/dist/core/wgsl/pnanovdb.chunks.generated.js +15 -12
- package/dist/core/wgsl/pnanovdb.chunks.generated.js.map +1 -1
- package/dist/core/wgsl/types.d.ts +97 -3
- package/dist/core/wgsl/types.js.map +1 -1
- package/dist/three/coarse-first.d.ts +53 -8
- package/dist/three/coarse-first.js +24 -6
- package/dist/three/coarse-first.js.map +1 -1
- package/dist/three/compute.d.ts +12 -2
- package/dist/three/compute.js +16 -6
- package/dist/three/compute.js.map +1 -1
- package/dist/three/device.d.ts +7 -0
- package/dist/three/device.js +3 -0
- package/dist/three/device.js.map +1 -1
- package/dist/three/frame/core-environment.d.ts +38 -0
- package/dist/three/frame/core-environment.js +154 -0
- package/dist/three/frame/core-environment.js.map +1 -0
- package/dist/three/frame/core-integrate-material.d.ts +34 -0
- package/dist/three/frame/core-integrate-material.js +162 -0
- package/dist/three/frame/core-integrate-material.js.map +1 -0
- package/dist/three/frame/core-occluders.d.ts +53 -0
- package/dist/three/frame/core-occluders.js +193 -0
- package/dist/three/frame/core-occluders.js.map +1 -0
- package/dist/three/frame/core-structs.d.ts +34 -0
- package/dist/three/frame/core-structs.js +61 -0
- package/dist/three/frame/core-structs.js.map +1 -0
- package/dist/three/frame/core-textures.d.ts +41 -0
- package/dist/three/frame/core-textures.js +114 -0
- package/dist/three/frame/core-textures.js.map +1 -0
- package/dist/three/frame/emission-light.d.ts +64 -114
- package/dist/three/frame/emission-light.js +188 -567
- package/dist/three/frame/emission-light.js.map +1 -1
- package/dist/three/frame/index.d.ts +11 -31
- package/dist/three/frame/index.js +9 -29
- package/dist/three/frame/index.js.map +1 -1
- package/dist/three/frame/medium.d.ts +12 -0
- package/dist/three/frame/medium.js.map +1 -1
- package/dist/three/frame/renderer.d.ts +58 -454
- package/dist/three/frame/renderer.js +409 -1427
- package/dist/three/frame/renderer.js.map +1 -1
- package/dist/three/frame/spectrum.d.ts +0 -14
- package/dist/three/frame/spectrum.js +2 -23
- package/dist/three/frame/spectrum.js.map +1 -1
- package/dist/three/frame/three-internals.d.ts +3 -8
- package/dist/three/frame/three-internals.js +13 -11
- package/dist/three/frame/three-internals.js.map +1 -1
- package/dist/three/frame/volume-shadows.d.ts +93 -107
- package/dist/three/frame/volume-shadows.js +278 -631
- package/dist/three/frame/volume-shadows.js.map +1 -1
- package/dist/three/frame/volume.d.ts +91 -33
- package/dist/three/frame/volume.js +63 -51
- package/dist/three/frame/volume.js.map +1 -1
- package/dist/three/grid-node.d.ts +34 -1
- package/dist/three/grid-node.js +36 -1
- package/dist/three/grid-node.js.map +1 -1
- package/dist/three/index.d.ts +20 -11
- package/dist/three/index.js +21 -12
- package/dist/three/index.js.map +1 -1
- package/dist/three/internal.d.ts +14 -8
- package/dist/three/internal.js +11 -7
- package/dist/three/internal.js.map +1 -1
- package/dist/three/level-set-material.d.ts +81 -8
- package/dist/three/level-set-material.js +162 -125
- package/dist/three/level-set-material.js.map +1 -1
- package/dist/three/level-set-physical-material.d.ts +154 -0
- package/dist/three/level-set-physical-material.js +253 -0
- package/dist/three/level-set-physical-material.js.map +1 -0
- package/dist/three/level-set-velocity.d.ts +94 -0
- package/dist/three/level-set-velocity.js +208 -0
- package/dist/three/level-set-velocity.js.map +1 -0
- package/dist/three/material.d.ts +141 -11
- package/dist/three/material.js +161 -18
- package/dist/three/material.js.map +1 -1
- package/dist/three/points.d.ts +60 -4
- package/dist/three/points.js +140 -9
- package/dist/three/points.js.map +1 -1
- package/dist/three/sparse-source.d.ts +49 -117
- package/dist/three/sparse-source.js +109 -580
- package/dist/three/sparse-source.js.map +1 -1
- package/dist/three/volume-source.d.ts +11 -156
- package/dist/three/volume-source.js +29 -272
- package/dist/three/volume-source.js.map +1 -1
- package/dist/tools/cpu/brick-atlas.d.ts +36 -0
- package/dist/tools/cpu/brick-atlas.js +129 -0
- package/dist/tools/cpu/brick-atlas.js.map +1 -0
- package/dist/tools/cpu/compute.d.ts +23 -4
- package/dist/tools/cpu/compute.js +35 -14
- package/dist/tools/cpu/compute.js.map +1 -1
- package/dist/tools/cpu/lean-reads.d.ts +81 -0
- package/dist/tools/cpu/lean-reads.js +262 -0
- package/dist/tools/cpu/lean-reads.js.map +1 -0
- package/dist/tools/cpu/level-set.d.ts +42 -3
- package/dist/tools/cpu/level-set.js +59 -7
- package/dist/tools/cpu/level-set.js.map +1 -1
- package/dist/tools/cpu/majorant.d.ts +265 -0
- package/dist/tools/cpu/majorant.js +541 -0
- package/dist/tools/cpu/majorant.js.map +1 -0
- package/dist/tools/cpu/march.d.ts +93 -2
- package/dist/tools/cpu/march.js +165 -14
- package/dist/tools/cpu/march.js.map +1 -1
- package/dist/tools/cpu/mesh-decimate.d.ts +124 -0
- package/dist/tools/cpu/mesh-decimate.js +1225 -0
- package/dist/tools/cpu/mesh-decimate.js.map +1 -0
- package/dist/tools/cpu/points.d.ts +29 -0
- package/dist/tools/cpu/points.js +38 -0
- package/dist/tools/cpu/points.js.map +1 -0
- package/dist/tools/cpu/read-value.d.ts +19 -6
- package/dist/tools/cpu/read-value.js +32 -17
- package/dist/tools/cpu/read-value.js.map +1 -1
- package/dist/tools/cpu/sample-trilinear.d.ts +17 -4
- package/dist/tools/cpu/sample-trilinear.js +19 -7
- package/dist/tools/cpu/sample-trilinear.js.map +1 -1
- package/dist/tools/cpu/stride-tables.d.ts +2 -2
- package/dist/tools/cpu/stride-tables.generated.d.ts +6 -5
- package/dist/tools/cpu/stride-tables.generated.js +7 -6
- package/dist/tools/cpu/stride-tables.generated.js.map +1 -1
- package/dist/tools/cpu/stride-tables.js +1 -1
- package/dist/tools/cpu/stride-tables.js.map +1 -1
- package/dist/tools/cpu/surface-nets.d.ts +90 -0
- package/dist/tools/cpu/surface-nets.js +597 -0
- package/dist/tools/cpu/surface-nets.js.map +1 -0
- package/dist/tools/errors.d.ts +9 -0
- package/dist/tools/errors.js +9 -0
- package/dist/tools/errors.js.map +1 -1
- package/dist/tools/frame/ambient.d.ts +98 -0
- package/dist/tools/frame/ambient.js +274 -0
- package/dist/tools/frame/ambient.js.map +1 -0
- package/dist/tools/frame/blackbody.d.ts +15 -0
- package/dist/tools/frame/blackbody.js +35 -0
- package/dist/tools/frame/blackbody.js.map +1 -1
- package/dist/tools/frame/brick-cache.d.ts +165 -0
- package/dist/tools/frame/brick-cache.js +326 -0
- package/dist/tools/frame/brick-cache.js.map +1 -0
- package/dist/tools/frame/emission.d.ts +9 -0
- package/dist/tools/frame/emission.js +9 -1
- package/dist/tools/frame/emission.js.map +1 -1
- package/dist/tools/frame/environment-gpu.d.ts +111 -0
- package/dist/tools/frame/environment-gpu.js +280 -0
- package/dist/tools/frame/environment-gpu.js.map +1 -0
- package/dist/tools/frame/environment.d.ts +3 -2
- package/dist/tools/frame/environment.js +8 -4
- package/dist/tools/frame/environment.js.map +1 -1
- package/dist/tools/frame/froxel.d.ts +58 -0
- package/dist/tools/frame/froxel.js +115 -0
- package/dist/tools/frame/froxel.js.map +1 -0
- package/dist/tools/frame/grid.d.ts +90 -0
- package/dist/tools/frame/grid.js +112 -13
- package/dist/tools/frame/grid.js.map +1 -1
- package/dist/tools/frame/index.d.ts +14 -0
- package/dist/tools/frame/index.js +45 -4
- package/dist/tools/frame/index.js.map +1 -1
- package/dist/tools/frame/medium.d.ts +16 -0
- package/dist/tools/frame/medium.js +3 -1
- package/dist/tools/frame/medium.js.map +1 -1
- package/dist/tools/frame/mie.d.ts +9 -0
- package/dist/tools/frame/mie.js +18 -0
- package/dist/tools/frame/mie.js.map +1 -1
- package/dist/tools/frame/mlp-nn.d.ts +36 -0
- package/dist/tools/frame/mlp-nn.js +159 -0
- package/dist/tools/frame/mlp-nn.js.map +1 -0
- package/dist/tools/frame/mlp-tza.d.ts +29 -0
- package/dist/tools/frame/mlp-tza.js +186 -0
- package/dist/tools/frame/mlp-tza.js.map +1 -0
- package/dist/tools/frame/mlp.d.ts +183 -0
- package/dist/tools/frame/mlp.js +434 -0
- package/dist/tools/frame/mlp.js.map +1 -0
- package/dist/tools/frame/ms-exit.d.ts +42 -0
- package/dist/tools/frame/ms-exit.js +90 -0
- package/dist/tools/frame/ms-exit.js.map +1 -0
- package/dist/tools/frame/multi-scale.d.ts +152 -0
- package/dist/tools/frame/multi-scale.js +302 -0
- package/dist/tools/frame/multi-scale.js.map +1 -0
- package/dist/tools/frame/neural-weights.d.ts +6 -5
- package/dist/tools/frame/neural-weights.js +234 -235
- package/dist/tools/frame/neural-weights.js.map +1 -1
- package/dist/tools/frame/neural.js +1 -1
- package/dist/tools/frame/neural.js.map +1 -1
- package/dist/tools/frame/occluders.d.ts +51 -0
- package/dist/tools/frame/occluders.js +72 -0
- package/dist/tools/frame/occluders.js.map +1 -0
- package/dist/tools/frame/pyramid-layout.d.ts +17 -0
- package/dist/tools/frame/pyramid-layout.js +47 -0
- package/dist/tools/frame/pyramid-layout.js.map +1 -1
- package/dist/tools/frame/shadows.d.ts +110 -0
- package/dist/tools/frame/shadows.js +286 -0
- package/dist/tools/frame/shadows.js.map +1 -1
- package/dist/tools/frame/sparse.d.ts +82 -0
- package/dist/tools/frame/sparse.js +242 -1
- package/dist/tools/frame/sparse.js.map +1 -1
- package/dist/tools/frame/spectral-stack.d.ts +159 -0
- package/dist/tools/frame/spectral-stack.js +391 -0
- package/dist/tools/frame/spectral-stack.js.map +1 -0
- package/dist/tools/frame/spectral.d.ts +21 -2
- package/dist/tools/frame/spectral.js +30 -8
- package/dist/tools/frame/spectral.js.map +1 -1
- package/dist/tools/frame/stack.d.ts +115 -0
- package/dist/tools/frame/stack.js +290 -0
- package/dist/tools/frame/stack.js.map +1 -0
- package/dist/tools/frame/view.d.ts +131 -0
- package/dist/tools/frame/view.js +337 -0
- package/dist/tools/frame/view.js.map +1 -0
- package/dist/tools/index.d.ts +66 -15
- package/dist/tools/index.js +55 -11
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/internal.d.ts +58 -17
- package/dist/tools/internal.js +65 -11
- package/dist/tools/internal.js.map +1 -1
- package/dist/tools/nanovdb/build-from-vdb.d.ts +11 -2
- package/dist/tools/nanovdb/build-from-vdb.js +10 -2
- package/dist/tools/nanovdb/build-from-vdb.js.map +1 -1
- package/dist/tools/nanovdb/bytes.d.ts +17 -4
- package/dist/tools/nanovdb/bytes.js +46 -3
- package/dist/tools/nanovdb/bytes.js.map +1 -1
- package/dist/tools/nanovdb/coarse-first.d.ts +19 -3
- package/dist/tools/nanovdb/coarse-first.js +7 -1
- package/dist/tools/nanovdb/coarse-first.js.map +1 -1
- package/dist/tools/nanovdb/half.d.ts +22 -0
- package/dist/tools/nanovdb/half.js +73 -0
- package/dist/tools/nanovdb/half.js.map +1 -0
- package/dist/tools/nanovdb/index.d.ts +3 -1
- package/dist/tools/nanovdb/index.js +2 -1
- package/dist/tools/nanovdb/index.js.map +1 -1
- package/dist/tools/nanovdb/inspect.d.ts +10 -1
- package/dist/tools/nanovdb/inspect.js +8 -1
- package/dist/tools/nanovdb/inspect.js.map +1 -1
- package/dist/tools/nanovdb/leaf-codec.d.ts +35 -1
- package/dist/tools/nanovdb/leaf-codec.js +40 -4
- package/dist/tools/nanovdb/leaf-codec.js.map +1 -1
- package/dist/tools/nanovdb/quantize.d.ts +39 -10
- package/dist/tools/nanovdb/quantize.js +96 -44
- package/dist/tools/nanovdb/quantize.js.map +1 -1
- package/dist/tools/nanovdb/resample.d.ts +20 -3
- package/dist/tools/nanovdb/resample.js +20 -7
- package/dist/tools/nanovdb/resample.js.map +1 -1
- package/dist/tools/nanovdb/serialize.d.ts +34 -3
- package/dist/tools/nanovdb/serialize.js +51 -7
- package/dist/tools/nanovdb/serialize.js.map +1 -1
- package/dist/tools/nanovdb/stats.d.ts +34 -5
- package/dist/tools/nanovdb/stats.js +87 -11
- package/dist/tools/nanovdb/stats.js.map +1 -1
- package/dist/tools/nanovdb/transform.d.ts +4 -0
- package/dist/tools/nanovdb/transform.js +3 -0
- package/dist/tools/nanovdb/transform.js.map +1 -1
- package/dist/tools/nanovdb/tree.d.ts +14 -3
- package/dist/tools/nanovdb/tree.js +25 -13
- package/dist/tools/nanovdb/tree.js.map +1 -1
- package/dist/tools/nanovdb/write-nvdb.d.ts +47 -12
- package/dist/tools/nanovdb/write-nvdb.js +108 -28
- package/dist/tools/nanovdb/write-nvdb.js.map +1 -1
- package/dist/tools/nvdb-file.d.ts +77 -7
- package/dist/tools/nvdb-file.js +177 -20
- package/dist/tools/nvdb-file.js.map +1 -1
- package/dist/tools/nvdb-stream.d.ts +23 -7
- package/dist/tools/nvdb-stream.js +78 -34
- package/dist/tools/nvdb-stream.js.map +1 -1
- package/dist/tools/reference/analytic.d.ts +41 -0
- package/dist/tools/reference/analytic.js +95 -0
- package/dist/tools/reference/analytic.js.map +1 -0
- package/dist/tools/reference/environment.d.ts +62 -0
- package/dist/tools/reference/environment.js +154 -0
- package/dist/tools/reference/environment.js.map +1 -0
- package/dist/tools/reference/index.d.ts +12 -0
- package/dist/tools/reference/index.js +13 -0
- package/dist/tools/reference/index.js.map +1 -0
- package/dist/tools/reference/media.d.ts +14 -0
- package/dist/tools/reference/media.js +30 -0
- package/dist/tools/reference/media.js.map +1 -0
- package/dist/tools/reference/rng.d.ts +20 -0
- package/dist/tools/reference/rng.js +30 -0
- package/dist/tools/reference/rng.js.map +1 -0
- package/dist/tools/reference/scene.d.ts +312 -0
- package/dist/tools/reference/scene.js +169 -0
- package/dist/tools/reference/scene.js.map +1 -0
- package/dist/tools/reference/tables.d.ts +98 -0
- package/dist/tools/reference/tables.js +264 -0
- package/dist/tools/reference/tables.js.map +1 -0
- package/dist/tools/reference/trace.d.ts +160 -0
- package/dist/tools/reference/trace.js +497 -0
- package/dist/tools/reference/trace.js.map +1 -0
- package/dist/tools/vdb/blosc-write.d.ts +43 -0
- package/dist/tools/vdb/blosc-write.js +197 -0
- package/dist/tools/vdb/blosc-write.js.map +1 -0
- package/dist/tools/vdb/blosc.d.ts +35 -5
- package/dist/tools/vdb/blosc.js +82 -26
- package/dist/tools/vdb/blosc.js.map +1 -1
- package/dist/tools/vdb/blosclz.d.ts +33 -0
- package/dist/tools/vdb/blosclz.js +112 -0
- package/dist/tools/vdb/blosclz.js.map +1 -0
- package/dist/tools/vdb/byte-reader.d.ts +13 -3
- package/dist/tools/vdb/byte-reader.js +26 -4
- package/dist/tools/vdb/byte-reader.js.map +1 -1
- package/dist/tools/vdb/compression.d.ts +13 -5
- package/dist/tools/vdb/compression.js +13 -2
- package/dist/tools/vdb/compression.js.map +1 -1
- package/dist/tools/vdb/grid.js +8 -2
- package/dist/tools/vdb/grid.js.map +1 -1
- package/dist/tools/vdb/index.d.ts +2 -1
- package/dist/tools/vdb/index.js.map +1 -1
- package/dist/tools/vdb/lz4.d.ts +30 -0
- package/dist/tools/vdb/lz4.js +228 -0
- package/dist/tools/vdb/lz4.js.map +1 -0
- package/dist/tools/vdb/metadata.js +1 -1
- package/dist/tools/vdb/metadata.js.map +1 -1
- package/dist/tools/vdb/parse.d.ts +24 -2
- package/dist/tools/vdb/parse.js +102 -32
- package/dist/tools/vdb/parse.js.map +1 -1
- package/dist/tools/vdb/point-render-data.d.ts +49 -1
- package/dist/tools/vdb/point-render-data.js +91 -11
- package/dist/tools/vdb/point-render-data.js.map +1 -1
- package/dist/tools/vdb/points.d.ts +26 -0
- package/dist/tools/vdb/points.js +46 -5
- package/dist/tools/vdb/points.js.map +1 -1
- package/dist/tools/vdb/types.d.ts +59 -2
- package/dist/tools/vdb/types.js.map +1 -1
- package/dist/tools/wvdb/bake.d.ts +38 -9
- package/dist/tools/wvdb/bake.js +63 -13
- package/dist/tools/wvdb/bake.js.map +1 -1
- package/dist/tools/wvdb/dense.d.ts +80 -1
- package/dist/tools/wvdb/dense.js +67 -8
- package/dist/tools/wvdb/dense.js.map +1 -1
- package/dist/tools/wvdb/format.d.ts +59 -0
- package/dist/tools/wvdb/format.js +3 -0
- package/dist/tools/wvdb/format.js.map +1 -1
- package/dist/tools/wvdb/index.d.ts +1 -0
- package/dist/tools/wvdb/index.js +1 -0
- package/dist/tools/wvdb/index.js.map +1 -1
- package/dist/tools/wvdb/level-set.d.ts +10 -2
- package/dist/tools/wvdb/level-set.js.map +1 -1
- package/dist/tools/wvdb/nanovdb.d.ts +6 -1
- package/dist/tools/wvdb/nanovdb.js +5 -1
- package/dist/tools/wvdb/nanovdb.js.map +1 -1
- package/dist/tools/wvdb/partial.d.ts +74 -0
- package/dist/tools/wvdb/partial.js +233 -0
- package/dist/tools/wvdb/partial.js.map +1 -0
- package/dist/tools/wvdb/read.d.ts +77 -1
- package/dist/tools/wvdb/read.js +30 -7
- package/dist/tools/wvdb/read.js.map +1 -1
- package/dist/tools/wvdb/write.d.ts +23 -1
- package/dist/tools/wvdb/write.js +8 -1
- package/dist/tools/wvdb/write.js.map +1 -1
- package/package.json +2 -1
- package/vendor/VENDOR.md +21 -6
- package/vendor/pnanovdb.wgsl +52 -14
- package/dist/three/frame/blackbody.d.ts +0 -42
- package/dist/three/frame/blackbody.js +0 -74
- package/dist/three/frame/blackbody.js.map +0 -1
- package/dist/three/frame/chunks.d.ts +0 -157
- package/dist/three/frame/chunks.js +0 -559
- package/dist/three/frame/chunks.js.map +0 -1
- package/dist/three/frame/density-material.d.ts +0 -53
- package/dist/three/frame/density-material.js +0 -353
- package/dist/three/frame/density-material.js.map +0 -1
- package/dist/three/frame/environment-grid-material.d.ts +0 -21
- package/dist/three/frame/environment-grid-material.js +0 -184
- package/dist/three/frame/environment-grid-material.js.map +0 -1
- package/dist/three/frame/environment-material.d.ts +0 -22
- package/dist/three/frame/environment-material.js +0 -87
- package/dist/three/frame/environment-material.js.map +0 -1
- package/dist/three/frame/grid-mip-material.d.ts +0 -12
- package/dist/three/frame/grid-mip-material.js +0 -61
- package/dist/three/frame/grid-mip-material.js.map +0 -1
- package/dist/three/frame/inject-material.d.ts +0 -56
- package/dist/three/frame/inject-material.js +0 -424
- package/dist/three/frame/inject-material.js.map +0 -1
- package/dist/three/frame/integrate-material.d.ts +0 -26
- package/dist/three/frame/integrate-material.js +0 -198
- package/dist/three/frame/integrate-material.js.map +0 -1
- package/dist/three/frame/layout.d.ts +0 -34
- package/dist/three/frame/layout.js +0 -48
- package/dist/three/frame/layout.js.map +0 -1
- package/dist/three/frame/lighting-material.d.ts +0 -41
- package/dist/three/frame/lighting-material.js +0 -257
- package/dist/three/frame/lighting-material.js.map +0 -1
- package/dist/three/frame/lights.d.ts +0 -11
- package/dist/three/frame/lights.js +0 -16
- package/dist/three/frame/lights.js.map +0 -1
- package/dist/three/frame/neural.d.ts +0 -14
- package/dist/three/frame/neural.js +0 -105
- package/dist/three/frame/neural.js.map +0 -1
- package/dist/three/frame/phase.d.ts +0 -44
- package/dist/three/frame/phase.js +0 -80
- package/dist/three/frame/phase.js.map +0 -1
- package/dist/three/frame/shadow-density-material.d.ts +0 -30
- package/dist/three/frame/shadow-density-material.js +0 -123
- package/dist/three/frame/shadow-density-material.js.map +0 -1
- package/dist/three/frame/temporal-material.d.ts +0 -29
- package/dist/three/frame/temporal-material.js +0 -152
- package/dist/three/frame/temporal-material.js.map +0 -1
- package/dist/three/frame/transmittance-material.d.ts +0 -31
- package/dist/three/frame/transmittance-material.js +0 -315
- package/dist/three/frame/transmittance-material.js.map +0 -1
- package/dist/three/frame/view.d.ts +0 -103
- package/dist/three/frame/view.js +0 -296
- package/dist/three/frame/view.js.map +0 -1
- package/dist/three/frame/volume-shadow-material.d.ts +0 -36
- package/dist/three/frame/volume-shadow-material.js +0 -128
- package/dist/three/frame/volume-shadow-material.js.map +0 -1
- package/dist/three/sequence.js.map +0 -1
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
// K6.Nc (pmndrs/vdb#3): our code (MIT). It writes the weight convention of pmndrs/pathtracer's `@pathtracer/mlp`
|
|
2
|
+
// (research track N, MIT, Copyright (c) 2026 Dennis Smolek; read at 06488fa, same code as 0e4435b): `config.ts` (layer
|
|
3
|
+
// shapes, `layerOffset`) and `oracle.ts` (`forward`: no biases, hidden ReLU, last layer linear). No code is taken from
|
|
4
|
+
// it. Divergences: DIVERGES.md (K6.Nc row).
|
|
5
|
+
/**
|
|
6
|
+
* K6.Nc: the 'neural' network in the weight convention of the pmndrs neural radiance cache (`@pathtracer/mlp`, the
|
|
7
|
+
* network pmndrs/pathtracer's NRC and pmndrs/gi's neural tail train on the GPU). That convention has **no biases**: a
|
|
8
|
+
* network is `{ inputs, width, hidden, outputs }` (inputs and width multiples of 8, every hidden layer `width` wide),
|
|
9
|
+
* its weights one flat f32 array, layer by layer, each row-major [out][in]; hidden layers are ReLU, the last is linear,
|
|
10
|
+
* and the input encoding carries constant-one inputs that act as the bias (`NrcCache.loadWeights` takes such an array).
|
|
11
|
+
*
|
|
12
|
+
* Ours has biases, so {@link vdbFrameMlpToNn} embeds it exactly: input `features` (our 3 L + 2 features come first)
|
|
13
|
+
* holds a constant 1, and the last unit of every hidden layer is a **carrier** fed only by that one (weight 1, so it
|
|
14
|
+
* stays 1 through each ReLU); each layer's biases become its weights from the one or the carrier. Our 20 → 32 → 32 → 1
|
|
15
|
+
* becomes 24 → 2 × 40 → 1 (2 600 weights; ours 1 761 with biases). {@link vdbFrameMlpFromNn} is the inverse for any
|
|
16
|
+
* network in that convention: the constant-one columns of the first layer become its biases, then every hidden unit
|
|
17
|
+
* with no input weights (a carrier, or a dead unit) is a constant and is folded into the next layer's biases and
|
|
18
|
+
* removed. Ours → convention → ours gives back the same weights bit for bit. The output transform (our 'exp') is not
|
|
19
|
+
* part of the convention: it stays an option, as in the `.tza` map (`mlp-tza.ts`).
|
|
20
|
+
*/
|
|
21
|
+
import { VDBToolsError } from "../errors.js";
|
|
22
|
+
import { vdbFrameMlpCheck, vdbFrameMlpOffsets } from "./mlp.js";
|
|
23
|
+
const bad = (message) => {
|
|
24
|
+
throw new VDBToolsError("VDB_BAD_OPTION", `mlp (nn convention): ${message}`);
|
|
25
|
+
};
|
|
26
|
+
const ceil8 = (n) => Math.ceil(n / 8) * 8;
|
|
27
|
+
/** The weight count of a network in the convention (`@pathtracer/mlp` `weightCount`). */
|
|
28
|
+
export function vdbFrameMlpNnWeightCount(shape) {
|
|
29
|
+
return shape.inputs * shape.width + (shape.hidden - 1) * shape.width * shape.width + shape.width * shape.outputs;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Our network in `@pathtracer/mlp`'s bias-free convention (exact; module comment). Needs ReLU hidden layers and a
|
|
33
|
+
* linear last layer (the convention has no other activations). The output transform is not carried.
|
|
34
|
+
*/
|
|
35
|
+
export function vdbFrameMlpToNn(mlp) {
|
|
36
|
+
const reason = vdbFrameMlpCheck(mlp);
|
|
37
|
+
if (reason)
|
|
38
|
+
bad(reason);
|
|
39
|
+
const layers = mlp.layers;
|
|
40
|
+
if (layers.length < 2)
|
|
41
|
+
bad("needs at least one hidden layer");
|
|
42
|
+
layers.forEach((l, i) => {
|
|
43
|
+
const want = i === layers.length - 1 ? "linear" : "relu";
|
|
44
|
+
if (l.activation !== want)
|
|
45
|
+
bad(`layer ${i} is ${l.activation}; the convention has ReLU hidden layers and a linear last layer`);
|
|
46
|
+
});
|
|
47
|
+
const features = layers[0].inputs;
|
|
48
|
+
const hidden = layers.length - 1;
|
|
49
|
+
const inputs = ceil8(features + 1);
|
|
50
|
+
const width = ceil8(Math.max(...layers.slice(0, hidden).map((l) => l.outputs)) + 1);
|
|
51
|
+
const outputs = layers[hidden].outputs;
|
|
52
|
+
if (outputs > width)
|
|
53
|
+
bad(`${outputs} outputs exceed the hidden width ${width}`);
|
|
54
|
+
const shape = { inputs, width, hidden, outputs };
|
|
55
|
+
const carrier = width - 1;
|
|
56
|
+
const w = new Float32Array(vdbFrameMlpNnWeightCount(shape));
|
|
57
|
+
const offsets = vdbFrameMlpOffsets(mlp);
|
|
58
|
+
let at = 0;
|
|
59
|
+
for (let li = 0; li <= hidden; li++) {
|
|
60
|
+
const l = layers[li];
|
|
61
|
+
const src = offsets[li];
|
|
62
|
+
const nIn = li === 0 ? inputs : width;
|
|
63
|
+
const nOut = li === hidden ? outputs : width;
|
|
64
|
+
// the bias input: our constant one (layer 0) or the previous layer's carrier
|
|
65
|
+
const one = li === 0 ? features : carrier;
|
|
66
|
+
for (let j = 0; j < l.outputs; j++) {
|
|
67
|
+
for (let i = 0; i < l.inputs; i++)
|
|
68
|
+
w[at + j * nIn + i] = mlp.weights[src + j * l.inputs + i];
|
|
69
|
+
w[at + j * nIn + one] = mlp.weights[src + l.outputs * l.inputs + j];
|
|
70
|
+
}
|
|
71
|
+
if (li < hidden)
|
|
72
|
+
w[at + carrier * nIn + one] = 1;
|
|
73
|
+
at += nIn * nOut;
|
|
74
|
+
}
|
|
75
|
+
return { shape, weights: w, features, ones: [features] };
|
|
76
|
+
}
|
|
77
|
+
/** The convention's input vector for our features: the features, 1 at each `ones` input, 0 elsewhere. */
|
|
78
|
+
export function vdbFrameMlpNnInputs(nn, features) {
|
|
79
|
+
if (features.length !== nn.features)
|
|
80
|
+
bad(`expected ${nn.features} features, got ${features.length}`);
|
|
81
|
+
const x = new Float32Array(nn.shape.inputs);
|
|
82
|
+
for (let i = 0; i < nn.features; i++)
|
|
83
|
+
x[i] = features[i];
|
|
84
|
+
for (const c of nn.ones)
|
|
85
|
+
x[c] = 1;
|
|
86
|
+
return x;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* A network in `@pathtracer/mlp`'s convention as ours (exact): the first layer's `ones` columns summed into its
|
|
90
|
+
* biases (other inputs past `features` are zero and dropped), then every hidden unit with no input weights folded into
|
|
91
|
+
* the next layer's biases as the constant relu(its bias) and removed (carriers and dead units).
|
|
92
|
+
*/
|
|
93
|
+
export function vdbFrameMlpFromNn(nn, o = {}) {
|
|
94
|
+
const { shape, features, ones } = nn;
|
|
95
|
+
for (const [k, v] of Object.entries(shape))
|
|
96
|
+
if (!Number.isInteger(v) || v < 1)
|
|
97
|
+
bad(`shape.${k} must be a positive integer (got ${v})`);
|
|
98
|
+
if (nn.weights.length !== vdbFrameMlpNnWeightCount(shape))
|
|
99
|
+
bad(`expected ${vdbFrameMlpNnWeightCount(shape)} weights, got ${nn.weights.length}`);
|
|
100
|
+
if (!(features >= 1 && features <= shape.inputs))
|
|
101
|
+
bad(`features must be 1 to ${shape.inputs} (got ${features})`);
|
|
102
|
+
for (const c of ones)
|
|
103
|
+
if (!(Number.isInteger(c) && c >= features && c < shape.inputs))
|
|
104
|
+
bad(`a constant-one input must be past the features (got ${c})`);
|
|
105
|
+
// dense f64 layers: W [out][in] and b [out]
|
|
106
|
+
const W = [];
|
|
107
|
+
const B = [];
|
|
108
|
+
let at = 0;
|
|
109
|
+
for (let l = 0; l <= shape.hidden; l++) {
|
|
110
|
+
const nIn = l === 0 ? shape.inputs : shape.width;
|
|
111
|
+
const nOut = l === shape.hidden ? shape.outputs : shape.width;
|
|
112
|
+
const rows = [];
|
|
113
|
+
const b = new Float64Array(nOut);
|
|
114
|
+
for (let j = 0; j < nOut; j++) {
|
|
115
|
+
const row = Float64Array.from(nn.weights.subarray(at + j * nIn, at + (j + 1) * nIn));
|
|
116
|
+
if (l === 0) {
|
|
117
|
+
for (const c of ones)
|
|
118
|
+
b[j] += row[c];
|
|
119
|
+
rows.push(row.slice(0, features));
|
|
120
|
+
}
|
|
121
|
+
else
|
|
122
|
+
rows.push(row);
|
|
123
|
+
}
|
|
124
|
+
W.push(rows);
|
|
125
|
+
B.push(b);
|
|
126
|
+
at += nIn * nOut;
|
|
127
|
+
}
|
|
128
|
+
// fold the constant hidden units (no input weights) into the next layer, last unit first so indices stay valid
|
|
129
|
+
for (let l = 0; l < shape.hidden; l++) {
|
|
130
|
+
for (let j = W[l].length - 1; j >= 0; j--) {
|
|
131
|
+
if (W[l][j].some((v) => v !== 0))
|
|
132
|
+
continue;
|
|
133
|
+
const k = Math.max(B[l][j], 0);
|
|
134
|
+
const next = W[l + 1];
|
|
135
|
+
next.forEach((row, r) => {
|
|
136
|
+
if (k !== 0)
|
|
137
|
+
B[l + 1][r] += row[j] * k;
|
|
138
|
+
W[l + 1][r] = Float64Array.from([...row.subarray(0, j), ...row.subarray(j + 1)]);
|
|
139
|
+
});
|
|
140
|
+
W[l].splice(j, 1);
|
|
141
|
+
B[l] = Float64Array.from([...B[l].subarray(0, j), ...B[l].subarray(j + 1)]);
|
|
142
|
+
}
|
|
143
|
+
if (W[l].length === 0)
|
|
144
|
+
bad(`hidden layer ${l} has no unit that depends on the inputs`);
|
|
145
|
+
}
|
|
146
|
+
const layers = W.map((rows, l) => ({ inputs: l === 0 ? features : W[l - 1].length, outputs: rows.length, activation: l === shape.hidden ? "linear" : "relu" }));
|
|
147
|
+
const weights = [];
|
|
148
|
+
W.forEach((rows, l) => {
|
|
149
|
+
for (const row of rows)
|
|
150
|
+
weights.push(...row);
|
|
151
|
+
weights.push(...B[l]);
|
|
152
|
+
});
|
|
153
|
+
const mlp = { name: o.name ?? "nn", levels: o.levels ?? (features - 2) / 3, layers, output: o.output ?? "exp", weights: Float32Array.from(weights) };
|
|
154
|
+
const reason = vdbFrameMlpCheck(mlp);
|
|
155
|
+
if (reason)
|
|
156
|
+
bad(reason);
|
|
157
|
+
return mlp;
|
|
158
|
+
}
|
|
159
|
+
//# sourceMappingURL=mlp-nn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mlp-nn.js","sourceRoot":"","sources":["../../../src/tools/frame/mlp-nn.ts"],"names":[],"mappings":"AAAA,iHAAiH;AACjH,uHAAuH;AACvH,uHAAuH;AACvH,4CAA4C;AAE5C;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,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AM,EAAE,CAAC,CAAC,MAAM,IAAI,KAAK,EAAE,OAAO,EAAE,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;IAClK,MAAM,MAAM,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC;IACrC,IAAI,MAAM;QAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACxB,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["// K6.Nc (pmndrs/vdb#3): our code (MIT). It writes the weight convention of pmndrs/pathtracer's `@pathtracer/mlp`\n// (research track N, MIT, Copyright (c) 2026 Dennis Smolek; read at 06488fa, same code as 0e4435b): `config.ts` (layer\n// shapes, `layerOffset`) and `oracle.ts` (`forward`: no biases, hidden ReLU, last layer linear). No code is taken from\n// it. Divergences: DIVERGES.md (K6.Nc row).\n\n/**\n * K6.Nc: the 'neural' network in the weight convention of the pmndrs neural radiance cache (`@pathtracer/mlp`, the\n * network pmndrs/pathtracer's NRC and pmndrs/gi's neural tail train on the GPU). That convention has **no biases**: a\n * network is `{ inputs, width, hidden, outputs }` (inputs and width multiples of 8, every hidden layer `width` wide),\n * its weights one flat f32 array, layer by layer, each row-major [out][in]; hidden layers are ReLU, the last is linear,\n * and the input encoding carries constant-one inputs that act as the bias (`NrcCache.loadWeights` takes such an array).\n *\n * Ours has biases, so {@link vdbFrameMlpToNn} embeds it exactly: input `features` (our 3 L + 2 features come first)\n * holds a constant 1, and the last unit of every hidden layer is a **carrier** fed only by that one (weight 1, so it\n * stays 1 through each ReLU); each layer's biases become its weights from the one or the carrier. Our 20 → 32 → 32 → 1\n * becomes 24 → 2 × 40 → 1 (2 600 weights; ours 1 761 with biases). {@link vdbFrameMlpFromNn} is the inverse for any\n * network in that convention: the constant-one columns of the first layer become its biases, then every hidden unit\n * with no input weights (a carrier, or a dead unit) is a constant and is folded into the next layer's biases and\n * removed. Ours → convention → ours gives back the same weights bit for bit. The output transform (our 'exp') is not\n * part of the convention: it stays an option, as in the `.tza` map (`mlp-tza.ts`).\n */\n\nimport { VDBToolsError } from \"../errors.js\";\nimport { vdbFrameMlpCheck, vdbFrameMlpOffsets, type VDBFrameMlp, type VDBFrameMlpLayer } from \"./mlp.js\";\n\n/** A network in `@pathtracer/mlp`'s convention (its `MlpShape` and flat weights), with where our inputs sit. */\nexport interface VDBFrameMlpNn {\n /** `@pathtracer/mlp`'s `MlpShape`: `hidden` ReLU layers of `width`, then a linear layer to `outputs`. */\n shape: { inputs: number; width: number; hidden: number; outputs: number };\n /** Layer by layer, row-major [out][in], no biases (`layerOffset` order). */\n weights: Float32Array;\n /** Inputs 0 … features − 1 are our feature vector (3 L + 2 values). */\n features: number;\n /** Inputs that hold a constant 1 (the bias inputs); every other input past `features` is 0. */\n ones: number[];\n}\n\nconst bad = (message: string): never => {\n throw new VDBToolsError(\"VDB_BAD_OPTION\", `mlp (nn convention): ${message}`);\n};\n\nconst ceil8 = (n: number) => Math.ceil(n / 8) * 8;\n\n/** The weight count of a network in the convention (`@pathtracer/mlp` `weightCount`). */\nexport function vdbFrameMlpNnWeightCount(shape: VDBFrameMlpNn[\"shape\"]): number {\n return shape.inputs * shape.width + (shape.hidden - 1) * shape.width * shape.width + shape.width * shape.outputs;\n}\n\n/**\n * Our network in `@pathtracer/mlp`'s bias-free convention (exact; module comment). Needs ReLU hidden layers and a\n * linear last layer (the convention has no other activations). The output transform is not carried.\n */\nexport function vdbFrameMlpToNn(mlp: VDBFrameMlp): VDBFrameMlpNn {\n const reason = vdbFrameMlpCheck(mlp);\n if (reason) bad(reason);\n const layers = mlp.layers;\n if (layers.length < 2) bad(\"needs at least one hidden layer\");\n layers.forEach((l, i) => {\n const want = i === layers.length - 1 ? \"linear\" : \"relu\";\n if (l.activation !== want) bad(`layer ${i} is ${l.activation}; the convention has ReLU hidden layers and a linear last layer`);\n });\n const features = layers[0]!.inputs;\n const hidden = layers.length - 1;\n const inputs = ceil8(features + 1);\n const width = ceil8(Math.max(...layers.slice(0, hidden).map((l) => l.outputs)) + 1);\n const outputs = layers[hidden]!.outputs;\n if (outputs > width) bad(`${outputs} outputs exceed the hidden width ${width}`);\n const shape = { inputs, width, hidden, outputs };\n const carrier = width - 1;\n const w = new Float32Array(vdbFrameMlpNnWeightCount(shape));\n const offsets = vdbFrameMlpOffsets(mlp);\n let at = 0;\n for (let li = 0; li <= hidden; li++) {\n const l = layers[li]!;\n const src = offsets[li]!;\n const nIn = li === 0 ? inputs : width;\n const nOut = li === hidden ? outputs : width;\n // the bias input: our constant one (layer 0) or the previous layer's carrier\n const one = li === 0 ? features : carrier;\n for (let j = 0; j < l.outputs; j++) {\n for (let i = 0; i < l.inputs; i++) w[at + j * nIn + i] = mlp.weights[src + j * l.inputs + i]!;\n w[at + j * nIn + one] = mlp.weights[src + l.outputs * l.inputs + j]!;\n }\n if (li < hidden) w[at + carrier * nIn + one] = 1;\n at += nIn * nOut;\n }\n return { shape, weights: w, features, ones: [features] };\n}\n\n/** The convention's input vector for our features: the features, 1 at each `ones` input, 0 elsewhere. */\nexport function vdbFrameMlpNnInputs(nn: Pick<VDBFrameMlpNn, \"shape\" | \"features\" | \"ones\">, features: ArrayLike<number>): Float32Array {\n if (features.length !== nn.features) bad(`expected ${nn.features} features, got ${features.length}`);\n const x = new Float32Array(nn.shape.inputs);\n for (let i = 0; i < nn.features; i++) x[i] = features[i]!;\n for (const c of nn.ones) x[c] = 1;\n return x;\n}\n\n/**\n * A network in `@pathtracer/mlp`'s convention as ours (exact): the first layer's `ones` columns summed into its\n * biases (other inputs past `features` are zero and dropped), then every hidden unit with no input weights folded into\n * the next layer's biases as the constant relu(its bias) and removed (carriers and dead units).\n */\nexport function vdbFrameMlpFromNn(nn: VDBFrameMlpNn, o: { name?: string; output?: VDBFrameMlp[\"output\"]; levels?: number } = {}): VDBFrameMlp {\n const { shape, features, ones } = nn;\n for (const [k, v] of Object.entries(shape)) if (!Number.isInteger(v) || v < 1) bad(`shape.${k} must be a positive integer (got ${v})`);\n if (nn.weights.length !== vdbFrameMlpNnWeightCount(shape)) bad(`expected ${vdbFrameMlpNnWeightCount(shape)} weights, got ${nn.weights.length}`);\n if (!(features >= 1 && features <= shape.inputs)) bad(`features must be 1 to ${shape.inputs} (got ${features})`);\n for (const c of ones) if (!(Number.isInteger(c) && c >= features && c < shape.inputs)) bad(`a constant-one input must be past the features (got ${c})`);\n // dense f64 layers: W [out][in] and b [out]\n const W: Float64Array[][] = [];\n const B: Float64Array[] = [];\n let at = 0;\n for (let l = 0; l <= shape.hidden; l++) {\n const nIn = l === 0 ? shape.inputs : shape.width;\n const nOut = l === shape.hidden ? shape.outputs : shape.width;\n const rows: Float64Array[] = [];\n const b = new Float64Array(nOut);\n for (let j = 0; j < nOut; j++) {\n const row = Float64Array.from(nn.weights.subarray(at + j * nIn, at + (j + 1) * nIn));\n if (l === 0) {\n for (const c of ones) b[j]! += row[c]!;\n rows.push(row.slice(0, features));\n } else rows.push(row);\n }\n W.push(rows);\n B.push(b);\n at += nIn * nOut;\n }\n // fold the constant hidden units (no input weights) into the next layer, last unit first so indices stay valid\n for (let l = 0; l < shape.hidden; l++) {\n for (let j = W[l]!.length - 1; j >= 0; j--) {\n if (W[l]![j]!.some((v) => v !== 0)) continue;\n const k = Math.max(B[l]![j]!, 0);\n const next = W[l + 1]!;\n next.forEach((row, r) => {\n if (k !== 0) B[l + 1]![r]! += row[j]! * k;\n W[l + 1]![r] = Float64Array.from([...row.subarray(0, j), ...row.subarray(j + 1)]);\n });\n W[l]!.splice(j, 1);\n B[l] = Float64Array.from([...B[l]!.subarray(0, j), ...B[l]!.subarray(j + 1)]);\n }\n if (W[l]!.length === 0) bad(`hidden layer ${l} has no unit that depends on the inputs`);\n }\n const layers: VDBFrameMlpLayer[] = W.map((rows, l) => ({ inputs: l === 0 ? features : W[l - 1]!.length, outputs: rows.length, activation: l === shape.hidden ? \"linear\" : \"relu\" }));\n const weights: number[] = [];\n W.forEach((rows, l) => {\n for (const row of rows) weights.push(...row);\n weights.push(...B[l]!);\n });\n const mlp: VDBFrameMlp = { name: o.name ?? \"nn\", levels: o.levels ?? (features - 2) / 3, layers, output: o.output ?? \"exp\", weights: Float32Array.from(weights) };\n const reason = vdbFrameMlpCheck(mlp);\n if (reason) bad(reason);\n return mlp;\n}\n"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type VDBFrameMlp } from "./mlp.js";
|
|
2
|
+
/** One tensor of a `.tza` blob (f32 values; f16 tensors are widened on read). */
|
|
3
|
+
export interface VDBTzaTensor {
|
|
4
|
+
data: Float32Array;
|
|
5
|
+
shape: number[];
|
|
6
|
+
/** The layout string (one char per dimension, e.g. "oi"); "" when the blob has none. */
|
|
7
|
+
layout: string;
|
|
8
|
+
/** The stored type: 'f' f32, 'h' f16. */
|
|
9
|
+
type: "f" | "h";
|
|
10
|
+
}
|
|
11
|
+
/** Reads a `.tza` v2 blob (the format `parseTZA` reads): tensor name → tensor, in file order. */
|
|
12
|
+
export declare function vdbTzaRead(bytes: ArrayBuffer | Uint8Array): Map<string, VDBTzaTensor>;
|
|
13
|
+
/** Writes tensors as a `.tza` v2 blob (data 64-byte aligned after the 12-byte header, then the table). */
|
|
14
|
+
export declare function vdbTzaWrite(tensors: ReadonlyMap<string, Pick<VDBTzaTensor, "data" | "shape"> & Partial<Pick<VDBTzaTensor, "layout" | "type">>>): Uint8Array;
|
|
15
|
+
/**
|
|
16
|
+
* K6.Na: a network as `.tza` tensors (`layers.<i>.weight` [outputs, inputs], `layers.<i>.bias` [outputs]). `type` 'h'
|
|
17
|
+
* stores binary16 (half the bytes; the weights round to f16, which changes the network: an A/B, not a format detail).
|
|
18
|
+
* Only networks whose hidden layers are ReLU and whose last layer is linear map onto the convention.
|
|
19
|
+
*/
|
|
20
|
+
export declare function vdbFrameMlpToTza(mlp: VDBFrameMlp, o?: {
|
|
21
|
+
type?: "f" | "h";
|
|
22
|
+
}): Uint8Array;
|
|
23
|
+
/** K6.Na: the network of a `.tza` blob written by {@link vdbFrameMlpToTza} (or any `layers.<i>.weight/bias` set). */
|
|
24
|
+
export declare function vdbFrameMlpFromTza(bytes: ArrayBuffer | Uint8Array, o?: {
|
|
25
|
+
name?: string;
|
|
26
|
+
output?: VDBFrameMlp["output"];
|
|
27
|
+
levels?: number;
|
|
28
|
+
extra?: VDBFrameMlp["extra"];
|
|
29
|
+
}): VDBFrameMlp;
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
// Portions derived from pmndrs/denoiser (MIT, Copyright (c) 2024 Dennis Smolek), commit 3ad5e98:
|
|
2
|
+
// packages/denoiser-core/src/tza.ts (`parseTZA`, `halfToFloat`: the OIDN TZA v2 weight container reader).
|
|
3
|
+
// Changes: a writer (the reader's inverse; binary16 through tools/nanovdb/half.ts), errors as VDBToolsError, and the
|
|
4
|
+
// map between a TZA tensor set and the core's generic MLP (`VDBFrameMlp`). Divergences: DIVERGES.md (K6.Na rows).
|
|
5
|
+
/**
|
|
6
|
+
* K6.Na: the 'neural' network in the weight container of the pmndrs neural tooling (pmndrs/denoiser reads Intel OIDN's
|
|
7
|
+
* `.tza` blobs with `parseTZA`, its Python converter with `tza.py`). A `.tza` is a list of named tensors (f32 'f' or
|
|
8
|
+
* f16 'h', any shape); a network is stored as PyTorch `nn.Linear` names: `layers.<i>.weight` [outputs, inputs] (row-major,
|
|
9
|
+
* layout "oi") and `layers.<i>.bias` [outputs] ("o"). Hidden layers are ReLU and the last is linear (the trainer's net);
|
|
10
|
+
* the output transform and the feature levels are not in the file: `levels` = (inputs − 2) / 3, `output` defaults to
|
|
11
|
+
* 'exp' (both options). Our weights stay a TypeScript data module too (the default network needs no fetch).
|
|
12
|
+
*/
|
|
13
|
+
import { VDBToolsError } from "../errors.js";
|
|
14
|
+
import { vdbFloatToHalf, vdbHalfToFloat } from "../nanovdb/half.js";
|
|
15
|
+
import { vdbFrameMlpExtraInputs } from "./mlp.js";
|
|
16
|
+
const MAGIC = 0x41d7;
|
|
17
|
+
const MAJOR_VERSION = 2;
|
|
18
|
+
/** Tensor data alignment of the writer (OIDN's blobs align tensors to 64 bytes). */
|
|
19
|
+
const ALIGN = 64;
|
|
20
|
+
const bad = (message) => {
|
|
21
|
+
throw new VDBToolsError("VDB_BAD_OPTION", `tza: ${message}`);
|
|
22
|
+
};
|
|
23
|
+
/** Reads a `.tza` v2 blob (the format `parseTZA` reads): tensor name → tensor, in file order. */
|
|
24
|
+
export function vdbTzaRead(bytes) {
|
|
25
|
+
const buf = bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes);
|
|
26
|
+
if (buf.byteLength < 12)
|
|
27
|
+
bad("too short for a header");
|
|
28
|
+
const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
29
|
+
if (view.getUint16(0, true) !== MAGIC)
|
|
30
|
+
bad("invalid or corrupted weights blob (magic)");
|
|
31
|
+
const major = view.getUint8(2);
|
|
32
|
+
if (major !== MAJOR_VERSION)
|
|
33
|
+
bad(`unsupported weights blob version ${major}`);
|
|
34
|
+
let offset = Number(view.getBigUint64(4, true));
|
|
35
|
+
const need = (n) => {
|
|
36
|
+
if (offset + n > buf.byteLength)
|
|
37
|
+
bad("table runs past the end of the blob");
|
|
38
|
+
};
|
|
39
|
+
need(4);
|
|
40
|
+
const count = view.getUint32(offset, true);
|
|
41
|
+
offset += 4;
|
|
42
|
+
const decoder = new TextDecoder();
|
|
43
|
+
const tensors = new Map();
|
|
44
|
+
for (let t = 0; t < count; t++) {
|
|
45
|
+
need(2);
|
|
46
|
+
const nameLength = view.getUint16(offset, true);
|
|
47
|
+
offset += 2;
|
|
48
|
+
need(nameLength + 1);
|
|
49
|
+
const name = decoder.decode(buf.subarray(offset, offset + nameLength));
|
|
50
|
+
offset += nameLength;
|
|
51
|
+
const dims = view.getUint8(offset);
|
|
52
|
+
offset += 1;
|
|
53
|
+
need(dims * 5 + 9);
|
|
54
|
+
const shape = [];
|
|
55
|
+
for (let d = 0; d < dims; d++) {
|
|
56
|
+
shape.push(view.getUint32(offset, true));
|
|
57
|
+
offset += 4;
|
|
58
|
+
}
|
|
59
|
+
const layout = decoder.decode(buf.subarray(offset, offset + dims));
|
|
60
|
+
offset += dims;
|
|
61
|
+
const type = String.fromCharCode(view.getUint8(offset));
|
|
62
|
+
offset += 1;
|
|
63
|
+
const at = Number(view.getBigUint64(offset, true));
|
|
64
|
+
offset += 8;
|
|
65
|
+
const n = shape.reduce((a, b) => a * b, 1);
|
|
66
|
+
if (type !== "f" && type !== "h")
|
|
67
|
+
bad(`tensor ${name}: invalid data type '${type}'`);
|
|
68
|
+
const size = n * (type === "f" ? 4 : 2);
|
|
69
|
+
if (at + size > buf.byteLength)
|
|
70
|
+
bad(`tensor ${name} runs past the end of the blob`);
|
|
71
|
+
const data = new Float32Array(n);
|
|
72
|
+
for (let i = 0; i < n; i++)
|
|
73
|
+
data[i] = type === "f" ? view.getFloat32(at + 4 * i, true) : vdbHalfToFloat(view.getUint16(at + 2 * i, true));
|
|
74
|
+
tensors.set(name, { data, shape, layout, type: type });
|
|
75
|
+
}
|
|
76
|
+
return tensors;
|
|
77
|
+
}
|
|
78
|
+
/** Writes tensors as a `.tza` v2 blob (data 64-byte aligned after the 12-byte header, then the table). */
|
|
79
|
+
export function vdbTzaWrite(tensors) {
|
|
80
|
+
const encoder = new TextEncoder();
|
|
81
|
+
const entries = [...tensors].map(([name, t]) => {
|
|
82
|
+
const type = t.type ?? "f";
|
|
83
|
+
const n = t.shape.reduce((a, b) => a * b, 1);
|
|
84
|
+
if (n !== t.data.length)
|
|
85
|
+
bad(`tensor ${name}: shape [${t.shape.join(", ")}] holds ${n} values, data has ${t.data.length}`);
|
|
86
|
+
const layout = t.layout ?? "";
|
|
87
|
+
if (layout && layout.length !== t.shape.length)
|
|
88
|
+
bad(`tensor ${name}: layout "${layout}" for ${t.shape.length} dimensions`);
|
|
89
|
+
return { name: encoder.encode(name), shape: t.shape, layout: encoder.encode(layout.padEnd(t.shape.length, "x")), type, data: t.data, bytes: n * (type === "f" ? 4 : 2) };
|
|
90
|
+
});
|
|
91
|
+
let at = 12;
|
|
92
|
+
const placed = entries.map((e) => {
|
|
93
|
+
at = Math.ceil(at / ALIGN) * ALIGN;
|
|
94
|
+
const offset = at;
|
|
95
|
+
at += e.bytes;
|
|
96
|
+
return offset;
|
|
97
|
+
});
|
|
98
|
+
const table = at;
|
|
99
|
+
const tableBytes = 4 + entries.reduce((s, e) => s + 2 + e.name.length + 1 + 5 * e.shape.length + 1 + 8, 0);
|
|
100
|
+
const out = new Uint8Array(table + tableBytes);
|
|
101
|
+
const view = new DataView(out.buffer);
|
|
102
|
+
view.setUint16(0, MAGIC, true);
|
|
103
|
+
view.setUint8(2, MAJOR_VERSION);
|
|
104
|
+
view.setUint8(3, 0);
|
|
105
|
+
view.setBigUint64(4, BigInt(table), true);
|
|
106
|
+
entries.forEach((e, i) => {
|
|
107
|
+
const o = placed[i];
|
|
108
|
+
for (let k = 0; k < e.data.length; k++) {
|
|
109
|
+
if (e.type === "f")
|
|
110
|
+
view.setFloat32(o + 4 * k, e.data[k], true);
|
|
111
|
+
else
|
|
112
|
+
view.setUint16(o + 2 * k, vdbFloatToHalf(e.data[k]), true);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
let p = table;
|
|
116
|
+
view.setUint32(p, entries.length, true);
|
|
117
|
+
p += 4;
|
|
118
|
+
entries.forEach((e, i) => {
|
|
119
|
+
view.setUint16(p, e.name.length, true);
|
|
120
|
+
p += 2;
|
|
121
|
+
out.set(e.name, p);
|
|
122
|
+
p += e.name.length;
|
|
123
|
+
view.setUint8(p, e.shape.length);
|
|
124
|
+
p += 1;
|
|
125
|
+
for (const d of e.shape) {
|
|
126
|
+
view.setUint32(p, d, true);
|
|
127
|
+
p += 4;
|
|
128
|
+
}
|
|
129
|
+
out.set(e.layout, p);
|
|
130
|
+
p += e.shape.length;
|
|
131
|
+
view.setUint8(p, e.type.charCodeAt(0));
|
|
132
|
+
p += 1;
|
|
133
|
+
view.setBigUint64(p, BigInt(placed[i]), true);
|
|
134
|
+
p += 8;
|
|
135
|
+
});
|
|
136
|
+
return out;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* K6.Na: a network as `.tza` tensors (`layers.<i>.weight` [outputs, inputs], `layers.<i>.bias` [outputs]). `type` 'h'
|
|
140
|
+
* stores binary16 (half the bytes; the weights round to f16, which changes the network: an A/B, not a format detail).
|
|
141
|
+
* Only networks whose hidden layers are ReLU and whose last layer is linear map onto the convention.
|
|
142
|
+
*/
|
|
143
|
+
export function vdbFrameMlpToTza(mlp, o = {}) {
|
|
144
|
+
const tensors = new Map();
|
|
145
|
+
let at = 0;
|
|
146
|
+
mlp.layers.forEach((l, i) => {
|
|
147
|
+
const wanted = i === mlp.layers.length - 1 ? "linear" : "relu";
|
|
148
|
+
if (l.activation !== wanted)
|
|
149
|
+
bad(`layer ${i} is '${l.activation}'; the .tza convention has ReLU hidden layers and a linear last layer`);
|
|
150
|
+
tensors.set(`layers.${i}.weight`, { data: mlp.weights.slice(at, at + l.outputs * l.inputs), shape: [l.outputs, l.inputs], layout: "oi", type: o.type ?? "f" });
|
|
151
|
+
at += l.outputs * l.inputs;
|
|
152
|
+
tensors.set(`layers.${i}.bias`, { data: mlp.weights.slice(at, at + l.outputs), shape: [l.outputs], layout: "o", type: o.type ?? "f" });
|
|
153
|
+
at += l.outputs;
|
|
154
|
+
});
|
|
155
|
+
return vdbTzaWrite(tensors);
|
|
156
|
+
}
|
|
157
|
+
/** K6.Na: the network of a `.tza` blob written by {@link vdbFrameMlpToTza} (or any `layers.<i>.weight/bias` set). */
|
|
158
|
+
export function vdbFrameMlpFromTza(bytes, o = {}) {
|
|
159
|
+
const tensors = vdbTzaRead(bytes);
|
|
160
|
+
const layers = [];
|
|
161
|
+
const parts = [];
|
|
162
|
+
for (let i = 0; tensors.has(`layers.${i}.weight`); i++) {
|
|
163
|
+
const w = tensors.get(`layers.${i}.weight`);
|
|
164
|
+
const b = tensors.get(`layers.${i}.bias`) ?? bad(`layers.${i}.bias is missing`);
|
|
165
|
+
if (w.shape.length !== 2)
|
|
166
|
+
bad(`layers.${i}.weight has ${w.shape.length} dimensions (want [outputs, inputs])`);
|
|
167
|
+
const [outputs, inputs] = w.shape;
|
|
168
|
+
if (b.shape.length !== 1 || b.shape[0] !== outputs)
|
|
169
|
+
bad(`layers.${i}.bias has shape [${b.shape.join(", ")}] (want [${outputs}])`);
|
|
170
|
+
layers.push({ inputs, outputs, activation: "relu" });
|
|
171
|
+
parts.push(w.data, b.data);
|
|
172
|
+
}
|
|
173
|
+
if (layers.length === 0)
|
|
174
|
+
bad("no layers.0.weight tensor");
|
|
175
|
+
layers[layers.length - 1].activation = "linear";
|
|
176
|
+
const weights = new Float32Array(parts.reduce((s, p) => s + p.length, 0));
|
|
177
|
+
let at = 0;
|
|
178
|
+
for (const p of parts) {
|
|
179
|
+
weights.set(p, at);
|
|
180
|
+
at += p.length;
|
|
181
|
+
}
|
|
182
|
+
// K6.Nb: an `extra: 'g'` network has one input after the 3 L + 2 features (the container has no attributes: an option)
|
|
183
|
+
const levels = o.levels ?? (layers[0].inputs - 2 - vdbFrameMlpExtraInputs(o)) / 3;
|
|
184
|
+
return { name: o.name ?? "tza", levels, layers, output: o.output ?? "exp", weights, ...(o.extra ? { extra: o.extra } : {}) };
|
|
185
|
+
}
|
|
186
|
+
//# sourceMappingURL=mlp-tza.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mlp-tza.js","sourceRoot":"","sources":["../../../src/tools/frame/mlp-tza.ts"],"names":[],"mappings":"AAAA,iGAAiG;AACjG,4GAA4G;AAC5G,qHAAqH;AACrH,kHAAkH;AAElH;;;;;;;GAOG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpE,OAAO,EAAE,sBAAsB,EAA2C,MAAM,UAAU,CAAC;AAE3F,MAAM,KAAK,GAAG,MAAM,CAAC;AACrB,MAAM,aAAa,GAAG,CAAC,CAAC;A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AG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;AAC/H,CAAC","sourcesContent":["// Portions derived from pmndrs/denoiser (MIT, Copyright (c) 2024 Dennis Smolek), commit 3ad5e98:\n// packages/denoiser-core/src/tza.ts (`parseTZA`, `halfToFloat`: the OIDN TZA v2 weight container reader).\n// Changes: a writer (the reader's inverse; binary16 through tools/nanovdb/half.ts), errors as VDBToolsError, and the\n// map between a TZA tensor set and the core's generic MLP (`VDBFrameMlp`). Divergences: DIVERGES.md (K6.Na rows).\n\n/**\n * K6.Na: the 'neural' network in the weight container of the pmndrs neural tooling (pmndrs/denoiser reads Intel OIDN's\n * `.tza` blobs with `parseTZA`, its Python converter with `tza.py`). A `.tza` is a list of named tensors (f32 'f' or\n * f16 'h', any shape); a network is stored as PyTorch `nn.Linear` names: `layers.<i>.weight` [outputs, inputs] (row-major,\n * layout \"oi\") and `layers.<i>.bias` [outputs] (\"o\"). Hidden layers are ReLU and the last is linear (the trainer's net);\n * the output transform and the feature levels are not in the file: `levels` = (inputs − 2) / 3, `output` defaults to\n * 'exp' (both options). Our weights stay a TypeScript data module too (the default network needs no fetch).\n */\n\nimport { VDBToolsError } from \"../errors.js\";\nimport { vdbFloatToHalf, vdbHalfToFloat } from \"../nanovdb/half.js\";\nimport { vdbFrameMlpExtraInputs, type VDBFrameMlp, type VDBFrameMlpLayer } from \"./mlp.js\";\n\nconst MAGIC = 0x41d7;\nconst MAJOR_VERSION = 2;\n/** Tensor data alignment of the writer (OIDN's blobs align tensors to 64 bytes). */\nconst ALIGN = 64;\n\n/** One tensor of a `.tza` blob (f32 values; f16 tensors are widened on read). */\nexport interface VDBTzaTensor {\n data: Float32Array;\n shape: number[];\n /** The layout string (one char per dimension, e.g. \"oi\"); \"\" when the blob has none. */\n layout: string;\n /** The stored type: 'f' f32, 'h' f16. */\n type: \"f\" | \"h\";\n}\n\nconst bad = (message: string): never => {\n throw new VDBToolsError(\"VDB_BAD_OPTION\", `tza: ${message}`);\n};\n\n/** Reads a `.tza` v2 blob (the format `parseTZA` reads): tensor name → tensor, in file order. */\nexport function vdbTzaRead(bytes: ArrayBuffer | Uint8Array): Map<string, VDBTzaTensor> {\n const buf = bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes);\n if (buf.byteLength < 12) bad(\"too short for a header\");\n const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);\n if (view.getUint16(0, true) !== MAGIC) bad(\"invalid or corrupted weights blob (magic)\");\n const major = view.getUint8(2);\n if (major !== MAJOR_VERSION) bad(`unsupported weights blob version ${major}`);\n let offset = Number(view.getBigUint64(4, true));\n const need = (n: number) => {\n if (offset + n > buf.byteLength) bad(\"table runs past the end of the blob\");\n };\n need(4);\n const count = view.getUint32(offset, true);\n offset += 4;\n const decoder = new TextDecoder();\n const tensors = new Map<string, VDBTzaTensor>();\n for (let t = 0; t < count; t++) {\n need(2);\n const nameLength = view.getUint16(offset, true);\n offset += 2;\n need(nameLength + 1);\n const name = decoder.decode(buf.subarray(offset, offset + nameLength));\n offset += nameLength;\n const dims = view.getUint8(offset);\n offset += 1;\n need(dims * 5 + 9);\n const shape: number[] = [];\n for (let d = 0; d < dims; d++) {\n shape.push(view.getUint32(offset, true));\n offset += 4;\n }\n const layout = decoder.decode(buf.subarray(offset, offset + dims));\n offset += dims;\n const type = String.fromCharCode(view.getUint8(offset));\n offset += 1;\n const at = Number(view.getBigUint64(offset, true));\n offset += 8;\n const n = shape.reduce((a, b) => a * b, 1);\n if (type !== \"f\" && type !== \"h\") bad(`tensor ${name}: invalid data type '${type}'`);\n const size = n * (type === \"f\" ? 4 : 2);\n if (at + size > buf.byteLength) bad(`tensor ${name} runs past the end of the blob`);\n const data = new Float32Array(n);\n for (let i = 0; i < n; i++) data[i] = type === \"f\" ? view.getFloat32(at + 4 * i, true) : vdbHalfToFloat(view.getUint16(at + 2 * i, true));\n tensors.set(name, { data, shape, layout, type: type as \"f\" | \"h\" });\n }\n return tensors;\n}\n\n/** Writes tensors as a `.tza` v2 blob (data 64-byte aligned after the 12-byte header, then the table). */\nexport function vdbTzaWrite(tensors: ReadonlyMap<string, Pick<VDBTzaTensor, \"data\" | \"shape\"> & Partial<Pick<VDBTzaTensor, \"layout\" | \"type\">>>): Uint8Array {\n const encoder = new TextEncoder();\n const entries = [...tensors].map(([name, t]) => {\n const type = t.type ?? \"f\";\n const n = t.shape.reduce((a, b) => a * b, 1);\n if (n !== t.data.length) bad(`tensor ${name}: shape [${t.shape.join(\", \")}] holds ${n} values, data has ${t.data.length}`);\n const layout = t.layout ?? \"\";\n if (layout && layout.length !== t.shape.length) bad(`tensor ${name}: layout \"${layout}\" for ${t.shape.length} dimensions`);\n return { name: encoder.encode(name), shape: t.shape, layout: encoder.encode(layout.padEnd(t.shape.length, \"x\")), type, data: t.data, bytes: n * (type === \"f\" ? 4 : 2) };\n });\n let at = 12;\n const placed = entries.map((e) => {\n at = Math.ceil(at / ALIGN) * ALIGN;\n const offset = at;\n at += e.bytes;\n return offset;\n });\n const table = at;\n const tableBytes = 4 + entries.reduce((s, e) => s + 2 + e.name.length + 1 + 5 * e.shape.length + 1 + 8, 0);\n const out = new Uint8Array(table + tableBytes);\n const view = new DataView(out.buffer);\n view.setUint16(0, MAGIC, true);\n view.setUint8(2, MAJOR_VERSION);\n view.setUint8(3, 0);\n view.setBigUint64(4, BigInt(table), true);\n entries.forEach((e, i) => {\n const o = placed[i]!;\n for (let k = 0; k < e.data.length; k++) {\n if (e.type === \"f\") view.setFloat32(o + 4 * k, e.data[k]!, true);\n else view.setUint16(o + 2 * k, vdbFloatToHalf(e.data[k]!), true);\n }\n });\n let p = table;\n view.setUint32(p, entries.length, true);\n p += 4;\n entries.forEach((e, i) => {\n view.setUint16(p, e.name.length, true);\n p += 2;\n out.set(e.name, p);\n p += e.name.length;\n view.setUint8(p, e.shape.length);\n p += 1;\n for (const d of e.shape) {\n view.setUint32(p, d, true);\n p += 4;\n }\n out.set(e.layout, p);\n p += e.shape.length;\n view.setUint8(p, e.type.charCodeAt(0));\n p += 1;\n view.setBigUint64(p, BigInt(placed[i]!), true);\n p += 8;\n });\n return out;\n}\n\n/**\n * K6.Na: a network as `.tza` tensors (`layers.<i>.weight` [outputs, inputs], `layers.<i>.bias` [outputs]). `type` 'h'\n * stores binary16 (half the bytes; the weights round to f16, which changes the network: an A/B, not a format detail).\n * Only networks whose hidden layers are ReLU and whose last layer is linear map onto the convention.\n */\nexport function vdbFrameMlpToTza(mlp: VDBFrameMlp, o: { type?: \"f\" | \"h\" } = {}): Uint8Array {\n const tensors = new Map<string, Pick<VDBTzaTensor, \"data\" | \"shape\" | \"layout\" | \"type\">>();\n let at = 0;\n mlp.layers.forEach((l, i) => {\n const wanted = i === mlp.layers.length - 1 ? \"linear\" : \"relu\";\n if (l.activation !== wanted) bad(`layer ${i} is '${l.activation}'; the .tza convention has ReLU hidden layers and a linear last layer`);\n tensors.set(`layers.${i}.weight`, { data: mlp.weights.slice(at, at + l.outputs * l.inputs), shape: [l.outputs, l.inputs], layout: \"oi\", type: o.type ?? \"f\" });\n at += l.outputs * l.inputs;\n tensors.set(`layers.${i}.bias`, { data: mlp.weights.slice(at, at + l.outputs), shape: [l.outputs], layout: \"o\", type: o.type ?? \"f\" });\n at += l.outputs;\n });\n return vdbTzaWrite(tensors);\n}\n\n/** K6.Na: the network of a `.tza` blob written by {@link vdbFrameMlpToTza} (or any `layers.<i>.weight/bias` set). */\nexport function vdbFrameMlpFromTza(bytes: ArrayBuffer | Uint8Array, o: { name?: string; output?: VDBFrameMlp[\"output\"]; levels?: number; extra?: VDBFrameMlp[\"extra\"] } = {}): VDBFrameMlp {\n const tensors = vdbTzaRead(bytes);\n const layers: VDBFrameMlpLayer[] = [];\n const parts: Float32Array[] = [];\n for (let i = 0; tensors.has(`layers.${i}.weight`); i++) {\n const w = tensors.get(`layers.${i}.weight`)!;\n const b = tensors.get(`layers.${i}.bias`) ?? bad(`layers.${i}.bias is missing`);\n if (w.shape.length !== 2) bad(`layers.${i}.weight has ${w.shape.length} dimensions (want [outputs, inputs])`);\n const [outputs, inputs] = w.shape as [number, number];\n if (b.shape.length !== 1 || b.shape[0] !== outputs) bad(`layers.${i}.bias has shape [${b.shape.join(\", \")}] (want [${outputs}])`);\n layers.push({ inputs, outputs, activation: \"relu\" });\n parts.push(w.data, b.data);\n }\n if (layers.length === 0) bad(\"no layers.0.weight tensor\");\n layers[layers.length - 1]!.activation = \"linear\";\n const weights = new Float32Array(parts.reduce((s, p) => s + p.length, 0));\n let at = 0;\n for (const p of parts) {\n weights.set(p, at);\n at += p.length;\n }\n // K6.Nb: an `extra: 'g'` network has one input after the 3 L + 2 features (the container has no attributes: an option)\n const levels = o.levels ?? (layers[0]!.inputs - 2 - vdbFrameMlpExtraInputs(o)) / 3;\n return { name: o.name ?? \"tza\", levels, layers, output: o.output ?? \"exp\", weights, ...(o.extra ? { extra: o.extra } : {}) };\n}\n"]}
|