From 4fcec287a854f16db68a642c8649c1fbadc3f4ae Mon Sep 17 00:00:00 2001 From: "Velimir (monty) Vesselinov" Date: Sat, 13 Jul 2024 16:24:45 -0600 Subject: [PATCH] normalizearray! --- src/NMFkMatrix.jl | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/NMFkMatrix.jl b/src/NMFkMatrix.jl index 9bf7a4e..f40c5af 100644 --- a/src/NMFkMatrix.jl +++ b/src/NMFkMatrix.jl @@ -129,16 +129,26 @@ function normalizearray(a::AbstractArray, dim::Integer; kw...) return normalizearray!(copy(a), dim; kw...) end -function normalizearray!(a::AbstractArray, dim::Integer; rev::Bool=false, log::Bool=false) +function normalizearray!(a::AbstractArray, dim::Integer; rev::Bool=false, log::Bool=false, logv::AbstractVector=[]) n = size(a, dim) - logv = falses(n) - if log + if length(logv) == 0 + logv = falses(n) + if log + for i = 1:n + nt = ntuple(k->(k == dim ? (i:i) : Colon()), ndims(a)) + s = StatsBase.skewness(vec(a[nt...])) + if s > 1 + a[nt...] .= NMFk.log10s(a[nt...]) + logv[i] = true + end + end + end + else + @assert length(logv) == n for i = 1:n nt = ntuple(k->(k == dim ? (i:i) : Colon()), ndims(a)) - s = StatsBase.skewness(vec(a[nt...])) - if s > 1 + if logv[i] a[nt...] .= NMFk.log10s(a[nt...]) - logv[i] = true end end end