Jump to content

LabVIEW Build Array Bug #1: Unexpected Array Growth


Joel Foster

Recommended Posts

Posted

Has anyone ever seen this behavior before?

Build-Transpose-Build sequence resulted in a non-empty array. This appears to be infinitely extendable (i.e. adding more transposes and builds increases the size of the 'Empty' output array)

image.png.f74fe92b18480d43fbbf2a6031859bdc.png

- Joel

Posted

If you look at the actual array sizes, things will make a lot more sense.

1. The Build Array will add the number of expanded elements to the first dimension. The array size after the first Build Array is (2,0), which is still an empty array.

2. The Transpose Array will swap the array sizes. The array size after the Transpose Array is (0,2), which is still an empty array.

3. Again, the Build Array will add the number of expanded elements to the first dimension. In this case, it will add 1 to the first dimension, resulting in the array size being (1,2), which is no longer an empty array.image.png.2472c2e9d5a19bbdd94796af62461089.png

  • Like 1
Posted

Case 1: Concatenate Build - works as expected (output is always empty)

image.png.80d148ce3a583fe64fdd0a9fb7b8d8a8.png

 

Case 2: Append Build - works as expected (output is always empty)

image.png.24f3a85e1677d564bbd2da9dea65ffe8.png

 

Case 3: Build Array - unexpected output, non-empty output array

image.png.b1afca2a6b43b6eca2f6b65fec1e5278.png

The change in size that you pointed out @crossrulz helped me understand why the For Loop was executing under these circumstances (I think)--Thank you; that was really bothering me--but I still don't understand why building an empty array after transposing results in a non-empty array--I can chain build-array functions all day without getting this behavior.

image.png.50cc15349f663ef66f5580d0499aa39e.png

Thanks,

Joel 

 

Posted

Additionally, I would argue that the Array Size function should return an element for each rank of the array, but for an empty array, these should all be zero...as they are for the Concatenate example.

Posted
52 minutes ago, crossrulz said:

Again, the Build Array will add the number of expanded elements to the first dimension. In this case, it will add 1 to the first dimension, resulting in the array size being (1,2), which is no longer an empty array.

I see. I didn't take enough time to understand your final point. It appears that the output array is populated based on the non-zero rank elements in the array size. However, why is the array *growing* under the hood? This is what is really causing me grief...I expect the rank to grow, just not the size of the underlying array. I would naively expect the number of elements in each dimension to remain zero unless explicitly populated.

Posted

I think everything in here is the expected behavior.  As Crossrulz said an array can be empty, if one of the dimensions are zero, but other dimensions aren't.  Yes this can cause things like a FOR loop to execute with an empty array. 

Lets say I have some loop talking to N serial devices.  Each device will generate an array of values.  So if I index those values coming out of the loop, it will create a 2D array.  Now lets say I want to close my N serial devices.  A programmer may ask how many devices are there?  Well you can look at the number of Rows in that 2D array and it will be the number of devices that were used earlier.  We might run that 2D array from earlier into a FOR loop and close each of them.  But what if each of the N serial devices returned an empty array?  Now if arrays worked like you expected, then the 2D array is empty and the loop should run zero times.  But LabVIEW knows the 2D array has N rows, and 0 columns.  So it can run the loop N times.  This isn't the exact scenario, but something like this is a reason why you might want your 2D array to be empty, but have a non zero number of rows.  You want it to run some other loop on the rows, even if the columns are empty.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.