Skip to content

Commit

Permalink
WIP: Hilbert/Banach space structures (#27401)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ranocha authored and andreasnoack committed Jun 19, 2018
1 parent 71ec240 commit d128b9c
Show file tree
Hide file tree
Showing 28 changed files with 322 additions and 274 deletions.
10 changes: 10 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,13 @@ This section lists changes that do not have deprecation warnings.
This change makes `@schedule` redundant with `@async`, so `@schedule` has been
deprecated ([#27164]).

* `norm(A::AbstractMatrix, p=2)` computes no longer the operator/matrix norm but the `norm` of `A`
as for other iterables, i.e. as if it were a vector. Especially, `norm(A::AbstractMatrix)` is the
Frobenius norm. To compute the operator/matrix norm, use the new function `opnorm` ([#27401]).

* `dot(u, v)` now acts recursively. Instead of `sum(u[i]' * v[i] for i in ...)`, it computes
`sum(dot(u[i], v[i]) for i in ...)`, similarly to `vecdot` before ([#27401]).

Library improvements
--------------------

Expand Down Expand Up @@ -1274,6 +1281,8 @@ Deprecated or removed

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

* `vecdot` and `vecnorm` are deprecated in favor of `dot` and `norm`, respectively ([#27401]).

Command-line option changes
---------------------------

Expand Down Expand Up @@ -1610,3 +1619,4 @@ Command-line option changes
[#27189]: https://github.com/JuliaLang/julia/issues/27189
[#27212]: https://github.com/JuliaLang/julia/issues/27212
[#27248]: https://github.com/JuliaLang/julia/issues/27248
[#27401]: https://github.com/JuliaLang/julia/issues/27401
3 changes: 1 addition & 2 deletions stdlib/LinearAlgebra/docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,6 @@ Linear algebra functions in Julia are largely implemented by calling functions f
Base.:*(::AbstractMatrix, ::AbstractMatrix)
Base.:\(::AbstractMatrix, ::AbstractVecOrMat)
LinearAlgebra.dot
LinearAlgebra.vecdot
LinearAlgebra.cross
LinearAlgebra.factorize
LinearAlgebra.Diagonal
Expand Down Expand Up @@ -358,7 +357,7 @@ LinearAlgebra.diag
LinearAlgebra.diagm
LinearAlgebra.rank
LinearAlgebra.norm
LinearAlgebra.vecnorm
LinearAlgebra.opnorm
LinearAlgebra.normalize!
LinearAlgebra.normalize
LinearAlgebra.cond
Expand Down
3 changes: 1 addition & 2 deletions stdlib/LinearAlgebra/src/LinearAlgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export
qr!,
lq,
lq!,
opnorm,
rank,
rdiv!,
schur,
Expand All @@ -143,8 +144,6 @@ export
triu,
tril!,
triu!,
vecdot,
vecnorm,

# Operators
\,
Expand Down
16 changes: 8 additions & 8 deletions stdlib/LinearAlgebra/src/dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
## BLAS cutoff threshold constants

const SCAL_CUTOFF = 2048
const DOT_CUTOFF = 128
#TODO const DOT_CUTOFF = 128
const ASUM_CUTOFF = 32
const NRM2_CUTOFF = 32

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

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

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

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

## Lyapunov and Sylvester equation

Expand Down
6 changes: 6 additions & 0 deletions stdlib/LinearAlgebra/src/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ using Base: @deprecate, depwarn

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

# deprecate vecnorm in favor of norm
@deprecate vecnorm norm

# deprecate vecdot in favor of dot
@deprecate vecdot dot

# PR #22188
export cholfact, cholfact!
@deprecate cholfact!(A::StridedMatrix, uplo::Symbol, ::Type{Val{false}}) cholesky!(Hermitian(A, uplo), Val(false))
Expand Down
Loading

0 comments on commit d128b9c

Please sign in to comment.