cutcutcodec 1.0.post3__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.
Potentially problematic release.
This version of cutcutcodec might be problematic. Click here for more details.
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/__init__.py +6 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/__main__.py +38 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/c_build.py +33 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/_helper_properties.py +52 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/audio/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/audio/properties/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/audio/properties/duration.py +83 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/ffprobe.py +637 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/graph/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/graph/find.py +82 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/graph/time_backprop.py +68 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/stream/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/stream/rate_audio.py +239 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/stream/rate_video.py +97 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/stream/shape.py +107 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/stream/time_backprop.py +183 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/video/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/video/properties/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/video/properties/duration.py +162 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/video/properties/nb_frames.py +159 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/video/properties/rate.py +102 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/analysis/video/properties/timestamps.py +194 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/classes/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/classes/container.py +40 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/classes/encoder.py +152 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/classes/filter.py +33 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/classes/frame.py +127 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/classes/frame_audio.py +205 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/classes/frame_video.py +322 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/classes/layout.py +206 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/classes/meta_filter.py +41 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/classes/muxer.py +184 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/classes/node.py +164 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/classes/stream.py +182 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/classes/stream_audio.py +130 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/classes/stream_video.py +193 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/__init__.py +7 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/ast_to_file.py +125 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/export/__init__.py +6 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/export/compatibility.py +734 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/export/default.py +99 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/export/encodec.py +40 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/export/muxer.py +8 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/export/rate.py +133 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/graph_to_ast.py +477 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/graph_to_json.py +104 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/graph_to_tree.py +190 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/json_to_graph.py +114 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/parse.py +123 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/sympy_to_torch/__init__.py +15 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/sympy_to_torch/dynamic.py +544 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/sympy_to_torch/lambdify.py +612 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/sympy_to_torch/preprocess.py +698 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/sympy_to_torch/printer.py +926 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/compilation/tree_to_graph.py +168 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/edit/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/edit/decision/__init__.py +8 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/edit/operation/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/edit/operation/add.py +73 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/edit/operation/remove.py +476 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/exceptions.py +60 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/audio/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/audio/add.py +170 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/audio/cat.py +60 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/audio/cut.py +112 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/audio/delay.py +85 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/audio/equation.py +261 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/audio/fir.py +231 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/audio/identity.py +48 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/audio/resample.py +451 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/audio/subclip.py +91 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/cut.py +74 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/mix/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/mix/audio_cast.py +208 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/mix/video_cast.py +197 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/subclip.py +53 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/video/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/video/add.py +331 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/video/cat.py +60 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/video/cut.py +113 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/video/delay.py +84 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/video/equation.py +265 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/video/identity.py +48 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/video/pad.py +99 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/filters/video/subclip.py +91 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/generation/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/generation/audio/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/generation/audio/empty.py +73 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/generation/audio/equation.py +56 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/generation/audio/noise.py +243 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/generation/video/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/generation/video/c_fractal.cpython-312-x86_64-linux-gnu.so +0 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/generation/video/empty.py +69 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/generation/video/equation.py +109 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/generation/video/fractal/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/generation/video/fractal/fractal.c +116 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/generation/video/fractal/geometry.py +100 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/generation/video/fractal/mandelbrot.py +176 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/generation/video/noise.py +112 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/interfaces/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/interfaces/seedable.py +82 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/io/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/io/read_ffmpeg.py +904 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/io/read_svg.py +145 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/io/scheduler.py +356 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/io/write.py +340 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/cache/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/cache/basic.py +35 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/cache/clean/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/cache/clean/graph.py +80 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/cache/hashes/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/cache/hashes/graph.py +81 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/cache/singleton.py +47 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/cuda/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/factor/__init__.py +5 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/factor/proba.py +189 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/generalize/__init__.py +5 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/generalize/delay_to_fir.py +88 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/graph.py +17 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/parallel/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/parallel/buffer.py +90 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/core/opti/utils.py +34 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/examples/audio_5.1_narration.oga +0 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/examples/intro.webm +0 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/examples/logo.svg +13 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/examples/project.json +226 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/examples/video.mp4 +0 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/__init__.py +8 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/__main__.py +25 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/actions.py +63 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/app/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/app/app.py +248 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/base.py +50 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/container_input_ffmpeg.py +90 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/filter_audio_delay.py +9 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/filter_audio_equation.py +45 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/filter_audio_fir.py +58 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/filter_audio_subclip.py +9 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/filter_cut.py +82 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/filter_delay.py +20 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/filter_subclip.py +21 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/filter_video_delay.py +9 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/filter_video_equation.py +53 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/filter_video_subclip.py +9 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/generator_audio_equation.py +14 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/generator_audio_noise.py +19 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/generator_video_equation.py +13 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/generator_video_mandelbrot.py +60 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/all/generator_video_noise.py +18 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/base.py +99 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/default.py +27 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/documentation.py +47 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/general.py +71 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/interface.py +305 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/loader.py +41 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edit_node_state/main.py +62 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/edition_tabs.py +34 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/entry/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/entry/base.py +122 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/entry/filters.py +42 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/entry/generators.py +42 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/entry_tabs.py +46 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/export/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/export/_helper.py +54 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/export/container.py +226 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/export/doc.py +67 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/export/encodec.py +289 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/export/main.py +173 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/flowchart/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/flowchart/edge_properties.py +56 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/flowchart/main.py +280 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/flowchart/node.py +44 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/main.py +151 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/menu.py +21 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/preferences/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/preferences/audio_settings.py +183 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/preferences/main.py +41 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/preferences/video_settings.py +257 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/run.py +71 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/timeline/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/timeline/main.py +30 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/timeline/slider.py +286 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/timeline/track.py +97 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/timeline/view.py +90 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/toolbar.py +29 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/tools.py +23 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/video_preview/__init__.py +3 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/video_preview/audio_player.py +103 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/video_preview/control.py +96 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/video_preview/frame_extractor.py +254 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/gui/video_preview/main.py +115 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/__init__.py +8 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/__main__.py +27 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/coding_style.py +49 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/generation.py +52 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/install.py +72 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/run.py +58 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/abstract.py +215 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/audio_cast.py +35 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/audio_equation.py +71 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/c_memory.py +132 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/compatibility.py +27 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/compile.py +42 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/encoder.py +23 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/filter_cut.py +107 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/filter_delay.py +71 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/filter_empty.py +40 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/fir.py +143 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/hashes.py +23 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/initialisation.py +24 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/muxer.py +22 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/nan_snapshot.py +39 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/read.py +192 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/serialization_equality.py +50 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/snapshot_shape.py +21 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/sympy_to_torch.py +135 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/thread_safe.py +77 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/time_range.py +55 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/video_equation.py +77 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/testing/tests/write.py +95 -0
- cutcutcodec-1.0.post3.data/platlib/cutcutcodec/utils.py +40 -0
- cutcutcodec-1.0.post3.dist-info/LICENSE +7 -0
- cutcutcodec-1.0.post3.dist-info/METADATA +271 -0
- cutcutcodec-1.0.post3.dist-info/RECORD +233 -0
- cutcutcodec-1.0.post3.dist-info/WHEEL +5 -0
- cutcutcodec-1.0.post3.dist-info/entry_points.txt +6 -0
- cutcutcodec-1.0.post3.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,698 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
"""Prepare the work for the Printer, decompose and analyse."""
|
|
4
|
+
|
|
5
|
+
from collections import OrderedDict
|
|
6
|
+
import itertools
|
|
7
|
+
import re
|
|
8
|
+
|
|
9
|
+
from sympy.core.basic import Basic
|
|
10
|
+
from sympy.core.containers import Tuple
|
|
11
|
+
from sympy.core.numbers import NumberSymbol
|
|
12
|
+
from sympy.core.symbol import Symbol
|
|
13
|
+
from sympy.simplify.cse_main import cse
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def _broadcast(
|
|
17
|
+
symb_expr: list[tuple[Symbol, Basic]], shapes: set[frozenset[Symbol]]
|
|
18
|
+
) -> dict[Symbol, frozenset[Symbol]]:
|
|
19
|
+
r"""Find the shape of all the sub vars.
|
|
20
|
+
|
|
21
|
+
Complexity o(n).
|
|
22
|
+
|
|
23
|
+
Parameters
|
|
24
|
+
----------
|
|
25
|
+
symb_expr : list[tuple[sympy.core.symbol.Symbol, sympy.core.basic.Basic]]
|
|
26
|
+
The list of symbols and atomic expressions.
|
|
27
|
+
shapes : set[frozenset[sympy.core.symbol.Symbol]]
|
|
28
|
+
The initials shapes. For a more complete description, please refer to
|
|
29
|
+
``cutcutcodec.core.compilation.sympy_to_torch.preprocess.preprocess``.
|
|
30
|
+
|
|
31
|
+
Returns
|
|
32
|
+
-------
|
|
33
|
+
shapes : dict[sympy.core.symbol.Symbol, frozenset[sympy.core.symbol.Symbol]]
|
|
34
|
+
All the shapes, for each intermediate vars, associate the broadcast shape of the tensor.
|
|
35
|
+
|
|
36
|
+
Examples
|
|
37
|
+
--------
|
|
38
|
+
>>> from pprint import pprint
|
|
39
|
+
>>> from sympy.abc import c, x
|
|
40
|
+
>>> from sympy import Number, Tuple, sin, symbols
|
|
41
|
+
>>> from cutcutcodec.core.compilation.sympy_to_torch.preprocess import _broadcast
|
|
42
|
+
>>> _, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11 = symbols("_ _:12")
|
|
43
|
+
>>> tree = [(_1, c**(-2)), (_2, 1/x), (_0, _1*_2), (_3, Number(0)), (_6, sin(x)),
|
|
44
|
+
... (_5, sin(_6)), (_4, _5 + 1), (_7, c), (_8, c), (_9, x), (_10, x),
|
|
45
|
+
... (_11, _0), (_, Tuple(_3, _7, _8, _9, _10, _0, _11, _4))]
|
|
46
|
+
>>> shapes = _broadcast(tree, set())
|
|
47
|
+
>>> pprint({v: sorted(shapes[v], key=str) for v in sorted(shapes, key=str)}, sort_dicts=False)
|
|
48
|
+
{_0: [c, x],
|
|
49
|
+
_1: [c],
|
|
50
|
+
_10: [x],
|
|
51
|
+
_11: [c, x],
|
|
52
|
+
_2: [x],
|
|
53
|
+
_3: [],
|
|
54
|
+
_4: [x],
|
|
55
|
+
_5: [x],
|
|
56
|
+
_6: [x],
|
|
57
|
+
_7: [c],
|
|
58
|
+
_8: [c],
|
|
59
|
+
_9: [x],
|
|
60
|
+
c: [c],
|
|
61
|
+
x: [x]}
|
|
62
|
+
>>> shapes = _broadcast(tree, {frozenset({c, x})})
|
|
63
|
+
>>> pprint({v: sorted(shapes[v], key=str) for v in sorted(shapes, key=str)}, sort_dicts=False)
|
|
64
|
+
{_0: [c],
|
|
65
|
+
_1: [c],
|
|
66
|
+
_10: [c],
|
|
67
|
+
_11: [c],
|
|
68
|
+
_2: [c],
|
|
69
|
+
_3: [],
|
|
70
|
+
_4: [c],
|
|
71
|
+
_5: [c],
|
|
72
|
+
_6: [c],
|
|
73
|
+
_7: [c],
|
|
74
|
+
_8: [c],
|
|
75
|
+
_9: [c],
|
|
76
|
+
c: [c],
|
|
77
|
+
x: [c]}
|
|
78
|
+
>>>
|
|
79
|
+
"""
|
|
80
|
+
# simplification of given shapes, remove single and merge common
|
|
81
|
+
shapes_simplified = []
|
|
82
|
+
for shape in (set(s) for s in shapes if s):
|
|
83
|
+
merge = False
|
|
84
|
+
for shape_ in shapes_simplified:
|
|
85
|
+
if shape & shape_:
|
|
86
|
+
shape_ |= shape # has to be set, not frozenset for inplace operation
|
|
87
|
+
merge = True
|
|
88
|
+
if not merge:
|
|
89
|
+
shapes_simplified.append(shape)
|
|
90
|
+
shapes_simplified = [frozenset(s) for s in shapes_simplified]
|
|
91
|
+
|
|
92
|
+
# parse shapes into dict
|
|
93
|
+
min_of_set = {s: frozenset((min(s, key=str),)) for s in shapes_simplified}
|
|
94
|
+
all_shapes = {symb: min_of_set[s] for s in shapes_simplified for symb in s}
|
|
95
|
+
|
|
96
|
+
# exploration of the tree
|
|
97
|
+
for symb, expr in symb_expr:
|
|
98
|
+
if isinstance(expr, Tuple):
|
|
99
|
+
continue
|
|
100
|
+
if (free_symbols := expr.free_symbols):
|
|
101
|
+
all_shapes[symb] = frozenset.union(
|
|
102
|
+
*(all_shapes.get(s, frozenset((s,))) for s in free_symbols)
|
|
103
|
+
)
|
|
104
|
+
for free_symbol in free_symbols:
|
|
105
|
+
all_shapes[free_symbol] = all_shapes.get(free_symbol, frozenset((free_symbol,)))
|
|
106
|
+
else: # case expr is numbers
|
|
107
|
+
all_shapes[symb] = frozenset()
|
|
108
|
+
return all_shapes
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def _expr_to_atomic(expr: Basic, *, _symbols=None) -> list[tuple[Symbol, Basic]]:
|
|
112
|
+
"""Apply ``cse`` and split the sub patterns.
|
|
113
|
+
|
|
114
|
+
Sum and product expressions can contain more than 2 terms.
|
|
115
|
+
|
|
116
|
+
Parameters
|
|
117
|
+
----------
|
|
118
|
+
expr : sympy.core.basic.Basic
|
|
119
|
+
The sympy expression to split.
|
|
120
|
+
|
|
121
|
+
Returns
|
|
122
|
+
-------
|
|
123
|
+
replacements : list of (Symbol, expression) pairs
|
|
124
|
+
All of the common subexpressions that were replaced.
|
|
125
|
+
All subexpressions are atomic.
|
|
126
|
+
|
|
127
|
+
Examples
|
|
128
|
+
--------
|
|
129
|
+
>>> from pprint import pprint
|
|
130
|
+
>>> from sympy.abc import c, x
|
|
131
|
+
>>> from sympy import Tuple, sin
|
|
132
|
+
>>> from cutcutcodec.core.compilation.sympy_to_torch.preprocess import _expr_to_atomic
|
|
133
|
+
>>> exp = Tuple(0, c, c, x, x, c**-2/x, c**-2/x, sin(sin(x)) + 1)
|
|
134
|
+
>>> pprint(_expr_to_atomic(exp))
|
|
135
|
+
[(_1, c**(-2)),
|
|
136
|
+
(_2, 1/x),
|
|
137
|
+
(_0, _1*_2),
|
|
138
|
+
(_3, 0),
|
|
139
|
+
(_6, sin(x)),
|
|
140
|
+
(_5, sin(_6)),
|
|
141
|
+
(_4, _5 + 1),
|
|
142
|
+
(_7, c),
|
|
143
|
+
(_8, c),
|
|
144
|
+
(_9, x),
|
|
145
|
+
(_10, x),
|
|
146
|
+
(_11, _0),
|
|
147
|
+
(_, (_3, _7, _8, _9, _10, _0, _11, _4))]
|
|
148
|
+
>>>
|
|
149
|
+
"""
|
|
150
|
+
# initialisation
|
|
151
|
+
if _symbols is None:
|
|
152
|
+
_symbols = iter(Symbol(f"_{i}") for i in itertools.count())
|
|
153
|
+
rep, final = cse(expr, symbols=_symbols, order="none", list=False) # fastest as possible
|
|
154
|
+
rep.append(((Symbol("_") if isinstance(expr, Tuple) else next(_symbols)), final))
|
|
155
|
+
else: # if cse is already called
|
|
156
|
+
rep = [(next(_symbols), expr)]
|
|
157
|
+
|
|
158
|
+
# main
|
|
159
|
+
atom_rep = []
|
|
160
|
+
for var, sub_expr in rep:
|
|
161
|
+
if sub_expr.is_Atom:
|
|
162
|
+
atom_rep.append((var, sub_expr))
|
|
163
|
+
continue
|
|
164
|
+
subs = {}
|
|
165
|
+
for arg in sub_expr.args:
|
|
166
|
+
if (
|
|
167
|
+
arg not in subs # we don't do the same calculs several times
|
|
168
|
+
and (
|
|
169
|
+
not arg.is_Atom # replace if sub expr is not atomic
|
|
170
|
+
or (arg.is_Number and isinstance(sub_expr, Tuple)) # no numbers in Tuple
|
|
171
|
+
)
|
|
172
|
+
):
|
|
173
|
+
atom_rep += _expr_to_atomic(arg, _symbols=_symbols)
|
|
174
|
+
subs[arg] = atom_rep[-1][0]
|
|
175
|
+
if subs:
|
|
176
|
+
sub_expr = sub_expr.xreplace(subs)
|
|
177
|
+
if isinstance(sub_expr, Tuple): # make sure no duplicate and no intermediate variables
|
|
178
|
+
args = [] # this ensures the independence of the output variables
|
|
179
|
+
for arg in sub_expr.args:
|
|
180
|
+
if not re.fullmatch(r"_\d+", str(arg)) or arg in args:
|
|
181
|
+
atom_rep.append((next(_symbols), arg))
|
|
182
|
+
args.append(atom_rep[-1][0])
|
|
183
|
+
else:
|
|
184
|
+
args.append(arg)
|
|
185
|
+
sub_expr = Tuple(*args)
|
|
186
|
+
atom_rep.append((var, sub_expr))
|
|
187
|
+
|
|
188
|
+
return atom_rep
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
def _get_args(symb_expr: list[tuple[Symbol, Basic]]) -> tuple[set[Symbol], set[Symbol]]:
|
|
192
|
+
"""Search the parameters and islotate wich one are changing inplace.
|
|
193
|
+
|
|
194
|
+
Complexity o(n).
|
|
195
|
+
|
|
196
|
+
Parameters
|
|
197
|
+
----------
|
|
198
|
+
symb_expr : list[tuple[sympy.core.symbol.Symbol, sympy.core.basic.Basic]]
|
|
199
|
+
The list of symbols and atomic expressions.
|
|
200
|
+
|
|
201
|
+
Returns
|
|
202
|
+
-------
|
|
203
|
+
all_args : set[sympy.core.symbol.Symbol]
|
|
204
|
+
All the input arguments
|
|
205
|
+
args_no_safe : set[sympy.core.symbol.Symbol]
|
|
206
|
+
The subset of arguments that is not read-only.
|
|
207
|
+
These arguments are modified inplace in the function
|
|
208
|
+
If the value of these arguments has to be concerved,
|
|
209
|
+
then a copy of these arguments should be passed to the function.
|
|
210
|
+
alloc : set[sympy.core.symbol.Symbol]
|
|
211
|
+
All the internal sub vars
|
|
212
|
+
|
|
213
|
+
Examples
|
|
214
|
+
--------
|
|
215
|
+
>>> from pprint import pprint
|
|
216
|
+
>>> from sympy.abc import c, x
|
|
217
|
+
>>> from sympy import Number, Tuple, sin, symbols
|
|
218
|
+
>>> from cutcutcodec.core.compilation.sympy_to_torch.preprocess import _get_args
|
|
219
|
+
>>> _, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11 = symbols("_ _:12")
|
|
220
|
+
>>> tree = [(_1, c**(-2)), (_2, 1/x), (_0, _1*_2), (_3, Number(0)), (_6, sin(x)),
|
|
221
|
+
... (_5, sin(_6)), (_4, _5 + 1), (_7, c), (_8, c), (_9, x), (_10, x),
|
|
222
|
+
... (_11, _0), (_, Tuple(_3, _7, _8, _9, _10, _0, _11, _4))]
|
|
223
|
+
>>> args, no_safe, alloc = _get_args(tree)
|
|
224
|
+
>>> sorted(args, key=str)
|
|
225
|
+
[c, x]
|
|
226
|
+
>>> sorted(no_safe, key=str)
|
|
227
|
+
[]
|
|
228
|
+
>>> sorted(alloc, key=str)
|
|
229
|
+
[_, _0, _1, _10, _11, _2, _3, _4, _5, _6, _7, _8, _9]
|
|
230
|
+
>>>
|
|
231
|
+
"""
|
|
232
|
+
all_args, no_safe, alloc = set(), set(), set()
|
|
233
|
+
for symb, expr in symb_expr:
|
|
234
|
+
symbs = expr.free_symbols
|
|
235
|
+
all_args |= symbs - alloc
|
|
236
|
+
if symb in all_args and expr != symb:
|
|
237
|
+
no_safe.add(symb)
|
|
238
|
+
else:
|
|
239
|
+
alloc.add(symb)
|
|
240
|
+
return all_args, no_safe, alloc
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
def _isolate_cst_dyn(
|
|
244
|
+
symb_expr: list[tuple[Symbol, Basic]], cst_args: set[Symbol]
|
|
245
|
+
) -> tuple[list[tuple[Symbol, Basic]], list[tuple[Symbol, Basic]]]:
|
|
246
|
+
"""Isolate the constant subexpressions.
|
|
247
|
+
|
|
248
|
+
Complexity o(n).
|
|
249
|
+
|
|
250
|
+
Parameters
|
|
251
|
+
----------
|
|
252
|
+
symb_expr : list[tuple[sympy.core.symbol.Symbol, sympy.core.basic.Basic]]
|
|
253
|
+
Returned value of ``_expr_to_atomic``.
|
|
254
|
+
cst_args : set[sympy.core.symbol.Symbol]
|
|
255
|
+
The constants input parameters.
|
|
256
|
+
The subexpressions of this parameters will be cached.
|
|
257
|
+
|
|
258
|
+
Returns
|
|
259
|
+
-------
|
|
260
|
+
cst_tree : list[tuple[sympy.core.symbol.Symbol, sympy.core.basic.Basic]]
|
|
261
|
+
The graph to compute the constant sub expressions.
|
|
262
|
+
The last value is a ``sympy.core.containers.Tuple``.
|
|
263
|
+
dyn_tree : list[tuple[sympy.core.symbol.Symbol, sympy.core.basic.Basic]]
|
|
264
|
+
The main tree containing only dynamic expressions.
|
|
265
|
+
|
|
266
|
+
Examples
|
|
267
|
+
--------
|
|
268
|
+
>>> from pprint import pprint
|
|
269
|
+
>>> from sympy.abc import c, x
|
|
270
|
+
>>> from sympy import Number, Tuple, sin, symbols
|
|
271
|
+
>>> from cutcutcodec.core.compilation.sympy_to_torch.preprocess import _isolate_cst_dyn
|
|
272
|
+
>>> _, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11 = symbols("_ _:12")
|
|
273
|
+
>>> tree = [(_1, c**(-2)), (_2, 1/x), (_0, _1*_2), (_3, Number(0)), (_6, sin(x)),
|
|
274
|
+
... (_5, sin(_6)), (_4, _5 + 1), (_7, c), (_8, c), (_9, x), (_10, x),
|
|
275
|
+
... (_11, _0), (_, Tuple(_3, _7, _8, _9, _10, _0, _11, _4))]
|
|
276
|
+
>>> cst, dyn = _isolate_cst_dyn(tree, {c})
|
|
277
|
+
>>> pprint(cst)
|
|
278
|
+
[(_1, c**(-2)), (_7, c), (_8, c), (_, (_1, _7, _8))]
|
|
279
|
+
>>> pprint(dyn)
|
|
280
|
+
[(_2, 1/x),
|
|
281
|
+
(_0, _1*_2),
|
|
282
|
+
(_3, 0),
|
|
283
|
+
(_6, sin(x)),
|
|
284
|
+
(_5, sin(_6)),
|
|
285
|
+
(_4, _5 + 1),
|
|
286
|
+
(_9, x),
|
|
287
|
+
(_10, x),
|
|
288
|
+
(_11, _0),
|
|
289
|
+
(_, (_3, _7, _8, _9, _10, _0, _11, _4))]
|
|
290
|
+
>>>
|
|
291
|
+
"""
|
|
292
|
+
# detection of cst sub expressions
|
|
293
|
+
csts = set() # contains all the cst sub symbols
|
|
294
|
+
for symb, expr in symb_expr:
|
|
295
|
+
if not expr.is_number and all(s in cst_args or s in csts for s in expr.free_symbols):
|
|
296
|
+
csts.add(symb)
|
|
297
|
+
|
|
298
|
+
# split the constant and the dynamic sub graphs
|
|
299
|
+
cst_tree = []
|
|
300
|
+
dyn_tree = []
|
|
301
|
+
for symb, expr in symb_expr:
|
|
302
|
+
if symb in csts: # if the expression is constant
|
|
303
|
+
cst_tree.append((symb, expr))
|
|
304
|
+
else:
|
|
305
|
+
dyn_tree.append((symb, expr))
|
|
306
|
+
|
|
307
|
+
# special case all the tree is constant
|
|
308
|
+
if not dyn_tree:
|
|
309
|
+
dyn_tree.append((Symbol("_"), symb_expr[-1][0]))
|
|
310
|
+
|
|
311
|
+
# selection of usefull cst symbols
|
|
312
|
+
final_csts = set()
|
|
313
|
+
for symb, expr in dyn_tree:
|
|
314
|
+
for sub_symb in expr.free_symbols:
|
|
315
|
+
if sub_symb in csts and sub_symb not in final_csts: # we keep the statics parts
|
|
316
|
+
final_csts.add(sub_symb)
|
|
317
|
+
cst_tree.append((Symbol("_"), Tuple(*sorted(final_csts, key=str))))
|
|
318
|
+
|
|
319
|
+
return cst_tree, dyn_tree
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
def _limit_realoc(
|
|
323
|
+
symb_expr: list[tuple[Symbol, Basic]],
|
|
324
|
+
broadcasted_shapes: dict[Symbol, frozenset[Symbol]],
|
|
325
|
+
safe: set[Symbol],
|
|
326
|
+
) -> dict[Symbol, set[Symbol]]:
|
|
327
|
+
"""Optimises memory by reusing as many old variables as possible.
|
|
328
|
+
|
|
329
|
+
Complexity o(n**2).
|
|
330
|
+
The ``sympy.core.containers.Tuple`` expressions are not considered.
|
|
331
|
+
|
|
332
|
+
Parameters
|
|
333
|
+
----------
|
|
334
|
+
symb_expr : list[tuple[sympy.core.symbol.Symbol, sympy.core.basic.Basic]]
|
|
335
|
+
The list of symbols and atomic expressions.
|
|
336
|
+
broadcasted_shapes : dict[sympy.core.symbol.Symbol, frozenset[sympy.core.symbol.Symbol]]
|
|
337
|
+
For each var, associate the broadcasted shape,
|
|
338
|
+
Output of ``cutcutcodec.core.compilation.sympy_to_torch.preprocess._broadcast``.
|
|
339
|
+
safe : set[sympy.core.symbol.Symbol]
|
|
340
|
+
The variables to keep safe. For a more complete description, please refer to
|
|
341
|
+
``cutcutcodec.core.compilation.sympy_to_torch.preprocess.preprocess``.
|
|
342
|
+
|
|
343
|
+
Returns
|
|
344
|
+
-------
|
|
345
|
+
alloc : dict[sympy.core.symbol.Symbol, set[sympy.core.symbol.Symbol]]
|
|
346
|
+
The intermediate variables to be declared and their respective dimensions.
|
|
347
|
+
symb_expr : list[tuple[sympy.core.symbol.Symbol, sympy.core.basic.Basic]]
|
|
348
|
+
The new equivalent tree that minimize the realocation and take care of the shapes.
|
|
349
|
+
|
|
350
|
+
Examples
|
|
351
|
+
--------
|
|
352
|
+
>>> from pprint import pprint
|
|
353
|
+
>>> from sympy.abc import c, x
|
|
354
|
+
>>> from sympy import Number, Tuple, sin, symbols
|
|
355
|
+
>>> from cutcutcodec.core.compilation.sympy_to_torch.preprocess import _broadcast, _limit_realoc
|
|
356
|
+
>>> _, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11 = symbols("_ _:12")
|
|
357
|
+
>>> tree = [(_1, c**(-2)), (_2, 1/x), (_0, _1*_2), (_3, Number(0)), (_6, sin(x)),
|
|
358
|
+
... (_5, sin(_6)), (_4, _5 + 1), (_7, c), (_8, c), (_9, x), (_10, x),
|
|
359
|
+
... (_11, _0), (_, Tuple(_3, _7, _8, _9, _10, _0, _11, _4))]
|
|
360
|
+
>>> alloc, tree = _limit_realoc(tree, _broadcast(tree, set()), {c, x})
|
|
361
|
+
>>> pprint({v: sorted(alloc[v], key=str) for v in sorted(alloc, key=str)}, sort_dicts=False)
|
|
362
|
+
{_0: [c, x], _1: [c], _10: [x], _11: [c, x], _2: [x], _3: [], _8: [c], _9: [x]}
|
|
363
|
+
>>> pprint(tree)
|
|
364
|
+
[(_1, c**(-2)),
|
|
365
|
+
(_2, 1/x),
|
|
366
|
+
(_0, _1*_2),
|
|
367
|
+
(_3, 0),
|
|
368
|
+
(_2, sin(x)),
|
|
369
|
+
(_2, sin(_2)),
|
|
370
|
+
(_2, _2 + 1),
|
|
371
|
+
(_1, c),
|
|
372
|
+
(_8, c),
|
|
373
|
+
(_9, x),
|
|
374
|
+
(_10, x),
|
|
375
|
+
(_11, _0),
|
|
376
|
+
(_, (_3, _1, _8, _9, _10, _0, _11, _2))]
|
|
377
|
+
>>> alloc, tree = _limit_realoc(tree, _broadcast(tree, {frozenset({c, x})}), set())
|
|
378
|
+
>>> pprint({v: sorted(alloc[v], key=str) for v in sorted(alloc, key=str)}, sort_dicts=False)
|
|
379
|
+
{_0: [c], _1: [c], _11: [c], _2: [c], _3: [], _9: [c]}
|
|
380
|
+
>>> pprint(tree)
|
|
381
|
+
[(_1, c**(-2)),
|
|
382
|
+
(_2, 1/x),
|
|
383
|
+
(_0, _1*_2),
|
|
384
|
+
(_3, 0),
|
|
385
|
+
(_2, sin(x)),
|
|
386
|
+
(_2, sin(_2)),
|
|
387
|
+
(_2, _2 + 1),
|
|
388
|
+
(_1, c),
|
|
389
|
+
(_9, x),
|
|
390
|
+
(_11, _0),
|
|
391
|
+
(_, (_3, _1, c, _9, x, _0, _11, _2))]
|
|
392
|
+
>>>
|
|
393
|
+
"""
|
|
394
|
+
args, _, _ = _get_args(symb_expr)
|
|
395
|
+
|
|
396
|
+
# at each step, find the new free sub symbols
|
|
397
|
+
used = [set()]
|
|
398
|
+
for _, expr in reversed(symb_expr):
|
|
399
|
+
used.insert(0, used[0] | expr.free_symbols)
|
|
400
|
+
all_new_free: list[set[Symbol]] = ( # each step, the new free vars o(n**2)
|
|
401
|
+
[(u1-u2)-safe for u1, u2 in zip(used[:-1], used[1:])]
|
|
402
|
+
)
|
|
403
|
+
|
|
404
|
+
# replacement line by line
|
|
405
|
+
new_tree: list[tuple[Symbol, Basic]] = [] # the new tree with substitutions
|
|
406
|
+
free: set[Symbol] = set() # the free symbols at the current step i
|
|
407
|
+
subs: dict[Symbol, Symbol] = {} # each old name, associate the new one
|
|
408
|
+
for new_free, (old_symb, old_expr) in zip(all_new_free, symb_expr):
|
|
409
|
+
# replace old vars by new
|
|
410
|
+
symb = subs.get(old_symb, old_symb)
|
|
411
|
+
expr = old_expr.xreplace(subs)
|
|
412
|
+
free |= {subs.get(s, s) for s in new_free}
|
|
413
|
+
# particular case
|
|
414
|
+
if isinstance(old_expr, Tuple): # particular case of tuple, end of tree
|
|
415
|
+
new_tree.append((symb, expr))
|
|
416
|
+
break
|
|
417
|
+
# selection of the new substitution variable
|
|
418
|
+
symb = min(
|
|
419
|
+
{f for f in free if broadcasted_shapes[f] == broadcasted_shapes[symb]},
|
|
420
|
+
key=lambda s: ((s != expr), (not str(s).startswith("_")), str(s)),
|
|
421
|
+
default=symb,
|
|
422
|
+
)
|
|
423
|
+
if symb != expr:
|
|
424
|
+
new_tree.append((symb, expr))
|
|
425
|
+
# updates the context
|
|
426
|
+
free -= {symb}
|
|
427
|
+
subs[old_symb] = symb
|
|
428
|
+
subs = {o: subs.get(n, n) for o, n in subs.items()}
|
|
429
|
+
broadcasted_shapes = {subs.get(s, s): v for s, v in broadcasted_shapes.items()}
|
|
430
|
+
|
|
431
|
+
# search for allocated variables and their size
|
|
432
|
+
alloc = {a: s for a, s in broadcasted_shapes.items() if a not in args}
|
|
433
|
+
return alloc, new_tree
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
def _rename(
|
|
437
|
+
symb_expr: list[tuple[Symbol, Basic]], subs: dict[Symbol, Symbol], *, return_subs=False
|
|
438
|
+
) -> list[tuple[Symbol, Basic]]:
|
|
439
|
+
"""Replace and rename the symbols in canonical order.
|
|
440
|
+
|
|
441
|
+
Complexity o(n).
|
|
442
|
+
|
|
443
|
+
Parameters
|
|
444
|
+
----------
|
|
445
|
+
symb_expr : list[tuple[sympy.core.symbol.Symbol, sympy.core.basic.Basic]]
|
|
446
|
+
The list of symbols and atomic expressions.
|
|
447
|
+
subs : dict[sympy.core.symbol.Symbol, sympy.core.symbol.Symbol]
|
|
448
|
+
The replacement name of some symbols.
|
|
449
|
+
return_subs : boolean, defaul=False
|
|
450
|
+
If set to True, return the dictionary of the substitutions.
|
|
451
|
+
|
|
452
|
+
Returns
|
|
453
|
+
-------
|
|
454
|
+
new_tree : list[tuple[sympy.core.symbol.Symbol, sympy.core.basic.Basic]]
|
|
455
|
+
The renamed elements.
|
|
456
|
+
|
|
457
|
+
Examples
|
|
458
|
+
--------
|
|
459
|
+
>>> from pprint import pprint
|
|
460
|
+
>>> from sympy.abc import c, x
|
|
461
|
+
>>> from sympy import Number, Tuple, sin, symbols
|
|
462
|
+
>>> from cutcutcodec.core.compilation.sympy_to_torch.preprocess import _rename
|
|
463
|
+
>>> _, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11 = symbols("_ _:12")
|
|
464
|
+
>>> tree = [(_1, c**(-2)), (_2, 1/x), (_0, _1*_2), (_3, Number(0)), (_6, sin(x)),
|
|
465
|
+
... (_5, sin(_6)), (_4, _5 + 1), (_7, c), (_8, c), (_9, x), (_10, x),
|
|
466
|
+
... (_11, _0), (_, Tuple(_3, _7, _8, _9, _10, _0, _11, _4))]
|
|
467
|
+
>>> pprint(_rename(tree, {}))
|
|
468
|
+
[(_0, c**(-2)),
|
|
469
|
+
(_1, 1/x),
|
|
470
|
+
(_2, _0*_1),
|
|
471
|
+
(_3, 0),
|
|
472
|
+
(_4, sin(x)),
|
|
473
|
+
(_5, sin(_4)),
|
|
474
|
+
(_6, _5 + 1),
|
|
475
|
+
(_7, c),
|
|
476
|
+
(_8, c),
|
|
477
|
+
(_9, x),
|
|
478
|
+
(_10, x),
|
|
479
|
+
(_11, _2),
|
|
480
|
+
(_, (_3, _7, _8, _9, _10, _2, _11, _6))]
|
|
481
|
+
>>> tree = [(_1, c**(-2)), (_2, 1/x), (_0, _1*_2), (_3, Number(0)), (_2, sin(x)),
|
|
482
|
+
... (_2, sin(_2)), (_2, _2 + 1), (_1, c), (_9, x), (_11, _0),
|
|
483
|
+
... (_, Tuple(_3, _1, c, _9, x, _0, _11, _2))]
|
|
484
|
+
>>> pprint(_rename(tree, {}))
|
|
485
|
+
[(_0, c**(-2)),
|
|
486
|
+
(_1, 1/x),
|
|
487
|
+
(_2, _0*_1),
|
|
488
|
+
(_3, 0),
|
|
489
|
+
(_1, sin(x)),
|
|
490
|
+
(_1, sin(_1)),
|
|
491
|
+
(_1, _1 + 1),
|
|
492
|
+
(_0, c),
|
|
493
|
+
(_4, x),
|
|
494
|
+
(_5, _2),
|
|
495
|
+
(_, (_3, _0, c, _4, x, _2, _5, _1))]
|
|
496
|
+
>>>
|
|
497
|
+
"""
|
|
498
|
+
subs_local = subs.copy()
|
|
499
|
+
renamed_tree = []
|
|
500
|
+
symbols = iter(Symbol(f"_{i}") for i in itertools.count())
|
|
501
|
+
|
|
502
|
+
for symb, expr in symb_expr:
|
|
503
|
+
if symb not in subs_local and re.fullmatch(r"_\d+", str(symb)):
|
|
504
|
+
subs_local[symb] = next(symbols)
|
|
505
|
+
renamed_tree.append((subs_local.get(symb, symb), expr.xreplace(subs_local)))
|
|
506
|
+
|
|
507
|
+
if return_subs:
|
|
508
|
+
return subs_local, renamed_tree
|
|
509
|
+
return renamed_tree
|
|
510
|
+
|
|
511
|
+
|
|
512
|
+
def evalf(expr: Basic) -> Basic:
|
|
513
|
+
"""Numerical eval and simplification of the expression.
|
|
514
|
+
|
|
515
|
+
Parameters
|
|
516
|
+
----------
|
|
517
|
+
expr : sympy.Expr
|
|
518
|
+
The sympy expression to symplify as numerical evaluable.
|
|
519
|
+
|
|
520
|
+
Returns
|
|
521
|
+
-------
|
|
522
|
+
sympy.Expr
|
|
523
|
+
The quite equivalent expression with floats.
|
|
524
|
+
|
|
525
|
+
Examples
|
|
526
|
+
--------
|
|
527
|
+
>>> import sympy
|
|
528
|
+
>>> from cutcutcodec.core.compilation.sympy_to_torch.preprocess import evalf
|
|
529
|
+
>>> evalf(sympy.pi)
|
|
530
|
+
3.141592653589793238462643
|
|
531
|
+
>>> evalf(sympy.sin(sympy.sin(1)))
|
|
532
|
+
0.7456241416655578888931511
|
|
533
|
+
>>> evalf(sympy.sqrt(2))
|
|
534
|
+
1.414213562373095048801689
|
|
535
|
+
>>>
|
|
536
|
+
"""
|
|
537
|
+
assert isinstance(expr, Basic), expr.__class__.__name__
|
|
538
|
+
if isinstance(expr, Tuple):
|
|
539
|
+
return Tuple(*map(evalf, expr))
|
|
540
|
+
if sub := expr.atoms(NumberSymbol):
|
|
541
|
+
expr = expr.xreplace({s: s.evalf(n=25) for s in sub})
|
|
542
|
+
return expr.evalf(n=25) # the float128 mantissa is 80 bits => n = ceil(log10(2**80)) = 25
|
|
543
|
+
|
|
544
|
+
|
|
545
|
+
def preprocess(
|
|
546
|
+
expr: Basic, cst_args: set[Symbol], shapes: set[frozenset[Symbol]], safe: set[Symbol]
|
|
547
|
+
) -> tuple[list[tuple[Symbol, Basic]], dict[Symbol, set[Symbol]], list[tuple[Symbol, Basic]]]:
|
|
548
|
+
"""Decompose and analyse the expression for the printer.
|
|
549
|
+
|
|
550
|
+
Parameters
|
|
551
|
+
----------
|
|
552
|
+
expr : sympy.core.basic.Basic
|
|
553
|
+
The complete sympy expression to compile.
|
|
554
|
+
cst_args : set[sympy.core.symbol.Symbol], optional
|
|
555
|
+
Arguments that change infrequently enough to be cached.
|
|
556
|
+
shapes : set[frozenset[sympy.core.symbol.Symbol]], optional
|
|
557
|
+
If some parameters have the same shape, it is possible to give this information
|
|
558
|
+
in order to find a more optimal solution for limited the allocations.
|
|
559
|
+
It variable represents the set of all tensor subsets with the same shapes.
|
|
560
|
+
For example, {frozenset({a, b, c}), frozenset({x, y})} means that
|
|
561
|
+
a, b, and c are the same shape, and x and y as well.
|
|
562
|
+
safe : set[sympy.core.symbol.Symbol]
|
|
563
|
+
A subset of arguments that should definitely not be modified in place
|
|
564
|
+
or returned without a copy. The variables provided to this set are safe.
|
|
565
|
+
Arguments not present in this set can be reused internally in order to optimize memory.
|
|
566
|
+
|
|
567
|
+
Returns
|
|
568
|
+
-------
|
|
569
|
+
tree : dict
|
|
570
|
+
cst_args : set[sympy.core.symbol.Symbol]
|
|
571
|
+
All the inputs arguments required for the cst tree input.
|
|
572
|
+
cst_alloc : dict[sympy.core.symbol.Symbol, set[sympy.core.symbol.Symbol]]
|
|
573
|
+
The intermediate variables to be declared and their respective dimensions for cst tree.
|
|
574
|
+
cst_tree : list[tuple[sympy.core.symbol.Symbol, typing.Union[sympy.core.basic.Basic, None]]]
|
|
575
|
+
Each steps of the cached function.
|
|
576
|
+
dyn_args : set[sympy.core.symbol.Symbol]
|
|
577
|
+
All the inputs arguments required for the dyn tree input.
|
|
578
|
+
dyn_alloc : dict[sympy.core.symbol.Symbol, set[sympy.core.symbol.Symbol]]
|
|
579
|
+
The intermediate variables to be declared and their respective dimensions for dyn tree.
|
|
580
|
+
dyn_tree : list[tuple[sympy.core.symbol.Symbol, typing.Union[sympy.core.basic.Basic, None]]]
|
|
581
|
+
Each steps of the main function.
|
|
582
|
+
|
|
583
|
+
Examples
|
|
584
|
+
--------
|
|
585
|
+
>>> from pprint import pprint
|
|
586
|
+
>>> from sympy.abc import c, x
|
|
587
|
+
>>> from sympy import Tuple, sin
|
|
588
|
+
>>> from cutcutcodec.core.compilation.sympy_to_torch.preprocess import preprocess
|
|
589
|
+
>>> exp = Tuple(0, c, c, x, x, c**-2/x, c**-2/x, sin(sin(x)) + 1)
|
|
590
|
+
>>> def print_tree(tree):
|
|
591
|
+
... print(
|
|
592
|
+
... "cst_alloc:",
|
|
593
|
+
... {
|
|
594
|
+
... s: sorted(tree["cst_alloc"][s], key=str)
|
|
595
|
+
... for s in sorted(tree["cst_alloc"], key=str)
|
|
596
|
+
... }
|
|
597
|
+
... )
|
|
598
|
+
... print("cst_tree:")
|
|
599
|
+
... pprint(tree["cst_tree"])
|
|
600
|
+
... print(
|
|
601
|
+
... "dyn_alloc:",
|
|
602
|
+
... {
|
|
603
|
+
... s: sorted(tree["dyn_alloc"][s], key=str)
|
|
604
|
+
... for s in sorted(tree["dyn_alloc"], key=str)
|
|
605
|
+
... }
|
|
606
|
+
... )
|
|
607
|
+
... print("dyn_tree:")
|
|
608
|
+
... pprint(tree["dyn_tree"])
|
|
609
|
+
...
|
|
610
|
+
>>> tree = preprocess(exp, {c}, set(), {c, x})
|
|
611
|
+
>>> print_tree(tree)
|
|
612
|
+
cst_alloc: {_cst_0: [c], _cst_1: [c], _cst_2: [c]}
|
|
613
|
+
cst_tree:
|
|
614
|
+
[(_cst_0, c**(-2)), (_cst_1, c), (_cst_2, c), (_, (_cst_0, _cst_1, _cst_2))]
|
|
615
|
+
dyn_alloc: {_0: [x], _1: [c, x], _2: [], _3: [x], _4: [x], _5: [c, x]}
|
|
616
|
+
dyn_tree:
|
|
617
|
+
[(_0, 1/x),
|
|
618
|
+
(_1, _0*_cst_0),
|
|
619
|
+
(_2, 0),
|
|
620
|
+
(_0, sin(x)),
|
|
621
|
+
(_0, sin(_0)),
|
|
622
|
+
(_0, _0 + 1.0),
|
|
623
|
+
(_3, x),
|
|
624
|
+
(_4, x),
|
|
625
|
+
(_5, _1),
|
|
626
|
+
(_, (_2, _cst_1, _cst_2, _3, _4, _1, _5, _0))]
|
|
627
|
+
>>> tree = preprocess(exp, set(), {frozenset({c, x})}, set())
|
|
628
|
+
>>> print_tree(tree)
|
|
629
|
+
cst_alloc: {c: [c], x: [c]}
|
|
630
|
+
cst_tree:
|
|
631
|
+
[(_, ())]
|
|
632
|
+
dyn_alloc: {_0: [c], _1: [c], _2: [], _3: [c], _4: [c], _5: [c]}
|
|
633
|
+
dyn_tree:
|
|
634
|
+
[(_0, c**(-2)),
|
|
635
|
+
(_1, 1/x),
|
|
636
|
+
(_0, _0*_1),
|
|
637
|
+
(_2, 0),
|
|
638
|
+
(_1, sin(x)),
|
|
639
|
+
(_1, sin(_1)),
|
|
640
|
+
(_1, _1 + 1.0),
|
|
641
|
+
(_3, c),
|
|
642
|
+
(_4, x),
|
|
643
|
+
(_5, _0),
|
|
644
|
+
(_, (_2, _3, c, _4, x, _0, _5, _1))]
|
|
645
|
+
>>>
|
|
646
|
+
"""
|
|
647
|
+
assert isinstance(expr, Basic), expr.__class__.__name__
|
|
648
|
+
assert isinstance(cst_args, set), cst_args.__class__.__name__
|
|
649
|
+
assert all(isinstance(s, Symbol) for s in cst_args), cst_args
|
|
650
|
+
assert cst_args.issubset(expr.free_symbols), f"{cst_args} not in {expr}"
|
|
651
|
+
assert isinstance(shapes, set), shapes.__class__.__name__
|
|
652
|
+
assert all(isinstance(g, frozenset) for g in shapes), shapes
|
|
653
|
+
assert all(isinstance(v, Symbol) for g in shapes for v in g), shapes
|
|
654
|
+
assert isinstance(safe, set), safe
|
|
655
|
+
assert all(isinstance(s, Symbol) for s in safe), safe
|
|
656
|
+
|
|
657
|
+
# decompose an split
|
|
658
|
+
atomic_tree = _expr_to_atomic(evalf(expr)) # decompose to atomic steps
|
|
659
|
+
cst_tree, dyn_tree = _isolate_cst_dyn(atomic_tree, cst_args) # isolate the cachable operations
|
|
660
|
+
|
|
661
|
+
# optimise cst tree
|
|
662
|
+
names = cst_tree[-1][1]
|
|
663
|
+
cst_args, _, _ = _get_args(cst_tree[:-1])
|
|
664
|
+
cst_alloc, cst_tree = _limit_realoc(cst_tree, _broadcast(cst_tree, shapes), safe=cst_args)
|
|
665
|
+
names = OrderedDict(zip(names, cst_tree[-1][1]))
|
|
666
|
+
subs, cst_tree = _rename(
|
|
667
|
+
cst_tree,
|
|
668
|
+
{
|
|
669
|
+
s: Symbol(f"_cst_{i}")
|
|
670
|
+
for i, s in enumerate(cst_tree[-1][1])
|
|
671
|
+
if re.fullmatch(r"_\d+", str(s))
|
|
672
|
+
},
|
|
673
|
+
return_subs=True
|
|
674
|
+
)
|
|
675
|
+
names = dict(zip(names, cst_tree[-1][1]))
|
|
676
|
+
cst_alloc = {subs.get(symb, symb): shape for symb, shape in cst_alloc.items()}
|
|
677
|
+
|
|
678
|
+
# optimize dyn tree
|
|
679
|
+
dyn_tree = _rename(dyn_tree, names, return_subs=False)
|
|
680
|
+
dyn_alloc, dyn_tree = _limit_realoc(
|
|
681
|
+
dyn_tree, _broadcast(cst_tree[:-1]+dyn_tree, shapes), safe=(safe | set(names.values()))
|
|
682
|
+
)
|
|
683
|
+
subs, dyn_tree = _rename(dyn_tree, {n: n for n in names.values()}, return_subs=True)
|
|
684
|
+
dyn_alloc = {subs.get(symb, symb): shape for symb, shape in dyn_alloc.items()}
|
|
685
|
+
|
|
686
|
+
# analyse parameters and safety
|
|
687
|
+
dyn_args, _, dyn_alloc_symbs = _get_args(dyn_tree)
|
|
688
|
+
dyn_alloc = {symb: shape for symb, shape in dyn_alloc.items() if symb in dyn_alloc_symbs}
|
|
689
|
+
|
|
690
|
+
# combine all the informations
|
|
691
|
+
return {
|
|
692
|
+
"cst_args": cst_args,
|
|
693
|
+
"cst_alloc": cst_alloc,
|
|
694
|
+
"cst_tree": cst_tree,
|
|
695
|
+
"dyn_args": dyn_args,
|
|
696
|
+
"dyn_alloc": dyn_alloc,
|
|
697
|
+
"dyn_tree": dyn_tree,
|
|
698
|
+
}
|