Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate functions vectorized via @vectorize_(1|2)arg in favor of compact broadcast syntax #17302

Merged
merged 18 commits into from
Sep 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
3307a5e
Deprecate vectorized functions in base/special/trig.jl in favor of co…
Sacha0 Jul 5, 2016
1eb5a31
Deprecate vectorized functions in base/special/log.jl in favor of com…
Sacha0 Jul 5, 2016
b0f4e94
Deprecate vectorized functions in base/special/gamma.jl in favor of c…
Sacha0 Jul 5, 2016
15234b4
Deprecate vectorized functions in base/special/erf.jl in favor of com…
Sacha0 Jul 5, 2016
7003a9d
Deprecate vectorized functions in base/special/bessel.jl in favor of …
Sacha0 Jul 5, 2016
898c512
Deprecate vectorized functions in base/math.jl in favor of compact br…
Sacha0 Jul 5, 2016
2a5b38d
Deprecate vectorized functions in base/floatfuncs.jl in favor of comp…
Sacha0 Jul 5, 2016
d5a9830
Deprecate vectorized functions in base/fastmath.jl in favor of compac…
Sacha0 Jul 5, 2016
edb235a
Deprecate vectorized functions in base/complex.jl in favor of compact…
Sacha0 Jul 5, 2016
a745a8e
Deprecate vectorized functions in base/dates/accessors.jl in favor of…
Sacha0 Jul 6, 2016
68a746b
Deprecate vectorized functions in base/dates/adjusters.jl in favor of…
Sacha0 Jul 6, 2016
8dc9725
Deprecate vectorized functions in base/dates/conversions.jl in favor …
Sacha0 Jul 6, 2016
253c5de
Deprecate vectorized functions in base/dates/query.jl in favor of com…
Sacha0 Jul 6, 2016
4df8f20
Clean up @vectorize_(1|2)arg deprecations.
Sacha0 Jul 8, 2016
8258554
Deprecate `@vectorize_1arg` and `@vectorize_2arg`.
Sacha0 Aug 13, 2016
bb88931
Update documentation following deprecation of macro-vectorized functi…
Sacha0 Aug 13, 2016
2c5fa85
Revise a few vectorized-math methods, specifically eliminating tempor…
Sacha0 Aug 31, 2016
b0e7481
Remove now-redundant integer-specialized condskeel methods.
Sacha0 Aug 31, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions base/complex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,6 @@ function cis(z::Complex)
v = exp(-imag(z))
Complex(v*cos(real(z)), v*sin(real(z)))
end
@vectorize_1arg Number cis

"""
angle(z)
Expand Down Expand Up @@ -807,16 +806,13 @@ function round{T<:AbstractFloat, MR, MI}(z::Complex{T}, ::RoundingMode{MR}, ::Ro
end
round(z::Complex) = Complex(round(real(z)), round(imag(z)))

@vectorize_1arg Complex round

function round(z::Complex, digits::Integer, base::Integer=10)
Complex(round(real(z), digits, base),
round(imag(z), digits, base))
end

float{T<:AbstractFloat}(z::Complex{T}) = z
float(z::Complex) = Complex(float(real(z)), float(imag(z)))
@vectorize_1arg Complex float

big{T<:AbstractFloat}(z::Complex{T}) = Complex{BigFloat}(z)
big{T<:Integer}(z::Complex{T}) = Complex{BigInt}(z)
Expand Down
15 changes: 0 additions & 15 deletions base/dates/accessors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,6 @@ yearmonth(dt::TimeType) = yearmonth(days(dt))
monthday(dt::TimeType) = monthday(days(dt))
yearmonthday(dt::TimeType) = yearmonthday(days(dt))

@vectorize_1arg TimeType year
@vectorize_1arg TimeType month
@vectorize_1arg TimeType day
@vectorize_1arg TimeType week
@vectorize_1arg DateTime hour
@vectorize_1arg DateTime minute
@vectorize_1arg DateTime second
@vectorize_1arg DateTime millisecond

@vectorize_1arg TimeType dayofmonth
@vectorize_1arg TimeType yearmonth
@vectorize_1arg TimeType monthday
@vectorize_1arg TimeType yearmonthday


# Documentation for exported accessors
for func in (:year, :month)
name = string(func)
Expand Down
12 changes: 0 additions & 12 deletions base/dates/adjusters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ function lastdayofweek end
lastdayofweek(dt::Date) = Date(UTD(value(dt) + (7 - dayofweek(dt))))
lastdayofweek(dt::DateTime) = DateTime(lastdayofweek(Date(dt)))

@vectorize_1arg TimeType firstdayofweek
@vectorize_1arg TimeType lastdayofweek

"""
firstdayofmonth(dt::TimeType) -> TimeType

