From ba31d673738965ba5801cd16748cb42c9bed3c99 Mon Sep 17 00:00:00 2001 From: relf Date: Wed, 12 Jun 2024 11:11:35 +0200 Subject: [PATCH 1/4] Add issue #9 test --- tests/test_factorial.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/test_factorial.py b/tests/test_factorial.py index 93d0bdc..dab0b0e 100644 --- a/tests/test_factorial.py +++ b/tests/test_factorial.py @@ -1,5 +1,5 @@ import unittest -from pyDOE3.doe_factorial import fullfact +from pyDOE3.doe_factorial import fracfact_opt, fullfact from pyDOE3.doe_factorial import ff2n from pyDOE3.doe_factorial import fracfact from pyDOE3.doe_factorial import fracfact_by_res @@ -98,3 +98,6 @@ def test_factorial6(self): ] actual = fracfact_by_res(6, 3) np.testing.assert_allclose(actual, expected) + + def test_issue_9(self): + fracfact_opt(4, 1) From fef70418cf5319072278948cff4d612d9a80789d Mon Sep 17 00:00:00 2001 From: relf Date: Wed, 12 Jun 2024 11:12:28 +0200 Subject: [PATCH 2/4] Fix integer division --- pyDOE3/doe_factorial.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyDOE3/doe_factorial.py b/pyDOE3/doe_factorial.py index 0942867..1006b99 100644 --- a/pyDOE3/doe_factorial.py +++ b/pyDOE3/doe_factorial.py @@ -406,7 +406,7 @@ def fracfact_opt(n_factors, n_erased, max_attempts=0): def n_comb(n, k): if k <= 0 or n <= 0 or k > n: return 0 - return math.factorial(n) / (math.factorial(k) * math.factorial(n - k)) + return math.factorial(n) // (math.factorial(k) * math.factorial(n - k)) if n_factors > 20: raise ValueError("Design too big, use 20 factors or less") From e6a8a88c198a0183d3a10cd59999b925bb9556a2 Mon Sep 17 00:00:00 2001 From: relf Date: Wed, 12 Jun 2024 11:21:12 +0200 Subject: [PATCH 3/4] Fix np.array data hashing --- pyDOE3/doe_factorial.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyDOE3/doe_factorial.py b/pyDOE3/doe_factorial.py index 1006b99..807415b 100644 --- a/pyDOE3/doe_factorial.py +++ b/pyDOE3/doe_factorial.py @@ -503,8 +503,8 @@ def fracfact_aliasing(design): for combination in all_combinations: contrast = np.prod(design[:, combination], axis=1) contrast.flags.writeable = False - aliases[contrast.data] = aliases.get(contrast.data, []) - aliases[contrast.data].append(combination) + aliases[contrast.data.tobytes()] = aliases.get(contrast.data.tobytes(), []) + aliases[contrast.data.tobytes()].append(combination) aliases_list = [] for alias in aliases.values(): From ccf3fd1152261b4201ff2623a5b3e67871942d10 Mon Sep 17 00:00:00 2001 From: relf Date: Wed, 12 Jun 2024 14:14:28 +0200 Subject: [PATCH 4/4] Assert returned value --- tests/test_factorial.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/tests/test_factorial.py b/tests/test_factorial.py index dab0b0e..a17a19f 100644 --- a/tests/test_factorial.py +++ b/tests/test_factorial.py @@ -100,4 +100,21 @@ def test_factorial6(self): np.testing.assert_allclose(actual, expected) def test_issue_9(self): - fracfact_opt(4, 1) + ffo_doe = fracfact_opt(4, 1) + self.assertEqual(ffo_doe[0], "a b c abc") + self.assertEqual( + ffo_doe[1], + [ + "a = bcd", + "b = acd", + "c = abd", + "d = abc", + "ab = cd", + "ac = bd", + "ad = bc", + "abcd", + ], + ) + np.testing.assert_array_equal( + ffo_doe[2], np.array([0.0, 0.0, 3.0, 4.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]) + )