LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Get all different values in an array - "or array elements" doesn't work with I32

Solved!
Go to solution

Hi,

 

I just found out that "or array elements" doesn't work with a 1D array of integer values. I had not expected that.

I did a semi-quick forum search and didn't find a pointer to an efficient solution. Can someone give me a hint?

 

Taking a step back my original intent is to list all values that show up in an integer array.

I thought if I converted the numbers to powers of 2 and or array elements I had solved the problem at hand - only to find out that doesn't work. Smiley Surprised

If someone could propose a different approach I'd be happy too.

I should mention that execution time is a factor here - I need fast code, but all suggestions are welcome as they might get me started.

 

Regards Florian

0 Kudos
Message 1 of 7
(4,244 Views)

Hi Florian,

 

whenever you "think" of some programming you should attach atleast a picture of your VI...

 

This would be the simple (non-optimized) approach to filter unique values of an input array:

check.png

I really don't understand where you want to use an "OR array" or "Power of 2" function here...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 7
(4,239 Views)

Thank you for posting GerdW,

 

you are right of course - I thought I had nothing to show. But pictures speak more than 1000 words.

I thought this would be the easiest code to find out what values the array produced and pretty efficient at that:

 

or I32 array.png

 

I should mention that I don't have to cover a huge range of numbers - so wasting space by upconverting the numbers to powers of two isn't an issue.

Your vi gave me an idea - I could make a bucket brigade version of that. That wouldn't be a bad start.

 

Regards Florian

0 Kudos
Message 3 of 7
(4,215 Views)
Solution
Accepted by topic author Florian.Ludwig

Hi Florian,

 

try that:

check.png

It seems the OR array" function is polymorph (as written in the context help), but doesn't handle I32 arrays. Atleast the error message implies just that...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 4 of 7
(4,208 Views)

Hi GerdW,

 

I tried that - and guess what: A benchmark showed it is the fastest solution! Smiley Very Happy

I must admit I had dismissed the simplest solution because I thought I could come up with a custom made solution with the info I had about what my input array would look like.

Simplicity rules, and you should never guess when it comes to performance. A benchmark has to be made!

 

Seems like the "or array elements" only works with different dimensions of Boolean arrays.

 

Regards

Florian

0 Kudos
Message 5 of 7
(4,188 Views)

It is usually best to just keep it as simple as possible.  What do you think the code in the OR Array Elements does?  I imagine it is just a simple FOR loop with a variable to keep the latest OR.  So I would do what GerdW just showed with the FOR loop.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 6 of 7
(4,184 Views)

You definitely have a point there.

 

I thought that the primitive might be faster though maybe due to some internal optimization that reduces loop overhead.

Additionally as I am an engineer turned programmer I couldn't dismiss the possibility there is an algorithm to mass OR more efficiently than just looping through it all that I am not aware of.

Like stopping to care for bits that already turned out as a 1 in previous iterations or something.

 

Also, there are some qualities to my input data that would take some time to explain which made me think I could optimize the algorithm (like numbers will mostly be in blocks etc.).

 

Regards

Florian

0 Kudos
Message 7 of 7
(4,175 Views)