Expand All @@ -68,9 +65,6 @@ function lastdayofmonth(dt::Date)
end
lastdayofmonth(dt::DateTime) = DateTime(lastdayofmonth(Date(dt)))

@vectorize_1arg TimeType firstdayofmonth
@vectorize_1arg TimeType lastdayofmonth

"""
firstdayofyear(dt::TimeType) -> TimeType

Expand All @@ -94,9 +88,6 @@ function lastdayofyear(dt::Date)
end
lastdayofyear(dt::DateTime) = DateTime(lastdayofyear(Date(dt)))

@vectorize_1arg TimeType firstdayofyear
@vectorize_1arg TimeType lastdayofyear

"""
firstdayofquarter(dt::TimeType) -> TimeType

Expand Down Expand Up @@ -125,9 +116,6 @@ function lastdayofquarter(dt::Date)
end
lastdayofquarter(dt::DateTime) = DateTime(lastdayofquarter(Date(dt)))

@vectorize_1arg TimeType firstdayofquarter
@vectorize_1arg TimeType lastdayofquarter

# Temporal Adjusters
immutable DateFunction
f::Function
Expand Down
10 changes: 0 additions & 10 deletions base/dates/conversions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ See `convert(Int64,dt::Date)` for inverse.
"""
Base.convert{R<:Real}(::Type{Date}, x::R) = Date(UTD(x))

@vectorize_1arg DateTime Date
@vectorize_1arg Date DateTime

### External Conversions
const UNIXEPOCH = value(DateTime(1970)) #Rata Die milliseconds for 1970-01-01T00:00:00

Expand Down Expand Up @@ -132,10 +129,3 @@ Takes the given `DateTime` and returns the number of Julian calendar days since
epoch `-4713-11-24T12:00:00` as a `Float64`.
"""
datetime2julian(dt::DateTime) = (value(dt) - JULIANEPOCH)/86400000.0

@vectorize_1arg Real unix2datetime
@vectorize_1arg DateTime datetime2unix
@vectorize_1arg Real rata2datetime
@vectorize_1arg DateTime datetime2rata
@vectorize_1arg Real julian2datetime
@vectorize_1arg DateTime datetime2julian
17 changes: 0 additions & 17 deletions base/dates/query.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,6 @@ function daysofweekinmonth(dt::TimeType)
(d in THIRTYONE) ? 5 : 4
end

@vectorize_1arg TimeType dayname
@vectorize_1arg TimeType dayabbr
@vectorize_1arg TimeType dayofweek
@vectorize_1arg TimeType dayofweekofmonth
@vectorize_1arg TimeType daysofweekinmonth

### Months
const January,February,March,April,May,June = 1,2,3,4,5,6
const July,August,September,October,November,December = 7,8,9,10,11,12
Expand Down Expand Up @@ -139,10 +133,6 @@ Returns the number of days in the month of `dt`. Value will be 28, 29, 30, or 31
"""
daysinmonth(dt::TimeType) = ((y,m) = yearmonth(dt); return daysinmonth(y,m))

@vectorize_1arg TimeType monthname
@vectorize_1arg TimeType monthabbr
@vectorize_1arg TimeType daysinmonth

### Years
"""
isleapyear(dt::TimeType) -> Bool
Expand All @@ -160,10 +150,6 @@ dayofyear(dt::TimeType) = ((y,m,d) = yearmonthday(dt); return dayofyear(y,m,d))

daysinyear(dt::TimeType) = 365 + isleapyear(dt)

@vectorize_1arg TimeType isleapyear
@vectorize_1arg TimeType dayofyear
@vectorize_1arg TimeType daysinyear

