architecture/network/onnx/export/layers

Decision router for ONNX layer emission.

This boundary does not build tensors directly. Its job is to inspect one export layer and choose the smallest valid emission strategy: Conv when an explicit mapping is present, recurrent single-step when the layer owns self-connections, compact dense export when activations are homogeneous, or per-neuron decomposition when activations differ.

flowchart TD
  Start[Layer inputs] --> Conv{Conv mapping for layer?}
  Conv -->|Yes| ConvEmit[Emit Conv path]
  Conv -->|No| Recurrent{Self-recurrent hidden layer?}
  Recurrent -->|Yes| RecEmit[Emit recurrent single-step path]
  Recurrent -->|No| Mixed{Mixed activations?}
  Mixed -->|No| DenseEmit[Emit dense Gemm + activation]
  Mixed -->|Yes| PerNeuron[Emit per-neuron Gemm + activation + Concat]

architecture/network/onnx/export/layers/network.onnx.export-conv.utils.ts

appendConvBiasInitializer

appendConvBiasInitializer(
  context: OnnxConvEmissionContext,
  convTensorNames: OnnxConvTensorNames,
  biasValues: number[],
): void

Append Conv bias initializer.

Parameters:

Returns: Nothing.

appendConvExportMetadata

appendConvExportMetadata(
  context: OnnxConvEmissionContext,
): void

Append Conv export metadata entries.

Parameters:

Returns: Nothing.

appendConvWeightInitializer

appendConvWeightInitializer(
  context: OnnxConvEmissionContext,
  convTensorNames: OnnxConvTensorNames,
  weightValues: number[],
): void

Append Conv weight initializer.

Parameters:

Returns: Nothing.

buildKernelCoordinatesForInputChannel

buildKernelCoordinatesForInputChannel(
  convSpec: Conv2DMapping,
  inputChannelIndex: number,
): OnnxConvKernelCoordinate[]

Build kernel coordinates for one input channel.

Parameters:

Returns: Kernel coordinates for the input channel.

calculateSpatialOutputSize

calculateSpatialOutputSize(
  inputSize: number,
  kernelSize: number,
  strideSize: number,
  leadingPadding: number,
  trailingPadding: number,
): number

Calculate one spatial output size from kernel, stride, and padding metadata.

Parameters:

Returns: Derived spatial output size.

collectConvBiasValues

collectConvBiasValues(
  representativeNeuronInternals: NodeInternals[],
): number[]

Collect Conv bias values from representative neurons.

Parameters:

Returns: Bias values.

collectConvParameters

collectConvParameters(
  context: OnnxConvEmissionContext,
): OnnxConvParameters

Collect flattened Conv weights and biases.

Parameters:

Returns: Conv initializer parameters.

collectConvWeightValues

collectConvWeightValues(
  context: OnnxConvEmissionContext,
  representativeNeuronInternals: NodeInternals[],
): number[]

Collect flattened Conv weight values.

Parameters:

Returns: Flattened Conv weights.

collectRepresentativeNeuronInternals

collectRepresentativeNeuronInternals(
  context: OnnxConvEmissionContext,
  outputChannelIndices: number[],
): NodeInternals[]

Collect representative neuron internals for each output channel.

Parameters:

Returns: Representative internals.

createConvPaddingValues

createConvPaddingValues(
  convSpec: Conv2DMapping,
): number[]

Create ONNX pads values for Conv node.

Parameters:

Returns: Padding values in ONNX order.

createConvTensorNames

createConvTensorNames(
  layerIndex: number,
): OnnxConvTensorNames

Create deterministic Conv parameter tensor names.

Parameters:

Returns: Conv tensor names.

createKernelCoordinates

createKernelCoordinates(
  convSpec: Conv2DMapping,
): OnnxConvKernelCoordinate[]

Create all Conv kernel coordinates across input channels.

Parameters:

Returns: Kernel coordinates.

createOutputChannelIndices

createOutputChannelIndices(
  convSpec: Conv2DMapping,
): number[]

Create output channel index list.

Parameters:

Returns: Output channel indices.

derivePooledTensorWidth

derivePooledTensorWidth(
  derivedPooledInputShape: { inputChannels: number; inputHeight: number; inputWidth: number; },
): number

Fold one derived pooled input shape to its flattened width.

Parameters:

Returns: Flattened pooled tensor width.

