Skip to content

Commit

Permalink
Remove extra whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
alejandro-isaza committed Sep 14, 2017
1 parent 1995bfb commit 90f2eb5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
14 changes: 7 additions & 7 deletions Source/Matrix.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ open class Matrix<Element: Value>: MutableQuadraticType, Equatable, CustomString
public convenience init(_ contents: [[Element]]) {
let rows = contents.count
let cols = contents[0].count

for element in contents {
precondition(element.count == cols)
}
Expand All @@ -109,23 +109,23 @@ open class Matrix<Element: Value>: MutableQuadraticType, Equatable, CustomString
elements.replaceSubrange(i*cols..<i*cols+min(cols, row.count), with: row)
}
}

/// Construct a Matrix from an array of rows
public convenience init<M: LinearType>(_ contents: [M]) where M.Element == Element {

let rows = contents.count
let cols = Int(contents[0].count)

for element in contents {
precondition(element.count == cols)
}

self.init(rows: rows, columns: cols)

for (i, row) in contents.enumerated() {
elements.replaceSubrange(i*cols..<i*cols+min(cols, row.count), with: row)
}

}

/// Construct a Matrix from an array of rows
Expand Down
13 changes: 6 additions & 7 deletions Tests/UpsurgeTests/RealMatrixTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,21 @@ import Upsurge
import XCTest

class RealMatrixTests: XCTestCase {

func testInit() {
let rowZero = [0.2, 0.3]
let rowOne = [0.1, 0.5]

let a = Matrix<Double>([rowZero, rowOne])

let arrayZero = ValueArray<Double>(rowZero)
let arrayOne = ValueArray<Double>(rowOne)

let b = Matrix<Double>([arrayZero, arrayOne])

XCTAssertEqual(a, b)
}



func testAdd() {
var a = Matrix<Double>(rows: 2, columns: 2, elements: [1, 2, 3, 4] as ValueArray<Double>)
let b = Matrix<Double>(rows: 2, columns: 2, elements: [2, 3, 4, 1] as ValueArray<Double>)
Expand Down

0 comments on commit 90f2eb5

Please sign in to comment.