diff --git a/.swiftlint.yml b/.swiftlint.yml new file mode 100644 index 00000000..4867335c --- /dev/null +++ b/.swiftlint.yml @@ -0,0 +1,7 @@ +disabled_rules: + - file_length + - for_where + - force_cast + - identifier_name + - large_tuple + - line_length diff --git a/Package.swift b/Package.swift index a2d259a0..54a19e7c 100644 --- a/Package.swift +++ b/Package.swift @@ -3,4 +3,3 @@ import PackageDescription let package = Package( name: "Upsurge" ) - diff --git a/Source/2DTensorSlice.swift b/Source/2DTensorSlice.swift index 818763a7..8ef7de40 100644 --- a/Source/2DTensorSlice.swift +++ b/Source/2DTensorSlice.swift @@ -21,7 +21,7 @@ open class TwoDimensionalTensorSlice: MutableQuadraticType, Equatable { public typealias Index = [Int] public typealias Slice = TwoDimensionalTensorSlice - + open var arrangement: QuadraticArrangement { return .rowMajor } diff --git a/Source/Complex.swift b/Source/Complex.swift index 0cac1cd1..ce31b823 100644 --- a/Source/Complex.swift +++ b/Source/Complex.swift @@ -78,76 +78,76 @@ public func <(lhs: Complex, rhs: Complex) -> Bool { // MARK: - Double -public func +(lhs: Complex, rhs: Complex) -> Complex { +public func + (lhs: Complex, rhs: Complex) -> Complex { return Complex(real: lhs.real + rhs.real, imag: lhs.imag + rhs.imag) } -public func -(lhs: Complex, rhs: Complex) -> Complex { +public func - (lhs: Complex, rhs: Complex) -> Complex { return Complex(real: lhs.real - rhs.real, imag: lhs.imag - rhs.imag) } -public func *(lhs: Complex, rhs: Complex) -> Complex { +public func * (lhs: Complex, rhs: Complex) -> Complex { return Complex(real: lhs.real * rhs.real - lhs.imag * rhs.imag, imag: lhs.real * rhs.imag + lhs.imag * rhs.real) } -public func *(x: Complex, a: Double) -> Complex { +public func * (x: Complex, a: Double) -> Complex { return Complex(real: x.real * a, imag: x.imag * a) } -public func *(a: Double, x: Complex) -> Complex { +public func * (a: Double, x: Complex) -> Complex { return Complex(real: x.real * a, imag: x.imag * a) } -public func /(lhs: Complex, rhs: Complex) -> Complex { +public func / (lhs: Complex, rhs: Complex) -> Complex { let rhsMagSq = rhs.real*rhs.real + rhs.imag*rhs.imag return Complex( real: (lhs.real*rhs.real + lhs.imag*rhs.imag) / rhsMagSq, imag: (lhs.imag*rhs.real - lhs.real*rhs.imag) / rhsMagSq) } -public func /(x: Complex, a: Double) -> Complex { +public func / (x: Complex, a: Double) -> Complex { return Complex(real: x.real / a, imag: x.imag / a) } -public func /(a: Double, x: Complex) -> Complex { +public func / (a: Double, x: Complex) -> Complex { let xMagSq = x.real*x.real + x.imag*x.imag return Complex(real: a*x.real / xMagSq, imag: -a*x.imag / xMagSq) } // MARK: - Float -public func +(lhs: Complex, rhs: Complex) -> Complex { +public func + (lhs: Complex, rhs: Complex) -> Complex { return Complex(real: lhs.real + rhs.real, imag: lhs.imag + rhs.imag) } -public func -(lhs: Complex, rhs: Complex) -> Complex { +public func - (lhs: Complex, rhs: Complex) -> Complex { return Complex(real: lhs.real - rhs.real, imag: lhs.imag - rhs.imag) } -public func *(lhs: Complex, rhs: Complex) -> Complex { +public func * (lhs: Complex, rhs: Complex) -> Complex { return Complex(real: lhs.real * rhs.real - lhs.imag * rhs.imag, imag: lhs.real * rhs.imag + lhs.imag * rhs.real) } -public func *(x: Complex, a: Float) -> Complex { +public func * (x: Complex, a: Float) -> Complex { return Complex(real: x.real * a, imag: x.imag * a) } -public func *(a: Float, x: Complex) -> Complex { +public func * (a: Float, x: Complex) -> Complex { return Complex(real: x.real * a, imag: x.imag * a) } -public func /(lhs: Complex, rhs: Complex) -> Complex { +public func / (lhs: Complex, rhs: Complex) -> Complex { let rhsMagSq = rhs.real*rhs.real + rhs.imag*rhs.imag return Complex( real: (lhs.real*rhs.real + lhs.imag*rhs.imag) / rhsMagSq, imag: (lhs.imag*rhs.real - lhs.real*rhs.imag) / rhsMagSq) } -public func /(x: Complex, a: Float) -> Complex { +public func / (x: Complex, a: Float) -> Complex { return Complex(real: x.real / a, imag: x.imag / a) } -public func /(a: Float, x: Complex) -> Complex { +public func / (a: Float, x: Complex) -> Complex { let xMagSq = x.real*x.real + x.imag*x.imag return Complex(real: a*x.real / xMagSq, imag: -a*x.imag / xMagSq) } diff --git a/Source/ComplexArithmetic.swift b/Source/ComplexArithmetic.swift index 295995e2..42ab58d4 100644 --- a/Source/ComplexArithmetic.swift +++ b/Source/ComplexArithmetic.swift @@ -26,79 +26,79 @@ public func sum(_ x: ComplexArray) -> Complex { // MARK: Operators -public func +=(lhs: inout ComplexArray, rhs: ComplexArray) { +public func += (lhs: inout ComplexArray, rhs: ComplexArray) { lhs.reals += rhs.reals lhs.imags += rhs.imags } -public func +(lhs: ComplexArray, rhs: ComplexArray) -> ComplexArray { +public func + (lhs: ComplexArray, rhs: ComplexArray) -> ComplexArray { var results = ComplexArray(lhs) results += rhs return results } -public func -=(lhs: inout ComplexArray, rhs: ComplexArray) { +public func -= (lhs: inout ComplexArray, rhs: ComplexArray) { lhs.reals -= rhs.reals lhs.imags -= rhs.imags } -public func -(lhs: ComplexArray, rhs: ComplexArray) -> ComplexArray { +public func - (lhs: ComplexArray, rhs: ComplexArray) -> ComplexArray { var results = ComplexArray(lhs) results -= rhs return results } -public func +=(lhs: inout ComplexArray, rhs: Complex) { +public func += (lhs: inout ComplexArray, rhs: Complex) { lhs.reals += rhs.real lhs.imags += rhs.imag } -public func +(lhs: ComplexArray, rhs: Complex) -> ComplexArray { +public func + (lhs: ComplexArray, rhs: Complex) -> ComplexArray { var results = ComplexArray(lhs) results += rhs return results } -public func +(lhs: Complex, rhs: ComplexArray) -> ComplexArray { +public func + (lhs: Complex, rhs: ComplexArray) -> ComplexArray { var results = ComplexArray(rhs) results += lhs return results } -public func -=(lhs: inout ComplexArray, rhs: Complex) { +public func -= (lhs: inout ComplexArray, rhs: Complex) { lhs.reals -= rhs.real lhs.imags -= rhs.imag } -public func -(lhs: ComplexArray, rhs: Complex) -> ComplexArray { +public func - (lhs: ComplexArray, rhs: Complex) -> ComplexArray { var results = ComplexArray(lhs) results -= rhs return results } -public func -(lhs: Complex, rhs: ComplexArray) -> ComplexArray { +public func - (lhs: Complex, rhs: ComplexArray) -> ComplexArray { var results = ComplexArray(rhs) results -= lhs return results } -public func *=(lhs: inout ComplexArray, rhs: Double) { +public func *= (lhs: inout ComplexArray, rhs: Double) { lhs.reals *= rhs lhs.imags *= rhs } -public func *(lhs: ComplexArray, rhs: Double) -> ComplexArray { +public func * (lhs: ComplexArray, rhs: Double) -> ComplexArray { var results = ComplexArray(lhs) results *= rhs return results } -public func /=(lhs: inout ComplexArray, rhs: Double) { +public func /= (lhs: inout ComplexArray, rhs: Double) { lhs.reals /= rhs lhs.imags /= rhs } -public func /(lhs: ComplexArray, rhs: Double) -> ComplexArray { +public func / (lhs: ComplexArray, rhs: Double) -> ComplexArray { var results = ComplexArray(lhs) results /= rhs return results @@ -112,79 +112,79 @@ public func sum(_ x: ComplexArray) -> Complex { // MARK: Operators -public func +=(lhs: inout ComplexArray, rhs: ComplexArray) { +public func += (lhs: inout ComplexArray, rhs: ComplexArray) { lhs.reals += rhs.reals lhs.imags += rhs.imags } -public func +(lhs: ComplexArray, rhs: ComplexArray) -> ComplexArray { +public func + (lhs: ComplexArray, rhs: ComplexArray) -> ComplexArray { var results = ComplexArray(lhs) results += rhs return results } -public func -=(lhs: inout ComplexArray, rhs: ComplexArray) { +public func -= (lhs: inout ComplexArray, rhs: ComplexArray) { lhs.reals -= rhs.reals lhs.imags -= rhs.imags } -public func -(lhs: ComplexArray, rhs: ComplexArray) -> ComplexArray { +public func - (lhs: ComplexArray, rhs: ComplexArray) -> ComplexArray { var results = ComplexArray(lhs) results -= rhs return results } -public func +=(lhs: inout ComplexArray, rhs: Complex) { +public func += (lhs: inout ComplexArray, rhs: Complex) { lhs.reals += rhs.real lhs.imags += rhs.imag } -public func +(lhs: ComplexArray, rhs: Complex) -> ComplexArray { +public func + (lhs: ComplexArray, rhs: Complex) -> ComplexArray { var results = ComplexArray(lhs) results += rhs return results } -public func +(lhs: Complex, rhs: ComplexArray) -> ComplexArray { +public func + (lhs: Complex, rhs: ComplexArray) -> ComplexArray { var results = ComplexArray(rhs) results += lhs return results } -public func -=(lhs: inout ComplexArray, rhs: Complex) { +public func -= (lhs: inout ComplexArray, rhs: Complex) { lhs.reals -= rhs.real lhs.imags -= rhs.imag } -public func -(lhs: ComplexArray, rhs: Complex) -> ComplexArray { +public func - (lhs: ComplexArray, rhs: Complex) -> ComplexArray { var results = ComplexArray(lhs) results -= rhs return results } -public func -(lhs: Complex, rhs: ComplexArray) -> ComplexArray { +public func - (lhs: Complex, rhs: ComplexArray) -> ComplexArray { var results = ComplexArray(rhs) results -= lhs return results } -public func *=(lhs: inout ComplexArray, rhs: Float) { +public func *= (lhs: inout ComplexArray, rhs: Float) { lhs.reals *= rhs lhs.imags *= rhs } -public func *(lhs: ComplexArray, rhs: Float) -> ComplexArray { +public func * (lhs: ComplexArray, rhs: Float) -> ComplexArray { var results = ComplexArray(lhs) results *= rhs return results } -public func /=(lhs: inout ComplexArray, rhs: Float) { +public func /= (lhs: inout ComplexArray, rhs: Float) { lhs.reals /= rhs lhs.imags /= rhs } -public func /(lhs: ComplexArray, rhs: Float) -> ComplexArray { +public func / (lhs: ComplexArray, rhs: Float) -> ComplexArray { var results = ComplexArray(lhs) results /= rhs return results diff --git a/Source/ComplexArray.swift b/Source/ComplexArray.swift index 16ece84a..e659cf4b 100644 --- a/Source/ComplexArray.swift +++ b/Source/ComplexArray.swift @@ -114,7 +114,7 @@ open class ComplexArray: MutableLinearType, ExpressibleByArrayLiteral, } /// Construct a ComplexArray from contiguous memory - public required init(_ values: C) where C.Element == Element { + public required init(_ values: C) where C.Element == Element { elements = ValueArray(values) } @@ -173,7 +173,7 @@ open class ComplexArray: MutableLinearType, ExpressibleByArrayLiteral, elements.append(newElement) } - open func append(contentsOf newElements: S) where S.Iterator.Element == Element { + open func append(contentsOf newElements: S) where S.Iterator.Element == Element { elements.append(contentsOf: newElements) } @@ -189,8 +189,7 @@ open class ComplexArray: MutableLinearType, ExpressibleByArrayLiteral, return Matrix(rows: count, columns: 1, elements: self) } - static public func ==(lhs: ComplexArray, rhs: ComplexArray) -> Bool { + static public func == (lhs: ComplexArray, rhs: ComplexArray) -> Bool { return lhs.count == rhs.count && lhs.elementsEqual(rhs) } } - diff --git a/Source/ComplexArrayRealSlice.swift b/Source/ComplexArrayRealSlice.swift index c98aa58b..67c1397a 100644 --- a/Source/ComplexArrayRealSlice.swift +++ b/Source/ComplexArrayRealSlice.swift @@ -123,8 +123,7 @@ public struct ComplexArrayRealSlice: MutableLinearType { return i + step } - static public func ==(lhs: ComplexArrayRealSlice, rhs: ComplexArrayRealSlice) -> Bool { + static public func == (lhs: ComplexArrayRealSlice, rhs: ComplexArrayRealSlice) -> Bool { return lhs.count == rhs.count && lhs.elementsEqual(rhs) } } - diff --git a/Source/ComplexArraySlice.swift b/Source/ComplexArraySlice.swift index 2b646ebe..94606a18 100644 --- a/Source/ComplexArraySlice.swift +++ b/Source/ComplexArraySlice.swift @@ -28,7 +28,7 @@ open class ComplexArraySlice: MutableLinearType { open let startIndex: Index open let endIndex: Index open let step: Index - + open var span: Span { return Span(ranges: [startIndex ... endIndex - 1]) } @@ -123,11 +123,11 @@ open class ComplexArraySlice: MutableLinearType { // MARK: - Equatable - public static func ==(lhs: ComplexArraySlice, rhs: ComplexArraySlice) -> Bool { + public static func == (lhs: ComplexArraySlice, rhs: ComplexArraySlice) -> Bool { return lhs.count == rhs.count && lhs.elementsEqual(rhs) } - public static func ==(lhs: ComplexArraySlice, rhs: ComplexArray) -> Bool { + public static func == (lhs: ComplexArraySlice, rhs: ComplexArray) -> Bool { return lhs.count == rhs.count && lhs.elementsEqual(rhs) } } diff --git a/Source/Matrix.swift b/Source/Matrix.swift index dc275d66..95ccfec9 100644 --- a/Source/Matrix.swift +++ b/Source/Matrix.swift @@ -206,7 +206,7 @@ open class Matrix: MutableQuadraticType, Equatable, CustomString return description } - + open func tile(_ m: Int, _ n: Int) -> Matrix { // Construct a block matrix of size m by n, with a copy of source matrix as each element. // m: Specifies the number of times to copy along the vertical axis. @@ -229,32 +229,30 @@ open class Matrix: MutableQuadraticType, Equatable, CustomString // MARK: - Equatable - public static func ==(lhs: Matrix, rhs: Matrix) -> Bool { + public static func == (lhs: Matrix, rhs: Matrix) -> Bool { return lhs.elements == rhs.elements } - public static func ==(lhs: Matrix, rhs: Slice) -> Bool { + public static func == (lhs: Matrix, rhs: Slice) -> Bool { assert(lhs.span ≅ rhs.span) return zip(lhs.span, rhs.span).all { lhs[$0] == rhs[$1] } } - public static func ==(lhs: Matrix, rhs: Tensor) -> Bool { + public static func == (lhs: Matrix, rhs: Tensor) -> Bool { return lhs.elements == rhs.elements } - public static func ==(lhs: Matrix, rhs: TensorSlice) -> Bool { + public static func == (lhs: Matrix, rhs: TensorSlice) -> Bool { assert(lhs.span ≅ rhs.span) return zip(lhs.span, rhs.span).all { lhs[$0] == rhs[$1] } } - public static func ==(lhs: Matrix, rhs: TwoDimensionalTensorSlice) -> Bool { + public static func == (lhs: Matrix, rhs: TwoDimensionalTensorSlice) -> Bool { assert(lhs.span ≅ rhs.span) return zip(lhs.span, rhs.span).all { lhs[$0] == rhs[$1] } } } - - // MARK: - public func swap(_ lhs: Matrix, rhs: Matrix) { diff --git a/Source/MatrixArithmetic.swift b/Source/MatrixArithmetic.swift index 5033c862..f5162aa2 100644 --- a/Source/MatrixArithmetic.swift +++ b/Source/MatrixArithmetic.swift @@ -71,14 +71,14 @@ public func normalize(_ x: M) -> Matrix where M.Elemen let inputMatrix = Matrix(x) var individualVectors: [[Double]] = [] - + for i in 0..(inputMatrix.column(i)/Double(two_norm)) + let normalizedVector = [Double](inputMatrix.column(i)/Double(two_norm)) individualVectors.append(normalizedVector) } @@ -212,14 +212,14 @@ public func normalize(_ x: M) -> Matrix where M.Element let inputMatrix = Matrix(x) var individualVectors: [[Float]] = [] - + for i in 0..(inputMatrix.column(i)/two_norm) + let normalizedVector = [Float](inputMatrix.column(i)/two_norm) individualVectors.append(normalizedVector) } diff --git a/Source/MatrixSlice.swift b/Source/MatrixSlice.swift index 0a28458c..6d8548f0 100644 --- a/Source/MatrixSlice.swift +++ b/Source/MatrixSlice.swift @@ -26,7 +26,7 @@ open class MatrixSlice: MutableQuadraticType, CustomStringConver open let rows: Int open let columns: Int - + open let base: Matrix open let span: Span @@ -168,28 +168,28 @@ open class MatrixSlice: MutableQuadraticType, CustomStringConver extension MatrixSlice { // MARK: - Equatable - public static func ==(lhs: MatrixSlice, rhs: Matrix) -> Bool { + public static func == (lhs: MatrixSlice, rhs: Matrix) -> Bool { assert(lhs.span ≅ rhs.span) return zip(lhs.span, rhs.span).all { lhs[$0] == rhs[$1] } } - public static func ==(lhs: MatrixSlice, rhs: MatrixSlice) -> Bool { + public static func == (lhs: MatrixSlice, rhs: MatrixSlice) -> Bool { assert(lhs.span ≅ rhs.span) return zip(lhs.span, rhs.span).all { lhs[$0] == rhs[$1] } } - public static func ==(lhs: MatrixSlice, rhs: Tensor) -> Bool { + public static func == (lhs: MatrixSlice, rhs: Tensor) -> Bool { assert(lhs.span ≅ rhs.span) return zip(lhs.span, rhs.span).all { lhs[$0] == rhs[$1] } } - public static func ==(lhs: MatrixSlice, rhs: TensorSlice) -> Bool { + public static func == (lhs: MatrixSlice, rhs: TensorSlice) -> Bool { assert(lhs.span ≅ rhs.span) return zip(lhs.span, rhs.span).all { lhs[$0] == rhs[$1] } } - public static func ==(lhs: MatrixSlice, rhs: TwoDimensionalTensorSlice) -> Bool { + public static func == (lhs: MatrixSlice, rhs: TwoDimensionalTensorSlice) -> Bool { assert(lhs.span ≅ rhs.span) return zip(lhs.span, rhs.span).all { lhs[$0] == rhs[$1] } } diff --git a/Source/Span.swift b/Source/Span.swift index 1f34fe81..5af63386 100644 --- a/Source/Span.swift +++ b/Source/Span.swift @@ -56,7 +56,7 @@ public struct Span: ExpressibleByArrayLiteral, Sequence { assert(base.contains(intervals)) var ranges = [Element]() - for (i,interval) in intervals.enumerated() { + for (i, interval) in intervals.enumerated() { let start = interval.start ?? base[i].lowerBound let end = interval.end ?? base[i].upperBound + 1 assert(base[i].lowerBound <= start && end <= base[i].upperBound + 1) diff --git a/Source/Tensor.swift b/Source/Tensor.swift index 3bd02449..7e270b23 100644 --- a/Source/Tensor.swift +++ b/Source/Tensor.swift @@ -189,25 +189,25 @@ public func swap(_ lhs: Tensor, rhs: Tensor) { // MARK: - Equatable extension Tensor { - public static func ==(lhs: Tensor, rhs: Tensor) -> Bool { + public static func == (lhs: Tensor, rhs: Tensor) -> Bool { return lhs.elements == rhs.elements } - public static func ==(lhs: Tensor, rhs: TensorSlice) -> Bool { + public static func == (lhs: Tensor, rhs: TensorSlice) -> Bool { assert(lhs.span ≅ rhs.span) return zip(lhs.span, rhs.span).all { lhs[$0] == rhs[$1] } } - public static func ==(lhs: Tensor, rhs: Matrix) -> Bool { + public static func == (lhs: Tensor, rhs: Matrix) -> Bool { return lhs.elements == rhs.elements } - public static func ==(lhs: Tensor, rhs: MatrixSlice) -> Bool { + public static func == (lhs: Tensor, rhs: MatrixSlice) -> Bool { assert(lhs.span ≅ rhs.span) return zip(lhs.span, rhs.span).all { lhs[$0] == rhs[$1] } } - public static func ==(lhs: Tensor, rhs: TwoDimensionalTensorSlice) -> Bool { + public static func == (lhs: Tensor, rhs: TwoDimensionalTensorSlice) -> Bool { assert(lhs.span ≅ rhs.span) return zip(lhs.span, rhs.span).all { lhs[$0] == rhs[$1] } } diff --git a/Source/TensorSlice.swift b/Source/TensorSlice.swift index fa27b8d5..cf4b8839 100644 --- a/Source/TensorSlice.swift +++ b/Source/TensorSlice.swift @@ -126,7 +126,7 @@ open class TensorSlice: MutableTensorType, Equatable { open func indexIsValid(_ indices: [Int]) -> Bool { assert(indices.count == dimensions.count) - return indices.enumerated().all { (i,index) in self.span[i].contains(index) } + return indices.enumerated().all { (i, index) in self.span[i].contains(index) } } } diff --git a/Source/ValueArray.swift b/Source/ValueArray.swift index e70e8827..5f877ca6 100644 --- a/Source/ValueArray.swift +++ b/Source/ValueArray.swift @@ -184,7 +184,7 @@ open class ValueArray: MutableLinearType, ExpressibleByArrayLite count += 1 } - open func append(contentsOf newElements: S) where S.Iterator.Element == Element { + open func append(contentsOf newElements: S) where S.Iterator.Element == Element { let a = Array(newElements) precondition(count + a.count <= capacity) let endPointer = mutablePointer + count @@ -192,7 +192,7 @@ open class ValueArray: MutableLinearType, ExpressibleByArrayLite count += a.count } - open func replaceSubrange(_ subrange: Range, with newElements: C) where C.Iterator.Element == Element { + open func replaceSubrange(_ subrange: Range, with newElements: C) where C.Iterator.Element == Element { assert(subrange.lowerBound >= startIndex && subrange.upperBound <= endIndex) _ = UnsafeMutableBufferPointer(start: mutablePointer + subrange.lowerBound, count: capacity - subrange.lowerBound).initialize(from: newElements) } @@ -204,12 +204,12 @@ open class ValueArray: MutableLinearType, ExpressibleByArrayLite open func toColumnMatrix() -> Matrix { return Matrix(rows: count, columns: 1, elements: self) } - - open func toMatrix(rows: Int, columns:Int) -> Matrix { + + open func toMatrix(rows: Int, columns: Int) -> Matrix { precondition(rows*columns == count, "Element count must equal rows*columns") return Matrix(rows: rows, columns: columns, elements: self) } - + open func tile(_ m: Int, _ n: Int) -> Matrix { // Construct a block matrix of size m by n, with a copy of source as each element. // m: Specifies the number of times to copy along the vertical axis. @@ -226,11 +226,11 @@ open class ValueArray: MutableLinearType, ExpressibleByArrayLite // MARK: - Equatable - public static func ==(lhs: ValueArray, rhs: ValueArray) -> Bool { + public static func == (lhs: ValueArray, rhs: ValueArray) -> Bool { return lhs.count == rhs.count && lhs.elementsEqual(rhs) } - public static func ==(lhs: ValueArray, rhs: Slice) -> Bool { + public static func == (lhs: ValueArray, rhs: Slice) -> Bool { return lhs.count == rhs.count && lhs.elementsEqual(rhs) } } diff --git a/Source/ValueArraySlice.swift b/Source/ValueArraySlice.swift index 2446e0c2..c4d128f4 100644 --- a/Source/ValueArraySlice.swift +++ b/Source/ValueArraySlice.swift @@ -133,7 +133,7 @@ public struct ValueArraySlice: MutableLinearType, CustomStringCo // MARK: - Equatable - public static func ==(lhs: ValueArraySlice, rhs: ValueArraySlice) -> Bool { + public static func == (lhs: ValueArraySlice, rhs: ValueArraySlice) -> Bool { return lhs.count == rhs.count && zip(lhs.indices, rhs.indices).all { lhs[$0] == rhs[$1] } diff --git a/Tests/UpsurgeTests/ArithmeticTests.swift b/Tests/UpsurgeTests/ArithmeticTests.swift index 573d6607..c1b0fef1 100644 --- a/Tests/UpsurgeTests/ArithmeticTests.swift +++ b/Tests/UpsurgeTests/ArithmeticTests.swift @@ -140,14 +140,14 @@ class ArithmeticTests: XCTestCase { XCTAssertEqual(slope, 1.0) XCTAssertEqual(intercept, 0.0) } - + func testScalarVectorSubtraction() { let a1: ValueArray = [1.0, 2.0, 3.0] let r1 = 1 - a1 XCTAssertEqual(r1[0], 0.0) XCTAssertEqual(r1[1], -1.0) XCTAssertEqual(r1[2], -2.0) - + let a2: ValueArray = [1.0, 2.0, 3.0] let r2 = 1 - a2 XCTAssertEqual(r2[0], 0.0) diff --git a/Tests/UpsurgeTests/RealMatrixTests.swift b/Tests/UpsurgeTests/RealMatrixTests.swift index ae9ee07d..2cb2aeb0 100644 --- a/Tests/UpsurgeTests/RealMatrixTests.swift +++ b/Tests/UpsurgeTests/RealMatrixTests.swift @@ -205,14 +205,14 @@ class RealMatrixTests: XCTestCase { let col = A.column(0) XCTAssertEqual(col.description, "[1.0, 1.0]") } - + func testTile() { let A = Matrix([ [1, 2], [3, 4] ]) let B = A.tile(2, 2) - + XCTAssertEqual(B.count, 16) XCTAssertEqual(B.elements, [1.0, 2.0, 1.0, 2.0, 3.0, 4.0, 3.0, 4.0, 1.0, 2.0, 1.0, 2.0, 3.0, 4.0, 3.0, 4.0]) } diff --git a/Tests/UpsurgeTests/ValueArrayTests.swift b/Tests/UpsurgeTests/ValueArrayTests.swift index b67b411b..0a0c14de 100644 --- a/Tests/UpsurgeTests/ValueArrayTests.swift +++ b/Tests/UpsurgeTests/ValueArrayTests.swift @@ -95,11 +95,11 @@ class RealArrayTests: XCTestCase { array[0..<10] = matrix.row(2) XCTAssertEqual(array, expected) } - + func testTile() { let a: ValueArray = [1.0, 2.0] let b = a.tile(2, 2) - + XCTAssertEqual(b.count, 8) XCTAssertEqual(b.elements, [1.0, 2.0, 1.0, 2.0, 1.0, 2.0, 1.0, 2.0]) } diff --git a/Tests/UpsurgeTests/XCTestCase+Surge.swift b/Tests/UpsurgeTests/XCTestCase+Surge.swift index b8097cb0..8facd0d4 100644 --- a/Tests/UpsurgeTests/XCTestCase+Surge.swift +++ b/Tests/UpsurgeTests/XCTestCase+Surge.swift @@ -30,6 +30,7 @@ extension XCTestCase { actual = mapped(source) } + // swiftlint:disable:next unused_enumerated for (i, _) in source.enumerated() { XCTAssertEqualWithAccuracy(actual[i], expected[i], accuracy: accuracy) } diff --git a/Upsurge.xcodeproj/project.pbxproj b/Upsurge.xcodeproj/project.pbxproj index fe1ebbce..7a77cc30 100644 --- a/Upsurge.xcodeproj/project.pbxproj +++ b/Upsurge.xcodeproj/project.pbxproj @@ -472,6 +472,7 @@ 614ACA6C1BD1CB7B00A1C13E /* Frameworks */, 614ACA6D1BD1CB7B00A1C13E /* Headers */, 614ACA6E1BD1CB7B00A1C13E /* Resources */, + 61F2BADF1E8A3B2D00E2D141 /* Run Swiftlint */, ); buildRules = ( ); @@ -508,6 +509,7 @@ 614ACAC61BD1CBF300A1C13E /* Frameworks */, 614ACAC71BD1CBF300A1C13E /* Headers */, 614ACAC81BD1CBF300A1C13E /* Resources */, + 61F2BAE21E8A3B5A00E2D141 /* Run SwiftLint */, ); buildRules = ( ); @@ -544,6 +546,7 @@ 61D046691C48BA5B00DB7279 /* Frameworks */, 61D0466A1C48BA5B00DB7279 /* Headers */, 61D0466B1C48BA5B00DB7279 /* Resources */, + 61F2BAE31E8A3B6B00E2D141 /* ShellScript */, ); buildRules = ( ); @@ -676,6 +679,53 @@ }; /* End PBXResourcesBuildPhase section */ +/* Begin PBXShellScriptBuildPhase section */ + 61F2BADF1E8A3B2D00E2D141 /* Run Swiftlint */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "Run Swiftlint"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "if which swiftlint >/dev/null; then\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi"; + showEnvVarsInLog = 0; + }; + 61F2BAE21E8A3B5A00E2D141 /* Run SwiftLint */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "Run SwiftLint"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "if which swiftlint >/dev/null; then\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi"; + showEnvVarsInLog = 0; + }; + 61F2BAE31E8A3B6B00E2D141 /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "if which swiftlint >/dev/null; then\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi"; + showEnvVarsInLog = 0; + }; +/* End PBXShellScriptBuildPhase section */ + /* Begin PBXSourcesBuildPhase section */ 614ACA6B1BD1CB7B00A1C13E /* Sources */ = { isa = PBXSourcesBuildPhase;