From 35abe8873129c0fc820fffb16adb3c5a92603b8d Mon Sep 17 00:00:00 2001 From: Bjorn Date: Sat, 13 Jun 2020 03:39:52 +0200 Subject: [PATCH 1/7] Changed how pyrival is imported --- pyrival/__init__.py | 18 ++--- pyrival/algebra/__init__.py | 41 ----------- pyrival/combinatorics/__init__.py | 20 ------ pyrival/data_structures/__init__.py | 68 ------------------- pyrival/geometry/__init__.py | 23 ------- pyrival/graphs/__init__.py | 39 ----------- pyrival/linear_algebra/__init__.py | 17 ----- pyrival/misc/__init__.py | 40 ----------- pyrival/numerical/__init__.py | 28 -------- pyrival/strings/__init__.py | 8 --- pyrival/tools/__init__.py | 3 - tests/algebra/test_chinese_remainder.py | 8 +-- tests/algebra/test_discrete_log.py | 6 +- tests/algebra/test_factors.py | 10 +-- tests/algebra/test_gcd.py | 9 ++- tests/algebra/test_is_prime.py | 22 +++--- tests/algebra/test_modinv.py | 9 ++- tests/algebra/test_phi.py | 7 +- tests/algebra/test_sieve.py | 5 +- tests/combinatorics/test_combinatorics.py | 15 ++-- tests/data_structures/test_BitArray.py | 4 +- tests/data_structures/test_RangeQuery.py | 4 +- tests/data_structures/test_SegmentTree.py | 4 +- .../data_structures/test_convex_hull_trick.py | 2 +- tests/graphs/test_maximum_matching.py | 17 +++-- tests/misc/test_as_integer_ratio.py | 7 +- tests/misc/test_bootstrap.py | 4 +- tests/misc/test_order_statistic.py | 5 +- tests/misc/test_readnumbers.py | 5 +- tests/numerical/test_iroot.py | 5 +- tests/numerical/test_search.py | 14 ++-- tests/strings/test_kmp.py | 9 +-- 32 files changed, 81 insertions(+), 395 deletions(-) delete mode 100644 pyrival/algebra/__init__.py delete mode 100644 pyrival/combinatorics/__init__.py delete mode 100644 pyrival/data_structures/__init__.py delete mode 100644 pyrival/geometry/__init__.py delete mode 100644 pyrival/graphs/__init__.py delete mode 100644 pyrival/linear_algebra/__init__.py delete mode 100644 pyrival/misc/__init__.py delete mode 100644 pyrival/numerical/__init__.py delete mode 100644 pyrival/strings/__init__.py delete mode 100644 pyrival/tools/__init__.py diff --git a/pyrival/__init__.py b/pyrival/__init__.py index 899e030..64fb941 100644 --- a/pyrival/__init__.py +++ b/pyrival/__init__.py @@ -1,14 +1,6 @@ -from .algebra import * -from .combinatorics import * -from .data_structures import * -from .geometry import * -from .graphs import * -from .linear_algebra import * -from .numerical import * -from .strings import * -from .version import version +from .version import version as __version__ -__version__ = version - -__all__ = (algebra.__all__ + combinatorics.__all__ + data_structures.__all__ + geometry.__all__ + graphs.__all__ + - linear_algebra.__all__ + numerical.__all__ + strings.__all__) +import os as _os +for s in ('algebra', 'combinatorics', 'data_structures', 'geometry', + 'graphs', 'linear_algebra', 'numerical', 'strings', 'misc', 'tools'): + __path__.append(_os.path.join(__path__[0], s)) diff --git a/pyrival/algebra/__init__.py b/pyrival/algebra/__init__.py deleted file mode 100644 index 71b4f9d..0000000 --- a/pyrival/algebra/__init__.py +++ /dev/null @@ -1,41 +0,0 @@ -from . import ntt -from .chinese_remainder import chinese_remainder, composite_crt -from .discrete_log import discrete_log -from .factors import all_factors, distinct_factors, pollard_rho, prime_factors -from .fft import fft, fft_conv -from .fst import fst, fst_conv -from .gcd import extended_gcd, gcd, gcdm, lcm, lcmm -from .is_prime import is_prime -from .mod_sqrt import mod_sqrt -from .modinv import modinv -from .phi import phi -from .primitive_root import ilog, primitive_root -from .sieve import prime_list, prime_sieve - -__all__ = [ - "ntt", - "chinese_remainder", - "composite_crt", - "discrete_log", - "all_factors", - "distinct_factors", - "pollard_rho", - "prime_factors", - "fft", - "fft_conv", - "fst", - "fst_conv", - "extended_gcd", - "gcd", - "gcdm", - "lcm", - "lcmm", - "is_prime", - "mod_sqrt", - "modinv", - "phi", - "ilog", - "primitive_root", - "prime_list", - "prime_sieve", -] diff --git a/pyrival/combinatorics/__init__.py b/pyrival/combinatorics/__init__.py deleted file mode 100644 index d66f7ba..0000000 --- a/pyrival/combinatorics/__init__.py +++ /dev/null @@ -1,20 +0,0 @@ -from .combinatorics import (bell, catalan, catalan_recursive, derangements, euler, euler_recursive, multinomial, nCr, - stirling_1_recursive, stirling_2, stirling_2_recursive) -from .nCr_mod import make_nCr_mod -from .partitions import partition - -__all__ = [ - "bell", - "catalan", - "catalan_recursive", - "derangements", - "euler", - "euler_recursive", - "multinomial", - "nCr", - "stirling_1_recursive", - "stirling_2", - "stirling_2_recursive", - "make_nCr_mod", - "partition", -] diff --git a/pyrival/data_structures/__init__.py b/pyrival/data_structures/__init__.py deleted file mode 100644 index 3ac4bed..0000000 --- a/pyrival/data_structures/__init__.py +++ /dev/null @@ -1,68 +0,0 @@ -from .BitArray import BitArray -from .CFraction import CFrac2Frac, CFraction -from .convex_hull_trick import convex_hull_trick, max_query -from .DisjointSetUnion import DisjointSetUnion, UnionFind -from .FenwickTree import FenwickTree -from .Fraction import Fraction, limit_denominator -from .Heap import Heap, OrderHeap, RemovalHeap, XHeap -from .LazySegmentTree import LazySegmentTree -from .LinkedList import LinkedList -from .Node import Node -from .PersistentSegTree import create, minimum, setter -from .RangeQuery import RangeQuery -from .SegmentTree import SegmentTree -from .SortedList import SortedList -from .Treap import (TreapHashMap, TreapHashSet, TreapMultiSet, TreapSet, treap_builder, treap_ceiling, - treap_create_node, treap_erase, treap_floor, treap_higher, treap_insert, treap_insert_unique, - treap_keys, treap_lower, treap_max, treap_merge, treap_min, treap_prior, treap_split) -from .tree_repr import tree_repr -from .Trie import Trie -from .TwoSat import TwoSat - -__all__ = [ - "BitArray", - "CFrac2Frac", - "CFraction", - "convex_hull_trick", - "DisjointSetUnion", - "UnionFind", - "FenwickTree", - "Fraction", - "limit_denominator", - "Heap", - "OrderHeap", - "RemovalHeap", - "XHeap", - "LazySegmentTree", - "LinkedList", - "Node", - "create", - "max_query", - "minimum", - "setter", - "RangeQuery", - "SegmentTree", - "SortedList", - "TreapHashMap", - "TreapHashSet", - "TreapMultiSet", - "TreapSet", - "treap_builder", - "treap_ceiling", - "treap_create_node", - "treap_erase", - "treap_floor", - "treap_higher", - "treap_insert", - "treap_insert_unique", - "treap_keys", - "treap_lower", - "treap_max", - "treap_merge", - "treap_min", - "treap_prior", - "treap_split", - "tree_repr", - "Trie", - "TwoSat", -] diff --git a/pyrival/geometry/__init__.py b/pyrival/geometry/__init__.py deleted file mode 100644 index b081193..0000000 --- a/pyrival/geometry/__init__.py +++ /dev/null @@ -1,23 +0,0 @@ -from .convex_hull import convex_hull -from .lines import collinear, dist, get_2dline, intersect, is_parallel, is_same, rotate -from .vectors import angle, closest_point, cross2d, cross3d, dot, norm_sq, scale, to_vec, translate - -__all__ = [ - "convex_hull", - "collinear", - "dist", - "get_2dline", - "intersect", - "is_parallel", - "is_same", - "rotate", - "angle", - "closest_point", - "cross2d", - "cross3d", - "dot", - "norm_sq", - "scale", - "to_vec", - "translate", -] diff --git a/pyrival/graphs/__init__.py b/pyrival/graphs/__init__.py deleted file mode 100644 index e99428a..0000000 --- a/pyrival/graphs/__init__.py +++ /dev/null @@ -1,39 +0,0 @@ -from .bellman_ford import bellman_ford -from .bfs import bfs, layers -from .components import connected_components -from .cycle_finding import cycle_finding -from .dfs import dfs -from .dijkstra import dijkstra -from .dinic import Dinic -from .euler_walk import euler_walk -from .find_path import find_path -from .floyd_warshall import floyd_warshall -from .is_bipartite import is_bipartite -from .kruskal import kruskal -from .lca import LCA -from .maximum_matching import maximum_matching -from .prim import prim -from .scc import scc -from .toposort import kahn, toposort - -__all__ = [ - "bellman_ford", - "bfs", - "layers", - "connected_components", - "cycle_finding", - "dfs", - "dijkstra", - "Dinic", - "euler_walk", - "find_path", - "floyd_warshall", - "is_bipartite", - "maximum_matching", - "kruskal", - "LCA", - "prim", - "scc", - "kahn", - "toposort", -] diff --git a/pyrival/linear_algebra/__init__.py b/pyrival/linear_algebra/__init__.py deleted file mode 100644 index 4d56f37..0000000 --- a/pyrival/linear_algebra/__init__.py +++ /dev/null @@ -1,17 +0,0 @@ -from .matrix import eye, mat_add, mat_inv, mat_mul, mat_pow, mat_sub, minor, transpose, vec_mul -from .multivariable_crt import is_sol, mcrt, pivot - -__all__ = [ - "eye", - "mat_add", - "mat_inv", - "mat_mul", - "mat_pow", - "mat_sub", - "minor", - "transpose", - "vec_mul", - "is_sol", - "mcrt", - "pivot", -] diff --git a/pyrival/misc/__init__.py b/pyrival/misc/__init__.py deleted file mode 100644 index d6f4e6c..0000000 --- a/pyrival/misc/__init__.py +++ /dev/null @@ -1,40 +0,0 @@ -from .alphabeta import AlphaBetaNode, alphabeta -from .as_integer_ratio import as_integer_ratio -from .bit_hacks import least_bit, next_mask, subset_masks, sum_of_subsets -from .bootstrap import bootstrap -from .cumsum2d import cumsum2d -from .FastIO import FastIO, IOWrapper, input -from .lis import lis -from .memoize import memodict, memoize -from .ordersort import ordersort, long_ordersort, multikey_ordersort -from .order_statistic import order_statistic -from .ostream import cout, endl, ostream -from .readnumbers import readnumbers -from .split import split - -__all__ = [ - "AlphaBetaNode", - "alphabeta", - "as_integer_ratio", - "least_bit", - "next_mask", - "subset_masks", - "sum_of_subsets", - "bootstrap", - "cumsum2d", - "FastIO", - "IOWrapper", - "input", - "lis", - "memodict", - "memoize", - "order_statistic", - "ordersort", - "cout", - "endl", - "ostream", - "readnumbers", - "split", - "long_ordersort", - "multikey_ordersort", -] diff --git a/pyrival/numerical/__init__.py b/pyrival/numerical/__init__.py deleted file mode 100644 index 5180c02..0000000 --- a/pyrival/numerical/__init__.py +++ /dev/null @@ -1,28 +0,0 @@ -from . import berlekamp_massey -from .hill_climbing import hill_climbing -from .integrate import fast_quad, quad, rec, simpson -from .interpolate import interpolate -from .iroot import iroot -from .polynomial import diff, divroot, poly -from .search import (binary_search, discrete_binary_search, discrete_ternary_search, fractional_binary_search, - golden_section_search, ternary_search) - -__all__ = [ - "berlekamp_massey", - "hill_climbing", - "fast_quad", - "quad", - "rec", - "simpson", - "interpolate", - "iroot", - "diff", - "divroot", - "poly", - "binary_search", - "discrete_binary_search", - "discrete_ternary_search", - "fractional_binary_search", - "golden_section_search", - "ternary_search", -] diff --git a/pyrival/strings/__init__.py b/pyrival/strings/__init__.py deleted file mode 100644 index 7a51267..0000000 --- a/pyrival/strings/__init__.py +++ /dev/null @@ -1,8 +0,0 @@ -from .hashing import Hashing -from .kmp import match, partial, string_find -from .lcs import lcs -from .LCSubstr import LCSubstr -from .LPSubstr import LPSubstr -from .min_rotation import least_rotation - -__all__ = ["Hashing", "match", "partial", "string_find", "lcs", "LCSubstr", "LPSubstr", "least_rotation"] diff --git a/pyrival/tools/__init__.py b/pyrival/tools/__init__.py deleted file mode 100644 index 32c1d42..0000000 --- a/pyrival/tools/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -from .stress_tester import cmd2func, func2judge, stress_tester - -__all__ = ["cmd2func", "func2judge", "stress_tester"] diff --git a/tests/algebra/test_chinese_remainder.py b/tests/algebra/test_chinese_remainder.py index 0cd66a4..e444b17 100644 --- a/tests/algebra/test_chinese_remainder.py +++ b/tests/algebra/test_chinese_remainder.py @@ -1,22 +1,20 @@ import random -import pyrival.algebra - +from pyrival.chinese_remainder import * def test_chinese_remainder(primes): for _ in range(1000): l = random.randint(2, 100) p = random.sample(primes, l) a = [random.randint(0, p[i] - 1) for i in range(l)] - x = pyrival.algebra.chinese_remainder(a, p) + x = chinese_remainder(a, p) assert [x % i for i in p] == a - def test_composite_crt(): for _ in range(1000): l = random.randint(2, 100) s = random.randint(0, 10000) m = [random.randint(2, 10000) for _ in range(l)] a = [s % m[i] for i in range(l)] - x = pyrival.algebra.composite_crt(a, m) + x = composite_crt(a, m) assert [x % i for i in m] == a diff --git a/tests/algebra/test_discrete_log.py b/tests/algebra/test_discrete_log.py index d7bb76b..33cb62b 100644 --- a/tests/algebra/test_discrete_log.py +++ b/tests/algebra/test_discrete_log.py @@ -1,6 +1,6 @@ import random -import pyrival.algebra +from pyrival.discrete_log import * # Good problem to test discrete log # https://codeforces.com/gym/101853/problem/G @@ -17,7 +17,7 @@ def brute(a, b, mod): for a in range(limit): for b in range(limit): for m in range(1, limit): - x = pyrival.algebra.discrete_log(a, b, m) + x = discrete_log(a, b, m) y = brute(a, b, m) assert x == y @@ -30,5 +30,5 @@ def test_discrete_log_random_cases(trials=200): x = random.randint(0, 10**9) b = pow(a, x, m) - y = pow(a, pyrival.algebra.discrete_log(a, b, m), m) + y = pow(a, discrete_log(a, b, m), m) assert y == b diff --git a/tests/algebra/test_factors.py b/tests/algebra/test_factors.py index 1015b73..a6ca4e4 100644 --- a/tests/algebra/test_factors.py +++ b/tests/algebra/test_factors.py @@ -1,18 +1,18 @@ import random -import pyrival.algebra +from pyrival.factors import * def test_pollard_rho(): for _ in range(1000): n = random.randint(2, 10000) - assert n % pyrival.algebra.pollard_rho(n) == 0 + assert n % pollard_rho(n) == 0 def test_prime_factors(prime_set): for _ in range(1000): n = random.randint(1, 10000) - for f, e in pyrival.algebra.prime_factors(n).items(): + for f, e in prime_factors(n).items(): assert f in prime_set assert n % (f**e) == 0 n //= f**e @@ -22,7 +22,7 @@ def test_prime_factors(prime_set): def test_distinct_factors(): for _ in range(1000): n = random.randint(1, 10000) - factors = set(pyrival.algebra.distinct_factors(n)) + factors = set(distinct_factors(n)) for i in range(1, n + 1): assert (n % i == 0) == (i in factors) @@ -30,7 +30,7 @@ def test_distinct_factors(): def test_all_factors(): for _ in range(1000): n = random.randint(1, 10000) - factors = pyrival.algebra.all_factors(n) + factors = all_factors(n) assert factors == sorted(factors) factors = set(factors) for i in range(1, n + 1): diff --git a/tests/algebra/test_gcd.py b/tests/algebra/test_gcd.py index bc3a7bc..641f0d1 100644 --- a/tests/algebra/test_gcd.py +++ b/tests/algebra/test_gcd.py @@ -1,19 +1,18 @@ import math import random -import pyrival.algebra - +import pyrival.gcd import * def test_gcd(): for _ in range(10000): x, y = random.randint(1, 1000), random.randint(1, 1000) - assert pyrival.algebra.gcd(x, y) == math.gcd(x, y) + assert gcd(x, y) == math.gcd(x, y) def test_extended_gcd(): for _ in range(10000): x, y = random.randint(1, 1000), random.randint(1, 1000) - g, s, r = pyrival.algebra.extended_gcd(x, y) + g, s, r = extended_gcd(x, y) assert g == math.gcd(x, y) assert s * x + r * y == g @@ -22,4 +21,4 @@ def test_extended_gcd(): def test_lcm(): for _ in range(10000): x, y = random.randint(1, 1000), random.randint(1, 1000) - assert pyrival.algebra.lcm(x, y) == x * y // math.gcd(x, y) + assert lcm(x, y) == x * y // math.gcd(x, y) diff --git a/tests/algebra/test_is_prime.py b/tests/algebra/test_is_prime.py index 172bc0d..7241aec 100644 --- a/tests/algebra/test_is_prime.py +++ b/tests/algebra/test_is_prime.py @@ -1,18 +1,18 @@ -import pyrival.algebra +from is_prime import * def test_is_prime(prime_set): for i in range(max(prime_set) + 1): - assert pyrival.algebra.is_prime(i) == (i in prime_set) + assert is_prime(i) == (i in prime_set) - assert pyrival.algebra.is_prime(10**8 + 7) == True - assert pyrival.algebra.is_prime(10**9 + 7) == True - assert pyrival.algebra.is_prime(10**9 + 9) == True + assert is_prime(10**8 + 7) == True + assert is_prime(10**9 + 7) == True + assert is_prime(10**9 + 9) == True - assert pyrival.algebra.is_prime(326549970232583195150330872691) == True - assert pyrival.algebra.is_prime(551957180201435611622967802607) == True - assert pyrival.algebra.is_prime(722963248890983103711213365897) == True + assert is_prime(326549970232583195150330872691) == True + assert is_prime(551957180201435611622967802607) == True + assert is_prime(722963248890983103711213365897) == True - assert pyrival.algebra.is_prime(688220523361999133670399137430) == False - assert pyrival.algebra.is_prime(400284591585155461390239326086) == False - assert pyrival.algebra.is_prime(576409959862662626347091665567) == False + assert is_prime(688220523361999133670399137430) == False + assert is_prime(400284591585155461390239326086) == False + assert is_prime(576409959862662626347091665567) == False diff --git a/tests/algebra/test_modinv.py b/tests/algebra/test_modinv.py index 565237d..1b6174f 100644 --- a/tests/algebra/test_modinv.py +++ b/tests/algebra/test_modinv.py @@ -1,11 +1,10 @@ import random -import pyrival.algebra - +from pyrival.modinv import * def test_modinv(): for _ in range(10000): a = random.randint(1, 10000) - assert (pyrival.algebra.modinv(a, 10**8 + 7) * a) % (10**8 + 7) == 1 - assert (pyrival.algebra.modinv(a, 10**9 + 7) * a) % (10**9 + 7) == 1 - assert (pyrival.algebra.modinv(a, 10**9 + 9) * a) % (10**9 + 9) == 1 + assert (modinv(a, 10**8 + 7) * a) % (10**8 + 7) == 1 + assert (modinv(a, 10**9 + 7) * a) % (10**9 + 7) == 1 + assert (modinv(a, 10**9 + 9) * a) % (10**9 + 9) == 1 diff --git a/tests/algebra/test_phi.py b/tests/algebra/test_phi.py index fb495c6..5f65118 100644 --- a/tests/algebra/test_phi.py +++ b/tests/algebra/test_phi.py @@ -1,5 +1,4 @@ -import pyrival.algebra +from pyrival.phi import * - -def test_phi(phi): - assert pyrival.algebra.phi(len(phi) - 1) == phi +def test_phi(f): + assert phi(len(f) - 1) == f diff --git a/tests/algebra/test_sieve.py b/tests/algebra/test_sieve.py index 4a89b68..18cfaec 100644 --- a/tests/algebra/test_sieve.py +++ b/tests/algebra/test_sieve.py @@ -1,5 +1,4 @@ -import pyrival.algebra - +from pyrival.sieve import * def test_prime_list(primes): - assert primes == pyrival.algebra.prime_list(primes[-1]) + assert primes == prime_list(primes[-1]) diff --git a/tests/combinatorics/test_combinatorics.py b/tests/combinatorics/test_combinatorics.py index fd16016..03cfe19 100644 --- a/tests/combinatorics/test_combinatorics.py +++ b/tests/combinatorics/test_combinatorics.py @@ -1,13 +1,12 @@ -import pyrival.combinatorics +from pyrival.combinatorics import * +def test_catalan_recursive(A): + assert all(catalan_recursive(i) == j for i, j in enumerate(A)) -def test_catalan_recursive(catalan): - assert all(pyrival.combinatorics.catalan_recursive(i) == j for i, j in enumerate(catalan)) +def test_derangements(A): + assert all(derangements(i) == j for i, j in enumerate(A)) -def test_derangements(derangements): - assert all(pyrival.combinatorics.derangements(i) == j for i, j in enumerate(derangements)) - -def test_catalan(catalan): - assert all(pyrival.combinatorics.catalan(i) == j for i, j in enumerate(catalan)) +def test_catalan(A) + assert all(catalan(i) == j for i, j in enumerate(A)) diff --git a/tests/data_structures/test_BitArray.py b/tests/data_structures/test_BitArray.py index 554d330..37eec31 100644 --- a/tests/data_structures/test_BitArray.py +++ b/tests/data_structures/test_BitArray.py @@ -1,8 +1,8 @@ -import pyrival.data_structures +from pyrival.BitArray import * def test_BitArray(): - array = pyrival.data_structures.BitArray(262144) + array = BitArray(262144) for i in range(262144): assert array[i] == 0 diff --git a/tests/data_structures/test_RangeQuery.py b/tests/data_structures/test_RangeQuery.py index 5d93f1d..b900378 100644 --- a/tests/data_structures/test_RangeQuery.py +++ b/tests/data_structures/test_RangeQuery.py @@ -1,6 +1,6 @@ import random -import pyrival.data_structures +from pyrival.RangeQuery import * import pytest @@ -16,7 +16,7 @@ def test_RangeQuery(default, func): l = random.randint(2, 100) arr = [random.randint(-1000, 1000) for _ in range(l)] - range_query = pyrival.data_structures.RangeQuery(arr, func) + range_query = RangeQuery(arr, func) q = random.randint(0, 100) for _ in range(q): diff --git a/tests/data_structures/test_SegmentTree.py b/tests/data_structures/test_SegmentTree.py index 01ab113..5cfd926 100644 --- a/tests/data_structures/test_SegmentTree.py +++ b/tests/data_structures/test_SegmentTree.py @@ -1,7 +1,7 @@ import operator as op import random -import pyrival.data_structures +from pyrival.SegmentTree import * import pytest @@ -19,7 +19,7 @@ def test_SegmentTree(default, func): l = random.randint(2, 100) arr = [random.randint(-1000, 1000) for _ in range(l)] - seg_tree = pyrival.data_structures.SegmentTree(arr, default, func) + seg_tree = SegmentTree(arr, default, func) q = random.randint(0, 100) for _ in range(q): diff --git a/tests/data_structures/test_convex_hull_trick.py b/tests/data_structures/test_convex_hull_trick.py index 206fc72..3901022 100644 --- a/tests/data_structures/test_convex_hull_trick.py +++ b/tests/data_structures/test_convex_hull_trick.py @@ -1,4 +1,4 @@ -from pyrival.data_structures import convex_hull_trick, max_query +from pyrival.convex_hull_trick import convex_hull_trick, max_query def brute(K, M, X): assert(len(K) == len(M)) diff --git a/tests/graphs/test_maximum_matching.py b/tests/graphs/test_maximum_matching.py index 265498c..7a96fce 100644 --- a/tests/graphs/test_maximum_matching.py +++ b/tests/graphs/test_maximum_matching.py @@ -1,30 +1,29 @@ -import pyrival.graphs - +from pyrival.maximum_matching import * def test_maximum_matching__corner_cases(): edges = [] for e in [(0, 1), (1, 2), (2, 0)]: edges.append(e) - assert pyrival.graphs.maximum_matching(edges) == 1 + assert maximum_matching(edges) == 1 for e in [(2, 3), (3, 4)]: edges.append(e) - assert pyrival.graphs.maximum_matching(edges) == 2 + assert maximum_matching(edges) == 2 for e in [(4, 5), (5, 6)]: edges.append(e) - assert pyrival.graphs.maximum_matching(edges) == 3 + assert maximum_matching(edges) == 3 for e in [(7, 8), (7, 9), (7, 10)]: edges.append(e) - assert pyrival.graphs.maximum_matching(edges) == 4 + assert maximum_matching(edges) == 4 edges.append((4, 10)) - assert pyrival.graphs.maximum_matching(edges) == 5 + assert maximum_matching(edges) == 5 for e in [(9, 11), (8, 11)]: edges.append(e) - assert pyrival.graphs.maximum_matching(edges) == 6 + assert maximum_matching(edges) == 6 def test_maximum_matching__large_pseudorandom_cases(): @@ -36,4 +35,4 @@ def test_maximum_matching__large_pseudorandom_cases(): if i != j: edges.append((i, j)) - assert pyrival.graphs.maximum_matching(edges) == 239 + assert maximum_matching(edges) == 239 diff --git a/tests/misc/test_as_integer_ratio.py b/tests/misc/test_as_integer_ratio.py index e87149d..59e17cf 100644 --- a/tests/misc/test_as_integer_ratio.py +++ b/tests/misc/test_as_integer_ratio.py @@ -1,15 +1,14 @@ import random -import pyrival.misc - +from pyrival.as_integer_ratio import * def test_as_integer_ratio_0(): - num, den = pyrival.misc.as_integer_ratio(0, 53) + num, den = as_integer_ratio(0, 53) assert abs(num / den) <= 1e-53 def test_as_integer_ratio(): for _ in range(100000): number = (random.random() - 0.5) * 10000 - num, den = pyrival.misc.as_integer_ratio(number, 53) + num, den = as_integer_ratio(number, 53) assert abs((num / den) - number) <= 1e-53 diff --git a/tests/misc/test_bootstrap.py b/tests/misc/test_bootstrap.py index 301b5cb..2cdb5ae 100644 --- a/tests/misc/test_bootstrap.py +++ b/tests/misc/test_bootstrap.py @@ -1,10 +1,10 @@ import random -import pyrival.misc +from pyrival.bootstrap import * def test_bootstrap(): - @pyrival.misc.bootstrap + @bootstrap def func(n): if n: yield (yield func(n - 1)) + n diff --git a/tests/misc/test_order_statistic.py b/tests/misc/test_order_statistic.py index 8979254..8605276 100644 --- a/tests/misc/test_order_statistic.py +++ b/tests/misc/test_order_statistic.py @@ -1,7 +1,6 @@ import random -import pyrival.misc - +from pyrival.order_statistic import * def test_order_statistic(): for _ in range(1000): @@ -9,4 +8,4 @@ def test_order_statistic(): sor = sorted(arr) for i in range(len(arr)): - assert pyrival.misc.order_statistic(arr, i) == sor[i] + assert order_statistic(arr, i) == sor[i] diff --git a/tests/misc/test_readnumbers.py b/tests/misc/test_readnumbers.py index c0b50ad..a1c56bd 100644 --- a/tests/misc/test_readnumbers.py +++ b/tests/misc/test_readnumbers.py @@ -2,8 +2,7 @@ import random import sys -import pyrival.misc - +from pyrival.readnumbers import * def test_readnumbers(monkeypatch): nums = [random.randint(-10000, 10000) for _ in range(100000)] @@ -12,6 +11,6 @@ def test_readnumbers(monkeypatch): stream = io.TextIOWrapper(io.BytesIO(string.encode("ascii"))) monkeypatch.setattr(sys, "stdin", stream) - read_nums = pyrival.misc.readnumbers() + read_nums = readnumbers() assert nums == read_nums diff --git a/tests/numerical/test_iroot.py b/tests/numerical/test_iroot.py index 79a64eb..3ff8e2f 100644 --- a/tests/numerical/test_iroot.py +++ b/tests/numerical/test_iroot.py @@ -1,13 +1,12 @@ import random -import pyrival.numerical - +from pyrival.iroot import * def test_iroot(): for _ in range(10000): k = random.randint(1, 10) n = random.randint(-10000 if k & 1 else 0, 10000) - root = pyrival.numerical.iroot(n, k) + root = iroot(n, k) if root < 0: assert (root - 1)**k < n <= root**k diff --git a/tests/numerical/test_search.py b/tests/numerical/test_search.py index 0f8e0e2..c99a857 100644 --- a/tests/numerical/test_search.py +++ b/tests/numerical/test_search.py @@ -1,31 +1,27 @@ import random -import pyrival.numerical - +from pyrival.search import * def test_binary_search(): for _ in range(10000): n = (random.random() * 2000) - 1000 - assert (abs(pyrival.numerical.binary_search(n.__le__, -1000, 1000, 1e-7) - n) <= 1e-7) - + assert (abs(binary_search(n.__le__, -1000, 1000, 1e-7) - n) <= 1e-7) def test_ternary_search(): for _ in range(10000): n = (random.random() * 2000) - 1000 h = (random.random() * 2000) - 1000 func = lambda x: h - abs(n - x) - assert (abs(pyrival.numerical.ternary_search(func, -1000, 1000, 1e-7) - n) <= 1e-7) - + assert (abs(ternary_search(func, -1000, 1000, 1e-7) - n) <= 1e-7) def test_discrete_binary_search(): for _ in range(10000): n = random.randint(-1000, 1000) - assert pyrival.numerical.discrete_binary_search(n.__le__, -1000, 1000) == n - + assert discrete_binary_search(n.__le__, -1000, 1000) == n def test_discrete_ternary_search(): for _ in range(10000): n = random.randint(-1000, 1000) h = random.randint(-1000, 1000) func = lambda x: h - abs(n - x) - assert pyrival.numerical.discrete_ternary_search(func, -1000, 1000) == n + assert discrete_ternary_search(func, -1000, 1000) == n diff --git a/tests/strings/test_kmp.py b/tests/strings/test_kmp.py index 616ccd3..8ffd286 100644 --- a/tests/strings/test_kmp.py +++ b/tests/strings/test_kmp.py @@ -1,7 +1,6 @@ import random -import pyrival.strings - +from pyrival.kmp import * def brute_force_match(s, pat): idx = [] @@ -15,7 +14,6 @@ def brute_force_match(s, pat): return idx - def test_match(): for _ in range(10000): s_len = random.randint(1, 50) @@ -24,8 +22,7 @@ def test_match(): s = [random.randint(0, 10) for _ in range(s_len)] pat = [random.randint(0, 10) for _ in range(pat_len)] - assert pyrival.strings.match(s, pat) == brute_force_match(s, pat) - + assert match(s, pat) == brute_force_match(s, pat) def test_string_find(): for _ in range(10000): @@ -35,4 +32,4 @@ def test_string_find(): s = [random.randint(0, 10) for _ in range(s_len)] pat = [random.randint(0, 10) for _ in range(pat_len)] - assert pyrival.strings.string_find(s, pat) == (brute_force_match(s, pat) != []) + assert string_find(s, pat) == (brute_force_match(s, pat) != []) From af5a66c17966e8a2b6ccc741de9f2b1fea2f0222 Mon Sep 17 00:00:00 2001 From: Bjorn Date: Sat, 13 Jun 2020 04:21:41 +0200 Subject: [PATCH 2/7] Trying to fix failing tests --- pyrival/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrival/__init__.py b/pyrival/__init__.py index 64fb941..992ea61 100644 --- a/pyrival/__init__.py +++ b/pyrival/__init__.py @@ -3,4 +3,4 @@ import os as _os for s in ('algebra', 'combinatorics', 'data_structures', 'geometry', 'graphs', 'linear_algebra', 'numerical', 'strings', 'misc', 'tools'): - __path__.append(_os.path.join(__path__[0], s)) + __path__.append(_os.path.join(_os.path.dirname(__file__), s)) From 476f49fb5a255922ef723ec3f1d3e0cab96e2771 Mon Sep 17 00:00:00 2001 From: Mukundan Senthil Date: Sat, 13 Jun 2020 13:11:40 +0530 Subject: [PATCH 3/7] Fix some tests --- tests/algebra/test_gcd.py | 2 +- tests/algebra/test_is_prime.py | 2 +- tests/combinatorics/test_combinatorics.py | 2 +- tests/misc/test_ordersort.py | 10 +++++----- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/algebra/test_gcd.py b/tests/algebra/test_gcd.py index 641f0d1..f599ff9 100644 --- a/tests/algebra/test_gcd.py +++ b/tests/algebra/test_gcd.py @@ -1,7 +1,7 @@ import math import random -import pyrival.gcd import * +from pyrival.gcd import * def test_gcd(): for _ in range(10000): diff --git a/tests/algebra/test_is_prime.py b/tests/algebra/test_is_prime.py index 7241aec..0523aa0 100644 --- a/tests/algebra/test_is_prime.py +++ b/tests/algebra/test_is_prime.py @@ -1,4 +1,4 @@ -from is_prime import * +from pyrival.is_prime import * def test_is_prime(prime_set): diff --git a/tests/combinatorics/test_combinatorics.py b/tests/combinatorics/test_combinatorics.py index 03cfe19..079d30e 100644 --- a/tests/combinatorics/test_combinatorics.py +++ b/tests/combinatorics/test_combinatorics.py @@ -8,5 +8,5 @@ def test_derangements(A): assert all(derangements(i) == j for i, j in enumerate(A)) -def test_catalan(A) +def test_catalan(A): assert all(catalan(i) == j for i, j in enumerate(A)) diff --git a/tests/misc/test_ordersort.py b/tests/misc/test_ordersort.py index 28f7fa8..caed32c 100644 --- a/tests/misc/test_ordersort.py +++ b/tests/misc/test_ordersort.py @@ -1,6 +1,6 @@ import random -import pyrival.misc +from pyrival.ordersort import * def test_ordersort(): @@ -9,7 +9,7 @@ def test_ordersort(): arr = [random.randint(0, 1000) for _ in range(l)] - got = pyrival.misc.ordersort(range(l), arr) + got = ordersort(range(l), arr) expected = sorted(range(l), key=arr.__getitem__) assert [arr[i] for i in got] == [arr[i] for i in expected] @@ -21,7 +21,7 @@ def test_ordersort_reverse(): arr = [random.randint(0, 1000) for _ in range(l)] - got = pyrival.misc.ordersort(range(l), arr, reverse=True) + got = ordersort(range(l), arr, reverse=True) expected = sorted(range(l), key=arr.__getitem__, reverse=True) assert [arr[i] for i in got] == [arr[i] for i in expected] @@ -33,7 +33,7 @@ def test_multikey_ordersort(): arr = [[random.randint(0, 1000) for _ in range(t)] for _ in range(l)] - got = pyrival.misc.multikey_ordersort(range(l), *zip(*arr)) + got = multikey_ordersort(range(l), *zip(*arr)) expected = sorted(range(l), key=arr.__getitem__) assert [arr[i] for i in got] == [arr[i] for i in expected] @@ -44,7 +44,7 @@ def test_long_ordersort(): arr = [random.randint(0, 10**18) for _ in range(l)] - got = pyrival.misc.long_ordersort(range(l), arr) + got = long_ordersort(range(l), arr) expected = sorted(range(l), key=arr.__getitem__) assert [arr[i] for i in got] == [arr[i] for i in expected] From 280747c27f645974ea26061485fd14da1a06ca96 Mon Sep 17 00:00:00 2001 From: Mukundan Senthil Date: Sat, 13 Jun 2020 18:32:08 +0530 Subject: [PATCH 4/7] Create empty __init__.py --- pyrival/algebra/__init__.py | 0 pyrival/combinatorics/__init__.py | 0 pyrival/data_structures/__init__.py | 0 pyrival/geometry/__init__.py | 0 pyrival/graphs/__init__.py | 0 pyrival/linear_algebra/__init__.py | 0 pyrival/misc/__init__.py | 0 pyrival/numerical/__init__.py | 0 pyrival/strings/__init__.py | 0 pyrival/tools/__init__.py | 0 10 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 pyrival/algebra/__init__.py create mode 100644 pyrival/combinatorics/__init__.py create mode 100644 pyrival/data_structures/__init__.py create mode 100644 pyrival/geometry/__init__.py create mode 100644 pyrival/graphs/__init__.py create mode 100644 pyrival/linear_algebra/__init__.py create mode 100644 pyrival/misc/__init__.py create mode 100644 pyrival/numerical/__init__.py create mode 100644 pyrival/strings/__init__.py create mode 100644 pyrival/tools/__init__.py diff --git a/pyrival/algebra/__init__.py b/pyrival/algebra/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pyrival/combinatorics/__init__.py b/pyrival/combinatorics/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pyrival/data_structures/__init__.py b/pyrival/data_structures/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pyrival/geometry/__init__.py b/pyrival/geometry/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pyrival/graphs/__init__.py b/pyrival/graphs/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pyrival/linear_algebra/__init__.py b/pyrival/linear_algebra/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pyrival/misc/__init__.py b/pyrival/misc/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pyrival/numerical/__init__.py b/pyrival/numerical/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pyrival/strings/__init__.py b/pyrival/strings/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pyrival/tools/__init__.py b/pyrival/tools/__init__.py new file mode 100644 index 0000000..e69de29 From 758e86429a2b9099f3e024404f37fe1232f82427 Mon Sep 17 00:00:00 2001 From: Bjorn Date: Sat, 13 Jun 2020 15:33:11 +0200 Subject: [PATCH 5/7] Fixed failing tests --- tests/algebra/test_phi.py | 6 +++--- tests/combinatorics/test_combinatorics.py | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/algebra/test_phi.py b/tests/algebra/test_phi.py index 5f65118..01939ca 100644 --- a/tests/algebra/test_phi.py +++ b/tests/algebra/test_phi.py @@ -1,4 +1,4 @@ -from pyrival.phi import * +from pyrival.phi import phi as f -def test_phi(f): - assert phi(len(f) - 1) == f +def test_phi(phi): + assert f(len(phi) - 1) == phi diff --git a/tests/combinatorics/test_combinatorics.py b/tests/combinatorics/test_combinatorics.py index 079d30e..77b4a42 100644 --- a/tests/combinatorics/test_combinatorics.py +++ b/tests/combinatorics/test_combinatorics.py @@ -1,12 +1,12 @@ -from pyrival.combinatorics import * +from pyrival.combinatorics import combinatorics -def test_catalan_recursive(A): - assert all(catalan_recursive(i) == j for i, j in enumerate(A)) +def test_catalan_recursive(catalan): + assert all(combinatorics.catalan_recursive(i) == j for i, j in enumerate(A)) -def test_derangements(A): - assert all(derangements(i) == j for i, j in enumerate(A)) +def test_derangements(derangements): + assert all(combinatorics.derangements(i) == j for i, j in enumerate(A)) -def test_catalan(A): - assert all(catalan(i) == j for i, j in enumerate(A)) +def test_catalan(catalan): + assert all(combinatorics.catalan(i) == j for i, j in enumerate(A)) From 6f1e0ebb688b1dfa9df61295b314de1fde8c487f Mon Sep 17 00:00:00 2001 From: Bjorn Date: Sat, 13 Jun 2020 15:36:43 +0200 Subject: [PATCH 6/7] Fixed failing tests --- tests/combinatorics/test_combinatorics.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/tests/combinatorics/test_combinatorics.py b/tests/combinatorics/test_combinatorics.py index 77b4a42..1fd3e54 100644 --- a/tests/combinatorics/test_combinatorics.py +++ b/tests/combinatorics/test_combinatorics.py @@ -1,12 +1,10 @@ from pyrival.combinatorics import combinatorics def test_catalan_recursive(catalan): - assert all(combinatorics.catalan_recursive(i) == j for i, j in enumerate(A)) - + assert all(combinatorics.catalan_recursive(i) == j for i, j in enumerate(catalan)) def test_derangements(derangements): - assert all(combinatorics.derangements(i) == j for i, j in enumerate(A)) - + assert all(combinatorics.derangements(i) == j for i, j in enumerate(derangements)) def test_catalan(catalan): - assert all(combinatorics.catalan(i) == j for i, j in enumerate(A)) + assert all(combinatorics.catalan(i) == j for i, j in enumerate(catalan)) From da4a60b3de85fc9151b182e87712dbe723670a6d Mon Sep 17 00:00:00 2001 From: Bjorn Date: Sat, 13 Jun 2020 15:51:25 +0200 Subject: [PATCH 7/7] Tiny change, hid one variable --- pyrival/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyrival/__init__.py b/pyrival/__init__.py index 992ea61..a636748 100644 --- a/pyrival/__init__.py +++ b/pyrival/__init__.py @@ -1,6 +1,6 @@ from .version import version as __version__ import os as _os -for s in ('algebra', 'combinatorics', 'data_structures', 'geometry', +for _s in ('algebra', 'combinatorics', 'data_structures', 'geometry', 'graphs', 'linear_algebra', 'numerical', 'strings', 'misc', 'tools'): - __path__.append(_os.path.join(_os.path.dirname(__file__), s)) + __path__.append(_os.path.join(_os.path.dirname(__file__), _s))