emitActivationNode

emitActivationNode(
  context: OnnxConvEmissionContext,
  convOutputName: string,
  activationOutputName: string,
): void

Emit activation node for Conv output.

Parameters:

Returns: Nothing.

emitConvAndActivationGraph

emitConvAndActivationGraph(
  context: OnnxConvEmissionContext,
  convTensorNames: OnnxConvTensorNames,
): string

Emit Conv and activation nodes and return activation output name.

Parameters:

Returns: Activation output name.

emitConvNode

emitConvNode(
  context: OnnxConvEmissionContext,
  convTensorNames: OnnxConvTensorNames,
  convOutputName: string,
  convInputName: string,
): void

Emit ONNX Conv node.

Parameters:

Returns: Nothing.

emitConvParameterInitializers

emitConvParameterInitializers(
  context: OnnxConvEmissionContext,
  convParameters: OnnxConvParameters,
): OnnxConvTensorNames

Emit Conv parameter initializers and return tensor names.

Parameters:

Returns: Conv tensor names.

emitFlattenReshapeBridge

emitFlattenReshapeBridge(
  context: OnnxConvEmissionContext,
  flattenedPoolingShape: { inputChannels: number; inputHeight: number; inputWidth: number; },
): string

Emit a reshape bridge that restores [N,C,H,W] input rank after flatten.

Parameters:

Returns: Reshape output tensor name.

emitOptionalPoolingAndFlattenForConv

emitOptionalPoolingAndFlattenForConv(
  context: OnnxConvEmissionContext,
  activationOutputName: string,
): string

Emit optional pooling and flatten nodes for Conv output.

Parameters:

Returns: Final output tensor name.

getActualPreviousTensorWidth

getActualPreviousTensorWidth(
  context: OnnxConvEmissionContext,
): number

Resolve the actual graph-input width seen by this Conv layer.

Parameters:

Returns: Previous tensor width after optional pooling.

getExpectedCurrentWidth

getExpectedCurrentWidth(
  convSpec: Conv2DMapping,
): number

Get expected current-layer width for Conv mapping.

Parameters:

Returns: Expected current-layer width.

getExpectedPreviousWidth

getExpectedPreviousWidth(
  convSpec: Conv2DMapping,
): number

Get expected previous-layer width for Conv mapping.

Parameters:

Returns: Expected previous-layer width.

isConvShapeCompatible

isConvShapeCompatible(
  context: OnnxConvEmissionContext,
): boolean

Determine whether declared Conv dimensions match layer widths.

Parameters:

Returns: Whether Conv dimensions match the network layers.

logConvShapeMismatch

logConvShapeMismatch(
  context: OnnxConvEmissionContext,
): void

Log Conv mapping shape mismatch warning.

Parameters:

Returns: Nothing.

resolveActivationPayload

resolveActivationPayload(
  context: OnnxConvEmissionContext,
): { operation: string; attributes?: { name: string; type?: string | undefined; f?: number | undefined; i?: number | undefined; s?: string | undefined; }[] | undefined; }

Resolve activation operator for Conv output.

Parameters:

Returns: Activation operator name.

resolveConvInputName

resolveConvInputName(
  context: OnnxConvEmissionContext,
): string

Resolve the tensor name that should feed the Conv node.

Parameters:

Returns: Previous output name, or a reshape bridge output for the narrow flatten subset.

resolveConvSourceLayout

resolveConvSourceLayout(
  context: OnnxConvEmissionContext,
  convSpec: Conv2DMapping,
): { channelStride: number; sourceHeight: number; sourceWidth: number; }

Resolve the source layout used when this Conv layer consumes a pooled predecessor.

Parameters:

Returns: Source layout dimensions used for dense-node indexing.

resolveConvSourceNode

resolveConvSourceNode(
  context: OnnxConvEmissionContext,
  kernelCoordinate: OnnxConvKernelCoordinate,
): default

Resolve source node referenced by one kernel coordinate.

Parameters:

Returns: Source node.

resolveDerivedPooledInputShape

resolveDerivedPooledInputShape(
  context: OnnxConvEmissionContext,
): { inputChannels: number; inputHeight: number; inputWidth: number; } | undefined

Resolve pooled input geometry from the immediately previous Conv + Pool metadata.

Parameters:

Returns: Derived pooled shape, or undefined when the metadata is unusable.

