in Sources/TensorFlow/Core/LazyTensorOperation.swift [401:456]
func execute() {
// If we want to stage this, we will need to add control dependencies.
// For the time-being, just build a TFE_Op and run it.
//
// Collect all the unmaterialized inputs.
var unmaterializedInputs = [LazyTensorOperation]()
unmaterializedInputs.reserveCapacity(inputs.count)
for input in inputs {
switch input {
case .single(let v):
if let lazyOperation = v.lazyTensorOperation {
unmaterializedInputs.append(lazyOperation)
}
case .list(let values):
unmaterializedInputs.append(
contentsOf: values.lazy.compactMap { $0.lazyTensorOperation }
)
}
}
// Materialize the inputs now.
LazyTensorOperation.materialize(targets: unmaterializedInputs)
// Build the TFEOp and execute.
let op = TFE_Op(name, outputCount)
for input in inputs {
switch input {
case .single(let v):
op.addInput(v._tfeTensorHandle)
case .list(let values):
for v in values {
op.addInput(v._tfeTensorHandle)
}
}
}
for (name, value) in attributes {
switch value {
case .boolValue(let v): op.updateAttribute(name, v)
case .intValue(let v): op.updateAttribute(name, v)
case .floatValue(let v): op.updateAttribute(name, v)
case .doubleValue(let v): op.updateAttribute(name, v)
case .stringValue(let v): op.updateAttribute(name, v)
case .boolArray(let v): op.updateAttribute(name, v)
case .intArray(let v): op.updateAttribute(name, v)
case .floatArray(let v): op.updateAttribute(name, v)
case .doubleArray(let v): op.updateAttribute(name, v)
case .stringArray(let v): op.updateAttribute(name, v)
case .constTensor(_): fatalError("Const Tensor cannot be eager attribute.")
case .tensorDataTypeValue(let v): op.updateAttribute(name, v)
case .tensorDataTypeArray(let v): op.updateAttribute(name, v)
case .optionalTensorShape(let v): op.updateAttribute(name, v)
case .optionalTensorShapeArray(let v): op.updateAttribute(name, v)
case .tensorFunctionPointer(let v): op.updateAttribute(name, v)
}
}
op.execute()
}