Skip to content

Commit

Permalink
Deprecate Func
Browse files Browse the repository at this point in the history
  • Loading branch information
martinholters committed Apr 21, 2016
1 parent 7943016 commit 1207e64
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 36 deletions.
2 changes: 2 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
8 changes: 0 additions & 8 deletions base/functors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 5 additions & 5 deletions base/reduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions base/reducedim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion base/sparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

module SparseArrays

using Base: Func
using Base: ReshapedArray
using Base.Sort: Forward
using Base.LinAlg: AbstractTriangular, PosDefException
Expand Down
4 changes: 2 additions & 2 deletions base/sparse/sparsematrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
33 changes: 15 additions & 18 deletions base/sparse/sparsevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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)


Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 1207e64

Please sign in to comment.