resolveInboundWeightOrZero

resolveInboundWeightOrZero(
  representativeNeuronInternal: NodeInternals,
  sourceNode: default,
): number

Resolve inbound weight or zero when missing.

Parameters:

Returns: Inbound weight value.

resolveInputFeatureIndex

resolveInputFeatureIndex(
  context: OnnxConvEmissionContext,
  convSpec: Conv2DMapping,
  kernelCoordinate: OnnxConvKernelCoordinate,
): number

Resolve flattened input feature index for one kernel coordinate.

Parameters:

Returns: Flattened input feature index.

resolvePoolingSpec

resolvePoolingSpec(
  context: OnnxConvEmissionContext,
): Pool2DMapping | undefined

Resolve pooling spec for current layer.

Parameters:

Returns: Pool mapping spec, if configured.

resolveRepresentativeNeuronIndex

resolveRepresentativeNeuronIndex(
  convSpec: Conv2DMapping,
  outputChannelIndex: number,
): number

Resolve representative neuron index for one output channel.

Parameters:

Returns: Representative neuron index.

resolveRepresentativeNeuronInternal

resolveRepresentativeNeuronInternal(
  context: OnnxConvEmissionContext,
  outputChannelIndex: number,
): NodeInternals

Resolve representative neuron internals for one output channel.

Parameters:

Returns: Representative neuron internals.

resolveSupportedFlattenedPoolingShape

resolveSupportedFlattenedPoolingShape(
  context: OnnxConvEmissionContext,
): { inputChannels: number; inputHeight: number; inputWidth: number; } | undefined

Resolve the narrow supported flatten-after-pool bridge shape, when present.

Parameters:

Returns: Supported flattened pooled shape for the later Conv bridge.

resolveUpstreamPoolingSpec

resolveUpstreamPoolingSpec(
  options: OnnxExportOptions,
  layerIndex: number,
): Pool2DMapping | undefined

Resolve pooling configured immediately after the previous layer.

Parameters:

Returns: Upstream pooling spec when present.

resolveWeightForCoordinate

resolveWeightForCoordinate(
  context: OnnxConvEmissionContext,
  representativeNeuronInternal: NodeInternals,
  kernelCoordinate: OnnxConvKernelCoordinate,
): number

Resolve weight for one kernel coordinate.

Parameters:

Returns: Weight value or zero when connection is missing.

tryEmitConvLayer

tryEmitConvLayer(
  params: OnnxConvEmissionParams,
): string | undefined

Try to emit one layer as a Conv-shaped ONNX segment when the caller supplied an explicit Conv mapping for that export layer.

This path reconstructs kernels from a fully connected layer by assuming the declared Conv geometry really matches the flattened previous and current layer widths. When that contract does not hold, the exporter logs the mismatch and returns undefined so the broader layer router can fall back or fail with a more appropriate message.

In addition to the Conv and activation nodes, this helper also owns optional pooling, flatten-after-pooling, and the metadata hints required for import to rebuild the same semantic interpretation.

Parameters:

Returns: New output tensor name when handled, otherwise undefined.

Example:

const outputName = tryEmitConvLayer({
  model,
  options: {
    conv2dMappings: [{ layerIndex: 1, inHeight: 28, inWidth: 28, inChannels: 1, outChannels: 8, kernelSize: 3 }],
  },
  layerIndex: 1,
  previousOutputName: 'input',
  previousLayerNodes,
  currentLayerNodes,
});

validateConvShapeOrWarn

validateConvShapeOrWarn(
  context: OnnxConvEmissionContext,
): boolean

Validate Conv dimensions and log mismatch details when invalid.

Parameters:

Returns: Whether Conv shape is compatible.

architecture/network/onnx/export/layers/network.onnx.export-dense.utils.ts

appendDenseBiasInitializer

appendDenseBiasInitializer(
  layerContext: DenseLayerContext,
  biasTensorName: string,
  biasVector: number[],
): void

Append dense bias initializer.

Parameters:

Returns: Nothing.

appendDenseNodes

appendDenseNodes(
  model: OnnxModel,
  orderedNodes: DenseOrderedNodePayload[],
): void

Append ordered dense nodes to the model graph.

Parameters:

Returns: Nothing.

appendDenseWeightInitializer

appendDenseWeightInitializer(
  layerContext: DenseLayerContext,
  weightTensorName: string,
  weightMatrixValues: number[],
): void

