This repository has been archived by the owner on Nov 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 127
Scatter ops for webworker #220
Open
Manojbhat09
wants to merge
1
commit into
microsoft:master
Choose a base branch
from
Manojbhat09:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import {Scatter} from '../../../ops/scatter'; | ||
import {Tensor} from '../../../tensor'; | ||
import {CpuInferenceHandler} from '../inference-handler'; | ||
|
||
export class CpuScatter extends Scatter { | ||
run(inferenceHandler: CpuInferenceHandler, inputs: Tensor[]): Tensor[]|Promise<Tensor[]> { | ||
const output = scatter(inputs[0], inputs[1], inputs[2]); | ||
return [output]; | ||
} | ||
} | ||
|
||
export function scatter(data: Tensor, indices: Tensor, updates: Tensor): Tensor { | ||
const datadims = data.dims; | ||
const indicedims = indices.dims; | ||
const updatedims = updates.dims; | ||
const datanew = new Tensor(datadims, data.type); | ||
const Y = datanew.data; | ||
const X = updates.data; | ||
let flatIndex = 0; | ||
let updateFlatIndex = 0; | ||
for (let i = 0; i < datadims[0]; ++i) { | ||
for (let j = 0; j < indicedims[1]; ++j) { | ||
flatIndex = i * datadims[1] + (indices.data[j] as number); | ||
updateFlatIndex = i * updatedims[1] + j; | ||
Y[flatIndex] = X[updateFlatIndex]; | ||
} | ||
} | ||
return new Tensor(datadims, data.type, undefined, undefined, Y); | ||
} |
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,39 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. | ||
|
||
import {Attribute} from '../attribute'; | ||
import {InferenceHandler} from '../backend'; | ||
import {Operator} from '../operators'; | ||
import {Tensor} from '../tensor'; | ||
|
||
export abstract class Scatter implements Operator { | ||
// Inputs are {data_tensor->float32/float64, indices_tensor-> int32, update_data_tensor->float32/float64} | ||
abstract run(inferenceHandler: InferenceHandler, inputs: Tensor[]): Tensor[]|Promise<Tensor[]>; | ||
|
||
initialize(attributes: Attribute): void {} | ||
|
||
checkInputs(inputs: Tensor[]): boolean { | ||
if (!inputs || inputs.length !== 3) { | ||
return false; | ||
} | ||
const tensorRank = inputs[0].dims.length; | ||
if (tensorRank < 1) { | ||
return false; | ||
} | ||
|
||
return this.checkInputTypes(inputs); | ||
} | ||
|
||
protected checkInputTypes(inputs: Tensor[]): boolean { | ||
if (inputs[0].type !== 'float32' && inputs[0].type !== 'float64') { | ||
return false; | ||
} | ||
if (inputs[1].type !== 'int32' && inputs[1].type !== 'int16') { | ||
return false; | ||
} | ||
if (inputs[2].type !== 'float32' && inputs[2].type !== 'float64') { | ||
return false; | ||
} | ||
return true; | ||
} | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this test does not exist. please see https://github.com/onnx/onnx/tree/master/onnx/backend/test/data/node