Browse Source

Replace array concat (#584)

Lutz Roeder 5 years ago
parent
commit
3c2a5be25c
16 changed files with 40 additions and 41 deletions
  1. 2 2
      source/caffe.js
  2. 2 2
      source/caffe2.js
  3. 3 3
      source/cntk.js
  4. 1 1
      source/coreml.js
  5. 2 2
      source/hdf5.js
  6. 2 2
      source/mxnet.js
  7. 2 2
      source/ncnn.js
  8. 4 4
      source/onnx.js
  9. 2 3
      source/openvino.js
  10. 5 5
      source/pytorch.js
  11. 6 6
      source/sklearn.js
  12. 2 2
      source/tengine.js
  13. 2 2
      source/tf.js
  14. 2 2
      source/tnn.js
  15. 1 1
      source/uff.js
  16. 2 2
      source/view-grapher.js

+ 2 - 2
source/caffe.js

@@ -510,7 +510,7 @@ caffe.Node = class {
                 }
             }
         }
-        this._inputs = this._inputs.concat(inputs.slice(inputIndex).map((input) => {
+        this._inputs.push(...inputs.slice(inputIndex).map((input) => {
             return new caffe.Parameter(inputIndex.toString(), [
                 input instanceof caffe.Tensor ? new caffe.Argument('', input.type, input) : new caffe.Argument(input, null, null)
             ]);
@@ -530,7 +530,7 @@ caffe.Node = class {
                 }
             }
         }
-        this._outputs = this._outputs.concat(outputs.slice(outputIndex).map((output, index) => {
+        this._outputs.push(...outputs.slice(outputIndex).map((output, index) => {
             return new caffe.Parameter((outputIndex + index).toString(), [
                 new caffe.Argument(output, null, null)
             ]);

+ 2 - 2
source/caffe2.js

@@ -475,7 +475,7 @@ caffe2.Node = class {
             }
         }
         else {
-            this._inputs = this._inputs.concat(inputs.slice(inputIndex).map((input, index) => {
+            this._inputs.push(...inputs.slice(inputIndex).map((input, index) => {
                 const inputName = ((inputIndex + index) == 0) ? 'input' : (inputIndex + index).toString();
                 return new caffe2.Parameter(inputName, [
                     new caffe2.Argument(input, null, tensors[input])
@@ -496,7 +496,7 @@ caffe2.Node = class {
             }
         }
         else {
-            this._outputs = this._outputs.concat(outputs.slice(outputIndex).map((output, index) => {
+            this._outputs.push(...outputs.slice(outputIndex).map((output, index) => {
                 const outputName = ((outputIndex + index) == 0) ? 'output' : (outputIndex + index).toString();
                 return new caffe2.Parameter(outputName, [
                     new caffe2.Argument(output, null, null)

+ 3 - 3
source/cntk.js

@@ -434,7 +434,7 @@ cntk.Node = class {
                     }
                 }
                 outputs.push(new cntk.Argument(version, output + '_Output_0'));
-                inputs = inputs.concat(initializers);
+                inputs.push(...initializers);
                 break;
             }
         }
@@ -456,7 +456,7 @@ cntk.Node = class {
                 }
             }
         }
-        this._inputs = this._inputs.concat(inputs.slice(inputIndex).map((argument, index) => {
+        this._inputs.push(...inputs.slice(inputIndex).map((argument, index) => {
             return new cntk.Parameter((inputIndex + index).toString(), [ argument ]);
         }));
 
@@ -470,7 +470,7 @@ cntk.Node = class {
                 }
             }
         }
-        this._outputs = this._outputs.concat(outputs.slice(outputIndex).map((argument) => {
+        this._outputs.push(...outputs.slice(outputIndex).map((argument) => {
             return new cntk.Parameter(outputIndex.toString(), [ argument ]);
         }));
     }

+ 1 - 1
source/coreml.js

@@ -620,7 +620,7 @@ coreml.Node = class {
                 return new coreml.Argument(argument.name, argument.type, null, null);
             }));
         });
-        this._inputs = this._inputs.concat(initializers);
+        this._inputs.push(...initializers);
         this._outputs = outputs.map((output, index) => {
             const name = this._metadata.getOutputName(this._type, index);
             return new coreml.Parameter(name, true, [ new coreml.Argument(output, null, null, null) ]);

+ 2 - 2
source/hdf5.js

@@ -1316,7 +1316,7 @@ hdf5.Tree = class {
                     }
                     else {
                         const tree = new hdf5.Tree(reader.at(childPointer));
-                        this.nodes = this.nodes.concat(tree.nodes);
+                        this.nodes.push(...tree.nodes);
                     }
                 }
                 break;
@@ -1335,7 +1335,7 @@ hdf5.Tree = class {
                     }
                     else {
                         const tree = new hdf5.Tree(reader.at(childPointer), dimensionality);
-                        this.nodes = this.nodes.concat(tree.nodes);
+                        this.nodes.push(...tree.nodes);
                     }
                 }
                 break;

+ 2 - 2
source/mxnet.js

@@ -695,7 +695,7 @@ mxnet.Node = class {
                 }
             }
             if (inputIndex < inputs.length) {
-                this._inputs = this._inputs.concat(inputs.slice(inputIndex).map((input, index) => {
+                this._inputs.push(...inputs.slice(inputIndex).map((input, index) => {
                     const inputId = '[' + input.join(',') + ']';
                     return new mxnet.Parameter((inputIndex + index).toString(), [
                         new mxnet.Argument(inputId, null, initializers[inputId])
@@ -721,7 +721,7 @@ mxnet.Node = class {
                 }
             }
             if (outputIndex < outputs.length) {
-                this._outputs = this._outputs.concat(outputs.slice(outputIndex).map((output, index) => {
+                this._outputs.push(...outputs.slice(outputIndex).map((output, index) => {
                     return new mxnet.Parameter((outputIndex + index).toString(), [
                         new mxnet.Argument('[' + output.join(',') + ']', null, null)
                     ]);

+ 2 - 2
source/ncnn.js

@@ -231,7 +231,7 @@ ncnn.Node = class {
                 }
             }
         }
-        this._inputs = this._inputs.concat(inputs.slice(inputIndex).map((input, index) => {
+        this._inputs.push(...inputs.slice(inputIndex).map((input, index) => {
             const inputName = ((inputIndex + index) == 0) ? 'input' : (inputIndex + index).toString();
             return new ncnn.Parameter(inputName, true, [
                 new ncnn.Argument(input, null, null)
@@ -252,7 +252,7 @@ ncnn.Node = class {
                 }
             }
         }
-        this._outputs = this._outputs.concat(outputs.slice(outputIndex).map((output, index) => {
+        this._outputs.push(...outputs.slice(outputIndex).map((output, index) => {
             const outputName = ((outputIndex + index) == 0) ? 'output' : (outputIndex + index).toString();
             return new ncnn.Parameter(outputName, true, [
                 new ncnn.Argument(output, null, null)

+ 4 - 4
source/onnx.js

@@ -345,7 +345,7 @@ onnx.Graph = class {
                 this._outputs.push(new onnx.Parameter(valueInfo.name, [ argument ]));
             }
             for (const node of nodes) {
-                let inputs = [];
+                const inputs = [];
                 const schema = metadata.type(node.op_type);
                 if (node.input && node.input.length > 0) {
                     let inputIndex = 0;
@@ -362,14 +362,14 @@ onnx.Graph = class {
                         }
                     }
                     else {
-                        inputs = inputs.concat(node.input.slice(inputIndex).map((id, index) => {
+                        inputs.push(...node.input.slice(inputIndex).map((id, index) => {
                             return new onnx.Parameter((inputIndex + index).toString(), [
                                 arg(id, null, null, null, imageFormat)
                             ]);
                         }));
                     }
                 }
-                let outputs = [];
+                const outputs = [];
                 if (node.output && node.output.length > 0) {
                     let outputIndex = 0;
                     if (schema && schema.outputs) {
@@ -385,7 +385,7 @@ onnx.Graph = class {
                         }
                     }
                     else {
-                        outputs = outputs.concat(node.output.slice(outputIndex).map((id, index) => {
+                        outputs.push(...node.output.slice(outputIndex).map((id, index) => {
                             return new onnx.Parameter((outputIndex + index).toString(), [
                                 arg(id, null, null, null, imageFormat)
                             ]);

+ 2 - 3
source/openvino.js

@@ -472,7 +472,6 @@ openvino.Node = class {
         this._id = layer.id;
         this._inputs = [];
         this._outputs = [];
-        this._initializers = [];
         this._attributes = [];
         const precision = layer.precision;
         let inputIndex = 0;
@@ -557,7 +556,7 @@ openvino.Node = class {
                 }
             }
             const shape = dimensions ? new openvino.TensorShape(dimensions) : null;
-            this._initializers.push(new openvino.Parameter(name, [
+            this._inputs.push(new openvino.Parameter(name, [
                 new openvino.Argument(id, null, new openvino.Tensor(dataType, shape, data, kind))
             ]));
         }
@@ -588,7 +587,7 @@ openvino.Node = class {
     }
 
     get inputs() {
-        return this._inputs.concat(this._initializers);
+        return this._inputs;
     }
 
     get outputs() {

+ 5 - 5
source/pytorch.js

@@ -1975,10 +1975,10 @@ pytorch.Execution = class {
                         statement.variable.length === 1 && statement.variable[0].type === 'id') {
                         const range = this.expression(statement.target[0], context);
                         const variable = statement.variable[0];
-                        let loop = [];
+                        const loop = [];
                         for (const value of range) {
                             loop.push({ type: '=', target: variable, expression: { type: 'number', value: value }});
-                            loop = loop.concat(statement.body.statements);
+                            loop.push(...statement.body.statements);
                         }
                         statements = loop.concat(statements);
                         break;
@@ -2725,13 +2725,13 @@ pytorch.Container.Zip = class {
                             }
                             delete module.submodules;
                         }
-                        let parameters = [];
+                        const parameters = [];
                         if (module.parameters) {
-                            parameters = parameters.concat(module.parameters);
+                            parameters.push(...module.parameters);
                             delete module.parameters;
                         }
                         if (module.arguments) {
-                            parameters = parameters.concat(module.arguments);
+                            parameters.push(...module.arguments);
                             delete module.arguments;
                         }
                         for (const parameter of parameters) {

+ 6 - 6
source/sklearn.js

@@ -133,7 +133,7 @@ sklearn.Graph = class {
                     value: value
                 });
             }
-            this._nodes = this._nodes.concat(groups.map((group) => {
+            this._nodes.push(...groups.map((group) => {
                 const inputs = group.arrays.map((array) => {
                     return new sklearn.Parameter(array.name, [
                         new sklearn.Argument(array.key, null, new sklearn.Tensor(array.key, array.value))
@@ -157,13 +157,13 @@ sklearn.Graph = class {
             }
             case 'sklearn.pipeline.FeatureUnion': {
                 this._groups = true;
-                let outputs = [];
+                const outputs = [];
                 name = name || 'union';
                 const output = this._concat(group, name);
                 const subgroup = this._concat(group, name);
                 this._add(subgroup, output, obj, inputs, [ output ]);
                 for (const transformer of obj.transformer_list){
-                    outputs = outputs.concat(this._process(subgroup, transformer[0], transformer[1], [ output ]));
+                    outputs.push(...this._process(subgroup, transformer[0], transformer[1], [ output ]));
                 }
                 return outputs;
             }
@@ -172,10 +172,10 @@ sklearn.Graph = class {
                 name = name || 'transformer';
                 const output = this._concat(group, name);
                 const subgroup = this._concat(group, name);
-                let outputs = [];
+                const outputs = [];
                 this._add(subgroup, output, obj, inputs, [ output ]);
                 for (const transformer of obj.transformers){
-                    outputs = outputs.concat(this._process(subgroup, transformer[0], transformer[1], [ output ]));
+                    outputs.push(...this._process(subgroup, transformer[0], transformer[1], [ output ]));
                 }
                 return outputs;
             }
@@ -200,7 +200,7 @@ sklearn.Graph = class {
         inputs = inputs.map((input) => {
             return new sklearn.Parameter(input, [ new sklearn.Argument(input, null, null) ]);
         });
-        inputs = inputs.concat(initializers.map((initializer) => {
+        inputs.push(...initializers.map((initializer) => {
             return new sklearn.Parameter(initializer.name, [ new sklearn.Argument('', null, initializer) ]);
         }));
         outputs = outputs.map((output) => {

+ 2 - 2
source/tengine.js

@@ -191,7 +191,7 @@ tengine.Node = class {
             }
         }
         else {
-            this._inputs = this._inputs.concat(inputs.slice(inputIndex).map((id, index) => {
+            this._inputs.push(...inputs.slice(inputIndex).map((id, index) => {
                 const inputName = ((inputIndex + index) == 0) ? 'input' : (inputIndex + index).toString();
                 return new tengine.Parameter(inputName, true, [ tensors[id] ]);
             }));
@@ -210,7 +210,7 @@ tengine.Node = class {
             }
         }
         else {
-            this._outputs = this._outputs.concat(outputs.slice(outputIndex).map((id, index) => {
+            this._outputs.push(...outputs.slice(outputIndex).map((id, index) => {
                 const outputName = ((outputIndex + index) == 0) ? 'output' : (outputIndex + index).toString();
                 return new tengine.Parameter(outputName, true, [ tensors[id] ]);
             }));

+ 2 - 2
source/tf.js

@@ -804,7 +804,7 @@ tf.Node = class {
                     inputIndex += inputCount;
                 }
             }
-            this._inputs = this._inputs.concat(inputs.slice(inputIndex).map((input, index) => {
+            this._inputs.push(...inputs.slice(inputIndex).map((input, index) => {
                 return new tf.Parameter((inputIndex + index).toString(), [
                     new tf.Argument(input, null, initializers[input])
                 ]);
@@ -833,7 +833,7 @@ tf.Node = class {
                     outputIndex += outputCount;
                 }
             }
-            this._outputs = this._outputs.concat(outputs.slice(outputIndex).map((output, index) => {
+            this._outputs.push(...outputs.slice(outputIndex).map((output, index) => {
                 return new tf.Parameter((outputIndex + index).toString(), [
                     new tf.Argument(output, null, null)
                 ]);

+ 2 - 2
source/tnn.js

@@ -203,7 +203,7 @@ tnn.Node = class {
             }
         }
         else {
-            this._inputs = this._inputs.concat(inputs.slice(inputIndex).map((input, index) => {
+            this._inputs.push(...inputs.slice(inputIndex).map((input, index) => {
                 const inputName = ((inputIndex + index) == 0) ? 'input' : (inputIndex + index).toString();
                 return new tnn.Parameter(inputName, [ new tnn.Argument(input, null, null) ]);
             }));
@@ -224,7 +224,7 @@ tnn.Node = class {
             }
         }
         else {
-            this._outputs = this._outputs.concat(outputs.slice(outputIndex).map((output, index) => {
+            this._outputs.push(...outputs.slice(outputIndex).map((output, index) => {
                 const outputName = ((outputIndex + index) == 0) ? 'output' : (outputIndex + index).toString();
                 return new tnn.Parameter(outputName, [ new tnn.Argument(output, null, null) ]);
             }));

+ 1 - 1
source/uff.js

@@ -241,7 +241,7 @@ uff.Node = class {
                     }
                 }
             }
-            this._inputs = this._inputs.concat(node.inputs.slice(inputIndex).map((id, index) => {
+            this._inputs.push(...node.inputs.slice(inputIndex).map((id, index) => {
                 const inputName = ((inputIndex + index) == 0) ? 'input' : (inputIndex + index).toString();
                 return new uff.Parameter(inputName, [ args.get(id) ]);
             }));

+ 2 - 2
source/view-grapher.js

@@ -310,14 +310,14 @@ grapher.NodeElement.Header = class {
             const yPadding = 4;
             const xPadding = 7;
             const element = this.createElement('g');
-            let classList = [ 'node-item' ];
+            const classList = [ 'node-item' ];
             parentElement.appendChild(element);
             const pathElement = this.createElement('path');
             const textElement = this.createElement('text');
             element.appendChild(pathElement);
             element.appendChild(textElement);
             if (item.classList) {
-                classList = classList.concat(item.classList);
+                classList.push(...item.classList);
             }
             element.setAttribute('class', classList.join(' '));
             if (item.id) {