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

Commit 01efbd9

Browse files
committed
Flip from inlinable to usableFromInline.
1 parent 683366d commit 01efbd9

File tree

1 file changed

+47
-40
lines changed

1 file changed

+47
-40
lines changed

Sources/TensorFlow/Core/Complex.swift

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

5+
@differentiable(where T : Differentiable)
56
public init(real: T = 0, imaginary: T = 0) {
6-
self.real = real
7-
self.imaginary = imaginary
7+
self.real = real
8+
self.imaginary = imaginary
89
}
910
}
1011

@@ -14,43 +15,43 @@ extension Complex : Differentiable where T : Differentiable {
1415
}
1516

1617
extension Complex {
17-
@inlinable
18+
1819
public static var i: Complex {
1920
return Complex(real: 0, imaginary: 1)
2021
}
2122

22-
@inlinable
23+
2324
public var isFinite: Bool {
2425
return real.isFinite && imaginary.isFinite
2526
}
2627

27-
@inlinable
28+
2829
public var isInfinite: Bool {
2930
return real.isInfinite || imaginary.isInfinite
3031
}
3132

32-
@inlinable
33+
3334
public var isNaN: Bool {
3435
return (real.isNaN && !imaginary.isInfinite) ||
3536
(imaginary.isNaN && !real.isInfinite)
3637
}
3738

38-
@inlinable
39+
3940
public var isZero: Bool {
4041
return real.isZero && imaginary.isZero
4142
}
4243
}
4344

4445
extension Complex : ExpressibleByIntegerLiteral {
45-
@inlinable
46+
4647
public init(integerLiteral value: Int) {
4748
self.real = T(value)
4849
self.imaginary = 0
4950
}
5051
}
5152

