LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Comparing Clusters with NaN elements

Solved!
Go to solution

I have a cluster of data, and I wanted to see if it had changed. I keep a master copy and an active copy, and planned to use a check for change in data to activate/deactivate a Save button.

 

Problem is, if any values in the cluster are NaN, the "is equal" comparison will always be false, since NaN is never equal to NaN.

 

This took some head scratching to figure out, but in the meantime, I discovered that if you compare elements in a cluster, in stead of aggregates, you get an output that is a cluster of (clusters of arrays of...)  booleans, showing exactly which elements are different.

 

In my case, pre-conditioning the cluster values (converting NaNs to zeros) prior to comparison will fix the issue.

_____________
Creator of the BundleMagic plugin for LabVIEW!
0 Kudos
Message 1 of 26
(308 Views)

You could use the NaN/Path/Refnum? comparison to see if you have any NaNs or to check unequal values in the array.

 

snip.png

 

Replacing NaNs with zeros before comparison may be easier than multiple comparisons.

Message 2 of 26
(302 Views)

What kind of cluster is it? Mixed? All numeric? all scalar DBLs, etc?

 

You get a "not equal=true" if the NaN remains a NaN, or if a NaN changed to a valid number, or a valid number change to NaN. Only in the first case the cluster does not change.

 

Preconditioning by replacing all NaNs with zero is only a good idea if zero is a good sentinel value that can never occur as valid number. You could e.g. pick Inf instead.

Message 3 of 26
(275 Views)

Has a cluster element changed from NaN to a valid number (or vice-versa)?

This gets convoluted! Take the input clusters, run each through both = and ≠, (compare elements) to themselves (That is, compare each cluster to itself). Then Negate the XOR of each = and ≠.. This gives you TRUE elements where a NaN exists in each input cluster. XOR those and get a TRUE where only 1 NaN occurs in any element. Now we rigorously have solved for the "has NaN Changed?" Question.

 

OR "has NaN Changed?" with the two inputs compared for inequally. Now you have a cluster of "Value Changed?"

 

Cluster to Array, OR Array elements to get Value Changed? (Aggregate.)  Negate for Equals?


"Should be" isn't "Is" -Jay
Message 4 of 26
(266 Views)

The issue is that this is large complex cluster with nested clusters containing arrays, and NaNs are used as placeholders for some of the data, especially optional values that the use rmight update.

 

Pre-parsing it is just not worth the trouble (for now), so I'm going to forge informing the user that the data has changed.

 

It does make we wish there were a more general tool for this type of comparison, that accepted, at least optionally that NaN = NaN.

_____________
Creator of the BundleMagic plugin for LabVIEW!
0 Kudos
Message 5 of 26
(237 Views)

@littlesphaeroid wrote:

 

 

It does make we wish there were a more general tool for this type of comparison, that accepted, at least optionally that NaN = NaN.


That you have to argue with IEEE. The IEEE-754 Standard defines how floating point values work and NaN MUST fail every comparison.  So NaN = AnyValue is false ... even when AnyValue is Not a Number.  That's just the way it works! NaN just isn't anywhere on the numberline and cannot be evaluated as any real number since- it isn't a number! 

 

We don't know what NaN is but, we are sure that it is something other than a number. 


"Should be" isn't "Is" -Jay
Message 6 of 26
(231 Views)

@JÞB wrote:
The IEEE-754 Standard defines how floating point values work an NaN MUST fail every comparison.  

More precisely, it must fail every "equal" comparison. 🙂

 

EDIT:... fail every comparison except "not equal" 

Message 7 of 26
(226 Views)

@altenbach wrote:

@JÞB wrote:
The IEEE-754 Standard defines how floating point values work an NaN MUST fail every comparison.  

More precisely, it must fail every "equal" comparison. 🙂


It fails <, <=, =, => and > (I may have unintentionally suggested earlier that NaN ≠ NaN is false.  Oops,  NaN ≠ NaN is TRUE.  of course that simplifies the convoluted logic in my earlier post)  

 

THUS my once yearly post with bug quota is satisfied. 


"Should be" isn't "Is" -Jay
0 Kudos
Message 8 of 26
(222 Views)

Hi

 

NaN is a unique combination of 0 and 1's and you can compare it.

 

Like this :

 

softball_0-1727620377870.png

 

Regards

 

0 Kudos
Message 9 of 26
(202 Views)

@softball wrote:

NaN is a unique combination of 0 and 1's and you can compare it.


No, it is not unique. Many bit patterns translate to NaN:

 

Quote from here:

 

NaNs are encoded with the exponent field filled with ones (like infinity values), and some non-zero number in the significand field (to make them distinct from infinity values); this allows the definition of multiple distinct NaN values, depending on which bits are set in the significand field, but also on the value of the leading sign bit (but applications are not required to provide distinct semantics for those distinct NaN values).

 

With some effort, we can create many different NaN values.

 

 

As an illustration, have a look here:

 

altenbach_0-1727622845505.png

 

0 Kudos
Message 10 of 26
(194 Views)