tensorflow / swift

Swift for TensorFlow
https://tensorflow.org/swift
Apache License 2.0
6.13k stars 606 forks source link

Add workaround for SR-13949 #581

Closed texasmichelle closed 3 years ago

texasmichelle commented 3 years ago

Adds a workaround for what appears to be a REPL-only upstream bug affecting calls to print() (SR-13949).

This fix resolves the following failures.

a_swift_tour.ipynb:

nbclient.exceptions.CellExecutionError: An error occurred while executing the following cell:
------------------
print(numbers.map({ (number: Int) -> Int in
    let result = 3 * number
    return result
}))
------------------

error: <Cell 34>:2:22: error: cannot find 'number' in scope
    let result = 3 * number
                     ^~~~~~

error: <Cell 34>:3:12: error: cannot find 'result' in scope
    return result
           ^~~~~~

custom_differentiation.ipynb:

nbclient.exceptions.CellExecutionError: An error occurred while executing the following cell:
------------------
var x: Float = 30
print(gradient(at: x) { x -> Float in
    // Print the partial derivative with respect to the result of `sin(x)`.
    let a = sin(x).withDerivative { print("∂+/∂sin = \($0)") } 
    // Force the partial derivative with respect to `x` to be `0.5`.
    let b = log(x.withDerivative { (dx: inout Float) in
        print("∂log/∂x = \(dx), but rewritten to 0.5");
        dx = 0.5
    })
    return a + b
})
------------------

error: <Cell 4>:7:32: error: cannot find 'dx' in scope
        print("∂log/∂x = \(dx), but rewritten to 0.5");

error: <Cell 4>:8:9: error: cannot find 'dx' in scope
        dx = 0.5
        ^~

error: <Cell 4>:10:12: error: cannot find 'a' in scope
    return a + b
           ^

error: <Cell 4>:10:16: error: cannot find 'b' in scope
    return a + b
               ^
review-notebook-app[bot] commented 3 years ago

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB