onnxruntime/js/web/lib/onnxjs/ops/sum.ts
Yulong Wang 4ebc9c3b5e
[JS] onnxruntime-web (#7394)
* add web

* add script and test

* fix lint

* add test/data/ops

* add test/data/node/ to gitignore

* modify scripts

* add onnxjs

* fix tests

* fix test-runner

* fix sourcemap

* fix onnxjs profiling

* update test list

* update README

* resolve comments

* set wasm as default backend

* rename package

* update copyright header

* do not use class "Buffer" in browser context

* revise readme
2021-04-27 00:04:25 -07:00

47 lines
1.2 KiB
TypeScript

// 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 Sum implements Operator {
abstract run(inferenceHandler: InferenceHandler, inputs: Tensor[]): Tensor[]|Promise<Tensor[]>;
initialize(_attributes: Attribute): void {}
checkInputs(inputs: Tensor[]): boolean {
if (!inputs || inputs.length === 0) {
return false;
}
const length = inputs[0].dims.length;
for (let i = 1; i < inputs.length; i++) {
if (length !== inputs[i].dims.length) {
return false;
}
for (let j = 0; j < length; j++) {
if (inputs[0].dims[j] !== inputs[i].dims[j]) {
return false;
}
}
}
return this.checkInputTypes(inputs);
}
protected checkInputTypes(inputs: Tensor[]): boolean {
if (inputs[0].type !== 'float32' && inputs[0].type !== 'float64') {
return false;
}
for (let i = 1; i < inputs.length; i++) {
if (inputs[0].type !== inputs[i].type) {
return false;
}
}
return true;
}
}