Swifty API discovery via '@available' on raw APIs. #483
Description
For many raw APIs, we already have corresponding idiomatic APIs that implement all of the raw API's functionality, e.g. Tensor.init(_:)
for Raw.cast(_:)
, Tensor.reshaped(to:)
for Raw.reshape(_:shape:)
, etc. These raw APIs are not recommend also because they are not differentiable. However, raw APIs are more discoverable than the idiomatic APIs to users who are familiar with Python TensorFlow, and there are no recommended alternatives when some differentiability error occurs on the raw API.
As such, we should consider adding an @available
attribute to raw APIs that have an idiomatic alternative that implements all of their functionality. Using such a raw API will produce a warning.
public extension Raw {
...
@available(*, deprecated, message: "use the 'reshape(_:)' method on 'Tensor' instead")
func Raw.reshape<T>(_ x: Tensor<T>, shape: Tensor<Int32>) -> Tensor<T>
...
}
Compiler warns if Raw.reshape
is used:
test.swift:1:1: warning: 'reshape(_:shape:)' is deprecated: use the 'reshaped(to:)' method on 'Tensor' instead
Raw.reshape(x)
^
Note: We could also use a renamed:
argument in an @available
attribute, but the message would not be as clear to Python users. For instance, "renamed to 'Tensor.reshaped(to:)'" is less descriptive than "use the 'reshaped(to:)' method on 'Tensor' instead".