LabVIEW Idea Exchange

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

Better polymorphic operations on waveforms

Status: New

After looking at the problem encountered here, it turns out that LabVIEW seems to make some insane choices when mixing a waveform with simple datatypes. Some behavior is good and intuitive. For example multiplying a waveform with a scalar applies the multiplication to the Y component only, because it would not make sense to e.g. also multiply the t0 or dt values.

 

It is less clear what should happen if multiplying a waveform with an array. Intuitively, one would expect something similar to the above, where the Y component is multiplied with the array. Unfortunately, LabVIEW chooses something else: It creates a huge array of waveforms, one for each element in the array. (as if wrapping a FOR loop around it, see image). If the waveform and the array both have thousands of elements, we can easily blow the lid off all available memory as in the quoted case. Pop! 😄 But the code looks so innocent!

 

 

I suggest that operations mixing waveform and simple datatypes (scalars, arrays) simply act on the Y component as shown.

 

(not sure how much existing code this would break, but it actually might fix some existing code!!! :D)

2 Comments
Darin.K
Trusted Enthusiast

I am inclined to have the VI break and make the programmer spell it out.  This would be an improvement since it would be a little more intuitive but still too idiomatic for my taste. 

altenbach
Knight of NI

> I am inclined to have the VI break ...

 

Agreed. More obvious when upgrading existing code than silently change the functionality to a different outcome.

 

Interstingly, if you hover over the waveform coercion dot in the middle example, it says that it expects an array of waveforms. Why would it coerce to an infinitely sized array fo waveforms? If it would instead coerce to an array of waveforms with a single array element, we would not have the memory problem (but it would probably be equally useless). 😉