Skip to content
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

Bools have no tangent #667

Merged
merged 1 commit into from
Mar 1, 2024
Merged

Bools have no tangent #667

merged 1 commit into from
Mar 1, 2024

Conversation

oxinabox
Copy link
Member

Doing this improves type stability of Diffractor's forwards mode since if you have code that is like

y_smallest = if x>y
    y<z
else 
   false
end

then the first branch would get a tangent of NoTangent() due to the fact that we have @non_differentiable Base.:>(::Any, ::Any).
But the second would (without this PR) get a tangent of false.

I am tempted to make this Integers.
But seemed starting conservative with Bool might be better

@willtebbutt you have thought about this a lot, what do you think?

@oxinabox oxinabox requested a review from willtebbutt February 28, 2024 00:58
Copy link

codecov bot commented Feb 28, 2024

Codecov Report

Attention: Patch coverage is 50.00000% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 93.54%. Comparing base (75e84bc) to head (4b2c810).

Files Patch % Lines
src/tangent_types/abstract_zero.jl 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #667      +/-   ##
==========================================
- Coverage   93.62%   93.54%   -0.09%     
==========================================
  Files          15       15              
  Lines         989      991       +2     
==========================================
+ Hits          926      927       +1     
- Misses         63       64       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@willtebbutt willtebbutt left a comment

Choose a reason for hiding this comment

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

I 100% agree that it should always hold that tangent_type(Bool) == NoTangent.

@@ -178,6 +179,8 @@ end

# Sad heauristic methods we need because of unassigned values
guess_zero_tangent_type(::Type{T}) where {T<:Number} = T
guess_zero_tangent_type(::Type{Bool}) = NoTangent()
Copy link
Member

Choose a reason for hiding this comment

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

Should this not just be NoTangent?

Copy link
Member Author

Choose a reason for hiding this comment

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

You are correct

@oxinabox
Copy link
Member Author

Should I go wider and do all Integers

@willtebbutt
Copy link
Member

I think that would be a good idea if you target the concrete subtypes, rather than the abstract type Integer.

@oxinabox oxinabox merged commit 7730f38 into main Mar 1, 2024
23 of 28 checks passed
@oxinabox oxinabox deleted the ox/nobool branch March 1, 2024 03:53
@oxinabox
Copy link
Member Author

oxinabox commented Mar 1, 2024

merging this now.
But tell me more?

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.

2 participants