Skip to content

Commit d128b9c

Browse files
ranochaandreasnoack
authored andcommitted
WIP: Hilbert/Banach space structures (#27401)
* change vecnorm to norm; introduce opnorm for matrix norms * fixed vecnorm -> norm in tests for IterativeEigenolvers, complex, offsetarray * dot,vecdot -> inner; deprecate vecdot * add dot(x,y)=inner(x,y) * use dot/inner instead of vecdot in test/offsetarray.jl * replace length with length(LinearIndices(... * const dot = inner * norm(x,p) uses norm(xi) instead of norm(xi,p) * update docstrings of norm and inner * fixed isapprox for UniformScaling * rename inner to dot * fix norm of RowVector and some docstrings as suggested by @Sacha0 * additional test in 'VecOrMat of Vectors' * removed a test in 'VecOrMat of Vectors' * change vecdot for sparse matrices to dot * added news * fixed typo in NEWS and test in givens.jl
1 parent 71ec240 commit d128b9c

28 files changed

+322
-274
lines changed

NEWS.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,13 @@ This section lists changes that do not have deprecation warnings.
511511
This change makes `@schedule` redundant with `@async`, so `@schedule` has been
512512
deprecated ([#27164]).
513513

514+
* `norm(A::AbstractMatrix, p=2)` computes no longer the operator/matrix norm but the `norm` of `A`
515+
as for other iterables, i.e. as if it were a vector. Especially, `norm(A::AbstractMatrix)` is the
516+
Frobenius norm. To compute the operator/matrix norm, use the new function `opnorm` ([#27401]).
517+
518+
* `dot(u, v)` now acts recursively. Instead of `sum(u[i]' * v[i] for i in ...)`, it computes
519+
`sum(dot(u[i], v[i]) for i in ...)`, similarly to `vecdot` before ([#27401]).
520+
514521
Library improvements
515522
--------------------
516523

@@ -1274,6 +1281,8 @@ Deprecated or removed
12741281

12751282
* The functions `eigs` and `svds` have been moved to the `Arpack.jl` package ([#27616]).
12761283

1284+
* `vecdot` and `vecnorm` are deprecated in favor of `dot` and `norm`, respectively ([#27401]).
1285+
12771286
Command-line option changes
12781287
---------------------------
12791288

@@ -1610,3 +1619,4 @@ Command-line option changes
16101619
[#27189]: https://github.com/JuliaLang/julia/issues/27189
16111620
[#27212]: https://github.com/JuliaLang/julia/issues/27212
16121621
[#27248]: https://github.com/JuliaLang/julia/issues/27248
1622+
[#27401]: https://github.com/JuliaLang/julia/issues/27401

stdlib/LinearAlgebra/docs/src/index.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,6 @@ Linear algebra functions in Julia are largely implemented by calling functions f
299299
Base.:*(::AbstractMatrix, ::AbstractMatrix)
300300
Base.:\(::AbstractMatrix, ::AbstractVecOrMat)
301301
LinearAlgebra.dot
302-
LinearAlgebra.vecdot
303302
LinearAlgebra.cross
304303
LinearAlgebra.factorize
305304
LinearAlgebra.Diagonal
@@ -358,7 +357,7 @@ LinearAlgebra.diag
358357
LinearAlgebra.diagm
359358
LinearAlgebra.rank
360359
LinearAlgebra.norm
361-
LinearAlgebra.vecnorm
360+
LinearAlgebra.opnorm
362361
LinearAlgebra.normalize!
363362
LinearAlgebra.normalize
364363
LinearAlgebra.cond

stdlib/LinearAlgebra/src/LinearAlgebra.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ export
126126
qr!,
127127
lq,
128128
lq!,
129+
opnorm,
129130
rank,
130131
rdiv!,
131132
schur,
@@ -143,8 +144,6 @@ export
143144
triu,
144145
tril!,
145146
triu!,
146-
vecdot,
147-
vecnorm,
148147

149148
# Operators
150149
\,

stdlib/LinearAlgebra/src/dense.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
## BLAS cutoff threshold constants
66

77
const SCAL_CUTOFF = 2048
8-
const DOT_CUTOFF = 128
8+
#TODO const DOT_CUTOFF = 128
99
const ASUM_CUTOFF = 32
1010
const NRM2_CUTOFF = 32
1111

@@ -137,11 +137,11 @@ function norm(x::StridedVector{T}, rx::Union{UnitRange{TI},AbstractRange{TI}}) w
137137
GC.@preserve x BLAS.nrm2(length(rx), pointer(x)+(first(rx)-1)*sizeof(T), step(rx))
138138
end
139139

140-
vecnorm1(x::Union{Array{T},StridedVector{T}}) where {T<:BlasReal} =
141-
length(x) < ASUM_CUTOFF ? generic_vecnorm1(x) : BLAS.asum(x)
140+
norm1(x::Union{Array{T},StridedVector{T}}) where {T<:BlasReal} =
141+
length(x) < ASUM_CUTOFF ? generic_norm1(x) : BLAS.asum(x)
142142

143-
vecnorm2(x::Union{Array{T},StridedVector{T}}) where {T<:BlasFloat} =
144-
length(x) < NRM2_CUTOFF ? generic_vecnorm2(x) : BLAS.nrm2(x)
143+
norm2(x::Union{Array{T},StridedVector{T}}) where {T<:BlasFloat} =
144+
length(x) < NRM2_CUTOFF ? generic_norm2(x) : BLAS.nrm2(x)
145145

146146
"""
147147
triu!(M, k::Integer)
@@ -509,7 +509,7 @@ function exp!(A::StridedMatrix{T}) where T<:BlasFloat
509509
return copytri!(parent(exp(Hermitian(A))), 'U', true)
510510
end
511511
ilo, ihi, scale = LAPACK.gebal!('B', A) # modifies A
512-
nA = norm(A, 1)
512+
nA = opnorm(A, 1)
513513
Inn = Matrix{T}(I, n, n)
514514
## For sufficiently small nA, use lower order Padé-Approximations
515515
if (nA <= 2.1)
@@ -1370,8 +1370,8 @@ function cond(A::AbstractMatrix, p::Real=2)
13701370
end
13711371
throw(ArgumentError("p-norm must be 1, 2 or Inf, got $p"))
13721372
end
1373-
_cond1Inf(A::StridedMatrix{<:BlasFloat}, p::Real) = _cond1Inf(lu(A), p, norm(A, p))
1374-
_cond1Inf(A::AbstractMatrix, p::Real) = norm(A, p)*norm(inv(A), p)
1373+
_cond1Inf(A::StridedMatrix{<:BlasFloat}, p::Real) = _cond1Inf(lu(A), p, opnorm(A, p))
1374+
_cond1Inf(A::AbstractMatrix, p::Real) = opnorm(A, p)*opnorm(inv(A), p)
13751375

13761376
## Lyapunov and Sylvester equation
13771377

stdlib/LinearAlgebra/src/deprecated.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ using Base: @deprecate, depwarn
66

77
@deprecate cond(F::LinearAlgebra.LU, p::Integer) cond(convert(AbstractArray, F), p)
88

9+
# deprecate vecnorm in favor of norm
10+
@deprecate vecnorm norm
11+
12+
# deprecate vecdot in favor of dot
13+
@deprecate vecdot dot
14+
915
# PR #22188
1016
export cholfact, cholfact!
1117
@deprecate cholfact!(A::StridedMatrix, uplo::Symbol, ::Type{Val{false}}) cholesky!(Hermitian(A, uplo), Val(false))

0 commit comments

Comments
 (0)