Append dense weight initializer.

Parameters:

Returns: Nothing.

buildSingleNeuronWeightRow

buildSingleNeuronWeightRow(
  targetNodeInternal: NodeInternals,
  previousLayerNodes: default[],
): number[]

Build one neuron's incoming weight row against previous layer.

Parameters:

Returns: Weight row values.

collectDenseInitializerValues

collectDenseInitializerValues(
  layerContext: DenseLayerContext,
): DenseInitializerValues

Collect dense weight matrix and bias vector values.

Parameters:

Returns: Dense initializer values.

createActivationNode

createActivationNode(
  denseActivationContext: DenseActivationContext,
): DenseActivationNodePayload

Create dense activation node definition.

Parameters:

Returns: ONNX activation node payload.

createDefaultGemmAttributes

createDefaultGemmAttributes(): { name: string; type: string; f?: number | undefined; i?: number | undefined; }[]

Build default Gemm attributes for ONNX export.

Returns: Default Gemm attribute list.

createDenseTensorNames

createDenseTensorNames(
  layerIndex: number,
): DenseTensorNames

Build dense tensor names for initializer emission.

Parameters:

Returns: Dense tensor names.

createGemmNode

createGemmNode(
  denseActivationContext: DenseActivationContext,
): DenseGemmNodePayload

Create dense Gemm node definition.

Parameters:

Returns: ONNX Gemm node payload.

createSharedActivationNodePayload

createSharedActivationNodePayload(
  params: SharedActivationNodeBuildParams,
): DenseActivationNodePayload

Build a shared activation node payload.

Parameters:

Returns: Activation node payload.

createSharedGemmNodePayload

createSharedGemmNodePayload(
  params: SharedGemmNodeBuildParams,
): DenseGemmNodePayload

Build a shared Gemm node payload.

Parameters:

Returns: Gemm node payload.

emitDenseActivationSubgraph

emitDenseActivationSubgraph(
  model: OnnxModel,
  denseActivationContext: DenseActivationContext,
): void

Emit Gemm and activation nodes using requested ordering.

Parameters:

Returns: Nothing.

emitDenseInitializers

emitDenseInitializers(
  layerContext: DenseLayerContext,
): DenseTensorNames

Emit dense initializers and return tensor names.

Parameters:

Returns: Tensor names.

emitDenseLayer

emitDenseLayer(
  params: DenseLayerParams,
): string

Emit the compact dense export path for a layer whose neurons all share the same activation.

This is the cheapest ONNX shape the exporter can produce for a standard MLP layer: one Gemm node for the affine transform and one activation node for the whole layer. The same helper also preserves the library's legacy node-ordering compatibility mode when older snapshots need deterministic graph ordering.

Parameters:

Returns: Output tensor name.

Example:

const outputName = emitDenseLayer({
  model,
  layerIndex: 2,
  previousOutputName: 'Layer_1',
  previousLayerNodes,
  currentLayerNodes,
  options: {},
  legacyNodeOrdering: false,
});

emitOptionalLayerOutput

emitOptionalLayerOutput(
  params: OptionalLayerOutputParams,
): string

Emit optional pooling and flatten output fold.

Parameters:

Returns: Output tensor name.

emitPerNeuronLayer

emitPerNeuronLayer(
  params: PerNeuronLayerParams,
): string

Emit the fallback dense-family representation for a layer whose target neurons use different activations.

Instead of pretending the layer is homogeneous, this path exports one tiny Gemm-plus-activation subgraph per neuron and then concatenates the results. The graph is larger, but it preserves mixed activation behavior that a single layer-wide activation node cannot express.

Parameters:

Returns: Output tensor name.

Example:

const outputName = emitPerNeuronLayer({
  model,
  layerIndex: 2,
  previousOutputName: 'Layer_1',
  previousLayerNodes,
  currentLayerNodes,
  options: { allowMixedActivations: true },
});

emitPerNeuronSubgraph

emitPerNeuronSubgraph(
  perNeuronSubgraphContext: PerNeuronSubgraphContext,
): string

Emit per-neuron Gemm + activation subgraph.

Parameters:

Returns: Per-neuron activation output name.

emitResidualAddLayer

emitResidualAddLayer(
  params: ResidualAddLayerParams,
): string

Emit a one-hop residual-add dense layer.

