Skip to content

Commit

Permalink
Add SwiftLint build phase and fix linter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
alejandro-isaza committed Mar 28, 2017
1 parent 8606700 commit 6d1e9ce
Show file tree
Hide file tree
Showing 21 changed files with 147 additions and 94 deletions.
7 changes: 7 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
disabled_rules:
- file_length
- for_where
- force_cast
- identifier_name
- large_tuple
- line_length
1 change: 0 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ import PackageDescription
let package = Package(
name: "Upsurge"
)

2 changes: 1 addition & 1 deletion Source/2DTensorSlice.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
open class TwoDimensionalTensorSlice<Element: Value>: MutableQuadraticType, Equatable {
public typealias Index = [Int]
public typealias Slice = TwoDimensionalTensorSlice<Element>

open var arrangement: QuadraticArrangement {
return .rowMajor
}
Expand Down
32 changes: 16 additions & 16 deletions Source/Complex.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,76 +78,76 @@ public func <<T: Real>(lhs: Complex<T>, rhs: Complex<T>) -> Bool {

// MARK: - Double

public func +(lhs: Complex<Double>, rhs: Complex<Double>) -> Complex<Double> {
public func + (lhs: Complex<Double>, rhs: Complex<Double>) -> Complex<Double> {
return Complex(real: lhs.real + rhs.real, imag: lhs.imag + rhs.imag)
}

public func -(lhs: Complex<Double>, rhs: Complex<Double>) -> Complex<Double> {
public func - (lhs: Complex<Double>, rhs: Complex<Double>) -> Complex<Double> {
return Complex(real: lhs.real - rhs.real, imag: lhs.imag - rhs.imag)
}

public func *(lhs: Complex<Double>, rhs: Complex<Double>) -> Complex<Double> {
public func * (lhs: Complex<Double>, rhs: Complex<Double>) -> Complex<Double> {
return Complex(real: lhs.real * rhs.real - lhs.imag * rhs.imag, imag: lhs.real * rhs.imag + lhs.imag * rhs.real)
}

public func *(x: Complex<Double>, a: Double) -> Complex<Double> {
public func * (x: Complex<Double>, a: Double) -> Complex<Double> {
return Complex(real: x.real * a, imag: x.imag * a)
}

public func *(a: Double, x: Complex<Double>) -> Complex<Double> {
public func * (a: Double, x: Complex<Double>) -> Complex<Double> {
return Complex(real: x.real * a, imag: x.imag * a)
}

public func /(lhs: Complex<Double>, rhs: Complex<Double>) -> Complex<Double> {
public func / (lhs: Complex<Double>, rhs: Complex<Double>) -> Complex<Double> {
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<Double>, a: Double) -> Complex<Double> {
public func / (x: Complex<Double>, a: Double) -> Complex<Double> {
return Complex(real: x.real / a, imag: x.imag / a)
}

public func /(a: Double, x: Complex<Double>) -> Complex<Double> {
public func / (a: Double, x: Complex<Double>) -> Complex<Double> {
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<Float>, rhs: Complex<Float>) -> Complex<Float> {
public func + (lhs: Complex<Float>, rhs: Complex<Float>) -> Complex<Float> {
return Complex(real: lhs.real + rhs.real, imag: lhs.imag + rhs.imag)
}

public func -(lhs: Complex<Float>, rhs: Complex<Float>) -> Complex<Float> {
public func - (lhs: Complex<Float>, rhs: Complex<Float>) -> Complex<Float> {
return Complex(real: lhs.real - rhs.real, imag: lhs.imag - rhs.imag)
}

public func *(lhs: Complex<Float>, rhs: Complex<Float>) -> Complex<Float> {
public func * (lhs: Complex<Float>, rhs: Complex<Float>) -> Complex<Float> {
return Complex(real: lhs.real * rhs.real - lhs.imag * rhs.imag, imag: lhs.real * rhs.imag + lhs.imag * rhs.real)
}

public func *(x: Complex<Float>, a: Float) -> Complex<Float> {
public func * (x: Complex<Float>, a: Float) -> Complex<Float> {
return Complex(real: x.real * a, imag: x.imag * a)
}

public func *(a: Float, x: Complex<Float>) -> Complex<Float> {
public func * (a: Float, x: Complex<Float>) -> Complex<Float> {
return Complex(real: x.real * a, imag: x.imag * a)
}

public func /(lhs: Complex<Float>, rhs: Complex<Float>) -> Complex<Float> {
public func / (lhs: Complex<Float>, rhs: Complex<Float>) -> Complex<Float> {
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<Float>, a: Float) -> Complex<Float> {
public func / (x: Complex<Float>, a: Float) -> Complex<Float> {
return Complex(real: x.real / a, imag: x.imag / a)
}

public func /(a: Float, x: Complex<Float>) -> Complex<Float> {
public func / (a: Float, x: Complex<Float>) -> Complex<Float> {
let xMagSq = x.real*x.real + x.imag*x.imag
return Complex(real: a*x.real / xMagSq, imag: -a*x.imag / xMagSq)
}
56 changes: 28 additions & 28 deletions Source/ComplexArithmetic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,79 +26,79 @@ public func sum(_ x: ComplexArray<Double>) -> Complex<Double> {

// MARK: Operators

public func +=(lhs: inout ComplexArray<Double>, rhs: ComplexArray<Double>) {
public func += (lhs: inout ComplexArray<Double>, rhs: ComplexArray<Double>) {
lhs.reals += rhs.reals
lhs.imags += rhs.imags
}

public func +(lhs: ComplexArray<Double>, rhs: ComplexArray<Double>) -> ComplexArray<Double> {
public func + (lhs: ComplexArray<Double>, rhs: ComplexArray<Double>) -> ComplexArray<Double> {
var results = ComplexArray(lhs)
results += rhs
return results
}

public func -=(lhs: inout ComplexArray<Double>, rhs: ComplexArray<Double>) {
public func -= (lhs: inout ComplexArray<Double>, rhs: ComplexArray<Double>) {
lhs.reals -= rhs.reals
lhs.imags -= rhs.imags
}

public func -(lhs: ComplexArray<Double>, rhs: ComplexArray<Double>) -> ComplexArray<Double> {
public func - (lhs: ComplexArray<Double>, rhs: ComplexArray<Double>) -> ComplexArray<Double> {
var results = ComplexArray(lhs)
results -= rhs
return results
}

public func +=(lhs: inout ComplexArray<Double>, rhs: Complex<Double>) {
public func += (lhs: inout ComplexArray<Double>, rhs: Complex<Double>) {
lhs.reals += rhs.real
lhs.imags += rhs.imag
}

public func +(lhs: ComplexArray<Double>, rhs: Complex<Double>) -> ComplexArray<Double> {
public func + (lhs: ComplexArray<Double>, rhs: Complex<Double>) -> ComplexArray<Double> {
var results = ComplexArray(lhs)
results += rhs
return results
}

public func +(lhs: Complex<Double>, rhs: ComplexArray<Double>) -> ComplexArray<Double> {
public func + (lhs: Complex<Double>, rhs: ComplexArray<Double>) -> ComplexArray<Double> {
var results = ComplexArray(rhs)
results += lhs
return results
}

public func -=(lhs: inout ComplexArray<Double>, rhs: Complex<Double>) {
public func -= (lhs: inout ComplexArray<Double>, rhs: Complex<Double>) {
lhs.reals -= rhs.real
lhs.imags -= rhs.imag
}

public func -(lhs: ComplexArray<Double>, rhs: Complex<Double>) -> ComplexArray<Double> {
public func - (lhs: ComplexArray<Double>, rhs: Complex<Double>) -> ComplexArray<Double> {
var results = ComplexArray(lhs)
results -= rhs
return results
}

public func -(lhs: Complex<Double>, rhs: ComplexArray<Double>) -> ComplexArray<Double> {
public func - (lhs: Complex<Double>, rhs: ComplexArray<Double>) -> ComplexArray<Double> {
var results = ComplexArray(rhs)
results -= lhs
return results
}

public func *=(lhs: inout ComplexArray<Double>, rhs: Double) {
public func *= (lhs: inout ComplexArray<Double>, rhs: Double) {
lhs.reals *= rhs
lhs.imags *= rhs
}

public func *(lhs: ComplexArray<Double>, rhs: Double) -> ComplexArray<Double> {
public func * (lhs: ComplexArray<Double>, rhs: Double) -> ComplexArray<Double> {
var results = ComplexArray(lhs)
results *= rhs
return results
}

public func /=(lhs: inout ComplexArray<Double>, rhs: Double) {
public func /= (lhs: inout ComplexArray<Double>, rhs: Double) {
lhs.reals /= rhs
lhs.imags /= rhs
}

public func /(lhs: ComplexArray<Double>, rhs: Double) -> ComplexArray<Double> {
public func / (lhs: ComplexArray<Double>, rhs: Double) -> ComplexArray<Double> {
var results = ComplexArray(lhs)
results /= rhs
return results
Expand All @@ -112,79 +112,79 @@ public func sum(_ x: ComplexArray<Float>) -> Complex<Float> {

// MARK: Operators

public func +=(lhs: inout ComplexArray<Float>, rhs: ComplexArray<Float>) {
public func += (lhs: inout ComplexArray<Float>, rhs: ComplexArray<Float>) {
lhs.reals += rhs.reals
lhs.imags += rhs.imags
}

public func +(lhs: ComplexArray<Float>, rhs: ComplexArray<Float>) -> ComplexArray<Float> {
public func + (lhs: ComplexArray<Float>, rhs: ComplexArray<Float>) -> ComplexArray<Float> {
var results = ComplexArray(lhs)
results += rhs
return results
}

public func -=(lhs: inout ComplexArray<Float>, rhs: ComplexArray<Float>) {
public func -= (lhs: inout ComplexArray<Float>, rhs: ComplexArray<Float>) {
lhs.reals -= rhs.reals
lhs.imags -= rhs.imags
}

public func -(lhs: ComplexArray<Float>, rhs: ComplexArray<Float>) -> ComplexArray<Float> {
public func - (lhs: ComplexArray<Float>, rhs: ComplexArray<Float>) -> ComplexArray<Float> {
var results = ComplexArray(lhs)
results -= rhs
return results
}

public func +=(lhs: inout ComplexArray<Float>, rhs: Complex<Float>) {
public func += (lhs: inout ComplexArray<Float>, rhs: Complex<Float>) {
lhs.reals += rhs.real
lhs.imags += rhs.imag
}

public func +(lhs: ComplexArray<Float>, rhs: Complex<Float>) -> ComplexArray<Float> {
public func + (lhs: ComplexArray<Float>, rhs: Complex<Float>) -> ComplexArray<Float> {
var results = ComplexArray(lhs)
results += rhs
return results
}

public func +(lhs: Complex<Float>, rhs: ComplexArray<Float>) -> ComplexArray<Float> {
public func + (lhs: Complex<Float>, rhs: ComplexArray<Float>) -> ComplexArray<Float> {
var results = ComplexArray(rhs)
results += lhs
return results
}

public func -=(lhs: inout ComplexArray<Float>, rhs: Complex<Float>) {
public func -= (lhs: inout ComplexArray<Float>, rhs: Complex<Float>) {
lhs.reals -= rhs.real
lhs.imags -= rhs.imag
}

public func -(lhs: ComplexArray<Float>, rhs: Complex<Float>) -> ComplexArray<Float> {
public func - (lhs: ComplexArray<Float>, rhs: Complex<Float>) -> ComplexArray<Float> {
var results = ComplexArray(lhs)
results -= rhs
return results
}

public func -(lhs: Complex<Float>, rhs: ComplexArray<Float>) -> ComplexArray<Float> {
public func - (lhs: Complex<Float>, rhs: ComplexArray<Float>) -> ComplexArray<Float> {
var results = ComplexArray(rhs)
results -= lhs
return results
}

public func *=(lhs: inout ComplexArray<Float>, rhs: Float) {
public func *= (lhs: inout ComplexArray<Float>, rhs: Float) {
lhs.reals *= rhs
lhs.imags *= rhs
}

public func *(lhs: ComplexArray<Float>, rhs: Float) -> ComplexArray<Float> {
public func * (lhs: ComplexArray<Float>, rhs: Float) -> ComplexArray<Float> {
var results = ComplexArray(lhs)
results *= rhs
return results
}

public func /=(lhs: inout ComplexArray<Float>, rhs: Float) {
public func /= (lhs: inout ComplexArray<Float>, rhs: Float) {
lhs.reals /= rhs
lhs.imags /= rhs
}

public func /(lhs: ComplexArray<Float>, rhs: Float) -> ComplexArray<Float> {
public func / (lhs: ComplexArray<Float>, rhs: Float) -> ComplexArray<Float> {
var results = ComplexArray(lhs)
results /= rhs
return results
Expand Down
7 changes: 3 additions & 4 deletions Source/ComplexArray.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ open class ComplexArray<T: Real>: MutableLinearType, ExpressibleByArrayLiteral,
}

/// Construct a ComplexArray from contiguous memory
public required init<C : LinearType>(_ values: C) where C.Element == Element {
public required init<C: LinearType>(_ values: C) where C.Element == Element {
elements = ValueArray(values)
}

Expand Down Expand Up @@ -173,7 +173,7 @@ open class ComplexArray<T: Real>: MutableLinearType, ExpressibleByArrayLiteral,
elements.append(newElement)
}

open func append<S : Sequence>(contentsOf newElements: S) where S.Iterator.Element == Element {
open func append<S: Sequence>(contentsOf newElements: S) where S.Iterator.Element == Element {
elements.append(contentsOf: newElements)
}

Expand All @@ -189,8 +189,7 @@ open class ComplexArray<T: Real>: 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)
}
}

3 changes: 1 addition & 2 deletions Source/ComplexArrayRealSlice.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ public struct ComplexArrayRealSlice<T: Real>: 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)
}
}

6 changes: 3 additions & 3 deletions Source/ComplexArraySlice.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ open class ComplexArraySlice<T: Real>: MutableLinearType {
open let startIndex: Index
open let endIndex: Index
open let step: Index

open var span: Span {
return Span(ranges: [startIndex ... endIndex - 1])
}
Expand Down Expand Up @@ -123,11 +123,11 @@ open class ComplexArraySlice<T: Real>: 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<T>) -> Bool {
public static func == (lhs: ComplexArraySlice, rhs: ComplexArray<T>) -> Bool {
return lhs.count == rhs.count && lhs.elementsEqual(rhs)
}
}
Loading

0 comments on commit 6d1e9ce

Please sign in to comment.