Skip to content

Instantly share code, notes, and snippets.

@simonster
Created February 14, 2014 02:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simonster/8994678 to your computer and use it in GitHub Desktop.
Save simonster/8994678 to your computer and use it in GitHub Desktop.
Strange error message
import Base: unique, hash
immutable Prehashed
hash::Uint
end
hash(x::Prehashed) = x.hash
function unique{T}(A::AbstractArray{T,2}, dim::Int)
hashes = zeros(Uint, size(A, 1))
# Compute hash for each row
for j = 1:size(A, 1), i = 1:size(A, 2)
hashes[j] = bitmix(hashes[j], hash(A[j, i]))
end
# Collect index of first row for each hash
uniquerow = Array(Int, size(A, 1))
firstrow = Dict{Prehashed,Int}()
for j = 1:size(A, 1)
uniquerow[j] = get!(firstrow, Prehashed(hashes[j]), j)
end
uniquerows = collect(values(firstrow))
# println(typeof((ifelse(true,sort(uniquerows),1:size(A,1)), 1:size(A,2))))
A[ifelse(true,sort(uniquerows),1:size(A,1)), 1:size(A,2)]
end
sz = 10000
A = rand(div(sz*100, 2), div(sz, 100))
A = A[shuffle!(repmat(1:div(sz*100, 2), 2)), :]
unique(A, 1)
println("ran once")
unique(A, 1)
println("does not get here")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment