@hoff97/tensor-js
Version:
PyTorch like deep learning inferrence library
38 lines • 1.76 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 { CPUTensor } from '../../tensor/cpu/tensor';
import { OnnxNode } from '../node';
export class ReshapeNode extends OnnxNode {
constructor(attributes, inputs, outputs, constants, onnxVersion, mode) {
super(attributes, inputs, outputs, constants, onnxVersion, mode);
}
forward(inputs) {
return __awaiter(this, void 0, void 0, function* () {
const x = inputs[0];
const shape = inputs[1];
if (!(shape instanceof CPUTensor)) {
throw new Error('Reshape only works with CPU tensor as shape tensor');
}
if (this.onnxVersion < 13) {
const _shape = new Array(shape.size);
for (let i = 0; i < shape.size; i++) {
_shape[i] = shape.get(i);
}
return [x.reshape(_shape)];
}
throw new Error(`Reshape with onnx version ${this.onnxVersion} not yet implemented`);
});
}
getType() {
return 'Reshape';
}
delete() { }
}
//# sourceMappingURL=reshape.js.map