~ubuntu-branches/ubuntu/wily/julia/wily

« back to all changes in this revision

Viewing changes to base/linalg.jl

  • Committer: Package Import Robot
  • Author(s): Sébastien Villemot
  • Date: 2013-02-06 17:54:29 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20130206175429-13br5kqpkfjqdmre
Tags: 0.0.0+20130206.git32ff5759-1
* New upstream snapshot.
* debian/copyright: reflect upstream changes
* debian/rules: update get-orig-source to reflect upstream changes
   + Don't ship nginx
   + Adapt for new configure-random target in deps/Makefile
* Enable build of Tk wrapper.
   + debian/control: add build dependency on tk-dev
   + debian/rules: add tk rule to build-arch
* debian/julia.install: install VERSION and COMMIT files
* no-webrepl.patch: new patch
* Refresh other patches
* Add source override for config.status file under deps/random/

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 
3
3
function scale!{T<:Number}(X::StridedArray{T}, s::Real)
4
4
    # FIXME: could use BLAS in more cases
5
 
    for i in 1:numel(X)
 
5
    for i in 1:length(X)
6
6
        X[i] *= s;
7
7
    end
8
8
    return X
33
33
 
34
34
function norm{T}(x::AbstractVector{T}, p::Number)
35
35
    if length(x) == 0
36
 
        a = zero(eltype(x))
 
36
        a = zero(T)
37
37
    elseif p == Inf
38
38
        a = max(abs(x))
39
39
    elseif p == -Inf
53
53
norm{T<:Integer}(x::AbstractVector{T}, p::Number) = norm(float(x), p)
54
54
norm(x::AbstractVector) = norm(x, 2)
55
55
 
56
 
function norm(A::AbstractMatrix, p)
 
56
function norm(A::AbstractMatrix, p::Number)
57
57
    m, n = size(A)
58
58
    if m == 0 || n == 0
59
59
        a = zero(eltype(A))
60
60
    elseif m == 1 || n == 1
61
 
        a = norm(reshape(A, numel(A)), p)
 
61
        a = norm(reshape(A, length(A)), p)
62
62
    elseif p == 1
63
63
        a = max(sum(abs(A),1))
64
64
    elseif p == 2
65
65
        a = max(svdvals(A))
66
66
    elseif p == Inf
67
67
        a = max(sum(abs(A),2))
68
 
    elseif p == :fro
69
 
        a = norm(reshape(A, numel(A)))
70
68
    else
71
 
        error("invalid parameter to matrix norm")
 
69
        error("invalid parameter p given to compute matrix norm")
72
70
    end
73
71
    return float(a)
74
72
end
78
76
norm(x::Number) = abs(x)
79
77
norm(x::Number, p) = abs(x)
80
78
 
 
79
normfro(A::AbstractMatrix) = norm(reshape(A, length(A)))
 
80
normfro(x::Number) = abs(x)
 
81
 
81
82
rank(A::AbstractMatrix, tol::Real) = sum(svdvals(A) .> tol)
82
83
function rank(A::AbstractMatrix)
83
84
    m,n = size(A)
84
85
    if m == 0 || n == 0; return 0; end
85
86
    sv = svdvals(A)
86
 
    sum(sv .> max(size(A,1),size(A,2))*eps(sv[1]))
 
87
    sum(sv .> max(size(A))*eps(sv[1]))
87
88
end
88
89
rank(x::Number) = x == 0 ? 0 : 1
89
90