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-15583] Handle zero cases in the derivative function for Array.append #57886

Open
rxwei opened this issue Dec 10, 2021 · 0 comments
Open

[SR-15583] Handle zero cases in the derivative function for Array.append #57886

rxwei opened this issue Dec 10, 2021 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. standard library Area: Standard library umbrella

Comments

@rxwei
Copy link
Member

rxwei commented Dec 10, 2021

Previous ID SR-15583
Radar rdar://75883982
Original Reporter @rxwei
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Standard Library
Labels Bug
Assignee None
Priority Medium

md5: 9fb09ff7d0330e61e8d4bf5bc095ed60

Issue Description:

Update [`Array._vjpAppend`](

mutating func _vjpAppend(_ element: Element) -> (
) to handle zero cases.

Proposed solution:

@usableFromInline
@derivative(of: append)
mutating func vjpAppend( element: Element) -> (
    value: Void, pullback: (inout TangentVector) -> Element.TangentVector
) {
    let appendedElementIndex = count
    append(element)
    return ((), { v in
        if v.base.isEmpty { return .zero }
        defer { v.base.removeLast() }
        return v.base[appendedElementIndex]
    })
}
@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
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. standard library Area: Standard library umbrella
Projects
None yet
Development

No branches or pull requests

1 participant