diff --git a/base/arraymath.jl b/base/arraymath.jl index 882934e0512e6..75ea8897a131e 100644 --- a/base/arraymath.jl +++ b/base/arraymath.jl @@ -28,14 +28,14 @@ promote_array_type{S<:Integer}(::typeof(/), ::Type{S}, ::Type{Bool}, T::Type) = promote_array_type{S<:Integer}(::typeof(\), ::Type{S}, ::Type{Bool}, T::Type) = T promote_array_type{S<:Integer}(F, ::Type{S}, ::Type{Bool}, T::Type) = T -for f in (:+, :-, :div, :mod, :&, :|) +for f in (:+, :-) @eval function ($f)(A::AbstractArray, B::AbstractArray) promote_shape(A, B) # check size compatibility broadcast($f, A, B) end end -for f in (:div, :mod, :rem, :&, :|, :/, :\, :*, :+, :-) +for f in (:/, :\, :*, :+, :-) if f != :/ @eval ($f){T}(A::Number, B::AbstractArray{T}) = broadcast($f, A, B) end diff --git a/base/bitarray.jl b/base/bitarray.jl index d44feffd9d923..f0ee068839fc9 100644 --- a/base/bitarray.jl +++ b/base/bitarray.jl @@ -1237,73 +1237,16 @@ end (/)(B::BitArray, x::Number) = (/)(Array(B), x) (/)(x::Number, B::BitArray) = (/)(x, Array(B)) -function div(A::BitArray, B::BitArray) - shp = promote_shape(size(A), size(B)) - all(B) || throw(DivideError()) - return reshape(copy(A), shp) -end -div(A::BitArray, B::Array{Bool}) = div(A, BitArray(B)) -div(A::Array{Bool}, B::BitArray) = div(BitArray(A), B) -function div(B::BitArray, x::Bool) - return x ? copy(B) : throw(DivideError()) -end -function div(x::Bool, B::BitArray) - all(B) || throw(DivideError()) - return x ? trues(size(B)) : falses(size(B)) -end -function div(x::Number, B::BitArray) - all(B) || throw(DivideError()) - y = div(x, true) - return fill(y, size(B)) -end - -function mod(A::BitArray, B::BitArray) - shp = promote_shape(size(A), size(B)) - all(B) || throw(DivideError()) - return falses(shp) -end -mod(A::BitArray, B::Array{Bool}) = mod(A, BitArray(B)) -mod(A::Array{Bool}, B::BitArray) = mod(BitArray(A), B) -function mod(B::BitArray, x::Bool) - return x ? falses(size(B)) : throw(DivideError()) -end -function mod(x::Bool, B::BitArray) - all(B) || throw(DivideError()) - return falses(size(B)) -end -function mod(x::Number, B::BitArray) - all(B) || throw(DivideError()) - y = mod(x, true) - return fill(y, size(B)) -end - -for f in (:div, :mod) - @eval begin - function ($f)(B::BitArray, x::Number) - T = promote_op($f, Bool, typeof(x)) - T === Any && return [($f)(b, x) for b in B] - F = Array{T}(size(B)) - for i = 1:length(F) - F[i] = ($f)(B[i], x) - end - return F - end - end -end - -function (&)(B::BitArray, x::Bool) - x ? copy(B) : falses(size(B)) -end -(&)(x::Bool, B::BitArray) = B & x - -function (|)(B::BitArray, x::Bool) - x ? trues(size(B)) : copy(B) -end -(|)(x::Bool, B::BitArray) = B | x - -for f in (:&, :|) +# broadcast specializations for &, |, and xor/⊻ +broadcast(::typeof(&), B::BitArray, x::Bool) = x ? copy(B) : falses(size(B)) +broadcast(::typeof(&), x::Bool, B::BitArray) = broadcast(&, B, x) +broadcast(::typeof(|), B::BitArray, x::Bool) = x ? trues(size(B)) : copy(B) +broadcast(::typeof(|), x::Bool, B::BitArray) = broadcast(|, B, x) +broadcast(::typeof(xor), B::BitArray, x::Bool) = x ? ~B : copy(B) +broadcast(::typeof(xor), x::Bool, B::BitArray) = broadcast(xor, B, x) +for f in (:&, :|, :xor) @eval begin - function ($f)(A::BitArray, B::BitArray) + function broadcast(::typeof($f), A::BitArray, B::BitArray) F = BitArray(promote_shape(size(A),size(B))...) Fc = F.chunks Ac = A.chunks @@ -1315,13 +1258,12 @@ for f in (:&, :|) Fc[end] &= _msk_end(F) return F end - ($f)(A::DenseArray{Bool}, B::BitArray) = ($f)(BitArray(A), B) - ($f)(B::BitArray, A::DenseArray{Bool}) = ($f)(B, BitArray(A)) - ($f)(x::Number, B::BitArray) = ($f)(x, Array(B)) - ($f)(B::BitArray, x::Number) = ($f)(Array(B), x) + broadcast(::typeof($f), A::DenseArray{Bool}, B::BitArray) = broadcast($f, BitArray(A), B) + broadcast(::typeof($f), B::BitArray, A::DenseArray{Bool}) = broadcast($f, B, BitArray(A)) end end + ## promotion to complex ## # TODO? diff --git a/base/complex.jl b/base/complex.jl index 95ca6ae4cdec2..4c1f837fb1f86 100644 --- a/base/complex.jl +++ b/base/complex.jl @@ -864,9 +864,6 @@ function complex{T}(A::AbstractArray{T}) convert(AbstractArray{typeof(complex(zero(T)))}, A) end -big{T<:Integer,N}(A::AbstractArray{Complex{T},N}) = convert(AbstractArray{Complex{BigInt},N}, A) -big{T<:AbstractFloat,N}(A::AbstractArray{Complex{T},N}) = convert(AbstractArray{Complex{BigFloat},N}, A) - ## promotion to complex ## _default_type(T::Type{Complex}) = Complex{Int} diff --git a/base/deprecated.jl b/base/deprecated.jl index 195d6b1e6ddcc..bd2deb760f2ae 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -1350,4 +1350,93 @@ export quadgk @deprecate map!{F}(f::F, A::AbstractArray) map!(f, A, A) @deprecate asyncmap!(f, c; ntasks=0, batch_size=nothing) asyncmap!(f, c, c; ntasks=ntasks, batch_size=batch_size) +# Deprecate manually vectorized abs2 methods in favor of compact broadcast syntax +@deprecate abs2(x::AbstractSparseVector) abs2.(x) + +# Deprecate manually vectorized trigonometric and hyperbolic functions in favor of compact broadcast syntax +for f in (:sec, :sech, :secd, :asec, :asech, + :csc, :csch, :cscd, :acsc, :acsch, + :cot, :coth, :cotd, :acot, :acoth) + @eval @deprecate $f{T<:Number}(A::AbstractArray{T}) $f.(A) +end + +# Deprecate manually vectorized clamp methods in favor of compact broadcast syntax +@deprecate clamp(A::AbstractArray, lo, hi) clamp.(A, lo, hi) + +# Deprecate manually vectorized round methods in favor of compact broadcast syntax +@deprecate round(M::Bidiagonal) round.(M) +@deprecate round(M::Tridiagonal) round.(M) +@deprecate round(M::SymTridiagonal) round.(M) +@deprecate round{T<:Integer}(::Type{T}, x::AbstractArray) round.(T, x) +@deprecate round{T<:Integer}(::Type{T}, x::AbstractArray, r::RoundingMode) round.(x, r) +@deprecate round(x::AbstractArray, r::RoundingMode) round.(x, r) +@deprecate round(x::AbstractArray, digits::Integer, base::Integer = 10) round.(x, digits, base) + +# Deprecate manually vectorized trunc methods in favor of compact broadcast syntax +@deprecate trunc(M::Bidiagonal) trunc.(M) +@deprecate trunc(M::Tridiagonal) trunc.(M) +@deprecate trunc(M::SymTridiagonal) trunc.(M) +@deprecate trunc{T<:Integer}(::Type{T}, x::AbstractArray) trunc.(T, x) +@deprecate trunc(x::AbstractArray, digits::Integer, base::Integer = 10) trunc.(x, digits, base) + +# Deprecate manually vectorized floor methods in favor of compact broadcast syntax +@deprecate floor(M::Bidiagonal) floor.(M) +@deprecate floor(M::Tridiagonal) floor.(M) +@deprecate floor(M::SymTridiagonal) floor.(M) +@deprecate floor{T<:Integer}(::Type{T}, A::AbstractArray) floor.(T, A) +@deprecate floor(A::AbstractArray, digits::Integer, base::Integer = 10) floor.(A, digits, base) + +# Deprecate manually vectorized ceil methods in favor of compact broadcast syntax +@deprecate ceil(M::Bidiagonal) ceil.(M) +@deprecate ceil(M::Tridiagonal) ceil.(M) +@deprecate ceil(M::SymTridiagonal) ceil.(M) +@deprecate ceil{T<:Integer}(::Type{T}, x::AbstractArray) ceil.(T, x) +@deprecate ceil(x::AbstractArray, digits::Integer, base::Integer = 10) ceil.(x, digits, base) + +# Deprecate manually vectorized `big` methods in favor of compact broadcast syntax +@deprecate big(r::UnitRange) big.(r) +@deprecate big(r::StepRange) big.(r) +@deprecate big(r::FloatRange) big.(r) +@deprecate big(r::LinSpace) big.(r) +@deprecate big{T<:Integer,N}(x::AbstractArray{T,N}) big.(x) +@deprecate big{T<:AbstractFloat,N}(x::AbstractArray{T,N}) big.(x) +@deprecate big(A::LowerTriangular) big.(A) +@deprecate big(A::UpperTriangular) big.(A) +@deprecate big(A::Base.LinAlg.UnitLowerTriangular) big.(A) +@deprecate big(A::Base.LinAlg.UnitUpperTriangular) big.(A) +@deprecate big(B::Bidiagonal) big.(B) +@deprecate big{T<:Integer,N}(A::AbstractArray{Complex{T},N}) big.(A) +@deprecate big{T<:AbstractFloat,N}(A::AbstractArray{Complex{T},N}) big.(A) +@deprecate big{T<:Integer,N}(x::AbstractArray{Complex{Rational{T}},N}) big.(A) + +# Deprecate manually vectorized div methods in favor of compact broadcast syntax +@deprecate div(A::Number, B::AbstractArray) div.(A, B) +@deprecate div(A::AbstractArray, B::Number) div.(A, B) +@deprecate div(A::AbstractArray, B::AbstractArray) div.(A, B) + +# Deprecate manually vectorized rem methods in favor of compact broadcast syntax +@deprecate rem(A::Number, B::AbstractArray) rem.(A, B) +@deprecate rem(A::AbstractArray, B::Number) rem.(A, B) + +# Deprecate manually vectorized mod methods in favor of compact broadcast syntax +@deprecate mod(B::BitArray, x::Bool) mod.(B, x) +@deprecate mod(x::Bool, B::BitArray) mod.(x, B) +@deprecate mod(A::AbstractArray, B::AbstractArray) mod.(A, B) +@deprecate mod{T}(x::Number, A::AbstractArray{T}) mod.(x, A) +@deprecate mod{T}(A::AbstractArray{T}, x::Number) mod.(A, x) + +# Deprecate vectorized & in favor of dot syntax +@deprecate (&)(a::Bool, B::BitArray) a .& B +@deprecate (&)(A::BitArray, b::Bool) A .& b +@deprecate (&)(a::Number, B::AbstractArray) a .& B +@deprecate (&)(A::AbstractArray, b::Number) A .& b +@deprecate (&)(A::AbstractArray, B::AbstractArray) A .& B + +# Deprecate vectorized | in favor of compact broadcast syntax +@deprecate (|)(a::Bool, B::BitArray) a .| B +@deprecate (|)(A::BitArray, b::Bool) A .| b +@deprecate (|)(a::Number, B::AbstractArray) a .| B +@deprecate (|)(A::AbstractArray, b::Number) A .| b +@deprecate (|)(A::AbstractArray, B::AbstractArray) A .| B + # End deprecations scheduled for 0.6 diff --git a/base/dft.jl b/base/dft.jl index 9116ef9754ee7..5ffeeaa46467f 100644 --- a/base/dft.jl +++ b/base/dft.jl @@ -354,7 +354,7 @@ plan_irfft export fftshift, ifftshift -fftshift(x) = circshift(x, div([size(x)...],2)) +fftshift(x) = circshift(x, div.([size(x)...],2)) """ fftshift(x) @@ -376,7 +376,7 @@ Swap the first and second halves of the given dimension of array `x`. """ fftshift(x,dim) -ifftshift(x) = circshift(x, div([size(x)...],-2)) +ifftshift(x) = circshift(x, div.([size(x)...],-2)) """ ifftshift(x, [dim]) diff --git a/base/dsp.jl b/base/dsp.jl index f7a7bd02cff6a..a3c7b924d3719 100644 --- a/base/dsp.jl +++ b/base/dsp.jl @@ -141,7 +141,7 @@ function conv{T<:Base.LinAlg.BlasFloat}(u::StridedVector{T}, v::StridedVector{T} end return y[1:n] end -conv{T<:Integer}(u::StridedVector{T}, v::StridedVector{T}) = round(Int,conv(float(u), float(v))) +conv{T<:Integer}(u::StridedVector{T}, v::StridedVector{T}) = round.(Int,conv(float(u), float(v))) conv{T<:Integer, S<:Base.LinAlg.BlasFloat}(u::StridedVector{T}, v::StridedVector{S}) = conv(float(u), v) conv{T<:Integer, S<:Base.LinAlg.BlasFloat}(u::StridedVector{S}, v::StridedVector{T}) = conv(u, float(v)) @@ -184,8 +184,8 @@ function conv2{T}(A::StridedMatrix{T}, B::StridedMatrix{T}) end return C end -conv2{T<:Integer}(A::StridedMatrix{T}, B::StridedMatrix{T}) = round(Int,conv2(float(A), float(B))) -conv2{T<:Integer}(u::StridedVector{T}, v::StridedVector{T}, A::StridedMatrix{T}) = round(Int,conv2(float(u), float(v), float(A))) +conv2{T<:Integer}(A::StridedMatrix{T}, B::StridedMatrix{T}) = round.(Int,conv2(float(A), float(B))) +conv2{T<:Integer}(u::StridedVector{T}, v::StridedVector{T}, A::StridedMatrix{T}) = round.(Int,conv2(float(u), float(v), float(A))) """ xcorr(u,v) diff --git a/base/float.jl b/base/float.jl index b89ec91e7c909..9183bb6a5eb35 100644 --- a/base/float.jl +++ b/base/float.jl @@ -735,7 +735,7 @@ function float{T}(A::AbstractArray{T}) convert(AbstractArray{typeof(float(zero(T)))}, A) end -for fn in (:float,:big) +for fn in (:float,) @eval begin $fn(r::StepRange) = $fn(r.start):$fn(r.step):$fn(last(r)) $fn(r::UnitRange) = $fn(r.start):$fn(last(r)) @@ -748,5 +748,13 @@ for fn in (:float,:big) end end -big{T<:AbstractFloat,N}(x::AbstractArray{T,N}) = convert(AbstractArray{BigFloat,N}, x) -big{T<:Integer,N}(x::AbstractArray{T,N}) = convert(AbstractArray{BigInt,N}, x) +# big, broadcast over arrays +# TODO: do the definitions below primarily pertaining to integers belong in float.jl? +function big end # no prior definitions of big in sysimg.jl, necessitating this +broadcast(::typeof(big), r::UnitRange) = big(r.start):big(last(r)) +broadcast(::typeof(big), r::StepRange) = big(r.start):big(r.step):big(last(r)) +broadcast(::typeof(big), r::FloatRange) = FloatRange(big(r.start), big(r.step), r.len, big(r.divisor)) +function broadcast(::typeof(big), r::LinSpace) + big(r.len) == r.len || throw(ArgumentError(string(r, ": too long for ", big))) + LinSpace(big(r.start), big(r.stop), big(r.len), big(r.divisor)) +end diff --git a/base/floatfuncs.jl b/base/floatfuncs.jl index 492c3d5f25d36..f34f6875c7b6e 100644 --- a/base/floatfuncs.jl +++ b/base/floatfuncs.jl @@ -112,49 +112,6 @@ function round(x::AbstractFloat, ::RoundingMode{:NearestTiesUp}) end round{T<:Integer}(::Type{T}, x::AbstractFloat, r::RoundingMode) = trunc(T,round(x,r)) -for f in (:trunc,:floor,:ceil,:round) - @eval begin - function ($f){T,R}(::Type{T}, x::AbstractArray{R,1}) - [ ($f)(T, y)::T for y in x ] - end - function ($f){T,R}(::Type{T}, x::AbstractArray{R,2}) - [ ($f)(T, x[i,j])::T for i = 1:size(x,1), j = 1:size(x,2) ] - end - function ($f){T}(::Type{T}, x::AbstractArray) - reshape([ ($f)(T, y)::T for y in x ], size(x)) - end - function ($f){R}(x::AbstractArray{R,1}, digits::Integer, base::Integer=10) - [ ($f)(y, digits, base) for y in x ] - end - function ($f){R}(x::AbstractArray{R,2}, digits::Integer, base::Integer=10) - [ ($f)(x[i,j], digits, base) for i = 1:size(x,1), j = 1:size(x,2) ] - end - function ($f)(x::AbstractArray, digits::Integer, base::Integer=10) - reshape([ ($f)(y, digits, base) for y in x ], size(x)) - end - end -end - -function round{R}(x::AbstractArray{R,1}, r::RoundingMode) - [ round(y, r) for y in x ] -end -function round{R}(x::AbstractArray{R,2}, r::RoundingMode) - [ round(x[i,j], r) for i = 1:size(x,1), j = 1:size(x,2) ] -end -function round(x::AbstractArray, r::RoundingMode) - reshape([ round(y, r) for y in x ], size(x)) -end - -function round{T,R}(::Type{T}, x::AbstractArray{R,1}, r::RoundingMode) - [ round(T, y, r)::T for y in x ] -end -function round{T,R}(::Type{T}, x::AbstractArray{R,2}, r::RoundingMode) - [ round(T, x[i,j], r)::T for i = 1:size(x,1), j = 1:size(x,2) ] -end -function round{T}(::Type{T}, x::AbstractArray, r::RoundingMode) - reshape([ round(T, y, r)::T for y in x ], size(x)) -end - # adapted from Matlab File Exchange roundsd: http://www.mathworks.com/matlabcentral/fileexchange/26212 # for round, og is the power of 10 relative to the decimal point # for signif, og is the absolute power of 10 diff --git a/base/linalg/bidiag.jl b/base/linalg/bidiag.jl index 2dc1882f4e16e..98db1a3fa26af 100644 --- a/base/linalg/bidiag.jl +++ b/base/linalg/bidiag.jl @@ -211,7 +211,7 @@ convert{Tnew,Told}(::Type{Bidiagonal{Tnew}}, A::Bidiagonal{Told}) = Bidiagonal(c # When asked to convert Bidiagonal{Told} to AbstractMatrix{Tnew}, preserve structure by converting to Bidiagonal{Tnew} <: AbstractMatrix{Tnew} convert{Tnew,Told}(::Type{AbstractMatrix{Tnew}}, A::Bidiagonal{Told}) = convert(Bidiagonal{Tnew}, A) -big(B::Bidiagonal) = Bidiagonal(big(B.dv), big(B.ev), B.isupper) +broadcast(::typeof(big), B::Bidiagonal) = Bidiagonal(big.(B.dv), big.(B.ev), B.isupper) similar{T}(B::Bidiagonal, ::Type{T}) = Bidiagonal{T}(similar(B.dv, T), similar(B.ev, T), B.isupper) @@ -253,12 +253,17 @@ end #Elementary operations broadcast(::typeof(abs), M::Bidiagonal) = Bidiagonal(abs.(M.dv), abs.(M.ev), abs.(M.isupper)) -for func in (:conj, :copy, :round, :trunc, :floor, :ceil, :real, :imag) +broadcast(::typeof(round), M::Bidiagonal) = Bidiagonal(round.(M.dv), round.(M.ev), M.isupper) +broadcast(::typeof(trunc), M::Bidiagonal) = Bidiagonal(trunc.(M.dv), trunc.(M.ev), M.isupper) +broadcast(::typeof(floor), M::Bidiagonal) = Bidiagonal(floor.(M.dv), floor.(M.ev), M.isupper) +broadcast(::typeof(ceil), M::Bidiagonal) = Bidiagonal(ceil.(M.dv), ceil.(M.ev), M.isupper) +for func in (:conj, :copy, :real, :imag) @eval ($func)(M::Bidiagonal) = Bidiagonal(($func)(M.dv), ($func)(M.ev), M.isupper) end -for func in (:round, :trunc, :floor, :ceil) - @eval ($func){T<:Integer}(::Type{T}, M::Bidiagonal) = Bidiagonal(($func)(T,M.dv), ($func)(T,M.ev), M.isupper) -end +broadcast{T<:Integer}(::typeof(round), ::Type{T}, M::Bidiagonal) = Bidiagonal(round.(T, M.dv), round.(T, M.ev), M.isupper) +broadcast{T<:Integer}(::typeof(trunc), ::Type{T}, M::Bidiagonal) = Bidiagonal(trunc.(T, M.dv), trunc.(T, M.ev), M.isupper) +broadcast{T<:Integer}(::typeof(floor), ::Type{T}, M::Bidiagonal) = Bidiagonal(floor.(T, M.dv), floor.(T, M.ev), M.isupper) +broadcast{T<:Integer}(::typeof(ceil), ::Type{T}, M::Bidiagonal) = Bidiagonal(ceil.(T, M.dv), ceil.(T, M.ev), M.isupper) transpose(M::Bidiagonal) = Bidiagonal(M.dv, M.ev, !M.isupper) ctranspose(M::Bidiagonal) = Bidiagonal(conj(M.dv), conj(M.ev), !M.isupper) diff --git a/base/linalg/triangular.jl b/base/linalg/triangular.jl index 561a375681164..a0eda4499fdf6 100644 --- a/base/linalg/triangular.jl +++ b/base/linalg/triangular.jl @@ -36,7 +36,7 @@ for t in (:LowerTriangular, :UnitLowerTriangular, :UpperTriangular, copy(A::$t) = $t(copy(A.data)) - big(A::$t) = $t(big(A.data)) + broadcast(::typeof(big), A::$t) = $t(big.(A.data)) real{T<:Real}(A::$t{T}) = A real{T<:Complex}(A::$t{T}) = (B = real(A.data); $t(B)) diff --git a/base/linalg/tridiag.jl b/base/linalg/tridiag.jl index ad433bb6a3bf7..26c2e7fe49b6e 100644 --- a/base/linalg/tridiag.jl +++ b/base/linalg/tridiag.jl @@ -97,12 +97,18 @@ similar{T}(S::SymTridiagonal, ::Type{T}) = SymTridiagonal{T}(similar(S.dv, T), s #Elementary operations broadcast(::typeof(abs), M::SymTridiagonal) = SymTridiagonal(abs.(M.dv), abs.(M.ev)) -for func in (:conj, :copy, :round, :trunc, :floor, :ceil, :real, :imag) +broadcast(::typeof(round), M::SymTridiagonal) = SymTridiagonal(round.(M.dv), round.(M.ev)) +broadcast(::typeof(trunc), M::SymTridiagonal) = SymTridiagonal(trunc.(M.dv), trunc.(M.ev)) +broadcast(::typeof(floor), M::SymTridiagonal) = SymTridiagonal(floor.(M.dv), floor.(M.ev)) +broadcast(::typeof(ceil), M::SymTridiagonal) = SymTridiagonal(ceil.(M.dv), ceil.(M.ev)) +for func in (:conj, :copy, :real, :imag) @eval ($func)(M::SymTridiagonal) = SymTridiagonal(($func)(M.dv), ($func)(M.ev)) end -for func in (:round, :trunc, :floor, :ceil) - @eval ($func){T<:Integer}(::Type{T},M::SymTridiagonal) = SymTridiagonal(($func)(T,M.dv), ($func)(T,M.ev)) -end +broadcast{T<:Integer}(::typeof(round), ::Type{T}, M::SymTridiagonal) = SymTridiagonal(round.(T, M.dv), round.(T, M.ev)) +broadcast{T<:Integer}(::typeof(trunc), ::Type{T}, M::SymTridiagonal) = SymTridiagonal(trunc.(T, M.dv), trunc.(T, M.ev)) +broadcast{T<:Integer}(::typeof(floor), ::Type{T}, M::SymTridiagonal) = SymTridiagonal(floor.(T, M.dv), floor.(T, M.ev)) +broadcast{T<:Integer}(::typeof(ceil), ::Type{T}, M::SymTridiagonal) = SymTridiagonal(ceil.(T, M.dv), ceil.(T, M.ev)) + transpose(M::SymTridiagonal) = M #Identity operation ctranspose(M::SymTridiagonal) = conj(M) @@ -502,16 +508,23 @@ copy!(dest::Tridiagonal, src::Tridiagonal) = Tridiagonal(copy!(dest.dl, src.dl), #Elementary operations broadcast(::typeof(abs), M::Tridiagonal) = Tridiagonal(abs.(M.dl), abs.(M.d), abs.(M.du), abs.(M.du2)) -for func in (:conj, :copy, :round, :trunc, :floor, :ceil, :real, :imag) +broadcast(::typeof(round), M::Tridiagonal) = Tridiagonal(round.(M.dl), round.(M.d), round.(M.du), round.(M.du2)) +broadcast(::typeof(trunc), M::Tridiagonal) = Tridiagonal(trunc.(M.dl), trunc.(M.d), trunc.(M.du), trunc.(M.du2)) +broadcast(::typeof(floor), M::Tridiagonal) = Tridiagonal(floor.(M.dl), floor.(M.d), floor.(M.du), floor.(M.du2)) +broadcast(::typeof(ceil), M::Tridiagonal) = Tridiagonal(ceil.(M.dl), ceil.(M.d), ceil.(M.du), ceil.(M.du2)) +for func in (:conj, :copy, :real, :imag) @eval function ($func)(M::Tridiagonal) Tridiagonal(($func)(M.dl), ($func)(M.d), ($func)(M.du), ($func)(M.du2)) end end -for func in (:round, :trunc, :floor, :ceil) - @eval function ($func){T<:Integer}(::Type{T},M::Tridiagonal) - Tridiagonal(($func)(T,M.dl), ($func)(T,M.d), ($func)(T,M.du), ($func)(T,M.du2)) - end -end +broadcast{T<:Integer}(::typeof(round), ::Type{T}, M::Tridiagonal) = + Tridiagonal(round.(T, M.dl), round.(T, M.d), round.(T, M.du), round.(T, M.du2)) +broadcast{T<:Integer}(::typeof(trunc), ::Type{T}, M::Tridiagonal) = + Tridiagonal(trunc.(T, M.dl), trunc.(T, M.d), trunc.(T, M.du), trunc.(T, M.du2)) +broadcast{T<:Integer}(::typeof(floor), ::Type{T}, M::Tridiagonal) = + Tridiagonal(floor.(T, M.dl), floor.(T, M.d), floor.(T, M.du), floor.(T, M.du2)) +broadcast{T<:Integer}(::typeof(ceil), ::Type{T}, M::Tridiagonal) = + Tridiagonal(ceil.(T, M.dl), ceil.(T, M.d), ceil.(T, M.du), ceil.(T, M.du2)) transpose(M::Tridiagonal) = Tridiagonal(M.du, M.d, M.dl) ctranspose(M::Tridiagonal) = conj(transpose(M)) diff --git a/base/math.jl b/base/math.jl index c15bf1f64d554..ea3f0cf5d8cc0 100644 --- a/base/math.jl +++ b/base/math.jl @@ -39,10 +39,10 @@ import Core.Intrinsics: sqrt_llvm, box, unbox, powi_llvm clamp(x, lo, hi) Return `x` if `lo <= x <= hi`. If `x < lo`, return `lo`. If `x > hi`, return `hi`. Arguments -are promoted to a common type. Operates elementwise over `x` if `x` is an array. +are promoted to a common type. ```jldoctest -julia> clamp([pi, 1.0, big(10.)], 2., 9.) +julia> clamp.([pi, 1.0, big(10.)], 2., 9.) 3-element Array{BigFloat,1}: 3.141592653589793238462643383279502884197169399375105820974944592307816406286198 2.000000000000000000000000000000000000000000000000000000000000000000000000000000 @@ -55,13 +55,6 @@ clamp{X,L,H}(x::X, lo::L, hi::H) = convert(promote_type(X,L,H), lo), convert(promote_type(X,L,H), x))) -clamp{T}(x::AbstractArray{T,1}, lo, hi) = [clamp(xx, lo, hi) for xx in x] -clamp{T}(x::AbstractArray{T,2}, lo, hi) = - [clamp(x[i,j], lo, hi) for i in indices(x,1), j in indices(x,2)] - -clamp{T}(x::AbstractArray{T}, lo, hi) = - reshape([clamp(xx, lo, hi) for xx in x], size(x)) - """ clamp!(array::AbstractArray, lo, hi) diff --git a/base/rational.jl b/base/rational.jl index 3304247d9783e..8066ecff200df 100644 --- a/base/rational.jl +++ b/base/rational.jl @@ -80,7 +80,6 @@ convert(::Type{Rational}, x::Float64) = convert(Rational{Int64}, x) convert(::Type{Rational}, x::Float32) = convert(Rational{Int}, x) big{T<:Integer}(z::Complex{Rational{T}}) = Complex{Rational{BigInt}}(z) -big{T<:Integer,N}(x::AbstractArray{Complex{Rational{T}},N}) = convert(AbstractArray{Complex{Rational{BigInt}},N}, x) promote_rule{T<:Integer,S<:Integer}(::Type{Rational{T}}, ::Type{S}) = Rational{promote_type(T,S)} promote_rule{T<:Integer,S<:Integer}(::Type{Rational{T}}, ::Type{Rational{S}}) = Rational{promote_type(T,S)} diff --git a/base/sparse/higherorderfns.jl b/base/sparse/higherorderfns.jl index 2887eec75291e..9effb8666ee60 100644 --- a/base/sparse/higherorderfns.jl +++ b/base/sparse/higherorderfns.jl @@ -141,7 +141,6 @@ end return SparseMatrixCSC(shape..., pointers, storedinds, storedvals) end # Ambiguity killers, TODO: nix conflicting specializations -broadcast(::typeof(abs), x::SparseVector) = _noshapecheck_map(abs, x) # base/sparse/sparevectors.jl: 921 ambiguityfunnel{Tf}(f::Tf, x, y) = _aresameshape(x, y) ? _noshapecheck_map(f, x, y) : _diffshape_broadcast(f, x, y) broadcast(::typeof(+), x::SparseVector, y::SparseVector) = ambiguityfunnel(+, x, y) # base/sparse/sparsevectors.jl:1266 broadcast(::typeof(-), x::SparseVector, y::SparseVector) = ambiguityfunnel(-, x, y) # base/sparse/sparsevectors.jl:1266 diff --git a/base/sparse/sparsematrix.jl b/base/sparse/sparsematrix.jl index ea9968f706672..274f628131526 100644 --- a/base/sparse/sparsematrix.jl +++ b/base/sparse/sparsematrix.jl @@ -1403,21 +1403,10 @@ sparse(S::UniformScaling, m::Integer, n::Integer=m) = speye_scaled(S.λ, m, n) conj!(A::SparseMatrixCSC) = (broadcast!(conj, A.nzval, A.nzval); A) (-)(A::SparseMatrixCSC) = SparseMatrixCSC(A.m, A.n, copy(A.colptr), copy(A.rowval), map(-, A.nzval)) -# TODO: The following definitions should be deprecated. -ceil{To}(::Type{To}, A::SparseMatrixCSC) = ceil.(To, A) -floor{To}(::Type{To}, A::SparseMatrixCSC) = floor.(To, A) -trunc{To}(::Type{To}, A::SparseMatrixCSC) = trunc.(To, A) -round{To}(::Type{To}, A::SparseMatrixCSC) = round.(To, A) - ## Binary arithmetic and boolean operators (+)(A::SparseMatrixCSC, B::SparseMatrixCSC) = map(+, A, B) (-)(A::SparseMatrixCSC, B::SparseMatrixCSC) = map(-, A, B) -# TODO: Vectorized min, max, |, and xor should be deprecated in favor of compact-broadcast syntax. -min(A::SparseMatrixCSC, B::SparseMatrixCSC) = map(min, A, B) -max(A::SparseMatrixCSC, B::SparseMatrixCSC) = map(max, A, B) -(&)(A::SparseMatrixCSC, B::SparseMatrixCSC) = map(&, A, B) -(|)(A::SparseMatrixCSC, B::SparseMatrixCSC) = map(|, A, B) ( +)(A::SparseMatrixCSC, B::Array ) = Array(A) + B ( +)(A::Array , B::SparseMatrixCSC) = A + Array(B) diff --git a/base/sparse/sparsevector.jl b/base/sparse/sparsevector.jl index 404a5f8ca5294..f5bad384f9148 100644 --- a/base/sparse/sparsevector.jl +++ b/base/sparse/sparsevector.jl @@ -918,14 +918,8 @@ hvcat{T}(rows::Tuple{Vararg{Int}}, xs::_TypedDenseConcatGroup{T}...) = Base.type ### Unary Map # zero-preserving functions (z->z, nz->nz) -broadcast(::typeof(abs), x::AbstractSparseVector) = SparseVector(length(x), copy(nonzeroinds(x)), abs.(nonzeros(x))) -for op in [:abs2, :conj] - @eval begin - $(op)(x::AbstractSparseVector) = - SparseVector(length(x), copy(nonzeroinds(x)), $(op).(nonzeros(x))) - end -end --(x::AbstractSparseVector) = SparseVector(length(x), copy(nonzeroinds(x)), -(nonzeros(x))) +conj(x::SparseVector) = SparseVector(length(x), copy(nonzeroinds(x)), conj(nonzeros(x))) +-(x::SparseVector) = SparseVector(length(x), copy(nonzeroinds(x)), -(nonzeros(x))) # functions f, such that # f(x) can be zero or non-zero when x != 0 @@ -1271,18 +1265,17 @@ end # definition of other binary functions -for (op, TF, mode) in [(:max, :Real, 2), - (:min, :Real, 2), - (:complex, :Real, 1)] - @eval begin - $(op){Tx<:$(TF),Ty<:$(TF)}(x::AbstractSparseVector{Tx}, y::AbstractSparseVector{Ty}) = - _binarymap($(op), x, y, $mode) - $(op){Tx<:$(TF),Ty<:$(TF)}(x::StridedVector{Tx}, y::AbstractSparseVector{Ty}) = - _binarymap($(op), x, y, $mode) - $(op){Tx<:$(TF),Ty<:$(TF)}(x::AbstractSparseVector{Tx}, y::StridedVector{Ty}) = - _binarymap($(op), x, y, $mode) - end -end +broadcast{Tx<:Real,Ty<:Real}(::typeof(min), x::SparseVector{Tx}, y::SparseVector{Ty}) = _binarymap(min, x, y, 2) +broadcast{Tx<:Real,Ty<:Real}(::typeof(min), x::StridedVector{Tx}, y::SparseVector{Ty}) = _binarymap(min, x, y, 2) +broadcast{Tx<:Real,Ty<:Real}(::typeof(min), x::SparseVector{Tx}, y::SparseVector{Ty}) = _binarymap(min, x, y, 2) + +broadcast{Tx<:Real,Ty<:Real}(::typeof(max), x::SparseVector{Tx}, y::SparseVector{Ty}) = _binarymap(max, x, y, 2) +broadcast{Tx<:Real,Ty<:Real}(::typeof(max), x::StridedVector{Tx}, y::SparseVector{Ty}) = _binarymap(max, x, y, 2) +broadcast{Tx<:Real,Ty<:Real}(::typeof(max), x::SparseVector{Tx}, y::SparseVector{Ty}) = _binarymap(max, x, y, 2) + +complex{Tx<:Real,Ty<:Real}(x::StridedVector{Tx}, y::AbstractSparseVector{Ty}) = _binarymap(complex, x, y, 1) +complex{Tx<:Real,Ty<:Real}(x::AbstractSparseVector{Tx}, y::StridedVector{Ty}) = _binarymap(complex, x, y, 1) +complex{Tx<:Real,Ty<:Real}(x::AbstractSparseVector{Tx}, y::AbstractSparseVector{Ty}) = _binarymap(complex, x, y, 1) ### Reduction diff --git a/base/special/trig.jl b/base/special/trig.jl index bc84f2b972554..291503aec000c 100644 --- a/base/special/trig.jl +++ b/base/special/trig.jl @@ -311,7 +311,6 @@ for (finv, f) in ((:sec, :cos), (:csc, :sin), (:cot, :tan), (:secd, :cosd), (:cscd, :sind), (:cotd, :tand)) @eval begin ($finv){T<:Number}(z::T) = one(T) / (($f)(z)) - ($finv){T<:Number}(z::AbstractArray{T}) = one(T) ./ (($f)(z)) end end @@ -324,11 +323,9 @@ for (tfa, tfainv, hfa, hfainv, fn) in ((:asec, :acos, :asech, :acosh, "secant"), @doc """ $($tname)(x) Compute the inverse $($fn) of `x`, where the output is in radians. """ ($tfa){T<:Number}(y::T) = ($tfainv)(one(T) / y) - ($tfa){T<:Number}(y::AbstractArray{T}) = ($tfainv)(one(T) ./ y) @doc """ $($hname)(x) Compute the inverse hyperbolic $($fn) of `x`. """ ($hfa){T<:Number}(y::T) = ($hfainv)(one(T) / y) - ($hfa){T<:Number}(y::AbstractArray{T}) = ($hfainv)(one(T) ./ y) end end diff --git a/examples/lru_test.jl b/examples/lru_test.jl index 92117f027ba5e..62aa29fbf6a03 100644 --- a/examples/lru_test.jl +++ b/examples/lru_test.jl @@ -10,7 +10,7 @@ get_str(i) = String(vcat(map(x->[x>>4; x&0x0F], reinterpret(UInt8, [Int32(i)])). isbounded{L<:LRUExample.LRU}(::Type{L}) = any(map(n->n==:maxsize, fieldnames(L))) isbounded{L<:LRUExample.LRU}(l::L) = isbounded(L) -nmax = round(Int,logspace(2, 5, 4)) +nmax = round.(Int, logspace(2, 5, 4)) function lrutest() #println("LRU consistency tests") diff --git a/test/bigint.jl b/test/bigint.jl index 0527f0bd9f49a..0e791a7be82e2 100644 --- a/test/bigint.jl +++ b/test/bigint.jl @@ -275,10 +275,10 @@ ndigits_mismatch(n) = ndigits(n) != ndigits(BigInt(n)) @test !any(ndigits_mismatch, 8192:9999) # The following should not crash (#16579) -ndigits(rand(big(-999:999)), rand(63:typemax(Int))) -ndigits(rand(big(-999:999)), big(2)^rand(2:999)) +ndigits(rand(big.(-999:999)), rand(63:typemax(Int))) +ndigits(rand(big.(-999:999)), big(2)^rand(2:999)) -for i in big([-20:-1;1:20]) +for i in big.([-20:-1;1:20]) for b in -10:1 @test_throws DomainError ndigits(i, b) end diff --git a/test/bitarray.jl b/test/bitarray.jl index 68e75746c3c26..9b4649e3f1111 100644 --- a/test/bitarray.jl +++ b/test/bitarray.jl @@ -13,7 +13,7 @@ tc(r1,r2) = false bitcheck(b::BitArray) = Base._check_bitarray_consistency(b) bitcheck(x) = true -function check_bitop(ret_type, func, args...) +function check_bitop_call(ret_type, func, args...) r1 = func(args...) r2 = func(map(x->(isa(x, BitArray) ? Array(x) : x), args)...) ret_type ≢ nothing && !isa(r1, ret_type) && @show ret_type, r1 @@ -22,15 +22,13 @@ function check_bitop(ret_type, func, args...) @test isequal(r1, ret_type ≡ nothing ? r2 : convert(ret_type, r2)) @test bitcheck(r1) end - macro check_bit_operation(ex, ret_type) @assert Meta.isexpr(ex, :call) - Expr(:call, :check_bitop, esc(ret_type), map(esc,ex.args)...) + Expr(:call, :check_bitop_call, esc(ret_type), map(esc, ex.args)...) end - macro check_bit_operation(ex) @assert Meta.isexpr(ex, :call) - Expr(:call, :check_bitop, nothing, map(esc,ex.args)...) + Expr(:call, :check_bitop_call, nothing, map(esc, ex.args)...) end let t0 = time() @@ -782,8 +780,8 @@ timesofar("unary arithmetic") let b1 = bitrand(n1, n2) b2 = bitrand(n1, n2) - @check_bit_operation (&)(b1, b2) BitMatrix - @check_bit_operation (|)(b1, b2) BitMatrix + @check_bit_operation broadcast(&, b1, b2) BitMatrix + @check_bit_operation broadcast(|, b1, b2) BitMatrix @check_bit_operation broadcast(xor, b1, b2) BitMatrix @check_bit_operation (+)(b1, b2) Matrix{Int} @check_bit_operation (-)(b1, b2) Matrix{Int} @@ -793,12 +791,12 @@ let b1 = bitrand(n1, n2) @check_bit_operation (/)(b1,1) Matrix{Float64} b2 = trues(n1, n2) - @check_bit_operation div(b1, b2) BitMatrix - @check_bit_operation mod(b1, b2) BitMatrix - @check_bit_operation div(b1,Array(b2)) BitMatrix - @check_bit_operation mod(b1,Array(b2)) BitMatrix - @check_bit_operation div(Array(b1),b2) BitMatrix - @check_bit_operation mod(Array(b1),b2) BitMatrix + @check_bit_operation broadcast(div, b1, b2) BitMatrix + @check_bit_operation broadcast(mod, b1, b2) BitMatrix + @check_bit_operation broadcast(div, b1, Array(b2)) BitMatrix + @check_bit_operation broadcast(mod, b1, Array(b2)) BitMatrix + @check_bit_operation broadcast(div, Array(b1), b2) BitMatrix + @check_bit_operation broadcast(mod, Array(b1), b2) BitMatrix end let b1 = bitrand(n1, n1) @@ -813,8 +811,8 @@ let b1 = bitrand(n1, n1) end let b0 = falses(0) - @check_bit_operation (&)(b0, b0) BitVector - @check_bit_operation (|)(b0, b0) BitVector + @check_bit_operation broadcast(&, b0, b0) BitVector + @check_bit_operation broadcast(|, b0, b0) BitVector @check_bit_operation broadcast(xor, b0, b0) BitVector @check_bit_operation broadcast(*, b0, b0) BitVector @check_bit_operation (*)(b0, b0') Matrix{Int} @@ -824,16 +822,16 @@ end let b1 = bitrand(n1, n2) i2 = rand(1:10, n1, n2) - @check_bit_operation (&)(b1, i2) Matrix{Int} - @check_bit_operation (|)(b1, i2) Matrix{Int} + @check_bit_operation broadcast(&, b1, i2) Matrix{Int} + @check_bit_operation broadcast(|, b1, i2) Matrix{Int} @check_bit_operation broadcast(xor, b1, i2) Matrix{Int} @check_bit_operation (+)(b1, i2) Matrix{Int} @check_bit_operation (-)(b1, i2) Matrix{Int} @check_bit_operation broadcast(*, b1, i2) Matrix{Int} @check_bit_operation broadcast(/, b1, i2) Matrix{Float64} @check_bit_operation broadcast(^, b1, i2) BitMatrix - @check_bit_operation div(b1, i2) Matrix{Int} - @check_bit_operation mod(b1, i2) Matrix{Int} + @check_bit_operation broadcast(div, b1, i2) Matrix{Int} + @check_bit_operation broadcast(mod, b1, i2) Matrix{Int} end # Matrix{Bool}/Matrix{Float64} @@ -843,8 +841,8 @@ let b1 = bitrand(n1, n2) @check_bit_operation broadcast(*, b1, f2) Matrix{Float64} @check_bit_operation broadcast(/, b1, f2) Matrix{Float64} @check_bit_operation broadcast(^, b1, f2) Matrix{Float64} - @check_bit_operation div(b1, f2) Matrix{Float64} - @check_bit_operation mod(b1, f2) Matrix{Float64} + @check_bit_operation broadcast(div, b1, f2) Matrix{Float64} + @check_bit_operation broadcast(mod, b1, f2) Matrix{Float64} end # Number/Matrix @@ -857,15 +855,15 @@ let b2 = bitrand(n1, n2) cu1 = complex(u1) cf1 = complex(f1) - @check_bit_operation (&)(i1, b2) Matrix{Int} - @check_bit_operation (|)(i1, b2) Matrix{Int} + @check_bit_operation broadcast(&, i1, b2) Matrix{Int} + @check_bit_operation broadcast(|, i1, b2) Matrix{Int} @check_bit_operation broadcast(xor, i1, b2) Matrix{Int} @check_bit_operation broadcast(+, i1, b2) Matrix{Int} @check_bit_operation broadcast(-, i1, b2) Matrix{Int} @check_bit_operation broadcast(*, i1, b2) Matrix{Int} - @check_bit_operation (&)(u1, b2) Matrix{UInt8} - @check_bit_operation (|)(u1, b2) Matrix{UInt8} + @check_bit_operation broadcast(&, u1, b2) Matrix{UInt8} + @check_bit_operation broadcast(|, u1, b2) Matrix{UInt8} @check_bit_operation broadcast(xor, u1, b2) Matrix{UInt8} @check_bit_operation broadcast(+, u1, b2) Matrix{UInt8} @check_bit_operation broadcast(-, u1, b2) Matrix{UInt8} @@ -882,23 +880,23 @@ let b2 = bitrand(n1, n2) b2 = trues(n1, n2) @check_bit_operation broadcast(/, true, b2) Matrix{Float64} - @check_bit_operation div(true, b2) BitMatrix - @check_bit_operation mod(true, b2) BitMatrix + @check_bit_operation broadcast(div, true, b2) BitMatrix + @check_bit_operation broadcast(mod, true, b2) BitMatrix @check_bit_operation broadcast(/, false, b2) Matrix{Float64} - @check_bit_operation div(false, b2) BitMatrix - @check_bit_operation mod(false, b2) BitMatrix + @check_bit_operation broadcast(div, false, b2) BitMatrix + @check_bit_operation broadcast(mod, false, b2) BitMatrix @check_bit_operation broadcast(/, i1, b2) Matrix{Float64} - @check_bit_operation div(i1, b2) Matrix{Int} - @check_bit_operation mod(i1, b2) Matrix{Int} + @check_bit_operation broadcast(div, i1, b2) Matrix{Int} + @check_bit_operation broadcast(mod, i1, b2) Matrix{Int} @check_bit_operation broadcast(/, u1, b2) Matrix{Float64} - @check_bit_operation div(u1, b2) Matrix{UInt8} - @check_bit_operation mod(u1, b2) Matrix{UInt8} + @check_bit_operation broadcast(div, u1, b2) Matrix{UInt8} + @check_bit_operation broadcast(mod, u1, b2) Matrix{UInt8} @check_bit_operation broadcast(/, f1, b2) Matrix{Float64} - @check_bit_operation div(f1, b2) Matrix{Float64} - @check_bit_operation mod(f1, b2) Matrix{Float64} + @check_bit_operation broadcast(div, f1, b2) Matrix{Float64} + @check_bit_operation broadcast(mod, f1, b2) Matrix{Float64} @check_bit_operation broadcast(/, ci1, b2) Matrix{Complex128} @check_bit_operation broadcast(/, cu1, b2) Matrix{Complex128} @@ -933,14 +931,14 @@ let b1 = bitrand(n1, n2) cf2 = complex(f2) b2 = Array(bitrand(n1,n2)) - @check_bit_operation (&)(b1, true) BitMatrix - @check_bit_operation (&)(b1, false) BitMatrix - @check_bit_operation (&)(true, b1) BitMatrix - @check_bit_operation (&)(false, b1) BitMatrix - @check_bit_operation (|)(b1, true) BitMatrix - @check_bit_operation (|)(b1, false) BitMatrix - @check_bit_operation (|)(true, b1) BitMatrix - @check_bit_operation (|)(false, b1) BitMatrix + @check_bit_operation broadcast(&, b1, true) BitMatrix + @check_bit_operation broadcast(&, b1, false) BitMatrix + @check_bit_operation broadcast(&, true, b1) BitMatrix + @check_bit_operation broadcast(&, false, b1) BitMatrix + @check_bit_operation broadcast(|, b1, true) BitMatrix + @check_bit_operation broadcast(|, b1, false) BitMatrix + @check_bit_operation broadcast(|, true, b1) BitMatrix + @check_bit_operation broadcast(|, false, b1) BitMatrix @check_bit_operation broadcast(xor, b1, true) BitMatrix @check_bit_operation broadcast(xor, b1, false) BitMatrix @check_bit_operation broadcast(xor, true, b1) BitMatrix @@ -955,41 +953,41 @@ let b1 = bitrand(n1, n2) @check_bit_operation broadcast(*, false, b1) BitMatrix @check_bit_operation broadcast(/, b1, true) Matrix{Float64} @check_bit_operation broadcast(/, b1, false) Matrix{Float64} - @check_bit_operation div(b1, true) BitMatrix - @check_bit_operation mod(b1, true) BitMatrix + @check_bit_operation broadcast(div, b1, true) BitMatrix + @check_bit_operation broadcast(mod,b1, true) BitMatrix - @check_bit_operation (&)(b1, b2) BitMatrix - @check_bit_operation (|)(b1, b2) BitMatrix + @check_bit_operation broadcast(&, b1, b2) BitMatrix + @check_bit_operation broadcast(|, b1, b2) BitMatrix @check_bit_operation broadcast(xor, b1, b2) BitMatrix - @check_bit_operation (&)(b2, b1) BitMatrix - @check_bit_operation (|)(b2, b1) BitMatrix + @check_bit_operation broadcast(&, b2, b1) BitMatrix + @check_bit_operation broadcast(|, b2, b1) BitMatrix @check_bit_operation broadcast(xor, b2, b1) BitMatrix - @check_bit_operation (&)(b1, i2) Matrix{Int} - @check_bit_operation (|)(b1, i2) Matrix{Int} + @check_bit_operation broadcast(&, b1, i2) Matrix{Int} + @check_bit_operation broadcast(|, b1, i2) Matrix{Int} @check_bit_operation broadcast(xor, b1, i2) Matrix{Int} @check_bit_operation broadcast(+, b1, i2) Matrix{Int} @check_bit_operation broadcast(-, b1, i2) Matrix{Int} @check_bit_operation broadcast(*, b1, i2) Matrix{Int} @check_bit_operation broadcast(/, b1, i2) Matrix{Float64} - @check_bit_operation div(b1, i2) Matrix{Int} - @check_bit_operation mod(b1, i2) Matrix{Int} + @check_bit_operation broadcast(div, b1, i2) Matrix{Int} + @check_bit_operation broadcast(mod, b1, i2) Matrix{Int} - @check_bit_operation (&)(b1, u2) Matrix{UInt8} - @check_bit_operation (|)(b1, u2) Matrix{UInt8} + @check_bit_operation broadcast(&, b1, u2) Matrix{UInt8} + @check_bit_operation broadcast(|, b1, u2) Matrix{UInt8} @check_bit_operation broadcast(xor, b1, u2) Matrix{UInt8} @check_bit_operation broadcast(+, b1, u2) Matrix{UInt8} @check_bit_operation broadcast(-, b1, u2) Matrix{UInt8} @check_bit_operation broadcast(*, b1, u2) Matrix{UInt8} @check_bit_operation broadcast(/, b1, u2) Matrix{Float64} - @check_bit_operation div(b1, u2) Matrix{UInt8} - @check_bit_operation mod(b1, u2) Matrix{UInt8} + @check_bit_operation broadcast(div, b1, u2) Matrix{UInt8} + @check_bit_operation broadcast(mod, b1, u2) Matrix{UInt8} @check_bit_operation broadcast(+, b1, f2) Matrix{Float64} @check_bit_operation broadcast(-, b1, f2) Matrix{Float64} @check_bit_operation broadcast(*, b1, f2) Matrix{Float64} @check_bit_operation broadcast(/, b1, f2) Matrix{Float64} - @check_bit_operation div(b1, f2) Matrix{Float64} - @check_bit_operation mod(b1, f2) Matrix{Float64} + @check_bit_operation broadcast(div, b1, f2) Matrix{Float64} + @check_bit_operation broadcast(mod, b1, f2) Matrix{Float64} @check_bit_operation broadcast(+, b1, ci2) Matrix{Complex{Int}} @check_bit_operation broadcast(-, b1, ci2) Matrix{Complex{Int}} @@ -1118,7 +1116,7 @@ let b1 = trues(v1) for i = 3:(v1-1), j = 2:i submask = b1 << (v1-j+1) - @test findnext((b1 >> i) | submask, j) == i+1 + @test findnext((b1 >> i) .| submask, j) == i+1 @test findnextnot((~(b1 >> i)) .⊻ submask, j) == i+1 end end @@ -1274,8 +1272,8 @@ for l = [0, 1, 63, 64, 65, 127, 128, 129, 255, 256, 257, 6399, 6400, 6401] @test map(~, b1) == map(x->~x, b1) == ~b1 @test map(identity, b1) == map(x->x, b1) == b1 - @test map(&, b1, b2) == map((x,y)->x&y, b1, b2) == b1 & b2 - @test map(|, b1, b2) == map((x,y)->x|y, b1, b2) == b1 | b2 + @test map(&, b1, b2) == map((x,y)->x&y, b1, b2) == broadcast(&, b1, b2) + @test map(|, b1, b2) == map((x,y)->x|y, b1, b2) == broadcast(|, b1, b2) @test map(⊻, b1, b2) == map((x,y)->x⊻y, b1, b2) == broadcast(⊻, b1, b2) == broadcast(xor, b1, b2) @test map(^, b1, b2) == map((x,y)->x^y, b1, b2) == b1 .^ b2 @@ -1299,8 +1297,8 @@ for l = [0, 1, 63, 64, 65, 127, 128, 129, 255, 256, 257, 6399, 6400, 6401] @test map!(zero, b, b1) == map!(x->false, b, b1) == falses(l) == b @test map!(one, b, b1) == map!(x->true, b, b1) == trues(l) == b - @test map!(&, b, b1, b2) == map!((x,y)->x&y, b, b1, b2) == b1 & b2 == b - @test map!(|, b, b1, b2) == map!((x,y)->x|y, b, b1, b2) == b1 | b2 == b + @test map!(&, b, b1, b2) == map!((x,y)->x&y, b, b1, b2) == broadcast(&, b1, b2) == b + @test map!(|, b, b1, b2) == map!((x,y)->x|y, b, b1, b2) == broadcast(|, b1, b2) == b @test map!(⊻, b, b1, b2) == map!((x,y)->x⊻y, b, b1, b2) == broadcast(⊻, b1, b2) == broadcast(xor, b1, b2) == b @test map!(^, b, b1, b2) == map!((x,y)->x^y, b, b1, b2) == b1 .^ b2 == b @@ -1409,7 +1407,7 @@ for sz = [(n1,n1), (n1,n2), (n2,n1)], (f,isf) = [(tril,istril), (triu,istriu)] end let b1 = bitrand(n1,n1) - b1 |= b1.' + b1 .|= b1.' @check_bit_operation issymmetric(b1) Bool @check_bit_operation ishermitian(b1) Bool end diff --git a/test/floatfuncs.jl b/test/floatfuncs.jl index 78546eae1b3ff..94a751ad447ce 100644 --- a/test/floatfuncs.jl +++ b/test/floatfuncs.jl @@ -45,26 +45,26 @@ end for elty in (Float32,Float64) x = rand(elty) A = fill(x,(10,10)) - @test round(A,RoundToZero) == fill(trunc(x),(10,10)) - @test round(A,RoundUp) == fill(ceil(x),(10,10)) - @test round(A,RoundDown) == fill(floor(x),(10,10)) + @test round.(A,RoundToZero) == fill(trunc(x),(10,10)) + @test round.(A,RoundUp) == fill(ceil(x),(10,10)) + @test round.(A,RoundDown) == fill(floor(x),(10,10)) A = fill(x,(10,10,10)) - @test round(A,RoundToZero) == fill(trunc(x),(10,10,10)) - @test round(A,RoundUp) == fill(ceil(x),(10,10,10)) - @test round(A,RoundDown) == fill(floor(x),(10,10,10)) + @test round.(A,RoundToZero) == fill(trunc(x),(10,10,10)) + @test round.(A,RoundUp) == fill(ceil(x),(10,10,10)) + @test round.(A,RoundDown) == fill(floor(x),(10,10,10)) for elty2 in (Int32,Int64) A = fill(x,(10,)) - @test round(elty2,A,RoundToZero) == fill(trunc(elty2,x),(10,)) - @test round(elty2,A,RoundUp) == fill(ceil(elty2,x),(10,)) - @test round(elty2,A,RoundDown) == fill(floor(elty2,x),(10,)) + @test round.(elty2,A,RoundToZero) == fill(trunc(elty2,x),(10,)) + @test round.(elty2,A,RoundUp) == fill(ceil(elty2,x),(10,)) + @test round.(elty2,A,RoundDown) == fill(floor(elty2,x),(10,)) A = fill(x,(10,10)) - @test round(elty2,A,RoundToZero) == fill(trunc(elty2,x),(10,10)) - @test round(elty2,A,RoundUp) == fill(ceil(elty2,x),(10,10)) - @test round(elty2,A,RoundDown) == fill(floor(elty2,x),(10,10)) + @test round.(elty2,A,RoundToZero) == fill(trunc(elty2,x),(10,10)) + @test round.(elty2,A,RoundUp) == fill(ceil(elty2,x),(10,10)) + @test round.(elty2,A,RoundDown) == fill(floor(elty2,x),(10,10)) A = fill(x,(10,10,10)) - @test round(elty2,A,RoundToZero) == fill(trunc(elty2,x),(10,10,10)) - @test round(elty2,A,RoundUp) == fill(ceil(elty2,x),(10,10,10)) - @test round(elty2,A,RoundDown) == fill(floor(elty2,x),(10,10,10)) - @test round(elty2,A) == fill(round(elty2,x),(10,10,10)) + @test round.(elty2,A,RoundToZero) == fill(trunc(elty2,x),(10,10,10)) + @test round.(elty2,A,RoundUp) == fill(ceil(elty2,x),(10,10,10)) + @test round.(elty2,A,RoundDown) == fill(floor(elty2,x),(10,10,10)) + @test round.(elty2,A) == fill(round(elty2,x),(10,10,10)) end end diff --git a/test/linalg/arnoldi.jl b/test/linalg/arnoldi.jl index 26e6653835c1f..84f43d3cdf764 100644 --- a/test/linalg/arnoldi.jl +++ b/test/linalg/arnoldi.jl @@ -236,9 +236,9 @@ end eigs(rand(1:10, 10, 10)) eigs(rand(1:10, 10, 10), rand(1:10, 10, 10) |> t -> t't) svds(rand(1:10, 10, 8)) - @test_throws MethodError eigs(big(rand(1:10, 10, 10))) - @test_throws MethodError eigs(big(rand(1:10, 10, 10)), rand(1:10, 10, 10)) - @test_throws MethodError svds(big(rand(1:10, 10, 8))) + @test_throws MethodError eigs(big.(rand(1:10, 10, 10))) + @test_throws MethodError eigs(big.(rand(1:10, 10, 10)), rand(1:10, 10, 10)) + @test_throws MethodError svds(big.(rand(1:10, 10, 8))) end # Symmetric generalized with singular B diff --git a/test/linalg/bidiag.jl b/test/linalg/bidiag.jl index b5b8110a49b6e..3ff104c84d30b 100644 --- a/test/linalg/bidiag.jl +++ b/test/linalg/bidiag.jl @@ -63,7 +63,7 @@ srand(1) @test size(T) == (n, n) @test Array(T) == diagm(dv) + diagm(ev, isupper?1:-1) @test Bidiagonal(Array(T), isupper) == T - @test big(T) == T + @test big.(T) == T @test Array(abs.(T)) == abs.(diagm(dv)) + abs.(diagm(ev, isupper?1:-1)) @test Array(real(T)) == real(diagm(dv)) + real(diagm(ev, isupper?1:-1)) @test Array(imag(T)) == imag(diagm(dv)) + imag(diagm(ev, isupper?1:-1)) @@ -160,14 +160,14 @@ srand(1) @testset "Round,float,trunc,ceil" begin if elty <: BlasReal - @test floor(Int,T) == Bidiagonal(floor(Int,T.dv),floor(Int,T.ev),T.isupper) - @test isa(floor(Int,T), Bidiagonal) - @test trunc(Int,T) == Bidiagonal(trunc(Int,T.dv),trunc(Int,T.ev),T.isupper) - @test isa(trunc(Int,T), Bidiagonal) - @test round(Int,T) == Bidiagonal(round(Int,T.dv),round(Int,T.ev),T.isupper) - @test isa(round(Int,T), Bidiagonal) - @test ceil(Int,T) == Bidiagonal(ceil(Int,T.dv),ceil(Int,T.ev),T.isupper) - @test isa(ceil(Int,T), Bidiagonal) + @test floor.(Int, T) == Bidiagonal(floor.(Int, T.dv), floor.(Int, T.ev), T.isupper) + @test isa(floor.(Int, T), Bidiagonal) + @test trunc.(Int,T) == Bidiagonal(trunc.(Int, T.dv), trunc.(Int, T.ev), T.isupper) + @test isa(trunc.(Int,T), Bidiagonal) + @test round.(Int, T) == Bidiagonal(round.(Int, T.dv), round.(Int, T.ev), T.isupper) + @test isa(round.(Int, T), Bidiagonal) + @test ceil.(Int,T) == Bidiagonal(ceil.(Int,T.dv), ceil.(Int,T.ev), T.isupper) + @test isa(ceil.(Int,T), Bidiagonal) end end diff --git a/test/linalg/generic.jl b/test/linalg/generic.jl index 296e7f02fc2f0..f31b099a05fcd 100644 --- a/test/linalg/generic.jl +++ b/test/linalg/generic.jl @@ -235,7 +235,7 @@ end @test !issymmetric(NaN) @test rank([1.0 0.0; 0.0 0.9],0.95) == 1 -@test qr(big([0 1; 0 0]))[2] == [0 1; 0 0] +@test qr(big.([0 1; 0 0]))[2] == [0 1; 0 0] @test norm([2.4e-322, 4.4e-323]) ≈ 2.47e-322 @test norm([2.4e-322, 4.4e-323], 3) ≈ 2.4e-322 diff --git a/test/linalg/qr.jl b/test/linalg/qr.jl index 8df1097b926d6..5e42c2375a614 100644 --- a/test/linalg/qr.jl +++ b/test/linalg/qr.jl @@ -148,8 +148,8 @@ end @test_throws ErrorException ctranspose(qrfact(randn(3,3))) @test_throws ErrorException transpose(qrfact(randn(3,3), Val{false})) @test_throws ErrorException ctranspose(qrfact(randn(3,3), Val{false})) -@test_throws ErrorException transpose(qrfact(big(randn(3,3)))) -@test_throws ErrorException ctranspose(qrfact(big(randn(3,3)))) +@test_throws ErrorException transpose(qrfact(big.(randn(3,3)))) +@test_throws ErrorException ctranspose(qrfact(big.(randn(3,3)))) # Issue 7304 let diff --git a/test/linalg/triangular.jl b/test/linalg/triangular.jl index 3cb032ed9aa35..4eef3fb6cd8fc 100644 --- a/test/linalg/triangular.jl +++ b/test/linalg/triangular.jl @@ -417,7 +417,7 @@ for eltya in (Float32, Float64, Complex64, Complex128, BigFloat, Int) x = Atri \ b γ = n*ε/(1 - n*ε) if eltya != BigFloat - bigA = big(Atri) + bigA = big.(Atri) x̂ = ones(n, 2) for i = 1:size(b, 2) @test norm(x̂[:,i] - x[:,i], Inf)/norm(x̂[:,i], Inf) <= condskeel(bigA, x̂[:,i])*γ/(1 - condskeel(bigA)*γ) @@ -442,11 +442,11 @@ for eltya in (Float32, Float64, Complex64, Complex128, BigFloat, Int) end debug && println("Test forward error [JIN 5705] if this is not a BigFloat") - b = eltyb == Int ? trunc(Int,Atri*ones(n, 2)) : convert(Matrix{eltyb}, Atri*ones(eltya, n, 2)) + b = eltyb == Int ? trunc.(Int,Atri*ones(n, 2)) : convert(Matrix{eltyb}, Atri*ones(eltya, n, 2)) x = Atri \ b γ = n*ε/(1 - n*ε) if eltya != BigFloat - bigA = big(Atri) + bigA = big.(Atri) x̂ = ones(n, 2) for i = 1:size(b, 2) @test norm(x̂[:,i] - x[:,i], Inf)/norm(x̂[:,i], Inf) <= condskeel(bigA, x̂[:,i])*γ/(1 - condskeel(bigA)*γ) diff --git a/test/linalg/tridiag.jl b/test/linalg/tridiag.jl index 4c50fc2d6794a..568b0b46b7d4a 100644 --- a/test/linalg/tridiag.jl +++ b/test/linalg/tridiag.jl @@ -272,14 +272,14 @@ let n = 12 #Size of matrix problem to test debug && println("Rounding to Ints") if elty <: Real - @test round(Int,A) == round(Int,fA) - @test isa(round(Int,A), SymTridiagonal) - @test trunc(Int,A) == trunc(Int,fA) - @test isa(trunc(Int,A), SymTridiagonal) - @test ceil(Int,A) == ceil(Int,fA) - @test isa(ceil(Int,A), SymTridiagonal) - @test floor(Int,A) == floor(Int,fA) - @test isa(floor(Int,A), SymTridiagonal) + @test round.(Int,A) == round.(Int,fA) + @test isa(round.(Int,A), SymTridiagonal) + @test trunc.(Int,A) == trunc.(Int,fA) + @test isa(trunc.(Int,A), SymTridiagonal) + @test ceil.(Int,A) == ceil.(Int,fA) + @test isa(ceil.(Int,A), SymTridiagonal) + @test floor.(Int,A) == floor.(Int,fA) + @test isa(floor.(Int,A), SymTridiagonal) end debug && println("Tridiagonal/SymTridiagonal mixing ops") @@ -390,14 +390,14 @@ let n = 12 #Size of matrix problem to test debug && println("Rounding to Ints") if elty <: Real - @test round(Int,A) == round(Int,fA) - @test isa(round(Int,A), Tridiagonal) - @test trunc(Int,A) == trunc(Int,fA) - @test isa(trunc(Int,A), Tridiagonal) - @test ceil(Int,A) == ceil(Int,fA) - @test isa(ceil(Int,A), Tridiagonal) - @test floor(Int,A) == floor(Int,fA) - @test isa(floor(Int,A), Tridiagonal) + @test round.(Int,A) == round.(Int,fA) + @test isa(round.(Int,A), Tridiagonal) + @test trunc.(Int,A) == trunc.(Int,fA) + @test isa(trunc.(Int,A), Tridiagonal) + @test ceil.(Int,A) == ceil.(Int,fA) + @test isa(ceil.(Int,A), Tridiagonal) + @test floor.(Int,A) == floor.(Int,fA) + @test isa(floor.(Int,A), Tridiagonal) end debug && println("Binary operations") diff --git a/test/math.jl b/test/math.jl index 8e20a57b0a407..42ae8506b71a9 100644 --- a/test/math.jl +++ b/test/math.jl @@ -13,8 +13,8 @@ @test clamp(3.0, 1, 3) == 3.0 @test clamp(4.0, 1, 3) == 3.0 - @test clamp([0, 1, 2, 3, 4], 1.0, 3.0) == [1.0, 1.0, 2.0, 3.0, 3.0] - @test clamp([0 1; 2 3], 1.0, 3.0) == [1.0 1.0; 2.0 3.0] + @test clamp.([0, 1, 2, 3, 4], 1.0, 3.0) == [1.0, 1.0, 2.0, 3.0, 3.0] + @test clamp.([0 1; 2 3], 1.0, 3.0) == [1.0 1.0; 2.0 3.0] begin x = [0.0, 1.0, 2.0, 3.0, 4.0] clamp!(x, 1, 3) diff --git a/test/numbers.jl b/test/numbers.jl index d09f15a276394..75e950d2511f7 100644 --- a/test/numbers.jl +++ b/test/numbers.jl @@ -2026,14 +2026,14 @@ x = 0.0 @test approx_eq(round(pi,3,5), 3.144) # vectorized trunc/round/floor/ceil with digits/base argument a = rand(2, 2, 2) -for f in (trunc, round, floor, ceil) - @test f(a[:, 1, 1], 2) == map(x->f(x, 2), a[:, 1, 1]) - @test f(a[:, :, 1], 2) == map(x->f(x, 2), a[:, :, 1]) - @test f(a, 9, 2) == map(x->f(x, 9, 2), a) - @test f(a[:, 1, 1], 9, 2) == map(x->f(x, 9, 2), a[:, 1, 1]) - @test f(a[:, :, 1], 9, 2) == map(x->f(x, 9, 2), a[:, :, 1]) - @test f(a, 9, 2) == map(x->f(x, 9, 2), a) - end +for f in (round, trunc, floor, ceil) + @test f.(a[:, 1, 1], 2) == map(x->f(x, 2), a[:, 1, 1]) + @test f.(a[:, :, 1], 2) == map(x->f(x, 2), a[:, :, 1]) + @test f.(a, 9, 2) == map(x->f(x, 9, 2), a) + @test f.(a[:, 1, 1], 9, 2) == map(x->f(x, 9, 2), a[:, 1, 1]) + @test f.(a[:, :, 1], 9, 2) == map(x->f(x, 9, 2), a[:, :, 1]) + @test f.(a, 9, 2) == map(x->f(x, 9, 2), a) +end # significant digits (would be nice to have a smart vectorized # version of signif) @test approx_eq(signif(123.456,1), 100.) @@ -2624,8 +2624,8 @@ end for (d,B) in ((4//2+1im,Rational{BigInt}),(3.0+1im,BigFloat),(2+1im,BigInt)) @test typeof(big(d)) == Complex{B} @test big(d) == d - @test typeof(big([d])) == Vector{Complex{B}} - @test big([d]) == [d] + @test typeof(big.([d])) == Vector{Complex{B}} + @test big.([d]) == [d] end # issue #12536 diff --git a/test/offsetarray.jl b/test/offsetarray.jl index 5698aa34cef0f..4890b9de84e4c 100644 --- a/test/offsetarray.jl +++ b/test/offsetarray.jl @@ -340,7 +340,7 @@ seek(io, 0) @test readdlm(io, eltype(A)) == parent(A) amin, amax = extrema(parent(A)) -@test clamp(A, (amax+amin)/2, amax) == clamp(parent(A), (amax+amin)/2, amax) +@test clamp.(A, (amax+amin)/2, amax).parent == clamp.(parent(A), (amax+amin)/2, amax) @test unique(A, 1) == parent(A) @test unique(A, 2) == parent(A) diff --git a/test/random.jl b/test/random.jl index f988ae08f61a6..6d2e9ebcfc52e 100644 --- a/test/random.jl +++ b/test/random.jl @@ -133,10 +133,10 @@ ke = Array{UInt64}(ziggurat_table_size) we = Array{Float64}(ziggurat_table_size) fe = Array{Float64}(ziggurat_table_size) function randmtzig_fill_ziggurat_tables() # Operates on the global arrays - wib = big(wi) - fib = big(fi) - web = big(we) - feb = big(fe) + wib = big.(wi) + fib = big.(fi) + web = big.(we) + feb = big.(fe) # Ziggurat tables for the normal distribution x1 = ziggurat_nor_r wib[256] = x1/nmantissa diff --git a/test/ranges.jl b/test/ranges.jl index e75624be37ffc..4d8161da0a627 100644 --- a/test/ranges.jl +++ b/test/ranges.jl @@ -663,7 +663,7 @@ test_linspace_identity(linspace(1f0, 1f0, 1), linspace(-1f0, -1f0, 1)) for _r in (1:2:100, 1:100, 1f0:2f0:100f0, 1.0:2.0:100.0, linspace(1, 100, 10), linspace(1f0, 100f0, 10)) float_r = float(_r) - big_r = big(_r) + big_r = big.(_r) @test typeof(big_r).name === typeof(_r).name if eltype(_r) <: AbstractFloat @test isa(float_r, typeof(_r)) diff --git a/test/reduce.jl b/test/reduce.jl index 40d6ac8a0149f..bf55acd49cb50 100644 --- a/test/reduce.jl +++ b/test/reduce.jl @@ -186,10 +186,10 @@ prod2(itr) = invoke(prod, Tuple{Any}, itr) @test all(x->x>0, [4]) == true @test all(x->x>0, [-3, 4, 5]) == false -@test reduce(|, fill(trues(5), 24)) == trues(5) -@test reduce(|, fill(falses(5), 24)) == falses(5) -@test reduce(&, fill(trues(5), 24)) == trues(5) -@test reduce(&, fill(falses(5), 24)) == falses(5) +@test reduce((a, b) -> a .| b, fill(trues(5), 24)) == trues(5) +@test reduce((a, b) -> a .| b, fill(falses(5), 24)) == falses(5) +@test reduce((a, b) -> a .& b, fill(trues(5), 24)) == trues(5) +@test reduce((a, b) -> a .& b, fill(falses(5), 24)) == falses(5) @test_throws TypeError any(x->0, [false]) @test_throws TypeError all(x->0, [false]) diff --git a/test/sparse/sparse.jl b/test/sparse/sparse.jl index 88c0b773abee5..17cd8859c2bc8 100644 --- a/test/sparse/sparse.jl +++ b/test/sparse/sparse.jl @@ -35,12 +35,12 @@ do33 = ones(3) sqrfloatmat, colfloatmat = sprand(4, 4, 0.5), sprand(4, 1, 0.5) @test_throws DimensionMismatch (+)(sqrfloatmat, colfloatmat) @test_throws DimensionMismatch (-)(sqrfloatmat, colfloatmat) - @test_throws DimensionMismatch min(sqrfloatmat, colfloatmat) - @test_throws DimensionMismatch max(sqrfloatmat, colfloatmat) + @test_throws DimensionMismatch map(min, sqrfloatmat, colfloatmat) + @test_throws DimensionMismatch map(max, sqrfloatmat, colfloatmat) sqrboolmat, colboolmat = sprand(Bool, 4, 4, 0.5), sprand(Bool, 4, 1, 0.5) - @test_throws DimensionMismatch (&)(sqrboolmat, colboolmat) - @test_throws DimensionMismatch (|)(sqrboolmat, colboolmat) - # @test_throws DimensionMismatch xor(sqrboolmat, colboolmat) # vectorized xor no longer exists + @test_throws DimensionMismatch map(&, sqrboolmat, colboolmat) + @test_throws DimensionMismatch map(|, sqrboolmat, colboolmat) + @test_throws DimensionMismatch map(xor, sqrboolmat, colboolmat) end end @@ -546,8 +546,8 @@ end # Test representatives of [unary functions that map both zeros and nonzeros to nonzeros] @test cos.(Afull) == Array(cos.(A)) # Test representatives of remaining vectorized-nonbroadcast unary functions - @test ceil(Int, Afull) == Array(ceil(Int, A)) - @test floor(Int, Afull) == Array(floor(Int, A)) + @test ceil.(Int, Afull) == Array(ceil.(Int, A)) + @test floor.(Int, Afull) == Array(floor.(Int, A)) # Tests of real, imag, abs, and abs2 for SparseMatrixCSC{Int,X}s previously elsewhere for T in (Int, Float16, Float32, Float64, BigInt, BigFloat) R = rand(T[1:100;], 2, 2) @@ -800,7 +800,7 @@ end @test countnz(A) == 11 @test A[I] == A[X] == c - S = sprand(50, 30, 0.5, x->round(Int,rand(x)*100)) + S = sprand(50, 30, 0.5, x -> round.(Int, rand(x) * 100)) I = sprand(Bool, 50, 30, 0.2) FS = Array(S) FI = Array(I) @@ -828,7 +828,7 @@ end S[FI] = [1:sum(FI);] @test sum(S) == sumS2 + sum(1:sum(FI)) - S = sprand(50, 30, 0.5, x->round(Int,rand(x)*100)) + S = sprand(50, 30, 0.5, x -> round.(Int, rand(x) * 100)) N = length(S) >> 2 I = randperm(N) .* 4 J = randperm(N) @@ -1432,17 +1432,17 @@ end @test A12118 - B12118 == sparse([1,2,3,4,4,5], [1,2,3,3,4,5], [-1,1,3,1,4,7]) @test typeof(A12118 - B12118) == SparseMatrixCSC{Int,Int} - @test max(A12118, B12118) == sparse([1,2,3,4,5], [1,2,3,4,5], [2,2,3,4,5]) - @test typeof(max(A12118, B12118)) == SparseMatrixCSC{Int,Int} + @test max.(A12118, B12118) == sparse([1,2,3,4,5], [1,2,3,4,5], [2,2,3,4,5]) + @test typeof(max.(A12118, B12118)) == SparseMatrixCSC{Int,Int} - @test min(A12118, B12118) == sparse([1,2,4,5], [1,2,3,5], [1,1,-1,-2]) - @test typeof(min(A12118, B12118)) == SparseMatrixCSC{Int,Int} + @test min.(A12118, B12118) == sparse([1,2,4,5], [1,2,3,5], [1,1,-1,-2]) + @test typeof(min.(A12118, B12118)) == SparseMatrixCSC{Int,Int} end @testset "sparse matrix norms" begin Ac = sprandn(10,10,.1) + im* sprandn(10,10,.1) Ar = sprandn(10,10,.1) - Ai = ceil(Int,Ar*100) + Ai = ceil.(Int,Ar*100) @test norm(Ac,1) ≈ norm(Array(Ac),1) @test norm(Ac,Inf) ≈ norm(Array(Ac),Inf) @test vecnorm(Ac) ≈ vecnorm(Array(Ac)) @@ -1452,11 +1452,11 @@ end @test norm(Ai,1) ≈ norm(Array(Ai),1) @test norm(Ai,Inf) ≈ norm(Array(Ai),Inf) @test vecnorm(Ai) ≈ vecnorm(Array(Ai)) - Ai = trunc(Int,Ar*100) + Ai = trunc.(Int, Ar*100) @test norm(Ai,1) ≈ norm(Array(Ai),1) @test norm(Ai,Inf) ≈ norm(Array(Ai),Inf) @test vecnorm(Ai) ≈ vecnorm(Array(Ai)) - Ai = round(Int,Ar*100) + Ai = round.(Int, Ar*100) @test norm(Ai,1) ≈ norm(Array(Ai),1) @test norm(Ai,Inf) ≈ norm(Array(Ai),Inf) @test vecnorm(Ai) ≈ vecnorm(Array(Ai)) @@ -1484,9 +1484,9 @@ end @testset "sparse matrix normestinv" begin Ac = sprandn(20,20,.5) + im* sprandn(20,20,.5) - Aci = ceil(Int64,100*sprand(20,20,.5))+ im*ceil(Int64,sprand(20,20,.5)) + Aci = ceil.(Int64, 100*sprand(20,20,.5)) + im*ceil.(Int64, sprand(20,20,.5)) Ar = sprandn(20,20,.5) - Ari = ceil(Int64,100*Ar) + Ari = ceil.(Int64, 100*Ar) if Base.USE_GPL_LIBS @test_approx_eq_eps Base.SparseArrays.normestinv(Ac,3) norm(inv(Array(Ac)),1) 1e-4 @test_approx_eq_eps Base.SparseArrays.normestinv(Aci,3) norm(inv(Array(Aci)),1) 1e-4 @@ -1506,27 +1506,26 @@ end A13024 = sparse([1,2,3,4,5], [1,2,3,4,5], fill(true,5)) B13024 = sparse([1,2,4,5], [1,2,3,5], fill(true,4)) - @test A13024 & B13024 == sparse([1,2,5], [1,2,5], fill(true,3)) - @test typeof(A13024 & B13024) == SparseMatrixCSC{Bool,Int} + @test broadcast(&, A13024, B13024) == sparse([1,2,5], [1,2,5], fill(true,3)) + @test typeof(broadcast(&, A13024, B13024)) == SparseMatrixCSC{Bool,Int} - @test A13024 | B13024 == sparse([1,2,3,4,4,5], [1,2,3,3,4,5], fill(true,6)) - @test typeof(A13024 | B13024) == SparseMatrixCSC{Bool,Int} + @test broadcast(|, A13024, B13024) == sparse([1,2,3,4,4,5], [1,2,3,3,4,5], fill(true,6)) + @test typeof(broadcast(|, A13024, B13024)) == SparseMatrixCSC{Bool,Int} @test broadcast(⊻, A13024, B13024) == sparse([3,4,4], [3,3,4], fill(true,3), 5, 5) @test typeof(broadcast(⊻, A13024, B13024)) == SparseMatrixCSC{Bool,Int} - @test max(A13024, B13024) == sparse([1,2,3,4,4,5], [1,2,3,3,4,5], fill(true,6)) - @test typeof(max(A13024, B13024)) == SparseMatrixCSC{Bool,Int} + @test broadcast(max, A13024, B13024) == sparse([1,2,3,4,4,5], [1,2,3,3,4,5], fill(true,6)) + @test typeof(broadcast(max, A13024, B13024)) == SparseMatrixCSC{Bool,Int} - @test min(A13024, B13024) == sparse([1,2,5], [1,2,5], fill(true,3)) - @test typeof(min(A13024, B13024)) == SparseMatrixCSC{Bool,Int} + @test broadcast(min, A13024, B13024) == sparse([1,2,5], [1,2,5], fill(true,3)) + @test typeof(broadcast(min, A13024, B13024)) == SparseMatrixCSC{Bool,Int} - @test broadcast(xor, A13024, B13024) == broadcast(xor, Array(A13024), Array(B13024)) - for op in (+, -, &, |) + for op in (+, -) @test op(A13024, B13024) == op(Array(A13024), Array(B13024)) end - for op in (max, min) - @test op(A13024, B13024) == op.(Array(A13024), Array(B13024)) + for op in (max, min, &, |, xor) + @test op.(A13024, B13024) == op.(Array(A13024), Array(B13024)) end end @@ -1605,7 +1604,7 @@ end @testset "issue #16073" begin @inferred sprand(1, 1, 1.0) @inferred sprand(1, 1, 1.0, rand, Float64) - @inferred sprand(1, 1, 1.0, x->round(Int,rand(x)*100)) + @inferred sprand(1, 1, 1.0, x -> round.(Int, rand(x) * 100)) end # Test that concatenations of combinations of sparse matrices with sparse matrices or dense diff --git a/test/sparse/sparsevector.jl b/test/sparse/sparsevector.jl index 6bc4362a005e8..80ef3784bc313 100644 --- a/test/sparse/sparsevector.jl +++ b/test/sparse/sparsevector.jl @@ -588,7 +588,7 @@ let x = spv_x1, x2 = spv_x2 # abs and abs2 @test exact_equal(abs.(x), SparseVector(8, [2, 5, 6], abs.([1.25, -0.75, 3.5]))) - @test exact_equal(abs2(x), SparseVector(8, [2, 5, 6], abs2.([1.25, -0.75, 3.5]))) + @test exact_equal(abs2.(x), SparseVector(8, [2, 5, 6], abs2.([1.25, -0.75, 3.5]))) # plus and minus xa = SparseVector(8, [1,2,5,6,7], [3.25,5.25,-0.75,-2.0,-6.0]) @@ -609,7 +609,7 @@ let x = spv_x1, x2 = spv_x2 # multiplies xm = SparseVector(8, [2, 6], [5.0, -19.25]) - @test exact_equal(x .* x, abs2(x)) + @test exact_equal(x .* x, abs2.(x)) @test exact_equal(x .* x2, xm) @test exact_equal(x2 .* x, xm) @@ -617,11 +617,11 @@ let x = spv_x1, x2 = spv_x2 @test x .* Array(x2) == Array(xm) # max & min - @test exact_equal(max(x, x), x) - @test exact_equal(min(x, x), x) - @test exact_equal(max(x, x2), + @test exact_equal(max.(x, x), x) + @test exact_equal(min.(x, x), x) + @test exact_equal(max.(x, x2), SparseVector(8, Int[1, 2, 6], Float64[3.25, 4.0, 3.5])) - @test exact_equal(min(x, x2), + @test exact_equal(min.(x, x2), SparseVector(8, Int[2, 5, 6, 7], Float64[1.25, -0.75, -5.5, -6.0])) end @@ -910,13 +910,13 @@ end # left-division operations involving triangular matrices and sparse vectors (#14005) let m = 10 sparsefloatvecs = SparseVector[sprand(m, 0.4) for k in 1:3] - sparseintvecs = SparseVector[SparseVector(m, sprvec.nzind, round(Int, sprvec.nzval*10)) for sprvec in sparsefloatvecs] + sparseintvecs = SparseVector[SparseVector(m, sprvec.nzind, round.(Int, sprvec.nzval*10)) for sprvec in sparsefloatvecs] sparsecomplexvecs = SparseVector[SparseVector(m, sprvec.nzind, complex(sprvec.nzval, sprvec.nzval)) for sprvec in sparsefloatvecs] sprmat = sprand(m, m, 0.2) sparsefloatmat = speye(m) + sprmat/(2m) sparsecomplexmat = speye(m) + SparseMatrixCSC(m, m, sprmat.colptr, sprmat.rowval, complex(sprmat.nzval, sprmat.nzval)/(4m)) - sparseintmat = speye(Int, m)*10m + SparseMatrixCSC(m, m, sprmat.colptr, sprmat.rowval, round(Int, sprmat.nzval*10)) + sparseintmat = speye(Int, m)*10m + SparseMatrixCSC(m, m, sprmat.colptr, sprmat.rowval, round.(Int, sprmat.nzval*10)) denseintmat = eye(Int, m)*10m + rand(1:m, m, m) densefloatmat = eye(m) + randn(m, m)/(2m)