@@ -8,7 +8,6 @@ Standard library module for basic statistics functionality.
8
8
module Statistics
9
9
10
10
using LinearAlgebra, SparseArrays
11
- using SparseArrays: getcolptr
12
11
13
12
using Base: has_offset_axes, require_one_based_indexing
14
13
@@ -1004,7 +1003,6 @@ function centralize_sumabs2!(R::AbstractArray{S}, A::SparseMatrixCSC{Tv,Ti}, mea
1004
1003
isempty (R) || fill! (R, zero (S))
1005
1004
isempty (A) && return R
1006
1005
1007
- colptr = getcolptr (A)
1008
1006
rowval = rowvals (A)
1009
1007
nzval = nonzeros (A)
1010
1008
m = size (A, 1 )
@@ -1017,8 +1015,8 @@ function centralize_sumabs2!(R::AbstractArray{S}, A::SparseMatrixCSC{Tv,Ti}, mea
1017
1015
# Reduction along rows
1018
1016
@inbounds for col = 1 : n
1019
1017
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)
1022
1020
r += abs2 (nzval[j] - mu)
1023
1021
end
1024
1022
R[1 , col] = r
@@ -1027,7 +1025,7 @@ function centralize_sumabs2!(R::AbstractArray{S}, A::SparseMatrixCSC{Tv,Ti}, mea
1027
1025
# Reduction along columns
1028
1026
rownz = fill (convert (Ti, n), m)
1029
1027
@inbounds for col = 1 : n
1030
- @simd for j = colptr[ col] : colptr[col + 1 ] - 1
1028
+ @simd for j = nzrange (A, col)
1031
1029
row = rowval[j]
1032
1030
R[row, 1 ] += abs2 (nzval[j] - means[row])
1033
1031
rownz[row] -= 1
@@ -1040,7 +1038,7 @@ function centralize_sumabs2!(R::AbstractArray{S}, A::SparseMatrixCSC{Tv,Ti}, mea
1040
1038
# Reduction along a dimension > 2
1041
1039
@inbounds for col = 1 : n
1042
1040
lastrow = 0
1043
- @simd for j = colptr[ col] : colptr[col + 1 ] - 1
1041
+ @simd for j = nzrange (A, col)
1044
1042
row = rowval[j]
1045
1043
for i = lastrow+ 1 : row- 1
1046
1044
R[i, col] = abs2 (means[i, col])
0 commit comments