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

Ensure scalar_rule rules are Number typed #62

Merged
merged 1 commit into from
Jun 20, 2019
Merged

Conversation

ararslan
Copy link
Member

Currently, @scalar_rule generates rrule methods with no type constraints. This poses a problem for rules with different definitions that have not yet been implemented. For example, the rule for matrix
exponential is quite different from that for scalar exponential, but in the absence of an rrule(::typeof(exp), ::AbstractMatrix) method, the incorrect fallback generated by @scalar_rule is used.

To solve this, @scalar_rule now allows type constraints, e.g. @scalar_rule(f(x::Complex), g(x)), and it adds explicit ::Number constraints to the generated methods if no such constraints are provided.

@ararslan ararslan requested a review from jrevels June 19, 2019 21:03
Copy link
Member

@jrevels jrevels left a comment

Choose a reason for hiding this comment

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

Update the docstring to reflect this new behavior?

Otherwise LGTM

@jrevels
Copy link
Member

jrevels commented Jun 19, 2019

IIUC, will also need to update

@scalar_rule(rem2pi(x, r), (One(), DNE()))
(the second argument is not ::Number, but ::RoundingMode)

Currently, `@scalar_rule` generates `rrule` methods with no type
constraints. This poses a problem for rules with different definitions
that have not yet been implemented. For example, the rule for matrix
exponential is quite different from that for scalar exponential, but in
the absence of an `rrule(::typeof(exp), ::AbstractMatrix)` method, the
incorrect fallback generated by `@scalar_rule` is used.

To solve this, `@scalar_rule` now allows type constaints, e.g.
`@scalar_rule(f(x::Complex), g(x))`, and it adds explicit `::Number`
constraints to the generated methods if no such constraints are
provided.
@ararslan
Copy link
Member Author

Good notes, thanks! I've added a blurb about it to the docstring and added a ::RoundingMode annotation to rem2pi.

@ararslan
Copy link
Member Author

Not sure what's up with the coverage drop. I think it doesn't like that I touched rem2pi.

@ararslan ararslan dismissed jrevels’s stale review June 20, 2019 16:43

Requested changes have been implemented

@ararslan ararslan merged commit 3c364f7 into master Jun 20, 2019
@ararslan ararslan deleted the aa/scalar-number branch June 20, 2019 16:48
@nickrobinson251 nickrobinson251 added the type constraints Potentially raises a question about how tightly to constrain argument types for a rule. See #232 label Jan 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type constraints Potentially raises a question about how tightly to constrain argument types for a rule. See #232
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants