You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The behaviour for broadcasted Period subtraction is currently
julia>Day(1) - [Day(2), Day(3)]
2-element Array{Base.Dates.Day,1}:1 day
2 days
and
julia>Day(1) .- [Day(2), Day(3)]
2-element Array{Base.Dates.Day,1}:1 day
2 days
whereas presumably the desired output is:
julia> [Day(1) -Day(2), Day(1) -Day(3)]
2-element Array{Base.Dates.Day,1}:-1 day
-2 days
Looking at dates/periods.jl, the first two method definitions here work fine for + but not -:
for op in (:.+, :.-)
op_ =symbol(string(op)[2:end])
@evalbegin
($op){P<:Period}(x::P,Y::StridedArray{P}) = ($op)(Y,x)
($op_){P<:Period}(x::P,Y::StridedArray{P}) = ($op)(Y,x)
($op_){P<:Period}(Y::StridedArray{P},x::P) = ($op)(Y,x)
endend
One option might be to implement unary addition (as identity) and then do
for op in (:.+, :.-)
op_ =symbol(string(op)[2:end])
@evalbegin
($op){P<:Period}(x::P,Y::StridedArray{P}) = ($op_)(($op)(Y,x))
($op_){P<:Period}(x::P,Y::StridedArray{P}) = ($op_)(($op)(Y,x))
($op_){P<:Period}(Y::StridedArray{P},x::P) = ($op)(Y,x)
endend
or, just hardcode the definitions as
(.+){P<:Period}(x::P,Y::StridedArray{P}) = Y .+ x
(+){P<:Period}(x::P,Y::StridedArray{P}) = Y .+ x
(+){P<:Period}(Y::StridedArray{P},x::P) = Y .+ x
(.-){P<:Period}(x::P,Y::StridedArray{P}) = (-Y) .+ x
(-){P<:Period}(x::P,Y::StridedArray{P}) = (-Y) .+ x
(-){P<:Period}(Y::StridedArray{P},x::P) = Y .- x
which would actually be fewer LOC... maybe more readable too.
The text was updated successfully, but these errors were encountered:
I'm working on a PR to get addition/subtraction working with heterogeneous Period arrays right now, so I'm happy to fix this while I'm at it - is there a preference between the two approaches mentioned above?
The behaviour for broadcasted
Period
subtraction is currentlyand
whereas presumably the desired output is:
Looking at dates/periods.jl, the first two method definitions here work fine for
+
but not-
:One option might be to implement unary addition (as identity) and then do
or, just hardcode the definitions as
which would actually be fewer LOC... maybe more readable too.
The text was updated successfully, but these errors were encountered: