Skip to content

Commit

Permalink
Allow using mode to pick most frequent string value.
Browse files Browse the repository at this point in the history
  • Loading branch information
orenbenkiki committed Apr 10, 2024
1 parent 4aa5aec commit 5aed40b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/v0.1.0/.documenter-siteinfo.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"documenter":{"julia_version":"1.10.2","generation_timestamp":"2024-04-09T17:27:42","documenter_version":"1.3.0"}}
{"documenter":{"julia_version":"1.10.2","generation_timestamp":"2024-04-10T08:11:56","documenter_version":"1.3.0"}}
8 changes: 8 additions & 0 deletions docs/v0.1.0/operations.html
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,14 @@ <h2 id="Reduction-operations">
</pre>
<p>Reduction operation that returns the most frequent value in the input (the &quot;mode&quot;).
</p>
<div class="admonition is-info">
<header class="admonition-header">Note
</header>
<div class="admonition-body">
<p>This operation supports strings; most operations do not.
</p>
</div>
</div>
</div>
</section>
</article>
Expand Down
2 changes: 1 addition & 1 deletion docs/v0.1.0/search_index.js

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions src/operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,10 @@ end
Mode()
Reduction operation that returns the most frequent value in the input (the "mode").
!!! note
This operation supports strings; most operations do not.
"""
struct Mode <: ReductionOperation end
@query_operation Mode
Expand All @@ -851,7 +855,7 @@ function Mode(::Token, ::Dict{String, Token})::Mode
return Mode()
end

function compute_reduction(operation::Mode, input::StorageMatrix{T})::StorageVector where {T <: StorageNumber}
function compute_reduction(operation::Mode, input::StorageMatrix)::StorageVector
output = Vector{reduction_result_type(operation, eltype(input))}(undef, size(input, 2))
@threads for column_index in 1:length(output)
column_vector = @view input[:, column_index]
Expand All @@ -860,7 +864,7 @@ function compute_reduction(operation::Mode, input::StorageMatrix{T})::StorageVec
return output
end

function compute_reduction(::Mode, input::StorageVector{T})::StorageNumber where {T <: StorageNumber}
function compute_reduction(::Mode, input::StorageVector)::StorageScalar
return mode(input)
end

Expand Down

0 comments on commit 5aed40b

Please sign in to comment.