### Quarters
"""
quarterofyear(dt::TimeType) -> Int
Expand All @@ -182,6 +168,3 @@ const QUARTERDAYS = [0,90,181,273]
Returns the day of the current quarter of `dt`. Range of value is 1:92.
"""
dayofquarter(dt::TimeType) = dayofyear(dt) - QUARTERDAYS[quarterofyear(dt)]

@vectorize_1arg TimeType quarterofyear
@vectorize_1arg TimeType dayofquarter
130 changes: 130 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -865,4 +865,134 @@ for f in (:sin, :sinh, :sind, :asin, :asinh, :asind,
@eval @deprecate $f(A::SparseMatrixCSC) $f.(A)
end

# For deprecating vectorized functions in favor of compact broadcast syntax
macro dep_vectorize_1arg(S, f)
S = esc(S)
f = esc(f)
T = esc(:T)
x = esc(:x)
AbsArr = esc(:AbstractArray)
:( @deprecate $f{$T<:$S}($x::$AbsArr{$T}) $f.($x) )
end
macro dep_vectorize_2arg(S, f)
S = esc(S)
f = esc(f)
T1 = esc(:T1)
T2 = esc(:T2)
x = esc(:x)
y = esc(:y)
AbsArr = esc(:AbstractArray)
quote
@deprecate $f{$T1<:$S}($x::$S, $y::$AbsArr{$T1}) $f.($x,$y)
@deprecate $f{$T1<:$S}($x::$AbsArr{$T1}, $y::$S) $f.($x,$y)
@deprecate $f{$T1<:$S,$T2<:$S}($x::$AbsArr{$T1}, $y::$AbsArr{$T2}) $f.($x,$y)
end
end

# Deprecate @vectorize_1arg-vectorized functions from...
for f in (
# base/special/trig.jl
:sinpi, :cospi, :sinc, :cosc,
# base/special/log.jl
:log, :log1p,
# base/special/gamma.jl
:gamma, :lfact, :digamma, :trigamma, :zeta, :eta,
# base/special/erf.jl
:erfcx, :erfi, :dawson,
# base/special/bessel.jl
:airyprime, :airyai, :airyaiprime, :airybi, :airybiprime,
:airy, :airyx, :besselj0, :besselj1, :bessely0, :bessely1,
# base/math.jl
:cbrt, :sinh, :cosh, :tanh, :atan, :asinh, :exp, :erf, :erfc, :exp2,
:expm1, :exp10, :sin, :cos, :tan, :asin, :acos, :acosh, :atanh,
#=:log,=# :log2, :log10, :lgamma, #=:log1p,=# :sqrt,
# base/floatfuncs.jl
:abs, :abs2, :angle, :isnan, :isinf, :isfinite,
# base/fastmath.jl
:acos_fast, :acosh_fast, :angle_fast, :asin_fast, :asinh_fast,
:atan_fast, :atanh_fast, :cbrt_fast, :cis_fast, :cos_fast,
:cosh_fast, :exp10_fast, :exp2_fast, :exp_fast, :expm1_fast,
:lgamma_fast, :log10_fast, :log1p_fast, :log2_fast, :log_fast,
:sin_fast, :sinh_fast, :sqrt_fast, :tan_fast, :tanh_fast,
# base/complex.jl
:cis,
)
@eval @dep_vectorize_1arg Number $f
end
for f in (
:invdigamma, # base/special/gamma.jl
:erfinc, :erfcinv, # base/special/erf.jl
:trunc, :floor, :ceil, :round, # base/floatfuncs.jl
:rad2deg, :deg2rad, :exponent, :significand, # base/math.jl
:unix2datetime, :rata2datetime, :julian2datetime, # base/dates/conversions.jl
:sind, :cosd, :tand, :asind, :acosd, :atand, :asecd, :acscd, :acotd, # base/special/trig.jl
)
@eval @dep_vectorize_1arg Real $f
end
# base/complex.jl
@dep_vectorize_1arg Complex round
@dep_vectorize_1arg Complex float
for f in (
# base/dates/accessors.jl
:year, :month, :day, :week, :dayofmonth, :yearmonth, :monthday, :yearmonthday,
# base/dates/adjusters.jl
:firstdayofweek, :lastdayofweek, :firstdayofmonth,
:lastdayofmonth, :firstdayofyear, :lastdayofyear,
:firstdayofquarter, :lastdayofquarter,
# base/dates/query.jl
:dayname, :dayabbr, :dayofweek, :dayofweekofmonth,
:daysofweekinmonth, :monthname, :monthabbr, :daysinmonth,
:isleapyear, :dayofyear, :daysinyear, :quarterofyear, :dayofquarter,
)
@eval @dep_vectorize_1arg Dates.TimeType $f
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this depends on #16966 — i.e. we need broadcast to recognize TimeType as a "scalar".

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, no, I guess it will work as-is for operations on Array{TimeType} by themselves.

end
for f in (
:hour, :minute, :second, :millisecond, # base/dates/accessors.jl
:Date, :datetime2unix, :datetime2rata, :datetime2julian, # base/dates/conversions.jl
)
@eval @dep_vectorize_1arg Dates.DateTime $f
end
@dep_vectorize_1arg Dates.Date Datetime # base/dates/conversions.jl

# Deprecate @vectorize_2arg-vectorized functions from...
for f in (
# base/special/gamma.jl
:polygamma, :zeta, :beta, :lbeta,
# base/special/bessel.jl
:airy, :airyx, :besseli, :besselix, :besselj, :besseljx,
:besselk, :besselkx, :bessely, :besselyx, :besselh,
:besselhx, :hankelh1, :hankelh2, :hankelh1x, :hankelh2x,
# base/math.jl
:log, :hypot, :atan2,
# base/fastmath.jl
:pow_fast, :atan2_fast, :hypot_fast, :max_fast, :min_fast, :minmax_fast,
)
@eval @dep_vectorize_2arg Number $f
end
for f in (
:max, :min, # base/math.jl
:copysign, :flipsign, # base/floatfuncs.jl
)
@eval @dep_vectorize_2arg Real $f
end

# Deprecate @vectorize_1arg and @vectorize_2arg themselves
macro vectorize_1arg(S,f)
depwarn(string("`@vectorize_1arg` is deprecated in favor of compact broadcast syntax. ",
"Instead of `@vectorize_1arg`'ing function `f` and calling `f(arg)`, call `f.(arg)`."),
:vectorize_1arg)
quote
@dep_vectorize_1arg($(esc(S)),$(esc(f)))
end
end
macro vectorize_2arg(S,f)
depwarn(string("`@vectorize_2arg` is deprecated in favor of compact broadcast syntax. ",
"Instead of `@vectorize_2arg`'ing function `f` and calling `f(arg1, arg2)`, call ",
"`f.(arg1,arg2)`. "), :vectorize_2arg)
quote
@dep_vectorize_2arg($(esc(S)),$(esc(f)))
end
end
export @vectorize_1arg, @vectorize_2arg

# End deprecations scheduled for 0.6
8 changes: 6 additions & 2 deletions base/docs/helpdb/Base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,9 @@ randsubseq!
"""
maximum(A, dims)

Compute the maximum value of an array over the given dimensions.
Compute the maximum value of an array over the given dimensions. See also the
[`max(a,b)`](:func:`max`) function to take the maximum of two or more arguments,
which can be applied elementwise to arrays via `max.(a,b)`.
"""
maximum(A,dims)

Expand Down Expand Up @@ -1531,7 +1533,9 @@ asinh
"""
minimum(A, dims)

Compute the minimum value of an array over the given dimensions.
Compute the minimum value of an array over the given dimensions. See also the
[`min(a,b)`](:func:`min`) function to take the minimum of two or more arguments,
which can be applied elementwise to arrays via `min.(a,b)`.
"""
minimum(A,dims)

Expand Down
2 changes: 0 additions & 2 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1396,8 +1396,6 @@ export
@generated,
@gensym,
@eval,
@vectorize_1arg,
@vectorize_2arg,
@deprecate,

# performance annotations
Expand Down
2 changes: 0 additions & 2 deletions base/fastmath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,6 @@ for f in (:acos, :acosh, :angle, :asin, :asinh, :atan, :atanh, :cbrt,
f_fast = fast_op[f]
@eval begin
$f_fast(x) = $f(x)
@vectorize_1arg Number $f_fast
end
end

Expand All @@ -356,7 +355,6 @@ for f in (:^, :atan2, :hypot, :max, :min, :minmax)
$f_fast(x::Number, y::Number) = $f_fast(promote(x, y)...)
# fall-back implementation that applies after promotion
$f_fast{T<:Number}(x::T, y::T) = $f(x, y)
@vectorize_2arg Number $f_fast
end
end

Expand Down
16 changes: 0 additions & 16 deletions base/floatfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ copysign(x::Float64, y::Float64) = box(Float64,copysign_float(unbox(Float64,x),u
copysign(x::Float32, y::Float32) = box(Float32,copysign_float(unbox(Float32,x),unbox(Float32,y)))
copysign(x::Float32, y::Real) = copysign(x, Float32(y))
copysign(x::Float64, y::Real) = copysign(x, Float64(y))
@vectorize_2arg Real copysign

flipsign(x::Float64, y::Float64) = box(Float64,xor_int(unbox(Float64,x),and_int(unbox(Float64,y),0x8000000000000000)))
flipsign(x::Float32, y::Float32) = box(Float32,xor_int(unbox(Float32,x),and_int(unbox(Float32,y),0x80000000)))
flipsign(x::Float32, y::Real) = flipsign(x, Float32(y))
flipsign(x::Float64, y::Real) = flipsign(x, Float64(y))
@vectorize_2arg Real flipsign

signbit(x::Float64) = signbit(reinterpret(Int64,x))
signbit(x::Float32) = signbit(reinterpret(Int32,x))
Expand Down Expand Up @@ -40,14 +38,6 @@ function hex2num(s::AbstractString)
return box(Float64,unbox(UInt64,parse(UInt64,s,16)))
end

@vectorize_1arg Number abs
@vectorize_1arg Number abs2
@vectorize_1arg Number angle

@vectorize_1arg Number isnan
@vectorize_1arg Number isinf
@vectorize_1arg Number isfinite

"""
round([T,] x, [digits, [base]], [r::RoundingMode])

Expand Down Expand Up @@ -107,7 +97,6 @@ julia> round(pi, 3, 2)
```
"""
round(T::Type, x)

round(x::Real, ::RoundingMode{:ToZero}) = trunc(x)
round(x::Real, ::RoundingMode{:Up}) = ceil(x)
round(x::Real, ::RoundingMode{:Down}) = floor(x)
Expand All @@ -123,11 +112,6 @@ function round(x::AbstractFloat, ::RoundingMode{:NearestTiesUp})
end
round{T<:Integer}(::Type{T}, x::AbstractFloat, r::RoundingMode) = trunc(T,round(x,r))

@vectorize_1arg Real trunc
@vectorize_1arg Real floor
@vectorize_1arg Real ceil
@vectorize_1arg Real round

for f in (:trunc,:floor,:ceil,:round)
@eval begin
function ($f){T,R}(::Type{T}, x::AbstractArray{R,1})
Expand Down
2 changes: 1 addition & 1 deletion base/irrationals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ for T in (Irrational, Rational, Integer, Number)
^(::Irrational{:e}, x::T) = exp(x)
end
for T in (Range, BitArray, StridedArray, AbstractArray)
.^(::Irrational{:e}, x::T) = exp(x)
.^(::Irrational{:e}, x::T) = exp.(x)
end

log(::Irrational{:e}) = 1 # use 1 to correctly promote expressions like log(x)/log(e)
Expand Down
2 changes: 1 addition & 1 deletion base/linalg/arnoldi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ function _svds(X; nsv::Int = 6, ritzvec::Bool = true, tol::Float64 = 0.0, maxite
end
ex = eigs(SVDOperator(X), I; ritzvec = ritzvec, nev = ncv, tol = tol, maxiter = maxiter, v0=padv0)
ind = [1:2:ncv;]
sval = abs(ex[1][ind])
sval = abs.(ex[1][ind])

if ritzvec
# calculating singular vectors
Expand Down
Loading