Skip to content

Commit 6a1ba35

Browse files
committed
Add check that n_hashes is positive to the SignALSH constructor.
1 parent baaa9a5 commit 6a1ba35

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/hashes/sign_alsh.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ end
4343
quote
4444
if maxnorm < 0
4545
"maxnorm must be non-negative" |> ErrorException |> throw
46+
elseif n_hashes 0
47+
"n_hashes must be positive" |> ErrorException |> throw
4648
elseif m 0
4749
"m must be positive" |> ErrorException |> throw
4850
end
@@ -202,4 +204,5 @@ index_hash(h::SignALSH, x) = SignALSH_P(h, x)
202204
query_hash(h::SignALSH, x) = SignALSH_Q(h, x)
203205

204206
n_hashes(h::SignALSH) = size(h.coeff_A, 1)
207+
similarity(::SignALSH) = inner_prod
205208
hashtype(::SignALSH) = BitArray{1}

test/hashes/test_sign_alsh.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ Tests
2121
hashfn = SignALSH(; dtype=Float64, maxnorm=1)
2222
@test isa(hashfn, SignALSH{Float64})
2323

24+
# n_hashes must be positive
25+
@test_throws ErrorException SignALSH(-1; maxnorm=1)
26+
@test_throws ErrorException SignALSH( 0; maxnorm=1)
27+
2428
# maxnorm must be specified and non-negative
2529
@test_throws ErrorException SignALSH()
2630
@test_throws ErrorException SignALSH(; maxnorm=-1)

0 commit comments

Comments
 (0)