-
-
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
Handle Dates-array arithmetic with promote_op #12370
Conversation
Can you describe briefly what the difference is between (hopefully I'm not the only one who's going to have this question) |
@@ -1,6 +1,6 @@ | |||
# This file is a part of Julia. License is MIT: http://julialang.org/license | |||
|
|||
abstract AbstractTime | |||
abstract AbstractTime <: AbstractScalar |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm... I guess this is ok. AbstractTime was kind of a catch all for all the Dates types, but this should be ok. The piece that may not make as much is the parsing Slot types, but those probably need to be reconfigured anyway.
Basically, the idea is that if someone was reluctant to call their type a |
I've actually wanted something like an |
I should add that another approach would be to use traits and introduce |
This question comes up a lot, a few times at JuliaCon for example, people often want to have container types that are conceptually number-like but aren't necessarily compatible with every single thing that we define in base for |
If we want to define |
scalar (in math context) is mainly used to refer to the coefficients in linear algebra (see https://en.wikipedia.org/wiki/Scalar_(mathematics)). In this sense, it is more specialized (instead of more general) than number. What about call it |
In the mean time, for symmetry, we may also consider introducing something like |
Some (brief) prior discussion here: #9270 (comment), which also mentions
Edit: Hm, looking closer I realized that it only defines mixed array/AbstractScalar arithmetic. I suppose that makes sense. Never mind me. |
Thanks for the excellent discussion. I'm tempted to rework this using traits. Methods like abstract IsContainerTrait
immutable AbstractContainer <: IsContainerTrait end
immutable AbstractAtom <: IsContainerTrait end
iscontainertrait(::AbstractArray) = AbstractContainer()
iscontainertrait(::Number) = AbstractAtom()
iscontainertrait(::AbstractTime) = AbstractAtom()
@inline *(A, B) = *((A, iscontainertrait(A)), (B, iscontainertrait(B)))
function *{AT,BT}(Atrait::Tuple{AT,AbstractContainer}, Btrait::Tuple{BT,AbstractAtom})
....
end However, I worry about adding yet another system (even for internal use) this late in 0.4. At this point, I wonder if the best course would be to revert #12115 and have people who need this functionality get it via a package. See #12115 (comment). Thoughts? Especially @quinnj, who hasn't chimed in about that yet. |
It seems like we really want to define |
There goes decidability of subtyping. |
You can do subtyping with negation types and have it be decidable. |
Sure, but is Julia's subtyping decidable if you add negation types? I'm not sure, but I doubt it. |
OK, I think I found a minimalistic way to do this. When I looked more carefully, the Array/Scalar operations were not really the core source of the problem. |
@@ -58,6 +58,9 @@ call(::DotMulFun, x, y) = x .* y | |||
immutable RDivFun <: Func{2} end | |||
call(::RDivFun, x, y) = x / y | |||
|
|||
immutable DotRDivFun <: Func{2} end | |||
call(::RDivFun, x, y) = x ./ y |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
call(::DotRDivFun
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'Doh! Thanks.
This avoids deprecation warnings with packages like Images and DataArrays (hopefully others too). The key point seems to be to avoid specializing on the element type while being generic about the container.
Yeah, this looks much simpler and uncontroversial now. |
Handle Dates-array arithmetic with promote_op
This fixes the ambiguity warnings triggered by #12115. It also introduces a new abstract type,
AbstractScalar
and makes use of it in defining operations.CC @GordStephen, @quinnj.