Skip to content

Added unit tests for matrix arithmetic #108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Aug 29, 2019
Prev Previous commit
Next Next commit
Renamed existing remaining test functions to match naming scheme
  • Loading branch information
regexident committed Aug 29, 2019
commit 3e138631182442cf9fcaf87fea08518c16ad2f71
26 changes: 13 additions & 13 deletions Tests/SurgeTests/MatrixTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ class MatrixTests: XCTestCase {
}) == nil
}

func testEigenDecompositionTrivialGeneric<T: FloatingPoint & ExpressibleByFloatLiteral>(defaultAccuracy: T, eigendecompostionFn: ((Matrix<T>) throws -> MatrixEigenDecompositionResult<T>)) throws {
func eigen_decomposition_trivial_generic<T: FloatingPoint & ExpressibleByFloatLiteral>(defaultAccuracy: T, eigendecompostionFn: ((Matrix<T>) throws -> MatrixEigenDecompositionResult<T>)) throws {
let matrix = Matrix<T>([
[1, 0, 0],
[0, 2, 0],
Expand All @@ -590,17 +590,17 @@ class MatrixTests: XCTestCase {
XCTAssertTrue(complexVectorMatches(flatRight, expectedEigenVector, accuracy: defaultAccuracy))
}

func testEigenDecompositionTrivial() throws {
try testEigenDecompositionTrivialGeneric(defaultAccuracy: doubleAccuracy) { (m: Matrix<Double>) throws -> MatrixEigenDecompositionResult<Double> in
func test_eigen_decomposition_trivial() throws {
try eigen_decomposition_trivial_generic(defaultAccuracy: doubleAccuracy) { (m: Matrix<Double>) throws -> MatrixEigenDecompositionResult<Double> in
try eigenDecompose(m)
}
try testEigenDecompositionTrivialGeneric(defaultAccuracy: floatAccuracy) { (m: Matrix<Float>) throws -> MatrixEigenDecompositionResult<Float> in
try eigen_decomposition_trivial_generic(defaultAccuracy: floatAccuracy) { (m: Matrix<Float>) throws -> MatrixEigenDecompositionResult<Float> in
try eigenDecompose(m)
}
}

// Example from https://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.eig.html
func testEigenDecompositionComplexResultsNumpyExampleGeneric<T: FloatingPoint & ExpressibleByFloatLiteral>(defaultAccuracy: T, eigendecompostionFn: ((Matrix<T>) throws -> MatrixEigenDecompositionResult<T>)) throws {
func eigen_decomposition_complex_results_numpy_example_generic<T: FloatingPoint & ExpressibleByFloatLiteral>(defaultAccuracy: T, eigendecompostionFn: ((Matrix<T>) throws -> MatrixEigenDecompositionResult<T>)) throws {
let matrix = Matrix<T>([
[1, -1],
[1, 1],
Expand All @@ -617,18 +617,18 @@ class MatrixTests: XCTestCase {
XCTAssertTrue(complexVectorMatches(flatRight, expectedEigenVector, accuracy: 0.000_001))
}

func testEigenDecompositionComplexResultsNumpyExample() throws {
try testEigenDecompositionComplexResultsNumpyExampleGeneric(defaultAccuracy: doubleAccuracy) { (m: Matrix<Double>) throws -> MatrixEigenDecompositionResult<Double> in
func test_eigen_decomposition_complex_results_numpy_example() throws {
try eigen_decomposition_complex_results_numpy_example_generic(defaultAccuracy: doubleAccuracy) { (m: Matrix<Double>) throws -> MatrixEigenDecompositionResult<Double> in
try eigenDecompose(m)
}
try testEigenDecompositionComplexResultsNumpyExampleGeneric(defaultAccuracy: floatAccuracy) { (m: Matrix<Float>) throws -> MatrixEigenDecompositionResult<Float> in
try eigen_decomposition_complex_results_numpy_example_generic(defaultAccuracy: floatAccuracy) { (m: Matrix<Float>) throws -> MatrixEigenDecompositionResult<Float> in
try eigenDecompose(m)
}
}

// Example from Intel's DGEEV documentation
// https://software.intel.com/sites/products/documentation/doclib/mkl_sa/11/mkl_lapack_examples/dgeev.htm
func testEigenDecompositionComplexResultsDGEEVExampleGeneric<T: FloatingPoint & ExpressibleByFloatLiteral>(defaultAccuracy: T, eigendecompostionFn: ((Matrix<T>) throws -> MatrixEigenDecompositionResult<T>)) throws {
func eigen_decomposition_complex_results_dgeev_example_generic<T: FloatingPoint & ExpressibleByFloatLiteral>(defaultAccuracy: T, eigendecompostionFn: ((Matrix<T>) throws -> MatrixEigenDecompositionResult<T>)) throws {
let matrix = Matrix<T>(rows: 5, columns: 5, grid: [
-1.01, 0.86, -4.60, 3.31, -4.81,
3.98, 0.53, -7.04, 5.29, 3.55,
Expand Down Expand Up @@ -666,16 +666,16 @@ class MatrixTests: XCTestCase {
}
}

func testEigenDecompositionComplexResultsDGEEVExample() throws {
try testEigenDecompositionComplexResultsDGEEVExampleGeneric(defaultAccuracy: doubleAccuracy) { (m: Matrix<Double>) throws -> MatrixEigenDecompositionResult<Double> in
func test_eigen_decomposition_complex_results_dgeev_example() throws {
try eigen_decomposition_complex_results_dgeev_example_generic(defaultAccuracy: doubleAccuracy) { (m: Matrix<Double>) throws -> MatrixEigenDecompositionResult<Double> in
try eigenDecompose(m)
}
try testEigenDecompositionComplexResultsDGEEVExampleGeneric(defaultAccuracy: floatAccuracy) { (m: Matrix<Float>) throws -> MatrixEigenDecompositionResult<Float> in
try eigen_decomposition_complex_results_dgeev_example_generic(defaultAccuracy: floatAccuracy) { (m: Matrix<Float>) throws -> MatrixEigenDecompositionResult<Float> in
try eigenDecompose(m)
}
}

func testEigenDecomposeThrowsWhenNotSquare() throws {
func test_eigen_decompose_throws_when_not_square() throws {
let matrix = Matrix<Double>([
[1, 0, 0],
[0, 2, 0],
Expand Down