@@ -8,7 +8,6 @@ Standard library module for basic statistics functionality.
88module Statistics
99
1010using LinearAlgebra, SparseArrays
11- using SparseArrays: getcolptr
1211
1312using Base: has_offset_axes, require_one_based_indexing
1413
@@ -1004,7 +1003,6 @@ function centralize_sumabs2!(R::AbstractArray{S}, A::SparseMatrixCSC{Tv,Ti}, mea
10041003 isempty (R) || fill! (R, zero (S))
10051004 isempty (A) && return R
10061005
1007- colptr = getcolptr (A)
10081006 rowval = rowvals (A)
10091007 nzval = nonzeros (A)
10101008 m = size (A, 1 )
@@ -1017,8 +1015,8 @@ function centralize_sumabs2!(R::AbstractArray{S}, A::SparseMatrixCSC{Tv,Ti}, mea
10171015 # Reduction along rows
10181016 @inbounds for col = 1 : n
10191017 mu = means[col]
1020- r = convert (S, (m- colptr[ col+ 1 ] + colptr[col] )* abs2 (mu))
1021- @simd for j = colptr[ col] : colptr[col + 1 ] - 1
1018+ r = convert (S, (m - length ( nzrange (A, col)) )* abs2 (mu))
1019+ @simd for j = nzrange (A, col)
10221020 r += abs2 (nzval[j] - mu)
10231021 end
10241022 R[1 , col] = r
@@ -1027,7 +1025,7 @@ function centralize_sumabs2!(R::AbstractArray{S}, A::SparseMatrixCSC{Tv,Ti}, mea
10271025 # Reduction along columns
10281026 rownz = fill (convert (Ti, n), m)
10291027 @inbounds for col = 1 : n
1030- @simd for j = colptr[ col] : colptr[col + 1 ] - 1
1028+ @simd for j = nzrange (A, col)
10311029 row = rowval[j]
10321030 R[row, 1 ] += abs2 (nzval[j] - means[row])
10331031 rownz[row] -= 1
@@ -1040,7 +1038,7 @@ function centralize_sumabs2!(R::AbstractArray{S}, A::SparseMatrixCSC{Tv,Ti}, mea
10401038 # Reduction along a dimension > 2
10411039 @inbounds for col = 1 : n
10421040 lastrow = 0
1043- @simd for j = colptr[ col] : colptr[col + 1 ] - 1
1041+ @simd for j = nzrange (A, col)
10441042 row = rowval[j]
10451043 for i = lastrow+ 1 : row- 1
10461044 R[i, col] = abs2 (means[i, col])
0 commit comments