Skip to content

Conversation

@mzgubic
Copy link
Member

@mzgubic mzgubic commented Nov 20, 2020

Helps with #112

@mzgubic
Copy link
Member Author

mzgubic commented Nov 20, 2020

Not sure why the tests for ChainRules fail, they work locally for me

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.

LGTM. Happy for this to be merged once tests pass.

Base.transpose(z::AbstractZero) = z
Base.:/(z::AbstractZero, ::Any) = z

Base.convert(::Type{T}, x::AbstractZero) where T <: Real = zero(T)
Copy link
Member

Choose a reason for hiding this comment

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

Any reason to restrict this to Real? I think it would make sense to at least allow Complex, but all subtypes of Number should work as well here.

Copy link
Member

@simeonschaub simeonschaub Nov 20, 2020

Choose a reason for hiding this comment

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

Oh, and I don't know if we really want to implement this for all AbstractZeros. I am not sure this makes sense for DoesNotExist(), so it might be better to do this just for Zero().

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for catching the Real -> Number, it was just an error on my part.

My understanding of the Zero vs DoesNotExist differential types is that the purpose of the distinction between them is primarily to signal meaning when defining rules. We do define mathematical operations on DoesNotExist in which it behaves like a zero, so it seems we aren't introducing any ideologically new behaviour by allowing it to be converted to a zero?

Copy link
Member Author

Choose a reason for hiding this comment

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

Suggested change
Base.convert(::Type{T}, x::AbstractZero) where T <: Real = zero(T)
Base.convert(::Type{T}, x::AbstractZero) where T <: Number = zero(T)

@mzgubic mzgubic merged commit d3a0a68 into master Nov 30, 2020
@oxinabox oxinabox deleted the mz/convert branch January 11, 2021 13:47
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