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

[SR-9596] [AD] Support the trailing 'where' clause in @differentiable attributes #52043

Closed
rxwei opened this issue Jan 3, 2019 · 1 comment
Closed
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. swift for tensorflow

Comments

@rxwei
Copy link
Member

rxwei commented Jan 3, 2019

Previous ID SR-9596
Radar None
Original Reporter @rxwei
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Swift for TensorFlow
Labels Bug
Assignee @dan-zheng
Priority Medium

md5: c7be10d7e95a72060b883a88c257d900

Issue Description:

Currently, we require the vjp to be defined in the same generic context. However, this is mathematically wrong and practically limiting.

extension Tensor where Scalar : Numeric {
  @differentiable(vjp: _vjp_mul)
  public static func * (lhs: Scalar, rhs: Tensor) -> Tensor {
    return Tensor(lhs) * rhs
  }
}

In this example, the original function is defined under constraint `Scalar : Numeric`. But it should not be differentiable unless 'Scalar : Differentiable'. For this, we have syntax support for a trailing 'where' clause in '@differentiable':

@differentiable(where Scalar : Differentiable)

But this is currently being ignored by the type checker. We should support it now in order to unblock defining primitives for tensor methods that take or return `Scalar`. With 'where' clauses type-checked, VJP/adjoint should be allowed to be defined in a more constrained generic context.

@dan-zheng
Copy link
Collaborator

Resolved in two PRs:

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. swift for tensorflow
Projects
None yet
Development

No branches or pull requests

2 participants