Skip to content

Commit

Permalink
Merge branch 'master' of github.com:JuliaLang/julia
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Aug 23, 2015
2 parents 0e12723 + e099909 commit f8c1986
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 4 deletions.
3 changes: 2 additions & 1 deletion base/docs/Docs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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]...)))

Expand Down
2 changes: 1 addition & 1 deletion base/docs/helpdb.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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!

Expand Down
1 change: 1 addition & 0 deletions base/linalg/lu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion base/markdown/Markdown.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
14 changes: 14 additions & 0 deletions test/docs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
34 changes: 33 additions & 1 deletion test/linalg/lu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
debug = false

using Base.Test
import Base.LinAlg.BlasInt, Base.LinAlg.BlasFloat

n = 10

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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])
Expand Down
3 changes: 3 additions & 0 deletions test/linalg/svd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit f8c1986

Please sign in to comment.