unique with a dim argument actually computes this as byproduct but does not 
return it. All we need is an API.

On Monday, August 11, 2014 1:27:57 PM UTC-4, Jacob Quinn wrote:
>
> There's an open issue about it here: 
> https://github.com/JuliaLang/julia/issues/1845
>
> I've also played around with a simple version based on a Set:
>
> function uniqueind(C)
>     out = Int[]
>     seen = Set{eltype(C)}()
>     for i = 1:length(C)
>         @inbounds x = C[i]
>         if !in(x, seen)
>             push!(seen, x)
>             push!(out, i)
>         end
>     end
>     out
> end
>
>
> On Mon, Aug 11, 2014 at 1:22 PM, Peter Simon <[email protected] 
> <javascript:>> wrote:
>
>> Greetings.
>>
>> I didn't find any built-in function to return the indices for the unique 
>> rows in a matrix, so I tried rolling my own.  I looked at, but didn't 
>> understand, the highly macro-ized, arbitrary dimensional code in the 
>> built-in unique() function.  I did discover hashing, though, from looking 
>> at that code.  Here is what I have so far:
>>
>>  function uniquerowindices2{T}(a::Matrix{T})
>>      rowhash = Uint64[hash(a[k,:]) for k = 1:size(a,1)]
>>      hu = unique(rowhash)
>>      ind = zeros(Int,length(hu))
>>      k1 = 1
>>      for m = 1:length(ind)
>>          for k = k1:length(rowhash)
>>              if rowhash[k] == hu[m]
>>                  ind[m] = k
>>                  k1 = k
>>                  break
>>              end
>>          end
>>      end
>>      return ind
>>  end
>>
>> This is quite a bit faster than my first effort, where I was comparing 
>> rows, rather than row hashes, but I'm betting someone out there has a much 
>> better way.  Thanks in advance,
>>
>> --Peter    
>>
>
>

Reply via email to