Files
swift-mirror/test/AutoDiff/stdlib/differentiable_protocol.swift
Dan Zheng 6dd557a557 [AutoDiff] NFC: garden tests. (#30588)
Add test/AutoDiff/lit.local.cfg: run tests only when `differentiable_programming`
is enabled in lit. With this, individual tests no longer need
`REQUIRES: differentiable_programming`.

Move multi-functionality SIL tests from test/AutoDiff/SIL/Serialization to
test/AutoDiff/SIL.

Garden test filenames.
2020-03-23 15:22:27 -07:00

46 lines
1.2 KiB
Swift

// RUN: %target-typecheck-verify-swift
import _Differentiation
// Test `Differentiable` protocol conformances.
struct FloatWrapper {
var value: Float
}
extension FloatWrapper: AdditiveArithmetic {
static var zero: Self {
FloatWrapper(value: Float.zero)
}
static func + (lhs: Self, rhs: Self) -> Self {
return FloatWrapper(value: lhs.value + rhs.value)
}
static func - (lhs: Self, rhs: Self) -> Self {
return FloatWrapper(value: lhs.value + rhs.value)
}
}
extension FloatWrapper: Differentiable {
public typealias TangentVector = Self
}
struct Wrapper<T> {
var value: T
}
extension Wrapper: Equatable where T: Equatable {}
extension Wrapper: AdditiveArithmetic where T: AdditiveArithmetic {
static var zero: Self {
Wrapper(value: T.zero)
}
static func + (lhs: Self, rhs: Self) -> Self {
return Wrapper(value: lhs.value + rhs.value)
}
static func - (lhs: Self, rhs: Self) -> Self {
return Wrapper(value: lhs.value + rhs.value)
}
}
extension Wrapper: Differentiable where T: Differentiable {
typealias TangentVector = Wrapper<T.TangentVector>
mutating func move(along direction: TangentVector) {
value.move(along: direction.value)
}
}