pytensor 3.4.0__cp315-cp315t-win_amd64.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.
- pytensor/__init__.py +61 -0
- pytensor/_sparse_lazy.py +31 -0
- pytensor/_version.py +21 -0
- pytensor/assumptions/__init__.py +108 -0
- pytensor/assumptions/alloc.py +181 -0
- pytensor/assumptions/blockwise.py +13 -0
- pytensor/assumptions/bundles.py +55 -0
- pytensor/assumptions/core.py +684 -0
- pytensor/assumptions/diagonal.py +153 -0
- pytensor/assumptions/dimshuffle.py +54 -0
- pytensor/assumptions/dot.py +58 -0
- pytensor/assumptions/elemwise.py +84 -0
- pytensor/assumptions/orthogonal.py +85 -0
- pytensor/assumptions/permutation.py +80 -0
- pytensor/assumptions/positive_definite.py +153 -0
- pytensor/assumptions/reshape.py +28 -0
- pytensor/assumptions/selection.py +131 -0
- pytensor/assumptions/shape.py +30 -0
- pytensor/assumptions/specify.py +189 -0
- pytensor/assumptions/subtensor.py +88 -0
- pytensor/assumptions/symmetric.py +129 -0
- pytensor/assumptions/triangular.py +203 -0
- pytensor/assumptions/tridiagonal.py +108 -0
- pytensor/assumptions/unit_magnitude.py +41 -0
- pytensor/basic.py +46 -0
- pytensor/bin/__init__.py +0 -0
- pytensor/bin/pytensor_cache.py +112 -0
- pytensor/breakpoint.py +161 -0
- pytensor/compile/__init__.py +65 -0
- pytensor/compile/aliasing.py +260 -0
- pytensor/compile/builders.py +980 -0
- pytensor/compile/compiledir.py +272 -0
- pytensor/compile/compilelock.py +87 -0
- pytensor/compile/debug/__init__.py +0 -0
- pytensor/compile/debug/debugmode.py +2310 -0
- pytensor/compile/debug/dump.py +75 -0
- pytensor/compile/debug/monitormode.py +111 -0
- pytensor/compile/debug/nanguardmode.py +260 -0
- pytensor/compile/debug/profiling.py +1573 -0
- pytensor/compile/executor.py +879 -0
- pytensor/compile/inner_function.py +74 -0
- pytensor/compile/io.py +255 -0
- pytensor/compile/maker.py +722 -0
- pytensor/compile/mode.py +633 -0
- pytensor/compile/ops.py +315 -0
- pytensor/compile/rebuild.py +548 -0
- pytensor/compile/rewriting.py +221 -0
- pytensor/compile/sharedvalue.py +229 -0
- pytensor/conditional/__init__.py +7 -0
- pytensor/conditional/op.py +455 -0
- pytensor/conditional/rewriting.py +651 -0
- pytensor/configdefaults.py +1143 -0
- pytensor/configparser.py +584 -0
- pytensor/d3viz/__init__.py +1 -0
- pytensor/d3viz/css/d3-context-menu.css +29 -0
- pytensor/d3viz/css/d3viz.css +98 -0
- pytensor/d3viz/d3viz.py +130 -0
- pytensor/d3viz/formatting.py +369 -0
- pytensor/d3viz/html/template.html +101 -0
- pytensor/d3viz/js/d3-context-menu.js +42 -0
- pytensor/d3viz/js/d3.v3.min.js +5 -0
- pytensor/d3viz/js/d3viz.js +969 -0
- pytensor/d3viz/js/dagre-d3.min.js +2 -0
- pytensor/d3viz/js/graphlib-dot.min.js +4 -0
- pytensor/gradient.py +2508 -0
- pytensor/graph/__init__.py +19 -0
- pytensor/graph/basic.py +1324 -0
- pytensor/graph/destroyhandler.py +788 -0
- pytensor/graph/features.py +959 -0
- pytensor/graph/fg.py +1253 -0
- pytensor/graph/null_type.py +42 -0
- pytensor/graph/op.py +780 -0
- pytensor/graph/replace.py +345 -0
- pytensor/graph/rewriting/__init__.py +4 -0
- pytensor/graph/rewriting/basic.py +3139 -0
- pytensor/graph/rewriting/db.py +547 -0
- pytensor/graph/rewriting/kanren.py +329 -0
- pytensor/graph/rewriting/reachability.py +135 -0
- pytensor/graph/rewriting/unify.py +594 -0
- pytensor/graph/rewriting/utils.py +116 -0
- pytensor/graph/traversal.py +783 -0
- pytensor/graph/type.py +242 -0
- pytensor/graph/utils.py +350 -0
- pytensor/ifelse.py +37 -0
- pytensor/ipython.py +215 -0
- pytensor/link/__init__.py +1 -0
- pytensor/link/basic.py +745 -0
- pytensor/link/c/__init__.py +0 -0
- pytensor/link/c/basic.py +2012 -0
- pytensor/link/c/c_code/lazylinker_c.c +1027 -0
- pytensor/link/c/c_code/pytensor_mod_helper.h +25 -0
- pytensor/link/c/cmodule.py +2937 -0
- pytensor/link/c/cutils.py +116 -0
- pytensor/link/c/cvm.py +29 -0
- pytensor/link/c/exceptions.py +12 -0
- pytensor/link/c/interface.py +632 -0
- pytensor/link/c/lazylinker_c.py +147 -0
- pytensor/link/c/op.py +646 -0
- pytensor/link/c/params_type.py +885 -0
- pytensor/link/c/type.py +787 -0
- pytensor/link/jax/__init__.py +1 -0
- pytensor/link/jax/dispatch/__init__.py +23 -0
- pytensor/link/jax/dispatch/basic.py +159 -0
- pytensor/link/jax/dispatch/blas.py +14 -0
- pytensor/link/jax/dispatch/blockwise.py +63 -0
- pytensor/link/jax/dispatch/einsum.py +20 -0
- pytensor/link/jax/dispatch/elemwise.py +107 -0
- pytensor/link/jax/dispatch/extra_ops.py +143 -0
- pytensor/link/jax/dispatch/linalg/__init__.py +8 -0
- pytensor/link/jax/dispatch/linalg/constructors.py +12 -0
- pytensor/link/jax/dispatch/linalg/decomposition.py +140 -0
- pytensor/link/jax/dispatch/linalg/inverse.py +20 -0
- pytensor/link/jax/dispatch/linalg/products.py +43 -0
- pytensor/link/jax/dispatch/linalg/solvers.py +103 -0
- pytensor/link/jax/dispatch/linalg/summary.py +20 -0
- pytensor/link/jax/dispatch/math.py +73 -0
- pytensor/link/jax/dispatch/pad.py +53 -0
- pytensor/link/jax/dispatch/random.py +454 -0
- pytensor/link/jax/dispatch/scalar.py +357 -0
- pytensor/link/jax/dispatch/scan.py +247 -0
- pytensor/link/jax/dispatch/shape.py +106 -0
- pytensor/link/jax/dispatch/signal/__init__.py +1 -0
- pytensor/link/jax/dispatch/signal/conv.py +24 -0
- pytensor/link/jax/dispatch/sort.py +26 -0
- pytensor/link/jax/dispatch/sparse.py +38 -0
- pytensor/link/jax/dispatch/subtensor.py +73 -0
- pytensor/link/jax/dispatch/tensor_basic.py +195 -0
- pytensor/link/jax/linker.py +142 -0
- pytensor/link/jax/ops.py +568 -0
- pytensor/link/mlx/__init__.py +1 -0
- pytensor/link/mlx/dispatch/__init__.py +21 -0
- pytensor/link/mlx/dispatch/basic.py +244 -0
- pytensor/link/mlx/dispatch/blas.py +42 -0
- pytensor/link/mlx/dispatch/blockwise.py +88 -0
- pytensor/link/mlx/dispatch/einsum.py +14 -0
- pytensor/link/mlx/dispatch/elemwise.py +133 -0
- pytensor/link/mlx/dispatch/extra_ops.py +35 -0
- pytensor/link/mlx/dispatch/linalg/__init__.py +7 -0
- pytensor/link/mlx/dispatch/linalg/decomposition.py +183 -0
- pytensor/link/mlx/dispatch/linalg/inverse.py +26 -0
- pytensor/link/mlx/dispatch/linalg/products.py +22 -0
- pytensor/link/mlx/dispatch/linalg/solvers.py +95 -0
- pytensor/link/mlx/dispatch/linalg/summary.py +40 -0
- pytensor/link/mlx/dispatch/math.py +82 -0
- pytensor/link/mlx/dispatch/pad.py +55 -0
- pytensor/link/mlx/dispatch/random.py +276 -0
- pytensor/link/mlx/dispatch/scalar/__init__.py +10 -0
- pytensor/link/mlx/dispatch/scalar/basic.py +127 -0
- pytensor/link/mlx/dispatch/scalar/bessel.py +508 -0
- pytensor/link/mlx/dispatch/scalar/beta.py +1131 -0
- pytensor/link/mlx/dispatch/scalar/erf.py +316 -0
- pytensor/link/mlx/dispatch/scalar/erfcinv.py +152 -0
- pytensor/link/mlx/dispatch/scalar/gamma.py +58 -0
- pytensor/link/mlx/dispatch/scalar/gammainc.py +552 -0
- pytensor/link/mlx/dispatch/scalar/helpers.py +214 -0
- pytensor/link/mlx/dispatch/scalar/math.py +271 -0
- pytensor/link/mlx/dispatch/shape.py +56 -0
- pytensor/link/mlx/dispatch/signal/__init__.py +0 -0
- pytensor/link/mlx/dispatch/signal/conv.py +33 -0
- pytensor/link/mlx/dispatch/sort.py +38 -0
- pytensor/link/mlx/dispatch/subtensor.py +118 -0
- pytensor/link/mlx/dispatch/tensor_basic.py +256 -0
- pytensor/link/mlx/linker.py +143 -0
- pytensor/link/numba/__init__.py +1 -0
- pytensor/link/numba/cache.py +207 -0
- pytensor/link/numba/dispatch/__init__.py +29 -0
- pytensor/link/numba/dispatch/_gamma_tables.py +821 -0
- pytensor/link/numba/dispatch/_llvmlite_self_ref.py +66 -0
- pytensor/link/numba/dispatch/_patch_list_to_tuple.py +330 -0
- pytensor/link/numba/dispatch/_patch_pointer_add.py +40 -0
- pytensor/link/numba/dispatch/array_utils.py +26 -0
- pytensor/link/numba/dispatch/basic.py +583 -0
- pytensor/link/numba/dispatch/blockwise.py +125 -0
- pytensor/link/numba/dispatch/compile_ops.py +178 -0
- pytensor/link/numba/dispatch/cython_support.py +197 -0
- pytensor/link/numba/dispatch/elemwise.py +1598 -0
- pytensor/link/numba/dispatch/extra_ops.py +351 -0
- pytensor/link/numba/dispatch/linalg/_BLAS.py +195 -0
- pytensor/link/numba/dispatch/linalg/_LAPACK.py +2003 -0
- pytensor/link/numba/dispatch/linalg/__init__.py +6 -0
- pytensor/link/numba/dispatch/linalg/constructors.py +90 -0
- pytensor/link/numba/dispatch/linalg/decomposition/__init__.py +0 -0
- pytensor/link/numba/dispatch/linalg/decomposition/cholesky.py +81 -0
- pytensor/link/numba/dispatch/linalg/decomposition/dispatch.py +671 -0
- pytensor/link/numba/dispatch/linalg/decomposition/eigen.py +1029 -0
- pytensor/link/numba/dispatch/linalg/decomposition/lu.py +192 -0
- pytensor/link/numba/dispatch/linalg/decomposition/lu_factor.py +90 -0
- pytensor/link/numba/dispatch/linalg/decomposition/qr.py +722 -0
- pytensor/link/numba/dispatch/linalg/decomposition/qz.py +1285 -0
- pytensor/link/numba/dispatch/linalg/decomposition/schur.py +225 -0
- pytensor/link/numba/dispatch/linalg/decomposition/svd.py +709 -0
- pytensor/link/numba/dispatch/linalg/inverse.py +40 -0
- pytensor/link/numba/dispatch/linalg/products.py +881 -0
- pytensor/link/numba/dispatch/linalg/solvers/__init__.py +0 -0
- pytensor/link/numba/dispatch/linalg/solvers/cholesky.py +85 -0
- pytensor/link/numba/dispatch/linalg/solvers/dispatch.py +189 -0
- pytensor/link/numba/dispatch/linalg/solvers/general.py +85 -0
- pytensor/link/numba/dispatch/linalg/solvers/hermitian.py +136 -0
- pytensor/link/numba/dispatch/linalg/solvers/linear_control.py +98 -0
- pytensor/link/numba/dispatch/linalg/solvers/lu_solve.py +134 -0
- pytensor/link/numba/dispatch/linalg/solvers/posdef.py +110 -0
- pytensor/link/numba/dispatch/linalg/solvers/symmetric.py +134 -0
- pytensor/link/numba/dispatch/linalg/solvers/triangular.py +132 -0
- pytensor/link/numba/dispatch/linalg/solvers/tridiagonal.py +368 -0
- pytensor/link/numba/dispatch/linalg/solvers/utils.py +11 -0
- pytensor/link/numba/dispatch/linalg/summary.py +46 -0
- pytensor/link/numba/dispatch/linalg/utils.py +133 -0
- pytensor/link/numba/dispatch/optimize/__init__.py +2 -0
- pytensor/link/numba/dispatch/optimize/scalar_minimize.py +489 -0
- pytensor/link/numba/dispatch/optimize/scalar_root.py +652 -0
- pytensor/link/numba/dispatch/optimize/utils.py +48 -0
- pytensor/link/numba/dispatch/random.py +518 -0
- pytensor/link/numba/dispatch/scalar.py +655 -0
- pytensor/link/numba/dispatch/scan.py +457 -0
- pytensor/link/numba/dispatch/shape.py +78 -0
- pytensor/link/numba/dispatch/signal/__init__.py +1 -0
- pytensor/link/numba/dispatch/signal/conv.py +125 -0
- pytensor/link/numba/dispatch/sort.py +65 -0
- pytensor/link/numba/dispatch/sparse/__init__.py +1 -0
- pytensor/link/numba/dispatch/sparse/basic.py +914 -0
- pytensor/link/numba/dispatch/sparse/math.py +1367 -0
- pytensor/link/numba/dispatch/sparse/variable.py +651 -0
- pytensor/link/numba/dispatch/string_codegen.py +31 -0
- pytensor/link/numba/dispatch/subtensor.py +887 -0
- pytensor/link/numba/dispatch/tensor_basic.py +501 -0
- pytensor/link/numba/dispatch/typed_list.py +251 -0
- pytensor/link/numba/dispatch/vectorize_codegen.py +1519 -0
- pytensor/link/numba/linker.py +32 -0
- pytensor/link/pytorch/dispatch/__init__.py +15 -0
- pytensor/link/pytorch/dispatch/basic.py +226 -0
- pytensor/link/pytorch/dispatch/blas.py +14 -0
- pytensor/link/pytorch/dispatch/blockwise.py +32 -0
- pytensor/link/pytorch/dispatch/elemwise.py +231 -0
- pytensor/link/pytorch/dispatch/extra_ops.py +53 -0
- pytensor/link/pytorch/dispatch/linalg/__init__.py +6 -0
- pytensor/link/pytorch/dispatch/linalg/decomposition.py +77 -0
- pytensor/link/pytorch/dispatch/linalg/inverse.py +22 -0
- pytensor/link/pytorch/dispatch/linalg/products.py +12 -0
- pytensor/link/pytorch/dispatch/linalg/summary.py +20 -0
- pytensor/link/pytorch/dispatch/math.py +14 -0
- pytensor/link/pytorch/dispatch/scalar.py +115 -0
- pytensor/link/pytorch/dispatch/shape.py +58 -0
- pytensor/link/pytorch/dispatch/sort.py +27 -0
- pytensor/link/pytorch/dispatch/subtensor.py +134 -0
- pytensor/link/pytorch/linker.py +104 -0
- pytensor/link/utils.py +949 -0
- pytensor/link/vm.py +1335 -0
- pytensor/misc/__init__.py +0 -0
- pytensor/misc/check_blas.py +300 -0
- pytensor/misc/check_blas_many.sh +21 -0
- pytensor/misc/check_duplicate_key.py +71 -0
- pytensor/misc/elemwise_openmp_speedup.py +77 -0
- pytensor/misc/elemwise_time_test.py +76 -0
- pytensor/misc/frozendict.py +44 -0
- pytensor/misc/may_share_memory.py +38 -0
- pytensor/misc/ordered_set.py +44 -0
- pytensor/misc/pkl_utils.py +64 -0
- pytensor/npy_2_compat.py +22 -0
- pytensor/printing.py +2731 -0
- pytensor/py.typed +0 -0
- pytensor/raise_op.py +203 -0
- pytensor/scalar/__init__.py +2 -0
- pytensor/scalar/basic.py +4357 -0
- pytensor/scalar/c_code/Faddeeva.cc +2517 -0
- pytensor/scalar/c_code/Faddeeva.hh +62 -0
- pytensor/scalar/c_code/gamma.c +375 -0
- pytensor/scalar/c_code/incbet.c +313 -0
- pytensor/scalar/loop.py +328 -0
- pytensor/scalar/math.py +1913 -0
- pytensor/scalar/sharedvar.py +61 -0
- pytensor/scan/__init__.py +57 -0
- pytensor/scan/basic.py +1192 -0
- pytensor/scan/checkpoints.py +191 -0
- pytensor/scan/op.py +3633 -0
- pytensor/scan/rewriting/__init__.py +30 -0
- pytensor/scan/rewriting/constant_folding.py +63 -0
- pytensor/scan/rewriting/db.py +283 -0
- pytensor/scan/rewriting/inner_graph.py +319 -0
- pytensor/scan/rewriting/inplace.py +197 -0
- pytensor/scan/rewriting/io.py +306 -0
- pytensor/scan/rewriting/merge.py +562 -0
- pytensor/scan/rewriting/push_out.py +986 -0
- pytensor/scan/rewriting/trace.py +1080 -0
- pytensor/scan/rewriting/utils.py +151 -0
- pytensor/scan/scan_perform.c +40260 -0
- pytensor/scan/scan_perform.cp315t-win_amd64.pyd +0 -0
- pytensor/scan/scan_perform.pyx +603 -0
- pytensor/scan/scan_perform_ext.py +17 -0
- pytensor/scan/utils.py +909 -0
- pytensor/scan/views.py +260 -0
- pytensor/sparse/__init__.py +5 -0
- pytensor/sparse/basic.py +1919 -0
- pytensor/sparse/linalg.py +96 -0
- pytensor/sparse/math.py +2151 -0
- pytensor/sparse/rewriting.py +2057 -0
- pytensor/sparse/sharedvar.py +30 -0
- pytensor/sparse/type.py +253 -0
- pytensor/sparse/utils.py +20 -0
- pytensor/sparse/variable.py +481 -0
- pytensor/tensor/__init__.py +162 -0
- pytensor/tensor/basic.py +4514 -0
- pytensor/tensor/blas/__init__.py +145 -0
- pytensor/tensor/blas/_core.py +189 -0
- pytensor/tensor/blas/batched.py +278 -0
- pytensor/tensor/blas/blas_c.py +110 -0
- pytensor/tensor/blas/c_code/__init__.py +0 -0
- pytensor/tensor/blas/c_code/alt_blas_common.h +21 -0
- pytensor/tensor/blas/c_code/alt_blas_template.c +369 -0
- pytensor/tensor/blas/c_code/blas_headers.py +1210 -0
- pytensor/tensor/blas/c_code/codegen.py +888 -0
- pytensor/tensor/blas/gemm.py +362 -0
- pytensor/tensor/blas/gemv.py +117 -0
- pytensor/tensor/blockwise.py +635 -0
- pytensor/tensor/einsum.py +818 -0
- pytensor/tensor/elemwise.py +1839 -0
- pytensor/tensor/elemwise_cgen.py +761 -0
- pytensor/tensor/exceptions.py +16 -0
- pytensor/tensor/extra_ops.py +1975 -0
- pytensor/tensor/fft.py +222 -0
- pytensor/tensor/fourier.py +188 -0
- pytensor/tensor/functional.py +131 -0
- pytensor/tensor/interpolate.py +200 -0
- pytensor/tensor/linalg/__init__.py +134 -0
- pytensor/tensor/linalg/_lazy.py +12 -0
- pytensor/tensor/linalg/constructors.py +121 -0
- pytensor/tensor/linalg/decomposition/__init__.py +1 -0
- pytensor/tensor/linalg/decomposition/cholesky.py +198 -0
- pytensor/tensor/linalg/decomposition/eigen.py +516 -0
- pytensor/tensor/linalg/decomposition/lu.py +347 -0
- pytensor/tensor/linalg/decomposition/qr.py +383 -0
- pytensor/tensor/linalg/decomposition/schur.py +607 -0
- pytensor/tensor/linalg/decomposition/svd.py +244 -0
- pytensor/tensor/linalg/dtype_utils.py +42 -0
- pytensor/tensor/linalg/inverse.py +218 -0
- pytensor/tensor/linalg/products.py +302 -0
- pytensor/tensor/linalg/solvers/__init__.py +0 -0
- pytensor/tensor/linalg/solvers/core.py +126 -0
- pytensor/tensor/linalg/solvers/general.py +269 -0
- pytensor/tensor/linalg/solvers/linear_control.py +462 -0
- pytensor/tensor/linalg/solvers/lstsq.py +98 -0
- pytensor/tensor/linalg/solvers/psd.py +108 -0
- pytensor/tensor/linalg/solvers/triangular.py +142 -0
- pytensor/tensor/linalg/solvers/tridiagonal.py +227 -0
- pytensor/tensor/linalg/summary.py +344 -0
- pytensor/tensor/math.py +4397 -0
- pytensor/tensor/nlinalg.py +58 -0
- pytensor/tensor/optimize.py +1370 -0
- pytensor/tensor/pad.py +686 -0
- pytensor/tensor/random/__init__.py +7 -0
- pytensor/tensor/random/basic.py +2179 -0
- pytensor/tensor/random/op.py +543 -0
- pytensor/tensor/random/rewriting/__init__.py +11 -0
- pytensor/tensor/random/rewriting/basic.py +385 -0
- pytensor/tensor/random/rewriting/jax.py +196 -0
- pytensor/tensor/random/rewriting/numba.py +192 -0
- pytensor/tensor/random/type.py +175 -0
- pytensor/tensor/random/utils.py +352 -0
- pytensor/tensor/random/variable.py +252 -0
- pytensor/tensor/reshape.py +528 -0
- pytensor/tensor/rewriting/__init__.py +22 -0
- pytensor/tensor/rewriting/assumptions.py +65 -0
- pytensor/tensor/rewriting/basic.py +1630 -0
- pytensor/tensor/rewriting/blas.py +885 -0
- pytensor/tensor/rewriting/blas_c.py +52 -0
- pytensor/tensor/rewriting/blockwise.py +372 -0
- pytensor/tensor/rewriting/einsum.py +53 -0
- pytensor/tensor/rewriting/elemwise.py +1221 -0
- pytensor/tensor/rewriting/extra_ops.py +119 -0
- pytensor/tensor/rewriting/fused_elemwise.py +955 -0
- pytensor/tensor/rewriting/inplace.py +352 -0
- pytensor/tensor/rewriting/jax.py +201 -0
- pytensor/tensor/rewriting/linalg/__init__.py +12 -0
- pytensor/tensor/rewriting/linalg/decomposition.py +732 -0
- pytensor/tensor/rewriting/linalg/inverse.py +177 -0
- pytensor/tensor/rewriting/linalg/products.py +434 -0
- pytensor/tensor/rewriting/linalg/reassociate_matmul.py +685 -0
- pytensor/tensor/rewriting/linalg/solvers.py +892 -0
- pytensor/tensor/rewriting/linalg/summary.py +324 -0
- pytensor/tensor/rewriting/linalg/utils.py +181 -0
- pytensor/tensor/rewriting/math.py +4232 -0
- pytensor/tensor/rewriting/numba.py +120 -0
- pytensor/tensor/rewriting/ofg.py +82 -0
- pytensor/tensor/rewriting/optimize.py +105 -0
- pytensor/tensor/rewriting/reshape.py +72 -0
- pytensor/tensor/rewriting/scalarize.py +268 -0
- pytensor/tensor/rewriting/shape.py +1041 -0
- pytensor/tensor/rewriting/sort.py +98 -0
- pytensor/tensor/rewriting/special.py +184 -0
- pytensor/tensor/rewriting/subtensor.py +3199 -0
- pytensor/tensor/rewriting/subtensor_lift.py +1567 -0
- pytensor/tensor/rewriting/uncanonicalize.py +232 -0
- pytensor/tensor/shape.py +1007 -0
- pytensor/tensor/sharedvar.py +137 -0
- pytensor/tensor/signal/__init__.py +4 -0
- pytensor/tensor/signal/conv.py +348 -0
- pytensor/tensor/slinalg.py +65 -0
- pytensor/tensor/sort.py +213 -0
- pytensor/tensor/special.py +341 -0
- pytensor/tensor/subtensor.py +3058 -0
- pytensor/tensor/symbolic.py +45 -0
- pytensor/tensor/type.py +1416 -0
- pytensor/tensor/type_other.py +143 -0
- pytensor/tensor/utils.py +307 -0
- pytensor/tensor/var.py +11 -0
- pytensor/tensor/variable.py +1122 -0
- pytensor/tensor/xlogx.py +37 -0
- pytensor/typed_list/__init__.py +3 -0
- pytensor/typed_list/basic.py +663 -0
- pytensor/typed_list/rewriting.py +26 -0
- pytensor/typed_list/type.py +141 -0
- pytensor/utils.py +426 -0
- pytensor/xtensor/__init__.py +9 -0
- pytensor/xtensor/basic.py +153 -0
- pytensor/xtensor/indexing.py +265 -0
- pytensor/xtensor/linalg.py +102 -0
- pytensor/xtensor/math.py +653 -0
- pytensor/xtensor/random/__init__.py +2 -0
- pytensor/xtensor/random/basic.py +254 -0
- pytensor/xtensor/random/type.py +88 -0
- pytensor/xtensor/random/variable.py +204 -0
- pytensor/xtensor/reduction.py +136 -0
- pytensor/xtensor/rewriting/__init__.py +6 -0
- pytensor/xtensor/rewriting/basic.py +87 -0
- pytensor/xtensor/rewriting/indexing.py +213 -0
- pytensor/xtensor/rewriting/math.py +47 -0
- pytensor/xtensor/rewriting/reduction.py +72 -0
- pytensor/xtensor/rewriting/shape.py +197 -0
- pytensor/xtensor/rewriting/utils.py +71 -0
- pytensor/xtensor/rewriting/vectorization.py +114 -0
- pytensor/xtensor/shape.py +707 -0
- pytensor/xtensor/signal.py +74 -0
- pytensor/xtensor/type.py +1143 -0
- pytensor/xtensor/vectorization.py +686 -0
- pytensor-3.4.0.dist-info/METADATA +208 -0
- pytensor-3.4.0.dist-info/RECORD +439 -0
- pytensor-3.4.0.dist-info/WHEEL +5 -0
- pytensor-3.4.0.dist-info/entry_points.txt +2 -0
- pytensor-3.4.0.dist-info/licenses/LICENSE.txt +41 -0
- pytensor-3.4.0.dist-info/top_level.txt +1 -0
pytensor/__init__.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
__docformat__ = "restructuredtext en"
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
from pytensor import _version
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
__version__: str = _version.get_versions()["version"]
|
|
11
|
+
|
|
12
|
+
del _version
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
from pytensor.configdefaults import config
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
# isort: off
|
|
19
|
+
from pytensor import tensor
|
|
20
|
+
from pytensor.compile import (
|
|
21
|
+
In,
|
|
22
|
+
Mode,
|
|
23
|
+
Out,
|
|
24
|
+
shared,
|
|
25
|
+
wrap_py,
|
|
26
|
+
)
|
|
27
|
+
from pytensor.compile.maker import function
|
|
28
|
+
from pytensor.compile.mode import get_mode
|
|
29
|
+
from pytensor.gradient import Lop, Rop, grad, pullback, pushforward
|
|
30
|
+
from pytensor.printing import debugprint as dprint
|
|
31
|
+
|
|
32
|
+
# Preload the deprecated module before binding the helper with the same name.
|
|
33
|
+
import pytensor.ifelse
|
|
34
|
+
from pytensor.conditional import ifelse
|
|
35
|
+
from pytensor.scan.basic import scan
|
|
36
|
+
from pytensor.scan.views import map
|
|
37
|
+
from pytensor.compile.builders import OpFromGraph
|
|
38
|
+
import pytensor.compile.rewriting # register OpFromGraph rewrites in optdb
|
|
39
|
+
from pytensor.link.jax.ops import wrap_jax
|
|
40
|
+
from pytensor import _sparse_lazy
|
|
41
|
+
# isort: on
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def __getattr__(name):
|
|
45
|
+
if name == "sparse":
|
|
46
|
+
# During pytensor.sparse's own import, submodules may do
|
|
47
|
+
# `import pytensor.sparse.X as Y` which probes pytensor.sparse via
|
|
48
|
+
# getattr before the parent attribute has been set. Return the
|
|
49
|
+
# partially-loaded module from sys.modules to avoid re-entry.
|
|
50
|
+
if "pytensor.sparse" in sys.modules:
|
|
51
|
+
return sys.modules["pytensor.sparse"]
|
|
52
|
+
import pytensor.sparse as sparse
|
|
53
|
+
|
|
54
|
+
return sparse
|
|
55
|
+
raise AttributeError(f"module 'pytensor' has no attribute {name!r}")
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
# Some config variables are registered by submodules. Only after all those
|
|
59
|
+
# imports were executed, we can warn about remaining flags provided by the user
|
|
60
|
+
# through PYTENSOR_FLAGS.
|
|
61
|
+
config.warn_unused_flags()
|
pytensor/_sparse_lazy.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"""Lazy registration of scipy.sparse handlers on pytensor's dispatchers.
|
|
2
|
+
|
|
3
|
+
Imported by `pytensor/__init__.py` so `pytensor.sparse` doesn't have to be
|
|
4
|
+
loaded eagerly at startup. The fallbacks match `type(x).__module__` against
|
|
5
|
+
`scipy.sparse` as a string, so this module itself doesn't import scipy.sparse;
|
|
6
|
+
the real handlers (and their scipy.sparse dependency) are pulled in only when
|
|
7
|
+
an actual scipy.sparse value is passed to `as_symbolic` / `shared`.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from pytensor.basic import _as_symbolic
|
|
11
|
+
from pytensor.compile.sharedvalue import shared_constructor
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def _lazy_as_symbolic_sparse(x):
|
|
15
|
+
if type(x).__module__.startswith("scipy.sparse"):
|
|
16
|
+
from pytensor.sparse.basic import as_symbolic_sparse
|
|
17
|
+
|
|
18
|
+
return as_symbolic_sparse
|
|
19
|
+
return None
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def _lazy_shared_sparse(x):
|
|
23
|
+
if type(x).__module__.startswith("scipy.sparse"):
|
|
24
|
+
from pytensor.sparse.sharedvar import sparse_constructor
|
|
25
|
+
|
|
26
|
+
return sparse_constructor
|
|
27
|
+
return None
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
_as_symbolic.register_lazy(_lazy_as_symbolic_sparse) # type: ignore[attr-defined]
|
|
31
|
+
shared_constructor.register_lazy(_lazy_shared_sparse) # type: ignore[attr-defined]
|
pytensor/_version.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
|
|
2
|
+
# This file was generated by 'versioneer.py' (0.29) from
|
|
3
|
+
# revision-control system data, or from the parent directory name of an
|
|
4
|
+
# unpacked source archive. Distribution tarballs contain a pre-generated copy
|
|
5
|
+
# of this file.
|
|
6
|
+
|
|
7
|
+
import json
|
|
8
|
+
|
|
9
|
+
version_json = '''
|
|
10
|
+
{
|
|
11
|
+
"date": "2026-11-30T16:14:14+0100",
|
|
12
|
+
"dirty": false,
|
|
13
|
+
"error": null,
|
|
14
|
+
"full-revisionid": "967cd9e9d9a27e0e2d9fcc2b1d51a83ab8ffc68e",
|
|
15
|
+
"version": "3.4.0"
|
|
16
|
+
}
|
|
17
|
+
''' # END VERSION_JSON
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def get_versions():
|
|
21
|
+
return json.loads(version_json)
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# Import every rule module so its registrations land on the global registry that
|
|
2
|
+
# ``check_assumption`` consults. The property modules pull in the shared helper
|
|
3
|
+
# modules (alloc, dimshuffle, subtensor, dot, elemwise) transitively.
|
|
4
|
+
import pytensor.assumptions.alloc
|
|
5
|
+
import pytensor.assumptions.blockwise
|
|
6
|
+
import pytensor.assumptions.diagonal
|
|
7
|
+
import pytensor.assumptions.dimshuffle
|
|
8
|
+
import pytensor.assumptions.orthogonal
|
|
9
|
+
import pytensor.assumptions.permutation
|
|
10
|
+
import pytensor.assumptions.positive_definite
|
|
11
|
+
import pytensor.assumptions.reshape
|
|
12
|
+
import pytensor.assumptions.selection
|
|
13
|
+
import pytensor.assumptions.shape
|
|
14
|
+
import pytensor.assumptions.subtensor
|
|
15
|
+
import pytensor.assumptions.symmetric
|
|
16
|
+
import pytensor.assumptions.triangular
|
|
17
|
+
import pytensor.assumptions.tridiagonal
|
|
18
|
+
import pytensor.assumptions.unit_magnitude
|
|
19
|
+
from pytensor.assumptions.bundles import register_matrix_property_rules
|
|
20
|
+
from pytensor.assumptions.core import (
|
|
21
|
+
ALL_KEYS,
|
|
22
|
+
DIAGONAL,
|
|
23
|
+
IMPLIES,
|
|
24
|
+
KEY_REGISTRY,
|
|
25
|
+
LOWER_TRIANGULAR,
|
|
26
|
+
MATRIX_KEYS,
|
|
27
|
+
ORTHOGONAL,
|
|
28
|
+
PERMUTATION,
|
|
29
|
+
POSITIVE_DEFINITE,
|
|
30
|
+
SELECTION,
|
|
31
|
+
SYMMETRIC,
|
|
32
|
+
TRIDIAGONAL,
|
|
33
|
+
UNIQUE_INDICES,
|
|
34
|
+
UNIT_MAGNITUDE,
|
|
35
|
+
UPPER_TRIANGULAR,
|
|
36
|
+
AssumptionFeature,
|
|
37
|
+
AssumptionKey,
|
|
38
|
+
ConflictingAssumptionsError,
|
|
39
|
+
FactState,
|
|
40
|
+
check_assumption,
|
|
41
|
+
implication_holds,
|
|
42
|
+
register_assumption,
|
|
43
|
+
register_constant_inference,
|
|
44
|
+
register_implies,
|
|
45
|
+
register_type_inference,
|
|
46
|
+
register_universal_assumption,
|
|
47
|
+
)
|
|
48
|
+
from pytensor.assumptions.specify import (
|
|
49
|
+
SpecifyAssumptions,
|
|
50
|
+
assume,
|
|
51
|
+
specify_assumption_rule,
|
|
52
|
+
)
|
|
53
|
+
from pytensor.graph.fg import FunctionGraph
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def summarize_assumptions(feature: AssumptionFeature, var) -> str:
|
|
57
|
+
"""Return a compact ``{...}`` tag of the facts known about *var*.
|
|
58
|
+
|
|
59
|
+
Each TRUE fact appears as its ``short_name``; each FALSE fact as ``!short_name``.
|
|
60
|
+
Implied facts are pruned: a TRUE fact is dropped when a stronger fact (one that
|
|
61
|
+
implies it) is also TRUE, and a FALSE fact is dropped when a weaker fact (one it
|
|
62
|
+
implies) is also FALSE. Return ``""`` when nothing is known.
|
|
63
|
+
"""
|
|
64
|
+
states = {}
|
|
65
|
+
for key in ALL_KEYS:
|
|
66
|
+
try:
|
|
67
|
+
states[key] = feature.get(var, key)
|
|
68
|
+
except ConflictingAssumptionsError:
|
|
69
|
+
states[key] = FactState.CONFLICT
|
|
70
|
+
|
|
71
|
+
tokens = []
|
|
72
|
+
for key in ALL_KEYS:
|
|
73
|
+
state = states[key]
|
|
74
|
+
label = key.short_name or key.name
|
|
75
|
+
if state is FactState.TRUE:
|
|
76
|
+
if any(
|
|
77
|
+
key in weaker
|
|
78
|
+
and implication_holds(var, stronger, key)
|
|
79
|
+
and states[stronger] is FactState.TRUE
|
|
80
|
+
for stronger, weaker in IMPLIES.items()
|
|
81
|
+
):
|
|
82
|
+
continue
|
|
83
|
+
tokens.append(label)
|
|
84
|
+
elif state is FactState.FALSE:
|
|
85
|
+
if any(
|
|
86
|
+
implication_holds(var, key, w) and states[w] is FactState.FALSE
|
|
87
|
+
for w in IMPLIES.get(key, ())
|
|
88
|
+
):
|
|
89
|
+
continue
|
|
90
|
+
tokens.append(f"!{label}")
|
|
91
|
+
elif state is FactState.CONFLICT:
|
|
92
|
+
tokens.append(f"{label}=CONFLICT")
|
|
93
|
+
|
|
94
|
+
return "{" + ", ".join(tokens) + "}" if tokens else ""
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def assumption_tags(outputs) -> dict:
|
|
98
|
+
"""Map each variable reachable from *outputs* to its :func:`summarize_assumptions`
|
|
99
|
+
tag, omitting variables with no known facts."""
|
|
100
|
+
fgraph = FunctionGraph(outputs=list(outputs), clone=False)
|
|
101
|
+
feature = AssumptionFeature()
|
|
102
|
+
fgraph.attach_feature(feature)
|
|
103
|
+
tags = {}
|
|
104
|
+
for var in fgraph.variables:
|
|
105
|
+
tag = summarize_assumptions(feature, var)
|
|
106
|
+
if tag:
|
|
107
|
+
tags[var] = tag
|
|
108
|
+
return tags
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
from functools import wraps
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
|
|
5
|
+
from pytensor.assumptions.core import (
|
|
6
|
+
MATRIX_KEYS,
|
|
7
|
+
FactState,
|
|
8
|
+
register_assumption,
|
|
9
|
+
true_if,
|
|
10
|
+
)
|
|
11
|
+
from pytensor.tensor.basic import (
|
|
12
|
+
Alloc,
|
|
13
|
+
NotScalarConstantError,
|
|
14
|
+
get_underlying_scalar_constant_value,
|
|
15
|
+
)
|
|
16
|
+
from pytensor.tensor.blockwise import Blockwise
|
|
17
|
+
from pytensor.tensor.variable import TensorConstant
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def alloc_has_zero_off_diagonal(
|
|
21
|
+
key, op, feature, fgraph, node, input_states
|
|
22
|
+
) -> list[FactState]:
|
|
23
|
+
"""``Alloc`` rule for DIAGONAL / LOWER_TRIANGULAR / UPPER_TRIANGULAR: TRUE when
|
|
24
|
+
the fill value is the scalar 0 (an all-zero square matrix) or the matrix is at
|
|
25
|
+
most 1x1 (no off-diagonal entries), FALSE when it is a known non-zero scalar
|
|
26
|
+
and the matrix is at least 2x2 -- the off-diagonal entries are then non-zero,
|
|
27
|
+
so none of these properties holds.
|
|
28
|
+
|
|
29
|
+
Requires the trailing two output dims to be statically known and equal; these
|
|
30
|
+
properties apply only to square matrices. SYMMETRIC uses :func:`alloc_is_symmetric`
|
|
31
|
+
instead, since a constant fill is symmetric whatever its value.
|
|
32
|
+
"""
|
|
33
|
+
out_shape = node.outputs[0].type.shape
|
|
34
|
+
if len(out_shape) < 2:
|
|
35
|
+
return [FactState.UNKNOWN]
|
|
36
|
+
m, n = out_shape[-2], out_shape[-1]
|
|
37
|
+
if m is None or n is None or m != n:
|
|
38
|
+
return [FactState.UNKNOWN]
|
|
39
|
+
if n <= 1:
|
|
40
|
+
return [FactState.TRUE]
|
|
41
|
+
try:
|
|
42
|
+
val = get_underlying_scalar_constant_value(node.inputs[0])
|
|
43
|
+
except NotScalarConstantError:
|
|
44
|
+
return [FactState.UNKNOWN]
|
|
45
|
+
return true_if(val == 0, else_false=True)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def alloc_is_symmetric(key, op, feature, fgraph, node, input_states) -> list[FactState]:
|
|
49
|
+
"""``Alloc`` rule for SYMMETRIC: a scalar fill broadcasts one value to every
|
|
50
|
+
entry, so a square output equals its transpose -- whatever the value.
|
|
51
|
+
|
|
52
|
+
A non-scalar fill (e.g. a vector broadcast across rows) is left UNKNOWN.
|
|
53
|
+
"""
|
|
54
|
+
out_shape = node.outputs[0].type.shape
|
|
55
|
+
if len(out_shape) < 2:
|
|
56
|
+
return [FactState.UNKNOWN]
|
|
57
|
+
m, n = out_shape[-2], out_shape[-1]
|
|
58
|
+
if m is None or n is None or m != n:
|
|
59
|
+
return [FactState.UNKNOWN]
|
|
60
|
+
return true_if(node.inputs[0].type.ndim == 0)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def eye_is_square(n, m) -> FactState:
|
|
64
|
+
"""Static squareness of an :class:`Eye` from its row/column size inputs:
|
|
65
|
+
TRUE when the two sizes are provably equal, FALSE when provably unequal,
|
|
66
|
+
UNKNOWN while either remains symbolic."""
|
|
67
|
+
if n is m:
|
|
68
|
+
return FactState.TRUE
|
|
69
|
+
if isinstance(n, TensorConstant) and isinstance(m, TensorConstant):
|
|
70
|
+
return FactState.TRUE if n.data.item() == m.data.item() else FactState.FALSE
|
|
71
|
+
return FactState.UNKNOWN
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def eye_identity_rule(key, op, feature, fgraph, node, input_states) -> list[FactState]:
|
|
75
|
+
"""Rule for ORTHOGONAL / PERMUTATION / POSITIVE_DEFINITE: TRUE only when an
|
|
76
|
+
:class:`Eye` is the identity matrix (square with ``k == 0``, or 0x0). Every
|
|
77
|
+
other Eye -- rectangular, off-main, or the all-zero matrix of an off-shape
|
|
78
|
+
band -- lacks all three properties, so it is FALSE once the shape is known
|
|
79
|
+
and UNKNOWN while it is still symbolic.
|
|
80
|
+
"""
|
|
81
|
+
n, m, k = node.inputs
|
|
82
|
+
if not isinstance(k, TensorConstant):
|
|
83
|
+
return [FactState.UNKNOWN]
|
|
84
|
+
if k.data.item() == 0:
|
|
85
|
+
return [eye_is_square(n, m)]
|
|
86
|
+
rows, cols = node.outputs[0].type.shape
|
|
87
|
+
if rows is None or cols is None:
|
|
88
|
+
return [FactState.UNKNOWN]
|
|
89
|
+
return true_if(rows == cols == 0, else_false=True)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def eye_band_is_empty(node, k: int) -> FactState:
|
|
93
|
+
"""Decide statically whether an :class:`Eye`'s ``k``-th diagonal is empty."""
|
|
94
|
+
rows, cols = node.outputs[0].type.shape
|
|
95
|
+
if rows is None or cols is None:
|
|
96
|
+
return FactState.UNKNOWN
|
|
97
|
+
band_is_empty = rows == 0 or cols == 0 or k <= -rows or k >= cols
|
|
98
|
+
return FactState.TRUE if band_is_empty else FactState.FALSE
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def eye_zero_or_identity_rule(
|
|
102
|
+
key, op, feature, fgraph, node, input_states
|
|
103
|
+
) -> list[FactState]:
|
|
104
|
+
"""Rule for SYMMETRIC / DIAGONAL: a square :class:`Eye` has both properties
|
|
105
|
+
when it is the identity (``k == 0``) *or* when the requested off-main band
|
|
106
|
+
``k`` falls entirely outside the shape, leaving an all-zero matrix. A
|
|
107
|
+
non-square Eye, or a square one whose off-main band intersects the shape, is
|
|
108
|
+
neither symmetric nor diagonal.
|
|
109
|
+
"""
|
|
110
|
+
n, m, k = node.inputs
|
|
111
|
+
if not isinstance(k, TensorConstant):
|
|
112
|
+
return [FactState.UNKNOWN]
|
|
113
|
+
square = eye_is_square(n, m)
|
|
114
|
+
if square is FactState.FALSE:
|
|
115
|
+
return [FactState.FALSE]
|
|
116
|
+
offset = k.data.item()
|
|
117
|
+
if offset == 0:
|
|
118
|
+
return [square]
|
|
119
|
+
return [eye_band_is_empty(node, offset)]
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def alloc_diag_rule(rule):
|
|
123
|
+
"""Restrict an :class:`AllocDiag` rule to diagonals on the trailing two axes."""
|
|
124
|
+
|
|
125
|
+
@wraps(rule)
|
|
126
|
+
def guarded_rule(key, op, feature, fgraph, node, input_states):
|
|
127
|
+
core_out_ndim = node.outputs[0].type.ndim
|
|
128
|
+
if isinstance(node.op, Blockwise):
|
|
129
|
+
core_out_ndim -= node.op.batch_ndim(node)
|
|
130
|
+
if (op.axis1, op.axis2) != (core_out_ndim - 2, core_out_ndim - 1):
|
|
131
|
+
return [FactState.UNKNOWN]
|
|
132
|
+
return rule(key, op, feature, fgraph, node, input_states)
|
|
133
|
+
|
|
134
|
+
return guarded_rule
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def alloc_diag_band_is_zero(node) -> FactState:
|
|
138
|
+
"""Decide statically whether the vector an :class:`AllocDiag` places is zero."""
|
|
139
|
+
diag = node.inputs[0]
|
|
140
|
+
if 0 in diag.type.shape:
|
|
141
|
+
return FactState.TRUE
|
|
142
|
+
if isinstance(diag, TensorConstant):
|
|
143
|
+
return FactState.FALSE if np.any(diag.data) else FactState.TRUE
|
|
144
|
+
try:
|
|
145
|
+
val = get_underlying_scalar_constant_value(diag)
|
|
146
|
+
except NotScalarConstantError:
|
|
147
|
+
return FactState.UNKNOWN
|
|
148
|
+
if val == 0:
|
|
149
|
+
return FactState.TRUE
|
|
150
|
+
if None in diag.type.shape:
|
|
151
|
+
# A non-zero fill of unknown size may still be empty.
|
|
152
|
+
return FactState.UNKNOWN
|
|
153
|
+
return FactState.FALSE
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
@alloc_diag_rule
|
|
157
|
+
def alloc_diag_has_zero_off_diagonal(
|
|
158
|
+
key, op, feature, fgraph, node, input_states
|
|
159
|
+
) -> list[FactState]:
|
|
160
|
+
"""Rule for DIAGONAL / SYMMETRIC: TRUE when :class:`AllocDiag` places values on
|
|
161
|
+
the main diagonal or places an all-zero vector, FALSE when it places a vector
|
|
162
|
+
with a non-zero entry on any other diagonal."""
|
|
163
|
+
if op.offset == 0:
|
|
164
|
+
return [FactState.TRUE]
|
|
165
|
+
return [alloc_diag_band_is_zero(node)]
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def alloc_propagates_matrix_property(
|
|
169
|
+
key, op, feature, fgraph, node, input_states
|
|
170
|
+
) -> list[FactState]:
|
|
171
|
+
"""``Alloc`` broadcasts a value across new or expanded leading axes. When the
|
|
172
|
+
value is already matrix-shaped with non-broadcastable core axes, the alloc
|
|
173
|
+
cannot touch those axes, so the matrix property carries through unchanged."""
|
|
174
|
+
value = node.inputs[0]
|
|
175
|
+
if value.type.ndim >= 2 and not any(value.type.broadcastable[-2:]):
|
|
176
|
+
return [input_states[0]]
|
|
177
|
+
return [FactState.UNKNOWN]
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
for _key in MATRIX_KEYS:
|
|
181
|
+
register_assumption(_key, Alloc)(alloc_propagates_matrix_property)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from pytensor.assumptions.core import (
|
|
2
|
+
infer_assumption_for_node,
|
|
3
|
+
register_universal_assumption,
|
|
4
|
+
)
|
|
5
|
+
from pytensor.tensor.blockwise import Blockwise
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@register_universal_assumption(Blockwise)
|
|
9
|
+
def _blockwise_delegate(key, op, feature, fgraph, node, input_states):
|
|
10
|
+
"""Delegate assumption inference to the ``core_op`` of a Blockwise wrapper."""
|
|
11
|
+
return infer_assumption_for_node(
|
|
12
|
+
key, op.core_op, feature, fgraph, node, input_states
|
|
13
|
+
)
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
from pytensor.assumptions.alloc import alloc_propagates_matrix_property
|
|
2
|
+
from pytensor.assumptions.core import AssumptionKey, register_assumption
|
|
3
|
+
from pytensor.assumptions.dimshuffle import dimshuffle_propagates_matrix_property
|
|
4
|
+
from pytensor.assumptions.reshape import (
|
|
5
|
+
join_dims_propagates_matrix_property,
|
|
6
|
+
split_dims_propagates_matrix_property,
|
|
7
|
+
)
|
|
8
|
+
from pytensor.assumptions.shape import (
|
|
9
|
+
reshape_propagates_matrix_property,
|
|
10
|
+
specify_shape_propagates_matrix_property,
|
|
11
|
+
)
|
|
12
|
+
from pytensor.assumptions.subtensor import (
|
|
13
|
+
incsubtensor_propagates_matrix_property,
|
|
14
|
+
subtensor_propagates_matrix_property,
|
|
15
|
+
)
|
|
16
|
+
from pytensor.tensor.basic import Alloc
|
|
17
|
+
from pytensor.tensor.elemwise import DimShuffle
|
|
18
|
+
from pytensor.tensor.reshape import JoinDims, SplitDims
|
|
19
|
+
from pytensor.tensor.shape import Reshape, SpecifyShape
|
|
20
|
+
from pytensor.tensor.subtensor import IncSubtensor, Subtensor
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def register_matrix_property_rules(key: AssumptionKey) -> None:
|
|
24
|
+
"""Register the standard propagation rules for a property of the trailing two axes.
|
|
25
|
+
|
|
26
|
+
Every rule here answers one question: does the Op leave the trailing two axes
|
|
27
|
+
undisturbed? The bundle thus suits any property of a matrix that batch dimensions
|
|
28
|
+
carry elementwise, such as triangularity or a fixed sparsity pattern.
|
|
29
|
+
|
|
30
|
+
Rules are tried in registration order until one returns a non-UNKNOWN state, so a
|
|
31
|
+
key needing different behavior for one Op registers its own with
|
|
32
|
+
``register_assumption(..., prepend=True)``.
|
|
33
|
+
|
|
34
|
+
Parameters
|
|
35
|
+
----------
|
|
36
|
+
key : AssumptionKey
|
|
37
|
+
The property to install the rules for.
|
|
38
|
+
|
|
39
|
+
Examples
|
|
40
|
+
--------
|
|
41
|
+
.. code-block:: python
|
|
42
|
+
|
|
43
|
+
from pytensor.assumptions import AssumptionKey, register_matrix_property_rules
|
|
44
|
+
|
|
45
|
+
TOEPLITZ = AssumptionKey("toeplitz", short_name="toep")
|
|
46
|
+
register_matrix_property_rules(TOEPLITZ)
|
|
47
|
+
"""
|
|
48
|
+
register_assumption(key, DimShuffle)(dimshuffle_propagates_matrix_property)
|
|
49
|
+
register_assumption(key, Reshape)(reshape_propagates_matrix_property)
|
|
50
|
+
register_assumption(key, SpecifyShape)(specify_shape_propagates_matrix_property)
|
|
51
|
+
register_assumption(key, JoinDims)(join_dims_propagates_matrix_property)
|
|
52
|
+
register_assumption(key, SplitDims)(split_dims_propagates_matrix_property)
|
|
53
|
+
register_assumption(key, Alloc)(alloc_propagates_matrix_property)
|
|
54
|
+
register_assumption(key, Subtensor)(subtensor_propagates_matrix_property)
|
|
55
|
+
register_assumption(key, IncSubtensor)(incsubtensor_propagates_matrix_property)
|