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

Commit 683366d

Browse files
committed
Cleanup comments and commented out code.
1 parent de575fe commit 683366d

File tree

1 file changed

+4
-88
lines changed

1 file changed

+4
-88
lines changed

Sources/TensorFlow/Core/Complex.swift

Lines changed: 4 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,47 @@
1-
import TensorFlow
2-
// T : FloatingPoint & Differentiable
31
public struct Complex<T : FloatingPoint> {
4-
// ---------------------------------------------------------------------------
5-
// MARK: Stored Properties
6-
// ---------------------------------------------------------------------------
7-
8-
/// The real component of the complex value.
92
public var real: T
10-
11-
/// The imaginary component of the complex value.
123
public var imaginary: T
134

14-
// ---------------------------------------------------------------------------
15-
// MARK: Initializers
16-
// ---------------------------------------------------------------------------
175
public init(real: T = 0, imaginary: T = 0) {
186
self.real = real
197
self.imaginary = imaginary
208
}
219
}
2210

23-
extension Complex : Differentiable where T : Differentiable/*, T.TangentVector == T*/ {
24-
// ---------------------------------------------------------------------------
25-
// MARK: Differentiability
26-
// ---------------------------------------------------------------------------
11+
extension Complex : Differentiable where T : Differentiable {
2712
public typealias TangentVector = Complex
2813
public typealias AllDifferentiableVariables = Complex
2914
}
3015

3116
extension Complex {
32-
// ---------------------------------------------------------------------------
33-
// MARK: Static Properties
34-
// ---------------------------------------------------------------------------
35-
36-
/// The imaginary unit _i_.
3717
@inlinable
3818
public static var i: Complex {
3919
return Complex(real: 0, imaginary: 1)
4020
}
4121

42-
/// A Boolean value indicating whether the instance is finite.
43-
///
44-
/// A complex value is finite if its real and imaginary components are both
45-
/// finite. A component is finite if it is not infinity or NaN.
4622
@inlinable
4723
public var isFinite: Bool {
4824
return real.isFinite && imaginary.isFinite
4925
}
5026

51-
/// A Boolean value indicating whether the instance is infinite.
52-
///
53-
/// A complex value is infinite if at least one of its components (real or
54-
/// imaginary) is infinite, even if the other component is NaN.
55-
///
56-
/// Note that `isFinite` and `isInfinite` do not form a dichotomy because NaN
57-
/// is neither finite nor infinite.
5827
@inlinable
5928
public var isInfinite: Bool {
6029
return real.isInfinite || imaginary.isInfinite
6130
}
6231

63-
/// A Boolean value indicating whether the instance is NaN ("not a number").
64-
///
65-
/// A complex value is NaN if at least one of its components (real or
66-
/// imaginary) is NaN and the other component is not infinite.
67-
///
68-
/// Because NaN is not equal to any value, including NaN, use this property
69-
/// instead of the equal-to operator (`==`) or not-equal-to operator (`!=`) to
70-
/// test whether a value is or is not NaN.
71-
///
72-
/// This property is `true` for both quiet and signaling NaNs.
7332
@inlinable
7433
public var isNaN: Bool {
7534
return (real.isNaN && !imaginary.isInfinite) ||
7635
(imaginary.isNaN && !real.isInfinite)
7736
}
7837

79-
/// A Boolean value indicating whether the instance is equal to zero.
80-
///
81-
/// A complex value is equal to zero if its real and imaginary components both
82-
/// represent either `-0.0` or `+0.0`.
8338
@inlinable
8439
public var isZero: Bool {
8540
return real.isZero && imaginary.isZero
8641
}
8742
}
8843

8944
extension Complex : ExpressibleByIntegerLiteral {
90-
// ---------------------------------------------------------------------------
91-
// MARK: ExpressibleByIntegerLiteral
92-
// ---------------------------------------------------------------------------
93-
9445
@inlinable
9546
public init(integerLiteral value: Int) {
9647
self.real = T(value)
@@ -99,16 +50,9 @@ extension Complex : ExpressibleByIntegerLiteral {
9950
}
10051

10152
extension Complex : CustomStringConvertible {
102-
// ---------------------------------------------------------------------------
103-
// MARK: CustomStringConvertible
104-
// ---------------------------------------------------------------------------
105-
10653
@inlinable
10754
public var description: String {
10855
return real.isNaN && real.sign == .minus
109-
// At present, -NaN is described as "nan", which is acceptable for real
110-
// values. However, it is arguably misleading to describe -NaN - NaNi as
111-
// "nan + nani" or "nan - nani". Therefore, handle this case separately.
11256
? imaginary.sign == .minus
11357
? "-\(-real) - \(-imaginary)i"
11458
: "-\(-real) + \(imaginary)i"
@@ -119,21 +63,13 @@ extension Complex : CustomStringConvertible {
11963
}
12064

12165
extension Complex : Equatable {
122-
// ---------------------------------------------------------------------------
123-
// MARK: Equatable
124-
// ---------------------------------------------------------------------------
125-
12666
@inlinable
12767
public static func == (lhs: Complex, rhs: Complex) -> Bool {
12868
return lhs.real == rhs.real && lhs.imaginary == rhs.imaginary
12969
}
13070
}
13171

13272
extension Complex : AdditiveArithmetic {
133-
// ---------------------------------------------------------------------------
134-
// MARK: AdditiveArithmetic
135-
// ---------------------------------------------------------------------------
136-
13773
@inlinable
13874
@differentiable(vjp: _vjpAdd(lhs:rhs:) where T : Differentiable)
13975
public static func + (lhs: Complex, rhs: Complex) -> Complex {
@@ -164,10 +100,6 @@ extension Complex : AdditiveArithmetic {
164100
}
165101

166102
extension Complex : Numeric {
167-
// ---------------------------------------------------------------------------
168-
// MARK: Numeric
169-
// ---------------------------------------------------------------------------
170-
171103
public init?<U>(exactly source: U) where U : BinaryInteger {
172104
guard let t = T(exactly: source) else { return nil }
173105
self.real = t
@@ -181,20 +113,17 @@ extension Complex : Numeric {
181113
let ac = a * c, bd = b * d, ad = a * d, bc = b * c
182114
let x = ac - bd
183115
let y = ad + bc
184-
// Recover infinities that computed as NaN + iNaN.
185-
// See C11 Annex G.
116+
186117
if x.isNaN && y.isNaN {
187118
var recalculate = false
188119
if a.isInfinite || b.isInfinite {
189-
// "Box" the infinity and change NaNs in the other operand to 0.
190120
a = T(signOf: a, magnitudeOf: a.isInfinite ? 1 : 0)
191121
b = T(signOf: b, magnitudeOf: b.isInfinite ? 1 : 0)
192122
if c.isNaN { c = T(signOf: c, magnitudeOf: 0) }
193123
if d.isNaN { d = T(signOf: d, magnitudeOf: 0) }
194124
recalculate = true
195125
}
196126
if c.isInfinite || d.isInfinite {
197-
// "Box" the infinity and change NaNs in the other operand to 0.
198127
if a.isNaN { a = T(signOf: a, magnitudeOf: 0) }
199128
if b.isNaN { b = T(signOf: b, magnitudeOf: 0) }
200129
c = T(signOf: c, magnitudeOf: c.isInfinite ? 1 : 0)
@@ -203,7 +132,6 @@ extension Complex : Numeric {
203132
}
204133
if !recalculate &&
205134
(ac.isInfinite || bd.isInfinite || ad.isInfinite || bc.isInfinite) {
206-
// Recover infinities from overflow by changing NaNs to 0.
207135
if a.isNaN { a = T(signOf: a, magnitudeOf: 0) }
208136
if b.isNaN { b = T(signOf: b, magnitudeOf: 0) }
209137
if c.isNaN { c = T(signOf: c, magnitudeOf: 0) }
@@ -239,10 +167,6 @@ extension Complex : Numeric {
239167
}
240168

241169
extension Complex : SignedNumeric {
242-
// ---------------------------------------------------------------------------
243-
// MARK: SignedNumeric
244-
// ---------------------------------------------------------------------------
245-
246170
@inlinable
247171
@differentiable(vjp: _vjpNegate where T : Differentiable)
248172
public static prefix func - (operand: Complex) -> Complex {
@@ -257,17 +181,12 @@ extension Complex : SignedNumeric {
257181
}
258182

259183
extension Complex {
260-
// ---------------------------------------------------------------------------
261-
// MARK: Division
262-
// ---------------------------------------------------------------------------
263-
264184
@inlinable
265185
@differentiable(vjp: _vjpDivide(lhs:rhs:) where T : Differentiable)
266186
public static func / (lhs: Complex, rhs: Complex) -> Complex {
267187
var a = lhs.real, b = lhs.imaginary, c = rhs.real, d = rhs.imaginary
268188
var x: T
269189
var y: T
270-
// Prevent avoidable overflow; see Numerical Recipes.
271190
if c.magnitude >= d.magnitude {
272191
let ratio = d / c
273192
let denominator = c + d * ratio
@@ -279,12 +198,10 @@ extension Complex {
279198
x = (a * ratio + b) / denominator
280199
y = (b * ratio - a) / denominator
281200
}
282-
// Recover infinities and zeros that computed as NaN + iNaN.
283-
// See C11 Annex G.
284201
if x.isNaN && y.isNaN {
285202
if c == 0 && d == 0 && (!a.isNaN || !b.isNaN) {
286203
x = T(signOf: c, magnitudeOf: .infinity) * a
287-
y = T(signOf: c /* sic */, magnitudeOf: .infinity) * b
204+
y = T(signOf: c, magnitudeOf: .infinity) * b
288205
} else if (a.isInfinite || b.isInfinite) && c.isFinite && d.isFinite {
289206
a = T(signOf: a, magnitudeOf: a.isInfinite ? 1 : 0)
290207
b = T(signOf: b, magnitudeOf: b.isInfinite ? 1 : 0)
@@ -313,7 +230,6 @@ extension Complex {
313230
}
314231
}
315232

316-
/// Returns the absolute value (magnitude, modulus) of `z`.
317233
@inlinable
318234
public func abs<T>(_ z: Complex<T>) -> Complex<T> {
319235
return Complex(real: z.magnitude)
@@ -353,7 +269,7 @@ extension Complex {
353269
}
354270
}
355271

356-
extension Complex where T : Differentiable/*, T.TangentVector == T*/ {
272+
extension Complex where T : Differentiable {
357273
@inlinable
358274
static func _vjpAdd(lhs: Complex, rhs: Complex)
359275
-> (Complex, (Complex) -> (Complex, Complex)) {

0 commit comments

Comments
 (0)