Skip to content

Commit

Permalink
Merge pull request #39 from bjorn-martinsson/simplify_init
Browse files Browse the repository at this point in the history
Simplify imports
  • Loading branch information
cheran-senthil authored Jun 13, 2020
2 parents f4f7a3b + da4a60b commit a023219
Show file tree
Hide file tree
Showing 33 changed files with 82 additions and 398 deletions.
18 changes: 5 additions & 13 deletions pyrival/__init__.py
Original file line number Diff line number Diff line change
@@ -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(_os.path.dirname(__file__), _s))
41 changes: 0 additions & 41 deletions pyrival/algebra/__init__.py
Original file line number Diff line number Diff line change
@@ -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",
]
20 changes: 0 additions & 20 deletions pyrival/combinatorics/__init__.py
Original file line number Diff line number Diff line change
@@ -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",
]
68 changes: 0 additions & 68 deletions pyrival/data_structures/__init__.py
Original file line number Diff line number Diff line change
@@ -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",
]
23 changes: 0 additions & 23 deletions pyrival/geometry/__init__.py
Original file line number Diff line number Diff line change
@@ -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",
]
39 changes: 0 additions & 39 deletions pyrival/graphs/__init__.py
Original file line number Diff line number Diff line change
@@ -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",
]
17 changes: 0 additions & 17 deletions pyrival/linear_algebra/__init__.py
Original file line number Diff line number Diff line change
@@ -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",
]
40 changes: 0 additions & 40 deletions pyrival/misc/__init__.py
Original file line number Diff line number Diff line change
@@ -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",
]
28 changes: 0 additions & 28 deletions pyrival/numerical/__init__.py
Original file line number Diff line number Diff line change
@@ -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",
]
8 changes: 0 additions & 8 deletions pyrival/strings/__init__.py
Original file line number Diff line number Diff line change
@@ -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"]
3 changes: 0 additions & 3 deletions pyrival/tools/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
from .stress_tester import cmd2func, func2judge, stress_tester

__all__ = ["cmd2func", "func2judge", "stress_tester"]
8 changes: 3 additions & 5 deletions tests/algebra/test_chinese_remainder.py
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions tests/algebra/test_discrete_log.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand All @@ -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
Loading

0 comments on commit a023219

Please sign in to comment.