Skip to content

Commit

Permalink
Merge pull request #21 from EcoJulia/mkb/patch_sums
Browse files Browse the repository at this point in the history
patch rowsums and colsums
  • Loading branch information
mkborregaard authored Oct 14, 2021
2 parents 3824b30 + 913b74f commit 669426b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/Interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ thingnames(asm::AbstractAssemblage) = thingnames(things(asm))
nzrows(a::AbstractMatrix) = findall(vec(sum(a, dims = 2) .> 0))
nzcols(a::AbstractMatrix) = findall(vec(sum(a, dims = 1) .> 0))
nnz(a::AbstractArray) = sum(a .> 0)
colsum(x) = sum(x, dims = 1)
rowsum(x) = sum(x, dims = 2)

occurring(asm::AbstractAssemblage) = occurring(occurrences(asm))
occurring(a::AbstractMatrix) = nzrows(a)
occurring(asm::AbstractAssemblage, idx) = occurring(occurrences(asm), asindices(idx, placenames(asm)))
occurring(a::AbstractMatrix) = nzrows(a)

occupied(asm::AbstractAssemblage) = occupied(occurrences(asm))
occupied(asm::AbstractAssemblage, idx) = occupied(occurrences(asm), asindices(idx, thingnames(asm)))
Expand All @@ -58,11 +60,11 @@ placeoccurrences(asm::AbstractAssemblage, idx) = placeoccurrences(occurrences(as
placeoccurrences(mat::AbstractMatrix, idx) = view(mat, :, idx) # make certain that the view implementation also takes thing or place names

richness(asm::AbstractAssemblage) = richness(occurrences(asm))
richness(a::AbstractMatrix{Bool}) = collect(vec(sum(a, dims = 1)))
richness(a::AbstractMatrix{Bool}) = collect(vec(colsum(a)))
richness(a::AbstractMatrix) = collect(vec(mapslices(nnz, a, dims = 1)))

occupancy(asm::AbstractAssemblage) = occupancy(occurrences(asm))
occupancy(a::AbstractMatrix{Bool}) = collect(vec(sum(a, dims=2)))
occupancy(a::AbstractMatrix{Bool}) = collect(vec(rowsum(a)))
occupancy(a::AbstractMatrix) = collect(vec(mapslices(nnz, a, dims=2)))

nrecords(asm::AbstractAssemblage) = nrecords(occurrences(asm))
Expand Down
4 changes: 2 additions & 2 deletions src/PlotRecipes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ RecipesBase.@recipe function f(var::AbstractVector, pnt::AbstractPoints)
cd[:,1], cd[:,2]
end

RecipesBase.@recipe function f(asm::AbstractAssemblage; occupied = true)
RecipesBase.@recipe function f(asm::AbstractAssemblage; showempty = false)
var = richness(asm)
if occupied
if !showempty
var = [Float64(v) for v in var]
(var[var.==0] .= NaN)
end
Expand Down

0 comments on commit 669426b

Please sign in to comment.