This subset preserves one skipped source layer by splitting the target layer into two affine branches: the ordinary adjacent-layer Gemm keeps the original bias term, and the skipped source layer emits a bias-free branch whose output is summed before the layer activation.

Parameters:

Returns: Output tensor name.

resolveDenseNodeOrder

resolveDenseNodeOrder(
  gemmNode: DenseGemmNodePayload,
  activationNode: DenseActivationNodePayload,
  legacyNodeOrdering: boolean,
): DenseOrderedNodePayload[]

Resolve dense node order for legacy and current exports.

Parameters:

Returns: Ordered node list.

resolveSingleNeuronInboundWeight

resolveSingleNeuronInboundWeight(
  targetNodeInternal: NodeInternals,
  sourceNode: default,
): number

Resolve one inbound connection weight for a source node.

Parameters:

Returns: Inbound weight or zero when missing.

architecture/network/onnx/export/layers/network.onnx.export-recurrent.utils.ts

buildDefaultGemmAttributes

buildDefaultGemmAttributes(): { name: string; type: string; f?: number | undefined; i?: number | undefined; }[]

Build the shared attribute list for ONNX Gemm node payloads.

Returns: Gemm attribute payload list.

buildInputBranchGemmEmissionContext

buildInputBranchGemmEmissionContext(
  context: RecurrentLayerEmissionContext,
  initializerNames: RecurrentInitializerNames,
  graphNames: RecurrentGraphNames,
): RecurrentGemmEmissionContext

Build Gemm emission context for the feed-forward branch.

Parameters:

Returns: Gemm emission context.

buildRecurrentBranchGemmEmissionContext

buildRecurrentBranchGemmEmissionContext(
  context: RecurrentLayerEmissionContext,
  initializerNames: RecurrentInitializerNames,
  graphNames: RecurrentGraphNames,
): RecurrentGemmEmissionContext

Build Gemm emission context for the recurrent hidden-state branch.

Parameters:

Returns: Gemm emission context.

buildRecurrentGraphNames

buildRecurrentGraphNames(
  context: RecurrentLayerEmissionContext,
): RecurrentGraphNames

Build deterministic graph names for recurrent-node emission.

Parameters:

Returns: Graph-name group for branch and activation nodes.

buildRecurrentInitializerNames

buildRecurrentInitializerNames(
  context: RecurrentLayerEmissionContext,
): RecurrentInitializerNames

Build deterministic tensor names for recurrent initializer emission.

Parameters:

Returns: Tensor-name group for initializer emission.

buildRecurrentLayerEmissionContext

buildRecurrentLayerEmissionContext(
  params: RecurrentLayerEmissionParams,
): RecurrentLayerEmissionContext

Build derived recurrent-layer context from input params.

Parameters:

Returns: Derived context with cached dimensions and layer slot.

collectRecurrentInitializerValues

collectRecurrentInitializerValues(
  context: RecurrentLayerEmissionContext,
): RecurrentInitializerValues

Collect recurrent initializer vectors for one layer.

Parameters:

Returns: Dense and recurrent initializer vectors.

emitRecurrentActivationNode

emitRecurrentActivationNode(
  context: RecurrentActivationEmissionContext,
): void

Emit activation node for recurrent branch sum output.

Parameters:

Returns: Nothing.

emitRecurrentAddNode

emitRecurrentAddNode(
  model: OnnxModel,
  graphNames: RecurrentGraphNames,
): void

Emit Add node that fuses feed-forward and recurrent branch outputs.

Parameters:

Returns: Nothing.

emitRecurrentGemmNode

emitRecurrentGemmNode(
  context: RecurrentGemmEmissionContext,
): void

Emit one recurrent Gemm node with shared ONNX attributes.

Parameters:

Returns: Nothing.

emitRecurrentInitializers

emitRecurrentInitializers(
  context: RecurrentInitializerEmissionContext,
): void

Emit dense and recurrent initializer tensors.

Parameters:

Returns: Nothing.

emitRecurrentLayer

emitRecurrentLayer(
  params: RecurrentLayerEmissionParams,
): string

Emit the constrained recurrent single-step export path for one hidden layer.

This boundary models recurrence with two parallel Gemm branches: one for the feed-forward input and one for the previous hidden state. The recurrent branch uses a diagonal matrix derived from self-connections only, which keeps the exported shape simple and matches the importer's current reconstruction contract.

