Skip to content
This repository was archived by the owner on Jul 1, 2023. It is now read-only.

Commit 9aefe8d

Browse files
committed
Style issues, added comments elaborating "maybe".
1 parent cca1581 commit 9aefe8d

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

Sources/TensorFlow/Core/LazyTensorOperation.swift

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ extension LazyTensorOperation {
737737
// Return materialized outputs if any.
738738
if let outputs = outputs { return outputs }
739739

740-
LazyTensorOperation.materializeLiveTensors(self)
740+
materializeLiveTensors()
741741

742742
// Our outputs should have been updated by now. Otherwise,
743743
// something terrible happened!
@@ -748,29 +748,35 @@ extension LazyTensorOperation {
748748
/// Converts symbolic tensor inputs to concrete inputs if the
749749
/// associated `LazyTensorOperation` has been materialized.
750750
private func maybeMaterializeInputs() {
751+
/// If `lazyTensor` is symbolic and the associated `LazyTensorOperation`
752+
/// has been materialized, return the corresponding concrete `LazyTensor`.
753+
/// Otherwise, return `lazyTensor` untouched.
751754
func maybeMaterialized(lazyTensor: LazyTensor) -> LazyTensor {
752755
let handle = lazyTensor.handle
753-
if case let LazyTensor.Handle.symbolic(lazyOp, index, _) = handle {
754-
if let outputs = lazyOp.outputs {
755-
return LazyTensor(_materialized: outputs[index])
756-
}
756+
if case let LazyTensor.Handle.symbolic(lazyOp, index, _) = handle,
757+
let outputs = lazyOp.outputs {
758+
return LazyTensor(_materialized: outputs[index])
757759
}
758760
return lazyTensor
759761
}
760762

763+
/// Rewrite the input such that all symbolic values that have been
764+
/// materialized have been replaced by the corresponding concerete
765+
/// inputs. If no symbolic values have been materialized or if there are
766+
/// no symbolic values, return the `input` untouched.
761767
func maybeMaterialized(input: Input) -> Input {
762768
switch input {
763769
case .single(let h):
764-
return Input.single(maybeMaterialized(lazyTensor: h))
770+
return .single(maybeMaterialized(lazyTensor: h))
765771
case .list(let elements):
766-
return Input.list(elements.map { maybeMaterialized(lazyTensor: $0) })
772+
return .list(elements.map { maybeMaterialized(lazyTensor: $0) })
767773
}
768774
}
769775
inputs = inputs.map { maybeMaterialized(input: $0) }
770776
}
771777

772-
private static func materializeLiveTensors(_ lazyOp: LazyTensorOperation) {
773-
let lazyTrace = LazyTensorTrace(lazyOp)
778+
private func materializeLiveTensors() {
779+
let lazyTrace = LazyTensorTrace(self)
774780
debugLog("Extracted trace:\n\(lazyTrace)")
775781

776782
let function = TFFunction(trace: lazyTrace)

0 commit comments

Comments
 (0)