Skip to content

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

Merged
merged 19 commits into from
Oct 18, 2021
Merged

Add realdot #2

merged 19 commits into from
Oct 18, 2021

Conversation

devmotion
Copy link
Member

@devmotion devmotion commented Oct 16, 2021

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 than imagdot and its implementation did not use any ChainRules-specific types (JuliaDiff/ChainRulesCore.jl#474 (comment)).

cc: @sethaxen

sethaxen and others added 14 commits June 30, 2020 08:00
* 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
Copy link

codecov bot commented Oct 16, 2021

Codecov Report

Merging #2 (c6d1099) into main (ebc598d) will increase coverage by 100.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##           main        #2        +/-   ##
===========================================
+ Coverage      0   100.00%   +100.00%     
===========================================
  Files         0         1         +1     
  Lines         0         5         +5     
===========================================
+ Hits          0         5         +5     
Impacted Files Coverage Δ
src/RealDot.jl 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ebc598d...c6d1099. Read the comment docs.

Copy link
Contributor

@sethaxen sethaxen left a 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

devmotion and others added 2 commits October 18, 2021 13:16
Co-authored-by: Seth Axen <seth.axen@gmail.com>
@devmotion
Copy link
Member Author

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.

@oxinabox
Copy link

Yes, you should move it.
It's not really a AD thing as we discovered.
So it must be a linear algebra thing.
So I guess not JuliaDiff

@sethaxen
Copy link
Contributor

Can you add a test for a number for which only *,conj, adjoint, and real are defined? as a proxy for hypercomplex numbers like Quaternions.Quaternion.

Co-authored-by: Seth Axen <seth.axen@gmail.com>
@devmotion
Copy link
Member Author

So it must be a linear algebra thing.

Do you mean the package should be moved to JuliaLinearAlgebra? Since so far it mainly deals with Numbers, I would rather move it to JuliaMath.

@devmotion
Copy link
Member Author

@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
Copy link
Contributor

@sethaxen sethaxen Oct 18, 2021

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)

Copy link
Member Author

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 😄

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be fixed now.

Copy link
Contributor

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.

Copy link
Contributor

@sethaxen sethaxen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@devmotion devmotion merged commit 6a8e18b into main Oct 18, 2021
@devmotion devmotion deleted the dw/realdot branch October 18, 2021 23:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants