Joel Foster Posted Monday at 05:22 PM Report Posted Monday at 05:22 PM 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) - Joel Quote
Joel Foster Posted Monday at 05:24 PM Author Report Posted Monday at 05:24 PM Unexpected Behavior #2: For Loop executes on 'Empty' Array Labview-array-bug2.vi Quote
crossrulz Posted Monday at 05:41 PM Report Posted Monday at 05:41 PM 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. 1 Quote
dadreamer Posted Monday at 06:02 PM Report Posted Monday at 06:02 PM I remember I even had an idea, that would make it easier to track such situations: Add Array Size(s) Indicator. In design time it would cost almost nothing. Although I admit, its use cases are quite rare. Quote
Joel Foster Posted Monday at 06:24 PM Author Report Posted Monday at 06:24 PM Case 1: Concatenate Build - works as expected (output is always empty) Case 2: Append Build - works as expected (output is always empty) Case 3: Build Array - unexpected output, non-empty output array 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. Thanks, Joel Quote
Joel Foster Posted Monday at 06:28 PM Author Report Posted Monday at 06:28 PM 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. Quote
Joel Foster Posted Monday at 06:38 PM Author Report Posted Monday at 06:38 PM 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. Quote
hooovahh Posted Monday at 09:10 PM Report Posted Monday at 09:10 PM 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.