diff --git a/base/deprecated.jl b/base/deprecated.jl index cf4afffe4d389..5b4c4b1ec691c 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -1021,6 +1021,8 @@ function pmap(f, c...; err_retry=nothing, err_stop=nothing, pids=nothing) end # 15692 +typealias Func{N} Function +deprecate(:Func) for (Fun, func) in [(:IdFun, :identity), (:AbsFun, :abs), (:Abs2Fun, :abs2), diff --git a/base/functors.jl b/base/functors.jl index 9103b005c6bcb..9d26a90478f2b 100644 --- a/base/functors.jl +++ b/base/functors.jl @@ -2,14 +2,6 @@ ###### Function Objects ("Functors") ###### -# Note that function objects are merely used as internal machinery to -# enhance code reuse and improve performance of map/reduce. -# They are not exported. -# When function arguments can be inlined, the use of function objects -# can be removed. - -abstract Func{N} - # More promote_op rules promote_op{T<:Integer}(::typeof(^), ::Type{Bool}, ::Type{T}) = Bool diff --git a/base/reduce.jl b/base/reduce.jl index 45e0c7f66fdb7..7d8278aa73431 100644 --- a/base/reduce.jl +++ b/base/reduce.jl @@ -165,7 +165,7 @@ reduce(op, a::Number) = a ## conditions and results of short-circuiting -immutable Predicate{F} <: Func{1} +immutable Predicate{F} f::F end (pred::Predicate)(x) = pred.f(x)::Bool @@ -241,7 +241,7 @@ sum_pairwise_blocksize(::typeof(abs2)) = 4096 mapreduce_impl(f, op::typeof(+), A::AbstractArray, ifirst::Int, ilast::Int) = mapreduce_pairwise_impl(f, op, A, ifirst, ilast, sum_pairwise_blocksize(f)) -sum(f::Union{Callable,Func{1}}, a) = mapreduce(f, +, a) +sum(f::Callable, a) = mapreduce(f, +, a) sum(a) = mapreduce(identity, +, a) sum(a::AbstractArray{Bool}) = countnz(a) sumabs(a) = mapreduce(abs, +, a) @@ -272,7 +272,7 @@ end ## prod -prod(f::Union{Callable,Func{1}}, a) = mapreduce(f, *, a) +prod(f::Callable, a) = mapreduce(f, *, a) prod(a) = mapreduce(identity, *, a) ## maximum & minimum @@ -317,8 +317,8 @@ function mapreduce_impl(f, op::typeof(scalarmin), A::AbstractArray, first::Int, v end -maximum(f::Union{Callable,Func{1}}, a) = mapreduce(f, scalarmax, a) -minimum(f::Union{Callable,Func{1}}, a) = mapreduce(f, scalarmin, a) +maximum(f::Callable, a) = mapreduce(f, scalarmax, a) +minimum(f::Callable, a) = mapreduce(f, scalarmin, a) maximum(a) = mapreduce(identity, scalarmax, a) minimum(a) = mapreduce(identity, scalarmin, a) diff --git a/base/reducedim.jl b/base/reducedim.jl index 05c3c6068ab87..fa2a1e6a1b832 100644 --- a/base/reducedim.jl +++ b/base/reducedim.jl @@ -245,11 +245,11 @@ for (fname, op) in [(:sum, :+), (:prod, :*), fname! = symbol(fname, '!') @eval begin - $(fname!)(f::Union{Function,Func{1}}, r::AbstractArray, A::AbstractArray; init::Bool=true) = + $(fname!)(f::Function, r::AbstractArray, A::AbstractArray; init::Bool=true) = mapreducedim!(f, $(op), initarray!(r, $(op), init), A) $(fname!)(r::AbstractArray, A::AbstractArray; init::Bool=true) = $(fname!)(identity, r, A; init=init) - $(fname)(f::Union{Function,Func{1}}, A::AbstractArray, region) = + $(fname)(f::Function, A::AbstractArray, region) = mapreducedim(f, $(op), A, region) $(fname)(A::AbstractArray, region) = $(fname)(identity, A, region) end diff --git a/base/sparse.jl b/base/sparse.jl index b148fb394707f..4a16213bda971 100644 --- a/base/sparse.jl +++ b/base/sparse.jl @@ -2,7 +2,6 @@ module SparseArrays -using Base: Func using Base: ReshapedArray using Base.Sort: Forward using Base.LinAlg: AbstractTriangular, PosDefException diff --git a/base/sparse/sparsematrix.jl b/base/sparse/sparsematrix.jl index 73b46b65a87e8..e30634f806956 100644 --- a/base/sparse/sparsematrix.jl +++ b/base/sparse/sparsematrix.jl @@ -320,7 +320,7 @@ sparse_IJ_sorted!(I,J,V::AbstractVector{Bool},m,n) = sparse_IJ_sorted!(I,J,V,m,n function sparse_IJ_sorted!{Ti<:Integer}(I::AbstractVector{Ti}, J::AbstractVector{Ti}, V::AbstractVector, - m::Integer, n::Integer, combine::Union{Function,Func}) + m::Integer, n::Integer, combine::Function) m = m < 0 ? 0 : m n = n < 0 ? 0 : n @@ -596,7 +596,7 @@ sparse(I,J,V::AbstractVector,m,n) = sparse(I, J, V, Int(m), Int(n), +) sparse(I,J,V::AbstractVector{Bool},m,n) = sparse(I, J, V, Int(m), Int(n), |) -sparse(I,J,v::Number,m,n,combine::Union{Function,Func}) = sparse(I, J, fill(v,length(I)), Int(m), Int(n), combine) +sparse(I,J,v::Number,m,n,combine::Function) = sparse(I, J, fill(v,length(I)), Int(m), Int(n), combine) function sparse(T::SymTridiagonal) m = length(T.dv) diff --git a/base/sparse/sparsevector.jl b/base/sparse/sparsevector.jl index ac4bff5d3d460..a1efa36bee8ad 100644 --- a/base/sparse/sparsevector.jl +++ b/base/sparse/sparsevector.jl @@ -2,10 +2,7 @@ ### Common definitions -import Base: Func, scalarmax, scalarmin, sort - -typealias UnaryOp Union{Function, Func{1}} -typealias BinaryOp Union{Function, Func{2}} +import Base: scalarmax, scalarmin, sort ### The SparseVector @@ -58,7 +55,7 @@ function _sparsevector!{Ti<:Integer}(I::Vector{Ti}, V::Vector, len::Integer) SparseVector(len, I, V) end -function _sparsevector!{Tv,Ti<:Integer}(I::Vector{Ti}, V::Vector{Tv}, len::Integer, combine::BinaryOp) +function _sparsevector!{Tv,Ti<:Integer}(I::Vector{Ti}, V::Vector{Tv}, len::Integer, combine::Function) if !isempty(I) p = sortperm(I) permute!(I, p) @@ -99,7 +96,7 @@ Duplicates are combined using the `combine` function, which defaults to `+` if no `combine` argument is provided, unless the elements of `V` are Booleans in which case `combine` defaults to `|`. """ -function sparsevec{Tv,Ti<:Integer}(I::AbstractVector{Ti}, V::AbstractVector{Tv}, combine::BinaryOp) +function sparsevec{Tv,Ti<:Integer}(I::AbstractVector{Ti}, V::AbstractVector{Tv}, combine::Function) length(I) == length(V) || throw(ArgumentError("index and value vectors must be the same length")) len = 0 @@ -112,7 +109,7 @@ function sparsevec{Tv,Ti<:Integer}(I::AbstractVector{Ti}, V::AbstractVector{Tv}, _sparsevector!(collect(Ti, I), collect(Tv, V), len, combine) end -function sparsevec{Tv,Ti<:Integer}(I::AbstractVector{Ti}, V::AbstractVector{Tv}, len::Integer, combine::BinaryOp) +function sparsevec{Tv,Ti<:Integer}(I::AbstractVector{Ti}, V::AbstractVector{Tv}, len::Integer, combine::Function) length(I) == length(V) || throw(ArgumentError("index and value vectors must be the same length")) maxi = convert(Ti, len) @@ -136,10 +133,10 @@ sparsevec{Ti<:Integer}(I::AbstractVector{Ti}, V::Union{Bool, AbstractVector{Bool len::Integer) = sparsevec(I, V, len, |) -sparsevec{Ti<:Integer}(I::AbstractVector{Ti}, v::Number, combine::BinaryOp) = +sparsevec{Ti<:Integer}(I::AbstractVector{Ti}, v::Number, combine::Function) = sparsevec(I, fill(v, length(I)), combine) -sparsevec{Ti<:Integer}(I::AbstractVector{Ti}, v::Number, len::Integer, combine::BinaryOp) = +sparsevec{Ti<:Integer}(I::AbstractVector{Ti}, v::Number, len::Integer, combine::Function) = sparsevec(I, fill(v, length(I)), len, combine) @@ -857,7 +854,7 @@ end # 1: f(nz, nz) -> z/nz, f(z, nz) -> nz, f(nz, z) -> nz # 2: f(nz, nz) -> z/nz, f(z, nz) -> z/nz, f(nz, z) -> z/nz -function _binarymap{Tx,Ty}(f::BinaryOp, +function _binarymap{Tx,Ty}(f::Function, x::AbstractSparseVector{Tx}, y::AbstractSparseVector{Ty}, mode::Int) @@ -895,7 +892,7 @@ function _binarymap{Tx,Ty}(f::BinaryOp, return SparseVector(n, rind, rval) end -function _binarymap_mode_0!(f::BinaryOp, mx::Int, my::Int, +function _binarymap_mode_0!(f::Function, mx::Int, my::Int, xnzind, xnzval, ynzind, ynzval, rind, rval) # f(nz, nz) -> nz, f(z, nz) -> z, f(nz, z) -> z ir = 0; ix = 1; iy = 1 @@ -915,7 +912,7 @@ function _binarymap_mode_0!(f::BinaryOp, mx::Int, my::Int, return ir end -function _binarymap_mode_1!{Tx,Ty}(f::BinaryOp, mx::Int, my::Int, +function _binarymap_mode_1!{Tx,Ty}(f::Function, mx::Int, my::Int, xnzind, xnzval::AbstractVector{Tx}, ynzind, ynzval::AbstractVector{Ty}, rind, rval) @@ -953,7 +950,7 @@ function _binarymap_mode_1!{Tx,Ty}(f::BinaryOp, mx::Int, my::Int, return ir end -function _binarymap_mode_2!{Tx,Ty}(f::BinaryOp, mx::Int, my::Int, +function _binarymap_mode_2!{Tx,Ty}(f::Function, mx::Int, my::Int, xnzind, xnzval::AbstractVector{Tx}, ynzind, ynzval::AbstractVector{Ty}, rind, rval) @@ -999,7 +996,7 @@ function _binarymap_mode_2!{Tx,Ty}(f::BinaryOp, mx::Int, my::Int, return ir end -function _binarymap{Tx,Ty}(f::BinaryOp, +function _binarymap{Tx,Ty}(f::Function, x::AbstractVector{Tx}, y::AbstractSparseVector{Ty}, mode::Int) @@ -1042,7 +1039,7 @@ function _binarymap{Tx,Ty}(f::BinaryOp, return dst end -function _binarymap{Tx,Ty}(f::BinaryOp, +function _binarymap{Tx,Ty}(f::Function, x::AbstractSparseVector{Tx}, y::AbstractVector{Ty}, mode::Int) @@ -1247,7 +1244,7 @@ function dot{Tx<:Number,Ty<:Number}(x::AbstractSparseVector{Tx}, y::AbstractVect return s end -function _spdot(f::BinaryOp, +function _spdot(f::Function, xj::Int, xj_last::Int, xnzind, xnzval, yj::Int, yj_last::Int, ynzind, ynzval) # dot product between ranges of non-zeros, @@ -1437,7 +1434,7 @@ Ac_mul_B!{Tx,Ty}(y::StridedVector{Ty}, A::SparseMatrixCSC, x::AbstractSparseVect Ac_mul_B!{Tx,Ty}(α::Number, A::SparseMatrixCSC, x::AbstractSparseVector{Tx}, β::Number, y::StridedVector{Ty}) = _At_or_Ac_mul_B!(dot, α, A, x, β, y) -function _At_or_Ac_mul_B!{Tx,Ty}(tfun::BinaryOp, +function _At_or_Ac_mul_B!{Tx,Ty}(tfun::Function, α::Number, A::SparseMatrixCSC, x::AbstractSparseVector{Tx}, β::Number, y::StridedVector{Ty}) m, n = size(A) @@ -1479,7 +1476,7 @@ At_mul_B(A::SparseMatrixCSC, x::AbstractSparseVector) = Ac_mul_B(A::SparseMatrixCSC, x::AbstractSparseVector) = _At_or_Ac_mul_B(dot, A, x) -function _At_or_Ac_mul_B{TvA,TiA,TvX,TiX}(tfun::BinaryOp, A::SparseMatrixCSC{TvA,TiA}, x::AbstractSparseVector{TvX,TiX}) +function _At_or_Ac_mul_B{TvA,TiA,TvX,TiX}(tfun::Function, A::SparseMatrixCSC{TvA,TiA}, x::AbstractSparseVector{TvX,TiX}) m, n = size(A) length(x) == m || throw(DimensionMismatch()) Tv = promote_type(TvA, TvX)