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,544 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
"""Torch dynamic evaluation of atomic sympy expression.
|
|
4
|
+
|
|
5
|
+
It is faster to initialise than the compilated version but it is slower to evaluate.
|
|
6
|
+
This dynamic evaluation support broadcasting.
|
|
7
|
+
|
|
8
|
+
Implemented functions:
|
|
9
|
+
|
|
10
|
+
* sympy.Abs
|
|
11
|
+
* sympy.acos
|
|
12
|
+
* sympy.acosh
|
|
13
|
+
* sympy.Add `+`
|
|
14
|
+
* sympy.asin
|
|
15
|
+
* sympy.atan
|
|
16
|
+
* sympy.cbrt
|
|
17
|
+
* sympy.cos
|
|
18
|
+
* sympy.cosh
|
|
19
|
+
* sympy.exp
|
|
20
|
+
* sympy.im
|
|
21
|
+
* sympy.log
|
|
22
|
+
* sympy.Mul `*`
|
|
23
|
+
* sympy.Pow `/` and `**`
|
|
24
|
+
* sympy.re
|
|
25
|
+
* sympy.sin
|
|
26
|
+
* sympy.sinh
|
|
27
|
+
* sympy.sqrt
|
|
28
|
+
* sympy.tan
|
|
29
|
+
* sympy.tanh
|
|
30
|
+
* sympy.Tuple
|
|
31
|
+
|
|
32
|
+
Not implemented functions:
|
|
33
|
+
|
|
34
|
+
* sympy.Add `+` and `-`
|
|
35
|
+
* sympy.And
|
|
36
|
+
* sympy.arg
|
|
37
|
+
* sympy.asinh
|
|
38
|
+
* sympy.atan2
|
|
39
|
+
* sympy.atanh
|
|
40
|
+
* sympy.ceiling
|
|
41
|
+
* sympy.Determinant
|
|
42
|
+
* sympy.Eq
|
|
43
|
+
* sympy.erf
|
|
44
|
+
* sympy.floor
|
|
45
|
+
* sympy.GreaterThan
|
|
46
|
+
* sympy.HadamardProduct
|
|
47
|
+
* sympy.LessThan
|
|
48
|
+
* sympy.loggamma
|
|
49
|
+
* sympy.MatAdd
|
|
50
|
+
* sympy.Max
|
|
51
|
+
* sympy.Min
|
|
52
|
+
* sympy.Mod `%`
|
|
53
|
+
* sympy.Ne
|
|
54
|
+
* sympy.Not
|
|
55
|
+
* sympy.Or
|
|
56
|
+
* sympy.sign
|
|
57
|
+
* sympy.StrictGreaterThan
|
|
58
|
+
* sympy.StrictLessThan
|
|
59
|
+
* sympy.Trace
|
|
60
|
+
"""
|
|
61
|
+
|
|
62
|
+
import numbers
|
|
63
|
+
import typing
|
|
64
|
+
|
|
65
|
+
from sympy.core.basic import Basic
|
|
66
|
+
from sympy.core.numbers import nan, oo
|
|
67
|
+
import torch
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def _dyn_eval(
|
|
71
|
+
expr: Basic, input_args: dict[str, torch.Tensor], new_var: typing.Optional[str] = None
|
|
72
|
+
) -> typing.Union[torch.Tensor, numbers.Real, tuple]:
|
|
73
|
+
"""Recursive replacement of sympy element by numerical elements.
|
|
74
|
+
|
|
75
|
+
Parameters
|
|
76
|
+
----------
|
|
77
|
+
expr : sympy.core.basic.Basic
|
|
78
|
+
The sympy expression to eval.
|
|
79
|
+
input_args : dict[str, torch.Tensor]
|
|
80
|
+
To each variable name present in the expression, associate the numerical value.
|
|
81
|
+
new_var : str, optional
|
|
82
|
+
If provide, complete inplace the dictionary ``input_args``.
|
|
83
|
+
If the variable is already present in the ``input_args``,
|
|
84
|
+
the values of the tensor are changed inplace.
|
|
85
|
+
"""
|
|
86
|
+
if expr.is_Atom:
|
|
87
|
+
if expr.is_symbol:
|
|
88
|
+
value = input_args[str(expr)]
|
|
89
|
+
if isinstance(value, torch.Tensor):
|
|
90
|
+
value = value.clone()
|
|
91
|
+
elif expr.is_integer or expr.is_real:
|
|
92
|
+
value = float(expr)
|
|
93
|
+
elif expr.is_complex:
|
|
94
|
+
value = complex(expr)
|
|
95
|
+
elif expr in {nan, oo, -oo}:
|
|
96
|
+
value = {nan: torch.nan, oo: torch.inf, -oo: -torch.inf}[expr]
|
|
97
|
+
else:
|
|
98
|
+
raise NotImplementedError(f"unknown atomic {expr}")
|
|
99
|
+
if new_var is not None:
|
|
100
|
+
input_args[new_var] = value
|
|
101
|
+
return value
|
|
102
|
+
try:
|
|
103
|
+
func = globals()[f"_{expr.__class__.__name__.lower()}"]
|
|
104
|
+
except KeyError as err:
|
|
105
|
+
raise NotImplementedError(f"no function {expr.__class__.__name__} for {expr}") from err
|
|
106
|
+
return func(expr, input_args, new_var)
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def _abs(
|
|
110
|
+
expr: Basic, input_args: dict[str, torch.Tensor], new_var: typing.Optional[str] = None,
|
|
111
|
+
) -> typing.Union[torch.Tensor, numbers.Real]:
|
|
112
|
+
"""Dynamic abs operation.
|
|
113
|
+
|
|
114
|
+
Examples
|
|
115
|
+
--------
|
|
116
|
+
>>> from sympy.abc import x
|
|
117
|
+
>>> import torch
|
|
118
|
+
>>> from cutcutcodec.core.compilation.sympy_to_torch.dynamic import _dyn_eval
|
|
119
|
+
>>> input_args = {"x": torch.tensor([torch.nan, -torch.inf, -2., 2., torch.inf])}
|
|
120
|
+
>>> _dyn_eval(abs(x), input_args, "x")
|
|
121
|
+
tensor([nan, inf, 2., 2., inf])
|
|
122
|
+
>>> _ is input_args["x"]
|
|
123
|
+
True
|
|
124
|
+
>>> input_args = {"x": torch.tensor([3+4j, -3+4j, 3-4j, -3-4j])}
|
|
125
|
+
>>> _dyn_eval(abs(x), input_args, "x")
|
|
126
|
+
tensor([5.+0.j, 5.+0.j, 5.+0.j, 5.+0.j])
|
|
127
|
+
>>> _ is input_args["x"]
|
|
128
|
+
True
|
|
129
|
+
>>>
|
|
130
|
+
"""
|
|
131
|
+
input_val = _dyn_eval(expr.args[0], input_args)
|
|
132
|
+
try:
|
|
133
|
+
abs_value = torch.abs(input_val, out=input_args.get(new_var, None))
|
|
134
|
+
except RuntimeError:
|
|
135
|
+
abs_value = torch.abs(input_val)
|
|
136
|
+
abs_value = abs_value.to(input_val.dtype)
|
|
137
|
+
if new_var is not None:
|
|
138
|
+
input_args[new_var] = abs_value
|
|
139
|
+
return abs_value
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def _acos(
|
|
143
|
+
expr: Basic, input_args: dict[str, torch.Tensor], new_var: typing.Optional[str] = None,
|
|
144
|
+
) -> typing.Union[torch.Tensor, numbers.Real]:
|
|
145
|
+
input_val = _dyn_eval(expr.args[0], input_args)
|
|
146
|
+
out = None
|
|
147
|
+
if new_var is not None:
|
|
148
|
+
if (out := input_args.get(new_var, None)) is not None:
|
|
149
|
+
if out.shape != input_val.shape or out.dtype != input_val.dtype:
|
|
150
|
+
out = None
|
|
151
|
+
acos_value = torch.acos(input_val, out=out)
|
|
152
|
+
if new_var is not None:
|
|
153
|
+
input_args[new_var] = acos_value
|
|
154
|
+
return acos_value
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def _acosh(
|
|
158
|
+
expr: Basic, input_args: dict[str, torch.Tensor], new_var: typing.Optional[str] = None,
|
|
159
|
+
) -> typing.Union[torch.Tensor, numbers.Real]:
|
|
160
|
+
input_val = _dyn_eval(expr.args[0], input_args)
|
|
161
|
+
out = None
|
|
162
|
+
if new_var is not None:
|
|
163
|
+
if (out := input_args.get(new_var, None)) is not None:
|
|
164
|
+
if out.shape != input_val.shape or out.dtype != input_val.dtype:
|
|
165
|
+
out = None
|
|
166
|
+
acosh_value = torch.acosh(input_val, out=out)
|
|
167
|
+
if new_var is not None:
|
|
168
|
+
input_args[new_var] = acosh_value
|
|
169
|
+
return acosh_value
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
def _add(
|
|
173
|
+
expr: Basic, input_args: dict[str, torch.Tensor], new_var: typing.Optional[str] = None,
|
|
174
|
+
) -> typing.Union[torch.Tensor, numbers.Real]:
|
|
175
|
+
"""Dynamic + operation.
|
|
176
|
+
|
|
177
|
+
Examples
|
|
178
|
+
--------
|
|
179
|
+
>>> from sympy.abc import x, y
|
|
180
|
+
>>> import torch
|
|
181
|
+
>>> from cutcutcodec.core.compilation.sympy_to_torch.dynamic import _dyn_eval
|
|
182
|
+
>>> input_args = {"x": torch.tensor([[0.0], [1.0]]), "y": torch.tensor([[2.0, 4.0]])}
|
|
183
|
+
>>> _dyn_eval(1 + x + y, input_args, "z")
|
|
184
|
+
tensor([[3., 5.],
|
|
185
|
+
[4., 6.]])
|
|
186
|
+
>>> _ is input_args["z"]
|
|
187
|
+
True
|
|
188
|
+
>>>
|
|
189
|
+
"""
|
|
190
|
+
args = [_dyn_eval(a, input_args) for a in expr.args]
|
|
191
|
+
args.sort(key=(lambda x: torch.numel(x) if isinstance(x, torch.Tensor) else 1))
|
|
192
|
+
sum_value = sum(args, start=args.pop(0))
|
|
193
|
+
if new_var is not None:
|
|
194
|
+
input_args[new_var] = sum_value
|
|
195
|
+
return sum_value
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
def _asin(
|
|
199
|
+
expr: Basic, input_args: dict[str, torch.Tensor], new_var: typing.Optional[str] = None,
|
|
200
|
+
) -> typing.Union[torch.Tensor, numbers.Real]:
|
|
201
|
+
input_val = _dyn_eval(expr.args[0], input_args)
|
|
202
|
+
out = None
|
|
203
|
+
if new_var is not None:
|
|
204
|
+
if (out := input_args.get(new_var, None)) is not None:
|
|
205
|
+
if out.shape != input_val.shape or out.dtype != input_val.dtype:
|
|
206
|
+
out = None
|
|
207
|
+
asin_value = torch.asin(input_val, out=out)
|
|
208
|
+
if new_var is not None:
|
|
209
|
+
input_args[new_var] = asin_value
|
|
210
|
+
return asin_value
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
def _atan(
|
|
214
|
+
expr: Basic, input_args: dict[str, torch.Tensor], new_var: typing.Optional[str] = None,
|
|
215
|
+
) -> typing.Union[torch.Tensor, numbers.Real]:
|
|
216
|
+
"""Dynamic atan operation.
|
|
217
|
+
|
|
218
|
+
Examples
|
|
219
|
+
--------
|
|
220
|
+
>>> from sympy.abc import x
|
|
221
|
+
>>> from sympy.functions.elementary.trigonometric import atan
|
|
222
|
+
>>> import torch
|
|
223
|
+
>>> from cutcutcodec.core.compilation.sympy_to_torch.dynamic import _dyn_eval
|
|
224
|
+
>>> input_args = {"x": torch.tensor([torch.nan])}
|
|
225
|
+
>>> _dyn_eval(atan(x), input_args, "x")
|
|
226
|
+
tensor([nan])
|
|
227
|
+
>>> _ is input_args["x"]
|
|
228
|
+
True
|
|
229
|
+
>>> input_args = {"x": torch.tensor([-torch.inf, -1.0, 0.0, 1.0, torch.inf])}
|
|
230
|
+
>>> _dyn_eval(atan(x), input_args, "x")
|
|
231
|
+
tensor([-1.5708, -0.7854, 0.0000, 0.7854, 1.5708])
|
|
232
|
+
>>> torch.div(_, torch.pi, out=_)
|
|
233
|
+
tensor([-0.5000, -0.2500, 0.0000, 0.2500, 0.5000])
|
|
234
|
+
>>> _ is input_args["x"]
|
|
235
|
+
True
|
|
236
|
+
>>>
|
|
237
|
+
"""
|
|
238
|
+
input_val = _dyn_eval(expr.args[0], input_args)
|
|
239
|
+
try:
|
|
240
|
+
cos_value = torch.atan(input_val, out=input_args.get(new_var, None))
|
|
241
|
+
except RuntimeError:
|
|
242
|
+
cos_value = torch.atan(input_val)
|
|
243
|
+
if new_var is not None:
|
|
244
|
+
input_args[new_var] = cos_value
|
|
245
|
+
return cos_value
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
def _cos(
|
|
249
|
+
expr: Basic, input_args: dict[str, torch.Tensor], new_var: typing.Optional[str] = None,
|
|
250
|
+
) -> typing.Union[torch.Tensor, numbers.Real]:
|
|
251
|
+
"""Dynamic cos operation.
|
|
252
|
+
|
|
253
|
+
Examples
|
|
254
|
+
--------
|
|
255
|
+
>>> from sympy.abc import x
|
|
256
|
+
>>> from sympy.functions.elementary.trigonometric import cos
|
|
257
|
+
>>> import torch
|
|
258
|
+
>>> from cutcutcodec.core.compilation.sympy_to_torch.dynamic import _dyn_eval
|
|
259
|
+
>>> input_args = {"x": torch.tensor([torch.nan])}
|
|
260
|
+
>>> _dyn_eval(cos(x), input_args, "x")
|
|
261
|
+
tensor([nan])
|
|
262
|
+
>>> _ is input_args["x"]
|
|
263
|
+
True
|
|
264
|
+
>>> input_args = {"x": torch.tensor([0., 0.78540, 2.35620, 3.14160, 3.92700, 5.49779, 6.28319])}
|
|
265
|
+
>>> _dyn_eval(cos(x), input_args, "x")
|
|
266
|
+
tensor([ 1.0000, 0.7071, -0.7071, -1.0000, -0.7071, 0.7071, 1.0000])
|
|
267
|
+
>>> _ is input_args["x"]
|
|
268
|
+
True
|
|
269
|
+
>>> input_args = {"x": torch.tensor([1+1j])}
|
|
270
|
+
>>> _dyn_eval(cos(x), input_args, "x")
|
|
271
|
+
tensor([0.8337-0.9889j])
|
|
272
|
+
>>>
|
|
273
|
+
"""
|
|
274
|
+
input_val = _dyn_eval(expr.args[0], input_args)
|
|
275
|
+
try:
|
|
276
|
+
cos_value = torch.cos(input_val, out=input_args.get(new_var, None))
|
|
277
|
+
except RuntimeError:
|
|
278
|
+
cos_value = torch.cos(input_val)
|
|
279
|
+
if new_var is not None:
|
|
280
|
+
input_args[new_var] = cos_value
|
|
281
|
+
return cos_value
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
def _cosh(
|
|
285
|
+
expr: Basic, input_args: dict[str, torch.Tensor], new_var: typing.Optional[str] = None,
|
|
286
|
+
) -> typing.Union[torch.Tensor, numbers.Real]:
|
|
287
|
+
input_val = _dyn_eval(expr.args[0], input_args)
|
|
288
|
+
out = None
|
|
289
|
+
if new_var is not None:
|
|
290
|
+
if (out := input_args.get(new_var, None)) is not None:
|
|
291
|
+
if out.shape != input_val.shape or out.dtype != input_val.dtype:
|
|
292
|
+
out = None
|
|
293
|
+
cosh_value = torch.cosh(input_val, out=out)
|
|
294
|
+
if new_var is not None:
|
|
295
|
+
input_args[new_var] = cosh_value
|
|
296
|
+
return cosh_value
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
def _exp(
|
|
300
|
+
expr: Basic, input_args: dict[str, torch.Tensor], new_var: typing.Optional[str] = None,
|
|
301
|
+
) -> typing.Union[torch.Tensor, numbers.Real]:
|
|
302
|
+
"""Dynamic exp operation.
|
|
303
|
+
|
|
304
|
+
Examples
|
|
305
|
+
--------
|
|
306
|
+
>>> from sympy.abc import x
|
|
307
|
+
>>> from sympy.functions.elementary.trigonometric import exp
|
|
308
|
+
>>> import torch
|
|
309
|
+
>>> from cutcutcodec.core.compilation.sympy_to_torch.dynamic import _dyn_eval
|
|
310
|
+
>>> input_args = {"x": torch.tensor([torch.nan])}
|
|
311
|
+
>>> _dyn_eval(exp(x), input_args, "x")
|
|
312
|
+
tensor([nan])
|
|
313
|
+
>>> _ is input_args["x"]
|
|
314
|
+
True
|
|
315
|
+
>>> input_args = {"x": torch.tensor([-torch.inf, -1.0, 0.0, 1.0, torch.inf])}
|
|
316
|
+
>>> _dyn_eval(exp(x), input_args, "x")
|
|
317
|
+
tensor([0.0000, 0.3679, 1.0000, 2.7183, inf])
|
|
318
|
+
>>> _ is input_args["x"]
|
|
319
|
+
True
|
|
320
|
+
>>> input_args = {"x": torch.tensor([1+1j])}
|
|
321
|
+
>>> _dyn_eval(exp(x), input_args, "x")
|
|
322
|
+
tensor([1.4687+2.2874j])
|
|
323
|
+
>>>
|
|
324
|
+
"""
|
|
325
|
+
input_val = _dyn_eval(expr.args[0], input_args)
|
|
326
|
+
try:
|
|
327
|
+
exp_value = torch.exp(input_val, out=input_args.get(new_var, None))
|
|
328
|
+
except RuntimeError:
|
|
329
|
+
exp_value = torch.exp(input_val)
|
|
330
|
+
if new_var is not None:
|
|
331
|
+
input_args[new_var] = exp_value
|
|
332
|
+
return exp_value
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
def _im(
|
|
336
|
+
expr: Basic, input_args: dict[str, torch.Tensor], new_var: typing.Optional[str] = None,
|
|
337
|
+
) -> typing.Union[torch.Tensor, numbers.Real]:
|
|
338
|
+
im_value = _dyn_eval(expr.args[0], input_args).imag
|
|
339
|
+
if str(expr.args[0]) != new_var:
|
|
340
|
+
im_value = im_value.clone()
|
|
341
|
+
if new_var is not None:
|
|
342
|
+
input_args[new_var] = im_value
|
|
343
|
+
return im_value
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
def _log(
|
|
347
|
+
expr: Basic, input_args: dict[str, torch.Tensor], new_var: typing.Optional[str] = None,
|
|
348
|
+
) -> typing.Union[torch.Tensor, numbers.Real]:
|
|
349
|
+
input_val = _dyn_eval(expr.args[0], input_args)
|
|
350
|
+
out = None
|
|
351
|
+
if new_var is not None:
|
|
352
|
+
if (out := input_args.get(new_var, None)) is not None:
|
|
353
|
+
if out.shape != input_val.shape or out.dtype != input_val.dtype:
|
|
354
|
+
out = None
|
|
355
|
+
log_value = torch.log(input_val, out=out)
|
|
356
|
+
if new_var is not None:
|
|
357
|
+
input_args[new_var] = log_value
|
|
358
|
+
return log_value
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
def _mul(
|
|
362
|
+
expr: Basic, input_args: dict[str, torch.Tensor], new_var: typing.Optional[str] = None,
|
|
363
|
+
) -> typing.Union[torch.Tensor, numbers.Real]:
|
|
364
|
+
"""Dynamic * operation.
|
|
365
|
+
|
|
366
|
+
Examples
|
|
367
|
+
--------
|
|
368
|
+
>>> from sympy.abc import x, y
|
|
369
|
+
>>> import torch
|
|
370
|
+
>>> from cutcutcodec.core.compilation.sympy_to_torch.dynamic import _dyn_eval
|
|
371
|
+
>>> input_args = {"x": torch.tensor([[0.0], [1.0]]), "y": torch.tensor([[2.0, 4.0]])}
|
|
372
|
+
>>> _dyn_eval(2 * x * y, input_args, "z")
|
|
373
|
+
tensor([[0., 0.],
|
|
374
|
+
[4., 8.]])
|
|
375
|
+
>>> _ is input_args["z"]
|
|
376
|
+
True
|
|
377
|
+
>>>
|
|
378
|
+
"""
|
|
379
|
+
args = [_dyn_eval(a, input_args) for a in expr.args]
|
|
380
|
+
args.sort(key=(lambda x: torch.numel(x) if isinstance(x, torch.Tensor) else 1))
|
|
381
|
+
mul_value = args.pop(0)
|
|
382
|
+
for item in args:
|
|
383
|
+
mul_value = mul_value * item
|
|
384
|
+
if new_var is not None:
|
|
385
|
+
input_args[new_var] = mul_value
|
|
386
|
+
return mul_value
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
def _pow(
|
|
390
|
+
expr: Basic, input_args: dict[str, torch.Tensor], new_var: typing.Optional[str] = None,
|
|
391
|
+
) -> typing.Union[torch.Tensor, numbers.Real]:
|
|
392
|
+
"""Dynamic ** operation.
|
|
393
|
+
|
|
394
|
+
Examples
|
|
395
|
+
--------
|
|
396
|
+
>>> from sympy.abc import x, y
|
|
397
|
+
>>> import torch
|
|
398
|
+
>>> from cutcutcodec.core.compilation.sympy_to_torch.dynamic import _dyn_eval
|
|
399
|
+
>>> input_args = {"x": torch.tensor([[2.0], [4.0]]), "y": torch.tensor([[0.5, 2.0]])}
|
|
400
|
+
>>> _dyn_eval(x**y, input_args, "z")
|
|
401
|
+
tensor([[ 1.4142, 4.0000],
|
|
402
|
+
[ 2.0000, 16.0000]])
|
|
403
|
+
>>> _ is input_args["z"]
|
|
404
|
+
True
|
|
405
|
+
>>> _dyn_eval(x**.5, input_args, "x") # sqrt
|
|
406
|
+
tensor([[1.4142],
|
|
407
|
+
[2.0000]])
|
|
408
|
+
>>> _dyn_eval(x**-1, input_args, "x") # 1/x
|
|
409
|
+
tensor([[0.7071],
|
|
410
|
+
[0.5000]])
|
|
411
|
+
>>>
|
|
412
|
+
"""
|
|
413
|
+
base, exp = _dyn_eval(expr.base, input_args), _dyn_eval(expr.exp, input_args)
|
|
414
|
+
out = None if new_var is None else input_args.get(new_var, None)
|
|
415
|
+
pow_value = None
|
|
416
|
+
if isinstance(exp, numbers.Real):
|
|
417
|
+
if exp == -1:
|
|
418
|
+
pow_value = torch.div(1, base, out=out)
|
|
419
|
+
elif exp == .5:
|
|
420
|
+
pow_value = torch.sqrt(base, out=out)
|
|
421
|
+
if pow_value is None:
|
|
422
|
+
pow_value = torch.pow(base, exp, out=out)
|
|
423
|
+
if new_var is not None:
|
|
424
|
+
input_args[new_var] = pow_value
|
|
425
|
+
return pow_value
|
|
426
|
+
|
|
427
|
+
|
|
428
|
+
def _re(
|
|
429
|
+
expr: Basic, input_args: dict[str, torch.Tensor], new_var: typing.Optional[str] = None,
|
|
430
|
+
) -> typing.Union[torch.Tensor, numbers.Real]:
|
|
431
|
+
re_value = _dyn_eval(expr.args[0], input_args).real
|
|
432
|
+
if str(expr.args[0]) != new_var:
|
|
433
|
+
re_value = re_value.clone()
|
|
434
|
+
if new_var is not None:
|
|
435
|
+
input_args[new_var] = re_value
|
|
436
|
+
return re_value
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
def _sign(
|
|
440
|
+
expr: Basic, input_args: dict[str, torch.Tensor], new_var: typing.Optional[str] = None,
|
|
441
|
+
) -> typing.Union[torch.Tensor, numbers.Real]:
|
|
442
|
+
arg = _dyn_eval(expr.args[0], input_args)
|
|
443
|
+
out = None
|
|
444
|
+
if new_var is not None:
|
|
445
|
+
if (out := input_args.get(new_var, None)) is not None:
|
|
446
|
+
if out.shape != arg.shape or out.dtype != arg.dtype:
|
|
447
|
+
out = None
|
|
448
|
+
if arg.dtype.is_floating_point:
|
|
449
|
+
sign_value = torch.sign(arg, out=out)
|
|
450
|
+
else:
|
|
451
|
+
sign_value = torch.where(arg == 0, torch.zeros_like(arg), arg/abs(arg), out=out)
|
|
452
|
+
if new_var is not None:
|
|
453
|
+
input_args[new_var] = sign_value
|
|
454
|
+
return sign_value
|
|
455
|
+
|
|
456
|
+
|
|
457
|
+
def _sin(
|
|
458
|
+
expr: Basic, input_args: dict[str, torch.Tensor], new_var: typing.Optional[str] = None,
|
|
459
|
+
) -> typing.Union[torch.Tensor, numbers.Real]:
|
|
460
|
+
"""Dynamic sin operation.
|
|
461
|
+
|
|
462
|
+
Examples
|
|
463
|
+
--------
|
|
464
|
+
>>> from sympy.abc import x
|
|
465
|
+
>>> from sympy.functions.elementary.trigonometric import sin
|
|
466
|
+
>>> import torch
|
|
467
|
+
>>> from cutcutcodec.core.compilation.sympy_to_torch.dynamic import _dyn_eval
|
|
468
|
+
>>> input_args = {"x": torch.tensor([torch.nan])}
|
|
469
|
+
>>> _dyn_eval(sin(x), input_args, "x")
|
|
470
|
+
tensor([nan])
|
|
471
|
+
>>> _ is input_args["x"]
|
|
472
|
+
True
|
|
473
|
+
>>> input_args = {"x": torch.tensor([0.78540, 1.57080, 2.35619, 3.92699, 4.71239, 5.49779])}
|
|
474
|
+
>>> _dyn_eval(abs(x), input_args, "x")
|
|
475
|
+
tensor([0.7854, 1.5708, 2.3562, 3.9270, 4.7124, 5.4978])
|
|
476
|
+
>>> _ is input_args["x"]
|
|
477
|
+
True
|
|
478
|
+
>>> input_args = {"x": torch.tensor([1+1j])}
|
|
479
|
+
>>> _dyn_eval(sin(x), input_args, "x")
|
|
480
|
+
tensor([1.2985+0.6350j])
|
|
481
|
+
>>>
|
|
482
|
+
"""
|
|
483
|
+
input_val = _dyn_eval(expr.args[0], input_args)
|
|
484
|
+
try:
|
|
485
|
+
sin_value = torch.sin(input_val, out=input_args.get(new_var, None))
|
|
486
|
+
except RuntimeError:
|
|
487
|
+
sin_value = torch.sin(input_val)
|
|
488
|
+
if new_var is not None:
|
|
489
|
+
input_args[new_var] = sin_value
|
|
490
|
+
return sin_value
|
|
491
|
+
|
|
492
|
+
|
|
493
|
+
def _sinh(
|
|
494
|
+
expr: Basic, input_args: dict[str, torch.Tensor], new_var: typing.Optional[str] = None,
|
|
495
|
+
) -> typing.Union[torch.Tensor, numbers.Real]:
|
|
496
|
+
input_val = _dyn_eval(expr.args[0], input_args)
|
|
497
|
+
out = None
|
|
498
|
+
if new_var is not None:
|
|
499
|
+
if (out := input_args.get(new_var, None)) is not None:
|
|
500
|
+
if out.shape != input_val.shape or out.dtype != input_val.dtype:
|
|
501
|
+
out = None
|
|
502
|
+
sinh_value = torch.sinh(input_val, out=out)
|
|
503
|
+
if new_var is not None:
|
|
504
|
+
input_args[new_var] = sinh_value
|
|
505
|
+
return sinh_value
|
|
506
|
+
|
|
507
|
+
|
|
508
|
+
def _tan(
|
|
509
|
+
expr: Basic, input_args: dict[str, torch.Tensor], new_var: typing.Optional[str] = None,
|
|
510
|
+
) -> typing.Union[torch.Tensor, numbers.Real]:
|
|
511
|
+
input_val = _dyn_eval(expr.args[0], input_args)
|
|
512
|
+
out = None
|
|
513
|
+
if new_var is not None:
|
|
514
|
+
if (out := input_args.get(new_var, None)) is not None:
|
|
515
|
+
if out.shape != input_val.shape or out.dtype != input_val.dtype:
|
|
516
|
+
out = None
|
|
517
|
+
tan_value = torch.tan(input_val, out=out)
|
|
518
|
+
if new_var is not None:
|
|
519
|
+
input_args[new_var] = tan_value
|
|
520
|
+
return tan_value
|
|
521
|
+
|
|
522
|
+
|
|
523
|
+
def _tanh(
|
|
524
|
+
expr: Basic, input_args: dict[str, torch.Tensor], new_var: typing.Optional[str] = None,
|
|
525
|
+
) -> typing.Union[torch.Tensor, numbers.Real]:
|
|
526
|
+
input_val = _dyn_eval(expr.args[0], input_args)
|
|
527
|
+
out = None
|
|
528
|
+
if new_var is not None:
|
|
529
|
+
if (out := input_args.get(new_var, None)) is not None:
|
|
530
|
+
if out.shape != input_val.shape or out.dtype != input_val.dtype:
|
|
531
|
+
out = None
|
|
532
|
+
tanh_value = torch.tanh(input_val, out=out)
|
|
533
|
+
if new_var is not None:
|
|
534
|
+
input_args[new_var] = tanh_value
|
|
535
|
+
return tanh_value
|
|
536
|
+
|
|
537
|
+
|
|
538
|
+
def _tuple(
|
|
539
|
+
expr: Basic, input_args: dict[str, torch.Tensor], new_var: typing.Optional[str] = None,
|
|
540
|
+
) -> typing.Union[torch.Tensor, numbers.Real]:
|
|
541
|
+
if new_var is None:
|
|
542
|
+
return tuple(_dyn_eval(a, input_args) for a in expr)
|
|
543
|
+
input_args[new_var] = _tuple(expr, input_args)
|
|
544
|
+
return input_args[new_var]
|