-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
[TF] Change APIs to use Int
instead of Int32
.
#24012
Conversation
This is just a start - there are definitely more usages of
|
f971189
to
5863cbd
Compare
I saw those places. It would be much nicer to incorporate those changes in this exact PR instead of changing them and reverting some changes made here in a separate PR. |
e29ae9e
to
fff5f92
Compare
All user-facing APIs now use |
@swift-ci Please test tensorflow |
- Let `TensorShape` store `[Int]`. - Change all `Tensor` and `Layer` APIs to use `Int` instead of `Int32`. - Remove unnecessary `Int` initializer calls.
9dcd510
to
7e6438c
Compare
7e6438c
to
739e6c2
Compare
return TensorShape( | ||
Array(dimensions[Int(bounds.lowerBound)..<Int(bounds.upperBound)]) | ||
) | ||
return TensorShape(Array(dimensions[bounds])) |
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.
I thought TensorShape
has a collection initializer, so i don't think Array(...)
is necessary.
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.
TensorShape
does not yet have a collection initializer. I will add one.
324d1cd
to
2281fbd
Compare
@swift-ci Please clean test tensorflow |
Filed TF-439 to track revisiting test failures.
Use friend `swift-apis` PR.
@swift-ci Please clean test tensorflow |
} | ||
return -1 | ||
} | ||
let ranks = value.map { shape in (shape?.rank).map(Int32.init) ?? -1 } |
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.
Why are the parentheses necessary?
- Let `TensorShape` store `[Int]`. - Let `Tensor` subscripts take `Int` and `Range<Int>`. - Reduce explicit calls to `Int32.init` in user code. - Notably, initializers taking `TensorShape` no longer need `Int32.init`. Added two shims: - `Tensor(_: [Int])` creates a `Tensor<Scalar>`, where `Scalar` conforms to `BinaryInteger`. - This is useful for `Tensor<Int32>(shape.dimensions)`. - Overload `Tensor` subscripts for `Int32` and `Range<Int32>`. - This is useful for `tensor[0..<x.rank]`. - I chose not to change `rank` and `scalarCount` to `Int` for now.
TensorShape
store[Int]
.Tensor
subscripts takeInt
andRange<Int>
.Int32.init
in user code.TensorShape
no longer needInt32.init
.Added two shims:
Tensor(_: [Int])
creates aTensor<Scalar>
, whereScalar
conforms to
BinaryInteger
.Tensor<Int32>(shape.dimensions)
.Tensor
subscripts forInt32
andRange<Int32>
.tensor[0..<x.rank]
.rank
andscalarCount
toInt
for now.