-
Notifications
You must be signed in to change notification settings - Fork 10.6k
[Python] Improve Python interop usability. #22104
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
[Python] Improve Python interop usability. #22104
Conversation
- Define `version` and `versionInfo` computed properties on `PythonInterface`
for convenience.
- Define labelless failable initializers from `PythonObject`
(representing `numpy.ndarray`) to `ShapedArray` and `Tensor`.
- A labelless initializer was not created for `Array` because `Array` is
always one-dimensional, so the conversion is semantically more significant.
Users can use the labelled `Array(numpyArray:)` initalizer.
| // Creates a `ShapedArray` instance from the given `PythonObject` if it is a | ||
| // `numpy.ndarray` instance with a matching scalar datatype. | ||
| public init?(_ pythonObject: PythonObject) { | ||
| self.init(numpyArray: pythonObject) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's not a numpy array, we should load it as a (potentially multi-dimensional) python array.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Added TODO comments in 49f70e4.
|
@swift-ci Please test tensorflow |
|
@swift-ci please test tensorflow Linux |
3 similar comments
|
@swift-ci please test tensorflow Linux |
|
@swift-ci please test tensorflow Linux |
|
@swift-ci please test tensorflow Linux |
|
@swift-ci please test tensorflow |
3a8f057 to
4100d28
Compare
`init?(numpy:)` is a bit shorter than the previous `init?(numpyArray:)`. Using a labelless initializer is problematic because it causes type inference problems due to implicit conversions.
4100d28 to
db4625e
Compare
|
@swift-ci Please test tensorflow |
1 similar comment
|
@swift-ci Please test tensorflow |
versionandversionInfocomputed properties onPythonInterfacefor convenience.
PythonObject(representing
numpy.ndarray) toShapedArrayandTensor.ArraybecauseArrayisalways one-dimensional, so the nature of the conversion is semantically bigger.