Skip to content

Commit

Permalink
Fix test file formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
msricher committed Mar 7, 2024
1 parent 1896b34 commit 9f96858
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 68 deletions.
34 changes: 15 additions & 19 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

import sphinx_rtd_theme

import permanent

# -- Path setup --------------------------------------------------------------

# If extensions (or modules to document with autodoc) are in another directory,
Expand All @@ -21,9 +17,9 @@

# -- Project information -----------------------------------------------------

project = 'Permanent'
copyright = '2022, QC-Devs'
author = 'QC-Devs'
project = "Permanent"
copyright = "2024, QC-Devs"
author = "QC-Devs"


# -- General configuration ---------------------------------------------------
Expand All @@ -32,15 +28,15 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.autosummary',
'sphinx.ext.napoleon',
'sphinx.ext.mathjax',
'sphinx_copybutton',
"sphinx.ext.autodoc",
"sphinx.ext.autosummary",
"sphinx.ext.napoleon",
"sphinx.ext.mathjax",
"sphinx_copybutton",
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
Expand All @@ -52,19 +48,19 @@

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = 'sphinx_rtd_theme'
html_theme = "sphinx_rtd_theme"

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
pygments_style = 'sphinx'
html_static_path = ["_static"]
pygments_style = "sphinx"


mathjax_path = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.6/MathJax.js'
mathjax_path = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.6/MathJax.js"


mathjax_config = {
'extensions': ['tex2jax.js'],
'jax': ['input/TeX', 'output/HTML-CSS'],
"extensions": ["tex2jax.js"],
"jax": ["input/TeX", "output/HTML-CSS"],
}
157 changes: 111 additions & 46 deletions permanent/test/test_permanent.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,173 +2,238 @@
import math
import permanent

REL_ERROR = 0.0001;

## Test square matrices
REL_ERROR = 0.0001


# Test square matrices
def test_2by2_comb():
matrix = np.arange(1, 5, dtype=np.double).reshape(2,2)
matrix = np.arange(1, 5, dtype=np.double).reshape(2, 2)
assert abs((permanent.combinatoric(matrix) - 10) / 10) <= REL_ERROR


def test_2by2_glynn():
matrix = np.arange(1, 5, dtype=np.double).reshape(2,2)
matrix = np.arange(1, 5, dtype=np.double).reshape(2, 2)
assert abs((permanent.glynn(matrix) - 10) / 10) <= REL_ERROR


def test_2by2_ryser():
matrix = np.arange(1, 5, dtype=np.double).reshape(2,2)
matrix = np.arange(1, 5, dtype=np.double).reshape(2, 2)
assert abs((permanent.ryser(matrix) - 10) / 10) <= REL_ERROR


def test_3by3_comb():
matrix = np.arange(1, 10, dtype=np.double).reshape(3,3)
matrix = np.arange(1, 10, dtype=np.double).reshape(3, 3)
assert abs((permanent.combinatoric(matrix) - 450) / 450) <= REL_ERROR


def test_3by3_glynn():
matrix = np.arange(1, 10, dtype=np.double).reshape(3,3)
matrix = np.arange(1, 10, dtype=np.double).reshape(3, 3)
assert abs((permanent.glynn(matrix) - 450) / 450) <= REL_ERROR


def test_3by3_ryser():
matrix = np.arange(1, 10, dtype=np.double).reshape(3,3)
matrix = np.arange(1, 10, dtype=np.double).reshape(3, 3)
assert abs((permanent.ryser(matrix) - 450) / 450) <= REL_ERROR


def test_4by4_comb():
matrix = np.arange(1, 17, dtype=np.double).reshape(4,4)
matrix = np.arange(1, 17, dtype=np.double).reshape(4, 4)
assert abs((permanent.combinatoric(matrix) - 55456) / 55456) <= REL_ERROR


def test_4by4_glynn():
matrix = np.arange(1, 17, dtype=np.double).reshape(4,4)
matrix = np.arange(1, 17, dtype=np.double).reshape(4, 4)
assert abs((permanent.glynn(matrix) - 55456) / 55456) <= REL_ERROR


def test_4by4_ryser():
matrix = np.arange(1, 17, dtype=np.double).reshape(4,4)
matrix = np.arange(1, 17, dtype=np.double).reshape(4, 4)
assert abs((permanent.ryser(matrix) - 55456) / 55456) <= REL_ERROR


def test_7by7_comb():
matrix = np.arange(1, 50, dtype=np.double).reshape(7,7)
assert abs((permanent.combinatoric(matrix) - 5373548250000) / 5373548250000) <= REL_ERROR
matrix = np.arange(1, 50, dtype=np.double).reshape(7, 7)
assert (
abs((permanent.combinatoric(matrix) - 5373548250000) / 5373548250000)
<= REL_ERROR
)