Hidden-state inputs are named hidden_prev for the first recurrent layer and hidden_prev_l{n} for later recurrent layers. Mixed activations are not supported on this path because the single activation node is applied after the input and recurrent branches are summed.

Parameters:

Returns: Output tensor name.

Example:

const outputName = emitRecurrentLayer({
  model,
  layerIndex: 1,
  previousOutputName: 'input',
  previousLayerNodes,
  currentLayerNodes,
});

readNodeInternals

readNodeInternals(
  node: default,
): NodeInternals

Normalize runtime node shape to recurrent-export internals contract.

Parameters:

Returns: Node internals used by ONNX emission helpers.

resolvePreviousHiddenInputName

resolvePreviousHiddenInputName(
  layerIndex: number,
): string

Resolve recurrent branch hidden-state input for one layer.

Parameters:

Returns: Hidden-state tensor input name.

architecture/network/onnx/export/layers/network.onnx.export-layer-graph.utils.ts

collectActivationNames

collectActivationNames(
  currentLayerNodes: default[],
): Set<string | undefined>

Collect activation names for current-layer nodes.

Parameters:

Returns: Activation name set.

createLayerActivationContext

createLayerActivationContext(
  traversalContext: LayerTraversalContext,
): LayerActivationContext

Build activation analysis context for non-convolution branches.

Parameters:

Returns: Activation analysis context.

createLayerTraversalContext

createLayerTraversalContext(
  input: LayerBuildContext,
): LayerTraversalContext

Build a compact traversal context with adjacent layers.

Parameters:

Returns: Traversal context.

createRecurrentDecisionContext

createRecurrentDecisionContext(
  traversalContext: LayerTraversalContext,
): LayerRecurrentDecisionContext

Build recurrent decision context with no extra parameters.

Parameters:

Returns: Recurrent decision context.

detectMixedActivations

detectMixedActivations(
  currentLayerNodes: default[],
  options: OnnxExportOptions,
): boolean

Determine whether a layer has mixed activation functions.

Parameters:

Returns: Whether mixed activations are present and enabled.

emitDenseBranch

emitDenseBranch(
  traversalContext: LayerTraversalContext,
): string

Emit standard dense layer branch.

Parameters:

Returns: Dense output tensor name.

emitDenseFamilyBranch

emitDenseFamilyBranch(
  traversalContext: LayerTraversalContext,
  activationContext: LayerActivationContext,
): string

Emit dense or per-neuron layer branch from activation analysis.

Parameters:

Returns: Output tensor name.

emitLayerGraph

emitLayerGraph(
  context: LayerBuildContext,
): string

Emit one export layer graph segment by routing the layer through the correct ONNX emission strategy.

Dispatch order matters:

Important invariants:

Parameters:

Returns: Output tensor name produced by this layer.

Example:

const outputName = emitLayerGraph({
  model,
  layers,
  layerIndex: 2,
  previousOutputName: 'Layer_1',
  options: { allowMixedActivations: true },
  recurrentLayerIndices: [],
  batchDimension: false,
  legacyNodeOrdering: false,
});

emitNonConvolutionBranch

emitNonConvolutionBranch(
  traversalContext: LayerTraversalContext,
  activationContext: LayerActivationContext,
): string

Emit recurrent or dense/per-neuron branch output.

Parameters:

Returns: Output tensor name.

emitPerNeuronBranch

emitPerNeuronBranch(
  traversalContext: LayerTraversalContext,
): string

Emit per-neuron decomposition branch for mixed activations.

Parameters:

Returns: Per-neuron output tensor name.

emitRecurrentBranch

emitRecurrentBranch(
  traversalContext: LayerTraversalContext,
  activationContext: LayerActivationContext,
): string

Emit recurrent layer branch with mixed-activation validation.

Parameters:

Returns: Recurrent output tensor name.

ensureRecurrentSupportsActivations

ensureRecurrentSupportsActivations(
  layerIndex: number,
  activationContext: LayerActivationContext,
): void

Ensure recurrent layers do not use unsupported mixed activations.

Parameters:

Returns: Nothing.

resolveActivationName

resolveActivationName(
  node: default,
): string | undefined

Resolve the activation name for one node.

Parameters:

Returns: Activation name when present.

shouldEmitRecurrentBranch

