Skip to content

Commit

Permalink
close #1875
Browse files Browse the repository at this point in the history
norm(A, :fro) is replaced with normfro(A).
  • Loading branch information
ViralBShah committed Jan 13, 2013
1 parent 0971b3b commit 485490e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
1 change: 1 addition & 0 deletions base/export.jl
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,7 @@ export
lud,
lud!,
norm,
normfro,
null,
pinv,
qr,
Expand Down
11 changes: 6 additions & 5 deletions base/linalg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ diag(A::AbstractVector) = error("Perhaps you meant to use diagm().")

function norm{T}(x::AbstractVector{T}, p::Number)
if length(x) == 0
a = zero(eltype(x))
a = zero(T)
elseif p == Inf
a = max(abs(x))
elseif p == -Inf
Expand All @@ -53,7 +53,7 @@ end
norm{T<:Integer}(x::AbstractVector{T}, p::Number) = norm(float(x), p)
norm(x::AbstractVector) = norm(x, 2)

function norm(A::AbstractMatrix, p)
function norm(A::AbstractMatrix, p::Number)
m, n = size(A)
if m == 0 || n == 0
a = zero(eltype(A))
Expand All @@ -65,10 +65,8 @@ function norm(A::AbstractMatrix, p)
a = max(svdvals(A))
elseif p == Inf
a = max(sum(abs(A),2))
elseif p == :fro
a = norm(reshape(A, length(A)))
else
error("invalid parameter to matrix norm")
error("invalid parameter p given to compute matrix norm")
end
return float(a)
end
Expand All @@ -78,6 +76,9 @@ norm(A::AbstractMatrix) = norm(A, 2)
norm(x::Number) = abs(x)
norm(x::Number, p) = abs(x)

normfro(A::AbstractMatrix) = norm(reshape(A, length(A)), 2)
normfro(x::Number) = abs(x)

rank(A::AbstractMatrix, tol::Real) = sum(svdvals(A) .> tol)
function rank(A::AbstractMatrix)
m,n = size(A)
Expand Down
2 changes: 1 addition & 1 deletion base/linalg_dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ end
svd(A) = svd(A,true,false)
svd(A, thin::Bool) = svd(A,true,thin)

svdvals(A) = svd(A,false,true)[2]
svdvals(A) = svdt(A,false,true)[2]


function (\){T<:BlasFloat}(A::StridedMatrix{T}, B::StridedVecOrMat{T})
Expand Down
8 changes: 6 additions & 2 deletions doc/stdlib/base.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1761,11 +1761,15 @@ Linear algebra functions in Julia are largely implemented by calling functions f

.. function:: norm(A, [p])

Compute the p-norm of a vector or a matrix. ``p`` is ``2`` by default, if not provided. If ``A`` is a matrix, valid values for ``p`` are ``1``, ``2``, ``Inf``, or ``:fro`` (Frobenius norm).
Compute the ``p``-norm of a vector or a matrix. ``p`` is ``2`` by default, if not provided. If ``A`` is a vector, ``norm(A, p)`` computes the ``p``-norm. ``norm(A, Inf)`` returns the largest value in ``abs(A)``, whereas ``norm(A, -Inf)`` returns the smallest. If ``A`` is a matrix, valid values for ``p`` are ``1``, ``2``, or ``Inf``. In order to compute the Frobenius norm, use ``normfro``.

.. function:: normfro(A)

Compute the Frobenius norm of a matrix ``A``.

.. function:: cond(M, [p])

Matrix condition number, computed using the p-norm. ``p`` is 2 by default, if not provided. Valid values for ``p`` are ``1``, ``2``, ``Inf``, or ``:fro`` (Frobenius norm).
Matrix condition number, computed using the p-norm. ``p`` is 2 by default, if not provided. Valid values for ``p`` are ``1``, ``2``, or ``Inf``.

.. function:: trace(M)

Expand Down

0 comments on commit 485490e

Please sign in to comment.