def test_7by7_glynn():
matrix = np.arange(1, 50, dtype=np.double).reshape(7,7)
matrix = np.arange(1, 50, dtype=np.double).reshape(7, 7)
assert abs((permanent.glynn(matrix) - 5373548250000) / 5373548250000) <= REL_ERROR


def test_7by7_ryser():
matrix = np.arange(1, 50, dtype=np.double).reshape(7,7)
matrix = np.arange(1, 50, dtype=np.double).reshape(7, 7)
assert abs((permanent.ryser(matrix) - 5373548250000) / 5373548250000) <= REL_ERROR


## Test rectangular matrices
def test_2by3_comb():
matrix = np.arange(1, 7, dtype=np.double).reshape(2,3)
matrix = np.arange(1, 7, dtype=np.double).reshape(2, 3)
assert abs((permanent.combinatoric(matrix) - 58) / 58) <= REL_ERROR


def test_2by3_glynn():
matrix = np.arange(1, 7, dtype=np.double).reshape(2,3)
matrix = np.arange(1, 7, dtype=np.double).reshape(2, 3)
assert abs((permanent.glynn(matrix) - 58) / 58) <= REL_ERROR


def test_2by3_ryser():
matrix = np.arange(1, 7, dtype=np.double).reshape(2,3)
matrix = np.arange(1, 7, dtype=np.double).reshape(2, 3)
assert abs((permanent.ryser(matrix) - 58) / 58) <= REL_ERROR


def test_2by4_comb():
matrix = np.arange(1, 9, dtype=np.double).reshape(2,4)
matrix = np.arange(1, 9, dtype=np.double).reshape(2, 4)
assert abs((permanent.combinatoric(matrix) - 190) / 190) <= REL_ERROR


def test_2by4_glynn():
matrix = np.arange(1, 9, dtype=np.double).reshape(2,4)
matrix = np.arange(1, 9, dtype=np.double).reshape(2, 4)
assert abs((permanent.glynn(matrix) - 190) / 190) <= REL_ERROR


def test_2by4_ryser():
matrix = np.arange(1, 9, dtype=np.double).reshape(2,4)
matrix = np.arange(1, 9, dtype=np.double).reshape(2, 4)
assert abs((permanent.ryser(matrix) - 190) / 190) <= REL_ERROR


def test_2by7_comb():
matrix = np.arange(1, 15, dtype=np.double).reshape(2,7)
matrix = np.arange(1, 15, dtype=np.double).reshape(2, 7)
assert abs((permanent.combinatoric(matrix) - 1820) / 1820) <= REL_ERROR


def test_2by7_glynn():
matrix = np.arange(1, 15, dtype=np.double).reshape(2,7)
matrix = np.arange(1, 15, dtype=np.double).reshape(2, 7)
assert abs((permanent.glynn(matrix) - 1820) / 1820) <= REL_ERROR


def test_2by7_ryser():
matrix = np.arange(1, 15, dtype=np.double).reshape(2,7)
matrix = np.arange(1, 15, dtype=np.double).reshape(2, 7)
assert abs((permanent.ryser(matrix) - 1820) / 1820) <= REL_ERROR


def test_5by7_comb():
matrix = np.arange(1, 36, dtype=np.double).reshape(5,7)
matrix = np.arange(1, 36, dtype=np.double).reshape(5, 7)
assert abs((permanent.combinatoric(matrix) - 1521238320) / 1521238320) <= REL_ERROR


def test_5by7_glynn():
matrix = np.arange(1, 36, dtype=np.double).reshape(5,7)
matrix = np.arange(1, 36, dtype=np.double).reshape(5, 7)
assert abs((permanent.glynn(matrix) - 1521238320) / 1521238320) <= REL_ERROR


def test_5by7_ryser():
matrix = np.arange(1, 36, dtype=np.double).reshape(5,7)
matrix = np.arange(1, 36, dtype=np.double).reshape(5, 7)
assert abs((permanent.ryser(matrix) - 1521238320) / 1521238320) <= REL_ERROR


def test_6by7_comb():
matrix = np.arange(1, 43, dtype=np.double).reshape(6,7)
assert abs((permanent.combinatoric(matrix) - 117681979920) / 117681979920) <= REL_ERROR
matrix = np.arange(1, 43, dtype=np.double).reshape(6, 7)
assert (
abs((permanent.combinatoric(matrix) - 117681979920) / 117681979920) <= REL_ERROR
)


def test_6by7_glynn():
matrix = np.arange(1, 43, dtype=np.double).reshape(6,7)
matrix = np.arange(1, 43, dtype=np.double).reshape(6, 7)
assert abs((permanent.glynn(matrix) - 117681979920) / 117681979920) <= REL_ERROR


