-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Period addition is not associative #9214
Comments
Also not commutative:
|
Ok, I have the commutative fix. Yeah, we should probably compress the periods as they're added to |
Make Period + CompoundPeriod communatative. Partially fixes #9214
Also not that |
Seems like this should do it in the constructor: type CompoundPeriod
periods::Array{Period,1}
function CompoundPeriod(p::Vector{Period})
n = length(p)
n < 2 && return new(p)
sort!(p, rev=true, lt=periodisless)
# canonicalize p by merging equal period types
i = j = 1
while j <= n
k = j+1
while k <= n
if typeof(p[j]) == typeof(p[k])
p[j] += p[k]
k += 1
else
break
end
end
p[i] = p[j]
i += 1
j = k
end
return new(resize!(p, i-1))
end
end |
Correction: should also canonicalize to eliminate zeros. |
I'll submit a PR shortly |
Shouldn't |
Also notice that |
Seems like the problem could be fixed by making the
CompoundPeriod
constructor canonicalize its contents by combining periods of the same type.The text was updated successfully, but these errors were encountered: