Skip to content

Commit

Permalink
Merge pull request webmachinelearning#671 from a-sully/reshape-nulls
Browse files Browse the repository at this point in the history
Remove uses of null as parameter to reshape() in code samples
  • Loading branch information
huningxin authored May 3, 2024
2 parents f849201 + 782afc7 commit 4165154
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -1558,7 +1558,7 @@ partial interface MLGraphBuilder {
The behavior of this operation when the input tensor is 4-D of the {{MLInputOperandLayout/"nchw"}} layout and the activation is {{MLGraphBuilder/relu()}} can be [EMULATED]
</summary>
<pre highlight="js">
const shape = [1,null,1,1];
const shape = [1, input.shape()[options.axis], 1, 1];
return builder.relu(
builder.add(
builder.mul(
Expand Down Expand Up @@ -3159,15 +3159,15 @@ partial interface MLGraphBuilder {
currentHidden[dir], hiddenSize, { bias: currentBias[dir],
recurrentBias: currentRecurrentBias[dir], resetAfter: options.resetAfter,
layout: options.layout, activations: options.activations }),
[1, null, hiddenSize]);
[1, batchSize, hiddenSize]);

currentOutput = (currentOutput ? builder.concat([currentOutput, result], 0) : result);
}

hiddenState = currentOutput;

if (options.returnSequence) {
currentOutput = builder.reshape(currentOutput, [1, numDirections, null, hiddenSize]);
currentOutput = builder.reshape(currentOutput, [1, numDirections, batchSize, hiddenSize]);
sequence = (sequence ? builder.concat([sequence, currentOutput], 0) : currentOutput);
}
}
Expand Down Expand Up @@ -3619,7 +3619,7 @@ partial interface MLGraphBuilder {

// The scale and bias values are applied per input feature
// e.g. axis 1 of the input tensor.
const shape = [1,null,1,1];
const shape = [1, input.shape()[1], 1, 1];
return builder.add(
builder.mul(
builder.reshape(options.scale, shape),
Expand Down Expand Up @@ -4115,8 +4115,8 @@ partial interface MLGraphBuilder {
recurrentBias: currentRecurrentBias[dir], peepholeWeight: currentPeepholeWeight[dir],
layout: options.layout, activations: options.activations });

let output = builder.reshape(results[0], [1, null, hiddenSize]);
let cell = builder.reshape(results[1], [1, null, hiddenSize]);
let output = builder.reshape(results[0], [1, batchSize, hiddenSize]);
let cell = builder.reshape(results[1], [1, batchSize, hiddenSize]);

nextHidden = (nextHidden ? builder.concat([nextHidden, output], 0) : output);
nextCell = (nextCell ? builder.concat([nextCell, cell], 0) : cell);
Expand All @@ -4126,7 +4126,7 @@ partial interface MLGraphBuilder {
cellState = nextCell;

if (options.returnSequence) {
nextHidden = builder.reshape(nextHidden, [1, numDirections, null, hiddenSize]);
nextHidden = builder.reshape(nextHidden, [1, numDirections, batchSize, hiddenSize]);
sequence = (sequence ? builder.concat([sequence, nextHidden], 0) : nextHidden);
}
}
Expand Down

0 comments on commit 4165154

Please sign in to comment.