shouldEmitRecurrentBranch(
  decisionContext: LayerRecurrentDecisionContext,
): boolean

Determine whether recurrent single-step emission applies.

Parameters:

Returns: Whether recurrent branch should be emitted.

tryEmitConvolutionBranch

tryEmitConvolutionBranch(
  traversalContext: LayerTraversalContext,
): string | undefined

Attempt convolution emission and return produced output when mapped.

Parameters:

Returns: Convolution output name when emitted; otherwise null.

tryEmitExplicitConcatMergeBranch

tryEmitExplicitConcatMergeBranch(
  traversalContext: LayerTraversalContext,
): string | undefined

Attempt the narrow explicit concat subset before residual fallback.

Parameters:

Returns: Concat-merge output tensor name when emitted; otherwise undefined.

tryEmitResidualAddBranch

tryEmitResidualAddBranch(
  traversalContext: LayerTraversalContext,
): string | undefined

Attempt the narrow one-hop residual-add subset before falling back.

Parameters:

Returns: Residual-add output tensor name when emitted; otherwise null.

architecture/network/onnx/export/layers/network.onnx.export-layer-common.utils.ts

appendIndexedMetadata

appendIndexedMetadata(
  model: OnnxModel,
  key: string,
  layerIndex: number,
): void

Append a layer index to a JSON-array metadata field on the ONNX model.

Parameters:

Returns: Nothing.

appendMetadataSpec

appendMetadataSpec(
  model: OnnxModel,
  key: string,
  spec: Conv2DMapping | Pool2DMapping,
): void

Append a structured metadata object to a JSON-array metadata field safely.

Parameters:

Returns: Nothing.

appendPoolingMetadata

appendPoolingMetadata(
  context: PoolingEmissionContext,
): void

Append pooling-layer metadata after a pooling node is emitted.

Stores both the layer index list and the serialized pooling specification.

Parameters:

Returns: Nothing.

asNodeInternals

asNodeInternals(
  node: default,
): NodeInternals

Normalize a public node instance to the internal shape used by ONNX export helpers.

This cast is intentionally localized so collection helpers stay strongly typed without repeating assertions at each call site.

Parameters:

Returns: Internal runtime-facing node representation.

buildDenseWeightsAndBiases

buildDenseWeightsAndBiases(
  previousLayerNodes: default[],
  currentLayerNodes: default[],
): DenseWeightBuildResult

Build the shared dense initializer payload used by both compact dense export and recurrent single-step export.

The returned weight matrix is flattened in row-major order by destination neuron. Missing edges are encoded as zeroes so partially connected layers can still be represented in a deterministic rectangular tensor layout. Biases are collected in the same destination-neuron order.

Parameters:

Returns: Flattened row-major weight matrix and bias vector.

Example:

const { weightMatrixValues, biasVector } = buildDenseWeightsAndBiases(
  previousLayerNodes,
  currentLayerNodes,
);

buildDiagonalRecurrentWeights

buildDiagonalRecurrentWeights(
  currentLayerNodes: default[],
): number[]

Build a diagonal recurrent weight matrix from per-node self-connections.

Only diagonal entries are populated because this helper encodes recurrent carry as one-step self-feedback for each destination neuron. Off-diagonal entries are emitted as zero to keep the matrix rectangular and deterministic.

Parameters:

Returns: Flattened row-major recurrent matrix.

buildIndexedMetadataProperty

buildIndexedMetadataProperty(
  key: string,
  layerIndex: number,
): OnnxMetadataProperty

Build a metadata property whose value is a JSON array of layer indexes.

Parameters:

Returns: Metadata property.

buildSpecMetadataProperty

buildSpecMetadataProperty(
  key: string,
  spec: Conv2DMapping | Pool2DMapping,
): OnnxMetadataProperty

Build a metadata property whose value is a JSON array of mapping specs.

Parameters:

Returns: Metadata property.

collectDenseRows

collectDenseRows(
  context: DenseWeightBuildContext,
): DenseWeightRow[]

Collect dense rows for each target node in current layer.

Parameters:

Returns: Dense rows containing per-target weights and bias.

collectDenseRowWeights

collectDenseRowWeights(
  context: DenseWeightRowCollectionContext,
): number[]

Collect one destination neuron's inbound weights in source-node order.

Missing inbound edges are encoded as zeros to preserve a full rectangular matrix even for sparse connectivity.

