@@ -58,26 +58,21 @@ public extension Dataset {
58
58
@inlinable @inline ( __always)
59
59
init ( randomSeed: Int64 ) {
60
60
let ( seed1, seed2) = _tensorSeeds ( Tensor ( randomSeed) )
61
- self . init (
62
- _handle : #tfop ( " RandomDataset " , seed1, seed2 ,
63
- output_types$dtype : Element . _typeList ,
64
- output_shapes : Element . _unknownShapeList )
65
- )
61
+ self . init ( _handle : Raw . experimentalRandomDataset (
62
+ seed : seed1,
63
+ seed2 : seed2 ,
64
+ outputTypes : Element . _typeList ,
65
+ outputShapes : Element . _unknownShapeList ) )
66
66
}
67
67
}
68
68
69
69
public extension Dataset {
70
70
/// Creates a dataset from a batch of elements as a tensor.
71
71
@inlinable @inline ( __always)
72
72
init ( elements: Element ) {
73
- // A dataset creation op only runs on TF CPU.
74
- self . init (
75
- _handle: #tfop(
76
- " TensorSliceDataset " , [ elements] ,
77
- Toutput_types$dtype: Element . _typeList,
78
- output_shapes: Element . _unknownShapeList
79
- )
80
- )
73
+ self . init ( _handle: Raw . tensorSliceDataset (
74
+ components: [ elements] ,
75
+ outputShapes: Element . _unknownShapeList) )
81
76
}
82
77
}
83
78
@@ -87,10 +82,10 @@ extension Dataset : Sequence {
87
82
/// Returns an iterator over the elements of this dataset.
88
83
@inlinable @inline ( __always)
89
84
public func makeIterator( ) -> DatasetIterator < Element > {
90
- let resource : ResourceHandle =
91
- #tfop ( " AnonymousIterator " , output_types$dtype : Element . _typeList,
92
- output_shapes : Element . _unknownShapeList)
93
- #tfop ( " MakeIterator " , _handle, resource) as Void
85
+ let resource = Raw . anonymousIterator (
86
+ outputTypes : Element . _typeList,
87
+ outputShapes : Element . _unknownShapeList)
88
+ Raw . makeIterator ( dataset : _handle, iterator : resource)
94
89
return DatasetIterator ( _handle: resource)
95
90
}
96
91
}
@@ -102,44 +97,43 @@ public extension Dataset {
102
97
func map< ResultElement : TensorGroup > (
103
98
_ transform: ( Element ) -> ResultElement
104
99
) -> Dataset < ResultElement > {
105
- return Dataset < ResultElement > (
106
- _handle: #tfop(
107
- " MapDataset " , _handle, [ Tensor < Int32 > ( 0 ) ] ,
108
- f$func: _tffunc ( transform) ,
109
- Targuments$dtype: [ Int32 . tensorFlowDataType] ,
110
- output_types$dtype: ResultElement . _typeList,
111
- output_shapes: ResultElement . _unknownShapeList
112
- )
113
- )
100
+ return Dataset < ResultElement > ( _handle: Raw . mapDataset (
101
+ inputDataset: _handle,
102
+ otherArguments: Tensor < Int32 > ( 0 ) ,
103
+ f: transform,
104
+ outputTypes: ResultElement . _typeList,
105
+ outputShapes: ResultElement . _unknownShapeList,
106
+ useInterOpParallelism: true ,
107
+ preserveCardinality: false ) )
114
108
}
115
109
116
110
@inlinable @inline ( __always)
117
- func map< ResultElement : TensorGroup > ( parallelCallCount: Int ,
118
- _ transform: ( Element ) -> ResultElement ) -> Dataset < ResultElement > {
119
- return Dataset < ResultElement > (
120
- _handle: #tfop( " ParallelMapDataset " , _handle, [ Tensor < Int32 > ( 0 ) ] ,
121
- [ Tensor < Int32 > ( Int32 ( parallelCallCount) ) ] ,
122
- f$func: _tffunc ( transform) ,
123
- Targuments$dtype: [ Int32 . tensorFlowDataType] ,
124
- output_types$dtype: ResultElement . _typeList,
125
- output_shapes: ResultElement . _unknownShapeList
126
- )
127
- )
111
+ func map< ResultElement : TensorGroup > (
112
+ parallelCallCount: Int ,
113
+ _ transform: ( Element ) -> ResultElement
114
+ ) -> Dataset < ResultElement > {
115
+ return Dataset < ResultElement > ( _handle: Raw . parallelMapDataset (
116
+ inputDataset: _handle,
117
+ otherArguments: Tensor < Int32 > ( 0 ) ,
118
+ numParallelCalls: Tensor < Int32 > ( Int32 ( parallelCallCount) ) ,
119
+ f: transform,
120
+ outputTypes: ResultElement . _typeList,
121
+ outputShapes: ResultElement . _unknownShapeList,
122
+ useInterOpParallelism: true ,
123
+ sloppy: false ,
124
+ preserveCardinality: false ) )
128
125
}
129
126
130
127
@inlinable @inline ( __always)
131
128
func filter(
132
129
_ isIncluded: ( Element ) -> Tensor < Bool >
133
130
) -> Dataset {
134
- return Dataset (
135
- _handle: #tfop(
136
- " FilterDataset " , _handle, [ Tensor < Int32 > ( 0 ) ] ,
137
- predicate$func: _tffunc ( isIncluded) ,
138
- Targuments$dtype: [ Int32 . tensorFlowDataType] ,
139
- output_types$dtype: Element . _typeList,
140
- output_shapes: Element . _unknownShapeList
141
- )
142
- )
131
+ return Dataset ( _handle: Raw . filterDataset (
132
+ inputDataset: _handle,
133
+ otherArguments: Tensor < Int32 > ( 0 ) ,
134
+ predicate: isIncluded,
135
+ outputTypes: Element . _typeList,
136
+ outputShapes: Element . _unknownShapeList) )
143
137
}
144
138
}
145
139
@@ -149,24 +143,22 @@ public extension Dataset {
149
143
sampleCount: Int , randomSeed: Int64
150
144
) -> Dataset {
151
145
let ( seed1, seed2) = _tensorSeeds ( Tensor ( randomSeed) )
152
- return Dataset (
153
- _handle : #tfop (
154
- " ShuffleDataset " , _handle , Tensor ( Int64 ( sampleCount) ) , seed1 , seed2 ,
155
- output_types$dtype : Element . _typeList ,
156
- output_shapes : Element . _unknownShapeList
157
- )
158
- )
146
+ return Dataset ( _handle : Raw . shuffleDataset (
147
+ inputDataset : _handle ,
148
+ bufferSize : Tensor ( Int64 ( sampleCount) ) ,
149
+ seed : seed1 ,
150
+ seed2 : seed2 ,
151
+ outputTypes : Element . _typeList ,
152
+ outputShapes : Element . _unknownShapeList ) )
159
153
}
160
154
161
155
@inlinable @inline ( __always)
162
156
func batched( _ batchSize: Int ) -> Dataset {
163
- return Dataset (
164
- _handle: #tfop(
165
- " BatchDataset " , _handle, Tensor ( Int64 ( batchSize) ) ,
166
- output_types$dtype: Element . _typeList,
167
- output_shapes: Element . _unknownShapeList
168
- )
169
- )
157
+ return Dataset ( _handle: Raw . batchDataset (
158
+ inputDataset: _handle,
159
+ batchSize: Tensor ( Int64 ( batchSize) ) ,
160
+ outputTypes: Element . _typeList,
161
+ outputShapes: Element . _unknownShapeList) )
170
162
}
171
163
}
172
164
@@ -186,16 +178,16 @@ extension DatasetIterator : IteratorProtocol {
186
178
/// exists.
187
179
@inlinable @inline ( __always)
188
180
public mutating func next( ) -> Element ? {
189
- let optional : VariantHandle =
190
- #tfop ( " IteratorGetNextAsOptional " , _handle,
191
- output_types$dtype : Element . _typeList,
192
- output_shapes : Element . _unknownShapeList)
193
- guard _TFGetScalarOrDie ( #tfop ( " OptionalHasValue " , optional) ) else {
181
+ let optional = Raw . iteratorGetNextAsOptional (
182
+ iterator : _handle,
183
+ outputTypes : Element . _typeList,
184
+ outputShapes : Element . _unknownShapeList)
185
+ guard Raw . optionalHasValue ( optional : optional) . scalarized ( ) else {
194
186
return nil
195
187
}
196
- return #tfop ( " OptionalGetValue " , optional ,
197
- output_types$dtype : Element . _typeList ,
198
- output_shapes : Element . _unknownShapeList) as Element
188
+ return Raw . optionalGetValue (
189
+ optional : optional ,
190
+ outputShapes : Element . _unknownShapeList)
199
191
}
200
192
}
201
193
@@ -217,9 +209,9 @@ public struct Zip2TensorGroup<T : TensorGroup, U : TensorGroup> : TensorGroup {
217
209
public func zip< T : TensorGroup , U : TensorGroup > (
218
210
_ dataset1: Dataset < T > , _ dataset2: Dataset < U >
219
211
) -> Dataset < Zip2TensorGroup < T , U > > {
220
- let handle : VariantHandle = #tfop (
221
- " ZipDataset " , Zip2TensorGroup ( dataset1. _handle, dataset2. _handle) ,
222
- output_types$dtype : Zip2TensorGroup< T, U> . _typeList,
223
- output_shapes : Zip2TensorGroup< T, U> . _unknownShapeList)
212
+ let handle = Raw . zipDataset (
213
+ inputDatasets : [ dataset1. _handle, dataset2. _handle] ,
214
+ outputTypes : Zip2TensorGroup< T, U> . _typeList,
215
+ outputShapes : Zip2TensorGroup< T, U> . _unknownShapeList)
224
216
return Dataset ( _handle: handle)
225
217
}
0 commit comments