Oh. Well, now I understand what's going on. uniqind, like uniq, uses qsort to sort its input so you don't have to use a monotonically increasing input. Qsort is free to rearrange equal values, so it does. You could implement your own non-rearranging (but less efficient) sorting algorithm, and use "mysorti" instead of "qsorti". Bubble should work for that.
Hmmm. You could also use qsortvec to carry out the sorting operation: $qv = $a->(*1)->glue(0,xvals($a)); $ordered = $a->qsortvec; $mask = $ordered->((0)) != $a->((0))->range(-1,$a->dim(1),'e'); $mask->(0) .= 1; $ui_foo = which($mask); $ui = $ordered->((1),$ui_foo); That works because qsortvec will retain the order of duplicated items in the original list -- it's doing a lexicographic sort on vectors in the 0 dim, and the index parameter in column 1 breaks the degeneracy for equal elements. > On May 5, 2015, at 6:20 PM, Trevor Carey-Smith > <[email protected]> wrote: > > Hi Craig, > > On 05/06/2015 12:05 PM, Craig DeForest wrote: >> Try this (NOTE NiceSlice syntax): >> >> $mask = ($a != $a->range(-1,$a->dim(0),'e')); >> $mask->(0) .= 1; >> $ui = which($mask); > > Thanks, but the trouble with this method is it relies on the duplicated > values being next to each other. It won't work if $a=pdl(1,2,2,1,2,2) > for example. I'm using the result to index another vector so don't want > to sort it first. > > Regards, > Trevor. > >>> On May 5, 2015, at 5:13 PM, Trevor Carey-Smith >>> <[email protected]> wrote: >>> >>> I am using uniqind() but I need it to return the index of the *first* >>> unique value. As it is the function returns a seemingly random index: >>> >>> pdl> $a=pdl(1,2,2,2) >>> pdl> p $a->uniqind >>> [0 1] >>> pdl> $b=pdl(1,2,2,2,2) >>> pdl> p $b->uniqind >>> [0 2] >>> >>> Can anyone provide an efficient way of doing this? >>> >>> I have come up with a convoluted method that does not scale well (when >>> the vector is large and has many non-unique values): >>> >>> pdl> $tmp=$b->uniq->(*1)->minus($b,0) == 0 >>> pdl> p $tmp->mult(xvals($tmp)+1,0)->setvaltobad(0)->minimum->minus(1,0) >>> [0 1] >>> >>> My PDL version is old (v2.4.7), but it is installed on a server and they >>> would rather avoid upgrades... >>> >>> Thanks for any help, >>> Trevor. > > > ------------------------------------------------------------------------------ > One dashboard for servers and applications across Physical-Virtual-Cloud > Widest out-of-the-box monitoring support with 50+ applications > Performance metrics, stats and reports that give you Actionable Insights > Deep dive visibility with transaction tracing using APM Insight. > http://ad.doubleclick.net/ddm/clk/290420510;117567292;y > _______________________________________________ > pdl-general mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/pdl-general > ------------------------------------------------------------------------------ One dashboard for servers and applications across Physical-Virtual-Cloud Widest out-of-the-box monitoring support with 50+ applications Performance metrics, stats and reports that give you Actionable Insights Deep dive visibility with transaction tracing using APM Insight. http://ad.doubleclick.net/ddm/clk/290420510;117567292;y _______________________________________________ pdl-general mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/pdl-general
