LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Add elelment by element in an array of cluster

18451iA3793EA325C7242D
@GerdW wrote:

@Yamaeda:

How should an IndexArray help here? Geeta wants to convert an array of clusters to a cluster of arrays containing all values...


I was fooled by the text "i want to get an array of clusters to a single cluster" which sounds like Op wanted a single cluster. OP's solution works but is unecessary, autoindexing should solve it!

 

 

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

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 11 of 20
(1,302 Views)

Your current solution is extremely slow because it reallocates an array for every element in the cluster at every iteration of the FOR loop.  This also highly fragments your program memory.  It would not surprise me if you ran out of memory.  You can probably get somewhere between one and three orders of magnitude speed improvement by using the following algorithm:

 

 

  1. Use a FOR loop to determine the final size of each array in your final cluster (loop through all your clusters and sum the array lengths).
  2. Preallocate this data using Initialize Array and use this to initialize the shift registers of the final loop.
  3. Use a second FOR loop to replace the data in the preinitialized arrays with the data from the clusters (use Replace Array Subset).
You can find some examples of this type of solution here.  You may also want to consider using the In Place Element Structure, provided your version of LabVIEW is new enough.

 

0 Kudos
Message 12 of 20
(1,296 Views)

In my solution above Autoindexing knows how big the arrays will be and preallocate. 😉

 

/Y

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

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 13 of 20
(1,285 Views)

Hi Yamaeda,

 

preallocation might become tricky when unbundling arrays! Each single cluster might contain a different sized array...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 14 of 20
(1,280 Views)

@GerdW wrote:

Hi Yamaeda,

 

preallocation might become tricky when unbundling arrays! Each single cluster might contain a different sized array...


Can you explain how Yamaeda's code would result in cluster with different size arrays?  The loop executes a certain number of times.  All of the output arrays have to be of equal size.

 

- tbob

Inventor of the WORM Global
0 Kudos
Message 15 of 20
(1,268 Views)

@tbob wrote:

@GerdW wrote:

Hi Yamaeda,

 

preallocation might become tricky when unbundling arrays! Each single cluster might contain a different sized array...


Can you explain how Yamaeda's code would result in cluster with different size arrays?  The loop executes a certain number of times.  All of the output arrays have to be of equal size.

 


I had to look at that post twice myself. I suspect Gerd has a Sea-Story G-Story to go with that note.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 16 of 20
(1,269 Views)

Hi,

 

my thoughts on pre-allocation were these:

It's not a concern of having different sized arrays after the conversion. It's the concern of having different sized arrays before conversion:

The OP has an array of clusters of arrays. The arrays in each cluster may have a different length.

When using an autoindexing FOR loop I doubt LabVIEW is able to preallocate the memory needed to store the array elements in the final 2D array. First LabVIEW would have to scan all the clusters for the biggest array elements to get the final size after autoindexing... As said: I doubt LabVIEW will do this.

Is there someone with deeper insights?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 17 of 20
(1,252 Views)

Well autoindexing arrays will add 1 dimension, so that part is quite easy, optimally the compiler, as you said, should scan for the longest array to preallocate a 2d array of finished size.

 

In this case, my previous example works, but it seems OP wants a 1D array in  each cluster, which ofc. can be solved with a Array Sizes -> Multiply array elements -> Reshape array.

 

It seems like a mess in general though needing to switch between these  two, so i'm voting to bite the bullet and correct the program and make it all use 1 version.

 

/Y

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

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 18 of 20
(1,243 Views)

@GerdW wrote:

Hi,

The OP has an array of clusters of arrays.


Look at the OP's first posted picture, in particular, the cluster in the array on the front panel.  I see a Boolean, a Numeric, and a String.  I don't see any arrays.

 

18451iA3793EA325C7242D

- tbob

Inventor of the WORM Global
0 Kudos
Message 19 of 20
(1,198 Views)

Oooops.  Disregard the pevious post.  I was looking at the first post on this page without realizing it was the second page, not the first.  The OP does have a cluster of arrays.  Looks like a bad start for a Monday for me.

- tbob

Inventor of the WORM Global
0 Kudos
Message 20 of 20
(1,189 Views)