Skip to content

Commit

Permalink
Merge pull request #168 from JuliaStats/andreasnoack-patch-2
Browse files Browse the repository at this point in the history
Implement one-argument cov2cor!
  • Loading branch information
ViralBShah authored Oct 21, 2024
2 parents c3721ed + 6e76739 commit 1b67c17
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 @@ -640,7 +640,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 @@ -696,7 +696,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 1b67c17

Please sign in to comment.