def test_6by7_ryser():
matrix = np.arange(1, 43, dtype=np.double).reshape(6,7)
matrix = np.arange(1, 43, dtype=np.double).reshape(6, 7)
assert abs((permanent.ryser(matrix) - 117681979920) / 117681979920) <= REL_ERROR


def test_ones_comb():
matrix = np.ones((10,10), dtype=np.double)
assert abs((permanent.combinatoric(matrix) - math.factorial(10)) / math.factorial(10)) <= REL_ERROR
matrix = np.ones((10, 10), dtype=np.double)
assert (
abs((permanent.combinatoric(matrix) - math.factorial(10)) / math.factorial(10))
<= REL_ERROR
)


def test_ones_ryser():
matrix = np.ones((10,10), dtype=np.double)
assert abs((permanent.ryser(matrix) - math.factorial(10)) / math.factorial(10)) <= REL_ERROR
matrix = np.ones((10, 10), dtype=np.double)
assert (
abs((permanent.ryser(matrix) - math.factorial(10)) / math.factorial(10))
<= REL_ERROR
)


def test_ones_glynn():
matrix = np.ones((10,10), dtype=np.double)
assert abs((permanent.glynn(matrix) - math.factorial(10)) / math.factorial(10)) <= REL_ERROR
matrix = np.ones((10, 10), dtype=np.double)
assert (
abs((permanent.glynn(matrix) - math.factorial(10)) / math.factorial(10))
<= REL_ERROR
)


def test_ones_comb_big():
matrix = np.ones((12,12), dtype=np.double)
assert abs((permanent.combinatoric(matrix) - math.factorial(12)) / math.factorial(12)) <= REL_ERROR
matrix = np.ones((12, 12), dtype=np.double)
assert (
abs((permanent.combinatoric(matrix) - math.factorial(12)) / math.factorial(12))
<= REL_ERROR
)


def test_ones_ryser_big():
matrix = np.ones((12,12), dtype=np.double)
assert abs((permanent.ryser(matrix) - math.factorial(12)) / math.factorial(12)) <= REL_ERROR
matrix = np.ones((12, 12), dtype=np.double)
assert (
abs((permanent.ryser(matrix) - math.factorial(12)) / math.factorial(12))
<= REL_ERROR
)


def test_ones_glynn_big():
matrix = np.ones((12,12), dtype=np.double)
assert abs((permanent.glynn(matrix) - math.factorial(12)) / math.factorial(12)) <= REL_ERROR
matrix = np.ones((12, 12), dtype=np.double)
assert (
abs((permanent.glynn(matrix) - math.factorial(12)) / math.factorial(12))
<= REL_ERROR
)


def test_identity_comb():
matrix = np.identity(10, dtype=np.double)
assert abs((permanent.combinatoric(matrix) - 1) / 1) <= REL_ERROR


def test_identity_ryser():
matrix = np.identity(10, dtype=np.double)
assert abs((permanent.ryser(matrix) - 1) / 1) <= REL_ERROR


def test_identity_glynn():
matrix = np.identity(10, dtype=np.double)
assert abs((permanent.glynn(matrix) - 1) / 1) <= REL_ERROR


def test_identity_ryser_odd():
matrix = np.identity(5, dtype=np.double)
assert abs((permanent.ryser(matrix) - 1) / 1) <= REL_ERROR


def test_identity_glynn_odd():
matrix = np.identity(5, dtype=np.double)
assert abs((permanent.glynn(matrix) - 1) / 1) <= REL_ERROR


def test_identity_comb_diag():
matrix = np.ones((3,7), dtype=np.double)
matrix = np.ones((3, 7), dtype=np.double)
diag_matrix = np.diag(np.diag(matrix))
assert abs((permanent.combinatoric(diag_matrix) - 1) / 1) <= REL_ERROR


def test_identity_ryser_diag():
matrix = np.ones((3,7), dtype=np.double)
matrix = np.ones((3, 7), dtype=np.double)
diag_matrix = np.diag(np.diag(matrix))
assert abs((permanent.ryser(diag_matrix) - 1) / 1) <= REL_ERROR


def test_identity_glynn_diag():
matrix = np.ones((3,7), dtype=np.double)
matrix = np.ones((3, 7), dtype=np.double)
diag_matrix = np.diag(np.diag(matrix))
assert abs((permanent.glynn(diag_matrix) - 1) / 1) <= REL_ERROR
3 changes: 0 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

from setuptools import setup

import numpy as np


name = "permanent"

Expand Down Expand Up @@ -61,7 +59,6 @@


if __name__ == "__main__":

setup(
name=name,
version=version,
Expand Down

0 comments on commit 9f96858

Please sign in to comment.