Skip to content

Commit

Permalink
Implement one-argument cov2cor!
Browse files Browse the repository at this point in the history
By adding a default value for `xsd`.
  • Loading branch information
andreasnoack authored May 26, 2024
1 parent 9addbb8 commit 6e76739
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Statistics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ clampcor(x) = x

# cov2cor!

function cov2cor!(C::AbstractMatrix{T}, xsd::AbstractArray) where T
function cov2cor!(C::AbstractMatrix{T}, xsd::AbstractArray=sqrt.(view(C, diagind(C)))) where T
require_one_based_indexing(C, xsd)
nx = length(xsd)
size(C) == (nx, nx) || throw(DimensionMismatch("inconsistent dimensions"))
Expand Down Expand Up @@ -695,7 +695,7 @@ corzm(x::AbstractVector{T}) where {T} =
T === Missing ? missing : one(float(nonmissingtype(T)))
function corzm(x::AbstractMatrix, vardim::Int=1)
c = unscaled_covzm(x, vardim)
return cov2cor!(c, collect(sqrt(c[i,i]) for i in 1:min(size(c)...)))
return cov2cor!(c)
end
corzm(x::AbstractVector, y::AbstractMatrix, vardim::Int=1) =
cov2cor!(unscaled_covzm(x, y, vardim), sqrt(sum(abs2, x)), sqrt!(sum(abs2, y, dims=vardim)))
Expand Down

0 comments on commit 6e76739

Please sign in to comment.