Skip to content

Commit

Permalink
Improve type stability
Browse files Browse the repository at this point in the history
Wrapping N and K in Val in the base method of count_kmers
  • Loading branch information
AntonOresten committed Mar 24, 2024
1 parent 3848024 commit 5bb8db9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/count.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ function count_kmers!(kmer_array::KmerArray{N, K}, sequence; reset::Bool = true)
end

"""
count_kmers(sequence, K, T=Int, zeros=zeros; N=default_alphabet_size(eltype(sequence)))
count_kmers(sequence, [N,] K, T=Int, zeros=zeros)
"""
function count_kmers(sequence, K::Integer, T::Type{<:Real}=Int, zeros=zeros; N::Integer = default_alphabet_size(eltype(sequence)))
return count_kmers!(KmerArray(N, K, T, zeros), sequence; reset=false)
end
count_kmers(sequence, ::Val{N}, ::Val{K}, T::Type{<:Real}=Int, zeros=zeros) where {N, K} = count_kmers!(KmerArray(N, K, T, zeros), sequence)
count_kmers(sequence, N::Integer, K::Integer, args...) = count_kmers(sequence, Val(N), Val(K), args...)
count_kmers(sequence, K::Integer, args...) = count_kmers(sequence, default_alphabet_size(eltype(sequence)), K, args...)
2 changes: 1 addition & 1 deletion test/count.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
end

@testset "count_kmers" begin
@test count_kmers([2, 0, 3, 3, 0, 1, 0], 1, N=4) == KmerArray([3, 1, 1, 2])
@test count_kmers([2, 0, 3, 3, 0, 1, 0], 4, 1) == KmerArray([3, 1, 1, 2])
end

@test_throws ErrorException VectorizedKmers.default_alphabet_size(String)
Expand Down

2 comments on commit 5bb8db9

@AntonOresten
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register

Release notes:

  • Wrap N and K values in Val in count_kmers method to improve type stability and unnecessary allocations.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error while trying to register: "Tag with name v0.9.1 already exists and points to a different commit"

Please sign in to comment.