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

Commit 23870cb

Browse files
committed
Remove trailing whitespace, add comment to make init differentiable.
1 parent 01efbd9 commit 23870cb

File tree

1 file changed

+37
-37
lines changed

1 file changed

+37
-37
lines changed

Sources/TensorFlow/Core/Complex.swift

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ public struct Complex<T : FloatingPoint> {
22
public var real: T
33
public var imaginary: T
44

5-
@differentiable(where T : Differentiable)
5+
// TODO: Make differentiable, crashing right now
66
public init(real: T = 0, imaginary: T = 0) {
77
self.real = real
88
self.imaginary = imaginary
@@ -15,43 +15,43 @@ extension Complex : Differentiable where T : Differentiable {
1515
}
1616

1717
extension Complex {
18-
18+
1919
public static var i: Complex {
2020
return Complex(real: 0, imaginary: 1)
2121
}
2222

23-
23+
2424
public var isFinite: Bool {
2525
return real.isFinite && imaginary.isFinite
2626
}
2727

28-
28+
2929
public var isInfinite: Bool {
3030
return real.isInfinite || imaginary.isInfinite
3131
}
3232

33-
33+
3434
public var isNaN: Bool {
3535
return (real.isNaN && !imaginary.isInfinite) ||
3636
(imaginary.isNaN && !real.isInfinite)
3737
}
3838

39-
39+
4040
public var isZero: Bool {
4141
return real.isZero && imaginary.isZero
4242
}
4343
}
4444

4545
extension Complex : ExpressibleByIntegerLiteral {
46-
46+
4747
public init(integerLiteral value: Int) {
4848
self.real = T(value)
4949
self.imaginary = 0
5050
}
5151
}
5252

5353
extension Complex : CustomStringConvertible {
54-
54+
5555
public var description: String {
5656
return real.isNaN && real.sign == .minus
5757
? imaginary.sign == .minus
@@ -64,36 +64,36 @@ extension Complex : CustomStringConvertible {
6464
}
6565

6666
extension Complex : Equatable {
67-
67+
6868
public static func == (lhs: Complex, rhs: Complex) -> Bool {
6969
return lhs.real == rhs.real && lhs.imaginary == rhs.imaginary
7070
}
7171
}
7272

7373
extension Complex : AdditiveArithmetic {
74-
74+
7575
@differentiable(vjp: _vjpAdd(lhs:rhs:) where T : Differentiable)
7676
public static func + (lhs: Complex, rhs: Complex) -> Complex {
77-
var lhs = lhs
78-
lhs += rhs
79-
return lhs
77+
var temp = lhs
78+
temp += rhs
79+
return temp
8080
}
8181

82-
82+
8383
public static func += (lhs: inout Complex, rhs: Complex) {
8484
lhs.real += rhs.real
8585
lhs.imaginary += rhs.imaginary
8686
}
8787

88-
88+
8989
@differentiable(vjp: _vjpSubtract(lhs:rhs:) where T : Differentiable)
9090
public static func - (lhs: Complex, rhs: Complex) -> Complex {
91-
var lhs = lhs
92-
lhs -= rhs
93-
return lhs
91+
var temp = lhs
92+
temp -= rhs
93+
return temp
9494
}
9595

96-
96+
9797
public static func -= (lhs: inout Complex, rhs: Complex) {
9898
lhs.real -= rhs.real
9999
lhs.imaginary -= rhs.imaginary
@@ -107,7 +107,7 @@ extension Complex : Numeric {
107107
self.imaginary = 0
108108
}
109109

110-
110+
111111
@differentiable(vjp: _vjpMultiply(lhs:rhs:) where T : Differentiable)
112112
public static func * (lhs: Complex, rhs: Complex) -> Complex {
113113
var a = lhs.real, b = lhs.imaginary, c = rhs.real, d = rhs.imaginary
@@ -149,12 +149,12 @@ extension Complex : Numeric {
149149
return Complex(real: x, imaginary: y)
150150
}
151151

152-
152+
153153
public static func *= (lhs: inout Complex, rhs: Complex) {
154154
lhs = lhs * rhs
155155
}
156156

157-
157+
158158
public var magnitude: T {
159159
var x = abs(real)
160160
var y = abs(imaginary)
@@ -168,21 +168,21 @@ extension Complex : Numeric {
168168
}
169169

170170
extension Complex : SignedNumeric {
171-
171+
172172
@differentiable(vjp: _vjpNegate where T : Differentiable)
173173
public static prefix func - (operand: Complex) -> Complex {
174174
return Complex(real: -operand.real, imaginary: -operand.imaginary)
175175
}
176176

177-
177+
178178
public mutating func negate() {
179179
real.negate()
180180
imaginary.negate()
181181
}
182182
}
183183

184184
extension Complex {
185-
185+
186186
@differentiable(vjp: _vjpDivide(lhs:rhs:) where T : Differentiable)
187187
public static func / (lhs: Complex, rhs: Complex) -> Complex {
188188
var a = lhs.real, b = lhs.imaginary, c = rhs.real, d = rhs.imaginary
@@ -218,51 +218,51 @@ extension Complex {
218218
return Complex(real: x, imaginary: y)
219219
}
220220

221-
221+
222222
public static func /= (lhs: inout Complex, rhs: Complex) {
223223
lhs = lhs / rhs
224224
}
225225
}
226226

227227
extension Complex {
228-
228+
229229
@differentiable(vjp: _vjpComplexConjugate where T : Differentiable)
230230
public func complexConjugate() -> Complex {
231231
return Complex(real: real, imaginary: -imaginary)
232232
}
233233
}
234234

235-
235+
236236
public func abs<T>(_ z: Complex<T>) -> Complex<T> {
237237
return Complex(real: z.magnitude)
238238
}
239239

240240
extension Complex {
241-
241+
242242
@differentiable(vjp: _vjpAdding(real:) where T : Differentiable, T.TangentVector == T)
243243
public func adding(real: T) -> Complex {
244244
var c = self
245245
c.real += real
246246
return c
247247
}
248248

249-
249+
250250
@differentiable(vjp: _vjpSubtracting(real:) where T : Differentiable, T.TangentVector == T)
251251
public func subtracting(real: T) -> Complex {
252252
var c = self
253253
c.real -= real
254254
return c
255255
}
256256

257-
257+
258258
@differentiable(vjp: _vjpAdding(imaginary:) where T : Differentiable, T.TangentVector == T)
259259
public func adding(imaginary: T) -> Complex {
260260
var c = self
261261
c.imaginary += imaginary
262262
return c
263263
}
264-
265-
264+
265+
266266
@differentiable(vjp: _vjpSubtracting(imaginary:) where T : Differentiable, T.TangentVector == T)
267267
public func subtracting(imaginary: T) -> Complex {
268268
var c = self
@@ -273,25 +273,25 @@ extension Complex {
273273

274274
extension Complex where T : Differentiable {
275275
@usableFromInline
276-
static func _vjpAdd(lhs: Complex, rhs: Complex)
276+
static func _vjpAdd(lhs: Complex, rhs: Complex)
277277
-> (Complex, (Complex) -> (Complex, Complex)) {
278278
return (lhs + rhs, { v in (v, v) })
279279
}
280280

281281
@usableFromInline
282-
static func _vjpSubtract(lhs: Complex, rhs: Complex)
282+
static func _vjpSubtract(lhs: Complex, rhs: Complex)
283283
-> (Complex, (Complex) -> (Complex, Complex)) {
284284
return (lhs - rhs, { v in (v, -v) })
285285
}
286286

287287
@usableFromInline
288-
static func _vjpMultiply(lhs: Complex, rhs: Complex)
288+
static func _vjpMultiply(lhs: Complex, rhs: Complex)
289289
-> (Complex, (Complex) -> (Complex, Complex)) {
290290
return (lhs * rhs, { v in (rhs * v, lhs * v) })
291291
}
292292

293293
@usableFromInline
294-
static func _vjpDivide(lhs: Complex, rhs: Complex)
294+
static func _vjpDivide(lhs: Complex, rhs: Complex)
295295
-> (Complex, (Complex) -> (Complex, Complex)) {
296296
return (lhs / rhs, { v in (v / rhs, -lhs / (rhs * rhs) * v) })
297297
}

0 commit comments

Comments
 (0)