-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
275 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
import {Tensor} from '../../../tensor'; | ||
import {ShapeUtil} from '../../../util'; | ||
import {WebGpuInferenceHandler} from '../inference-handler'; | ||
|
||
export const reshape = (handler: WebGpuInferenceHandler, inputs: Tensor[]): Tensor[] => { | ||
const reshapedDims = ShapeUtil.calculateReshapedDims(inputs[0].dims, inputs[1].integerData); | ||
return [handler.reshape(inputs[0], reshapedDims)]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
import {Graph} from '../../../graph'; | ||
import {OperatorInitialization} from '../../../operators'; | ||
import {Tensor} from '../../../tensor'; | ||
import {ShapeUtil} from '../../../util'; | ||
import {WebGpuInferenceHandler} from '../inference-handler'; | ||
|
||
export const unsqueeze = (inferenceHandler: WebGpuInferenceHandler, inputs: Tensor[], axes: number[]): Tensor[] => { | ||
validateInputs(inputs); | ||
const outputShape = ShapeUtil.unsqueezeShape(inputs[0].dims, axes); | ||
const output = inferenceHandler.reshape(inputs[0], outputShape); | ||
return [output]; | ||
}; | ||
|
||
export const unsqueezeV13 = (inferenceHandler: WebGpuInferenceHandler, inputs: Tensor[]): Tensor[] => { | ||
validateInputsV13(inputs); | ||
return unsqueeze(inferenceHandler, [inputs[0]], Array.from(inputs[1].integerData)); | ||
}; | ||
|
||
export const parseUnsqueezeAttributes: OperatorInitialization<number[]> = (node: Graph.Node): number[] => | ||
node.attributes.getInts('axes'); | ||
|
||
const validateInputs = (inputs: Tensor[]): void => { | ||
if (!inputs || inputs.length !== 1) { | ||
throw new Error('Unsqueeze requires 1 input.'); | ||
} | ||
|
||
if (inputs[0].type === 'string') { | ||
throw new Error('invalid input tensor types.'); | ||
} | ||
}; | ||
|
||
const validateInputsV13 = (inputs: Tensor[]): void => { | ||
if (!inputs || inputs.length !== 2) { | ||
throw new Error('Unsqueeze requires 2 inputs.'); | ||
} | ||
|
||
if (inputs[1].type !== 'int32') { | ||
throw new Error('Invalid input type.'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.