Skip to content

Commit

Permalink
Merge pull request #1 from tr1ckyf0x/master
Browse files Browse the repository at this point in the history
Converted project to Swift 4
  • Loading branch information
statuser authored Oct 9, 2017
2 parents 2f8d913 + 9a02978 commit 5c890bc
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 74 deletions.
30 changes: 23 additions & 7 deletions Dimensional/Dimensional.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -207,16 +207,16 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0720;
LastUpgradeCheck = 0820;
LastUpgradeCheck = 0900;
ORGANIZATIONNAME = "Jaden Geller";
TargetAttributes = {
4D59D53D1C3C757D00058827 = {
CreatedOnToolsVersion = 7.2;
LastSwiftMigration = 0820;
LastSwiftMigration = 0900;
};
4D59D5471C3C757D00058827 = {
CreatedOnToolsVersion = 7.2;
LastSwiftMigration = 0820;
LastSwiftMigration = 0900;
};
6B4D54F91E15F0E900BF47C3 = {
CreatedOnToolsVersion = 8.2.1;
Expand Down Expand Up @@ -320,14 +320,20 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down Expand Up @@ -370,14 +376,20 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down Expand Up @@ -422,7 +434,8 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -442,7 +455,8 @@
PRODUCT_BUNDLE_IDENTIFIER = com.JadenGeller.Dimensional;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand All @@ -454,7 +468,8 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.JadenGeller.DimensionalTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -466,7 +481,8 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.JadenGeller.DimensionalTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0820"
LastUpgradeVersion = "0900"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -26,6 +26,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
Expand Down Expand Up @@ -55,6 +56,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
9 changes: 2 additions & 7 deletions Dimensional/DimensionalTests/DimensionalTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class DimensionalTests: XCTestCase {

func testTranspose() {
let matrix: Matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
XCTAssertTrue([[1, 4, 7], [2, 5, 8], [3, 6, 9]] == matrix.transpose)
XCTAssertTrue([[1, 4, 7], [2, 5, 8], [3, 6, 9]] == matrix.transposed)
}

func testRepeatedValue() {
Expand Down Expand Up @@ -97,12 +97,7 @@ class DimensionalTests: XCTestCase {
[0,6,10,14],
[0,0,11,15],
[0,0,0,16]])
let testMatrix = test.transpose * test
let testMatrix = test.transposed * test
XCTAssertTrue(test == testMatrix.cholesky)




}

}
3 changes: 2 additions & 1 deletion Dimensional/Vector.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
//
// Created by John Howell on 1/24/17.
// Copyright © 2017 John Howell. All rights reserved.
// Modified by Vladislav Lisyanskiy on 9/10/2017. - Converted to Swift 4.
//

import Foundation

extension Array where Element: FloatingPointArithmeticType {
extension Array where Element: FloatingPointArithmetic {
public func dot(_ vector: [Element]) -> Element {
precondition(self.count == vector.count, "Vectors are not the same length")
return zip(self, vector).map { $0.0 * $0.1 }.reduce(Element(0), +)
Expand Down
22 changes: 9 additions & 13 deletions Sources/Matrix.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//
// Created by Jaden Geller on 1/5/16.
// Copyright © 2016 Jaden Geller. All rights reserved.
// Modified by Vladislav Lisyanskiy on 9/10/2017. - Converted to Swift 4.
//

public struct Matrix<Member> {
Expand All @@ -30,11 +31,10 @@ extension Matrix: ExpressibleByArrayLiteral {
public init(_ columns: ColumnView<Member>) {
self.rowBacking = columns.matrix.rowBacking
}

}

extension Matrix {
public subscript(row: Int, column: Int) -> Member {
public subscript(_ row: Int, _ column: Int) -> Member {
get {
return rowBacking[row][column]
}
Expand Down Expand Up @@ -129,21 +129,20 @@ extension Matrix {
return rows.count == columns.count
}

public var transpose: Matrix {
public var transposed: Matrix {
return Matrix(RowView(columns))
}

}

extension Matrix where Member: Equatable {
public var isSymmetric: Bool {
guard isSquare else { return false}
return transpose == self

guard isSquare else { return false }
return transposed == self
}

}

public typealias MatrixDimensions = (width: Int, height: Int)

extension Matrix where Member: ExpressibleByIntegerLiteral {
public static func diagonal(_ dimensions: MatrixDimensions, diagonalValue: Member, defaultValue: Member) -> Matrix {
var matrix = Matrix(repeating: defaultValue, dimensions: dimensions)
Expand All @@ -155,10 +154,9 @@ extension Matrix where Member: ExpressibleByIntegerLiteral {

public static func diagonalFromVector(_ vector: Array<Member>) -> Matrix {
var matrix = Matrix(repeating: 0, dimensions: (vector.count, vector.count))
for i in 0..<vector.count {
matrix[i,i] = vector[i]
vector.enumerated().forEach { index, value in
matrix[index, index] = value
}

return matrix
}

Expand All @@ -171,8 +169,6 @@ extension Matrix where Member: ExpressibleByIntegerLiteral {
}
}

public typealias MatrixDimensions = (width: Int, height: Int)

extension Matrix {
public init(repeating: Member, dimensions: MatrixDimensions) {
self.rowBacking = Array(repeating: Array(repeating: repeating, count: dimensions.width), count: dimensions.height
Expand Down
Loading

0 comments on commit 5c890bc

Please sign in to comment.