Skip to content

Commit 835d143

Browse files
eaplataniosrxwei
authored andcommitted
Removed 'HackyTensorflowMigrationSupport' from apple/swift.
Removed HackyTensorflowMigrationSupport.swift from apple/swift. Friend PR: swiftlang/swift#25147.
1 parent 1d484e1 commit 835d143

File tree

3 files changed

+52
-7
lines changed

3 files changed

+52
-7
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ xcuserdata
55
DerivedData/
66
*.xcodeproj
77
*~
8+
*.vscode
9+
*.idea
810

911
### MacOS ###
1012
.DS_Store

Sources/TensorFlow/Core/DataTypes.swift

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,18 @@
1414

1515
import CTensorFlow
1616

17-
public extension TensorDataType {
18-
var _cDataType: TF_DataType {
19-
return TF_DataType(rawValue: _internalStorageType)
17+
/// A TensorFlow dynamic type value that can be created from types that conform to
18+
/// `TensorFlowScalar`.
19+
// This simply wraps a `TF_DataType` and allows user code to handle
20+
// `TF_DataType` without importing CTensorFlow, which pollutes the namespace
21+
// with TensorFlow C API declarations.
22+
public struct TensorDataType {
23+
public var _cDataType: TF_DataType
24+
25+
@usableFromInline
26+
internal init(_ cDataType: TF_DataType) {
27+
self._cDataType = cDataType
2028
}
21-
22-
init(_ cDataType: TF_DataType) {
23-
self.init(rawValue: cDataType.rawValue)
24-
}
2529
}
2630

2731
@usableFromInline

Sources/TensorFlow/Core/TensorGroup.swift

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,45 @@
1414

1515
import CTensorFlow
1616

17+
/// A protocol representing types that can be mapped to `Array<CTensorHandle>`.
18+
///
19+
/// This protocol is defined separately from `TensorGroup` in order for the number of tensors to be
20+
/// determined at runtime. For example, `[Tensor<Float>]` may have an unknown number of elements at
21+
/// compile time.
22+
///
23+
/// This protocol can be derived automatically for structs whose stored properties all conform to
24+
/// the `TensorGroup` protocol. It cannot be derived automatically for structs whose properties all
25+
/// conform to `TensorArrayProtocol` due to the constructor requirement (i.e., in such cases it
26+
/// would be impossible to know how to break down `count` among the stored properties).
27+
public protocol TensorArrayProtocol {
28+
/// Writes the tensor handles to `address`, which must be allocated with enough capacity to hold
29+
/// `_tensorHandleCount` handles. The tensor handles written to `address` are borrowed: this
30+
/// container still owns them.
31+
func _unpackTensorHandles(into address: UnsafeMutablePointer<CTensorHandle>?)
32+
33+
var _tensorHandleCount: Int32 { get }
34+
var _typeList: [TensorDataType] { get }
35+
36+
init(_owning tensorHandles: UnsafePointer<CTensorHandle>?, count: Int)
37+
}
38+
39+
/// A protocol representing types that can be mapped to and from `Array<CTensorHandle>`.
40+
///
41+
/// When a `TensorGroup` is used as an argument to a tensor operation, it is passed as an argument
42+
/// list whose elements are the tensor fields of the type.
43+
///
44+
/// When a `TensorGroup` is returned as a result of a tensor operation, it is initialized with its
45+
/// tensor fields set to the tensor operation's tensor results.
46+
public protocol TensorGroup: TensorArrayProtocol {
47+
48+
/// The types of the tensor stored properties in this type.
49+
static var _typeList: [TensorDataType] { get }
50+
51+
/// Initializes a value of this type, taking ownership of the `_tensorHandleCount` tensors
52+
/// starting at address `tensorHandles`.
53+
init(_owning tensorHandles: UnsafePointer<CTensorHandle>?)
54+
}
55+
1756
public extension TensorGroup {
1857
/// The number of tensor fields in this type.
1958
static var _tensorHandleCount: Int32 { return Int32(Self._typeList.count) }

0 commit comments

Comments
 (0)