Skip to content

Commit 485490e

Browse files
committed
close #1875
norm(A, :fro) is replaced with normfro(A).
1 parent 0971b3b commit 485490e

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

base/export.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,7 @@ export
707707
lud,
708708
lud!,
709709
norm,
710+
normfro,
710711
null,
711712
pinv,
712713
qr,

base/linalg.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ diag(A::AbstractVector) = error("Perhaps you meant to use diagm().")
3333

3434
function norm{T}(x::AbstractVector{T}, p::Number)
3535
if length(x) == 0
36-
a = zero(eltype(x))
36+
a = zero(T)
3737
elseif p == Inf
3838
a = max(abs(x))
3939
elseif p == -Inf
@@ -53,7 +53,7 @@ end
5353
norm{T<:Integer}(x::AbstractVector{T}, p::Number) = norm(float(x), p)
5454
norm(x::AbstractVector) = norm(x, 2)
5555

56-
function norm(A::AbstractMatrix, p)
56+
function norm(A::AbstractMatrix, p::Number)
5757
m, n = size(A)
5858
if m == 0 || n == 0
5959
a = zero(eltype(A))
@@ -65,10 +65,8 @@ function norm(A::AbstractMatrix, p)
6565
a = max(svdvals(A))
6666
elseif p == Inf
6767
a = max(sum(abs(A),2))
68-
elseif p == :fro
69-
a = norm(reshape(A, length(A)))
7068
else
71-
error("invalid parameter to matrix norm")
69+
error("invalid parameter p given to compute matrix norm")
7270
end
7371
return float(a)
7472
end
@@ -78,6 +76,9 @@ norm(A::AbstractMatrix) = norm(A, 2)
7876
norm(x::Number) = abs(x)
7977
norm(x::Number, p) = abs(x)
8078

79+
normfro(A::AbstractMatrix) = norm(reshape(A, length(A)), 2)
80+
normfro(x::Number) = abs(x)
81+
8182
rank(A::AbstractMatrix, tol::Real) = sum(svdvals(A) .> tol)
8283
function rank(A::AbstractMatrix)
8384
m,n = size(A)

base/linalg_dense.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ end
779779
svd(A) = svd(A,true,false)
780780
svd(A, thin::Bool) = svd(A,true,thin)
781781

782-
svdvals(A) = svd(A,false,true)[2]
782+
svdvals(A) = svdt(A,false,true)[2]
783783

784784

785785
function (\){T<:BlasFloat}(A::StridedMatrix{T}, B::StridedVecOrMat{T})

doc/stdlib/base.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1761,11 +1761,15 @@ Linear algebra functions in Julia are largely implemented by calling functions f
17611761

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

1764-
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).
1764+
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``.
1765+
1766+
.. function:: normfro(A)
1767+
1768+
Compute the Frobenius norm of a matrix ``A``.
17651769

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

1768-
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).
1772+
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``.
17691773

17701774
.. function:: trace(M)
17711775

0 commit comments

Comments
 (0)