Skip to content
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

Fix fractfact_opt for Python3 #10

Merged
merged 4 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pyDOE3/doe_factorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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():
Expand Down
22 changes: 21 additions & 1 deletion tests/test_factorial.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -98,3 +98,23 @@ def test_factorial6(self):
]
actual = fracfact_by_res(6, 3)
np.testing.assert_allclose(actual, expected)

def test_issue_9(self):
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])
)
Loading