diff --git a/base/abstractarray.jl b/base/abstractarray.jl index 8a2b5dff32c2f..f9ea9a6e1fb14 100644 --- a/base/abstractarray.jl +++ b/base/abstractarray.jl @@ -155,7 +155,7 @@ similar{T}(a::AbstractArray{T}, dims::DimsInteger) = similar(a, T, dims) similar{T}(a::AbstractArray{T}, dims::Integer...) = similar(a, T, dims) similar( a::AbstractArray, T::Type, dims::Integer...) = similar(a, T, dims) # similar creates an Array by default -similar( a::AbstractArray, T::Type, dims::DimsInteger) = Array(T, dims...) +similar( a::AbstractArray, T::Type, dims::DimsInteger) = similar(a, T, convert(Dims, dims)) similar( a::AbstractArray, T::Type, dims::Dims) = Array(T, dims) ## from general iterable to any array diff --git a/base/array.jl b/base/array.jl index 6c1918db755b6..59c123dbb17bc 100644 --- a/base/array.jl +++ b/base/array.jl @@ -117,7 +117,7 @@ end ## Constructors ## -similar(a::Array, T, dims::Dims) = Array(T, dims) +similar(a::Array, T::Type, dims::Dims) = Array(T, dims) similar{T}(a::Array{T,1}) = Array(T, size(a,1)) similar{T}(a::Array{T,2}) = Array(T, size(a,1), size(a,2)) similar{T}(a::Array{T,1}, dims::Dims) = Array(T, dims) diff --git a/base/bool.jl b/base/bool.jl index 67c3831f2d4e6..cef413455db46 100644 --- a/base/bool.jl +++ b/base/bool.jl @@ -61,4 +61,5 @@ rem(x::Bool, y::Bool) = y ? false : throw(DivideError()) mod(x::Bool, y::Bool) = rem(x,y) promote_op(op, ::Type{Bool}, ::Type{Bool}) = typeof(op(true, true)) +promote_op(::typeof(^), ::Type{Bool}, ::Type{Bool}) = Bool promote_op{T<:Integer}(::typeof(^), ::Type{Bool}, ::Type{T}) = Bool diff --git a/base/irrationals.jl b/base/irrationals.jl index 0fb91aee4f138..e7a65dcbf4b34 100644 --- a/base/irrationals.jl +++ b/base/irrationals.jl @@ -127,7 +127,7 @@ for T in (Range, BitArray, StridedArray, AbstractArray) end log(::Irrational{:e}) = 1 # use 1 to correctly promote expressions like log(x)/log(e) -log(::Irrational{:e}, x) = log(x) +log(::Irrational{:e}, x::Number) = log(x) # align along = for nice Array printing function alignment(io::IO, x::Irrational) diff --git a/base/linalg/hessenberg.jl b/base/linalg/hessenberg.jl index fb3d13f6d9805..b45a1e67efdc1 100644 --- a/base/linalg/hessenberg.jl +++ b/base/linalg/hessenberg.jl @@ -33,7 +33,8 @@ immutable HessenbergQ{T,S<:AbstractMatrix} <: AbstractMatrix{T} end HessenbergQ{T}(factors::AbstractMatrix{T}, τ::Vector{T}) = HessenbergQ{T,typeof(factors)}(factors, τ) HessenbergQ(A::Hessenberg) = HessenbergQ(A.factors, A.τ) -size(A::HessenbergQ, args...) = size(A.factors, args...) +size(A::HessenbergQ, d) = size(A.factors, d) +size(A::HessenbergQ) = size(A.factors) function getindex(A::Hessenberg, d::Symbol) d == :Q && return HessenbergQ(A) diff --git a/base/linalg/symmetric.jl b/base/linalg/symmetric.jl index d4ebe7344a2ca..9308eb4d654f5 100644 --- a/base/linalg/symmetric.jl +++ b/base/linalg/symmetric.jl @@ -22,7 +22,8 @@ end typealias HermOrSym{T,S} Union{Hermitian{T,S}, Symmetric{T,S}} typealias RealHermSymComplexHerm{T<:Real,S} Union{Hermitian{T,S}, Symmetric{T,S}, Hermitian{Complex{T},S}} -size(A::HermOrSym, args...) = size(A.data, args...) +size(A::HermOrSym, d) = size(A.data, d) +size(A::HermOrSym) = size(A.data) @inline function getindex(A::Symmetric, i::Integer, j::Integer) @boundscheck checkbounds(A, i, j) @inbounds r = (A.uplo == 'U') == (i < j) ? A.data[i, j] : A.data[j, i] diff --git a/base/linalg/triangular.jl b/base/linalg/triangular.jl index 6a58d538c6257..7b52bd91e93ca 100644 --- a/base/linalg/triangular.jl +++ b/base/linalg/triangular.jl @@ -17,7 +17,8 @@ for t in (:LowerTriangular, :UnitLowerTriangular, :UpperTriangular, return $t{eltype(A), typeof(A)}(A) end - size(A::$t, args...) = size(A.data, args...) + size(A::$t, d) = size(A.data, d) + size(A::$t) = size(A.data) convert{T,S}(::Type{$t{T}}, A::$t{T,S}) = A convert{Tnew,Told,S}(::Type{$t{Tnew}}, A::$t{Told,S}) = (Anew = convert(AbstractMatrix{Tnew}, A.data); $t(Anew)) diff --git a/base/multidimensional.jl b/base/multidimensional.jl index f050701da89ff..6bbc164c3838e 100644 --- a/base/multidimensional.jl +++ b/base/multidimensional.jl @@ -196,6 +196,11 @@ using .IteratorsMD # Bounds-checking specialization # Specializing for a fixed number of arguments provides a ~25% # improvement over the general definitions in abstractarray.jl + +# This is annoying, but we must first define logical indexing to avoid ambiguities +_internal_checkbounds(A::AbstractVector, I::AbstractVector{Bool}) = length(A) == length(I) || throw_boundserror(A, I) +_internal_checkbounds(A::AbstractVector, I::AbstractArray{Bool}) = size(A) == size(I) || throw_boundserror(A, I) + for N = 1:5 args = [:($(Symbol(:I, d))) for d = 1:N] targs = [:($(Symbol(:I, d))::Union{Colon,Number,AbstractArray}) for d = 1:N] # prevent co-opting the CartesianIndex version @@ -215,9 +220,6 @@ for N = 1:5 end end end -# This is annoying, but we must also define logical indexing to avoid ambiguities -_internal_checkbounds(A::AbstractVector, I::AbstractArray{Bool}) = size(A) == size(I) || throw_boundserror(A, I) -_internal_checkbounds(A::AbstractVector, I::AbstractVector{Bool}) = length(A) == length(I) || throw_boundserror(A, I) # Bounds-checking with CartesianIndex @inline function checkbounds(::Type{Bool}, ::Tuple{}, I1::CartesianIndex) diff --git a/base/rational.jl b/base/rational.jl index e900d8e696c68..86bedaac2f404 100644 --- a/base/rational.jl +++ b/base/rational.jl @@ -340,6 +340,9 @@ function round{T}(::Type{T}, x::Rational{Bool}) convert(T, x) end +round{T}(::Type{T}, x::Rational{Bool}, ::RoundingMode{:Nearest}) = round(T, x) +round{T}(::Type{T}, x::Rational{Bool}, ::RoundingMode{:NearestTiesAway}) = round(T, x) +round{T}(::Type{T}, x::Rational{Bool}, ::RoundingMode{:NearestTiesUp}) = round(T, x) round{T}(::Type{T}, x::Rational{Bool}, ::RoundingMode) = round(T, x) trunc{T}(x::Rational{T}) = Rational(trunc(T,x)) diff --git a/base/reshapedarray.jl b/base/reshapedarray.jl index d085cede6383b..03e5a71ac720c 100644 --- a/base/reshapedarray.jl +++ b/base/reshapedarray.jl @@ -72,7 +72,7 @@ size_strides(out::Tuple) = out size(A::ReshapedArray) = A.dims size(A::ReshapedArray, d) = d <= ndims(A) ? A.dims[d] : 1 similar(A::ReshapedArray, eltype::Type) = similar(parent(A), eltype, size(A)) -similar(A::ReshapedArray, eltype::Type, dims...) = similar(parent(A), eltype, dims...) +similar(A::ReshapedArray, eltype::Type, dims::Dims...) = similar(parent(A), eltype, dims...) linearindexing{R<:ReshapedArrayLF}(::Type{R}) = LinearFast() parent(A::ReshapedArray) = A.parent parentindexes(A::ReshapedArray) = map(s->1:s, size(parent(A))) diff --git a/base/sharedarray.jl b/base/sharedarray.jl index 3e0e5ad50e941..3d64870f26208 100644 --- a/base/sharedarray.jl +++ b/base/sharedarray.jl @@ -430,8 +430,8 @@ function shmem_randn(dims; kwargs...) end shmem_randn(I::Int...; kwargs...) = shmem_randn(I; kwargs...) -similar(S::SharedArray, T, dims::Dims) = similar(S.s, T, dims) -similar(S::SharedArray, T) = similar(S.s, T, size(S)) +similar(S::SharedArray, T::Type, dims::Dims) = similar(S.s, T, dims) +similar(S::SharedArray, T::Type) = similar(S.s, T, size(S)) similar(S::SharedArray, dims::Dims) = similar(S.s, eltype(S), dims) similar(S::SharedArray) = similar(S.s, eltype(S), size(S)) diff --git a/base/sparse/sparsematrix.jl b/base/sparse/sparsematrix.jl index 61fcfbb1c1545..a2239c49880b2 100644 --- a/base/sparse/sparsematrix.jl +++ b/base/sparse/sparsematrix.jl @@ -241,7 +241,7 @@ end similar(S::SparseMatrixCSC, Tv::Type=eltype(S)) = SparseMatrixCSC(S.m, S.n, copy(S.colptr), copy(S.rowval), Array(Tv, length(S.nzval))) similar{Tv,Ti,TvNew,TiNew}(S::SparseMatrixCSC{Tv,Ti}, ::Type{TvNew}, ::Type{TiNew}) = SparseMatrixCSC(S.m, S.n, convert(Array{TiNew},S.colptr), convert(Array{TiNew}, S.rowval), Array(TvNew, length(S.nzval))) -similar{Tv, N}(S::SparseMatrixCSC, ::Type{Tv}, d::NTuple{N, Integer}) = spzeros(Tv, d...) +similar{Tv}(S::SparseMatrixCSC, ::Type{Tv}, d::Dims...) = spzeros(Tv, d...) function convert{Tv,Ti,TvS,TiS}(::Type{SparseMatrixCSC{Tv,Ti}}, S::SparseMatrixCSC{TvS,TiS}) if Tv == TvS && Ti == TiS diff --git a/base/subarray.jl b/base/subarray.jl index 95f1f7c990422..e0a5ee2e301aa 100644 --- a/base/subarray.jl +++ b/base/subarray.jl @@ -67,7 +67,7 @@ viewindexing(I::Tuple{AbstractArray, Vararg{Any}}) = LinearSlow() size(V::SubArray) = V.dims length(V::SubArray) = prod(V.dims) -similar(V::SubArray, T, dims::Dims) = similar(V.parent, T, dims) +similar(V::SubArray, T::Type, dims::Dims) = similar(V.parent, T, dims) parent(V::SubArray) = V.parent parentindexes(V::SubArray) = V.indexes