Skip to content

Commit

Permalink
Include percent of true boolean values in messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
orenbenkiki committed Apr 11, 2024
1 parent 379e7e1 commit b33b302
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 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-11T10:26:28","documenter_version":"1.3.0"}}
{"documenter":{"julia_version":"1.10.2","generation_timestamp":"2024-04-11T10:54:13","documenter_version":"1.3.0"}}
20 changes: 14 additions & 6 deletions src/messages.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ function depict(value::Symbol)::String
return ":$(value)"
end

function depict(value::AbstractVector)::String
return depict_vector(value, "")
function depict(vector::AbstractVector)::String
return depict_array(vector, depict_vector(vector, ""))
end

function depict_vector(vector::SparseArrays.ReadOnly, prefix::AbstractString)::String
Expand Down Expand Up @@ -129,7 +129,7 @@ function depict_vector_size(vector::AbstractVector, kind::AbstractString)::Strin
end

function depict(matrix::AbstractMatrix)::String
return depict_matrix(matrix, ""; transposed = false)
return depict_array(matrix, depict_matrix(matrix, ""; transposed = false))
end

function depict_matrix(matrix::SparseArrays.ReadOnly, prefix::AbstractString; transposed::Bool = false)::String
Expand Down Expand Up @@ -171,16 +171,24 @@ function depict_matrix(matrix::AbstractMatrix, ::AbstractString; transposed::Boo
end
end

function depict(value::AbstractArray)::String
function depict(array::AbstractArray)::String
text = ""
for dim_size in size(value)
for dim_size in size(array)
if text == ""
text = "$(dim_size)"
else
text = "$(text) x $(dim_size)"
end
end
return "$(text) x $(eltype(value)) ($(typeof(value)))"
return depict_array(array, "$(text) x $(eltype(array)) ($(typeof(array)))")
end

function depict_array(array::AbstractArray, text::String)::String
if eltype(array) == Bool
trues = sum(array) # NOJET
text *= " ($(trues) true, $(depict_percent(trues, length(array))))"
end
return text
end

"""
Expand Down
6 changes: 3 additions & 3 deletions test/example_data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ function test_description(
batch.partial: 20 x String (Dense)
type: 20 x String (Dense)
gene:
lateral: 10 x Bool (Dense)
marker: 10 x Bool (Dense)
lateral: 10 x Bool (Dense) (7 true, 70%)
marker: 10 x Bool (Dense) (4 true, 40%)
module: 10 x String (Dense)
noisy: 10 x Bool (Dense)
noisy: 10 x Bool (Dense) (4 true, 40%)
type:
color: 3 x String (Dense)
matrices:
Expand Down

0 comments on commit b33b302

Please sign in to comment.