LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Replace row of array in place

I have a big array 2D with 4 rows of 608400 elements, in a given time, y want to add a new point to the INE of the rows, deleting the element in indx 0, wich could be done by replacing the element 0 and then rotating the row by -1, but, in order to obtain the row you must first use array subset, and then make a branch in the original array and replace subset with this new row. In assuming this males a copie of the row wich slows down my program, and the in place element structure does not allow uwired inputs, only operates on elements. Ty in advance
0 Kudos
Message 1 of 12
(4,603 Views)
One of the rows*
This makes a copie*
0 Kudos
Message 2 of 12
(4,599 Views)
If i wire the hole array in to a input ouput element in a in place structure, abd then perform the described operation (index array, then replace element 0, rotate -1 and then replace the row in the original array with replace subset, and then wire the resut to the output of the in place structure, would this avoid the copie?
0 Kudos
Message 3 of 12
(4,591 Views)

I'm pretty sure the compiler is smart enough now to do all of that in place.  The Rotate 1D Array is what will take a long time.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 12
(4,576 Views)

I'm not completely certain I understand what you are trying to do.  I know you have a 4 x 608400 array, which I assume stays a fixed size.  I think that you are treating it like a lossy queue, right?  You are adding a new element, which "pushes" all the older elements up one space and deletes the oldest (first) one -- is that correct?  And are you doing this for all 4 rows at once (in which case, I would describe it as "replacing a column" of the array)?

 

If this is what you are doing, then you have essentially created what I learned (when I programmed in Fortran) was called a "circular buffer".  Depending on how you use this buffer, you can easily add a new element in very quickly with no array copying or rotation necessary.  Just do what we did so many years ago -- maintain a pointer to the "next free slot" in the array (initially index 0, when the array is empty, and incrementing Mod 608400 with each insertion).  Insertions thus take almost no time -- it is a simple "replace element at index "Next Free Slot and circularly increment the index".  If you want to extract elements, the oldest is at "Next Free Slot", as well.  Depending on how you want to use the elements, you may or might not need to modify the Index for other operations.  In the event that, at some point, you need an entire row, simply copy the existing row, rotate it left by "Next Free Slot", and you are Good to Go.

 

Bob Schor

Message 5 of 12
(4,558 Views)

@Bob_Schor wrote:

 

If this is what you are doing, then you have essentially created what I learned (when I programmed in Fortran) was called a "circular buffer". 


Did you say Circular Buffer.  Full disclosure, I've never tested the circular buffer with an array of that size.  No matter what you do there will be copies made, the goal is to make the fewest number of copies, and doing things efficiently.

0 Kudos
Message 6 of 12
(4,550 Views)

@AntonioNI wrote:
I have a big array 2D with 4 rows of 608400 elements, in a given time, y want to add a new point to the INE of the rows, deleting the element in indx 0, wich could be done by replacing the element 0 and then rotating the row by -1, but, in order to obtain the row you must first use array subset, and then make a branch in the original array and replace subset with this new row. In assuming this males a copie of the row wich slows down my program, and the in place element structure does not allow uwired inputs, only operates on elements. Ty in advance

"Array subset" is the incorrect tool to get a row. The correct tool is "index array" with the first index specifying the row and second index input disconnected.

 

You can do this nearly in-place using a loop and a shift regsiter. Can you show us some of your code? (Simplify it to make the rows smaller as a demo).

0 Kudos
Message 7 of 12
(4,533 Views)

Example atached.

Download All
0 Kudos
Message 8 of 12
(4,503 Views)

80-100 ms in all methods, including the last on in this atached img. I guess is not that bad, will have to deal with it xP

0 Kudos
Message 9 of 12
(4,487 Views)

@AntonioNI wrote:

80-100 ms in all methods, including the last on in this atached img. I guess is not that bad, will have to deal with it xP


Why do you suddenly have 3D arrays?

0 Kudos
Message 10 of 12
(4,477 Views)