Created
February 14, 2014 02:16
-
-
Save simonster/8994678 to your computer and use it in GitHub Desktop.
Strange error message
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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