LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Efficient way to replace array subset into an array at discontigous indices

Solved!
Go to solution

@siddharth9678 wrote:

Thanks for the reply....Sorry for not sharing labview code as i didnt start doing so. 

Sorry for the confusion created by ambigous description. Long story short ...what i want is lets say i have an array of initialized 0s of size 100 and i have data elements d0,d1,d2,d3 to replaced at index 1,9,11,20 in zero initiazed array. Can this be done in an efficient manner than having 4 array replacement operations.

 

Still i have described my earlier problem statement....

"After four elements have been replaced, should they remain for the next iterations or should the next iteration start from an array of zeroes again? If they remain, what should happen if an index occurs a second time?"

They remain for next iterations after four elements has been replaced per iteration.

No of iterations can be any thing between 1 to 25. No index occurs second time.

 

 Scenario is this...Total no of data elements is known in advance.

Let say there are 100 data elements D0,D1....,D99. Now for my case i am dividing this data in bunch of 4 datas each time/iteration.

Lets say no of iterations = 2

1st iteration data D0,D1,D2,D3 at indices 1,9,11,20

2nd iteration data D4,D5,D6,D7 at indices 2,25,48,51

 

Basically there is a table where i have indices mapped to the iteration value.

 

Since size of the data is known in advance, i have created zero initialized array of size 100 where in at indices 1,9,11,20 i will have D0,D1,D2,D3 and at 2,25,48,51 i will have D4,D5,D6,D7.At remaining indices all will be 0. Main thing i want help is  "4 array replacements per iteration" if this can be optimized in terms of array replacement. As far as i know it may not be optimized further...Still wanted to take opinion of experts on this.

 


This is still completely confusing!

 

  • What is the difference between d1 and D1, for example?
  • How does the mapping table look like?
  • How many D's are there?
  • Do you need the intermediary results or just the final one?

 

Why not show a simple example, just using text, e.g.:

 

d = a, b, c, d, e, f, g, h (?)

table= 1, 9, 11, 20, 2, 25, 48, 51 (?)

at start: a= [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

after iteration 1: a=?

after iteration 2:  a=?

at the end: a=?

 

Why are you against four array replacements? These are very fast in-place operations, even if you would have a primitive to do four at once, the CPU needs to do them one at a time anyway behind the scene, right? How exactly are you doing it currently? Do you get the correct result?

0 Kudos
Message 11 of 14
(530 Views)

Hi,

 


@altenbach wrote:
Why are you against four array replacements?

When there are ALWAYS 4 replacements you could even resize the ReplaceArrayElement function to replace 4 elements with just one node…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 12 of 14
(509 Views)
Solution
Accepted by siddharth9678

@GerdW wrote:

Hi,

 


@altenbach wrote:
Why are you against four array replacements?

When there are ALWAYS 4 replacements you could even resize the ReplaceArrayElement function to replace 4 elements with just one node…


True but that would just does the looping internally. That would require two index array operation (one for the four table values and one for the four d elements) and would make it non-scalable, because next time they might be 3 or seven elements. There would be no difference is efficiency.

 

Most likely this is not exactly the correct solution, but here we compare the code size and complexity using a resized replace array subset vs. a simple inner loop. I would always go with the bottom solution. FOR loops are one of the most efficient structures.

 

altenbach_0-1681828144959.png

 

Message 13 of 14
(486 Views)

@siddharth9678 wrote:

Thanks for the reply....Sorry for not sharing labview code as i didnt start doing so. 

Sorry for the confusion created by ambigous description. Long story short ...what i want is lets say i have an array of initialized 0s of size 100 and i have data elements d0,d1,d2,d3 to replaced at index 1,9,11,20 in zero initiazed array. Can this be done in an efficient manner than having 4 array replacement operations.


Well, you can expand the Replace Array subset to take multiple inputs at once. Which i'd only recommend only if you know you always have some data coming in in packets of e.g. 4 at a time, and probably not even then. Just do it in a loop and it'll be easier, efficient and scalable.

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 14 of 14
(472 Views)