Parameters:

Returns: Row weights in source-node order.

collectPoolingAttributes

collectPoolingAttributes(
  poolSpec: Pool2DMapping,
): PoolingAttributes

Collect ONNX pooling attribute arrays from one pooling spec.

Optional pad fields default to zero so exported nodes always carry explicit 2D padding metadata.

Parameters:

Returns: Pooling attributes for ONNX node payload.

collectRecurrentRow

collectRecurrentRow(
  context: RecurrentRowCollectionContext,
): number[]

Collect one recurrent matrix row for a destination neuron.

Diagonal entries read the neuron's self-connection weight; all other coordinates remain zero.

Parameters:

Returns: Recurrent row values.

collectRecurrentRows

collectRecurrentRows(
  context: DiagonalRecurrentBuildContext,
): number[][]

Collect all recurrent matrix rows for the current layer.

Each row corresponds to one destination neuron and is assembled with diagonal-only recurrent semantics.

Parameters:

Returns: Recurrent row collection.

emitOptionalFlattenAfterPooling

emitOptionalFlattenAfterPooling(
  context: FlattenAfterPoolingContext,
): string

Conditionally emit a Flatten node after pooling.

When disabled, the pooled tensor name is returned unchanged.

Parameters:

Returns: Output tensor name after optional flatten.

emitOptionalPoolingAndFlatten

emitOptionalPoolingAndFlatten(
  params: OptionalPoolingAndFlattenParams,
): string

Emit optional pooling and flatten nodes after a layer output.

Parameters:

Returns: Final output tensor name after optional pooling/flatten.

emitPoolingNode

emitPoolingNode(
  context: PoolingEmissionContext,
): string

Emit one pooling node and return its output tensor name.

Parameters:

Returns: Pooling output tensor name.

ensureMetadataRegistry

ensureMetadataRegistry(
  model: OnnxModel,
): OnnxMetadataProperty[]

Ensure the ONNX model metadata registry exists and return it.

The returned array is mutable and shared with model.metadata_props.

Parameters:

Returns: Mutable metadata registry.

findMetadataProperty

findMetadataProperty(
  metadataRegistry: OnnxMetadataProperty[],
  key: string,
): OnnxMetadataProperty | undefined

Find a metadata property by key.

Parameters:

Returns: Matching metadata property if present.

foldDenseRowsToInitializers

foldDenseRowsToInitializers(
  denseRows: DenseWeightRow[],
): DenseWeightBuildResult

Fold per-target dense rows into ONNX initializer buffers.

The fold preserves row-major order by destination neuron so downstream tensor shapes remain stable across exports of the same topology.

Parameters:

Returns: Flattened dense initializer result.

parseMetadataArray

parseMetadataArray(
  metadataValue: string,
): ItemType[] | undefined

Parse a metadata JSON array value safely.

Returns undefined when parsing fails or when the payload is not an array.

Parameters:

Returns: Parsed array when valid, otherwise undefined.

resolveDiagonalRecurrentWeight

resolveDiagonalRecurrentWeight(
  context: RecurrentRowCollectionContext,
  columnIndex: number,
): number

Resolve recurrent weight value for one matrix coordinate.

Parameters:

Returns: Recurrent weight for diagonal entries, otherwise zero.

resolveInboundWeight

resolveInboundWeight(
  targetNodeInternal: NodeInternals,
  sourceNode: default,
): number

Resolve source-to-target inbound connection weight.

Parameters:

Returns: Inbound weight or zero for disconnected edges.

serializeIndexedMetadataValue

serializeIndexedMetadataValue(
  currentValue: string,
  layerIndex: number,
): string

Serialize index metadata after appending one unique index.

Parameters:

Returns: Serialized JSON value.

serializeSpecMetadataValue

serializeSpecMetadataValue(
  currentValue: string,
  spec: Conv2DMapping | Pool2DMapping,
): string

Serialize spec metadata after appending one spec object.

Parameters:

Returns: Serialized JSON value.

toPoolingEmissionContext

toPoolingEmissionContext(
  params: OptionalPoolingAndFlattenParams,
): PoolingEmissionContext

Resolve a normalized pooling emission context from optional export parameters.

This helper centralizes optional-to-required conversion before node emission.

Parameters:

Returns: Pooling emission context.

Generated from source JSDoc • GitHub