c# - Merge multiple float arrays and calculate the average of each item -


I have several float arrays. Their length does not lie with each other. Now I have them all in a float array Have to be sold. For them to sell, I want to calculate the average value for each index. It means:

  output [n] = (input0 [n] + input1 [n] + input2 [n] ... + inputx [n]) / x   

To calculate them all very quickly, I do not care if the code is read or expandable or not. It should be as fast as possible:

I have created the following code:

  Private zero mix () {list & lt; Float [] & gt; Input = new list & lt; Float [] & gt; (); // ... // Input [n] is float array // eg: // 0: [0.5, 0.3, 0.6, 0.1, -0.3, 0.1, -0.9] // 1: [0.1, 0.7, - 0.2, 0.8, -0.2] // 2: [-0.3, 0.9, 0.5, 0.4, 0.8, -0.6] // 3: [0.5, -0.2, 0.4] // ---------- --------------- ---------------------- // The average value for the first value should be: // (0.5 + 0.1 - 0.3 + 0.5) / 4 // Combine all together: // =================== An output buffer, interns length = input.max (X = & gt; x.Length); Float [] output = new float [length]; {Float value = 0; for int n = 0; n & lt; height; n ++); Int count = 0; (Int x = 0; x & lt; input.Qount; x ++) for {float [] inputBuffer = input [x]; // If check the input buffer (lang> = n) // select the input array / check whether there is a value to get {value + = inputBuffer [n]; // Get the value of input array calculation +; }} Output [n] = value / calculation; // calculation of average}}   

As you can see, there is nested for loop in it. I would have thought this code is not fast enough yet. So is there anything to make it faster?

There are two things to make it faster: / p>

  1. < p> Restore the code so that if statement is in an external loop instead of the internal loop.
  2. Take advantage of the SIMD library here:

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -