Jump to content


Photo
- - - - -

Comparison VI Data Changed - Bug or Documentation misleading!?!


  • Please log in to reply
20 replies to this topic

#1 Götz Becker

Götz Becker

    Very Active

  • Premium Member
  • 136 posts
  • Location:Munich
  • Version:LabVIEW 2011
  • Since:2004

Posted 05 June 2012 - 12:06 PM

The Data Changed OpenG VI doesn't work with NaNs.
Basically it lacks isNaN checking. Since it is documented as TRUE if the data changed, it should work for NaNs as well.
data_changed_nan_bug.png


#2 crossrulz

crossrulz

    Extremely Active

  • Members
  • PipPipPipPip
  • 253 posts
  • Location:Cincinnati, OH
  • Version:LabVIEW 2011
  • Since:2004

Posted 05 June 2012 - 12:48 PM

It's the classic "NaN != NaN" scenario

#3 Götz Becker

Götz Becker

    Very Active

  • Premium Member
  • 136 posts
  • Location:Munich
  • Version:LabVIEW 2011
  • Since:2004

Posted 05 June 2012 - 02:04 PM

Sure it is... but for me, with my non native english knowledge, the documentation "...that will output a true if the data flowing into it has changed." reads as only a change will output a true. This includes proper NaN checking.


#4 asbo

asbo

    I have no idea what you're talking about... so:

  • V I Engineering, Inc.
  • 1,273 posts
  • Version:LabVIEW 2011
  • Since:2008

Posted 05 June 2012 - 03:40 PM

So tweak the VI and post a fixed version for inclusion :) All it should take is a couple of "Not A Number/Path/Refnum?" nodes in the DBL instances and you're set.

#5 Götz Becker

Götz Becker

    Very Active

  • Premium Member
  • 136 posts
  • Location:Munich
  • Version:LabVIEW 2011
  • Since:2004

Posted 05 June 2012 - 03:47 PM

Had to finish some real work... :-)

Here my proposal. proposal.png
Attached File  data_changed_DBL_NaN_aware.vi   7.81K   26 downloads

