1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | Object.defineProperty(exports, "__esModule", { value: true });
|
19 | var tfjs_1 = require("@tensorflow/tfjs");
|
20 | var nodejs_kernel_backend_1 = require("../nodejs_kernel_backend");
|
21 | exports.gatherV2Config = {
|
22 | kernelName: tfjs_1.GatherV2,
|
23 | backendName: 'tensorflow',
|
24 | kernelFunc: function (args) {
|
25 | var _a = args.inputs, x = _a.x, indices = _a.indices;
|
26 | var backend = args.backend;
|
27 | var _b = args.attrs, axis = _b.axis, batchDims = _b.batchDims;
|
28 |
|
29 | var indicesVals = backend.readSync(indices.dataId);
|
30 | var axisDim = x.shape[axis];
|
31 | var _loop_1 = function (i) {
|
32 | var index = indicesVals[i];
|
33 | tfjs_1.util.assert(index <= axisDim - 1 && index >= 0, function () { return "GatherV2: the index value " + index + " is not in [0, " + (axisDim - 1) + "]"; });
|
34 | };
|
35 | for (var i = 0; i < indicesVals.length; ++i) {
|
36 | _loop_1(i);
|
37 | }
|
38 |
|
39 | tfjs_1.backend_util.segment_util.collectGatherOpShapeInfo(x, indices, axis, batchDims);
|
40 | var axisTensor = tfjs_1.scalar(axis, 'int32');
|
41 | var opAttrs = [
|
42 | { name: 'batch_dims', type: backend.binding.TF_ATTR_INT, value: batchDims },
|
43 | nodejs_kernel_backend_1.createTensorsTypeOpAttr('Tparams', x.dtype),
|
44 | nodejs_kernel_backend_1.createTensorsTypeOpAttr('Tindices', indices.dtype),
|
45 | nodejs_kernel_backend_1.createTensorsTypeOpAttr('Taxis', 'int32')
|
46 | ];
|
47 | var res = backend.executeSingleOutput(tfjs_1.GatherV2, opAttrs, [x, indices, axisTensor]);
|
48 | axisTensor.dispose();
|
49 | return res;
|
50 | }
|
51 | };
|