Skip to content

Commit e3c757b

Browse files
committed
Register SignALSH as the default hash function for inner_prod similarity.
1 parent 6a1ba35 commit e3c757b

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

src/hashes/lshfunction.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,4 @@ Associate similarity functions with LSHFunction subtypes
7070
@register_similarity!(ℓ1, L1Hash)
7171
@register_similarity!(ℓ2, L2Hash)
7272
@register_similarity!(jaccard, MinHash)
73+
@register_similarity!(inner_prod, SignALSH)

src/hashes/mips_hash.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ LSHFunction and AsymmetricLSHFunction API compliance
230230
========================#
231231
index_hash(hashfn::MIPSHash, x) = MIPSHash_P(hashfn, x)
232232
query_hash(hashfn::MIPSHash, x) = MIPSHash_Q(hashfn, x)
233+
similarity(::MIPSHash) = inner_prod
233234

234235
n_hashes(hashfn::MIPSHash) = length(hashfn.shift)
235236
hashtype(::MIPSHash) = Vector{Int32}

test/test_lshfunction.jl renamed to test/hashes/test_lshfunction.jl

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Tests for the LSHFunction() function for constructing hash functions.
66

77
using Test, Random, LSH
88

9-
include("utils.jl")
9+
include(joinpath("..", "utils.jl"))
1010

1111
#==================
1212
Tests
@@ -40,6 +40,20 @@ Tests
4040
@test isa(hashfn, MinHash)
4141
end
4242

43+
@testset "Create inner product similarity hash function" begin
44+
hashfn = LSHFunction(inner_prod, 10; maxnorm=1)
45+
46+
@test similarity(hashfn) == inner_prod
47+
@test n_hashes(hashfn) == 10
48+
@test isa(hashfn, SignALSH)
49+
50+
# Test that same exceptions are thrown for invalid construction of
51+
# SignALSH
52+
@test_throws ErrorException LSHFunction(inner_prod, -1; maxnorm=10)
53+
@test_throws ErrorException LSHFunction(inner_prod; m=0, maxnorm=10)
54+
@test_throws ErrorException LSHFunction(inner_prod)
55+
end
56+
4357
@testset "Call LSHFunction() with invalid similarity function" begin
4458
import LinearAlgebra: dot, norm
4559
my_cossim(x,y) = dot(x,y) / (norm(x) * norm(y))

test/runtests.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ include(joinpath("hashes", "test_minhash.jl"))
2424
include(joinpath("hashes", "test_lphash.jl"))
2525
include(joinpath("hashes", "test_mips_hash.jl"))
2626
include(joinpath("hashes", "test_sign_alsh.jl"))
27-
28-
include("test_lshfunction.jl")
27+
include(joinpath("hashes", "test_lshfunction.jl"))
2928

3029
include(joinpath("function_hashing", "test_monte_carlo.jl"))
3130
include(joinpath("function_hashing", "test_chebhash.jl"))

0 commit comments

Comments
 (0)