08-20-2013 04:05 AM
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.
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
Solved! Go to Solution.
08-20-2013 04:14 AM - edited 08-20-2013 04:15 AM
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:
I really don't understand where you want to use an "OR array" or "Power of 2" function here...
08-20-2013 05:24 AM
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:
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
08-20-2013 05:48 AM
08-20-2013 08:16 AM
Hi GerdW,
I tried that - and guess what: A benchmark showed it is the fastest solution!
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
08-20-2013 08:24 AM
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.
08-20-2013 08:37 AM
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