Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

once more unto the decomposition breach, dear friends! #27212

Merged
merged 23 commits into from
May 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,21 @@ This section lists changes that do not have deprecation warnings.
* `readuntil` now does *not* include the delimiter in its result, matching the
behavior of `readline`. Pass `keep=true` to get the old behavior ([#25633]).

* `lu` methods now return decomposition objects such as `LU` rather than
tuples of arrays or tuples of numbers ([#26997], [#27159], [#27212]).

* `schur` methods now return decomposition objects such as `Schur` and
`GeneralizedSchur` rather than tuples of arrays ([#26997], [#27159], [#27212]).

* `lq` methods now return decomposition objects such as `LQ`
rather than tuples of arrays ([#26997], [#27159], [#27212]).

* `qr` methods now return decomposition objects such as `QR`, `QRPivoted`,
and `QRCompactWY` rather than tuples of arrays ([#26997], [#27159], [#27212]).

* `svd` methods now return decomposition objects such as `SVD` and
`GeneralizedSVD` rather than tuples of arrays or tuples of numbers ([#26997], [#27159], [#27212]).

* `countlines` now always counts the last non-empty line even if it does not
end with EOL, matching the behavior of `eachline` and `readlines` ([#25845]).

Expand Down Expand Up @@ -688,6 +703,31 @@ Deprecated or removed
* The keyword `immutable` is fully deprecated to `struct`, and
`type` is fully deprecated to `mutable struct` ([#19157], [#20418]).

* `lufact`, `schurfact`, `lqfact`, `qrfact`, `ldltfact`, `svdfact`,
`bkfact`, `hessfact`, `eigfact`, and `cholfact` have respectively been
deprecated to `lu`, `schur`, `lq`, `qr`, `ldlt`, `svd`, `bunchkaufman`,
`hessenberg`, `eigen`, and `cholesky` ([#26997], [#27159], [#27212]).

* `lufact!`, `schurfact!`, `lqfact!`, `qrfact!`, `ldltfact!`, `svdfact!`,
`bkfact!`, `hessfact!`, and `eigfact!` have respectively been deprecated to
`lu!`, `schur!`, `lq!`, `qr!`, `ldlt!`, `svd!`, `bunchkaufman!`,
`hessenberg!`, and `eigen!` ([#26997], [#27159], [#27212]).

* `eig(A[, args...])` has been deprecated in favor of `eigen(A[, args...])`.
Whereas the former returns a tuple of arrays, the latter returns an `Eigen` object.
So for a direct replacement, use `(eigen(A[, args...])...,)`. But going forward,
consider using the direct result of `eigen(A[, args...])` instead, either
destructured into its components (`vals, vecs = eigen(A[, args...])`) or
as an `Eigen` object (`X = eigen(A[, args...])`) ([#26997], [#27159], [#27212]).

* `eig(A::AbstractMatrix, B::AbstractMatrix)` and `eig(A::Number, B::Number)`
have been deprecated in favor of `eigen(A, B)`. Whereas the former each return
a tuple of arrays, the latter returns a `GeneralizedEigen` object. So for a direct
replacement, use `(eigen(A, B)...,)`. But going forward, consider using the
direct result of `eigen(A, B)` instead, either destructured into its components
(`vals, vecs = eigen(A, B)`), or as a `GeneralizedEigen` object
(`X = eigen(A, B)`) ([#26997], [#27159], [#27212]).

* Indexing into multidimensional arrays with more than one index but fewer indices than there are
dimensions is no longer permitted when those trailing dimensions have lengths greater than 1.
Instead, reshape the array or add trailing indices so the dimensionality and number of indices
Expand Down
48 changes: 24 additions & 24 deletions doc/src/manual/arrays.md
Original file line number Diff line number Diff line change
Expand Up @@ -746,37 +746,37 @@ creating any temporaries, and by calling the appropriate LAPACK function with th
dimension size and stride parameters.

```julia-repl
julia> a = rand(10,10)
julia> a = rand(10, 10)
10×10 Array{Float64,2}:
0.561255 0.226678 0.203391 0.308912 … 0.750307 0.235023 0.217964
0.718915 0.537192 0.556946 0.996234 0.666232 0.509423 0.660788
0.493501 0.0565622 0.118392 0.493498 0.262048 0.940693 0.252965
0.0470779 0.736979 0.264822 0.228787 0.161441 0.897023 0.567641
0.343935 0.32327 0.795673 0.452242 0.468819 0.628507 0.511528
0.935597 0.991511 0.571297 0.74485 … 0.84589 0.178834 0.284413
0.160706 0.672252 0.133158 0.65554 0.371826 0.770628 0.0531208
0.306617 0.836126 0.301198 0.0224702 0.39344 0.0370205 0.536062
0.890947 0.168877 0.32002 0.486136 0.096078 0.172048 0.77672
0.507762 0.573567 0.220124 0.165816 0.211049 0.433277 0.539476
0.517515 0.0348206 0.749042 0.0979679 … 0.75984 0.950481 0.579513
0.901092 0.873479 0.134533 0.0697848 0.0586695 0.193254 0.726898
0.976808 0.0901881 0.208332 0.920358 0.288535 0.705941 0.337137
0.657127 0.0317896 0.772837 0.534457 0.0966037 0.700694 0.675999
0.471777 0.144969 0.0718405 0.0827916 0.527233 0.173132 0.694304
0.160872 0.455168 0.489254 0.827851 … 0.62226 0.0995456 0.946522
0.291857 0.769492 0.68043 0.629461 0.727558 0.910796 0.834837
0.775774 0.700731 0.700177 0.0126213 0.00822304 0.327502 0.955181
0.9715 0.64354 0.848441 0.241474 0.591611 0.792573 0.194357
0.646596 0.575456 0.0995212 0.038517 0.709233 0.477657 0.0507231

julia> b = view(a, 2:2:8,2:2:4)
4×2 SubArray{Float64,2,Array{Float64,2},Tuple{StepRange{Int64,Int64},StepRange{Int64,Int64}},false}:
0.537192 0.996234
0.736979 0.228787
0.991511 0.74485
0.836126 0.0224702
4×2 view(::Array{Float64,2}, 2:2:8, 2:2:4) with eltype Float64:
0.873479 0.0697848
0.0317896 0.534457
0.455168 0.827851
0.700731 0.0126213

julia> (q,r) = qr(b);
julia> (q, r) = qr(b);

julia> q
2 Array{Float64,2}:
-0.338809 0.78934
-0.464815 -0.230274
-0.625349 0.194538
-0.527347 -0.534856
4 LinearAlgebra.QRCompactWYQ{Float64,Array{Float64,2}}:
-0.722358 0.227524 -0.247784 -0.604181
-0.0262896 -0.575919 -0.804227 0.144377
-0.376419 -0.75072 0.540177 -0.0541979
-0.579497 0.230151 -0.00552346 0.781782

julia> r
2×2 Array{Float64,2}:
-1.58553 -0.921517
0.0 0.866567
-1.20921 -0.383393
0.0 -0.910506
```
4 changes: 2 additions & 2 deletions doc/src/manual/parallel-computing.md
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ we could compute the singular values of several large random matrices in paralle
```julia-repl
julia> M = Matrix{Float64}[rand(1000,1000) for i = 1:10];

julia> pmap(svd, M);
julia> pmap(svdvals, M);
```

Julia's [`pmap`](@ref) is designed for the case where each function call does a large amount
Expand Down Expand Up @@ -486,7 +486,7 @@ As an example, consider computing the singular values of matrices of different s
```julia-repl
julia> M = Matrix{Float64}[rand(800,800), rand(600,600), rand(800,800), rand(600,600)];

julia> pmap(svd, M);
julia> pmap(svdvals, M);
```

If one process handles both 800×800 matrices and another handles both 600×600 matrices, we will
Expand Down
4 changes: 2 additions & 2 deletions doc/src/manual/performance-tips.md
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ function norm(A)
if isa(A, Vector)
return sqrt(real(dot(A,A)))
elseif isa(A, Matrix)
return maximum(svd(A)[2])
return maximum(svdvals(A))
else
error("norm: invalid argument")
end
Expand All @@ -555,7 +555,7 @@ This can be written more concisely and efficiently as:

```julia
norm(x::Vector) = sqrt(real(dot(x,x)))
norm(A::Matrix) = maximum(svd(A)[2])
norm(A::Matrix) = maximum(svdvals(A))
```

## Write "type-stable" functions
Expand Down
4 changes: 2 additions & 2 deletions stdlib/Distributed/test/distributed_exec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -576,8 +576,8 @@ end
n = 10
as = [rand(4,4) for i in 1:n]
bs = deepcopy(as)
cs = collect(Distributed.pgenerate(x->(sleep(rand()*0.1); svdfact(x)), bs))
svdas = map(svdfact, as)
cs = collect(Distributed.pgenerate(x->(sleep(rand()*0.1); svd(x)), bs))
svdas = map(svd, as)
for i in 1:n
@test cs[i].U ≈ svdas[i].U
@test cs[i].S ≈ svdas[i].S
Expand Down
6 changes: 3 additions & 3 deletions stdlib/IterativeEigensolvers/src/IterativeEigensolvers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function _eigs(A, B;
sym = !iscmplx && issymmetric(A) && issymmetric(B)
nevmax = sym ? n-1 : n-2
if nevmax <= 0
throw(ArgumentError("input matrix A is too small. Use eigfact instead."))
throw(ArgumentError("input matrix A is too small. Use eigen instead."))
end
if nev > nevmax
@warn "Adjusting nev from $nev to $nevmax"
Expand Down Expand Up @@ -317,10 +317,10 @@ function _svds(X; nsv::Int = 6, ritzvec::Bool = true, tol::Float64 = 0.0, maxite
# left_sv = sqrt(2) * ex[2][ 1:size(X,1), ind ] .* sign.(ex[1][ind]')
if size(X, 1) >= size(X, 2)
V = ex[2]
U = qr(rmul!(X*V, Diagonal(inv.(svals))))[1]
U = Array(qr(rmul!(X*V, Diagonal(inv.(svals)))).Q)
else
U = ex[2]
V = qr(rmul!(X'U, Diagonal(inv.(svals))))[1]
V = Array(qr(rmul!(X'U, Diagonal(inv.(svals)))).Q)
end

# right_sv = sqrt(2) * ex[2][ size(X,1)+1:end, ind ]
Expand Down
22 changes: 11 additions & 11 deletions stdlib/IterativeEigensolvers/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ LinearAlgebra.A_mul_B!(rho2::StridedVector{T},Phi::CPM{T},rho::StridedVector{T})

let
# Generate random isometry
(Q,R) = qr(randn(100,50))
Q = reshape(Q,(50,2,50))
(Q, R) = qr(randn(100, 50))
Q = reshape(Array(Q), (50, 2, 50))
# Construct trace-preserving completely positive map from this
Phi = CPM(copy(Q))
(d,v,nconv,numiter,numop,resid) = eigs(Phi,nev=1,which=:LM)
Expand Down Expand Up @@ -189,16 +189,16 @@ end
S2 = svd(Array(A))

## singular values match:
@test S1[1].S ≈ S2[2][1:2]
@test S1[1].S ≈ S2.S[1:2]
@testset "singular vectors" begin
## 1st left singular vector
s1_left = sign(S1[1].U[3,1]) * S1[1].U[:,1]
s2_left = sign(S2[1][3,1]) * S2[1][:,1]
s2_left = sign(S2.U[3,1]) * S2.U[:,1]
@test s1_left ≈ s2_left

## 1st right singular vector
s1_right = sign(S1[1].V[3,1]) * S1[1].V[:,1]
s2_right = sign(S2[3][3,1]) * S2[3][:,1]
s2_right = sign(S2.V[3,1]) * S2.V[:,1]
@test s1_right ≈ s2_right
end
# Issue number 10329
Expand All @@ -213,7 +213,7 @@ end
end
@testset "passing guess for Krylov vectors" begin
S1 = svds(A, nsv = 2, v0=rand(eltype(A),size(A,2)))
@test S1[1].S ≈ S2[2][1:2]
@test S1[1].S ≈ S2.S[1:2]
end

@test_throws ArgumentError svds(A,nsv=0)
Expand All @@ -227,7 +227,7 @@ end
for j in 2:i
d[j] = d[1]
end
A = qr(randn(rng, 20, 20))[1]*Diagonal(d)*qr(randn(rng, 20, 20))[1]
A = qr(randn(rng, 20, 20)).Q*Diagonal(d)*qr(randn(rng, 20, 20)).Q
@testset "Number of singular values: $j" for j in 2:6
# Default size of subspace
F = svds(A, nsv = j, v0 = v0)
Expand All @@ -251,21 +251,21 @@ end
S2 = svd(Array(A))

## singular values match:
@test S1[1].S ≈ S2[2][1:2]
@test S1[1].S ≈ S2.S[1:2]
@testset "singular vectors" begin
## left singular vectors
s1_left = abs.(S1[1].U[:,1:2])
s2_left = abs.(S2[1][:,1:2])
s2_left = abs.(S2.U[:,1:2])
@test s1_left ≈ s2_left

## right singular vectors
s1_right = abs.(S1[1].V[:,1:2])
s2_right = abs.(S2[3][:,1:2])
s2_right = abs.(S2.V[:,1:2])
@test s1_right ≈ s2_right
end
@testset "passing guess for Krylov vectors" begin
S1 = svds(A, nsv = 2, v0=rand(eltype(A),size(A,2)))
@test S1[1].S ≈ S2[2][1:2]
@test S1[1].S ≈ S2.S[1:2]
end

@test_throws ArgumentError svds(A,nsv=0)
Expand Down
37 changes: 15 additions & 22 deletions stdlib/LinearAlgebra/docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ Legend:

### Matrix factorizations

| Matrix type | LAPACK | [`eig`](@ref) | [`eigvals`](@ref) | [`eigvecs`](@ref) | [`svd`](@ref) | [`svdvals`](@ref) |
| Matrix type | LAPACK | [`eigen`](@ref) | [`eigvals`](@ref) | [`eigvecs`](@ref) | [`svd`](@ref) | [`svdvals`](@ref) |
|:------------------------- |:------ |:------------- |:----------------- |:----------------- |:------------- |:----------------- |
| [`Symmetric`](@ref) | SY | | ARI | | | |
| [`Hermitian`](@ref) | HE | | ARI | | | |
Expand Down Expand Up @@ -312,47 +312,40 @@ LinearAlgebra.LowerTriangular
LinearAlgebra.UpperTriangular
LinearAlgebra.UniformScaling
LinearAlgebra.lu
LinearAlgebra.lufact
LinearAlgebra.lufact!
LinearAlgebra.lu!
LinearAlgebra.chol
LinearAlgebra.cholfact
LinearAlgebra.cholfact!
LinearAlgebra.cholesky
LinearAlgebra.cholesky!
LinearAlgebra.lowrankupdate
LinearAlgebra.lowrankdowndate
LinearAlgebra.lowrankupdate!
LinearAlgebra.lowrankdowndate!
LinearAlgebra.ldltfact
LinearAlgebra.ldltfact!
LinearAlgebra.ldlt
LinearAlgebra.ldlt!
LinearAlgebra.qr
LinearAlgebra.qr!
LinearAlgebra.qrfact
LinearAlgebra.qrfact!
LinearAlgebra.QR
LinearAlgebra.QRCompactWY
LinearAlgebra.QRPivoted
LinearAlgebra.lqfact!
LinearAlgebra.lqfact
LinearAlgebra.lq!
LinearAlgebra.lq
LinearAlgebra.bkfact
LinearAlgebra.bkfact!
LinearAlgebra.eig
LinearAlgebra.bunchkaufman
LinearAlgebra.bunchkaufman!
LinearAlgebra.eigvals
LinearAlgebra.eigvals!
LinearAlgebra.eigmax
LinearAlgebra.eigmin
LinearAlgebra.eigvecs
LinearAlgebra.eigfact
LinearAlgebra.eigfact!
LinearAlgebra.hessfact
LinearAlgebra.hessfact!
LinearAlgebra.schurfact
LinearAlgebra.schurfact!
LinearAlgebra.eigen
LinearAlgebra.eigen!
LinearAlgebra.hessenberg
LinearAlgebra.hessenberg!
LinearAlgebra.schur!
LinearAlgebra.schur
LinearAlgebra.ordschur
LinearAlgebra.ordschur!
LinearAlgebra.svdfact
LinearAlgebra.svdfact!
LinearAlgebra.svd
LinearAlgebra.svd!
LinearAlgebra.svdvals
LinearAlgebra.svdvals!
LinearAlgebra.Givens
Expand Down
Loading