LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Array size of empty array - bug

I have 2 empty arrays with different sizes

0 Kudos
Message 1 of 13
(5,625 Views)

The two arrays are different, one has 1 row and 0 columns the other has 0 rows and 0 columns. Both are empty.

The number of elements is the product of the two sizes and thus zero in both cases.

 

To check if an array is empty, use the "empty array?" primitive.

 

No bug.

0 Kudos
Message 2 of 13
(5,603 Views)

The "empty array?" primitive would consider both 1x0 & 0x0 arrays as empty.

 

But when I concatenate empty array of size 0x0 with 2x2 array, resultant array is 2x2 which is expected. If I concatenate empty array of size 1x0 with 2x2 array, resultant array is 3x2 which is not expected.

0 Kudos
Message 3 of 13
(5,592 Views)

I admit I find this last example confusing on several levels.  I'm not sure how you made the 1x0 empty array, but it definitely added a non-empty 1-D array of zeros.  There is probably a "rule" governing this that is sensible and logical.  More telling is that such strange 2D arrays appear to be anomalies, illogical constructs that (under circumstance where they could arise) should be tested with the "Empty Array?" test.

 

It reminds me of wiring an empty array "through" a For Loop and being surprised when the Error on the Error line entering the Loop on a tunnel didn't make it out the other side (Error went in, but No Error came out).  It was clearly my mistake, as I hadn't "read the rules" carefully and didn't consider this case ...  [I now know better and "do it right"].

 

Bob Schor

0 Kudos
Message 4 of 13
(5,575 Views)
(Sorry, posting by phone, cannot look at the VI. I have a look at it later).

Bob, you can use "initialize array" to generate any "odd" empty array as long as at least one of the dimensions is size zero, then convert the output into a diagram constant. There are many other ways.
0 Kudos
Message 5 of 13
(5,572 Views)

@altenbach wrote:
Bob, you can use "initialize array" to generate any "odd" empty array as long as at least one of the dimensions is size zero, then convert the output into a diagram constant. There are many other ways.

Thanks.  I'd forgotten the details.  I usually initialize an empty array by dropping an Array construct, dragging the Index to the number of dimensions I need, dropping the Type I want, then hiding the Indices to keep it compact and slightly "strange-looking" to remind myself "Don't Touch" ...

 

BS

0 Kudos
Message 6 of 13
(5,566 Views)

We had a very long discussion about all this many years ago. I'll try to find it.

 

An interesting applications is that if you autoindex on an empty 2D array with N rows, the FOR loop will actually run N times. (As you can guess, the 2D array going into the second loop is 5x0.).

 

 

 

 

0 Kudos
Message 7 of 13
(5,557 Views)

@altenbach wrote:

We had a very long discussion about all this many years ago. I'll try to find it. 

 


OK, here's a related discussion from 2003 and another one from 2010. The question comes up occasionally. 😄

0 Kudos
Message 8 of 13
(5,551 Views)

@sharath006 wrote:

The "empty array?" primitive would consider both 1x0 & 0x0 arrays as empty.

 

But when I concatenate empty array of size 0x0 with 2x2 array, resultant array is 2x2 which is expected. If I concatenate empty array of size 1x0 with 2x2 array, resultant array is 3x2 which is not expected.


This is exactly correct behavior. The empty array contains a row of zero lenght that will get paded with zeroes when appending arrays that don't match in size. The longest array determines the number of columns here.

 

Similarly, if you change the order of the two input arrays, you get a row of zeroes at the top:

 

 

 

Another example: Imagine that you are autoindexing a 1D array at the output tunnel of a FOR loop and that array is empty for some of the iterations. You still get a row, just with all zeroes for these cases. It would not make sense to get an output array with fewer rows than iterations.

0 Kudos
Message 9 of 13
(5,547 Views)

Thanks, Christian.  I'd never seen the page you referenced in "How LabVIEW Stores Data in Memory", so I went looking for it in LabVIEW 2016 Help.  I found it after about 10 minutes of looking, using various Search terms, stumbling onto this page by looking up Arrays in the Index, navigating to the entry "arrays, alignment in memory" (which is another topic), and there I was on "How LabVIEW Stores Data in Memory".  A lot of useful stuff, much of which I knew (or knew how to find out), but some "forgotten lore".

 

Bob Schor 

0 Kudos
Message 10 of 13
(5,540 Views)