@hoff97/tensor-js
Version:
PyTorch like deep learning inferrence library
46 lines • 2.27 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import { OnnxNode } from '../node';
export class SliceNode extends OnnxNode {
constructor(attributes, inputs, outputs, constants, onnxVersion, mode) {
super(attributes, inputs, outputs, constants, onnxVersion, mode);
this.axes = this.getAttributeInts('axes');
this.starts = this.getAttributeInts('starts');
this.ends = this.getAttributeInts('ends');
}
forward(inputs) {
return __awaiter(this, void 0, void 0, function* () {
if (this.onnxVersion < 10) {
if (this.starts === undefined || this.ends === undefined) {
throw new Error('Slice with onnx version < 10 needs starts and ends defined as attributes');
}
const x = inputs[0];
return [x.slice(this.starts, this.ends, this.axes)];
}
else {
const x = inputs[0];
const starts = inputs[1];
const ends = inputs[2];
const axes = inputs[3];
const steps = inputs[4];
const startValues = yield this.toValues(starts);
const endValues = yield this.toValues(ends);
const axesValues = axes !== undefined ? yield this.toValues(axes) : undefined;
const stepValues = steps !== undefined ? yield this.toValues(steps) : undefined;
return [x.slice(startValues, endValues, axesValues, stepValues)];
}
});
}
getType() {
return 'Slice';
}
delete() { }
}
//# sourceMappingURL=slice.js.map