LabVIEW Idea Exchange

cancel
Showing results for 
Search instead for 
Did you mean: 
tshurtz

For loops that can auto index beyond the end of the shortest array

A right click option for each auto indexed array that allows will not use the length of that array in choosing the number of iterations. If there is no input to the count terminal all auto-indexed terminals can go beyond their length otherwise at least one must remain as a driver for determining the length. If multiple are left with the default (existing) behavior, the shortest length will be used. For any iteration where the array is shorter that the "i" of the loop, the defaults for the data type will be returned (just as if "index array" blocks had been used inside the loop. 

 

Similarly the loop could be set to use the longest array instead of the shortest.

 

Additionally a similar function could be done when any array compare or math functions are done. In the case of compare functions if set to use longest array, the result will be false for any compare to an empty element of the shorter array, and math functions will use the default data type for empty elements.

9 Comments
wiebe@CARYA
Knight of NI

That are two different ideas.

 

The for loop option would save one Index Array (per array). Not sure how I feel about it. It sure can be annoying from time to time.

 

Autoindexing.PNG

This will always iterate 10 times, no matter what the array sizes are. The red color of the indexing is just an example, it could probably be improved.

AristosQueue (NI)
NI Employee (retired)

Can you explain why you want this? What is your use case for needing to index arrays of different sizes? I've been inclined over the years to call it a bug that LV allows the arrays to be different sizes from each other or to differ from the N value. What problem are you trying to solve?

tshurtz
Member

I agree it would be nice if you tried to index outside of the array bounds (or had different length arrays) without setting the proposed modification it should throw a run time error or something. but seeing as they have not done that in the past and instead just pretend like it all worked just fine when in fact it truncated some of your arrays can really bite you if you are not careful.

 

I have had several instances over the last few years where I knew my data was of different lengths but wanted the ability described. I have had to manually index inside the loop which just takes up space and is tedious.

 

One instance I can think of (for the function request) off the top of my head is putting two different length arrays into a "=" function and the array that comes out is all true but they are different lengths. In the proposed idea (for functions) it would have false for all elements beyond the end of the shorter array. 

 

 

wiebe@CARYA
Knight of NI

One use case is optional VI inputs.

 

So you have an array with values, and one or two other inputs that are arrays, but optional. When not wired, the defaults are used. This is most useful for Boolean arrays, but also numerics when 0 as default makes sense (like offsets). Even classes, when the class is an array of functors, and the default does nothing.

 

I'm not for or against the idea; all it saves is one index array. I do admit that when developing, once in a while I miss this kind of behaviour. But it doesn't happen that often. Really haven't made up my mind about this...

AristosQueue (NI)
NI Employee (retired)

Weibe: Can you show  me a block diagram where you are autoindexing over both of those arrays in the same For Loop? I think I get it, but I want to be sure.

wiebe@CARYA
Knight of NI

I've searched for all my for loops, but stopped at 700... I gave up searching for an example from the wild. Apparently, I usually find ways around it. It's not very elegant...

 

But here's a mockup:

Optional Auto Indexing.PNG

 

Just for completeness: this would save the caller from doing things like this:

Optional Auto Indexing usage.PNG

  

altenbach
Knight of NI
wiebe@CARYA
Knight of NI

I'd say this one is duplicate then?

Darren
Proven Zealot