Skip to content

Commit

Permalink
rename trace to tr
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Mar 8, 2018
1 parent f3118ce commit 502bcb1
Show file tree
Hide file tree
Showing 13 changed files with 24 additions and 22 deletions.
4 changes: 2 additions & 2 deletions stdlib/IterativeEigensolvers/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ let

@test d[1] 1. # largest eigenvalue should be 1.
v = reshape(v,(50,50)) # reshape to matrix
v /= trace(v) # factor out arbitrary phase
v /= tr(v) # factor out arbitrary phase
@test vecnorm(imag(v)) 0. # it should be real
v = real(v)
# @test vecnorm(v-v')/2 ≈ 0. # it should be Hermitian
Expand All @@ -173,7 +173,7 @@ let
# Repeat with starting vector
(d2,v2,nconv2,numiter2,numop2,resid2) = eigs(Phi,nev=1,which=:LM,v0=reshape(v,(2500,)))
v2 = reshape(v2,(50,50))
v2 /= trace(v2)
v2 /= tr(v2)
@test numiter2 < numiter
@test v v2

Expand Down
6 changes: 3 additions & 3 deletions stdlib/LinearAlgebra/docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ DocTestSetup = :(using LinearAlgebra)
```

In addition to (and as part of) its support for multi-dimensional arrays, Julia provides native implementations
of many common and useful linear algebra operations. Basic operations, such as [`trace`](@ref), [`det`](@ref),
of many common and useful linear algebra operations. Basic operations, such as [`tr`](@ref), [`det`](@ref),
and [`inv`](@ref) are all supported:

```jldoctest
Expand All @@ -15,7 +15,7 @@ julia> A = [1 2 3; 4 1 6; 7 8 1]
4 1 6
7 8 1
julia> trace(A)
julia> tr(A)
3
julia> det(A)
Expand Down Expand Up @@ -371,7 +371,7 @@ LinearAlgebra.normalize!
LinearAlgebra.normalize
LinearAlgebra.cond
LinearAlgebra.condskeel
LinearAlgebra.trace
LinearAlgebra.tr
LinearAlgebra.det
LinearAlgebra.logdet
LinearAlgebra.logabsdet
Expand Down
2 changes: 1 addition & 1 deletion stdlib/LinearAlgebra/src/LinearAlgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export
svdvals!,
svdvals,
sylvester,
trace,
tr,
transpose,
transpose!,
transpose_type,
Expand Down
2 changes: 1 addition & 1 deletion stdlib/LinearAlgebra/src/dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ function diagm_container(kv::Pair{<:Integer,<:BitVector}...)
end


function trace(A::Matrix{T}) where T
function tr(A::Matrix{T}) where T
n = checksquare(A)
t = zero(T)
for i=1:n
Expand Down
2 changes: 2 additions & 0 deletions stdlib/LinearAlgebra/src/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1258,3 +1258,5 @@ end
@deprecate scale!(a::AbstractVector, B::AbstractMatrix) lmul!(Diagonal(a), B)
@deprecate scale!(C::AbstractMatrix, A::AbstractMatrix, b::AbstractVector) mul!(C, A, Diagonal(b))
@deprecate scale!(C::AbstractMatrix, a::AbstractVector, B::AbstractMatrix) mul!(C, Diagonal(a), B)

Base.@deprecate_binding trace tr
8 changes: 4 additions & 4 deletions stdlib/LinearAlgebra/src/generic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ end
rank(x::Number) = x == 0 ? 0 : 1

"""
trace(M)
tr(M)
Matrix trace. Sums the diagonal elements of `M`.
Expand All @@ -742,15 +742,15 @@ julia> A = [1 2; 3 4]
1 2
3 4
julia> trace(A)
julia> tr(A)
5
```
"""
function trace(A::AbstractMatrix)
function tr(A::AbstractMatrix)
checksquare(A)
sum(diag(A))
end
trace(x::Number) = x
tr(x::Number) = x

#kron(a::AbstractVector, b::AbstractVector)
#kron(a::AbstractMatrix{T}, b::AbstractMatrix{S}) where {T,S}
Expand Down
2 changes: 1 addition & 1 deletion stdlib/LinearAlgebra/src/symmetric.jl
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ Base.copy(A::Adjoint{<:Any,<:Symmetric}) =
Base.collect(A::Transpose{<:Any,<:Hermitian}) =
Hermitian(copy(transpose(A.parent.data)), ifelse(A.parent.uplo == 'U', :L, :U))

trace(A::Hermitian) = real(trace(A.data))
tr(A::Hermitian) = real(tr(A.data))

Base.conj(A::HermOrSym) = typeof(A)(conj(A.data), A.uplo)
Base.conj!(A::HermOrSym) = typeof(A)(conj!(A.data), A.uplo)
Expand Down
2 changes: 1 addition & 1 deletion stdlib/LinearAlgebra/test/diagonal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ srand(1)
@test op(D)==op(DM)
end

for func in (det, trace)
for func in (det, tr)
@test func(D) func(DM) atol=n^2*eps(relty)*(1+(elty<:Complex))
end
if relty <: BlasFloat
Expand Down
4 changes: 2 additions & 2 deletions stdlib/LinearAlgebra/test/generic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ end
@test_throws DimensionMismatch cross(fill(1,3), fill(1,4))
@test_throws DimensionMismatch cross(fill(1,2), fill(1,3))

@test trace(Bidiagonal(fill(1,5),fill(0,4),:U)) == 5
@test tr(Bidiagonal(fill(1,5),fill(0,4),:U)) == 5


@testset "array and subarray" begin
Expand Down Expand Up @@ -222,7 +222,7 @@ end
@testset "ops on Numbers" begin
@testset for elty in [Float32,Float64,ComplexF32,ComplexF64]
a = rand(elty)
@test trace(a) == a
@test tr(a) == a
@test rank(zero(elty)) == 0
@test rank(one(elty)) == 1
@test !isfinite(cond(zero(elty)))
Expand Down
6 changes: 3 additions & 3 deletions stdlib/LinearAlgebra/test/symmetric.jl
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ end
end

@testset "linalg unary ops" begin
@testset "trace" begin
@test trace(asym) == trace(Symmetric(asym))
@test trace(aherm) == trace(Hermitian(aherm))
@testset "tr" begin
@test tr(asym) == tr(Symmetric(asym))
@test tr(aherm) == tr(Hermitian(aherm))
end

@testset "isposdef[!]" begin
Expand Down
2 changes: 1 addition & 1 deletion stdlib/SparseArrays/src/SparseArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ using LinearAlgebra

import Base: +, -, *, \, /, &, |, xor, ==
import LinearAlgebra: mul!, ldiv!, rdiv!, chol, adjoint!, diag, dot, eig,
issymmetric, istril, istriu, lu, trace, transpose!, tril!, triu!,
issymmetric, istril, istriu, lu, tr, transpose!, tril!, triu!,
vecnorm, cond, diagm, factorize, ishermitian, norm, lmul!, rmul!, tril, triu

import Base: @get!, acos, acosd, acot, acotd, acsch, asech, asin, asind, asinh,
Expand Down
2 changes: 1 addition & 1 deletion stdlib/SparseArrays/src/sparsematrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3360,7 +3360,7 @@ function diag(A::SparseMatrixCSC{Tv,Ti}, d::Integer=0) where {Tv,Ti}
return SparseVector{Tv,Ti}(l, ind, val)
end

function trace(A::SparseMatrixCSC{Tv}) where Tv
function tr(A::SparseMatrixCSC{Tv}) where Tv
n = checksquare(A)
s = zero(Tv)
for i in 1:n
Expand Down
4 changes: 2 additions & 2 deletions stdlib/SparseArrays/test/sparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1445,8 +1445,8 @@ end
end

@testset "trace" begin
@test_throws DimensionMismatch trace(spzeros(5,6))
@test trace(sparse(1.0I, 5, 5)) == 5
@test_throws DimensionMismatch tr(spzeros(5,6))
@test tr(sparse(1.0I, 5, 5)) == 5
end

@testset "spdiagm" begin
Expand Down

0 comments on commit 502bcb1

Please sign in to comment.