pyflow-analysis 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pyflow/__init__.py +22 -0
- pyflow/_pyflow.py +50 -0
- pyflow/analysis/__init__.py +14 -0
- pyflow/analysis/alias/__init__.py +3 -0
- pyflow/analysis/alias/flow_sensitive/__init__.py +148 -0
- pyflow/analysis/alias/flow_sensitive/_transfer_calls.py +3493 -0
- pyflow/analysis/alias/flow_sensitive/_transfer_ops.py +1969 -0
- pyflow/analysis/alias/flow_sensitive/abstraction.py +1632 -0
- pyflow/analysis/alias/flow_sensitive/heap_analysis.py +280 -0
- pyflow/analysis/alias/flow_sensitive/heap_effects.py +1209 -0
- pyflow/analysis/alias/flow_sensitive/heap_state.py +381 -0
- pyflow/analysis/alias/flow_sensitive/heap_summary.py +299 -0
- pyflow/analysis/alias/flow_sensitive/intrinsics.py +948 -0
- pyflow/analysis/alias/flow_sensitive/model.py +449 -0
- pyflow/analysis/alias/flow_sensitive/points_to_graph.py +722 -0
- pyflow/analysis/alias/flow_sensitive/transfer.py +1483 -0
- pyflow/analysis/alias/kcfa/__init__.py +33 -0
- pyflow/analysis/alias/kcfa/_pythonstan/__init__.py +2 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/__init__.py +1 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/ai/__init__.py +53 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/ai/logging.py +490 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/ai/operation.py +1601 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/ai/pointer_adapter.py +353 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/ai/solver.py +559 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/ai/state.py +701 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/ai/value.py +804 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/analysis.py +86 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/class_hierarchy.py +83 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/closure.py +69 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/dataflow/__init__.py +4 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/dataflow/analysis.py +58 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/dataflow/driver.py +38 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/dataflow/liveness.py +33 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/dataflow/reaching_definition.py +52 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/dataflow/solver.py +178 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/defuse.py +46 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/pointer/__init__.py +18 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/pointer/kcfa/__init__.py +110 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/pointer/kcfa/analysis.py +382 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/pointer/kcfa/builtin_api_handler.py +1872 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/pointer/kcfa/call_graph_analyzer.py +289 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/pointer/kcfa/class_hierarchy.py +304 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/pointer/kcfa/config.py +139 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/pointer/kcfa/constraints.py +576 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/pointer/kcfa/context.py +496 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/pointer/kcfa/context_selector.py +297 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/pointer/kcfa/debug_monitor.py +34 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/pointer/kcfa/heap_model.py +221 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/pointer/kcfa/ir_translator.py +1181 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/pointer/kcfa/libs/__init__.py +2 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/pointer/kcfa/libs/math.py +244 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/pointer/kcfa/module_analysis.py +269 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/pointer/kcfa/module_summary.py +191 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/pointer/kcfa/object.py +685 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/pointer/kcfa/pointer_flow_graph.py +282 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/pointer/kcfa/points_to_set.py +301 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/pointer/kcfa/processor/__init__.py +21 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/pointer/kcfa/processor/attribute_semantics.py +512 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/pointer/kcfa/processor/compose_processor.py +46 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/pointer/kcfa/processor/container.py +128 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/pointer/kcfa/processor/generator.py +353 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/pointer/kcfa/processor/normal_call.py +664 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/pointer/kcfa/processor/processor.py +36 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/pointer/kcfa/processor/super_resolve.py +131 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/pointer/kcfa/pta_query_adapter.py +329 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/pointer/kcfa/solver.py +917 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/pointer/kcfa/solver_interface.py +76 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/pointer/kcfa/state.py +735 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/pointer/kcfa/unknown_tracker.py +126 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/pointer/kcfa/variable.py +144 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/scope/__init__.py +2 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/scope/analysis.py +37 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/scope/closure.py +81 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/transform/__init__.py +8 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/transform/block_cfg.py +133 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/transform/cfg.py +95 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/transform/driver.py +26 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/transform/icfg/__init__.py +0 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/transform/icfg/base.py +112 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/transform/icfg/baseprocess.py +524 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/transform/icfg/icfg.py +0 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/transform/icfg/icfg_pre_transform.py +69 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/transform/icfg/icfg_transform.py +0 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/transform/icfg/postprocessor.py +308 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/transform/icfg/preprocessor.py +375 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/transform/ir.py +361 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/transform/three_address.py +1161 -0
- pyflow/analysis/alias/kcfa/_pythonstan/analysis/transform/transform.py +27 -0
- pyflow/analysis/alias/kcfa/_pythonstan/graph/__init__.py +0 -0
- pyflow/analysis/alias/kcfa/_pythonstan/graph/call_graph/__init__.py +2 -0
- pyflow/analysis/alias/kcfa/_pythonstan/graph/call_graph/call_edge.py +45 -0
- pyflow/analysis/alias/kcfa/_pythonstan/graph/call_graph/call_graph.py +77 -0
- pyflow/analysis/alias/kcfa/_pythonstan/graph/cfg/__init__.py +3 -0
- pyflow/analysis/alias/kcfa/_pythonstan/graph/cfg/base_block.py +83 -0
- pyflow/analysis/alias/kcfa/_pythonstan/graph/cfg/cfg.py +200 -0
- pyflow/analysis/alias/kcfa/_pythonstan/graph/cfg/dump.py +20 -0
- pyflow/analysis/alias/kcfa/_pythonstan/graph/cfg/edges.py +162 -0
- pyflow/analysis/alias/kcfa/_pythonstan/graph/cfg/visualize.py +112 -0
- pyflow/analysis/alias/kcfa/_pythonstan/graph/dominator_tree.py +126 -0
- pyflow/analysis/alias/kcfa/_pythonstan/graph/graph.py +81 -0
- pyflow/analysis/alias/kcfa/_pythonstan/graph/icfg/__init__.py +0 -0
- pyflow/analysis/alias/kcfa/_pythonstan/graph/icfg/icfg.py +98 -0
- pyflow/analysis/alias/kcfa/_pythonstan/ir/__init__.py +2 -0
- pyflow/analysis/alias/kcfa/_pythonstan/ir/ir_statements.py +1579 -0
- pyflow/analysis/alias/kcfa/_pythonstan/ir/ir_visitor.py +21 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/LICENSE.pythonstan +28 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/README.md +99 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/__pycache__/abc.cpython-313.pyc +0 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/__pycache__/base64.cpython-313.pyc +0 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/__pycache__/bisect.cpython-313.pyc +0 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/__pycache__/collections.cpython-313.pyc +0 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/__pycache__/contextlib.cpython-313.pyc +0 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/__pycache__/copy.cpython-313.pyc +0 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/__pycache__/csv.cpython-313.pyc +0 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/__pycache__/dataclasses.cpython-313.pyc +0 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/__pycache__/datetime.cpython-313.pyc +0 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/__pycache__/email.cpython-313.pyc +0 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/__pycache__/enum.cpython-313.pyc +0 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/__pycache__/fnmatch.cpython-313.pyc +0 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/__pycache__/functools.cpython-313.pyc +0 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/__pycache__/glob.cpython-313.pyc +0 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/__pycache__/hashlib.cpython-313.pyc +0 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/__pycache__/heapq.cpython-313.pyc +0 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/__pycache__/hmac.cpython-313.pyc +0 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/__pycache__/http.cpython-313.pyc +0 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/__pycache__/importlib.cpython-313.pyc +0 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/__pycache__/inspect.cpython-313.pyc +0 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/__pycache__/io.cpython-313.pyc +0 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/__pycache__/itertools.cpython-313.pyc +0 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/__pycache__/json.cpython-313.pyc +0 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/__pycache__/logging.cpython-313.pyc +0 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/__pycache__/math.cpython-313.pyc +0 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/__pycache__/mimetypes.cpython-313.pyc +0 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/__pycache__/operator.cpython-313.pyc +0 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/__pycache__/os.cpython-313.pyc +0 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/__pycache__/pathlib.cpython-313.pyc +0 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/__pycache__/pickle.cpython-313.pyc +0 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/__pycache__/random.cpython-313.pyc +0 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/__pycache__/re.cpython-313.pyc +0 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/__pycache__/secrets.cpython-313.pyc +0 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/__pycache__/shutil.cpython-313.pyc +0 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/__pycache__/somelib.cpython-313.pyc +0 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/__pycache__/tempfile.cpython-313.pyc +0 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/__pycache__/time.cpython-313.pyc +0 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/__pycache__/traceback.cpython-313.pyc +0 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/__pycache__/types.cpython-313.pyc +0 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/__pycache__/uuid.cpython-313.pyc +0 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/__pycache__/warnings.cpython-313.pyc +0 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/__pycache__/weakref.cpython-313.pyc +0 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/abc.py +80 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/base64.py +62 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/bisect.py +52 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/collections.py +187 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/contextlib.py +113 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/copy.py +15 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/csv.py +163 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/dataclasses.py +150 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/datetime.py +171 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/email.py +270 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/enum.py +144 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/fnmatch.py +14 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/functools.py +84 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/glob.py +10 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/hashlib.py +74 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/heapq.py +91 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/hmac.py +31 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/http.py +317 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/importlib.py +126 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/inspect.py +246 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/io.py +471 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/itertools.py +164 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/json.py +80 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/logging.py +193 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/math.py +244 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/mimetypes.py +119 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/operator.py +310 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/os.py +286 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/pathlib.py +196 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/pickle.py +153 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/random.py +125 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/re.py +125 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/secrets.py +29 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/shutil.py +99 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/somelib.py +2 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/tempfile.py +76 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/time.py +65 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/traceback.py +151 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/types.py +247 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/urllib/__init__.py +1 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/urllib/__pycache__/__init__.cpython-313.pyc +0 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/urllib/__pycache__/parse.cpython-313.pyc +0 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/urllib/parse.py +221 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/uuid.py +34 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/warnings.py +82 -0
- pyflow/analysis/alias/kcfa/_pythonstan/stubs/stdlib/weakref.py +272 -0
- pyflow/analysis/alias/kcfa/_pythonstan/utils/__init__.py +1 -0
- pyflow/analysis/alias/kcfa/_pythonstan/utils/ast_rename.py +35 -0
- pyflow/analysis/alias/kcfa/_pythonstan/utils/common.py +70 -0
- pyflow/analysis/alias/kcfa/_pythonstan/utils/persistent_rb_tree.py +364 -0
- pyflow/analysis/alias/kcfa/_pythonstan/utils/temp_var_generator.py +68 -0
- pyflow/analysis/alias/kcfa/_pythonstan/utils/toposort.py +63 -0
- pyflow/analysis/alias/kcfa/_pythonstan/utils/var_collector.py +72 -0
- pyflow/analysis/alias/kcfa/_pythonstan/world/__init__.py +1 -0
- pyflow/analysis/alias/kcfa/_pythonstan/world/analysis_manager.py +141 -0
- pyflow/analysis/alias/kcfa/_pythonstan/world/class_hierarchy.py +56 -0
- pyflow/analysis/alias/kcfa/_pythonstan/world/config.py +93 -0
- pyflow/analysis/alias/kcfa/_pythonstan/world/import_manager.py +16 -0
- pyflow/analysis/alias/kcfa/_pythonstan/world/namespace.py +327 -0
- pyflow/analysis/alias/kcfa/_pythonstan/world/pipeline.py +153 -0
- pyflow/analysis/alias/kcfa/_pythonstan/world/scope_manager.py +133 -0
- pyflow/analysis/alias/kcfa/_pythonstan/world/world.py +49 -0
- pyflow/analysis/alias/kcfa/bridge.py +136 -0
- pyflow/analysis/astcollector.py +171 -0
- pyflow/analysis/cache/incremental.py +226 -0
- pyflow/analysis/callgraph/__init__.py +58 -0
- pyflow/analysis/callgraph/ast_based.py +184 -0
- pyflow/analysis/callgraph/callgraph.py +86 -0
- pyflow/analysis/callgraph/constraint_based/__init__.py +26 -0
- pyflow/analysis/callgraph/constraint_based/_analyzer.py +1976 -0
- pyflow/analysis/callgraph/constraint_based/_collector.py +704 -0
- pyflow/analysis/callgraph/constraint_based/_evaluator.py +984 -0
- pyflow/analysis/callgraph/constraint_based/_loader.py +115 -0
- pyflow/analysis/callgraph/constraint_based/_resolver.py +2852 -0
- pyflow/analysis/callgraph/constraint_based/api.py +233 -0
- pyflow/analysis/callgraph/constraint_based/engine.py +717 -0
- pyflow/analysis/callgraph/constraint_based/model.py +303 -0
- pyflow/analysis/callgraph/formats.py +99 -0
- pyflow/analysis/callgraph/pycg_based.py +273 -0
- pyflow/analysis/cdg/__init__.py +52 -0
- pyflow/analysis/cdg/construction.py +256 -0
- pyflow/analysis/cdg/dump.py +415 -0
- pyflow/analysis/cdg/graph.py +456 -0
- pyflow/analysis/cfg/__init__.py +38 -0
- pyflow/analysis/cfg/dfs.py +55 -0
- pyflow/analysis/cfg/dom.py +243 -0
- pyflow/analysis/cfg/dump.py +322 -0
- pyflow/analysis/cfg/expandphi.py +113 -0
- pyflow/analysis/cfg/gc.py +93 -0
- pyflow/analysis/cfg/graph.py +878 -0
- pyflow/analysis/cfg/inline.py +337 -0
- pyflow/analysis/cfg/killflow.py +360 -0
- pyflow/analysis/cfg/optimize.py +164 -0
- pyflow/analysis/cfg/simplify.py +19 -0
- pyflow/analysis/cfg/ssa.py +693 -0
- pyflow/analysis/cfg/ssatransform.py +13 -0
- pyflow/analysis/cfg/structuralanalysis.py +422 -0
- pyflow/analysis/cfg/transform.py +527 -0
- pyflow/analysis/cpa/__init__.py +657 -0
- pyflow/analysis/cpa/base.py +430 -0
- pyflow/analysis/cpa/codecloner.py +262 -0
- pyflow/analysis/cpa/constraintextractor.py +797 -0
- pyflow/analysis/cpa/constraints.py +1071 -0
- pyflow/analysis/cpa/simpleimagebuilder.py +299 -0
- pyflow/analysis/cpasignature.py +132 -0
- pyflow/analysis/cpg/__init__.py +93 -0
- pyflow/analysis/cpg/build.py +221 -0
- pyflow/analysis/cpg/dump.py +102 -0
- pyflow/analysis/cpg/graph.py +1877 -0
- pyflow/analysis/cpg/persist.py +346 -0
- pyflow/analysis/cpg/profiles.py +286 -0
- pyflow/analysis/cpg/rules.py +365 -0
- pyflow/analysis/cpg/taint.py +1934 -0
- pyflow/analysis/dataflowIR/__init__.py +6 -0
- pyflow/analysis/dataflowIR/annotations.py +174 -0
- pyflow/analysis/dataflowIR/convert.py +795 -0
- pyflow/analysis/dataflowIR/dump.py +443 -0
- pyflow/analysis/dataflowIR/graph.py +1648 -0
- pyflow/analysis/dataflowIR/ordering.py +134 -0
- pyflow/analysis/dataflowIR/predicate.py +233 -0
- pyflow/analysis/dataflowIR/transform/__init__.py +15 -0
- pyflow/analysis/dataflowIR/transform/dce.py +215 -0
- pyflow/analysis/dataflowIR/transform/loadelimination.py +185 -0
- pyflow/analysis/dataflowIR/traverse.py +91 -0
- pyflow/analysis/ddg/__init__.py +53 -0
- pyflow/analysis/ddg/construction.py +310 -0
- pyflow/analysis/ddg/dump.py +218 -0
- pyflow/analysis/ddg/graph.py +295 -0
- pyflow/analysis/dump/__init__.py +15 -0
- pyflow/analysis/dump/dumpgraphs.py +93 -0
- pyflow/analysis/dump/dumpreport.py +841 -0
- pyflow/analysis/dump/dumputil.py +98 -0
- pyflow/analysis/fsdf/__init__.py +1107 -0
- pyflow/analysis/fsdf/canonicalset.py +176 -0
- pyflow/analysis/fsdf/canonicaltree.py +1071 -0
- pyflow/analysis/ifds/__init__.py +284 -0
- pyflow/analysis/ifds/annotation_fallback.py +21 -0
- pyflow/analysis/ifds/annotation_synthesis.py +803 -0
- pyflow/analysis/ifds/api.py +567 -0
- pyflow/analysis/ifds/backward_solver.py +328 -0
- pyflow/analysis/ifds/cfg_adapter.py +1575 -0
- pyflow/analysis/ifds/clients/_call_model.py +166 -0
- pyflow/analysis/ifds/clients/_client_common.py +1617 -0
- pyflow/analysis/ifds/clients/flow_path_collector.py +159 -0
- pyflow/analysis/ifds/clients/library_presets.py +1134 -0
- pyflow/analysis/ifds/clients/nullness.py +754 -0
- pyflow/analysis/ifds/clients/registry/__init__.py +26 -0
- pyflow/analysis/ifds/clients/registry/loader.py +688 -0
- pyflow/analysis/ifds/clients/registry/validate.py +37 -0
- pyflow/analysis/ifds/clients/taint.py +782 -0
- pyflow/analysis/ifds/clients/typestate.py +1550 -0
- pyflow/analysis/ifds/clients/typestate_engine.py +534 -0
- pyflow/analysis/ifds/diagnostics.py +29 -0
- pyflow/analysis/ifds/preparation.py +97 -0
- pyflow/analysis/ifds/problem.py +363 -0
- pyflow/analysis/ifds/queries.py +142 -0
- pyflow/analysis/ifds/reporting.py +289 -0
- pyflow/analysis/ifds/shadow_scan.py +349 -0
- pyflow/analysis/ifds/solver.py +1495 -0
- pyflow/analysis/ifds/supergraph.py +186 -0
- pyflow/analysis/ifds/transfers.py +187 -0
- pyflow/analysis/ipa/__init__.py +77 -0
- pyflow/analysis/ipa/calling/__init__.py +17 -0
- pyflow/analysis/ipa/calling/callbinder.py +93 -0
- pyflow/analysis/ipa/calling/cpa.py +197 -0
- pyflow/analysis/ipa/calling/transfer.py +208 -0
- pyflow/analysis/ipa/constraintextractor.py +804 -0
- pyflow/analysis/ipa/constraints/__init__.py +18 -0
- pyflow/analysis/ipa/constraints/base.py +66 -0
- pyflow/analysis/ipa/constraints/calls.py +424 -0
- pyflow/analysis/ipa/constraints/flow.py +445 -0
- pyflow/analysis/ipa/constraints/node.py +299 -0
- pyflow/analysis/ipa/constraints/qualifiers.py +17 -0
- pyflow/analysis/ipa/constraints/split.py +178 -0
- pyflow/analysis/ipa/dump.py +246 -0
- pyflow/analysis/ipa/entrypointbuilder.py +52 -0
- pyflow/analysis/ipa/escape/__init__.py +19 -0
- pyflow/analysis/ipa/escape/objectescape.py +77 -0
- pyflow/analysis/ipa/ipanalysis.py +319 -0
- pyflow/analysis/ipa/memory/__init__.py +16 -0
- pyflow/analysis/ipa/memory/extractorpolicy.py +38 -0
- pyflow/analysis/ipa/memory/storegraphpolicy.py +17 -0
- pyflow/analysis/ipa/model/__init__.py +18 -0
- pyflow/analysis/ipa/model/context.py +277 -0
- pyflow/analysis/ipa/model/invocation.py +159 -0
- pyflow/analysis/ipa/model/object.py +102 -0
- pyflow/analysis/ipa/model/objectname.py +77 -0
- pyflow/analysis/ipa/model/region.py +51 -0
- pyflow/analysis/ipa/summary/__init__.py +120 -0
- pyflow/analysis/ir_utils.py +215 -0
- pyflow/analysis/lifetimeanalysis/__init__.py +935 -0
- pyflow/analysis/lifetimeanalysis/database/__init__.py +17 -0
- pyflow/analysis/lifetimeanalysis/database/base.py +72 -0
- pyflow/analysis/lifetimeanalysis/database/lattice.py +189 -0
- pyflow/analysis/lifetimeanalysis/database/mapping.py +174 -0
- pyflow/analysis/lifetimeanalysis/database/structure.py +224 -0
- pyflow/analysis/lifetimeanalysis/database/tupleset.py +141 -0
- pyflow/analysis/numbering/__init__.py +17 -0
- pyflow/analysis/numbering/dataflow.py +214 -0
- pyflow/analysis/numbering/dominance.py +120 -0
- pyflow/analysis/numbering/readmodify.py +251 -0
- pyflow/analysis/numbering/ssa.py +604 -0
- pyflow/analysis/pdg/__init__.py +55 -0
- pyflow/analysis/pdg/construction.py +447 -0
- pyflow/analysis/pdg/cypher.py +1150 -0
- pyflow/analysis/pdg/dump.py +129 -0
- pyflow/analysis/pdg/graph.py +308 -0
- pyflow/analysis/programculler.py +224 -0
- pyflow/analysis/shape/__init__.py +466 -0
- pyflow/analysis/shape/constraintbuilder.py +933 -0
- pyflow/analysis/shape/constraints.py +510 -0
- pyflow/analysis/shape/dataflow.py +202 -0
- pyflow/analysis/shape/model/__init__.py +27 -0
- pyflow/analysis/shape/model/canonical.py +137 -0
- pyflow/analysis/shape/model/configuration.py +78 -0
- pyflow/analysis/shape/model/expressions.py +268 -0
- pyflow/analysis/shape/model/pathinformation.py +645 -0
- pyflow/analysis/shape/model/referencecount.py +212 -0
- pyflow/analysis/shape/model/secondary.py +31 -0
- pyflow/analysis/shape/model/slots.py +69 -0
- pyflow/analysis/shape/regionanalysis.py +152 -0
- pyflow/analysis/shape/transferfunctions.py +353 -0
- pyflow/analysis/storegraph/__init__.py +19 -0
- pyflow/analysis/storegraph/annotations.py +70 -0
- pyflow/analysis/storegraph/canonicalobjects.py +329 -0
- pyflow/analysis/storegraph/extendedtypes.py +311 -0
- pyflow/analysis/storegraph/setmanager.py +123 -0
- pyflow/analysis/storegraph/storegraph.py +577 -0
- pyflow/analysis/tools.py +112 -0
- pyflow/analysis/typeinfo/__init__.py +93 -0
- pyflow/analysis/typeinfo/_config.py +84 -0
- pyflow/analysis/typeinfo/annotation_resolver.py +483 -0
- pyflow/analysis/typeinfo/collector.py +361 -0
- pyflow/analysis/typeinfo/constants.py +378 -0
- pyflow/analysis/typeinfo/docstring_parser.py +289 -0
- pyflow/analysis/typeinfo/generic_binder.py +145 -0
- pyflow/analysis/typeinfo/gradual_typing.py +255 -0
- pyflow/analysis/typeinfo/models.py +43 -0
- pyflow/analysis/typeinfo/service.py +774 -0
- pyflow/analysis/typeinfo/string_subtype_inference.py +113 -0
- pyflow/analysis/typeinfo/string_subtypes.py +150 -0
- pyflow/analysis/typeinfo/stub_loader.py +667 -0
- pyflow/analysis/typeinfo/type_inference.py +747 -0
- pyflow/analysis/typeinfo/type_utils.py +361 -0
- pyflow/analysis/typeinfo/typesystem.py +2346 -0
- pyflow/analysis/typeinfo/typetracing.py +672 -0
- pyflow/api/__init__.py +94 -0
- pyflow/api/entrypoints/__init__.py +36 -0
- pyflow/api/entrypoints/declaration.py +345 -0
- pyflow/api/entrypoints/entry_point.py +59 -0
- pyflow/api/entrypoints/wrappers.py +83 -0
- pyflow/api/queries/__init__.py +65 -0
- pyflow/api/queries/_cfg_utils.py +53 -0
- pyflow/api/queries/_dataflow_ipa.py +29 -0
- pyflow/api/queries/_dataflow_reaching_defs.py +105 -0
- pyflow/api/queries/_dataflow_store_graph.py +152 -0
- pyflow/api/queries/_dataflow_taint.py +76 -0
- pyflow/api/queries/_models.py +177 -0
- pyflow/api/queries/call_graph.py +168 -0
- pyflow/api/queries/capabilities.py +106 -0
- pyflow/api/queries/context.py +152 -0
- pyflow/api/queries/control_flow.py +35 -0
- pyflow/api/queries/data_flow.py +157 -0
- pyflow/api/queries/engine.py +201 -0
- pyflow/api/queries/localization.py +8 -0
- pyflow/api/queries/service.py +339 -0
- pyflow/api/queries/tasks/__init__.py +8 -0
- pyflow/api/queries/tasks/code_localization.py +425 -0
- pyflow/api/queries/tasks/test_generation.py +338 -0
- pyflow/api/queries/test_generation.py +8 -0
- pyflow/application/__init__.py +109 -0
- pyflow/application/context.py +116 -0
- pyflow/application/errors.py +55 -0
- pyflow/application/makefile.py +213 -0
- pyflow/application/passes.py +515 -0
- pyflow/application/passmanager.py +755 -0
- pyflow/application/pipeline.py +459 -0
- pyflow/application/program.py +147 -0
- pyflow/checker/__init__.py +51 -0
- pyflow/checker/formatters/__init__.py +14 -0
- pyflow/checker/formatters/json.py +153 -0
- pyflow/checker/formatters/sarif.py +263 -0
- pyflow/checker/formatters/text.py +168 -0
- pyflow/checker/formatters/utils.py +17 -0
- pyflow/checker/llm/__init__.py +19 -0
- pyflow/checker/llm/exploit.py +129 -0
- pyflow/checker/llm/judge.py +105 -0
- pyflow/checker/llm/llm_utils.py +131 -0
- pyflow/checker/microbench.py +338 -0
- pyflow/checker/pattern/__init__.py +14 -0
- pyflow/checker/pattern/checkers/__init__.py +34 -0
- pyflow/checker/pattern/checkers/aws_security.py +234 -0
- pyflow/checker/pattern/checkers/blacklist_calls.py +54 -0
- pyflow/checker/pattern/checkers/blacklist_imports.py +73 -0
- pyflow/checker/pattern/checkers/class_pollution.py +459 -0
- pyflow/checker/pattern/checkers/command_injection.py +340 -0
- pyflow/checker/pattern/checkers/deserialization.py +373 -0
- pyflow/checker/pattern/checkers/django_security.py +285 -0
- pyflow/checker/pattern/checkers/exception_handling.py +317 -0
- pyflow/checker/pattern/checkers/exec_use.py +16 -0
- pyflow/checker/pattern/checkers/fastapi_security.py +291 -0
- pyflow/checker/pattern/checkers/flask_security.py +264 -0
- pyflow/checker/pattern/checkers/hardcoded_password.py +239 -0
- pyflow/checker/pattern/checkers/hardcoded_secrets.py +279 -0
- pyflow/checker/pattern/checkers/ldap_injection.py +281 -0
- pyflow/checker/pattern/checkers/path_traversal.py +124 -0
- pyflow/checker/pattern/checkers/shell_injection.py +46 -0
- pyflow/checker/pattern/checkers/sql_injection.py +170 -0
- pyflow/checker/pattern/checkers/sql_injection_enhanced.py +574 -0
- pyflow/checker/pattern/checkers/ssrf.py +419 -0
- pyflow/checker/pattern/checkers/template_security.py +310 -0
- pyflow/checker/pattern/checkers/weak_crypto.py +89 -0
- pyflow/checker/pattern/checkers/xxe_vulnerabilities.py +155 -0
- pyflow/checker/pattern/core/__init__.py +17 -0
- pyflow/checker/pattern/core/blacklist.py +569 -0
- pyflow/checker/pattern/core/config.py +15 -0
- pyflow/checker/pattern/core/constants.py +52 -0
- pyflow/checker/pattern/core/context.py +276 -0
- pyflow/checker/pattern/core/issue.py +325 -0
- pyflow/checker/pattern/core/manager.py +253 -0
- pyflow/checker/pattern/core/metrics.py +78 -0
- pyflow/checker/pattern/core/node_visitor.py +430 -0
- pyflow/checker/pattern/core/test_loader.py +41 -0
- pyflow/checker/pattern/core/test_properties.py +54 -0
- pyflow/checker/pattern/core/test_set.py +33 -0
- pyflow/checker/pattern/core/tester.py +244 -0
- pyflow/checker/pattern/core/utils.py +167 -0
- pyflow/checker/quality.py +374 -0
- pyflow/checker/semantic/__init__.py +16 -0
- pyflow/checker/semantic/core/__init__.py +23 -0
- pyflow/checker/semantic/core/base.py +26 -0
- pyflow/checker/semantic/core/context.py +270 -0
- pyflow/checker/semantic/core/issue.py +9 -0
- pyflow/checker/semantic/core/manager.py +150 -0
- pyflow/checker/semantic/core/runner.py +58 -0
- pyflow/checker/semantic/detectors/__init__.py +17 -0
- pyflow/checker/semantic/detectors/ast_helpers.py +114 -0
- pyflow/checker/semantic/detectors/leak.py +500 -0
- pyflow/checker/semantic/detectors/null_dereference.py +132 -0
- pyflow/checker/semantic/detectors/semantic_taint.py +2258 -0
- pyflow/checker/supply_chain.py +568 -0
- pyflow/cli/__init__.py +12 -0
- pyflow/cli/alias.py +397 -0
- pyflow/cli/callgraph.py +185 -0
- pyflow/cli/ir.py +461 -0
- pyflow/cli/main.py +125 -0
- pyflow/cli/optimize.py +603 -0
- pyflow/cli/security.py +1262 -0
- pyflow/cli/supply_chain.py +114 -0
- pyflow/config/nullness/django.json +21 -0
- pyflow/config/nullness/fastapi.json +17 -0
- pyflow/config/nullness/flask.json +37 -0
- pyflow/config/nullness/sql.json +21 -0
- pyflow/config/nullness/sqlalchemy.json +33 -0
- pyflow/config/nullness/stdlib.json +161 -0
- pyflow/config/rule-pack.schema.json +54 -0
- pyflow/config/taint/aiohttp.json +640 -0
- pyflow/config/taint/cloud.json +485 -0
- pyflow/config/taint/concurrency.json +25 -0
- pyflow/config/taint/django.json +710 -0
- pyflow/config/taint/falcon.json +375 -0
- pyflow/config/taint/fastapi.json +192 -0
- pyflow/config/taint/flask.json +504 -0
- pyflow/config/taint/injection.json +2294 -0
- pyflow/config/taint/network.json +367 -0
- pyflow/config/taint/nosql.json +166 -0
- pyflow/config/taint/pandas.json +463 -0
- pyflow/config/taint/requests.json +952 -0
- pyflow/config/taint/serialization.json +109 -0
- pyflow/config/taint/sql.json +730 -0
- pyflow/config/taint/sqlalchemy.json +235 -0
- pyflow/config/taint/stdlib.json +4388 -0
- pyflow/config/taint/tornado.json +151 -0
- pyflow/config/taint/xml.json +89 -0
- pyflow/config/typestate/concurrency.json +145 -0
- pyflow/config/typestate/network.json +130 -0
- pyflow/config/typestate/requests.json +88 -0
- pyflow/config/typestate/sql.json +107 -0
- pyflow/config/typestate/sqlalchemy.json +45 -0
- pyflow/config/typestate/stdlib.json +91 -0
- pyflow/config.py +30 -0
- pyflow/frontend/__init__.py +28 -0
- pyflow/frontend/ast_converter.py +2593 -0
- pyflow/frontend/class_hierarchy.py +665 -0
- pyflow/frontend/dependency_resolver.py +1836 -0
- pyflow/frontend/function_extractor.py +602 -0
- pyflow/frontend/object_manager.py +224 -0
- pyflow/frontend/programextractor.py +1033 -0
- pyflow/frontend/project_resolution.py +511 -0
- pyflow/frontend/source_locator.py +163 -0
- pyflow/frontend/stub_manager.py +425 -0
- pyflow/language/__init__.py +5 -0
- pyflow/language/asttools/__init__.py +34 -0
- pyflow/language/asttools/annotation.py +242 -0
- pyflow/language/asttools/antlrtranslator.py +344 -0
- pyflow/language/asttools/astpprint.py +132 -0
- pyflow/language/asttools/complexity.py +224 -0
- pyflow/language/asttools/decorators.py +71 -0
- pyflow/language/asttools/metaast/__init__.py +370 -0
- pyflow/language/asttools/metaast/codegeneration.py +622 -0
- pyflow/language/asttools/origin.py +83 -0
- pyflow/language/asttools/symbols.py +204 -0
- pyflow/language/asttools/visitors.py +179 -0
- pyflow/language/modules/__init__.py +18 -0
- pyflow/language/modules/_scope_graph.py +484 -0
- pyflow/language/modules/ast_helper.py +211 -0
- pyflow/language/modules/module_definitions.py +240 -0
- pyflow/language/modules/project_handler.py +110 -0
- pyflow/language/modules/transform.py +290 -0
- pyflow/language/modules/util.py +413 -0
- pyflow/language/python/__init__.py +21 -0
- pyflow/language/python/annotations.py +378 -0
- pyflow/language/python/ast.py +749 -0
- pyflow/language/python/collapser.py +604 -0
- pyflow/language/python/default_markers.py +8 -0
- pyflow/language/python/defuse.py +469 -0
- pyflow/language/python/fold.py +220 -0
- pyflow/language/python/program.py +371 -0
- pyflow/language/python/pythonbase.py +353 -0
- pyflow/language/python/pythonoutput.py +82 -0
- pyflow/language/python/simplecodegen.py +975 -0
- pyflow/optimization/__init__.py +29 -0
- pyflow/optimization/argumentnormalization.py +429 -0
- pyflow/optimization/callconverter.py +295 -0
- pyflow/optimization/clone.py +743 -0
- pyflow/optimization/codeinlining.py +587 -0
- pyflow/optimization/convertboolelimination.py +111 -0
- pyflow/optimization/cullprogram.py +155 -0
- pyflow/optimization/dataflow/__init__.py +17 -0
- pyflow/optimization/dataflow/base.py +780 -0
- pyflow/optimization/dataflow/forward.py +681 -0
- pyflow/optimization/dataflow/reverse.py +454 -0
- pyflow/optimization/dce.py +354 -0
- pyflow/optimization/fold.py +780 -0
- pyflow/optimization/loadelimination.py +342 -0
- pyflow/optimization/methodcall.py +554 -0
- pyflow/optimization/rewrite.py +129 -0
- pyflow/optimization/simplify.py +143 -0
- pyflow/optimization/storeelimination.py +129 -0
- pyflow/optimization/termrewrite.py +287 -0
- pyflow/stats/__init__.py +436 -0
- pyflow/stubs/__init__.py +34 -0
- pyflow/stubs/__pycache__/__init__.cpython-313.pyc +0 -0
- pyflow/stubs/__pycache__/lltranslator.cpython-313.pyc +0 -0
- pyflow/stubs/__pycache__/stubcollector.cpython-313.pyc +0 -0
- pyflow/stubs/lltranslator.py +493 -0
- pyflow/stubs/std/__init__.py +83 -0
- pyflow/stubs/std/__pycache__/__init__.cpython-313.pyc +0 -0
- pyflow/stubs/std/__pycache__/argparse_stubs.cpython-313.pyc +0 -0
- pyflow/stubs/std/__pycache__/collections_stubs.cpython-313.pyc +0 -0
- pyflow/stubs/std/__pycache__/container.cpython-313.pyc +0 -0
- pyflow/stubs/std/__pycache__/copy_stubs.cpython-313.pyc +0 -0
- pyflow/stubs/std/__pycache__/csv_stubs.cpython-313.pyc +0 -0
- pyflow/stubs/std/__pycache__/datetime_stubs.cpython-313.pyc +0 -0
- pyflow/stubs/std/__pycache__/functools_stubs.cpython-313.pyc +0 -0
- pyflow/stubs/std/__pycache__/hashlib_stubs.cpython-313.pyc +0 -0
- pyflow/stubs/std/__pycache__/interpreter.cpython-313.pyc +0 -0
- pyflow/stubs/std/__pycache__/io_stubs.cpython-313.pyc +0 -0
- pyflow/stubs/std/__pycache__/itertools_stubs.cpython-313.pyc +0 -0
- pyflow/stubs/std/__pycache__/json_stubs.cpython-313.pyc +0 -0
- pyflow/stubs/std/__pycache__/llfunc.cpython-313.pyc +0 -0
- pyflow/stubs/std/__pycache__/logging_stubs.cpython-313.pyc +0 -0
- pyflow/stubs/std/__pycache__/mathstubs.cpython-313.pyc +0 -0
- pyflow/stubs/std/__pycache__/operator_stubs.cpython-313.pyc +0 -0
- pyflow/stubs/std/__pycache__/os_stubs.cpython-313.pyc +0 -0
- pyflow/stubs/std/__pycache__/pathlib_stubs.cpython-313.pyc +0 -0
- pyflow/stubs/std/__pycache__/pickle_stubs.cpython-313.pyc +0 -0
- pyflow/stubs/std/__pycache__/random.cpython-313.pyc +0 -0
- pyflow/stubs/std/__pycache__/re_stubs.cpython-313.pyc +0 -0
- pyflow/stubs/std/__pycache__/sampler.cpython-313.pyc +0 -0
- pyflow/stubs/std/__pycache__/shutil_stubs.cpython-313.pyc +0 -0
- pyflow/stubs/std/__pycache__/subprocess_stubs.cpython-313.pyc +0 -0
- pyflow/stubs/std/__pycache__/sys_stubs.cpython-313.pyc +0 -0
- pyflow/stubs/std/__pycache__/tempfile_stubs.cpython-313.pyc +0 -0
- pyflow/stubs/std/__pycache__/threading_stubs.cpython-313.pyc +0 -0
- pyflow/stubs/std/__pycache__/time_stubs.cpython-313.pyc +0 -0
- pyflow/stubs/std/argparse_stubs.py +200 -0
- pyflow/stubs/std/collections_stubs.py +77 -0
- pyflow/stubs/std/container.py +374 -0
- pyflow/stubs/std/copy_stubs.py +54 -0
- pyflow/stubs/std/csv_stubs.py +187 -0
- pyflow/stubs/std/datetime_stubs.py +70 -0
- pyflow/stubs/std/functools_stubs.py +61 -0
- pyflow/stubs/std/hashlib_stubs.py +198 -0
- pyflow/stubs/std/interpreter.py +360 -0
- pyflow/stubs/std/io_stubs.py +339 -0
- pyflow/stubs/std/itertools_stubs.py +89 -0
- pyflow/stubs/std/json_stubs.py +40 -0
- pyflow/stubs/std/llfunc.py +240 -0
- pyflow/stubs/std/logging_stubs.py +295 -0
- pyflow/stubs/std/mathstubs.py +393 -0
- pyflow/stubs/std/objects/__init__.py +9 -0
- pyflow/stubs/std/objects/__pycache__/__init__.cpython-313.pyc +0 -0
- pyflow/stubs/std/objects/__pycache__/float.cpython-313.pyc +0 -0
- pyflow/stubs/std/objects/__pycache__/int.cpython-313.pyc +0 -0
- pyflow/stubs/std/objects/__pycache__/str.cpython-313.pyc +0 -0
- pyflow/stubs/std/objects/float.py +248 -0
- pyflow/stubs/std/objects/int.py +221 -0
- pyflow/stubs/std/objects/str.py +175 -0
- pyflow/stubs/std/operator_stubs.py +148 -0
- pyflow/stubs/std/os_stubs.py +727 -0
- pyflow/stubs/std/pathlib_stubs.py +364 -0
- pyflow/stubs/std/pickle_stubs.py +97 -0
- pyflow/stubs/std/random.py +29 -0
- pyflow/stubs/std/re_stubs.py +178 -0
- pyflow/stubs/std/sampler.py +17 -0
- pyflow/stubs/std/shutil_stubs.py +212 -0
- pyflow/stubs/std/subprocess_stubs.py +149 -0
- pyflow/stubs/std/sys_stubs.py +226 -0
- pyflow/stubs/std/tempfile_stubs.py +129 -0
- pyflow/stubs/std/threading_stubs.py +328 -0
- pyflow/stubs/std/time_stubs.py +283 -0
- pyflow/stubs/stubcollector.py +463 -0
- pyflow/util/PADS/Automata.py +640 -0
- pyflow/util/PADS/BFS.py +28 -0
- pyflow/util/PADS/Biconnectivity.py +270 -0
- pyflow/util/PADS/Bipartite.py +89 -0
- pyflow/util/PADS/BipartiteMatching.py +129 -0
- pyflow/util/PADS/CardinalityMatching.py +316 -0
- pyflow/util/PADS/Chordal.py +33 -0
- pyflow/util/PADS/CubicHam.py +351 -0
- pyflow/util/PADS/DFS.py +100 -0
- pyflow/util/PADS/Eratosthenes.py +138 -0
- pyflow/util/PADS/GraphExamples.py +36 -0
- pyflow/util/PADS/Graphs.py +82 -0
- pyflow/util/PADS/GrayGraph.py +36 -0
- pyflow/util/PADS/IntegerPartitions.py +317 -0
- pyflow/util/PADS/LCA.py +349 -0
- pyflow/util/PADS/LCS.py +38 -0
- pyflow/util/PADS/LexBFS.py +32 -0
- pyflow/util/PADS/LongestIncreasingSubsequence.py +65 -0
- pyflow/util/PADS/Medium.py +414 -0
- pyflow/util/PADS/MinimumSpanningTree.py +26 -0
- pyflow/util/PADS/OrderedSequence.py +133 -0
- pyflow/util/PADS/PartialCube.py +227 -0
- pyflow/util/PADS/PartialOrder.py +129 -0
- pyflow/util/PADS/PartitionRefinement.py +85 -0
- pyflow/util/PADS/ReadUndirectedGraph.py +431 -0
- pyflow/util/PADS/Repetitivity.py +160 -0
- pyflow/util/PADS/SMAWK.py +190 -0
- pyflow/util/PADS/Sequence.py +118 -0
- pyflow/util/PADS/StrongConnectivity.py +106 -0
- pyflow/util/PADS/Sudoku.py +2028 -0
- pyflow/util/PADS/UnionFind.py +63 -0
- pyflow/util/PADS/Util.py +28 -0
- pyflow/util/PADS/Wrap.py +79 -0
- pyflow/util/PADS/__init__.py +13 -0
- pyflow/util/PADS/xyzGraph.py +127 -0
- pyflow/util/__init__.py +19 -0
- pyflow/util/antlr3/__init__.py +134 -0
- pyflow/util/antlr3/compat.py +12 -0
- pyflow/util/antlr3/constants.py +24 -0
- pyflow/util/antlr3/dfa.py +179 -0
- pyflow/util/antlr3/dottreegen.py +170 -0
- pyflow/util/antlr3/exceptions.py +346 -0
- pyflow/util/antlr3/extras.py +11 -0
- pyflow/util/antlr3/main.py +198 -0
- pyflow/util/antlr3/recognizers.py +1341 -0
- pyflow/util/antlr3/streams.py +1250 -0
- pyflow/util/antlr3/tokens.py +370 -0
- pyflow/util/antlr3/tree.py +2190 -0
- pyflow/util/antlr3/treewizard.py +566 -0
- pyflow/util/application/__init__.py +13 -0
- pyflow/util/application/async_utils.py +101 -0
- pyflow/util/application/compilerexceptions.py +21 -0
- pyflow/util/application/console.py +235 -0
- pyflow/util/application/errorhandler.py +241 -0
- pyflow/util/canonical.py +204 -0
- pyflow/util/debug/__init__.py +11 -0
- pyflow/util/debug/blame.py +94 -0
- pyflow/util/debug/debugger.py +105 -0
- pyflow/util/debug/trace.py +56 -0
- pyflow/util/graphalgorithim/__init__.py +17 -0
- pyflow/util/graphalgorithim/basic.py +77 -0
- pyflow/util/graphalgorithim/color.py +104 -0
- pyflow/util/graphalgorithim/djtree.py +299 -0
- pyflow/util/graphalgorithim/dominator.py +531 -0
- pyflow/util/graphalgorithim/exclusiongraph.py +624 -0
- pyflow/util/graphalgorithim/merge.py +221 -0
- pyflow/util/io/__init__.py +6 -0
- pyflow/util/io/dot.py +540 -0
- pyflow/util/io/filesystem.py +210 -0
- pyflow/util/io/formatting.py +71 -0
- pyflow/util/io/report.py +224 -0
- pyflow/util/io/xmloutput.py +270 -0
- pyflow/util/json_dict.py +92 -0
- pyflow/util/monkeypatch/__init__.py +21 -0
- pyflow/util/monkeypatch/xcollections.py +206 -0
- pyflow/util/monkeypatch/xmath.py +108 -0
- pyflow/util/monkeypatch/xnamedtuple.py +180 -0
- pyflow/util/monkeypatch/xtypes.py +56 -0
- pyflow/util/orderedset.py +420 -0
- pyflow/util/pydot.py +1998 -0
- pyflow/util/python/__init__.py +136 -0
- pyflow/util/python/apply.py +180 -0
- pyflow/util/python/calling.py +558 -0
- pyflow/util/python/opnames.py +153 -0
- pyflow/util/randomness.py +230 -0
- pyflow/util/singleton.py +112 -0
- pyflow/util/tvl.py +321 -0
- pyflow/util/typedispatch.py +342 -0
- pyflow/util/unionfind.py +169 -0
- pyflow_analysis-0.1.0.dist-info/METADATA +184 -0
- pyflow_analysis-0.1.0.dist-info/RECORD +757 -0
- pyflow_analysis-0.1.0.dist-info/WHEEL +5 -0
- pyflow_analysis-0.1.0.dist-info/entry_points.txt +2 -0
- pyflow_analysis-0.1.0.dist-info/licenses/LICENSE.txt +202 -0
- pyflow_analysis-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
"""Generate and manipulate partitions of integers into sums of integers.
|
|
2
|
+
|
|
3
|
+
D. Eppstein, August 2005.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import unittest
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def mckay(n):
|
|
10
|
+
"""
|
|
11
|
+
Integer partitions of n, in reverse lexicographic order.
|
|
12
|
+
Note that the generated output consists of the same list object,
|
|
13
|
+
repeated the correct number of times; the caller must leave this
|
|
14
|
+
list unchanged, and must make a copy of any partition that is
|
|
15
|
+
intended to last longer than the next call into the generator.
|
|
16
|
+
The algorithm follows Knuth v4 fasc3 p38 in rough outline.
|
|
17
|
+
"""
|
|
18
|
+
if n == 0:
|
|
19
|
+
yield []
|
|
20
|
+
if n <= 0:
|
|
21
|
+
return
|
|
22
|
+
partition = [n]
|
|
23
|
+
last_nonunit = (n > 1) - 1
|
|
24
|
+
while True:
|
|
25
|
+
yield partition
|
|
26
|
+
if last_nonunit < 0:
|
|
27
|
+
return
|
|
28
|
+
if partition[last_nonunit] == 2:
|
|
29
|
+
partition[last_nonunit] = 1
|
|
30
|
+
partition.append(1)
|
|
31
|
+
last_nonunit -= 1
|
|
32
|
+
continue
|
|
33
|
+
replacement = partition[last_nonunit] - 1
|
|
34
|
+
total_replaced = replacement + len(partition) - last_nonunit
|
|
35
|
+
reps, rest = divmod(total_replaced, replacement)
|
|
36
|
+
partition[last_nonunit:] = reps * [replacement]
|
|
37
|
+
if rest:
|
|
38
|
+
partition.append(rest)
|
|
39
|
+
last_nonunit = len(partition) - (partition[-1] == 1) - 1
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def revlex_partitions(n):
|
|
43
|
+
"""
|
|
44
|
+
Integer partitions of n, in reverse lexicographic order.
|
|
45
|
+
The output and asymptotic runtime are the same as mckay(n),
|
|
46
|
+
but the algorithm is different: it involves no division,
|
|
47
|
+
and is simpler than mckay, but uses O(n) extra space for
|
|
48
|
+
a recursive call stack.
|
|
49
|
+
"""
|
|
50
|
+
if n == 0:
|
|
51
|
+
yield []
|
|
52
|
+
if n <= 0:
|
|
53
|
+
return
|
|
54
|
+
for p in revlex_partitions(n - 1):
|
|
55
|
+
if len(p) == 1 or (len(p) > 1 and p[-1] < p[-2]):
|
|
56
|
+
p[-1] += 1
|
|
57
|
+
yield p
|
|
58
|
+
p[-1] -= 1
|
|
59
|
+
p.append(1)
|
|
60
|
+
yield p
|
|
61
|
+
p.pop()
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def lex_partitions(n):
|
|
65
|
+
"""Similar to revlex_partitions, but in lexicographic order."""
|
|
66
|
+
if n == 0:
|
|
67
|
+
yield []
|
|
68
|
+
if n <= 0:
|
|
69
|
+
return
|
|
70
|
+
for p in lex_partitions(n - 1):
|
|
71
|
+
p.append(1)
|
|
72
|
+
yield p
|
|
73
|
+
p.pop()
|
|
74
|
+
if len(p) == 1 or (len(p) > 1 and p[-1] < p[-2]):
|
|
75
|
+
p[-1] += 1
|
|
76
|
+
yield p
|
|
77
|
+
p[-1] -= 1
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
partitions = revlex_partitions # default partition generating algorithm
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def binary_partitions(n):
|
|
84
|
+
"""
|
|
85
|
+
Generate partitions of n into powers of two, in revlex order.
|
|
86
|
+
Knuth exercise 7.2.1.4.64.
|
|
87
|
+
The average time per output is constant.
|
|
88
|
+
But this doesn't really solve the exercise, because it isn't loopless...
|
|
89
|
+
"""
|
|
90
|
+
|
|
91
|
+
# Generate the binary representation of n
|
|
92
|
+
if n < 0:
|
|
93
|
+
return
|
|
94
|
+
pow = 1
|
|
95
|
+
sum = 0
|
|
96
|
+
while pow <= n:
|
|
97
|
+
pow <<= 1
|
|
98
|
+
partition = []
|
|
99
|
+
while pow:
|
|
100
|
+
if sum + pow <= n:
|
|
101
|
+
partition.append(pow)
|
|
102
|
+
sum += pow
|
|
103
|
+
pow >>= 1
|
|
104
|
+
|
|
105
|
+
# Find all partitions of numbers up to n into powers of two > 1,
|
|
106
|
+
# in revlex order, by repeatedly splitting the smallest nonunit power,
|
|
107
|
+
# and replacing the following sequence of 1's by the first revlex
|
|
108
|
+
# partition with maximum power less than the result of the split.
|
|
109
|
+
|
|
110
|
+
# Time analysis:
|
|
111
|
+
#
|
|
112
|
+
# Each outer iteration increases len(partition) by at most one
|
|
113
|
+
# (only if the power being split is a 2) and each inner iteration
|
|
114
|
+
# in which some ones are replaced by x decreases len(partition),
|
|
115
|
+
# so the number of those inner iterations is less than one per
|
|
116
|
+
# output.
|
|
117
|
+
#
|
|
118
|
+
# Each time a power 2^k is split, it creates two or more 2^{k-1}'s,
|
|
119
|
+
# all of which must eventually be split as well. So, it S_k denotes
|
|
120
|
+
# the number of times a 2^k is split, and X denotes the total
|
|
121
|
+
# number of outputs generated, then S_k <= X/2^{k-1}.
|
|
122
|
+
# On an outer iteration in which 2^k is split, there will be k
|
|
123
|
+
# inner iterations in which x is halved, so the total number
|
|
124
|
+
# of such inner iterations is <= sum_k k*X/2^{k-1} = O(X).
|
|
125
|
+
#
|
|
126
|
+
# Therefore the overall average time per output is constant.
|
|
127
|
+
|
|
128
|
+
last_nonunit = len(partition) - 1 - (n & 1)
|
|
129
|
+
while True:
|
|
130
|
+
yield partition
|
|
131
|
+
if last_nonunit < 0:
|
|
132
|
+
return
|
|
133
|
+
if partition[last_nonunit] == 2:
|
|
134
|
+
partition[last_nonunit] = 1
|
|
135
|
+
partition.append(1)
|
|
136
|
+
last_nonunit -= 1
|
|
137
|
+
continue
|
|
138
|
+
partition.append(1)
|
|
139
|
+
x = partition[last_nonunit] = partition[last_nonunit + 1] = (
|
|
140
|
+
partition[last_nonunit] >> 1
|
|
141
|
+
) # make the split!
|
|
142
|
+
last_nonunit += 1
|
|
143
|
+
while x > 1:
|
|
144
|
+
if len(partition) - last_nonunit - 1 >= x:
|
|
145
|
+
del partition[-x + 1 :]
|
|
146
|
+
last_nonunit += 1
|
|
147
|
+
partition[last_nonunit] = x
|
|
148
|
+
else:
|
|
149
|
+
x >>= 1
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def fixed_length_partitions(n, L):
|
|
153
|
+
"""
|
|
154
|
+
Integer partitions of n into L parts, in colex order.
|
|
155
|
+
The algorithm follows Knuth v4 fasc3 p38 in rough outline;
|
|
156
|
+
Knuth credits it to Hindenburg, 1779.
|
|
157
|
+
"""
|
|
158
|
+
|
|
159
|
+
# guard against special cases
|
|
160
|
+
if L == 0:
|
|
161
|
+
if n == 0:
|
|
162
|
+
yield []
|
|
163
|
+
return
|
|
164
|
+
if L == 1:
|
|
165
|
+
if n > 0:
|
|
166
|
+
yield [n]
|
|
167
|
+
return
|
|
168
|
+
if n < L:
|
|
169
|
+
return
|
|
170
|
+
|
|
171
|
+
partition = [n - L + 1] + (L - 1) * [1]
|
|
172
|
+
while True:
|
|
173
|
+
yield partition
|
|
174
|
+
if partition[0] - 1 > partition[1]:
|
|
175
|
+
partition[0] -= 1
|
|
176
|
+
partition[1] += 1
|
|
177
|
+
continue
|
|
178
|
+
j = 2
|
|
179
|
+
s = partition[0] + partition[1] - 1
|
|
180
|
+
while j < L and partition[j] >= partition[0] - 1:
|
|
181
|
+
s += partition[j]
|
|
182
|
+
j += 1
|
|
183
|
+
if j >= L:
|
|
184
|
+
return
|
|
185
|
+
partition[j] = x = partition[j] + 1
|
|
186
|
+
j -= 1
|
|
187
|
+
while j > 0:
|
|
188
|
+
partition[j] = x
|
|
189
|
+
s -= x
|
|
190
|
+
j -= 1
|
|
191
|
+
partition[0] = s
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
def conjugate(p):
|
|
195
|
+
"""
|
|
196
|
+
Find the conjugate of a partition.
|
|
197
|
+
E.g. len(p) = max(conjugate(p)) and vice versa.
|
|
198
|
+
"""
|
|
199
|
+
result = []
|
|
200
|
+
j = len(p)
|
|
201
|
+
if j <= 0:
|
|
202
|
+
return result
|
|
203
|
+
while True:
|
|
204
|
+
result.append(j)
|
|
205
|
+
while len(result) >= p[j - 1]:
|
|
206
|
+
j -= 1
|
|
207
|
+
if j == 0:
|
|
208
|
+
return result
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
# If run standalone, perform unit tests
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
class PartitionTest(unittest.TestCase):
|
|
215
|
+
counts = [1, 1, 2, 3, 5, 7, 11, 15, 22, 30, 42, 56, 77, 101, 135]
|
|
216
|
+
|
|
217
|
+
def testCounts(self):
|
|
218
|
+
"""Check that each generator has the right number of outputs."""
|
|
219
|
+
for n in range(len(self.counts)):
|
|
220
|
+
self.assertEqual(self.counts[n], len(list(mckay(n))))
|
|
221
|
+
self.assertEqual(self.counts[n], len(list(lex_partitions(n))))
|
|
222
|
+
self.assertEqual(self.counts[n], len(list(revlex_partitions(n))))
|
|
223
|
+
|
|
224
|
+
def testSums(self):
|
|
225
|
+
"""Check that all outputs are partitions of the input."""
|
|
226
|
+
for n in range(len(self.counts)):
|
|
227
|
+
for p in mckay(n):
|
|
228
|
+
self.assertEqual(n, sum(p))
|
|
229
|
+
for p in revlex_partitions(n):
|
|
230
|
+
self.assertEqual(n, sum(p))
|
|
231
|
+
for p in lex_partitions(n):
|
|
232
|
+
self.assertEqual(n, sum(p))
|
|
233
|
+
|
|
234
|
+
def testRevLex(self):
|
|
235
|
+
"""Check that the revlex generators' outputs are in revlex order."""
|
|
236
|
+
for n in range(len(self.counts)):
|
|
237
|
+
last = [n + 1]
|
|
238
|
+
for p in mckay(n):
|
|
239
|
+
self.assert_(last > p)
|
|
240
|
+
last = list(p) # make less-mutable copy
|
|
241
|
+
last = [n + 1]
|
|
242
|
+
for p in revlex_partitions(n):
|
|
243
|
+
self.assert_(last > p)
|
|
244
|
+
last = list(p) # make less-mutable copy
|
|
245
|
+
|
|
246
|
+
def testLex(self):
|
|
247
|
+
"""Check that the lex generator's outputs are in lex order."""
|
|
248
|
+
for n in range(1, len(self.counts)):
|
|
249
|
+
last = []
|
|
250
|
+
for p in lex_partitions(n):
|
|
251
|
+
if not (last < p):
|
|
252
|
+
print("last:", last, "p:", p)
|
|
253
|
+
self.assert_(last < p)
|
|
254
|
+
last = list(p) # make less-mutable copy
|
|
255
|
+
|
|
256
|
+
def testRange(self):
|
|
257
|
+
"""Check that all numbers in output partitions are in range."""
|
|
258
|
+
for n in range(len(self.counts)):
|
|
259
|
+
for p in mckay(n):
|
|
260
|
+
for x in p:
|
|
261
|
+
self.assert_(0 < x <= n)
|
|
262
|
+
for p in lex_partitions(n):
|
|
263
|
+
for x in p:
|
|
264
|
+
self.assert_(0 < x <= n)
|
|
265
|
+
for p in revlex_partitions(n):
|
|
266
|
+
for x in p:
|
|
267
|
+
self.assert_(0 < x <= n)
|
|
268
|
+
|
|
269
|
+
def testFixedLength(self):
|
|
270
|
+
"""Check that the fixed length partition outputs are correct."""
|
|
271
|
+
for n in range(len(self.counts)):
|
|
272
|
+
pn = [list(p) for p in revlex_partitions(n)]
|
|
273
|
+
pn.sort()
|
|
274
|
+
np = 0
|
|
275
|
+
for L in range(n + 1):
|
|
276
|
+
pnL = [list(p) for p in fixed_length_partitions(n, L)]
|
|
277
|
+
pnL.sort()
|
|
278
|
+
np += len(pnL)
|
|
279
|
+
self.assertEqual(pnL, [p for p in pn if len(p) == L])
|
|
280
|
+
self.assertEqual(np, len(pn))
|
|
281
|
+
|
|
282
|
+
def testConjugatePartition(self):
|
|
283
|
+
"""Check that conjugating a partition forms another partition."""
|
|
284
|
+
for n in range(len(self.counts)):
|
|
285
|
+
for p in partitions(n):
|
|
286
|
+
c = conjugate(p)
|
|
287
|
+
for x in c:
|
|
288
|
+
self.assert_(0 < x <= n)
|
|
289
|
+
self.assertEqual(sum(c), n)
|
|
290
|
+
|
|
291
|
+
def testConjugateInvolution(self):
|
|
292
|
+
"""Check that double conjugation returns the same partition."""
|
|
293
|
+
for n in range(len(self.counts)):
|
|
294
|
+
for p in partitions(n):
|
|
295
|
+
self.assertEqual(p, conjugate(conjugate(p)))
|
|
296
|
+
|
|
297
|
+
def testConjugateMaxLen(self):
|
|
298
|
+
"""Check the max-length reversing property of conjugation."""
|
|
299
|
+
for n in range(1, len(self.counts)):
|
|
300
|
+
for p in partitions(n):
|
|
301
|
+
self.assertEqual(len(p), max(conjugate(p)))
|
|
302
|
+
|
|
303
|
+
def testBinary(self):
|
|
304
|
+
"""Test that the binary partitions are generated correctly."""
|
|
305
|
+
for n in range(len(self.counts)):
|
|
306
|
+
binaries = []
|
|
307
|
+
for p in partitions(n):
|
|
308
|
+
for x in p:
|
|
309
|
+
if x & (x - 1):
|
|
310
|
+
break
|
|
311
|
+
else:
|
|
312
|
+
binaries.append(list(p))
|
|
313
|
+
self.assertEqual(binaries, [list(p) for p in binary_partitions(n)])
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
if __name__ == "__main__":
|
|
317
|
+
unittest.main()
|
pyflow/util/PADS/LCA.py
ADDED
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
"""Range minimization and tree least common ancestor data structures
|
|
2
|
+
with linear space and preprocessing time, and constant query time,
|
|
3
|
+
from Bender and Farach-Colton, "The LCA Problem Revisited",
|
|
4
|
+
Proc. LATIN 2000 (pp.88-94), http://www.cs.sunysb.edu/~bender/pub/lca.ps
|
|
5
|
+
|
|
6
|
+
Some experimentation would be needed to determine how large a query
|
|
7
|
+
range needs to be to make this faster than computing the min of the range
|
|
8
|
+
directly, and how much input data is needed to make the linear space
|
|
9
|
+
version pay off compared to the much simpler LogarithmicRangeMin that
|
|
10
|
+
it uses as a subroutine.
|
|
11
|
+
|
|
12
|
+
D. Eppstein, November 2003.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
import unittest, random
|
|
16
|
+
from pyflow.util.PADS.UnionFind import UnionFind
|
|
17
|
+
|
|
18
|
+
# sets.Set is deprecated in Python 3, use built-in set instead
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class RangeMin:
|
|
22
|
+
"""If X is any list, RangeMin(X)[i:j] == min(X[i:j]).
|
|
23
|
+
Initializing RangeMin(X) takes time and space linear in len(X),
|
|
24
|
+
and querying the minimum of a range takes constant time per query.
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
def __init__(self, X):
|
|
28
|
+
"""Set up structure with sequence X as data.
|
|
29
|
+
Uses an LCA structure on a Cartesian tree for the input."""
|
|
30
|
+
self._data = list(X)
|
|
31
|
+
if len(X) > 1:
|
|
32
|
+
big = map(max, self._ansv(False), self._ansv(True))
|
|
33
|
+
parents = dict([(i, big[i][1]) for i in range(len(X)) if big[i]])
|
|
34
|
+
self._lca = LCA(parents)
|
|
35
|
+
|
|
36
|
+
def __getslice__(self, left, right):
|
|
37
|
+
"""Return min(X[left:right])."""
|
|
38
|
+
right = min(right, len(self._data)) # handle omitted right index
|
|
39
|
+
if right <= left:
|
|
40
|
+
return None # empty range has no minimum
|
|
41
|
+
return self._data[self._lca(left, right - 1)]
|
|
42
|
+
|
|
43
|
+
def __len__(self):
|
|
44
|
+
"""How much data do we have? Needed for negative index in slice."""
|
|
45
|
+
return len(self._data)
|
|
46
|
+
|
|
47
|
+
def _ansv(self, reversed):
|
|
48
|
+
"""All nearest smaller values.
|
|
49
|
+
For each x in the data, find the value smaller than x in the closest
|
|
50
|
+
position to the left of x (if not reversed) or to the right of x
|
|
51
|
+
(if reversed), and return list of pairs (smaller value,position).
|
|
52
|
+
Due to our use of positions as a tie-breaker, values equal to x
|
|
53
|
+
count as smaller on the left and larger on the right.
|
|
54
|
+
"""
|
|
55
|
+
stack = [None] # protect stack top with sentinel
|
|
56
|
+
output = [0] * len(self._data)
|
|
57
|
+
for xi in _pairs(self._data, reversed):
|
|
58
|
+
while stack[-1] > xi:
|
|
59
|
+
stack.pop()
|
|
60
|
+
output[xi[1]] = stack[-1]
|
|
61
|
+
stack.append(xi)
|
|
62
|
+
return output
|
|
63
|
+
|
|
64
|
+
def _lca(self, first, last):
|
|
65
|
+
"""Function to replace LCA when we have too little data."""
|
|
66
|
+
return 0
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
class RestrictedRangeMin:
|
|
70
|
+
"""Linear-space RangeMin for integer data obeying the constraint
|
|
71
|
+
abs(X[i]-X[i-1])==1.
|
|
72
|
+
We don't actually check this constraint, but results may be incorrect
|
|
73
|
+
if it is violated. For the use of this data structure from LCA, the
|
|
74
|
+
data are actually pairs rather than integers, but the minima of
|
|
75
|
+
all ranges are in the same positions as the minima of the integers
|
|
76
|
+
in the first positions of each pair, so the data structure still works.
|
|
77
|
+
"""
|
|
78
|
+
|
|
79
|
+
def __init__(self, X):
|
|
80
|
+
# Compute parameters for partition into blocks.
|
|
81
|
+
# Position i in X becomes transformed into
|
|
82
|
+
# position i&self._blockmask in block i>>self.blocklen
|
|
83
|
+
self._blocksize = _log2(len(X)) // 2
|
|
84
|
+
self._blockmask = (1 << self._blocksize) - 1
|
|
85
|
+
blocklen = 1 << self._blocksize
|
|
86
|
+
|
|
87
|
+
# Do partition into blocks, find minima within
|
|
88
|
+
# each block, prefix minima in each block,
|
|
89
|
+
# and suffix minima in each block
|
|
90
|
+
blocks = [] # map block to block id
|
|
91
|
+
ids = {} # map block id to PrecomputedRangeMin
|
|
92
|
+
blockmin = [] # map block to min value
|
|
93
|
+
self._prefix = [None] # map data index to prefix min of block
|
|
94
|
+
self._suffix = [] # map data index to suffix min of block
|
|
95
|
+
for i in range(0, len(X), blocklen):
|
|
96
|
+
XX = X[i : i + blocklen]
|
|
97
|
+
blockmin.append(min(XX))
|
|
98
|
+
self._prefix += PrefixMinima(XX)
|
|
99
|
+
self._suffix += PrefixMinima(XX, reversed=True)
|
|
100
|
+
blockid = len(XX) < blocklen and -1 or self._blockid(XX)
|
|
101
|
+
blocks.append(blockid)
|
|
102
|
+
if blockid not in ids:
|
|
103
|
+
ids[blockid] = PrecomputedRangeMin(_pairs(XX))
|
|
104
|
+
self._blocks = [ids[b] for b in blocks]
|
|
105
|
+
|
|
106
|
+
# Build data structure for interblock queries
|
|
107
|
+
self._blockrange = LogarithmicRangeMin(blockmin)
|
|
108
|
+
self._data = list(X)
|
|
109
|
+
|
|
110
|
+
def __getslice__(self, left, right):
|
|
111
|
+
firstblock = left >> self._blocksize
|
|
112
|
+
lastblock = (right - 1) >> self._blocksize
|
|
113
|
+
if firstblock == lastblock:
|
|
114
|
+
i = left & self._blockmask
|
|
115
|
+
position = self._blocks[firstblock][i : i + right - left][1]
|
|
116
|
+
return self._data[position + (firstblock << self._blocksize)]
|
|
117
|
+
else:
|
|
118
|
+
best = min(self._suffix[left], self._prefix[right])
|
|
119
|
+
if lastblock > firstblock + 1:
|
|
120
|
+
best = min(best, self._blockrange[firstblock + 1 : lastblock])
|
|
121
|
+
return best
|
|
122
|
+
|
|
123
|
+
def _blockid(self, XX):
|
|
124
|
+
"""Return value such that all blocks with the same
|
|
125
|
+
pattern of increments and decrements get the same id.
|
|
126
|
+
"""
|
|
127
|
+
blockid = 0
|
|
128
|
+
for i in range(1, len(XX)):
|
|
129
|
+
blockid = blockid * 2 + (XX[i] > XX[i - 1])
|
|
130
|
+
return blockid
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
class PrecomputedRangeMin:
|
|
134
|
+
"""RangeMin solved in quadratic space by precomputing all solutions."""
|
|
135
|
+
|
|
136
|
+
def __init__(self, X):
|
|
137
|
+
self._minima = [PrefixMinima(X[i:]) for i in range(len(X))]
|
|
138
|
+
|
|
139
|
+
def __getslice__(self, x, y):
|
|
140
|
+
return self._minima[x][y - x - 1]
|
|
141
|
+
|
|
142
|
+
def __len__(self):
|
|
143
|
+
return len(self._minima)
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
class LogarithmicRangeMin:
|
|
147
|
+
"""RangeMin in O(n log n) space and constant query time."""
|
|
148
|
+
|
|
149
|
+
def __init__(self, X):
|
|
150
|
+
"""Compute min(X[i:i+2**j]) for each possible i,j."""
|
|
151
|
+
self._minima = m = [list(X)]
|
|
152
|
+
for j in range(_log2(len(X))):
|
|
153
|
+
m.append(map(min, m[-1], m[-1][1 << j :]))
|
|
154
|
+
|
|
155
|
+
def __getslice__(self, x, y):
|
|
156
|
+
"""Find range minimum by representing range as the union
|
|
157
|
+
of two overlapping subranges with power-of-two lengths.
|
|
158
|
+
"""
|
|
159
|
+
j = _logtable[y - x]
|
|
160
|
+
row = self._minima[j]
|
|
161
|
+
return min(row[x], row[y - 2**j])
|
|
162
|
+
|
|
163
|
+
def __len__(self):
|
|
164
|
+
return len(self._minima[0])
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
class LCA:
|
|
168
|
+
"""Structure for finding least common ancestors in trees.
|
|
169
|
+
Tree nodes may be any hashable objects; a tree is specified
|
|
170
|
+
by a dictionary mapping nodes to their parents.
|
|
171
|
+
LCA(T)(x,y) finds the LCA of nodes x and y in tree T.
|
|
172
|
+
"""
|
|
173
|
+
|
|
174
|
+
def __init__(self, parent, RangeMinFactory=RestrictedRangeMin):
|
|
175
|
+
"""Construct LCA structure from tree parent relation."""
|
|
176
|
+
children = {}
|
|
177
|
+
for x in parent:
|
|
178
|
+
children.setdefault(parent[x], []).append(x)
|
|
179
|
+
root = [x for x in children if x not in parent]
|
|
180
|
+
if len(root) != 1:
|
|
181
|
+
raise ValueError("LCA input is not a tree")
|
|
182
|
+
|
|
183
|
+
levels = []
|
|
184
|
+
self._representatives = {}
|
|
185
|
+
self._visit(children, levels, root[0], 0)
|
|
186
|
+
if [x for x in parent if x not in self._representatives]:
|
|
187
|
+
raise ValueError("LCA input is not a tree")
|
|
188
|
+
self._rangemin = RangeMinFactory(levels)
|
|
189
|
+
|
|
190
|
+
def __call__(self, *nodes):
|
|
191
|
+
"""Find least common ancestor of a set of nodes."""
|
|
192
|
+
r = [self._representatives[x] for x in nodes]
|
|
193
|
+
return self._rangemin[min(r) : max(r) + 1][1]
|
|
194
|
+
|
|
195
|
+
def _visit(self, children, levels, node, level):
|
|
196
|
+
"""Perform Euler traversal of tree."""
|
|
197
|
+
self._representatives[node] = len(levels)
|
|
198
|
+
pair = (level, node)
|
|
199
|
+
levels.append(pair)
|
|
200
|
+
for child in children.get(node, []):
|
|
201
|
+
self._visit(children, levels, child, level + 1)
|
|
202
|
+
levels.append(pair)
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
class OfflineLCA(dict):
|
|
206
|
+
"""Find LCAs of all pairs in a given sequence, using Union-Find."""
|
|
207
|
+
|
|
208
|
+
def __init__(self, parent, pairs):
|
|
209
|
+
"""Set up to find LCAs of pairs in tree defined by parent.
|
|
210
|
+
LCA of any given pair x,y can then be found by self[x][y].
|
|
211
|
+
However unlike the online LCA structure we can not find LCAs
|
|
212
|
+
of pairs that are not supplied to us at startup time.
|
|
213
|
+
"""
|
|
214
|
+
|
|
215
|
+
# set up dictionary where answers get stored
|
|
216
|
+
dict.__init__(self)
|
|
217
|
+
for u, v in pairs:
|
|
218
|
+
self.setdefault(u, {})[v] = self.setdefault(v, {})[u] = None
|
|
219
|
+
|
|
220
|
+
# set up data structure for finding node ancestor on search path
|
|
221
|
+
# self.descendants forms a collection of disjoint sets,
|
|
222
|
+
# one set for the descendants of each search path node.
|
|
223
|
+
# self.ancestors maps disjoint set ids to the ancestors themselves.
|
|
224
|
+
self.descendants = UnionFind()
|
|
225
|
+
self.ancestors = {}
|
|
226
|
+
|
|
227
|
+
# invert the parent relationship so we can traverse the tree
|
|
228
|
+
self.children = {}
|
|
229
|
+
for x, px in parent.items():
|
|
230
|
+
self.children.setdefault(px, []).append(x)
|
|
231
|
+
root = [x for x in self.children if x not in parent]
|
|
232
|
+
if len(root) != 1:
|
|
233
|
+
raise ValueError("LCA input is not a tree")
|
|
234
|
+
|
|
235
|
+
# initiate depth first traversal
|
|
236
|
+
self.visited = set()
|
|
237
|
+
self.traverse(root[0])
|
|
238
|
+
|
|
239
|
+
def traverse(self, node):
|
|
240
|
+
"""Perform depth first traversal of tree."""
|
|
241
|
+
self.ancestors[self.descendants[node]] = node
|
|
242
|
+
for child in self.children.get(node, []):
|
|
243
|
+
self.traverse(child)
|
|
244
|
+
self.descendants.union(child, node)
|
|
245
|
+
self.ancestors[self.descendants[node]] = node
|
|
246
|
+
self.visited.add(node)
|
|
247
|
+
for query in self[node]:
|
|
248
|
+
if query in self.visited:
|
|
249
|
+
lca = self.ancestors[self.descendants[query]]
|
|
250
|
+
self[node][query] = self[query][node] = lca
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
# Various utility functions
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
def PrefixMinima(X, reversed=False):
|
|
257
|
+
"""Compute table of prefix minima
|
|
258
|
+
(or suffix minima, if reversed=True) of list X.
|
|
259
|
+
"""
|
|
260
|
+
current = None
|
|
261
|
+
output = [None] * len(X)
|
|
262
|
+
for x, i in _pairs(X, reversed):
|
|
263
|
+
if current is None:
|
|
264
|
+
current = x
|
|
265
|
+
else:
|
|
266
|
+
current = min(current, x)
|
|
267
|
+
output[i] = current
|
|
268
|
+
return output
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
def _pairs(X, reversed=False):
|
|
272
|
+
"""Return pairs (x,i) for x in list X, where i is
|
|
273
|
+
the index of x in the data, in forward or reverse order.
|
|
274
|
+
"""
|
|
275
|
+
indices = range(len(X))
|
|
276
|
+
if reversed:
|
|
277
|
+
indices.reverse()
|
|
278
|
+
return [(X[i], i) for i in indices]
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
_logtable = [None, 0]
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
def _log2(n):
|
|
285
|
+
"""Make table of logs reach up to n and return floor(log_2(n))."""
|
|
286
|
+
while len(_logtable) <= n:
|
|
287
|
+
_logtable.extend([1 + _logtable[-1]] * len(_logtable))
|
|
288
|
+
return _logtable[n]
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
# if run as "python LCA.py", run tests on random data
|
|
292
|
+
# and check that RangeMin's results are correct.
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
class RandomRangeMinTest(unittest.TestCase):
|
|
296
|
+
def testRangeMin(self):
|
|
297
|
+
for trial in range(20):
|
|
298
|
+
data = [
|
|
299
|
+
random.choice(range(1000000)) for i in range(random.randint(1, 100))
|
|
300
|
+
]
|
|
301
|
+
R = RangeMin(data)
|
|
302
|
+
for sample in range(100):
|
|
303
|
+
i = random.randint(0, len(data) - 1)
|
|
304
|
+
j = random.randint(i + 1, len(data))
|
|
305
|
+
self.assertEqual(R[i:j], min(data[i:j]))
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
class LCATest(unittest.TestCase):
|
|
309
|
+
parent = {
|
|
310
|
+
"b": "a",
|
|
311
|
+
"c": "a",
|
|
312
|
+
"d": "a",
|
|
313
|
+
"e": "b",
|
|
314
|
+
"f": "b",
|
|
315
|
+
"g": "f",
|
|
316
|
+
"h": "g",
|
|
317
|
+
"i": "g",
|
|
318
|
+
}
|
|
319
|
+
lcas = {
|
|
320
|
+
("a", "b"): "a",
|
|
321
|
+
("b", "c"): "a",
|
|
322
|
+
("c", "d"): "a",
|
|
323
|
+
("d", "e"): "a",
|
|
324
|
+
("e", "f"): "b",
|
|
325
|
+
("e", "g"): "b",
|
|
326
|
+
("e", "h"): "b",
|
|
327
|
+
("c", "i"): "a",
|
|
328
|
+
("a", "i"): "a",
|
|
329
|
+
("f", "i"): "f",
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
def testLCA(self):
|
|
333
|
+
L = LCA(self.parent)
|
|
334
|
+
for k, v in self.lcas.items():
|
|
335
|
+
self.assertEqual(L(*k), v)
|
|
336
|
+
|
|
337
|
+
def testLogLCA(self):
|
|
338
|
+
L = LCA(self.parent, LogarithmicRangeMin)
|
|
339
|
+
for k, v in self.lcas.items():
|
|
340
|
+
self.assertEqual(L(*k), v)
|
|
341
|
+
|
|
342
|
+
def testOfflineLCA(self):
|
|
343
|
+
L = OfflineLCA(self.parent, self.lcas.keys())
|
|
344
|
+
for (p, q), v in self.lcas.items():
|
|
345
|
+
self.assertEqual(L[p][q], v)
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
if __name__ == "__main__":
|
|
349
|
+
unittest.main()
|
pyflow/util/PADS/LCS.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"""Dynamic program for longest common subsequences
|
|
2
|
+
|
|
3
|
+
D. Eppstein, March 2002.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def LongestCommonSubsequence(A, B):
|
|
8
|
+
"""Find longest common subsequence of iterables A and B."""
|
|
9
|
+
A = list(A)
|
|
10
|
+
B = list(B)
|
|
11
|
+
|
|
12
|
+
# Fill dictionary lcsLen[i,j] with length of LCS of A[:i] and B[:j]
|
|
13
|
+
lcsLen = {}
|
|
14
|
+
for i in range(len(A) + 1):
|
|
15
|
+
for j in range(len(B) + 1):
|
|
16
|
+
if i == 0 or j == 0:
|
|
17
|
+
lcsLen[i, j] = 0
|
|
18
|
+
elif A[i - 1] == B[j - 1]:
|
|
19
|
+
lcsLen[i, j] = lcsLen[i - 1, j - 1] + 1
|
|
20
|
+
else:
|
|
21
|
+
lcsLen[i, j] = max(lcsLen[i - 1, j], lcsLen[i, j - 1])
|
|
22
|
+
|
|
23
|
+
# Produce actual sequence by backtracking through pairs (i,j),
|
|
24
|
+
# using computed lcsLen values to guide backtracking
|
|
25
|
+
i = len(A)
|
|
26
|
+
j = len(B)
|
|
27
|
+
LCS = []
|
|
28
|
+
while lcsLen[i, j]:
|
|
29
|
+
while lcsLen[i, j] == lcsLen[i - 1, j]:
|
|
30
|
+
i -= 1
|
|
31
|
+
while lcsLen[i, j] == lcsLen[i, j - 1]:
|
|
32
|
+
j -= 1
|
|
33
|
+
i -= 1
|
|
34
|
+
j -= 1
|
|
35
|
+
LCS.append(A[i])
|
|
36
|
+
|
|
37
|
+
LCS.reverse()
|
|
38
|
+
return LCS
|