LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

simplify array by removing duplicates

Solved!
Go to solution

@JÞB wrote:

Not as neat as it could be.  Tip: Any time you find a comparison output wired to a case selector And the input to the compare is on a tunnel of that same case. Think about the Rube Goldberg thread you might show up as a victimSmiley Wink  String to Number functions work on arrays. Nice job though

Capture.PNG

 

EDIT: My eyes popped out when I look again.  Get rid of the Transpose and wire the "2" to the Col input leaving Row unwired will slice by column Smiley Very Happy

 


@Jeff sorry, i don't know why i didn't address you directly but in third person only

regarding the transpose ... lol .. thx, somehow i missed that very much too 😉

TIL "decimal string to number" works on arrays, never used it that way.

 

regarding the rube goldberg, i guess i don't understand you all that well there, could you provide a negative example please (not trolling, really curious)

... thinking a little more ... you mean, that i had the extra case structure which you put into the first one?

 

i guess all the "errors" show the way/stages i worked through the problem

 

that was fun 😉

 

and for posterity:

yay4.png

 

 

@altenbach very nice solution, will be studied, did not spend a thought about runtimes, and never used variants this way .. i really should regard them more as dictionaries


If Tetris has taught me anything, it's errors pile up and accomplishments disappear.
0 Kudos
Message 11 of 27
(2,100 Views)

could not edit my post anymore

yay5.png

 

OT: nice, was confused for a second .. the interface for picture upload changed between postings


If Tetris has taught me anything, it's errors pile up and accomplishments disappear.
Message 12 of 27
(2,092 Views)

@jwscs wrote:

could not edit my post anymore

yay5.png

 

OT: nice, was confused for a second .. the interface for picture upload changed between postings


 

Actually, if you look a lot harder

you had two case structures with the exact same conditions.  Found String Not? (Index -1, or default) and Found Index <0 = True/False.  Since the -1, Default and Less than 0=True, False are just plain the same for the output of Search 1D array.  You get an Honorable Mention on the R-G thread (I see you posted it yourself NICE!)

 

Well documented Explanation! Kudos

 

now, could you improve it?  (the optimizer in the compiler probably migrates this anyway BUT)

Spoiler
Slice the array outside the loop and convert the number as string to number auto-indexing the two arrays into the loop looks cleaner to a pre-optomized compiler LabVIEW Jockey like me.  But, I still learn some tricks from the best 'round here. (And often get to try new things that sometimes fail miserably)

"Should be" isn't "Is" -Jay
0 Kudos
Message 13 of 27
(2,086 Views)

yay7.png

i have not looked at the spoiler yet

but i am guessing, because i still know way to little about how the compiler optimizes stuff.

 

Update: seems this is what you had in mind

 

Update2: props to altenbach ... i like this solution more and more


If Tetris has taught me anything, it's errors pile up and accomplishments disappear.
Message 14 of 27
(2,080 Views)

@jwscs wrote:

yay7.png

i have not looked at the spoiler yet

but i am guessing, because i still know way to little about how the compiler optimizes stuff.

 

Update: seems this is what you had in mind

 

Update2: props to altenbach ... i like this solution more and more


Altenbach deserves the props!  and bingo on the modification.  Very few people know exactly what that option for the optimizer slide bar really does in the tools-options dialog (and many who do know won't tell you because its an undocumented feature)  What do the terms mean?

Capture Start.PNG

And which optimizations cut out when? Which exist?

This is a fairly simple vi and the code complexity is...  UNKNOWN! Snippets don't drop on the new interface.  Going over to Feedback to solve that!

 

But, the Code complexity  of that snip should "Rarely Limit" full optimization.  


"Should be" isn't "Is" -Jay
0 Kudos
Message 15 of 27
(2,066 Views)

So if we don't want to use variants, we could still do it at least without case structures. 😄

 

Here's my original variant version and below the version without case structures (LabVIEW 2014. Make sure it works correctly. One limitation is that the string entry cannot be an empty string).

 

 CountEntries

Download All
0 Kudos
Message 16 of 27
(2,060 Views)

Jump on Value Changed.vim my friend.Smiley LOL

 

I think the variant solution was more elegant as modified by jwscs.  A Benchmark could prove me wrong again, show I'm right again, or do both at the same time.  That difference would be trivial.  Yet, I do like to learn as I go.

 

If you can show a faster lookup than that Variant trick - You have been holding back!  

Spoiler
Nothing but love CA!

 I do not see the limitation (I learn something new every day) Unless its the (maybe ) error out of Variant to Data


"Should be" isn't "Is" -Jay
0 Kudos
Message 17 of 27
(2,051 Views)

@JÞB wrote:

 

I think the variant solution was more elegant as modified by jwscs.


I am not so sure. One of the problems is that allocating all these extra 1D arrays (2 strings and 1 numeric)  before the loop costs more memory. Mine works exclusively (and intentionally) on scalars inside the loop. He also has twice the number of auto-indexing input tunnels on the loop. One is enough. 😄

 

I haven't done any benchmarks and doubt there is a big difference in speed. For smallish inputs it does not matter anyway.

0 Kudos
Message 18 of 27
(2,045 Views)

@altenbach wrote:

@JÞB wrote:

 

I think the variant solution was more elegant as modified by jwscs.


I am not so sure. One of the problems is that allocating all these extra 1D arrays (2 strings and 1 numeric)  before the loop costs more memory. Mine works exclusively (and intentionally) on scalars inside the loop. He also has twice the number of auto-indexing input tunnels on the loop. One is enough. 😄

 

I haven't done any benchmarks and doubt there is a big difference in speed. For smallish inputs it does not matter anyway.


If LabVIEW ever offered ragged arrays... I'd grant that argument for this example.  UNLESS, I'm about to learn somethingSmiley LOL I had always assumed that the number of auto-indexing input tunnels into a Loop did not affect performance But, I usually deal with "Test" where the UUT is the bottleneck.  I don't dive to Si

 

Always willing to learn a lessonSmiley LOL.  


"Should be" isn't "Is" -Jay
0 Kudos
Message 19 of 27
(2,035 Views)

@JÞB wrote:

I had always assumed the the number of auto-indexing input tunnels into a Loop did not affect performance

I was thinking more about code readability. There is probably no difference in performance. (of course LabVIEW probably needs to check all the array sizes and pick the shortest to determine the number of iterations, but that's peanuts. :D)

0 Kudos
Message 20 of 27
(2,032 Views)