From dd0a6f75a5b792fab9458129e5db1d1b3e8750b3 Mon Sep 17 00:00:00 2001 From: Dan Zheng Date: Wed, 12 Jun 2019 04:36:00 +0000 Subject: [PATCH] Fix `VectorProtocol` tests. --- test/AutoDiff/refcounting.swift | 2 +- test/Sema/struct_key_path_iterable.swift | 8 ++++---- test/Sema/struct_vector_protocol.swift | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/test/AutoDiff/refcounting.swift b/test/AutoDiff/refcounting.swift index b0f40611a1d59..eea3d474bf60d 100644 --- a/test/AutoDiff/refcounting.swift +++ b/test/AutoDiff/refcounting.swift @@ -11,7 +11,7 @@ public struct Vector : AdditiveArithmetic, VectorProtocol, Differentiable, Equat public var y: Float public var nonTrivialStuff = NonTrivialStuff() public typealias TangentVector = Vector - public typealias Scalar = Float + public typealias VectorSpaceScalar = Float public static var zero: Vector { return Vector(0) } public init(_ scalar: Float) { self.x = scalar; self.y = scalar } diff --git a/test/Sema/struct_key_path_iterable.swift b/test/Sema/struct_key_path_iterable.swift index a212882bc6f3f..f2c6f2c407d60 100644 --- a/test/Sema/struct_key_path_iterable.swift +++ b/test/Sema/struct_key_path_iterable.swift @@ -44,8 +44,8 @@ extension TensorParameters : VectorProtocol { static func - (lhs: TensorParameters, rhs: TensorParameters) -> TensorParameters { return TensorParameters(w: lhs.w + rhs.w, b: lhs.b + rhs.b) } - typealias Scalar = Tensor - static func * (lhs: Scalar, rhs: TensorParameters) -> TensorParameters { + typealias VectorSpaceScalar = Tensor + static func * (lhs: VectorSpaceScalar, rhs: TensorParameters) -> TensorParameters { return TensorParameters(w: lhs + rhs.w, b: lhs + rhs.b) } } @@ -89,7 +89,7 @@ func pow(_ x: T, _ y: T) -> T { } struct AdamOptimizer

- where P : VectorProtocol, P.Scalar == Tensor + where P : VectorProtocol, P.VectorSpaceScalar == Tensor { let learningRate: Scalar var beta1: Scalar @@ -134,7 +134,7 @@ struct AdamOptimizer

func testOptimizer

( parameters: inout P, withGradients gradients: P ) - where P : VectorProtocol, P.Scalar == Tensor + where P : VectorProtocol, P.VectorSpaceScalar == Tensor { var optimizer = AdamOptimizer() print(parameters) diff --git a/test/Sema/struct_vector_protocol.swift b/test/Sema/struct_vector_protocol.swift index e3f830d7d9c31..00c010b405b0f 100644 --- a/test/Sema/struct_vector_protocol.swift +++ b/test/Sema/struct_vector_protocol.swift @@ -2,13 +2,13 @@ // RUN: %target-swift-frontend -typecheck -verify -primary-file %s %S/Inputs/struct_vector_protocol_other_module.swift func testVectorProtocol( -_ x: inout T, scalar: T.Scalar +_ x: inout T, scalar: T.VectorSpaceScalar ) { // Test `AdditiveArithmetic` requirements: `zero`, `+`, `-`. let zero = T.zero x += x + zero x -= x - zero - // Test `VectorProtocol` requirements: `Scalar`, `*`. + // Test `VectorProtocol` requirements: `VectorSpaceScalar`, `*`. x *= scalar _ = scalar * x _ = x * scalar @@ -32,7 +32,7 @@ func testVector2(float2: Float2) { _ = Vector2(x: 1, y: 1) _ = Vector2(x: float2, y: float2) } -func testGeneric(vec2: inout Vector2, scalar: T.Scalar) { +func testGeneric(vec2: inout Vector2, scalar: T.VectorSpaceScalar) { testVectorProtocol(&vec2, scalar: scalar) } @@ -90,7 +90,7 @@ extension GenericExtended : Equatable, AdditiveArithmetic, VectorProtocol where struct Empty : VectorProtocol {} // expected-error {{type 'Empty' does not conform to protocol 'VectorProtocol'}} // Test type whose members conform to `VectorProtocol` -// but have different `Scalar` associated type. +// but have different `VectorSpaceScalar` associated type. struct InvalidMixedScalar: VectorProtocol { // expected-error {{type 'InvalidMixedScalar' does not conform to protocol 'VectorProtocol'}} var float: Float var double: Double