diff --git a/base/docs/Docs.jl b/base/docs/Docs.jl index 025975aab2e8b..4d9551f83762d 100644 --- a/base/docs/Docs.jl +++ b/base/docs/Docs.jl @@ -187,7 +187,8 @@ catdoc(xs...) = vcat(xs...) # Type Documentation isdoc(x) = isexpr(x, :string, AbstractString) || - (isexpr(x, :macrocall) && endswith(string(x.args[1]), "_str")) + (isexpr(x, :macrocall) && x.args[1] == symbol("@doc_str")) || + (isexpr(x, :call) && x.args[1] == Expr(:., Base.Markdown, QuoteNode(:doc_str))) dict_expr(d) = :(Dict($([:($(Expr(:quote, f)) => $d) for (f, d) in d]...))) diff --git a/base/docs/helpdb.jl b/base/docs/helpdb.jl index a3b1391fb43cd..cdea57e776a69 100644 --- a/base/docs/helpdb.jl +++ b/base/docs/helpdb.jl @@ -10692,7 +10692,7 @@ Store values from array `X` within some subset of `A` as specified by `inds`. setindex!(collection, value, key...) -Store the given value at the given key or index within a collection. The syntax `a[i,j,...] = x` is converted by the compiler to `setindex!(a, x, i, j, ...)`. +Store the given value at the given key or index within a collection. The syntax `a[i,j,...] = x` is converted by the compiler to `(setindex!(a, x, i, j, ...); x)`. """ setindex! diff --git a/base/linalg/lu.jl b/base/linalg/lu.jl index 805a9a397e17f..f3c9f9757dbc0 100644 --- a/base/linalg/lu.jl +++ b/base/linalg/lu.jl @@ -210,6 +210,7 @@ function logdet{T<:Complex,S}(A::LU{T,S}) end inv!{T<:BlasFloat,S<:StridedMatrix}(A::LU{T,S}) = @assertnonsingular LAPACK.getri!(A.factors, A.ipiv) A.info +inv{T<:BlasFloat,S<:StridedMatrix}(A::LU{T,S}) = inv!(LU(copy(A.factors), copy(A.ipiv), copy(A.info))) cond{T<:BlasFloat,S<:StridedMatrix}(A::LU{T,S}, p::Number) = inv(LAPACK.gecon!(p == 1 ? '1' : 'I', A.factors, norm((A[:L]*A[:U])[A[:p],:], p))) cond(A::LU, p::Number) = norm(A[:L]*A[:U],p)*norm(inv(A),p) diff --git a/base/markdown/Markdown.jl b/base/markdown/Markdown.jl index 4d41816fdc878..3abe1b15d922c 100644 --- a/base/markdown/Markdown.jl +++ b/base/markdown/Markdown.jl @@ -50,8 +50,10 @@ macro md_str(s, t...) mdexpr(s, t...) end +doc_str(md, file, mod) = (md.meta[:path] = file; md.meta[:module] = mod; md) + macro doc_str(s, t...) - docexpr(s, t...) + :(doc_str($(mdexpr(s, t...)), @__FILE__, current_module())) end function Base.display(d::Base.REPL.REPLDisplay, md::Vector{MD}) diff --git a/test/docs.jl b/test/docs.jl index b1067aa6cb393..54c7aadf80524 100644 --- a/test/docs.jl +++ b/test/docs.jl @@ -95,6 +95,15 @@ t(::Int, ::Any) "t-3" t{S <: Integer}(::S) +"FieldDocs" +type FieldDocs + "one" + one + doc"two" + two + three +end + end import Base.Docs: meta @@ -157,6 +166,11 @@ end @test @doc(DocsTest.t(::Int, ::Any)) == doc"t-2" @test @doc(DocsTest.t{S <: Integer}(::S)) == doc"t-3" +let fields = meta(DocsTest)[DocsTest.FieldDocs].fields + @test haskey(fields, :one) && fields[:one] == doc"one" + @test haskey(fields, :two) && fields[:two] == doc"two" +end + # issue 11993 # Check if we are documenting the expansion of the macro macro m1_11993() diff --git a/test/linalg/lu.jl b/test/linalg/lu.jl index 3b451ee330b97..6c96ee03b8c85 100644 --- a/test/linalg/lu.jl +++ b/test/linalg/lu.jl @@ -3,6 +3,7 @@ debug = false using Base.Test +import Base.LinAlg.BlasInt, Base.LinAlg.BlasFloat n = 10 @@ -32,6 +33,11 @@ for eltya in (Float32, Float64, Complex64, Complex128, BigFloat, Int) d = eltya == Int ? Tridiagonal(rand(1:7, n-1), rand(1:7, n), rand(1:7, n-1)) : convert(Tridiagonal{eltya}, eltya <: Complex ? Tridiagonal(complex(dlreal, dlimg), complex(dreal, dimg), complex(dureal, duimg)) : Tridiagonal(dlreal, dreal, dureal)) ε = εa = eps(abs(float(one(eltya)))) + if eltya <: BlasFloat + num = rand(eltya) + @test lu(num) == (one(eltya),num,1) + @test_approx_eq full(lufact(num)) eltya[num] + end for eltyb in (Float32, Float64, Complex64, Complex128, Int) b = eltyb == Int ? rand(1:5, n, 2) : convert(Matrix{eltyb}, eltyb <: Complex ? complex(breal, bimg) : breal) c = eltyb == Int ? rand(1:5, n) : convert(Vector{eltyb}, eltyb <: Complex ? complex(creal, cimg) : creal) @@ -41,7 +47,10 @@ for eltya in (Float32, Float64, Complex64, Complex128, BigFloat, Int) debug && println("(Automatic) Square LU decomposition") κ = cond(a,1) lua = factorize(a) + @test_throws KeyError lua[:Z] l,u,p = lua[:L], lua[:U], lua[:p] + ll,ul,pl = lu(a) + @test_approx_eq ll * ul a[pl,:] @test_approx_eq l*u a[p,:] @test_approx_eq (l*u)[invperm(p),:] a @test_approx_eq a * inv(lua) eye(n) @@ -50,15 +59,21 @@ debug && println("(Automatic) Square LU decomposition") @test norm(a'*(lua'\a') - a', 1) < ε*κ*n^2 @test norm(a*(lua\c) - c, 1) < ε*κ*n # c is a vector @test norm(a'*(lua'\c) - c, 1) < ε*κ*n # c is a vector + @test_approx_eq full(lua) a if eltya <: Real && eltyb <: Real @test norm(a.'*(lua.'\b) - b,1) < ε*κ*n*2 # Two because the right hand side has two columns @test norm(a.'*(lua.'\c) - c,1) < ε*κ*n end - @test_approx_eq full(lua) a + if eltya <: BlasFloat && eltyb <: BlasFloat + e = rand(eltyb,n,n) + @test norm(e/lua - e/a,1) < ε*κ*n^2 + end debug && println("Tridiagonal LU") κd = cond(full(d),1) lud = lufact(d) + @test lufact(lud) == lud + @test_throws KeyError lud[:Z] @test_approx_eq lud[:L]*lud[:U] lud[:P]*full(d) @test_approx_eq lud[:L]*lud[:U] full(d)[lud[:p],:] @test_approx_eq full(lud) d @@ -71,6 +86,23 @@ debug && println("Tridiagonal LU") end f = zeros(eltyb, n+1) @test_throws DimensionMismatch lud\f + @test_throws DimensionMismatch lud.'\f + @test_throws DimensionMismatch lud'\f + + if eltya <: BlasFloat && eltyb <: BlasFloat + e = rand(eltyb,n,n) + @test norm(e/lud - e/d,1) < ε*κ*n^2 + @test norm((lud.'\e') - full(d.')\e',1) < ε*κd*n^2 + #test singular + du = rand(eltya,n-1) + dl = rand(eltya,n-1) + dd = rand(eltya,n) + dd[1] = zero(eltya) + du[1] = zero(eltya) + dl[1] = zero(eltya) + zT = Tridiagonal(dl,dd,du) + @test lufact(zT).info == 1 + end debug && println("Thin LU") lua = @inferred lufact(a[:,1:n1]) diff --git a/test/linalg/svd.jl b/test/linalg/svd.jl index 8fcbe91f41f6e..fb7d889ac6f38 100644 --- a/test/linalg/svd.jl +++ b/test/linalg/svd.jl @@ -44,8 +44,11 @@ debug && println("Generalized svd") @test_approx_eq gsvd[:V]*gsvd[:D2]*gsvd[:R]*gsvd[:Q]' a_svd @test_approx_eq usv[:Vt]' usv[:V] @test_throws KeyError usv[:Z] + @test_throws KeyError gsvd[:Z] + @test_approx_eq gsvd[:vals] svdvals(a,a_svd) α = eltya == Int ? -1 : rand(eltya) β = svdfact(α) @test β[:S] == [abs(α)] @test svdvals(α) == abs(α) + end