Skip to content
This repository was archived by the owner on Apr 23, 2025. It is now read-only.

Commit 29e9f88

Browse files
committed
Apply swift-format tool
1 parent aef87e3 commit 29e9f88

File tree

5 files changed

+33
-27
lines changed

5 files changed

+33
-27
lines changed

FastStyleTransfer/Demo/main.swift

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@ struct Config {
1919
}
2020

2121
var config = Config()
22-
parseArguments(into: &config, with: [
23-
"weights": \Config.weights,
24-
"image": \Config.image,
25-
"output": \Config.output
26-
])
22+
parseArguments(
23+
into: &config,
24+
with: [
25+
"weights": \Config.weights,
26+
"image": \Config.image,
27+
"output": \Config.output
28+
]
29+
)
2730

2831
guard let image = config.image, let output = config.output else {
2932
print("Error: No input image!")

FastStyleTransfer/Models/TransformerNet.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,7 @@ public struct ResidualBlock: Layer {
122122
/// - Returns: The output.
123123
@differentiable
124124
public func callAsFunction(_ input: Input) -> Output {
125-
return input + input.sequenced(through:
126-
conv1, in1, relu,
127-
conv2, in2
128-
)
125+
return input + input.sequenced(through: conv1, in1, relu, conv2, in2)
129126
}
130127
}
131128

FastStyleTransfer/Utility/ImportableLayer.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public extension ImportableLayer {
3636

3737
/// Returns map of all recursive properties name to keypath.
3838
func getRecursiveNamedKeyPaths<T>(
39-
ofType valueType: T.Type
39+
ofType valueType: T.Type
4040
) -> [String: WritableKeyPath<Self, T>] {
4141
let labels = getRecursiveProperties(ofType: T.self)
4242
let keys = self.recursivelyAllWritableKeyPaths(to: T.self)
@@ -69,7 +69,7 @@ public extension ImportableLayer {
6969
mutating func unsafeImport(fromCheckpointPath path: String, map: ImportMap) {
7070
let tensorNames = map.values.map { $0.0 }
7171
let tensorValues = Raw.restoreV2(
72-
prefix: StringTensor(path),
72+
prefix: StringTensor(path),
7373
tensorNames: StringTensor(tensorNames),
7474
shapeAndSlices: StringTensor(Array(repeating: "", count: tensorNames.count)),
7575
dtypes: Array(repeating: Float.tensorFlowDataType, count: tensorNames.count)

FastStyleTransfer/Utility/Resize.swift

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,17 @@ public func resizeNearestNeighbor<Scalar: TensorFlowFloatingPoint>(
1616

1717
@usableFromInline
1818
internal func _vjpResizeNearestNeighbor<Scalar: TensorFlowFloatingPoint>(
19-
input: Tensor<Scalar>, scaleFactor: Float
19+
input: Tensor<Scalar>, scaleFactor: Float
2020
) -> (Tensor<Scalar>, (Tensor<Scalar>) -> Tensor<Scalar>) {
2121
let result = resizeNearestNeighbor(input, scaleFactor: scaleFactor)
22-
return (result, { v in
23-
let size = Tensor<Int32>(
24-
shape: [2],
25-
scalars: [input.shape[1], input.shape[2]].map { Int32($0) }
26-
)
27-
return Raw.resizeNearestNeighborGrad(grads: result, size: size)
28-
})
22+
return (
23+
result,
24+
{ v in
25+
let size = Tensor<Int32>(
26+
shape: [2],
27+
scalars: [input.shape[1], input.shape[2]].map { Int32($0) }
28+
)
29+
return Raw.resizeNearestNeighborGrad(grads: result, size: size)
30+
}
31+
)
2932
}

FastStyleTransfer/Utility/Tensor+Additions.swift

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,18 @@ public extension Tensor where Scalar: Numeric {
1818
internal extension Tensor where Scalar: TensorFlowFloatingPoint {
1919
@inlinable
2020
func _vjpPaddedWithReflection(
21-
forSizes sizes: [(before: Int, after: Int)]
21+
forSizes sizes: [(before: Int, after: Int)]
2222
) -> (Tensor, (Tensor) -> Tensor) {
2323
let result = paddedWithReflection(forSizes: sizes)
24-
return (result, { v in
25-
let paddings = Tensor<Int32>(
26-
shape: [sizes.count, 2],
27-
scalars: sizes.flatMap { [Int32($0.before), Int32($0.after)] }
28-
)
29-
return Raw.mirrorPadGrad(result, paddings: paddings, mode: Raw.Mode5.reflect)
30-
})
24+
return (
25+
result,
26+
{ v in
27+
let paddings = Tensor<Int32>(
28+
shape: [sizes.count, 2],
29+
scalars: sizes.flatMap { [Int32($0.before), Int32($0.after)] }
30+
)
31+
return Raw.mirrorPadGrad(result, paddings: paddings, mode: Raw.Mode5.reflect)
32+
}
33+
)
3134
}
3235
}

0 commit comments

Comments
 (0)