This repository has been archived by the owner on Aug 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Add interface for word related functions #57
Open
mariatsalakou
wants to merge
10
commits into
libsemigroups:master
Choose a base branch
from
mariatsalakou:words
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+331
−1
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e745f93
Add interface for word related functions
mariatsalakou fc4da58
Updated __init__.py
mariatsalakou 004ab11
Updated __init__.py
mariatsalakou b453aaf
Updated __init__.py
mariatsalakou 90c8086
added test for siso
mariatsalakou 3d6f644
added tests for wil
mariatsalakou d7ddb1a
tests for wislo
mariatsalakou 8209bde
fixed syntax mistakes
mariatsalakou e249c6d
fixed syntax errors
mariatsalakou c72e760
Merge branch 'master' into words
james-d-mitchell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
""" | ||
This file contains the interface to libsemigroups actions; see | ||
|
||
https://libsemigroups.readthedocs.io/en/latest/words.html | ||
|
||
for further details. | ||
""" | ||
|
||
import cppyy | ||
|
||
from cppyy.gbl.libsemigroups import number_of_words | ||
|
||
from libsemigroups_cppyy.detail import ForwardRange | ||
|
||
from cppyy.gbl.libsemigroups import cbegin_wilo, cend_wilo | ||
|
||
from cppyy.gbl.libsemigroups import cbegin_wislo, cend_wislo | ||
|
||
from cppyy.gbl.libsemigroups import cbegin_sislo, cend_sislo | ||
|
||
from cppyy.gbl.libsemigroups import cbegin_silo, cend_silo | ||
|
||
def wilo(n, upper_bound, first, last): | ||
return ForwardRange( | ||
cppyy.gbl.libsemigroups.cbegin_wilo(n, upper_bound, first, last), | ||
cppyy.gbl.libsemigroups.cend_wilo(n, upper_bound, first, last),) | ||
|
||
def wislo(n, first, last): | ||
return ForwardRange( | ||
cppyy.gbl.libsemigroups.cbegin_wislo(n, first, last), | ||
cppyy.gbl.libsemigroups.cend_wislo(n, first, last),) | ||
|
||
def sislo(alphabet, first, last): | ||
return ForwardRange( | ||
cppyy.gbl.libsemigroups.cbegin_sislo(alphabet, first, last), | ||
cppyy.gbl.libsemigroups.cend_sislo(alphabet, first, last),) | ||
|
||
def silo(alphabet, upper_bound, first, last): | ||
return ForwardRange( | ||
cppyy.gbl.libsemigroups.cbegin_silo(alphabet, upper_bound, first, last), | ||
cppyy.gbl.libsemigroups.cend_silo(alphabet, upper_bound, first, last),) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import unittest, libsemigroups_cppyy | ||
from libsemigroups_cppyy import silo, sislo, number_of_words | ||
|
||
class TestSilo(unittest.TestCase): | ||
def test_001(self): | ||
u = "" | ||
v = "aaaaaaaaaa" | ||
w = [x for x in silo("a", 10, "", "aaaaaaaaaa")] | ||
self.assertEqual(len(w), 10) | ||
self.assertEqual(w, ['','a','aa','aaa','aaaa','aaaaa','aaaaaa','aaaaaaa','aaaaaaaa','aaaaaaaaa']) | ||
w = [x for x in silo("", 10 , "", "aaaaaaaaaa")] | ||
self.assertEqual(len(w), 1) | ||
w = [x for x in silo("a", 4, "aa", v)] | ||
self.assertEqual(w, ["aa", "aaa"]) | ||
|
||
def test_002(self): | ||
u = "" | ||
v = "aaaaaaaaaa" | ||
w1 = [x for x in silo("ab", 4, v, u)] | ||
self.assertEqual(w1, []) | ||
w2 = [x for x in silo("ab", 4, u, u)] | ||
self.assertEqual(w2, []) | ||
w3 = [x for x in silo("ab", 2, "a", "bb")] | ||
self.assertEqual(w3, ["a", "b"]) | ||
w4 = [x for x in silo("ab", 1, u, v)] | ||
self.assertEqual(w4, [""]) | ||
|
||
def test_003(self): | ||
w = [x for x in silo("ab", 4, "a", "bbbbb")] | ||
self.assertEqual(len(w), 14) | ||
self.assertEqual(w, ['a','aa','aaa','aab','ab','aba','abb','b','ba','baa','bab','bb','bba','bbb']) | ||
w = [x for x in silo("ba", 4, "b", "aaaaa")] | ||
self.assertEqual(w, ['b','bb','bbb','bba','ba','bab','baa','a','ab','abb','aba','aa','aab','aaa']) | ||
|
||
def test_004(self): | ||
w = [x for x in silo("abc", 13, "", "ccccccccccccc")] | ||
self.assertEqual(len(w), 797161) | ||
self.assertEqual(len(w), number_of_words(3, 0 , 13)) | ||
|
||
def test_005(self): | ||
first = "" | ||
last = "aaaaaaaaaa" | ||
w = [x for x in sislo("a", first, last)] | ||
self.assertEqual(len(w), 10) | ||
self.assertEqual(w, ["", "a", "aa", "aaa", "aaaa", "aaaaa", "aaaaaa", "aaaaaaa", "aaaaaaaa", "aaaaaaaaa"]) | ||
w = [x for x in sislo("a", "aa", "aaaa")] | ||
self.assertEqual(w, ["aa","aaa"]) | ||
|
||
def test_006(self): | ||
first = "" | ||
last = "bbaaab" | ||
w1 = [x for x in sislo("ab", last, first)] | ||
self.assertEqual(w1, []) | ||
w2 = [x for x in sislo("ab", first, first)] | ||
self.assertEqual(w2, []) | ||
w3 = [x for x in sislo("ab", "a", "aa")] | ||
self.assertEqual(w3, ["a", "b"]) | ||
w4 = [x for x in sislo("ab", first, last)] | ||
self.assertEqual(len(w4), 112) | ||
self.assertEqual(w4, ["", "a", "b", "aa", "ab", "ba","bb", "aaa", "aab", "aba", "abb", "baa", "bab", "bba", "bbb", "aaaa", "aaab", "aaba", "aabb", "abaa", "abab", "abba", "abbb", "baaa","baab", "baba", "babb", "bbaa", "bbab", "bbba","bbbb", "aaaaa", "aaaab", "aaaba", "aaabb", "aabaa","aabab", "aabba", "aabbb", "abaaa", "abaab", "ababa", "ababb", "abbaa", "abbab", "abbba", "abbbb", "baaaa","baaab", "baaba", "baabb", "babaa", "babab", "babba","babbb", "bbaaa", "bbaab", "bbaba", "bbabb", "bbbaa","bbbab", "bbbba", "bbbbb", "aaaaaa", "aaaaab", "aaaaba", "aaaabb", "aaabaa", "aaabab", "aaabba", "aaabbb", "aabaaa", "aabaab", "aababa", "aababb", "aabbaa", "aabbab", "aabbba","aabbbb", "abaaaa", "abaaab", "abaaba", "abaabb", "ababaa", "ababab", "ababba", "ababbb", "abbaaa", "abbaab", "abbaba","abbabb", "abbbaa", "abbbab", "abbbba", "abbbbb", "baaaaa","baaaab", "baaaba", "baaabb", "baabaa", "baabab", "baabba", "baabbb", "babaaa", "babaab", "bababa", "bababb", "babbaa","babbab", "babbba", "babbbb", "bbaaaa"]) | ||
|
||
def test_007(self): | ||
w = [ x for x in sislo("ab", "a", "aaaa")] | ||
self.assertEqual(w, ["a", "b", "aa", "ab", "ba", "bb", "aaa", "aab", "aba", "abb", "baa", "bab", "bba", "bbb"]) | ||
self.assertEqual(len(w), 14) | ||
w = [ x for x in sislo("ba", "b", "bbbb")] | ||
self.assertEqual(w, ["b", "a", "bb", "ba", "ab", "aa", "bbb", "bba", "bab", "baa", "abb", "aba", "aab", "aaa"]) | ||
|
||
def test_008(self): | ||
w = [x for x in sislo("abc", "", "aaaaaaaaaaaaa")] | ||
self.assertEqual(len(w), 797161) | ||
self.assertEqual(len(w), number_of_words(3, 0, 13)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import unittest, libsemigroups_cppyy | ||
from libsemigroups_cppyy import wilo, number_of_words | ||
|
||
class TestWilo(unittest.TestCase): | ||
def test_001(self): | ||
u = [0, 0, 0, 0] | ||
v = [1, 1, 1, 1] | ||
self.assertEqual([x for x in wilo(2,1,v,u)], []) | ||
self.assertEqual([x for x in wilo(2,1,u,u)], []) | ||
w1 = [x for x in wilo(2, 2, [], [1,1])] | ||
self.assertEqual(len(w1), 3) | ||
w2 = [] | ||
for i in range(0, len(w1)): | ||
w2.append([x for x in w1[i]]) | ||
self.assertEqual(w2, [[], [0], [1]]) | ||
w3 = [x for x in wilo(2, 1, [], [1,1])] | ||
self.assertEqual(len(w3), 1) | ||
self.assertEqual([x for x in w3[0]], []) | ||
w4 = [x for x in wilo(2, 1, [], [0])] | ||
self.assertEqual(len(w4), 1) | ||
self.assertEqual([x for x in w4[0]], []) | ||
def test_002(self): | ||
w = [ x for x in wilo(2, 4, [0], [1, 1, 1, 1])] | ||
u = [] | ||
for i in range(0, len(w)): | ||
u.append([x for x in w[i]]) | ||
self.assertEqual(u, [[0],[0,0],[0,0,0],[0,0,1],[0,1],[0,1,0],[0,1,1],[1],[1,0],[1,0,0],[1,0,1],[1,1],[1,1,0],[1,1,1]]) | ||
self.assertEqual(len(u), 14) | ||
def test_003(self): | ||
first = [0] | ||
last = [2, 2, 2, 2] | ||
w = [x for x in wilo(3, 4, first, last)] | ||
u = [] | ||
self.assertEqual(len(w), 39) | ||
self.assertEqual(len(w), number_of_words(3,1,4)) | ||
for i in range(0, len(w)): | ||
u.append([x for x in w[i]]) | ||
self.assertEqual(u, [[0], [0, 0], [0, 0, 0], [0, 0, 1], [0, 0, 2], [0, 1], [0, 1, 0], [0, 1, 1], [0, 1, 2], [0, 2], [0, 2, 0], [0, 2, 1], [0, 2, 2], [1], [1, 0], [1, 0, 0], [1, 0, 1], [1, 0, 2], [1, 1], [1, 1, 0], [1, 1, 1], [1, 1, 2], [1, 2], [1, 2, 0], [1, 2, 1], [1, 2, 2], [2], [2, 0], [2, 0, 0], [2, 0, 1], [2, 0, 2], [2, 1], [2, 1, 0],[2, 1, 1],[2, 1, 2],[2, 2], [2, 2, 0], [2, 2, 1], [2, 2, 2]]) | ||
|
||
def test_004(self): | ||
first = [] | ||
last = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2] | ||
w = [x for x in wilo(3, 10, first, last)] | ||
self.assertEqual(len(w), 29524) | ||
self.assertEqual(len(w), number_of_words(3, 0, 10)) | ||
|
||
def test_004(self): | ||
first = [] | ||
last = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2] | ||
w = [x for x in wilo(3, 13, first, last)] | ||
self.assertEqual(len(w), 797161) | ||
self.assertEqual(len(w), number_of_words(3, 0, 13)) | ||
|
||
def test_005(self): | ||
first = [] | ||
last = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] | ||
w = [ x for x in wilo(1, 10, first, last)] | ||
self.assertEqual(len(w), 10) | ||
u = [] | ||
for i in range(0, len(w)): | ||
u.append([x for x in w[i]]) | ||
self.assertEqual(u, [[], | ||
[0], | ||
[0, 0], | ||
[0, 0, 0], | ||
[0, 0, 0, 0], | ||
[0, 0, 0, 0, 0], | ||
[0, 0, 0, 0, 0, 0], | ||
[0, 0, 0, 0, 0, 0, 0], | ||
[0, 0, 0, 0, 0, 0, 0, 0], | ||
[0, 0, 0, 0, 0, 0, 0, 0, 0]]) | ||
w = [ x for x in wilo(0, 0, first, last)] | ||
self.assertEqual(w, []) | ||
first = [0, 0] | ||
last = [0, 0, 0, 0] | ||
w = [x for x in wilo(1, 4, first, last)] | ||
self.assertEqual(len(w), 2) | ||
self.assertEqual([x for x in w[0]], [0, 0]) | ||
self.assertEqual([x for x in w[1]], [0, 0, 0]) | ||
w = [x for x in wilo(1, 1, first, last)] | ||
self.assertEqual(w, []) | ||
w = [x for x in wilo(1, 5, [0], [1])] | ||
self.assertEqual(len(w), 4) | ||
u = [] | ||
for i in range(0, len(w)): | ||
u.append([x for x in w[i]]) | ||
self.assertEqual(u, [[0], [0, 0], [0, 0, 0], [0, 0, 0, 0]]) | ||
|
||
def test_006(self): | ||
first = [0, 1, 2, 3] | ||
last = [4, 4, 4, 4, 4] | ||
w = [x for x in wilo(4, 5, first, last)] | ||
self.assertEqual(len(w), 303) | ||
|
||
def test_007(self): | ||
first = [0, 1] | ||
last = [1, 1, 1] | ||
w = [ x for x in wilo(2, 3, first, last) ] | ||
self.assertEqual(len(w), 4) | ||
u = [] | ||
for i in range(0, len(w)): | ||
u.append([x for x in w[i]]) | ||
self.assertEqual(u, [[0, 1], [1], [1, 0], [1, 1]]) | ||
w = [ x for x in wilo(2, 1, first, last) ] | ||
self.assertEqual(w, []) | ||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import unittest, libsemigroups_cppyy | ||
from libsemigroups_cppyy import wislo, number_of_words | ||
|
||
class WisloTests(unittest.TestCase): | ||
def test_000(self): | ||
first = [0] | ||
last = [0, 0, 0, 0] | ||
w = [x for x in wislo(2, first, last)] | ||
self.assertEqual(len(w), 14) | ||
u = [] | ||
for i in range(0, len(w)): | ||
u.append([x for x in w[i]]) | ||
self.assertEqual(u, [[0], | ||
[1], | ||
[0, 0], | ||
[0, 1], | ||
[1, 0], | ||
[1, 1], | ||
[0, 0, 0], | ||
[0, 0, 1], | ||
[0, 1, 0], | ||
[0, 1, 1], | ||
[1, 0, 0], | ||
[1, 0, 1], | ||
[1, 1, 0], | ||
[1, 1, 1]]) | ||
def test_001(self): | ||
first = [0, 0, 0, 0] | ||
last = [0, 0, 0, 0, 0] | ||
w1 = [x for x in wislo(2, last, first)] | ||
self.assertEqual(w1, []) | ||
w2 = [x for x in wislo(2, last, last)] | ||
self.assertEqual(w2, []) | ||
w3 = [x for x in wislo(2, last, [0,0,0,0,0,0])] | ||
self.assertEqual(len(w3), 32) | ||
u = [] | ||
for i in range(0, len(w3)): | ||
u.append([x for x in w3[i]]) | ||
self.assertEqual(u, [[0, 0, 0, 0, 0], | ||
[0, 0, 0, 0, 1], | ||
[0, 0, 0, 1, 0], | ||
[0, 0, 0, 1, 1], | ||
[0, 0, 1, 0, 0], | ||
[0, 0, 1, 0, 1], | ||
[0, 0, 1, 1, 0], | ||
[0, 0, 1, 1, 1], | ||
[0, 1, 0, 0, 0], | ||
[0, 1, 0, 0, 1], | ||
[0, 1, 0, 1, 0], | ||
[0, 1, 0, 1, 1], | ||
[0, 1, 1, 0, 0], | ||
[0, 1, 1, 0, 1], | ||
[0, 1, 1, 1, 0], | ||
[0, 1, 1, 1, 1], | ||
[1, 0, 0, 0, 0], | ||
[1, 0, 0, 0, 1], | ||
[1, 0, 0, 1, 0], | ||
[1, 0, 0, 1, 1], | ||
[1, 0, 1, 0, 0], | ||
[1, 0, 1, 0, 1], | ||
[1, 0, 1, 1, 0], | ||
[1, 0, 1, 1, 1], | ||
[1, 1, 0, 0, 0], | ||
[1, 1, 0, 0, 1], | ||
[1, 1, 0, 1, 0], | ||
[1, 1, 0, 1, 1], | ||
[1, 1, 1, 0, 0], | ||
[1, 1, 1, 0, 1], | ||
[1, 1, 1, 1, 0], | ||
[1, 1, 1, 1, 1]]) | ||
def test_002(self): | ||
first = [] | ||
last = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] | ||
w = [ x for x in wislo(3, first, last)] | ||
self.assertEqual(len(w), 29524) | ||
self.assertEqual(len(w), number_of_words(3, 0, 10)) | ||
|
||
def test_003(self): | ||
first = [] | ||
last = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] | ||
w = [ x for x in wislo(3, first, last)] | ||
self.assertEqual(len(w), 797161) | ||
self.assertEqual(len(w), number_of_words(3, 0, 13)) | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import unittest, libsemigroups_cppyy | ||
from libsemigroups_cppyy import number_of_words | ||
|
||
|
||
class TestNumberOfWords(unittest.TestCase): | ||
def test_000(self): | ||
self.assertEqual(number_of_words(3, 1, 4), 39) | ||
self.assertEqual(number_of_words(3, 0, 10), 29524) | ||
self.assertEqual(number_of_words(2, 5, 6), 32) | ||
self.assertEqual(number_of_words(3, 0, 13), 797161) | ||
self.assertEqual(number_of_words(2, 4, 1), 0) | ||
self.assertEqual(number_of_words(2, 4, 4), 0) | ||
self.assertEqual(number_of_words(2, 4, 2), 0) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can fix this by doing: