Skip to content

Commit

Permalink
rename methods of min and max that do reductions to minimum and maximum
Browse files Browse the repository at this point in the history
this is step 1 for JuliaLang#4235
  • Loading branch information
JeffBezanson committed Oct 11, 2013
1 parent df8321e commit 5f9bbbe
Show file tree
Hide file tree
Showing 35 changed files with 127 additions and 124 deletions.
18 changes: 9 additions & 9 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function checkbounds(sz::Int, I::AbstractVector{Bool})
end

function checkbounds{T<:Integer}(sz::Int, I::Ranges{T})
if !isempty(I) && (min(I) < 1 || max(I) > sz)
if !isempty(I) && (minimum(I) < 1 || maximum(I) > sz)
throw(BoundsError())
end
end
Expand Down Expand Up @@ -755,7 +755,7 @@ function cat(catdim::Integer, X...)
nargs = length(X)
dimsX = map((a->isa(a,AbstractArray) ? size(a) : (1,)), X)
ndimsX = map((a->isa(a,AbstractArray) ? ndims(a) : 1), X)
d_max = max(ndimsX)
d_max = maximum(ndimsX)

if catdim > d_max + 1
for i=1:nargs
Expand Down Expand Up @@ -823,7 +823,7 @@ function cat_t(catdim::Integer, typeC, A::AbstractArray...)
nargs = length(A)
dimsA = map(size, A)
ndimsA = map(ndims, A)
d_max = max(ndimsA)
d_max = maximum(ndimsA)

if catdim > d_max + 1
for i=1:nargs
Expand Down Expand Up @@ -1394,9 +1394,9 @@ reduced_dims0(A, region) = ntuple(ndims(A), i->(size(A,i)==0 ? 0 :
reducedim(f::Function, A, region, v0) =
reducedim(f, A, region, v0, similar(A, reduced_dims(A, region)))

max{T}(A::AbstractArray{T}, b::(), region) =
maximum{T}(A::AbstractArray{T}, region) =
isempty(A) ? similar(A,reduced_dims0(A,region)) : reducedim(max,A,region,typemin(T))
min{T}(A::AbstractArray{T}, b::(), region) =
minimum{T}(A::AbstractArray{T}, region) =
isempty(A) ? similar(A,reduced_dims0(A,region)) : reducedim(min,A,region,typemax(T))
sum{T}(A::AbstractArray{T}, region) = reducedim(+,A,region,zero(T))
prod{T}(A::AbstractArray{T}, region) = reducedim(*,A,region,one(T))
Expand Down Expand Up @@ -1531,8 +1531,8 @@ function prod{T}(A::AbstractArray{T})
v
end

function min{T<:Real}(A::AbstractArray{T})
if isempty(A); error("min: argument is empty"); end
function minimum{T<:Real}(A::AbstractArray{T})
if isempty(A); error("minimum: argument is empty"); end
v = A[1]
for i=2:length(A)
@inbounds x = A[i]
Expand All @@ -1543,8 +1543,8 @@ function min{T<:Real}(A::AbstractArray{T})
v
end

function max{T<:Real}(A::AbstractArray{T})
if isempty(A); error("max: argument is empty"); end
function maximum{T<:Real}(A::AbstractArray{T})
if isempty(A); error("maximum: argument is empty"); end
v = A[1]
for i=2:length(A)
@inbounds x = A[i]
Expand Down
6 changes: 3 additions & 3 deletions base/bitarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1852,8 +1852,8 @@ function any(B::BitArray)
return false
end

min(B::BitArray) = isempty(B) ? error("min: argument is empty") : all(B)
max(B::BitArray) = isempty(B) ? error("max: argument is empty") : any(B)
minimum(B::BitArray) = isempty(B) ? error("minimum: argument is empty") : all(B)
maximum(B::BitArray) = isempty(B) ? error("maximum: argument is empty") : any(B)

## map over bitarrays ##

Expand Down Expand Up @@ -2176,7 +2176,7 @@ function cat(catdim::Integer, X::Union(BitArray, Integer)...)
end
dimsX = map((a->isa(a,BitArray) ? size(a) : (1,)), X)
ndimsX = map((a->isa(a,BitArray) ? ndims(a) : 1), X)
d_max = max(ndimsX)
d_max = maximum(ndimsX)

if catdim > d_max + 1
for i=1:nargs
Expand Down
2 changes: 1 addition & 1 deletion base/darray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function DArray(init, dims, procs)
end
DArray(init, dims, procs, defaultdist(dims,procs))
end
DArray(init, dims) = DArray(init, dims, workers()[1:min(nworkers(),max(dims))])
DArray(init, dims) = DArray(init, dims, workers()[1:min(nworkers(),maximum(dims))])

# new DArray similar to an existing one
DArray(init, d::DArray) = DArray(init, size(d), procs(d), [size(d.chunks)...])
Expand Down
6 changes: 6 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ export PipeString
@deprecate open_any_tcp_port listenany
@deprecate subtype issubtype
@deprecate bsxfun broadcast
@deprecate max(x) maximum(x)
@deprecate min(x) minimum(x)
@deprecate max(f::Function,x) maximum(f,x)
@deprecate min(f::Function,x) minimum(f,x)
@deprecate max(x,_::(),d) maximum(x,d)
@deprecate min(x,_::(),d) minimum(x,d)

deprecated_ls() = run(`ls -l`)
deprecated_ls(args::Cmd) = run(`ls -l $args`)
Expand Down
2 changes: 2 additions & 0 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,9 @@ export
logspace,
mapslices,
max,
maximum,
min,
minimum,
nans,
ndims,
nnz,
Expand Down
2 changes: 1 addition & 1 deletion base/iterator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type Zip
end
zip(itrs...) = Zip(itrs...)

length(z::Zip) = min(length, z.itrs)
length(z::Zip) = minimum(length, z.itrs)
start(z::Zip) = { start(itr) for itr in z.itrs }
function next(z::Zip, state)
for i = 1:length(z.itrs)
Expand Down
2 changes: 1 addition & 1 deletion base/linalg/bitarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ gradient(F::BitVector, h::BitVector) = gradient(bitunpack(F), bitunpack(h))
## diag and related

function diag(B::BitMatrix)
n = min(size(B))
n = minimum(size(B))
v = similar(B, n)
for i = 1:n
v[i] = B[i,i]
Expand Down
4 changes: 2 additions & 2 deletions base/linalg/blas.jl
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ function axpy!{T,Ta<:Number,Ti<:Integer}(alpha::Ta, x::Array{T}, rx::Union(Range
error("Ranges should be of the same length")
end

if min(rx) < 1 || max(rx) > length(x) || min(ry) < 1 || max(ry) > length(y)
if minimum(rx) < 1 || maximum(rx) > length(x) || minimum(ry) < 1 || maximum(ry) > length(y)
throw(BoundsError())
end
axpy!(length(rx), convert(T, alpha), pointer(x)+(first(rx)-1)*sizeof(T),
Expand Down Expand Up @@ -590,7 +590,7 @@ end

function copy!{T<:BlasFloat,Ti<:Integer}(dest::Array{T}, rdest::Union(Range1{Ti},Range{Ti}),
src::Array{T}, rsrc::Union(Range1{Ti},Range{Ti}))
if min(rdest) < 1 || max(rdest) > length(dest) || min(rsrc) < 1 || max(rsrc) > length(src)
if minimum(rdest) < 1 || maximum(rdest) > length(dest) || minimum(rsrc) < 1 || maximum(rsrc) > length(src)
throw(BoundsError())
end
if length(rdest) != length(rsrc)
Expand Down
2 changes: 1 addition & 1 deletion base/linalg/cholmod.jl
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,7 @@ end
findnz(L::CholmodFactor) = findnz(CholmodSparse(L))

function diag{Tv}(A::CholmodSparse{Tv})
minmn = min(size(A))
minmn = minimum(size(A))
res = zeros(Tv,minmn)
cp0 = A.colptr0
rv0 = A.rowval0
Expand Down
18 changes: 9 additions & 9 deletions base/linalg/dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ isposdef(x::Number) = imag(x)==0 && real(x) > 0
norm{T<:BlasFloat}(x::Vector{T}) = BLAS.nrm2(length(x), x, 1)

function norm{T<:BlasFloat, TI<:Integer}(x::Vector{T}, rx::Union(Range1{TI},Range{TI}))
if min(rx) < 1 || max(rx) > length(x)
if minimum(rx) < 1 || maximum(rx) > length(x)
throw(BoundsError())
end
BLAS.nrm2(length(rx), pointer(x)+(first(rx)-1)*sizeof(T), step(rx))
Expand All @@ -35,14 +35,14 @@ function norm{T<:BlasFloat}(x::Vector{T}, p::Number)
elseif p == 1
BLAS.asum(n, x, 1)
elseif p == Inf
max(abs(x))
maximum(abs(x))
elseif p == -Inf
min(abs(x))
minimum(abs(x))
elseif p == 0
convert(T, nnz(x))
else
absx = abs(x)
dx = max(absx)
dx = maximum(absx)
if dx != zero(T)
scale!(absx, 1/dx)
a = dx * (sum(absx.^p).^(1/p))
Expand Down Expand Up @@ -135,7 +135,7 @@ function trace{T}(A::Matrix{T})
error("expected square matrix")
end
t = zero(T)
for i=1:min(size(A))
for i=1:minimum(size(A))
t += A[i,i]
end
return t
Expand Down Expand Up @@ -526,7 +526,7 @@ function pinv{T<:BlasFloat}(A::StridedMatrix{T})
if m == 0 || n == 0 return Array(T, n, m) end
SVD = svdfact(A, true)
Sinv = zeros(T, length(SVD[:S]))
index = SVD[:S] .> eps(real(one(T)))*max(m,n)*max(SVD[:S])
index = SVD[:S] .> eps(real(one(T)))*max(m,n)*maximum(SVD[:S])
Sinv[index] = 1.0 ./ SVD[:S][index]
SVD[:Vt]'scale(Sinv, SVD[:U]')
end
Expand All @@ -540,7 +540,7 @@ function null{T<:BlasFloat}(A::StridedMatrix{T})
if m == 0 || n == 0 return eye(T, n) end
SVD = svdfact(A, false)
if m == 0; return eye(T, n); end
indstart = sum(SVD[:S] .> max(m,n)*max(SVD[:S])*eps(eltype(SVD[:S]))) + 1
indstart = sum(SVD[:S] .> max(m,n)*maximum(SVD[:S])*eps(eltype(SVD[:S]))) + 1
SVD[:V][:,indstart:]
end
null{T<:Integer}(A::StridedMatrix{T}) = null(float(A))
Expand All @@ -549,8 +549,8 @@ null(a::StridedVector) = null(reshape(a, length(a), 1))
function cond(A::StridedMatrix, p)
if p == 2
v = svdvals(A)
maxv = max(v)
return maxv == 0.0 ? Inf : maxv / min(v)
maxv = maximum(v)
return maxv == 0.0 ? Inf : maxv / minimum(v)
elseif p == 1 || p == Inf
m, n = size(A)
if m != n; error("Use 2-norm for non-square matrices"); end
Expand Down
10 changes: 5 additions & 5 deletions base/linalg/factorization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ qr(A::Union(Number, AbstractMatrix)) = qr(A, true)
size(A::QR, args::Integer...) = size(A.vs, args...)

function getindex(A::QR, d::Symbol)
if d == :R; return triu(A.vs[1:min(size(A)),:]); end;
if d == :R; return triu(A.vs[1:minimum(size(A)),:]); end;
if d == :Q; return QRPackedQ(A); end
error("No such type field")
end
Expand Down Expand Up @@ -330,7 +330,7 @@ qrp(A::AbstractMatrix) = qrp(A, false)
size(A::QRPivoted, args::Integer...) = size(A.hh, args...)

function getindex{T<:BlasFloat}(A::QRPivoted{T}, d::Symbol)
if d == :R; return triu(A.hh[1:min(size(A)),:]); end;
if d == :R; return triu(A.hh[1:minimum(size(A)),:]); end;
if d == :Q; return QRPivotedQ(A); end
if d == :p; return A.jpvt; end
if d == :P
Expand All @@ -347,7 +347,7 @@ end

# Julia implementation similarly to xgelsy
function (\){T<:BlasFloat}(A::QRPivoted{T}, B::StridedMatrix{T}, rcond::Real)
nr = min(size(A.hh))
nr = minimum(size(A.hh))
nrhs = size(B, 2)
if nr == 0 return zeros(0, nrhs), 0 end
ar = abs(A.hh[1])
Expand Down Expand Up @@ -531,11 +531,11 @@ eigvals(x::Number) = [one(x)]
#Computes maximum and minimum eigenvalue
function eigmax(A::Union(Number, AbstractMatrix))
v = eigvals(A)
iseltype(v,Complex) ? error("Complex eigenvalues cannot be ordered") : max(v)
iseltype(v,Complex) ? error("Complex eigenvalues cannot be ordered") : maximum(v)
end
function eigmin(A::Union(Number, AbstractMatrix))
v = eigvals(A)
iseltype(v,Complex) ? error("Complex eigenvalues cannot be ordered") : min(v)
iseltype(v,Complex) ? error("Complex eigenvalues cannot be ordered") : minimum(v)
end

inv(A::Eigen) = scale(A.vectors, 1.0/A.values)*A.vectors'
Expand Down
14 changes: 7 additions & 7 deletions base/linalg/generic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ function norm{T}(x::AbstractVector{T}, p::Number)
if length(x) == 0
a = zero(T)
elseif p == Inf
a = max(abs(x))
a = maximum(abs(x))
elseif p == -Inf
a = min(abs(x))
a = minimum(abs(x))
else
absx = abs(x)
dx = max(absx)
dx = maximum(absx)
if dx != zero(T)
scale!(absx, 1/dx)
a = dx * (sum(absx.^p).^(1/p))
Expand All @@ -61,11 +61,11 @@ function norm(A::AbstractMatrix, p::Number)
elseif m == 1 || n == 1
a = norm(reshape(A, length(A)), p)
elseif p == 1
a = max(sum(abs(A),1))
a = maximum(sum(abs(A),1))
elseif p == 2
a = max(svdvals(A))
a = maximum(svdvals(A))
elseif p == Inf
a = max(sum(abs(A),2))
a = maximum(sum(abs(A),2))
else
error("invalid parameter p given to compute matrix norm")
end
Expand All @@ -85,7 +85,7 @@ function rank(A::AbstractMatrix)
m,n = size(A)
if m == 0 || n == 0; return 0; end
sv = svdvals(A)
sum(sv .> max(size(A))*eps(sv[1]))
sum(sv .> maximum(size(A))*eps(sv[1]))
end
rank(x::Number) = x == 0 ? 0 : 1

Expand Down
2 changes: 1 addition & 1 deletion base/linalg/lapack.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2457,7 +2457,7 @@ for (syev, syevr, sygvd, elty, relty) in
ccall(($(string(syev)),liblapack), Void,
(Ptr{BlasChar}, Ptr{BlasChar}, Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt},
Ptr{$relty}, Ptr{$elty}, Ptr{BlasInt}, Ptr{$relty}, Ptr{BlasInt}),
&jobz, &uplo, &n, A, &max(stride(A,2)), W, work, &lwork, rwork, info)
&jobz, &uplo, &n, A, &stride(A,2), W, work, &lwork, rwork, info)
if info[1] != 0 throw(LAPACKException(info[1])) end
if lwork < 0
lwork = blas_int(real(work[1]))
Expand Down
2 changes: 1 addition & 1 deletion base/linalg/matmul.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ scale(b::Vector, A::Matrix) =
dot{T<:Union(Float32, Float64)}(x::Vector{T}, y::Vector{T}) = BLAS.dot(x, y)
function dot{T<:BLAS.BlasFloat, TI<:Integer}(x::Vector{T}, rx::Union(Range1{TI},Range{TI}), y::Vector{T}, ry::Union(Range1{TI},Range{TI}))
length(rx) != length(ry) ? error("ranges should be of same length") : true
if min(rx) < 1 || max(rx) > length(x) || min(ry) < 1 || max(ry) > length(y)
if minimum(rx) < 1 || maximum(rx) > length(x) || minimum(ry) < 1 || maximum(ry) > length(y)
throw(BoundsError())
end
BLAS.dot(length(rx), pointer(x)+(first(rx)-1)*sizeof(T), step(rx), pointer(y)+(first(ry)-1)*sizeof(T), step(ry))
Expand Down
2 changes: 1 addition & 1 deletion base/pkg/entry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ function tag(pkg::String, ver::Union(Symbol,VersionNumber), commit::String, msg:
sort!(existing)
if isa(ver,Symbol)
prv = isempty(existing) ? v"0" :
isempty(ancestors) ? max(existing) : max(ancestors)
isempty(ancestors) ? maximum(existing) : maximum(ancestors)
ver = (ver == :bump ) ? nextbump(prv) :
(ver == :patch) ? nextpatch(prv) :
(ver == :minor) ? nextminor(prv) :
Expand Down
2 changes: 1 addition & 1 deletion base/pkg/query.jl
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ function prune_versions(reqs::Requires, deps::Dict{ByteString,Dict{VersionNumber
eqclassp = eq_classes[p]
for cl in classes
if !isempty(cl)
vtop = max(cl)
vtop = maximum(cl)
push!(prunedp, vtop)
@assert !haskey(eqclassp, vtop)
eqclassp[vtop] = cl
Expand Down
6 changes: 3 additions & 3 deletions base/pkg/read.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function installed_version(pkg::String, avail::Dict=available(pkg))
ispath(pkg,".git") || return typemin(VersionNumber)
head = Git.head(dir=pkg)
vers = [keys(filter((ver,info)->info.sha1==head, avail))...]
!isempty(vers) && return max(vers)
!isempty(vers) && return maximum(vers)
cache = Cache.path(pkg)
cache_has_head = isdir(cache) && Git.iscommit(head, dir=cache)
ancestors = VersionNumber[]
Expand All @@ -79,10 +79,10 @@ function installed_version(pkg::String, avail::Dict=available(pkg))
both = sort!(intersect(ancestors,descendants))
isempty(both) || warn("$pkg: some versions are both ancestors and descendants of head: $both")
if !isempty(descendants)
v = min(descendants)
v = minimum(descendants)
return VersionNumber(v.major, v.minor, v.patch, ("",), ())
elseif !isempty(ancestors)
v = max(ancestors)
v = maximum(ancestors)
return VersionNumber(v.major, v.minor, v.patch, (), ("",))
else
return typemin(VersionNumber)
Expand Down
2 changes: 1 addition & 1 deletion base/pkg/resolve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function sanity_check(deps::Dict{ByteString,Dict{VersionNumber,Available}})
vers = Array((ByteString,VersionNumber,VersionNumber), 0)
for (p,d) in deps, vn in keys(d)
lvns = VersionNumber[filter(vn2->(vn2>vn), keys(d))...]
nvn = isempty(lvns) ? typemax(VersionNumber) : min(lvns)
nvn = isempty(lvns) ? typemax(VersionNumber) : minimum(lvns)
push!(vers, (p,vn,nvn))
end
sort!(vers, by=pvn->(-ndeps[pvn[1]][pvn[2]]))
Expand Down
6 changes: 3 additions & 3 deletions base/pkg/resolve/maxsum.jl
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ type Messages
end
# normalize fields
for p0 = 1:np
m = max(fld[p0])
m = maximum(fld[p0])
for v0 = 1:spp[p0]
fld[p0][v0] -= m
end
Expand Down Expand Up @@ -303,7 +303,7 @@ function update(p0::Int, graph::Graph, msgs::Messages)
# compute the new message by passing cavmsg
# through the constraint encoded in the bitmask
# (nearly equivalent to:
# newmsg = [ max(cavmsg[bm1[:,v1]]) for v1 = 1:spp1 ]
# newmsg = [ maximum(cavmsg[bm1[:,v1]]) for v1 = 1:spp1 ]
# except for the gnrg term)
m = FieldValue(-1)
for v1 = 1:spp1
Expand All @@ -330,7 +330,7 @@ function update(p0::Int, graph::Graph, msgs::Messages)
end

diff = newmsg - oldmsg
maxdiff = max(maxdiff, max(abs(diff)))
maxdiff = max(maxdiff, maximum(abs(diff)))

# update the field of p1
fld1 = fld[p1]
Expand Down
Loading

0 comments on commit 5f9bbbe

Please sign in to comment.