-
Notifications
You must be signed in to change notification settings - Fork 89
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
Add missing complex tests and rules #216
Conversation
The one failure on Julia 1.4.2 is odd. |
Hmm yeah, that is very strange... checking for approximate equality is fine though imho. |
src/rulesets/Base/utils.jl
Outdated
@inline _realconjtimes(x, y) = real(conj(x) * y) | ||
@inline _realconjtimes(x::Complex, y::Complex) = real(x) * real(y) + imag(x) * imag(y) | ||
@inline _realconjtimes(x::Real, y::Complex) = x * real(y) | ||
@inline _realconjtimes(x::Complex, y::Real) = real(x) * y | ||
@inline _realconjtimes(x::Real, y::Real) = x * y | ||
|
||
# imag(conj(x) * y) avoiding computing the real part if possible | ||
@inline _imagconjtimes(x, y) = imag(conj(x) * y) | ||
@inline _imagconjtimes(x::Complex, y::Complex) = -imag(x) * real(y) + real(x) * imag(y) | ||
@inline _imagconjtimes(x::Real, y::Complex) = x * imag(y) | ||
@inline _imagconjtimes(x::Complex, y::Real) = -imag(x) * y | ||
@inline _imagconjtimes(x::Real, y::Real) = Zero() |
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.
should these all be AbstractComplex
?
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.
I don't think there is an AbstractComplex
in base.
Okay this should be ready for review. @MasonProtter I ended up simplifying the rules for |
Looks good to me! |
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.
Minor style thing. Otherwise LGTM
Co-authored-by: willtebbutt <[email protected]>
This PR fixes #215 by adding missing complex tests and where necessary generalizing rules and adding missing rules. New rules are
adjoint(::Number)
real(::Number)
imag(::Complex)
Complex(::Number)
Complex(::Number, ::Number)
hypot(::Complex)
hypot(::T, ::T) where T<:Union{Real,Complex}
exp(::Number)
It also simplifies the rules for
abs
,angle
, andsign
with shared utility functions.I believe as of this PR, all scalar functions in Base for which we have complex rules should be tested on complex inputs.