diff --git a/src/Utils.jl b/src/Utils.jl index 5215315d..8b4d29f7 100644 --- a/src/Utils.jl +++ b/src/Utils.jl @@ -3,14 +3,14 @@ export rownorm², nrmsd """ This function computes the 2-norm² of a rows of S for dense matrices. """ -function rownorm²(B::Transpose{T,S},row::Int) where {T,S<:DenseMatrix} +function rownorm²(B::Transpose{T,S},row::Int64) where {T,S<:DenseMatrix} A = B.parent U = real(eltype(A)) res::U = BLAS.nrm2(size(A,1), pointer(A,(LinearIndices(size(A)))[1,row]), 1)^2 return res end -function rownorm²(A::AbstractMatrix,row::Int) +function rownorm²(A::AbstractMatrix,row::Int64) T = real(eltype(A)) res = zero(T) @simd for n=1:size(A,2) @@ -19,19 +19,27 @@ function rownorm²(A::AbstractMatrix,row::Int) return res end -rownorm²(A::AbstractLinearOperator,row) = rownorm²(Matrix(A[row, :]), 1) -rownorm²(A::ProdOp{T, <:WeightingOp, matT}, row) where {T, matT} = A.A.weights[row]^2*rownorm²(A.B, row) +rownorm²(A::AbstractLinearOperator,row::Int64) = rownorm²(Matrix(A[row, :]), 1) +rownorm²(A::ProdOp{T, <:WeightingOp, matT}, row::Int64) where {T, matT} = A.A.weights[row]^2*rownorm²(A.B, row) """ This function computes the 2-norm² of a rows of S for sparse matrices. """ -function rownorm²(B::Transpose{T,S},row::Int) where {T,S<:SparseMatrixCSC} +function rownorm²(B::Transpose{T,S},row::Int64) where {T,S<:SparseMatrixCSC} A = B.parent U = real(eltype(A)) res::U = BLAS.nrm2(A.colptr[row+1]-A.colptr[row], pointer(A.nzval,A.colptr[row]), 1)^2 return res end +function rownorm²(A, rows) + res = zero(real(eltype(A))) + @simd for row in rows + res += rownorm²(A, row) + end + return res +end + ### dot_with_matrix_row ###