@@ -111,85 +111,85 @@ where Element: Differentiable & ElementaryFunctions {
111
111
///
112
112
/// For real types, if `x` is negative the result is `.nan`. For complex
113
113
/// types there is a branch cut on the negative real axis.
114
- public static func sqrt( _ x: Self ) -> Self { . init ( Array . sqrt ( x. base) ) }
114
+ public static func sqrt( _ x: Self ) -> Self { Self ( Array . sqrt ( x. base) ) }
115
115
116
116
/// The cosine of `x`, interpreted as an angle in radians.
117
- public static func cos( _ x: Self ) -> Self { . init ( Array . cos ( x. base) ) }
117
+ public static func cos( _ x: Self ) -> Self { Self ( Array . cos ( x. base) ) }
118
118
119
119
/// The sine of `x`, interpreted as an angle in radians.
120
- public static func sin( _ x: Self ) -> Self { . init ( Array . sin ( x. base) ) }
120
+ public static func sin( _ x: Self ) -> Self { Self ( Array . sin ( x. base) ) }
121
121
122
122
/// The tangent of `x`, interpreted as an angle in radians.
123
- public static func tan( _ x: Self ) -> Self { . init ( Array . tan ( x. base) ) }
123
+ public static func tan( _ x: Self ) -> Self { Self ( Array . tan ( x. base) ) }
124
124
125
125
/// The inverse cosine of `x` in radians.
126
- public static func acos( _ x: Self ) -> Self { . init ( Array . acos ( x. base) ) }
126
+ public static func acos( _ x: Self ) -> Self { Self ( Array . acos ( x. base) ) }
127
127
128
128
/// The inverse sine of `x` in radians.
129
- public static func asin( _ x: Self ) -> Self { . init ( Array . asin ( x. base) ) }
129
+ public static func asin( _ x: Self ) -> Self { Self ( Array . asin ( x. base) ) }
130
130
131
131
/// The inverse tangent of `x` in radians.
132
- public static func atan( _ x: Self ) -> Self { . init ( Array . atan ( x. base) ) }
132
+ public static func atan( _ x: Self ) -> Self { Self ( Array . atan ( x. base) ) }
133
133
134
134
/// The hyperbolic cosine of `x`.
135
- public static func cosh( _ x: Self ) -> Self { . init ( Array . cosh ( x. base) ) }
135
+ public static func cosh( _ x: Self ) -> Self { Self ( Array . cosh ( x. base) ) }
136
136
137
137
/// The hyperbolic sine of `x`.
138
- public static func sinh( _ x: Self ) -> Self { . init ( Array . sinh ( x. base) ) }
138
+ public static func sinh( _ x: Self ) -> Self { Self ( Array . sinh ( x. base) ) }
139
139
140
140
/// The hyperbolic tangent of `x`.
141
- public static func tanh( _ x: Self ) -> Self { . init ( Array . tanh ( x. base) ) }
141
+ public static func tanh( _ x: Self ) -> Self { Self ( Array . tanh ( x. base) ) }
142
142
143
143
/// The inverse hyperbolic cosine of `x`.
144
- public static func acosh( _ x: Self ) -> Self { . init ( Array . acosh ( x. base) ) }
144
+ public static func acosh( _ x: Self ) -> Self { Self ( Array . acosh ( x. base) ) }
145
145
146
146
/// The inverse hyperbolic sine of `x`.
147
- public static func asinh( _ x: Self ) -> Self { . init ( Array . asinh ( x. base) ) }
147
+ public static func asinh( _ x: Self ) -> Self { Self ( Array . asinh ( x. base) ) }
148
148
149
149
/// The inverse hyperbolic tangent of `x`.
150
- public static func atanh( _ x: Self ) -> Self { . init ( Array . atanh ( x. base) ) }
150
+ public static func atanh( _ x: Self ) -> Self { Self ( Array . atanh ( x. base) ) }
151
151
152
152
/// The exponential function applied to `x`, or `e**x`.
153
- public static func exp( _ x: Self ) -> Self { . init ( Array . exp ( x. base) ) }
153
+ public static func exp( _ x: Self ) -> Self { Self ( Array . exp ( x. base) ) }
154
154
155
155
/// Two raised to to power `x`.
156
- public static func exp2( _ x: Self ) -> Self { . init ( Array . exp2 ( x. base) ) }
156
+ public static func exp2( _ x: Self ) -> Self { Self ( Array . exp2 ( x. base) ) }
157
157
158
158
/// Ten raised to to power `x`.
159
- public static func exp10( _ x: Self ) -> Self { . init ( Array . exp10 ( x. base) ) }
159
+ public static func exp10( _ x: Self ) -> Self { Self ( Array . exp10 ( x. base) ) }
160
160
161
161
/// `exp(x) - 1` evaluated so as to preserve accuracy close to zero.
162
- public static func expm1( _ x: Self ) -> Self { . init ( Array . expm1 ( x. base) ) }
162
+ public static func expm1( _ x: Self ) -> Self { Self ( Array . expm1 ( x. base) ) }
163
163
164
164
/// The natural logarithm of `x`.
165
- public static func log( _ x: Self ) -> Self { . init ( Array . log ( x. base) ) }
165
+ public static func log( _ x: Self ) -> Self { Self ( Array . log ( x. base) ) }
166
166
167
167
/// The base-two logarithm of `x`.
168
- public static func log2( _ x: Self ) -> Self { . init ( Array . log2 ( x. base) ) }
168
+ public static func log2( _ x: Self ) -> Self { Self ( Array . log2 ( x. base) ) }
169
169
170
170
/// The base-ten logarithm of `x`.
171
- public static func log10( _ x: Self ) -> Self { . init ( Array . log10 ( x. base) ) }
171
+ public static func log10( _ x: Self ) -> Self { Self ( Array . log10 ( x. base) ) }
172
172
173
173
/// `log(1 + x)` evaluated so as to preserve accuracy close to zero.
174
- public static func log1p( _ x: Self ) -> Self { . init ( Array . log1p ( x. base) ) }
174
+ public static func log1p( _ x: Self ) -> Self { Self ( Array . log1p ( x. base) ) }
175
175
176
176
/// `exp(y log(x))` computed without loss of intermediate precision.
177
177
///
178
178
/// For real types, if `x` is negative the result is NaN, even if `y` has
179
179
/// an integral value. For complex types, there is a branch cut on the
180
180
/// negative real axis.
181
- public static func pow( _ x: Self , _ y: Self ) -> Self { . init ( Array . pow ( x. base, y. base) ) }
181
+ public static func pow( _ x: Self , _ y: Self ) -> Self { Self ( Array . pow ( x. base, y. base) ) }
182
182
183
183
/// `x` raised to the `n`th power.
184
184
///
185
185
/// The product of `n` copies of `x`.
186
- public static func pow( _ x: Self , _ n: Int ) -> Self { . init ( Array . pow ( x. base, n) ) }
186
+ public static func pow( _ x: Self , _ n: Int ) -> Self { Self ( Array . pow ( x. base, n) ) }
187
187
188
188
/// The `n`th root of `x`.
189
189
///
190
190
/// For real types, if `x` is negative and `n` is even, the result is NaN.
191
191
/// For complex types, there is a branch cut along the negative real axis.
192
- public static func root( _ x: Self , _ n: Int ) -> Self { . init ( Array . root ( x. base, n) ) }
192
+ public static func root( _ x: Self , _ n: Int ) -> Self { Self ( Array . root ( x. base, n) ) }
193
193
}
194
194
195
195
extension Array . DifferentiableView :
@@ -226,7 +226,7 @@ where Element: Differentiable & VectorProtocol {
226
226
public typealias VectorSpaceScalar = Element . VectorSpaceScalar
227
227
228
228
public func adding( _ x: Element . VectorSpaceScalar ) -> Array < Element > . DifferentiableView {
229
- . init ( map { $0. adding ( x) } )
229
+ Self ( map { $0. adding ( x) } )
230
230
}
231
231
232
232
public mutating func add( _ x: Element . VectorSpaceScalar ) {
@@ -236,7 +236,7 @@ where Element: Differentiable & VectorProtocol {
236
236
}
237
237
238
238
public func subtracting( _ x: Element . VectorSpaceScalar ) -> Array < Element > . DifferentiableView {
239
- . init ( map { $0. subtracting ( x) } )
239
+ Self ( map { $0. subtracting ( x) } )
240
240
}
241
241
242
242
public mutating func subtract( _ x: Element . VectorSpaceScalar ) {
@@ -246,7 +246,7 @@ where Element: Differentiable & VectorProtocol {
246
246
}
247
247
248
248
public func scaled( by scale: Element . VectorSpaceScalar ) -> Self {
249
- . init ( map { $0. scaled ( by: scale) } )
249
+ Self ( map { $0. scaled ( by: scale) } )
250
250
}
251
251
252
252
public mutating func scale( by scale: Element . VectorSpaceScalar ) {
@@ -263,11 +263,11 @@ where Element: Differentiable & PointwiseMultiplicative {
263
263
fatalError ( " One is not array-representable " )
264
264
}
265
265
266
- public var reciprocal : Self { . init ( map { $0. reciprocal } ) }
266
+ public var reciprocal : Self { Self ( map { $0. reciprocal } ) }
267
267
268
268
public static func .* ( lhs: Self , rhs: Self ) -> Self {
269
269
precondition ( lhs. count == rhs. count, " Count mismatch: \( lhs. count) and \( rhs. count) " )
270
- return . init ( zip ( lhs, rhs) . map ( .* ) )
270
+ return Self ( zip ( lhs, rhs) . map ( .* ) )
271
271
}
272
272
273
273
public static func .*= ( lhs: inout Self , rhs: Self ) {
@@ -294,94 +294,103 @@ where Wrapped.TangentVector: ElementaryFunctions {
294
294
///
295
295
/// For real types, if `x` is negative the result is `.nan`. For complex
296
296
/// types there is a branch cut on the negative real axis.
297
- public static func sqrt( _ x: Self ) -> Self { . init ( x. value. map ( Wrapped . TangentVector. sqrt) ) }
297
+ public static func sqrt( _ x: Self ) -> Self { Self ( x. value. map ( Wrapped . TangentVector. sqrt) ) }
298
298
299
299
/// The cosine of `x`, interpreted as an angle in radians.
300
- public static func cos( _ x: Self ) -> Self { . init ( x. value. map ( Wrapped . TangentVector. sqrt ) ) }
300
+ public static func cos( _ x: Self ) -> Self { Self ( x. value. map ( Wrapped . TangentVector. cos ) ) }
301
301
302
302
/// The sine of `x`, interpreted as an angle in radians.
303
- public static func sin( _ x: Self ) -> Self { . init ( x. value. map ( Wrapped . TangentVector. sqrt ) ) }
303
+ public static func sin( _ x: Self ) -> Self { Self ( x. value. map ( Wrapped . TangentVector. sin ) ) }
304
304
305
305
/// The tangent of `x`, interpreted as an angle in radians.
306
- public static func tan( _ x: Self ) -> Self { . init ( x. value. map ( Wrapped . TangentVector. sqrt ) ) }
306
+ public static func tan( _ x: Self ) -> Self { Self ( x. value. map ( Wrapped . TangentVector. tan ) ) }
307
307
308
308
/// The inverse cosine of `x` in radians.
309
- public static func acos( _ x: Self ) -> Self { . init ( x. value. map ( Wrapped . TangentVector. sqrt ) ) }
309
+ public static func acos( _ x: Self ) -> Self { Self ( x. value. map ( Wrapped . TangentVector. acos ) ) }
310
310
311
311
/// The inverse sine of `x` in radians.
312
- public static func asin( _ x: Self ) -> Self { . init ( x. value. map ( Wrapped . TangentVector. sqrt ) ) }
312
+ public static func asin( _ x: Self ) -> Self { Self ( x. value. map ( Wrapped . TangentVector. asin ) ) }
313
313
314
314
/// The inverse tangent of `x` in radians.
315
- public static func atan( _ x: Self ) -> Self { . init ( x. value. map ( Wrapped . TangentVector. sqrt ) ) }
315
+ public static func atan( _ x: Self ) -> Self { Self ( x. value. map ( Wrapped . TangentVector. atan ) ) }
316
316
317
317
/// The hyperbolic cosine of `x`.
318
- public static func cosh( _ x: Self ) -> Self { . init ( x. value. map ( Wrapped . TangentVector. sqrt ) ) }
318
+ public static func cosh( _ x: Self ) -> Self { Self ( x. value. map ( Wrapped . TangentVector. cosh ) ) }
319
319
320
320
/// The hyperbolic sine of `x`.
321
- public static func sinh( _ x: Self ) -> Self { . init ( x. value. map ( Wrapped . TangentVector. sqrt ) ) }
321
+ public static func sinh( _ x: Self ) -> Self { Self ( x. value. map ( Wrapped . TangentVector. sinh ) ) }
322
322
323
323
/// The hyperbolic tangent of `x`.
324
- public static func tanh( _ x: Self ) -> Self { . init ( x. value. map ( Wrapped . TangentVector. sqrt ) ) }
324
+ public static func tanh( _ x: Self ) -> Self { Self ( x. value. map ( Wrapped . TangentVector. tanh ) ) }
325
325
326
326
/// The inverse hyperbolic cosine of `x`.
327
- public static func acosh( _ x: Self ) -> Self { . init ( x. value. map ( Wrapped . TangentVector. sqrt ) ) }
327
+ public static func acosh( _ x: Self ) -> Self { Self ( x. value. map ( Wrapped . TangentVector. acosh ) ) }
328
328
329
329
/// The inverse hyperbolic sine of `x`.
330
- public static func asinh( _ x: Self ) -> Self { . init ( x. value. map ( Wrapped . TangentVector. sqrt ) ) }
330
+ public static func asinh( _ x: Self ) -> Self { Self ( x. value. map ( Wrapped . TangentVector. asinh ) ) }
331
331
332
332
/// The inverse hyperbolic tangent of `x`.
333
- public static func atanh( _ x: Self ) -> Self { . init ( x. value. map ( Wrapped . TangentVector. sqrt ) ) }
333
+ public static func atanh( _ x: Self ) -> Self { Self ( x. value. map ( Wrapped . TangentVector. atanh ) ) }
334
334
335
335
/// The exponential function applied to `x`, or `e**x`.
336
- public static func exp( _ x: Self ) -> Self { . init ( x. value. map ( Wrapped . TangentVector. sqrt ) ) }
336
+ public static func exp( _ x: Self ) -> Self { Self ( x. value. map ( Wrapped . TangentVector. exp ) ) }
337
337
338
338
/// Two raised to to power `x`.
339
- public static func exp2( _ x: Self ) -> Self { . init ( x. value. map ( Wrapped . TangentVector. sqrt ) ) }
339
+ public static func exp2( _ x: Self ) -> Self { Self ( x. value. map ( Wrapped . TangentVector. exp2 ) ) }
340
340
341
341
/// Ten raised to to power `x`.
342
- public static func exp10( _ x: Self ) -> Self { . init ( x. value. map ( Wrapped . TangentVector. sqrt ) ) }
342
+ public static func exp10( _ x: Self ) -> Self { Self ( x. value. map ( Wrapped . TangentVector. exp10 ) ) }
343
343
344
344
/// `exp(x) - 1` evaluated so as to preserve accuracy close to zero.
345
- public static func expm1( _ x: Self ) -> Self { . init ( x. value. map ( Wrapped . TangentVector. sqrt ) ) }
345
+ public static func expm1( _ x: Self ) -> Self { Self ( x. value. map ( Wrapped . TangentVector. expm1 ) ) }
346
346
347
347
/// The natural logarithm of `x`.
348
- public static func log( _ x: Self ) -> Self { . init ( x. value. map ( Wrapped . TangentVector. sqrt ) ) }
348
+ public static func log( _ x: Self ) -> Self { Self ( x. value. map ( Wrapped . TangentVector. log ) ) }
349
349
350
350
/// The base-two logarithm of `x`.
351
- public static func log2( _ x: Self ) -> Self { . init ( x. value. map ( Wrapped . TangentVector. sqrt ) ) }
351
+ public static func log2( _ x: Self ) -> Self { Self ( x. value. map ( Wrapped . TangentVector. log2 ) ) }
352
352
353
353
/// The base-ten logarithm of `x`.
354
- public static func log10( _ x: Self ) -> Self { . init ( x. value. map ( Wrapped . TangentVector. sqrt ) ) }
354
+ public static func log10( _ x: Self ) -> Self { Self ( x. value. map ( Wrapped . TangentVector. log10 ) ) }
355
355
356
356
/// `log(1 + x)` evaluated so as to preserve accuracy close to zero.
357
- public static func log1p( _ x: Self ) -> Self { . init ( x. value. map ( Wrapped . TangentVector. sqrt ) ) }
357
+ public static func log1p( _ x: Self ) -> Self { Self ( x. value. map ( Wrapped . TangentVector. log1p ) ) }
358
358
359
359
/// `exp(y log(x))` computed without loss of intermediate precision.
360
360
///
361
361
/// For real types, if `x` is negative the result is NaN, even if `y` has
362
362
/// an integral value. For complex types, there is a branch cut on the
363
363
/// negative real axis.
364
- public static func pow( _ x: Self , _ y: Self ) -> Self { . init( x. value. map ( Wrapped . TangentVector. sqrt) ) }
364
+ public static func pow( _ x: Self , _ y: Self ) -> Self {
365
+ switch ( x. value, y. value) {
366
+ case let ( x? , y? ) : return Self ( Wrapped . TangentVector. pow ( x, y) )
367
+ default : return Self ( nil )
368
+ }
369
+ }
365
370
366
371
/// `x` raised to the `n`th power.
367
372
///
368
373
/// The product of `n` copies of `x`.
369
- public static func pow( _ x: Self , _ n: Int ) -> Self { . init( x. value. map ( { x in Wrapped . TangentVector. pow ( x, n) } ) ) }
374
+ public static func pow( _ x: Self , _ n: Int ) -> Self {
375
+ Self ( x. value. map ( { x in Wrapped . TangentVector. pow ( x, n) } ) )
376
+ }
370
377
371
378
/// The `n`th root of `x`.
372
379
///
373
380
/// For real types, if `x` is negative and `n` is even, the result is NaN.
374
381
/// For complex types, there is a branch cut along the negative real axis.
375
- public static func root( _ x: Self , _ n: Int ) -> Self { . init( x. value. map ( { x in Wrapped . TangentVector. root ( x, n) } ) ) }
382
+ public static func root( _ x: Self , _ n: Int ) -> Self {
383
+ Self ( x. value. map ( { x in Wrapped . TangentVector. root ( x, n) } ) )
384
+ }
376
385
}
377
386
378
387
extension Optional . TangentVector : PointwiseMultiplicative
379
388
where Wrapped. TangentVector: PointwiseMultiplicative {
380
389
public static var one : Self {
381
- . init ( Wrapped . TangentVector. one)
390
+ Self ( Wrapped . TangentVector. one)
382
391
}
383
392
384
- public var reciprocal : Self { . init ( value. map { $0. reciprocal } ) }
393
+ public var reciprocal : Self { Self ( value. map { $0. reciprocal } ) }
385
394
386
395
public static func .* ( lhs: Self , rhs: Self ) -> Self {
387
396
switch ( lhs. value, rhs. value) {
@@ -399,15 +408,17 @@ extension Optional.TangentVector: VectorProtocol
399
408
where Wrapped. TangentVector: VectorProtocol {
400
409
public typealias VectorSpaceScalar = Wrapped . TangentVector . VectorSpaceScalar
401
410
402
- public func adding( _ x: VectorSpaceScalar ) -> Self { . init ( value. map { $0. adding ( x) } ) }
411
+ public func adding( _ x: VectorSpaceScalar ) -> Self { Self ( value. map { $0. adding ( x) } ) }
403
412
404
413
public mutating func add( _ x: VectorSpaceScalar ) { value? . add ( x) }
405
414
406
- public func subtracting( _ x: VectorSpaceScalar ) -> Self { . init ( value. map { $0. subtracting ( x) } ) }
415
+ public func subtracting( _ x: VectorSpaceScalar ) -> Self { Self ( value. map { $0. subtracting ( x) } ) }
407
416
408
417
public mutating func subtract( _ x: VectorSpaceScalar ) { value? . subtract ( x) }
409
418
410
- public func scaled( by scale: VectorSpaceScalar ) -> Self { . init( value. map { $0. scaled ( by: scale) } ) }
419
+ public func scaled( by scale: VectorSpaceScalar ) -> Self {
420
+ Self ( value. map { $0. scaled ( by: scale) } )
421
+ }
411
422
412
423
public mutating func scale( by scale: VectorSpaceScalar ) {
413
424
value? . scale ( by: scale)
0 commit comments