-
Notifications
You must be signed in to change notification settings - Fork 3
Add realdot
#2
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 realdot
#2
Conversation
* Fix indentation * Test \ on complex inputs * Test ^ on complex inputs * Test identity on complex inputs * Test muladd on complex inputs * Test binary functions on complex inputs * Test functions on complex inputs * Release type constraint on exp * Add _realconjtimes * Use _realconjtimes in abs/abs2 rules * Add complex rule for hypot * Add generic rule for adjoint * Add generic rule for real * Add generic rule for imag * Add complex rule for hypot * Add rules/tests for Complex * Test frule for identity * Add missing angle test * Make inline just in case * Unify abs rules * Introduce _imagconjtimes utility function * Unify angle rules * Unify sign rules * Multiply by correct variable * Fix argument order * Bump ChainRulesTestUtils version number * Restrict to Complex * Use muladd * Update src/rulesets/Base/fastmath_able.jl Co-authored-by: willtebbutt <wt0881@my.bristol.ac.uk> Co-authored-by: willtebbutt <wt0881@my.bristol.ac.uk>
* rename DoesNotExist * rename Composite * bump version and compat * rename Zero * remove typos * reexport deprecated types manually
Co-authored-by: Seth Axen <seth.axen@gmail.com>
Codecov Report
@@ Coverage Diff @@
## main #2 +/- ##
===========================================
+ Coverage 0 100.00% +100.00%
===========================================
Files 0 1 +1
Lines 0 5 +5
===========================================
+ Hits 0 5 +5
Continue to review full report at Codecov.
|
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.
LGTM, just minor suggestions on the readme
Co-authored-by: Seth Axen <seth.axen@gmail.com>
Thanks, I'll merge once tests pass! One remaining question to consider though: @sethaxen and @oxinabox, do you think I should move it JuliaMath or JuliaDiff before registering it? This wouldn't affect maintenance or have any immediate impact on the package but would mainly make it look a bit more official. I guess this could be helpful if we want to add it as a dependency to ChainRules and SpecialFunctions. |
Yes, you should move it. |
Can you add a test for a number for which only |
Co-authored-by: Seth Axen <seth.axen@gmail.com>
Do you mean the package should be moved to JuliaLinearAlgebra? Since so far it mainly deals with |
@sethaxen I added a test with quaternions. |
test/runtests.jl
Outdated
a, b = reim(w) | ||
return q * Quaternion(a, b, zero(a), zero(a)) | ||
end | ||
Base.:*(q::Union{Real,Complex,CustomComplex}, w::Quaternion) = w * q |
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.
Quaternions aren't multiplicatively commutative, so this does not work:
julia> using Quaternions
julia> q = quatrand();
julia> p = Quaternion(randn(2)..., 0, 0);
julia> p*q - q*p # doesn't work
Quaternion{Float64}(0.0, 0.0, 2.3421250648992906, 1.0118653825634418, false)
julia> p*q - (q'*p')' # this is fine
Quaternion{Float64}(0.0, 0.0, 0.0, 0.0, false)
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.
Haha yeah I guess it's clear that I've never worked with quaternions 😄 In fact for the tests it does not matter and the result could be anything since Quaternion
will use the fallback definition realdot(x, y) = real(dot(x, y))
and hence tests will always pass, regardless of whether dot
is implemented correctly or not, as long as some value can be computed. Of course, I'll fix it so that it seems that I know what I am doing here even though I just copy stuff from Quaternions 😄
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 be fixed now.
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.
Yeah, quaternions are super useful as a sanity check for chain rules of numers/numerical arrays, since they behave like matrices. I have probably thought way too much about them.
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.
LGTM!
This PR adds
realdot
from JuliaDiff/ChainRulesCore.jl#474, which was defined initially (and still is defined) as_realconjtimes
in ChainRules.jl.The commits are a bit messy since I wanted to preserve the git history to give credit to the original authors (mainly @sethaxen) more explicitly. I only added
realdot
(for now) since it seems more generally useful thanimagdot
and its implementation did not use any ChainRules-specific types (JuliaDiff/ChainRulesCore.jl#474 (comment)).cc: @sethaxen