LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Build Array from 2D to 3D. Unexpected size.

If I wire an empty 2D array (size 0,0) into a Build Array function, the resulting 3D array is of size (1,0,0) which seems mathematically impossible.  The behavior becomes more pronounced when multiple empty 2D arrays are wired into the Build Array function.  I have seen this behavior in 8.6 and 2009.

 

The problem I have run into is that if I auto-index this "empty" 3D array into a For Loop, the loop actually runs, but each iteration reads in an empty 2D array.

 

Has anyone else noticed this behavior?  Is it a bug?

 

build 3D array.PNG

Certified LabVIEW Developer
Message 1 of 29
(12,531 Views)

As a follow up, this behavior is documented in the following thread:

http://forums.ni.com/ni/board/message?board.id=170&message.id=43707&query.id=790026#M43707

 

However, the reply to the thread accepts that an empty array constant is different from an empty array created by the Build Array function.  I do not accept this difference as reasonable or acceptable.  If you disagree, please explain.

Certified LabVIEW Developer
0 Kudos
Message 2 of 29
(12,509 Views)

Here is proof of the problem.  An "empty array" is auto-indexed into a For Loop, and the For Loop executes.

 

build 2d array bug_ForLoop.PNG

Certified LabVIEW Developer
0 Kudos
Message 3 of 29
(12,498 Views)

I think the behavior is correct. You are building an array with three empty columns and thus there are three iterations.

 

Why would you expect anything else? 

0 Kudos
Message 4 of 29
(12,489 Views)

@altenbach

 

So, you are saying that if you wired an empty array to a For Loop, you would expect the loop to execute a non-zero number of times?  That is in fact what happened.

 

How can you mathematically have a 2-dimensional array with 3 rows and 0 columns?

 

If I create an empty 2-D array constant, it has 0 rows and 0 columns.  If I create an empty 2-D array with the Build Array function, I would expect exactly the same outcome, a 2-D array with 0 rows and 0 columns.

 

The array is empty.  The "Empty Array?" function says that the array is empty.  A For Loop with an empty array connected to an auto-indexing input tunnel should execute zero times.  The For Loop in my example does not follow perform this expected behavior.

Certified LabVIEW Developer
Message 5 of 29
(12,480 Views)

An array can have nonzero values in any of the dimensions. The number of elements is the product of all dimensions, so if any of the dimensions is zero, the array will be empty. It does not mean that all dimensions are zero.

 

If you want a 0x0 2D array, don't use built array, but use initialize array with both dimensions zero.

 

(There seems to be a slight inconsistency if you try to reshape the size=0 1D array to a 2D array of either dimension 2x0 or 0x2. The resulting array will be 0x0 while I would expect it to be similar to the result of initializing a 2D array as 0x2 or 2x0.)

 

 

Message 6 of 29
(12,462 Views)

Hi Christian,

 

I don't follow your explanation.

 

It seems like there is a bug in this pile somewhere.

 

If I create 2d control and leave it empty and wire it to a For loop the For loop does not iterate.

 

If I write the results of a build with two empty 1d inputs to a local of that control fisrt the display looks the same but the For loop iterates.

 

If I pause the execution after the write and doa "empty array" on the control before the control is read, it does not iterate.

 

So from where I sit it looks like the build is not computing the dimensions correctly when an empty array constant is used.

 

Either that or there are two type of empty arrays... arrays that are empty and arrays that are almost empty. Smiley Tongue

 

Play with the attached and tell me what I am missing.

 

Ben

 

Huh.PNG

 

Huh.PNG

I am leaning toward this being a bug in the Build array returning the wrong size down the wire.
Message Edited by Ben on 03-22-2010 02:19 PM
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 7 of 29
(12,448 Views)

@ altenbach

 

I disagree with you on the expected behavior of the build array function, given an empty array input.  A For Loop should never execute if an empty array is connected to an auto-indexing input tunnel, regardless of how that empty array was constructed.

 

However, the inconsistency is arguably more troublesome in the long run.  You mentioned your failed attempt to Reshape an array to dimension 2X0.  As a counter-point, you can use Initialize Array to create an array of dimension 2X0.  If you then try to Reshape that array from 2X0 to 2X0 (effectively changing nothing), the resulting array is actually 0X0 as you mention.

 

I do not think this is a slight inconsistency, considering it affects when a For Loop will execute, and, as Ben mentions, it affects how empty an "empty" array really is.

Message Edited by atigert on 03-22-2010 02:54 PM
Message Edited by atigert on 03-22-2010 02:55 PM
Message Edited by atigert on 03-22-2010 02:58 PM
Certified LabVIEW Developer
0 Kudos
Message 8 of 29
(12,395 Views)

I changed my mind (all it took was to sit here and ponder how many different ways an array can be empty).

 

 

I put together this code that creates an array of the same degree of emptyness  with both empty and non-empty arrays.

 

Untitled.png 

 

Since I get the same results without using the build array the "build array" can't be at fault and since the same bizzare   behavior happens then it must be the the implementation of some rule about building arrays out of empty arrays OR how multiple array dimensions are mapped in memory.

 

Could someone that understands    please speak to the topic of "Emptyness".

 

After all of these experiments with empty arrays I'm going to slide away from the keyboard.

 

 

Ben

 

Summary No Bug

Message Edited by Ben on 03-22-2010 06:28 PM
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 9 of 29
(12,353 Views)

Ben,

 

If you are not burned out on array emptiness testing, I've got a couple of interesting test cases.

 

---Creating "Empty" array constants---

1.  In your last example you shared, you had an array indicator to which you wrote a 2X0 array.  Right-click that indicator and change it to a constant.

2.  Create a second 2D array constant using an array constant shell and a constant from the pallettes.

3.  Wire each constant to an Array Size function with indicator and to separate For Loops.

 

At this point you have 2 array constants that look exactly the same, but will cause different For Loop behaviors.

 

 

---Generating an "Out of Memory" warning pop-up---

1.  Use the Initialize Array (or other methods) to create a 2D array of size 0X50000000, and wire an indicator to it.

2.  After running the VI, view the front panel.  The indicator is empty.

3.  Insert a value into element (0,0).

 

As soon as I input a value for one element, the array automatically tried to fill in the rest of the 50000000 elements with zeros, and generated a pop-up informing me that I was out of memory.  After pressing the OK button, the array was empty again.  Depending on your memory size, you may be able to create a larger array before seeing this issue.

 

You can potentially reek all kinds of havoc by having an "empty" multi-dimensional arrays with very large dimension sizes with one dimension of length zero.  There will be no problem unless you manage to insert a single value.  Granted, if you use Insert In Array, the fake dimension sizes return to normal, but if you are dealing with a front panel control that you have initialized with the absurd array, and the operator inserts a value,  your VI will likely exhibit undesirable behaviours.

 

These specific tests were performed under LabVIEW 8.6.  My initial posted test cases were duplicated under 2009 and 7.1 with the same results.

 

Andrew

Message Edited by atigert on 03-22-2010 11:28 PM
Certified LabVIEW Developer
Message 10 of 29
(12,338 Views)