5253
extension Complex : CustomStringConvertible {
53-
@inlinable
54+
5455
public var description: String {
5556
return real.isNaN && real.sign == .minus
5657
? imaginary.sign == .minus
@@ -63,36 +64,36 @@ extension Complex : CustomStringConvertible {
6364
}
6465

6566
extension Complex : Equatable {
66-
@inlinable
67+
6768
public static func == (lhs: Complex, rhs: Complex) -> Bool {
6869
return lhs.real == rhs.real && lhs.imaginary == rhs.imaginary
6970
}
7071
}
7172

7273
extension Complex : AdditiveArithmetic {
73-
@inlinable
74+
7475
@differentiable(vjp: _vjpAdd(lhs:rhs:) where T : Differentiable)
7576
public static func + (lhs: Complex, rhs: Complex) -> Complex {
7677
var lhs = lhs
7778
lhs += rhs
7879
return lhs
7980
}
8081

81-
@inlinable
82+
8283
public static func += (lhs: inout Complex, rhs: Complex) {
8384
lhs.real += rhs.real
8485
lhs.imaginary += rhs.imaginary
8586
}
8687

87-
@inlinable
88+
8889
@differentiable(vjp: _vjpSubtract(lhs:rhs:) where T : Differentiable)
8990
public static func - (lhs: Complex, rhs: Complex) -> Complex {
9091
var lhs = lhs
9192
lhs -= rhs
9293
return lhs
9394
}
9495

95-
@inlinable
96+
9697
public static func -= (lhs: inout Complex, rhs: Complex) {
9798
lhs.real -= rhs.real
9899
lhs.imaginary -= rhs.imaginary
@@ -106,7 +107,7 @@ extension Complex : Numeric {
106107
self.imaginary = 0
107108
}
108109

109-
@inlinable
110+
110111
@differentiable(vjp: _vjpMultiply(lhs:rhs:) where T : Differentiable)
111112
public static func * (lhs: Complex, rhs: Complex) -> Complex {
112113
var a = lhs.real, b = lhs.imaginary, c = rhs.real, d = rhs.imaginary
@@ -148,12 +149,12 @@ extension Complex : Numeric {
148149
return Complex(real: x, imaginary: y)
149150
}
150151

151-
@inlinable
152+
152153
public static func *= (lhs: inout Complex, rhs: Complex) {
153154
lhs = lhs * rhs
154155
}
155156

156-
@inlinable
157+
157158
public var magnitude: T {
158159
var x = abs(real)
159160
var y = abs(imaginary)
@@ -167,21 +168,21 @@ extension Complex : Numeric {
167168
}
168169

169170
extension Complex : SignedNumeric {
170-
@inlinable
171+
171172
@differentiable(vjp: _vjpNegate where T : Differentiable)
172173
public static prefix func - (operand: Complex) -> Complex {
173174
return Complex(real: -operand.real, imaginary: -operand.imaginary)
174175
}
175176

176-
@inlinable
177+
177178
public mutating func negate() {
178179
real.negate()
179180
imaginary.negate()
180181
}
181182
}
182183

183184
extension Complex {
184-
@inlinable
185+
185186
@differentiable(vjp: _vjpDivide(lhs:rhs:) where T : Differentiable)
186187
public static func / (lhs: Complex, rhs: Complex) -> Complex {
187188
var a = lhs.real, b = lhs.imaginary, c = rhs.real, d = rhs.imaginary
@@ -217,50 +218,51 @@ extension Complex {
217218
return Complex(real: x, imaginary: y)
218219
}
219220

220-
@inlinable
221+
221222
public static func /= (lhs: inout Complex, rhs: Complex) {
222223
lhs = lhs / rhs
223224
}
224225
}
225226

226227
extension Complex {
227-
@inlinable
228+
229+
@differentiable(vjp: _vjpComplexConjugate where T : Differentiable)
228230
public func complexConjugate() -> Complex {
229231
return Complex(real: real, imaginary: -imaginary)
230232
}
231233
}
232234

233-
@inlinable
235+
234236
public func abs<T>(_ z: Complex<T>) -> Complex<T> {
235237
return Complex(real: z.magnitude)
236238
}
237239

238240
extension Complex {
239-
@inlinable
241+
240242
@differentiable(vjp: _vjpAdding(real:) where T : Differentiable, T.TangentVector == T)
241243
public func adding(real: T) -> Complex {
242244
var c = self
243245
c.real += real
244246
return c
245247
}
246248

247-
@inlinable
249+
248250
@differentiable(vjp: _vjpSubtracting(real:) where T : Differentiable, T.TangentVector == T)
249251
public func subtracting(real: T) -> Complex {
250252
var c = self
251253
c.real -= real
252254
return c
253255
}
254256

255-
@inlinable
257+
256258
@differentiable(vjp: _vjpAdding(imaginary:) where T : Differentiable, T.TangentVector == T)
257259
public func adding(imaginary: T) -> Complex {
258260
var c = self
259261
c.imaginary += imaginary
260262
return c
261263
}
262264

263-
@inlinable
265+
264266
@differentiable(vjp: _vjpSubtracting(imaginary:) where T : Differentiable, T.TangentVector == T)
265267
public func subtracting(imaginary: T) -> Complex {
266268
var c = self
@@ -270,54 +272,59 @@ extension Complex {
270272
}
271273

272274
extension Complex where T : Differentiable {
273-
@inlinable
275+
@usableFromInline
274276
static func _vjpAdd(lhs: Complex, rhs: Complex)
275277
-> (Complex, (Complex) -> (Complex, Complex)) {
276-
return (lhs * rhs, { v in (v, v) })
278+
return (lhs + rhs, { v in (v, v) })
277279
}
278280

279-
@inlinable
281+
@usableFromInline
280282
static func _vjpSubtract(lhs: Complex, rhs: Complex)
281283
-> (Complex, (Complex) -> (Complex, Complex)) {
282-
return (lhs * rhs, { v in (v, -v) })
284+
return (lhs - rhs, { v in (v, -v) })
283285
}
284286

285-
@inlinable
287+
@usableFromInline
286288
static func _vjpMultiply(lhs: Complex, rhs: Complex)
287289
-> (Complex, (Complex) -> (Complex, Complex)) {
288290
return (lhs * rhs, { v in (rhs * v, lhs * v) })
289291
}
290292

291-
@inlinable
293+
@usableFromInline
292294
static func _vjpDivide(lhs: Complex, rhs: Complex)
293295
-> (Complex, (Complex) -> (Complex, Complex)) {
294-
return (lhs * rhs, { v in (v / rhs, -lhs / (rhs * rhs) * v) })
296+
return (lhs / rhs, { v in (v / rhs, -lhs / (rhs * rhs) * v) })
295297
}
296298

297-
@inlinable
299+
@usableFromInline
298300
static func _vjpNegate(operand: Complex)
299301
-> (Complex, (Complex) -> Complex) {
300-
return (-operand, { v in -v})
302+
return (-operand, { -$0 })
303+
}
304+
305+
@usableFromInline
306+
func _vjpComplexConjugate() -> (Complex, (Complex) -> Complex) {
307+
return (complexConjugate(), { v in v.complexConjugate() })
301308
}
302309
}
303310

304311
extension Complex where T : Differentiable, T.TangentVector == T {
305-
@inlinable
312+
@usableFromInline
306313
func _vjpAdding(real: T) -> (Complex, (Complex) -> (Complex, T)) {
307314
return (self.adding(real: real), { ($0, $0.real) })
308315
}
309316

310-
@inlinable
317+
@usableFromInline
311318
func _vjpSubtracting(real: T) -> (Complex, (Complex) -> (Complex, T)) {
312319
return (self.subtracting(real: real), { ($0, -$0.real) })
313320
}
314321

315-
@inlinable
322+
@usableFromInline
316323
func _vjpAdding(imaginary: T) -> (Complex, (Complex) -> (Complex, T)) {
317324
return (self.adding(real: real), { ($0, $0.imaginary) })
318325
}
319326

320-
@inlinable
327+
@usableFromInline
321328
func _vjpSubtracting(imaginary: T) -> (Complex, (Complex) -> (Complex, T)) {
322329
return (self.subtracting(real: real), { ($0, -$0.imaginary) })
323330
}

0 commit comments

Comments
 (0)