(Sry about the feedback node... I just don't like the while loop SR any more.)


#6 asbo

asbo

    I have no idea what you're talking about... so:

  • V I Engineering, Inc.
  • 1,273 posts
  • Version:LabVIEW 2011
  • Since:2008

Posted 05 June 2012 - 05:57 PM

Using your VI (sorta, I had to rewrite it), I changed the test case, I think the new implementation VI misses (non-NaN) -> (NaN).


value changed.dbl.test.png

I took a couple minutes to play with it, and think this covers each of the possible transition cases.

value changed.dbl.test.fixed.png

#7 Götz Becker

Götz Becker

    Very Active

  • Premium Member
  • 136 posts
  • Location:Munich
  • Version:LabVIEW 2011
  • Since:2004

Posted 05 June 2012 - 06:51 PM

Ah, damn I should have tested it better... thanks!


#8 Aristos Queue

Aristos Queue

    LV R&D: I write C++/# so you don't have to.

  • Premium Member
  • 2,620 posts
  • Location:Austin, TX
  • Version:LabVIEW 2011
  • Since:2000

Posted 06 June 2012 - 01:54 AM

And this, ladies and gentlemen, is why any time you have heard me speak in the last three years, I have harped on one point in almost every speech: the importance of buddying code. Nothing -- NOTHING -- does more to catch bugs and correct architecture mistakes that will bite you in the future than having a second set of eyes look over your code. If you have a team, buddy your code. If you are a lone developer or contractor, find someone else in a similar role in your community and buddy each other's code. It will help A LOT. I promise.

#9 crossrulz

crossrulz

    Extremely Active

  • Members
  • PipPipPipPip
  • 253 posts
  • Location:Cincinnati, OH
  • Version:LabVIEW 2011
  • Since:2004

Posted 06 June 2012 - 12:40 PM

I don't see why Gotz's code didn't work. I downloaded his VI and ran with the same case as asbo and it works perfectly for me. Did you break it before running your test, asbo?

Example_VI.png

#10 asbo

asbo

    I have no idea what you're talking about... so:

  • V I Engineering, Inc.
  • 1,273 posts
  • Version:LabVIEW 2011
  • Since:2008

Posted 06 June 2012 - 04:50 PM

And my public smear campaign is foiled...

I mentioned above, I used his snippet (which didn't include the subVI), so I probably didn't wire it up correctly. Sorry I couldn't be a poster boy, AQ :)

#11 crossrulz

crossrulz

    Extremely Active

  • Members
  • PipPipPipPip
  • 253 posts
  • Location:Cincinnati, OH
  • Version:LabVIEW 2011
  • Since:2004

Posted 06 June 2012 - 06:54 PM

Sorry I couldn't be a poster boy, AQ :)

You are probably still the poster boy since we had to use another buddy in order to find that the first buddy make a mistake. I'm just curious what your code originally looked like in order to get the results you did.

#12 asbo

asbo

    I have no idea what you're talking about... so:

  • V I Engineering, Inc.
  • 1,273 posts
  • Version:LabVIEW 2011
  • Since:2008

Posted 06 June 2012 - 10:35 PM

You are probably still the poster boy since we had to use another buddy in order to find that the first buddy make a mistake. I'm just curious what your code originally looked like in order to get the results you did.

It's in the opposite case of the diagram disable structure, so:
post-13461-0-72053400-1338920203-2.png

The answer is that I wired the "value" input's "Not a Number?" node to the NOR instead of the AND. Alas...

#13 crossrulz

crossrulz

    Extremely Active

  • Members
  • PipPipPipPip
  • 253 posts
  • Location:Cincinnati, OH
  • Version:LabVIEW 2011
  • Since:2004

Posted 06 June 2012 - 11:27 PM

So if this goes into OpenG, I would prefer Gotz's implementation (less logic). And Gotz, I prefer the FB node over the shift registers. They look cleaner for some reason.

#14 asbo

asbo

    I have no idea what you're talking about... so:

  • V I Engineering, Inc.
  • 1,273 posts
  • Version:LabVIEW 2011
  • Since:2008

Posted 06 June 2012 - 11:32 PM

So if this goes into OpenG, I would prefer Gotz's implementation (less logic). And Gotz, I prefer the FB node over the shift registers. They look cleaner for some reason.

I agree. However, I'd like to spend a few minutes and see if they benchmark differently. I fully expect the compiler to be smart enough to reduce mine.

#15 rolfk

rolfk

    LabVIEW Aficionado

  • Premium Member
  • 2,045 posts
  • Location:Netherlands
  • Version:LabVIEW 2011
  • Since:1992

Posted 07 June 2012 - 07:17 AM

I agree. However, I'd like to spend a few minutes and see if they benchmark differently. I fully expect the compiler to be smart enough to reduce mine.


Maybe LLVM does that, but I doubt that the original LabVIEW compiler did boolean logic reduction. Even then the difference is likely very small in comparison to the time needed for the Variant case for instance. Two logic operations versus six does not amount to many nanoseconds for sure on modern CPU architectures.

And it is clear from a quick glance what asbo did wrong when copying the code. He should have ORed the two isNaN? results, not one of them and the isEqual? result.

#16 Mellroth

Mellroth

    The 500 club

  • Members
  • PipPipPipPipPip
  • 535 posts
  • Version:LabVIEW 2011
  • Since:1995

Posted 07 June 2012 - 12:24 PM

What about using a simple typecast to U64 before checking diff?
DBL-changed.png

It will however return TRUE for differently represented NANs, but otherwise it should be fine.

/J

#17 rolfk

rolfk

    LabVIEW Aficionado

  • Premium Member
  • 2,045 posts
  • Location:Netherlands
  • Version:LabVIEW 2011
  • Since:1992

Posted 07 June 2012 - 02:46 PM

What about using a simple typecast to U64 before checking diff?
DBL-changed.png

It will however return TRUE for differently represented NANs, but otherwise it should be fine.

/J


That should work if the NaNs are guaranteed to come from LabVIEW itself but could fail because of the reason you mention, if the NaN could come from somewhere else such as a network bytestream.

#18 ShaunR

ShaunR

    LabVIEW Archetype

  • Members
  • PipPipPipPipPipPip
  • 2,224 posts
  • Version:LabVIEW 2009
  • Since:1994

Posted 07 June 2012 - 03:37 PM

That should work if the NaNs are guaranteed to come from LabVIEW itself but could fail because of the reason you mention, if the NaN could come from somewhere else such as a network bytestream.

That could be overcome with a bitmask check.
A positive attitude may not solve all your problems, but it will annoy enough people to make it worth the effort. (Herm Albright 1876-1944).

Founder and general mischief maker on www.labview-tools.com.
SQlite aficionado and websocket zealot.
If it 'aint in LabVIEW, then you 'aint got a clue!

#19 asbo

asbo

    I have no idea what you're talking about... so:

  • V I Engineering, Inc.
  • 1,273 posts
  • Version:LabVIEW 2011
  • Since:2008

Posted 07 June 2012 - 06:17 PM

That could be overcome with a bitmask check.

Then you'd need to find out if a type cast and mask are faster than logical comparisons. Depends on how much overhead there is in the LabVIEW operators for NaN but hopefully it's pretty ideal.

#20 rolfk

rolfk

    LabVIEW Aficionado

  • Premium Member
  • 2,045 posts
  • Location:Netherlands
  • Version:LabVIEW 2011
  • Since:1992

Posted 07 June 2012 - 08:27 PM

That could be overcome with a bitmask check.


I would almost bet my hat, that that is also what the "Is NaN/Refnum/.." function does. Which makes it likely a similar fast operation as the typecast with following bitmask operation. And because of that I would prefer the explicit and clear use of the Is NaN primitive any time above the much less clear "Advanced Operation" hack, even if it would save a few CPU cycles.