pyrecest 1.0.3__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.
- pyrecest/__init__.py +1 -0
- pyrecest/_backend/.pylintrc +2 -0
- pyrecest/_backend/LICENSE_geomstats +9 -0
- pyrecest/_backend/README.md +37 -0
- pyrecest/_backend/__init__.py +368 -0
- pyrecest/_backend/_backend_config.py +11 -0
- pyrecest/_backend/_common.py +29 -0
- pyrecest/_backend/_dtype_utils.py +420 -0
- pyrecest/_backend/_shared_numpy/__init__.py +424 -0
- pyrecest/_backend/_shared_numpy/_common.py +119 -0
- pyrecest/_backend/_shared_numpy/_dispatch.py +12 -0
- pyrecest/_backend/_shared_numpy/linalg.py +138 -0
- pyrecest/_backend/_shared_numpy/random.py +29 -0
- pyrecest/_backend/autograd/__init__.py +194 -0
- pyrecest/_backend/autograd/_common.py +36 -0
- pyrecest/_backend/autograd/_dtype.py +0 -0
- pyrecest/_backend/autograd/autodiff.py +372 -0
- pyrecest/_backend/autograd/linalg.py +62 -0
- pyrecest/_backend/autograd/random.py +5 -0
- pyrecest/_backend/jax/__init__.py +432 -0
- pyrecest/_backend/jax/_dtype.py +29 -0
- pyrecest/_backend/jax/autodiff.py +129 -0
- pyrecest/_backend/jax/fft.py +8 -0
- pyrecest/_backend/jax/linalg.py +34 -0
- pyrecest/_backend/jax/random.py +133 -0
- pyrecest/_backend/jax/signal.py +1 -0
- pyrecest/_backend/jax/spatial.py +1 -0
- pyrecest/_backend/numpy/__init__.py +237 -0
- pyrecest/_backend/numpy/_common.py +36 -0
- pyrecest/_backend/numpy/_dtype.py +0 -0
- pyrecest/_backend/numpy/autodiff.py +66 -0
- pyrecest/_backend/numpy/fft.py +11 -0
- pyrecest/_backend/numpy/linalg.py +33 -0
- pyrecest/_backend/numpy/random.py +8 -0
- pyrecest/_backend/numpy/signal.py +1 -0
- pyrecest/_backend/numpy/spatial.py +1 -0
- pyrecest/_backend/pytorch/__init__.py +917 -0
- pyrecest/_backend/pytorch/_common.py +35 -0
- pyrecest/_backend/pytorch/_dtype.py +148 -0
- pyrecest/_backend/pytorch/autodiff.py +458 -0
- pyrecest/_backend/pytorch/fft.py +10 -0
- pyrecest/_backend/pytorch/linalg.py +161 -0
- pyrecest/_backend/pytorch/random.py +59 -0
- pyrecest/_backend/pytorch/signal.py +2 -0
- pyrecest/_backend/pytorch/spatial.py +27 -0
- pyrecest/distributions/__init__.py +417 -0
- pyrecest/distributions/abstract_bounded_domain_distribution.py +14 -0
- pyrecest/distributions/abstract_bounded_nonperiodic_distribution.py +14 -0
- pyrecest/distributions/abstract_custom_distribution.py +77 -0
- pyrecest/distributions/abstract_custom_nonperiodic_distribution.py +13 -0
- pyrecest/distributions/abstract_dirac_distribution.py +142 -0
- pyrecest/distributions/abstract_disk_distribution.py +17 -0
- pyrecest/distributions/abstract_distribution_type.py +8 -0
- pyrecest/distributions/abstract_ellipsoidal_ball_distribution.py +49 -0
- pyrecest/distributions/abstract_grid_distribution.py +112 -0
- pyrecest/distributions/abstract_manifold_specific_distribution.py +239 -0
- pyrecest/distributions/abstract_mixture.py +105 -0
- pyrecest/distributions/abstract_nonperiodic_distribution.py +9 -0
- pyrecest/distributions/abstract_orthogonal_basis_distribution.py +70 -0
- pyrecest/distributions/abstract_periodic_distribution.py +35 -0
- pyrecest/distributions/abstract_periodic_grid_distribution.py +8 -0
- pyrecest/distributions/abstract_se2_distribution.py +196 -0
- pyrecest/distributions/abstract_se3_distribution.py +127 -0
- pyrecest/distributions/abstract_uniform_distribution.py +37 -0
- pyrecest/distributions/cart_prod/__init__.py +0 -0
- pyrecest/distributions/cart_prod/abstract_cart_prod_distribution.py +10 -0
- pyrecest/distributions/cart_prod/abstract_custom_lin_bounded_cart_prod_distribution.py +30 -0
- pyrecest/distributions/cart_prod/abstract_hypercylindrical_distribution.py +426 -0
- pyrecest/distributions/cart_prod/abstract_lin_bounded_cart_prod_distribution.py +59 -0
- pyrecest/distributions/cart_prod/abstract_lin_hemisphere_cart_prod_distribution.py +9 -0
- pyrecest/distributions/cart_prod/abstract_lin_hyperhemisphere_cart_prod_distribution.py +13 -0
- pyrecest/distributions/cart_prod/abstract_lin_hypersphere_cart_prod_distribution.py +13 -0
- pyrecest/distributions/cart_prod/abstract_lin_hypersphere_subset_cart_prod_distribution.py +9 -0
- pyrecest/distributions/cart_prod/abstract_lin_periodic_cart_prod_distribution.py +19 -0
- pyrecest/distributions/cart_prod/cart_prod_dirac_distribution.py +8 -0
- pyrecest/distributions/cart_prod/cart_prod_stacked_distribution.py +58 -0
- pyrecest/distributions/cart_prod/custom_hypercylindrical_distribution.py +69 -0
- pyrecest/distributions/cart_prod/hypercylindrical_dirac_distribution.py +61 -0
- pyrecest/distributions/cart_prod/hypercylindrical_state_space_subdivision_distribution.py +292 -0
- pyrecest/distributions/cart_prod/hypercylindrical_state_space_subdivision_gaussian_distribution.py +182 -0
- pyrecest/distributions/cart_prod/hyperhemisphere_cart_prod_dirac_distribution.py +38 -0
- pyrecest/distributions/cart_prod/lin_bounded_cart_prod_dirac_distribution.py +52 -0
- pyrecest/distributions/cart_prod/lin_hypersphere_cart_prod_dirac_distribution.py +22 -0
- pyrecest/distributions/cart_prod/lin_hypersphere_subset_dirac_distribution.py +22 -0
- pyrecest/distributions/cart_prod/lin_periodic_cart_prod_dirac_distribution.py +7 -0
- pyrecest/distributions/cart_prod/mardia_sutton_distribution.py +183 -0
- pyrecest/distributions/cart_prod/partially_wrapped_normal_distribution.py +189 -0
- pyrecest/distributions/cart_prod/se2_bingham_distribution.py +342 -0
- pyrecest/distributions/cart_prod/se2_pwn_distribution.py +134 -0
- pyrecest/distributions/cart_prod/state_space_subdivision_distribution.py +75 -0
- pyrecest/distributions/cart_prod/state_space_subdivision_gaussian_distribution.py +248 -0
- pyrecest/distributions/circle/__init__.py +0 -0
- pyrecest/distributions/circle/abstract_circular_distribution.py +72 -0
- pyrecest/distributions/circle/circular_dirac_distribution.py +26 -0
- pyrecest/distributions/circle/circular_fourier_distribution.py +345 -0
- pyrecest/distributions/circle/circular_grid_distribution.py +138 -0
- pyrecest/distributions/circle/circular_mixture.py +48 -0
- pyrecest/distributions/circle/circular_uniform_distribution.py +47 -0
- pyrecest/distributions/circle/custom_circular_distribution.py +55 -0
- pyrecest/distributions/circle/generalized_von_mises_distribution.py +77 -0
- pyrecest/distributions/circle/piecewise_constant_distribution.py +225 -0
- pyrecest/distributions/circle/sine_skewed_distributions.py +246 -0
- pyrecest/distributions/circle/von_mises_distribution.py +174 -0
- pyrecest/distributions/circle/wrapped_cauchy_distribution.py +28 -0
- pyrecest/distributions/circle/wrapped_exponential_distribution.py +43 -0
- pyrecest/distributions/circle/wrapped_laplace_distribution.py +38 -0
- pyrecest/distributions/circle/wrapped_normal_distribution.py +202 -0
- pyrecest/distributions/conditional/__init__.py +11 -0
- pyrecest/distributions/conditional/abstract_conditional_distribution.py +161 -0
- pyrecest/distributions/conditional/s2_cond_s2_grid_distribution.py +115 -0
- pyrecest/distributions/conditional/sd_cond_sd_grid_distribution.py +201 -0
- pyrecest/distributions/conditional/sd_half_cond_sd_half_grid_distribution.py +169 -0
- pyrecest/distributions/conditional/td_cond_td_grid_distribution.py +202 -0
- pyrecest/distributions/custom_hyperrectangular_distribution.py +19 -0
- pyrecest/distributions/disk_uniform_distribution.py +23 -0
- pyrecest/distributions/ellipsoidal_ball_uniform_distribution.py +89 -0
- pyrecest/distributions/hypersphere_subset/__init__.py +0 -0
- pyrecest/distributions/hypersphere_subset/abstract_complex_hyperspherical_distribution.py +58 -0
- pyrecest/distributions/hypersphere_subset/abstract_hemispherical_distribution.py +21 -0
- pyrecest/distributions/hypersphere_subset/abstract_hyperhemispherical_distribution.py +222 -0
- pyrecest/distributions/hypersphere_subset/abstract_hypersphere_subset_dirac_distribution.py +66 -0
- pyrecest/distributions/hypersphere_subset/abstract_hypersphere_subset_distribution.py +466 -0
- pyrecest/distributions/hypersphere_subset/abstract_hypersphere_subset_grid_distribution.py +137 -0
- pyrecest/distributions/hypersphere_subset/abstract_hypersphere_subset_uniform_distribution.py +40 -0
- pyrecest/distributions/hypersphere_subset/abstract_hyperspherical_distribution.py +270 -0
- pyrecest/distributions/hypersphere_subset/abstract_sphere_subset_distribution.py +149 -0
- pyrecest/distributions/hypersphere_subset/abstract_spherical_distribution.py +42 -0
- pyrecest/distributions/hypersphere_subset/abstract_spherical_harmonics_distribution.py +125 -0
- pyrecest/distributions/hypersphere_subset/bingham_distribution.py +308 -0
- pyrecest/distributions/hypersphere_subset/complex_angular_central_gaussian_distribution.py +149 -0
- pyrecest/distributions/hypersphere_subset/complex_bingham_distribution.py +389 -0
- pyrecest/distributions/hypersphere_subset/complex_watson_distribution.py +324 -0
- pyrecest/distributions/hypersphere_subset/custom_hemispherical_distribution.py +45 -0
- pyrecest/distributions/hypersphere_subset/custom_hyperhemispherical_distribution.py +82 -0
- pyrecest/distributions/hypersphere_subset/custom_hyperspherical_distribution.py +22 -0
- pyrecest/distributions/hypersphere_subset/hemispherical_uniform_distribution.py +10 -0
- pyrecest/distributions/hypersphere_subset/hyperhemispherical_bingham_distribution.py +53 -0
- pyrecest/distributions/hypersphere_subset/hyperhemispherical_dirac_distribution.py +16 -0
- pyrecest/distributions/hypersphere_subset/hyperhemispherical_grid_distribution.py +250 -0
- pyrecest/distributions/hypersphere_subset/hyperhemispherical_uniform_distribution.py +51 -0
- pyrecest/distributions/hypersphere_subset/hyperhemispherical_watson_distribution.py +59 -0
- pyrecest/distributions/hypersphere_subset/hyperspherical_dirac_distribution.py +44 -0
- pyrecest/distributions/hypersphere_subset/hyperspherical_grid_distribution.py +308 -0
- pyrecest/distributions/hypersphere_subset/hyperspherical_mixture.py +23 -0
- pyrecest/distributions/hypersphere_subset/hyperspherical_uniform_distribution.py +56 -0
- pyrecest/distributions/hypersphere_subset/spherical_grid_distribution.py +169 -0
- pyrecest/distributions/hypersphere_subset/spherical_harmonics_distribution_complex.py +469 -0
- pyrecest/distributions/hypersphere_subset/spherical_harmonics_distribution_real.py +88 -0
- pyrecest/distributions/hypersphere_subset/von_mises_fisher_distribution.py +203 -0
- pyrecest/distributions/hypersphere_subset/watson_distribution.py +126 -0
- pyrecest/distributions/hypertorus/__init__.py +0 -0
- pyrecest/distributions/hypertorus/abstract_hypertoroidal_distribution.py +314 -0
- pyrecest/distributions/hypertorus/abstract_toroidal_bivar_vm_distribution.py +35 -0
- pyrecest/distributions/hypertorus/abstract_toroidal_distribution.py +73 -0
- pyrecest/distributions/hypertorus/custom_hypertoroidal_distribution.py +52 -0
- pyrecest/distributions/hypertorus/custom_toroidal_distribution.py +10 -0
- pyrecest/distributions/hypertorus/hypertoroidal_dirac_distribution.py +120 -0
- pyrecest/distributions/hypertorus/hypertoroidal_fourier_distribution.py +715 -0
- pyrecest/distributions/hypertorus/hypertoroidal_grid_distribution.py +310 -0
- pyrecest/distributions/hypertorus/hypertoroidal_mixture.py +80 -0
- pyrecest/distributions/hypertorus/hypertoroidal_uniform_distribution.py +104 -0
- pyrecest/distributions/hypertorus/hypertoroidal_wrapped_normal_distribution.py +163 -0
- pyrecest/distributions/hypertorus/toroidal_dirac_distribution.py +55 -0
- pyrecest/distributions/hypertorus/toroidal_fourier_distribution.py +318 -0
- pyrecest/distributions/hypertorus/toroidal_mixture.py +18 -0
- pyrecest/distributions/hypertorus/toroidal_uniform_distribution.py +14 -0
- pyrecest/distributions/hypertorus/toroidal_vm_matrix_distribution.py +328 -0
- pyrecest/distributions/hypertorus/toroidal_vm_rivest_distribution.py +146 -0
- pyrecest/distributions/hypertorus/toroidal_von_mises_cosine_distribution.py +86 -0
- pyrecest/distributions/hypertorus/toroidal_von_mises_sine_distribution.py +32 -0
- pyrecest/distributions/hypertorus/toroidal_wrapped_normal_distribution.py +127 -0
- pyrecest/distributions/nonperiodic/__init__.py +0 -0
- pyrecest/distributions/nonperiodic/abstract_hyperrectangular_distribution.py +43 -0
- pyrecest/distributions/nonperiodic/abstract_linear_distribution.py +351 -0
- pyrecest/distributions/nonperiodic/custom_linear_distribution.py +76 -0
- pyrecest/distributions/nonperiodic/gaussian_distribution.py +134 -0
- pyrecest/distributions/nonperiodic/gaussian_mixture.py +57 -0
- pyrecest/distributions/nonperiodic/hyperrectangular_uniform_distribution.py +13 -0
- pyrecest/distributions/nonperiodic/linear_dirac_distribution.py +82 -0
- pyrecest/distributions/nonperiodic/linear_mixture.py +28 -0
- pyrecest/distributions/se2_dirac_distribution.py +110 -0
- pyrecest/distributions/se3_cart_prod_stacked_distribution.py +22 -0
- pyrecest/distributions/se3_dirac_distribution.py +48 -0
- pyrecest/evaluation/__init__.py +37 -0
- pyrecest/evaluation/check_and_fix_config.py +93 -0
- pyrecest/evaluation/configure_for_filter.py +152 -0
- pyrecest/evaluation/determine_all_deviations.py +57 -0
- pyrecest/evaluation/eot_shape_database.py +221 -0
- pyrecest/evaluation/evaluate_for_file.py +71 -0
- pyrecest/evaluation/evaluate_for_simulation_config.py +91 -0
- pyrecest/evaluation/evaluate_for_variables.py +81 -0
- pyrecest/evaluation/generate_groundtruth.py +94 -0
- pyrecest/evaluation/generate_measurements.py +194 -0
- pyrecest/evaluation/generate_simulated_scenarios.py +40 -0
- pyrecest/evaluation/get_axis_label.py +39 -0
- pyrecest/evaluation/get_distance_function.py +70 -0
- pyrecest/evaluation/get_extract_mean.py +51 -0
- pyrecest/evaluation/group_results_by_filter.py +23 -0
- pyrecest/evaluation/iterate_configs_and_runs.py +78 -0
- pyrecest/evaluation/perform_predict_update_cycles.py +91 -0
- pyrecest/evaluation/plot_results.py +292 -0
- pyrecest/evaluation/simulation_database.py +39 -0
- pyrecest/evaluation/summarize_filter_results.py +62 -0
- pyrecest/filters/__init__.py +153 -0
- pyrecest/filters/_linear_gaussian.py +109 -0
- pyrecest/filters/_ukf.py +291 -0
- pyrecest/filters/abstract_axial_filter.py +73 -0
- pyrecest/filters/abstract_dummy_filter.py +49 -0
- pyrecest/filters/abstract_extended_object_tracker.py +99 -0
- pyrecest/filters/abstract_filter.py +63 -0
- pyrecest/filters/abstract_grid_filter.py +52 -0
- pyrecest/filters/abstract_multitarget_tracker.py +33 -0
- pyrecest/filters/abstract_nearest_neighbor_tracker.py +166 -0
- pyrecest/filters/abstract_particle_filter.py +139 -0
- pyrecest/filters/abstract_tracker_with_logging.py +65 -0
- pyrecest/filters/axial_kalman_filter.py +106 -0
- pyrecest/filters/bingham_filter.py +156 -0
- pyrecest/filters/circular_particle_filter.py +35 -0
- pyrecest/filters/circular_ukf.py +280 -0
- pyrecest/filters/euclidean_particle_filter.py +69 -0
- pyrecest/filters/gaussian_mixture_phd_filter.py +538 -0
- pyrecest/filters/global_nearest_neighbor.py +251 -0
- pyrecest/filters/goal_conditioned_replay_imm_filter.py +1551 -0
- pyrecest/filters/goal_conditioned_replay_particle_filter.py +1461 -0
- pyrecest/filters/gprhm_tracker.py +177 -0
- pyrecest/filters/hypercylindrical_particle_filter.py +43 -0
- pyrecest/filters/hyperhemisphere_cart_prod_particle_filter.py +117 -0
- pyrecest/filters/hyperhemispherical_grid_filter.py +333 -0
- pyrecest/filters/hyperhemispherical_particle_filter.py +42 -0
- pyrecest/filters/hyperspherical_dummy_filter.py +27 -0
- pyrecest/filters/hyperspherical_particle_filter.py +60 -0
- pyrecest/filters/hyperspherical_ukf.py +303 -0
- pyrecest/filters/hypertoroidal_dummy_filter.py +27 -0
- pyrecest/filters/hypertoroidal_fourier_filter.py +414 -0
- pyrecest/filters/hypertoroidal_particle_filter.py +67 -0
- pyrecest/filters/interacting_multiple_model_filter.py +605 -0
- pyrecest/filters/joint_probabilistic_data_association_filter.py +399 -0
- pyrecest/filters/kalman_filter.py +133 -0
- pyrecest/filters/kernel_sme_filter.py +440 -0
- pyrecest/filters/lin_bounded_particle_filter.py +6 -0
- pyrecest/filters/lin_periodic_particle_filter.py +6 -0
- pyrecest/filters/manifold_mixins.py +66 -0
- pyrecest/filters/multi_bernoulli_tracker.py +662 -0
- pyrecest/filters/multi_hypothesis_tracker.py +600 -0
- pyrecest/filters/piecewise_constant_filter.py +232 -0
- pyrecest/filters/random_matrix_tracker.py +128 -0
- pyrecest/filters/se2_ukf.py +316 -0
- pyrecest/filters/spherical_harmonics_filter.py +248 -0
- pyrecest/filters/state_space_subdivision_filter.py +331 -0
- pyrecest/filters/toroidal_particle_filter.py +13 -0
- pyrecest/filters/toroidal_wrapped_normal_filter.py +20 -0
- pyrecest/filters/track_manager.py +972 -0
- pyrecest/filters/ukf_on_manifolds.py +318 -0
- pyrecest/filters/unscented_kalman_filter.py +167 -0
- pyrecest/filters/von_mises_filter.py +64 -0
- pyrecest/filters/von_mises_fisher_filter.py +61 -0
- pyrecest/filters/wrapped_normal_filter.py +76 -0
- pyrecest/sampling/__init__.py +33 -0
- pyrecest/sampling/abstract_sampler.py +7 -0
- pyrecest/sampling/euclidean_sampler.py +292 -0
- pyrecest/sampling/hyperspherical_sampler.py +416 -0
- pyrecest/sampling/hypertoroidal_sampler.py +30 -0
- pyrecest/sampling/leopardi_sampler.py +533 -0
- pyrecest/smoothers/__init__.py +14 -0
- pyrecest/smoothers/abstract_smoother.py +137 -0
- pyrecest/smoothers/rauch_tung_striebel_smoother.py +296 -0
- pyrecest/smoothers/unscented_rauch_tung_striebel_smoother.py +511 -0
- pyrecest/tests/__init__.py +0 -0
- pyrecest/tests/distributions/__init__.py +0 -0
- pyrecest/tests/distributions/test_abstract_circular_distribution.py +90 -0
- pyrecest/tests/distributions/test_abstract_dirac_distribution.py +27 -0
- pyrecest/tests/distributions/test_abstract_hypercylindrical_distribution.py +115 -0
- pyrecest/tests/distributions/test_abstract_hyperhemispherical_distribution.py +73 -0
- pyrecest/tests/distributions/test_abstract_hypersphere_subset_dirac_distribution.py +79 -0
- pyrecest/tests/distributions/test_abstract_hypersphere_subset_distribution.py +309 -0
- pyrecest/tests/distributions/test_abstract_hyperspherical_distribution.py +102 -0
- pyrecest/tests/distributions/test_abstract_hypertoroidal_distribution.py +42 -0
- pyrecest/tests/distributions/test_abstract_linear_distribution.py +103 -0
- pyrecest/tests/distributions/test_abstract_mixture.py +60 -0
- pyrecest/tests/distributions/test_abstract_periodic_grid_distribution.py +21 -0
- pyrecest/tests/distributions/test_abstract_se2_distribution.py +47 -0
- pyrecest/tests/distributions/test_abstract_sphere_subset_distribution.py +88 -0
- pyrecest/tests/distributions/test_bingham_distribution.py +47 -0
- pyrecest/tests/distributions/test_circular_fourier_distribution.py +201 -0
- pyrecest/tests/distributions/test_circular_grid_distribution.py +49 -0
- pyrecest/tests/distributions/test_circular_uniform_distribution.py +114 -0
- pyrecest/tests/distributions/test_complex_angular_central_gaussian_distribution.py +194 -0
- pyrecest/tests/distributions/test_complex_bingham_distribution.py +240 -0
- pyrecest/tests/distributions/test_complex_watson_distribution.py +237 -0
- pyrecest/tests/distributions/test_custom_hemispherical_distribution.py +85 -0
- pyrecest/tests/distributions/test_custom_hypercylindrical_distribution.py +77 -0
- pyrecest/tests/distributions/test_custom_hyperrectangular_distribution.py +41 -0
- pyrecest/tests/distributions/test_custom_hyperspherical_distribution.py +63 -0
- pyrecest/tests/distributions/test_custom_linear_distribution.py +43 -0
- pyrecest/tests/distributions/test_disk_uniform_distribution.py +41 -0
- pyrecest/tests/distributions/test_ellipsoidal_ball_uniform_distribution.py +29 -0
- pyrecest/tests/distributions/test_gaussian_distribution.py +99 -0
- pyrecest/tests/distributions/test_generalized_von_mises_distribution.py +68 -0
- pyrecest/tests/distributions/test_gssvm_distribution.py +80 -0
- pyrecest/tests/distributions/test_hemispherical_uniform_distribution.py +25 -0
- pyrecest/tests/distributions/test_hypercylindrical_dirac_distribution.py +167 -0
- pyrecest/tests/distributions/test_hypercylindrical_state_space_subdivision_distribution.py +176 -0
- pyrecest/tests/distributions/test_hyperhemispherical_bingham_distribution.py +45 -0
- pyrecest/tests/distributions/test_hyperhemispherical_grid_distribution.py +375 -0
- pyrecest/tests/distributions/test_hyperhemispherical_uniform_distribution.py +60 -0
- pyrecest/tests/distributions/test_hyperspherical_dirac_distribution.py +105 -0
- pyrecest/tests/distributions/test_hyperspherical_grid_distribution.py +454 -0
- pyrecest/tests/distributions/test_hyperspherical_mixture.py +59 -0
- pyrecest/tests/distributions/test_hyperspherical_uniform_distribution.py +70 -0
- pyrecest/tests/distributions/test_hypertoroidal_dirac_distribution.py +159 -0
- pyrecest/tests/distributions/test_hypertoroidal_fourier_distribution.py +516 -0
- pyrecest/tests/distributions/test_hypertoroidal_grid_distribution.py +67 -0
- pyrecest/tests/distributions/test_hypertoroidal_wrapped_normal_distribution.py +27 -0
- pyrecest/tests/distributions/test_linear_dirac_distribution.py +70 -0
- pyrecest/tests/distributions/test_linear_mixture.py +47 -0
- pyrecest/tests/distributions/test_mardia_sutton_distribution.py +123 -0
- pyrecest/tests/distributions/test_multi_hypothesis_tracker.py +114 -0
- pyrecest/tests/distributions/test_partially_wrapped_normal_distribution.py +54 -0
- pyrecest/tests/distributions/test_piecewise_constant_distribution.py +127 -0
- pyrecest/tests/distributions/test_s2_cond_s2_grid_distribution.py +233 -0
- pyrecest/tests/distributions/test_sd_cond_sd_grid_distribution.py +355 -0
- pyrecest/tests/distributions/test_se2_bingham_distribution.py +153 -0
- pyrecest/tests/distributions/test_se2_dirac_distribution.py +124 -0
- pyrecest/tests/distributions/test_se2_pwn_distribution.py +101 -0
- pyrecest/tests/distributions/test_se3_dirac_distribution.py +45 -0
- pyrecest/tests/distributions/test_sine_skewed_distributions.py +213 -0
- pyrecest/tests/distributions/test_spherical_harmonics_distribution_complex.py +1355 -0
- pyrecest/tests/distributions/test_spherical_harmonics_distribution_real.py +501 -0
- pyrecest/tests/distributions/test_state_space_subdivision_gaussian_distribution.py +159 -0
- pyrecest/tests/distributions/test_td_cond_td_grid_distribution.py +290 -0
- pyrecest/tests/distributions/test_toroidal_fourier_distribution.py +262 -0
- pyrecest/tests/distributions/test_toroidal_uniform_distribution.py +84 -0
- pyrecest/tests/distributions/test_toroidal_vm_matrix_distribution.py +101 -0
- pyrecest/tests/distributions/test_toroidal_vm_rivest_distribution.py +135 -0
- pyrecest/tests/distributions/test_toroidal_von_mises_cosine_distribution.py +67 -0
- pyrecest/tests/distributions/test_toroidal_von_mises_sine_distribution.py +96 -0
- pyrecest/tests/distributions/test_toroidal_wrapped_normal_distribution.py +46 -0
- pyrecest/tests/distributions/test_von_mises_distribution.py +46 -0
- pyrecest/tests/distributions/test_von_mises_fisher_distribution.py +241 -0
- pyrecest/tests/distributions/test_watson_distribution.py +124 -0
- pyrecest/tests/distributions/test_wrapped_cauchy_distribution.py +51 -0
- pyrecest/tests/distributions/test_wrapped_exponential_distribution.py +85 -0
- pyrecest/tests/distributions/test_wrapped_laplace_distribution.py +76 -0
- pyrecest/tests/distributions/test_wrapped_normal_distribution.py +53 -0
- pyrecest/tests/filters/__init__.py +0 -0
- pyrecest/tests/filters/test_axial_kalman_filter.py +207 -0
- pyrecest/tests/filters/test_bingham_filter.py +184 -0
- pyrecest/tests/filters/test_circular_particle_filter.py +156 -0
- pyrecest/tests/filters/test_circular_ukf.py +128 -0
- pyrecest/tests/filters/test_euclidean_particle_filter.py +71 -0
- pyrecest/tests/filters/test_gaussian_mixture_phd_filter.py +149 -0
- pyrecest/tests/filters/test_global_nearest_neighbor.py +381 -0
- pyrecest/tests/filters/test_global_nearest_neighbor_pairwise_costs.py +147 -0
- pyrecest/tests/filters/test_gnn_cost_matrix_interface.py +79 -0
- pyrecest/tests/filters/test_goal_conditioned_replay_common.py +16 -0
- pyrecest/tests/filters/test_goal_conditioned_replay_imm_filter.py +114 -0
- pyrecest/tests/filters/test_goal_conditioned_replay_particle_filter.py +92 -0
- pyrecest/tests/filters/test_gprhm_tracker.py +80 -0
- pyrecest/tests/filters/test_hypercylindrical_particle_filter.py +92 -0
- pyrecest/tests/filters/test_hyperhemisphere_cart_prod_particle_filter.py +99 -0
- pyrecest/tests/filters/test_hyperhemispherical_grid_filter.py +153 -0
- pyrecest/tests/filters/test_hyperhemispherical_particle_filter.py +52 -0
- pyrecest/tests/filters/test_hyperspherical_dummy_filter.py +85 -0
- pyrecest/tests/filters/test_hyperspherical_particle_filter.py +76 -0
- pyrecest/tests/filters/test_hyperspherical_ukf.py +246 -0
- pyrecest/tests/filters/test_hypertoroidal_dummy_filter.py +83 -0
- pyrecest/tests/filters/test_hypertoroidal_fourier_filter.py +509 -0
- pyrecest/tests/filters/test_hypertoroidal_particle_filter.py +61 -0
- pyrecest/tests/filters/test_interacting_multiple_model_filter.py +145 -0
- pyrecest/tests/filters/test_joint_probabilistic_data_association_filter.py +150 -0
- pyrecest/tests/filters/test_kalman_filter.py +60 -0
- pyrecest/tests/filters/test_kernel_sme_filter.py +413 -0
- pyrecest/tests/filters/test_multi_bernoulli_tracker.py +322 -0
- pyrecest/tests/filters/test_multi_hypothesis_tracker.py +94 -0
- pyrecest/tests/filters/test_piecewise_constant_filter.py +148 -0
- pyrecest/tests/filters/test_random_matrix_tracker.py +165 -0
- pyrecest/tests/filters/test_se2_ukf.py +206 -0
- pyrecest/tests/filters/test_spherical_harmonics_filter.py +181 -0
- pyrecest/tests/filters/test_state_space_subdivision_filter.py +248 -0
- pyrecest/tests/filters/test_toroidal_particle_filter.py +45 -0
- pyrecest/tests/filters/test_toroidal_wrapped_normal_filter.py +39 -0
- pyrecest/tests/filters/test_ukf_on_manifolds.py +319 -0
- pyrecest/tests/filters/test_unscented_kalman_filter.py +85 -0
- pyrecest/tests/filters/test_von_mises_filter.py +47 -0
- pyrecest/tests/filters/test_von_mises_fisher_filter.py +48 -0
- pyrecest/tests/filters/test_wrapped_normal_filter.py +53 -0
- pyrecest/tests/smoothers/__init__.py +0 -0
- pyrecest/tests/smoothers/test_rauch_tung_striebel_smoother.py +100 -0
- pyrecest/tests/smoothers/test_unscented_rauch_tung_striebel_smoother.py +118 -0
- pyrecest/tests/test_backend_interface.py +12 -0
- pyrecest/tests/test_backend_size.py +15 -0
- pyrecest/tests/test_eot_shape_database.py +82 -0
- pyrecest/tests/test_euclidean_sampler.py +115 -0
- pyrecest/tests/test_evaluation_basic.py +643 -0
- pyrecest/tests/test_history_recorder.py +155 -0
- pyrecest/tests/test_hyperspherical_sampler.py +447 -0
- pyrecest/tests/test_hypertoroidal_sampler.py +42 -0
- pyrecest/tests/test_metrics.py +64 -0
- pyrecest/tests/test_nonrigid_point_set_registration.py +224 -0
- pyrecest/tests/test_point_set_registration.py +158 -0
- pyrecest/tests/utils/test_assignment.py +162 -0
- pyrecest/utils/__init__.py +18 -0
- pyrecest/utils/_point_set_registration_common.py +304 -0
- pyrecest/utils/assignment.py +272 -0
- pyrecest/utils/history_recorder.py +152 -0
- pyrecest/utils/metrics.py +37 -0
- pyrecest/utils/nonrigid_point_set_registration.py +314 -0
- pyrecest/utils/plotting.py +61 -0
- pyrecest/utils/point_set_registration.py +321 -0
- pyrecest-1.0.3.dist-info/METADATA +85 -0
- pyrecest-1.0.3.dist-info/RECORD +413 -0
- pyrecest-1.0.3.dist-info/WHEEL +4 -0
- pyrecest-1.0.3.dist-info/licenses/LICENSE +21 -0
pyrecest/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import pyrecest._backend # noqa
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 Nina Miolane
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Backend Interface
|
|
2
|
+
|
|
3
|
+
This folder contains code from the Geomstats project, adjusted for pyRecEst by Florian Pfaff. The original version of Geomstats is authored by Nina Miolane et al., and is a Python package geared towards Riemannian Geometry in Machine Learning.
|
|
4
|
+
|
|
5
|
+
## Original Project Details
|
|
6
|
+
|
|
7
|
+
- **Title**: Geomstats: A Python Package for Riemannian Geometry in Machine Learning
|
|
8
|
+
- **Authors**: Nina Miolane, Nicolas Guigui, Alice Le Brigant, Johan Mathe, Benjamin Hou, Yann Thanwerdas, Stefan Heyder, Olivier Peltre, Niklas Koep, Hadi Zaatiti, Hatem Hajri, Yann Cabanes, Thomas Gerald, Paul Chauchat, Christian Shewmake, Daniel Brooks, Bernhard Kainz, Claire Donnat, Susan Holmes, Xavier Pennec
|
|
9
|
+
- **Journal**: Journal of Machine Learning Research, 2020, Vol. 21, No. 223, Pp. 1-9
|
|
10
|
+
- **URL**: [Geomstats Project](http://jmlr.org/papers/v21/19-027.html)
|
|
11
|
+
|
|
12
|
+
## License
|
|
13
|
+
|
|
14
|
+
This code is provided under the MIT License. A copy of the license can be found in this folder.
|
|
15
|
+
|
|
16
|
+
## Modifications
|
|
17
|
+
|
|
18
|
+
The code in this folder has been modified by Florian Pfaff to adapt it to pyRecEst.
|
|
19
|
+
|
|
20
|
+
## (Adapted) Usage Instructions
|
|
21
|
+
|
|
22
|
+
In order to expose a new backend function/attribute to the rest of the
|
|
23
|
+
codebase, it is necessary to add the name to the respective list in the
|
|
24
|
+
`BACKEND_ATTRIBUTES` dictionary in `pyrecest/_backend/__init__.py`.
|
|
25
|
+
This serves two purposes:
|
|
26
|
+
|
|
27
|
+
1. Define a clear boundary between backend interface and backend-internal code:
|
|
28
|
+
Only functions/attributes which are used outside the backend should be made
|
|
29
|
+
available to the rest of the codebase.
|
|
30
|
+
1. Guarantee each backend exposes the same attributes:
|
|
31
|
+
When loading a backend, the backend importer verifies that a backend
|
|
32
|
+
provides each attribute listed in the `BACKEND_ATTRIBUTES` dict.
|
|
33
|
+
This way, we guarantee that unit tests fail during CI builds when a
|
|
34
|
+
maintainer/contributor forgets to provide an implementation of a feature for
|
|
35
|
+
a particular backend.
|
|
36
|
+
If a feature cannot be supported for some reason, the function should raise
|
|
37
|
+
a `NotImplementedError` for the time being.
|
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
"""Execution backends.
|
|
2
|
+
|
|
3
|
+
Lead authors: Johan Mathe and Niklas Koep.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import importlib
|
|
7
|
+
import importlib.abc
|
|
8
|
+
import importlib.machinery
|
|
9
|
+
import logging
|
|
10
|
+
import os
|
|
11
|
+
import sys
|
|
12
|
+
import types
|
|
13
|
+
|
|
14
|
+
import pyrecest._backend._common as common
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def get_backend_name():
|
|
18
|
+
return os.environ.get("PYRECEST_BACKEND", "numpy")
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
BACKEND_NAME = get_backend_name()
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
BACKEND_ATTRIBUTES = {
|
|
25
|
+
"": [
|
|
26
|
+
# Types
|
|
27
|
+
"int32",
|
|
28
|
+
"int64",
|
|
29
|
+
"float32",
|
|
30
|
+
"float64",
|
|
31
|
+
"complex64",
|
|
32
|
+
"complex128",
|
|
33
|
+
"uint8",
|
|
34
|
+
# Functions
|
|
35
|
+
"abs",
|
|
36
|
+
"all",
|
|
37
|
+
"allclose",
|
|
38
|
+
"amax",
|
|
39
|
+
"amin",
|
|
40
|
+
"angle",
|
|
41
|
+
"any",
|
|
42
|
+
"arange",
|
|
43
|
+
"arccos",
|
|
44
|
+
"arccosh",
|
|
45
|
+
"arcsin",
|
|
46
|
+
"arctan2",
|
|
47
|
+
"arctanh",
|
|
48
|
+
"argmax",
|
|
49
|
+
"argmin",
|
|
50
|
+
"array",
|
|
51
|
+
"array_from_sparse",
|
|
52
|
+
"asarray",
|
|
53
|
+
"as_dtype",
|
|
54
|
+
"assignment",
|
|
55
|
+
"assignment_by_sum",
|
|
56
|
+
"atol",
|
|
57
|
+
"broadcast_arrays",
|
|
58
|
+
"broadcast_to",
|
|
59
|
+
"cast",
|
|
60
|
+
"ceil",
|
|
61
|
+
"clip",
|
|
62
|
+
"comb",
|
|
63
|
+
"concatenate",
|
|
64
|
+
"conj",
|
|
65
|
+
"convert_to_wider_dtype",
|
|
66
|
+
"copy",
|
|
67
|
+
"cos",
|
|
68
|
+
"cosh",
|
|
69
|
+
"cross",
|
|
70
|
+
"cumprod",
|
|
71
|
+
"cumsum",
|
|
72
|
+
"diag_indices",
|
|
73
|
+
"diagonal",
|
|
74
|
+
"divide",
|
|
75
|
+
"dot",
|
|
76
|
+
"einsum",
|
|
77
|
+
"empty",
|
|
78
|
+
"empty_like",
|
|
79
|
+
"equal",
|
|
80
|
+
"erf",
|
|
81
|
+
"exp",
|
|
82
|
+
"expand_dims",
|
|
83
|
+
"eye",
|
|
84
|
+
"flatten",
|
|
85
|
+
"flip",
|
|
86
|
+
"floor",
|
|
87
|
+
"from_numpy",
|
|
88
|
+
"gamma",
|
|
89
|
+
"get_default_dtype",
|
|
90
|
+
"get_default_cdtype",
|
|
91
|
+
"get_slice",
|
|
92
|
+
"greater",
|
|
93
|
+
"has_autodiff",
|
|
94
|
+
"hsplit",
|
|
95
|
+
"hstack",
|
|
96
|
+
"imag",
|
|
97
|
+
"isclose",
|
|
98
|
+
"isnan",
|
|
99
|
+
"isscalar",
|
|
100
|
+
"is_array",
|
|
101
|
+
"is_complex",
|
|
102
|
+
"is_floating",
|
|
103
|
+
"is_bool",
|
|
104
|
+
"kron",
|
|
105
|
+
"less",
|
|
106
|
+
"less_equal",
|
|
107
|
+
"linspace",
|
|
108
|
+
"log",
|
|
109
|
+
"logical_and",
|
|
110
|
+
"logical_or",
|
|
111
|
+
"mat_from_diag_triu_tril",
|
|
112
|
+
"matmul",
|
|
113
|
+
"matvec",
|
|
114
|
+
"maximum",
|
|
115
|
+
"mean",
|
|
116
|
+
"meshgrid",
|
|
117
|
+
"minimum",
|
|
118
|
+
"mod",
|
|
119
|
+
"moveaxis",
|
|
120
|
+
"ndim",
|
|
121
|
+
"one_hot",
|
|
122
|
+
"ones",
|
|
123
|
+
"ones_like",
|
|
124
|
+
"outer",
|
|
125
|
+
"pad",
|
|
126
|
+
"pi",
|
|
127
|
+
"polygamma",
|
|
128
|
+
"power",
|
|
129
|
+
"prod",
|
|
130
|
+
"quantile",
|
|
131
|
+
"ravel_tril_indices",
|
|
132
|
+
"real",
|
|
133
|
+
"repeat",
|
|
134
|
+
"reshape",
|
|
135
|
+
"rtol",
|
|
136
|
+
"scatter_add",
|
|
137
|
+
"searchsorted",
|
|
138
|
+
"set_default_dtype",
|
|
139
|
+
"set_diag",
|
|
140
|
+
"shape",
|
|
141
|
+
"size",
|
|
142
|
+
"sign",
|
|
143
|
+
"sin",
|
|
144
|
+
"sinh",
|
|
145
|
+
"split",
|
|
146
|
+
"sqrt",
|
|
147
|
+
"squeeze",
|
|
148
|
+
"sort",
|
|
149
|
+
"stack",
|
|
150
|
+
"std",
|
|
151
|
+
"sum",
|
|
152
|
+
"take",
|
|
153
|
+
"tan",
|
|
154
|
+
"tanh",
|
|
155
|
+
"tile",
|
|
156
|
+
"to_numpy",
|
|
157
|
+
"to_ndarray",
|
|
158
|
+
"trace",
|
|
159
|
+
"transpose",
|
|
160
|
+
"tril",
|
|
161
|
+
"triu",
|
|
162
|
+
"tril_indices",
|
|
163
|
+
"triu_indices",
|
|
164
|
+
"tril_to_vec",
|
|
165
|
+
"triu_to_vec",
|
|
166
|
+
"vec_to_diag",
|
|
167
|
+
"unique",
|
|
168
|
+
"vectorize",
|
|
169
|
+
"vstack",
|
|
170
|
+
"where",
|
|
171
|
+
"zeros",
|
|
172
|
+
"zeros_like",
|
|
173
|
+
"trapezoid", # Changed from trapz to trapezoid from scipy.integrate
|
|
174
|
+
# The ones below are for pyrecest
|
|
175
|
+
"diag",
|
|
176
|
+
"diff",
|
|
177
|
+
"apply_along_axis",
|
|
178
|
+
"nonzero",
|
|
179
|
+
"column_stack",
|
|
180
|
+
"conj",
|
|
181
|
+
"atleast_1d",
|
|
182
|
+
"atleast_2d",
|
|
183
|
+
"dstack",
|
|
184
|
+
"full",
|
|
185
|
+
"isreal",
|
|
186
|
+
"triu",
|
|
187
|
+
"kron",
|
|
188
|
+
"angle",
|
|
189
|
+
"arctan",
|
|
190
|
+
"cov",
|
|
191
|
+
"count_nonzero",
|
|
192
|
+
"full_like",
|
|
193
|
+
"isinf",
|
|
194
|
+
"isfinite",
|
|
195
|
+
"deg2rad",
|
|
196
|
+
"rad2deg",
|
|
197
|
+
"argsort",
|
|
198
|
+
"max",
|
|
199
|
+
"min",
|
|
200
|
+
"roll",
|
|
201
|
+
"dstack",
|
|
202
|
+
"vmap",
|
|
203
|
+
"gammaln",
|
|
204
|
+
"round",
|
|
205
|
+
"array_equal",
|
|
206
|
+
# For Riemannian score-based SDE
|
|
207
|
+
"log1p"
|
|
208
|
+
],
|
|
209
|
+
"autodiff": [
|
|
210
|
+
"custom_gradient",
|
|
211
|
+
"hessian",
|
|
212
|
+
"hessian_vec",
|
|
213
|
+
"jacobian",
|
|
214
|
+
"jacobian_vec",
|
|
215
|
+
"jacobian_and_hessian",
|
|
216
|
+
"value_and_grad",
|
|
217
|
+
"value_and_jacobian",
|
|
218
|
+
"value_jacobian_and_hessian",
|
|
219
|
+
],
|
|
220
|
+
"linalg": [
|
|
221
|
+
"cholesky",
|
|
222
|
+
"det",
|
|
223
|
+
"eig",
|
|
224
|
+
"eigh",
|
|
225
|
+
"eigvalsh",
|
|
226
|
+
"expm",
|
|
227
|
+
"fractional_matrix_power",
|
|
228
|
+
"inv",
|
|
229
|
+
"is_single_matrix_pd",
|
|
230
|
+
"logm",
|
|
231
|
+
"matrix_power",
|
|
232
|
+
"norm",
|
|
233
|
+
"qr",
|
|
234
|
+
"quadratic_assignment",
|
|
235
|
+
"polar",
|
|
236
|
+
"solve",
|
|
237
|
+
"solve_sylvester",
|
|
238
|
+
"sqrtm",
|
|
239
|
+
"svd",
|
|
240
|
+
"matrix_rank",
|
|
241
|
+
"block_diag", # For PyRecEst
|
|
242
|
+
"pinv",
|
|
243
|
+
],
|
|
244
|
+
"random": [
|
|
245
|
+
"choice",
|
|
246
|
+
"normal",
|
|
247
|
+
"multinomial",
|
|
248
|
+
"multivariate_normal",
|
|
249
|
+
# TODO (nkoep): Remove 'rand' and replace it by 'uniform'. Much like
|
|
250
|
+
# 'randn' is a convenience wrapper (which we don't use)
|
|
251
|
+
# for 'normal', 'rand' only wraps 'uniform'.
|
|
252
|
+
"rand",
|
|
253
|
+
"randint",
|
|
254
|
+
"seed",
|
|
255
|
+
"uniform",
|
|
256
|
+
# For PyRecEst
|
|
257
|
+
"get_state",
|
|
258
|
+
"set_state",
|
|
259
|
+
],
|
|
260
|
+
"fft": [ # For PyRecEst
|
|
261
|
+
"rfft",
|
|
262
|
+
"irfft",
|
|
263
|
+
"fftshift",
|
|
264
|
+
"ifftshift",
|
|
265
|
+
"fftn",
|
|
266
|
+
"ifftn",
|
|
267
|
+
],
|
|
268
|
+
"spatial": [ # For PyRecEst
|
|
269
|
+
"Rotation",
|
|
270
|
+
],
|
|
271
|
+
"signal": [ # For PyRecEst
|
|
272
|
+
"fftconvolve",
|
|
273
|
+
],
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
class BackendImporter(importlib.abc.MetaPathFinder, importlib.abc.Loader):
|
|
278
|
+
"""
|
|
279
|
+
Meta path finder and loader for dynamically creating backend modules.
|
|
280
|
+
|
|
281
|
+
Implements the modern PEP 451 import protocol (create_module / exec_module).
|
|
282
|
+
|
|
283
|
+
Responsible for intercepting imports of 'pyrecest.backend' and redirecting
|
|
284
|
+
them to dynamically constructed backend implementations (e.g. numpy, torch).
|
|
285
|
+
"""
|
|
286
|
+
|
|
287
|
+
def __init__(self, path: str):
|
|
288
|
+
self._path = path
|
|
289
|
+
|
|
290
|
+
@staticmethod
|
|
291
|
+
def _import_backend(backend_name: str):
|
|
292
|
+
try:
|
|
293
|
+
return importlib.import_module(f"pyrecest._backend.{backend_name}")
|
|
294
|
+
except ModuleNotFoundError as e:
|
|
295
|
+
raise RuntimeError(f"Unknown backend '{backend_name}'") from e
|
|
296
|
+
|
|
297
|
+
def _create_backend_module(self, backend_name: str):
|
|
298
|
+
backend = self._import_backend(backend_name)
|
|
299
|
+
|
|
300
|
+
new_module = types.ModuleType(self._path)
|
|
301
|
+
new_module.__file__ = getattr(backend, "__file__", None)
|
|
302
|
+
|
|
303
|
+
# expose chosen backend
|
|
304
|
+
new_module.__backend_name__ = backend_name
|
|
305
|
+
new_module.BACKEND_NAME = backend_name
|
|
306
|
+
new_module.get_backend_name = staticmethod(lambda: backend_name)
|
|
307
|
+
|
|
308
|
+
for module_name, attributes in BACKEND_ATTRIBUTES.items():
|
|
309
|
+
if module_name:
|
|
310
|
+
try:
|
|
311
|
+
submodule = getattr(backend, module_name)
|
|
312
|
+
except AttributeError:
|
|
313
|
+
raise RuntimeError(
|
|
314
|
+
f"Backend '{backend_name}' exposes no '{module_name}' module"
|
|
315
|
+
) from None
|
|
316
|
+
new_submodule = types.ModuleType(f"{self._path}.{module_name}")
|
|
317
|
+
new_submodule.__file__ = getattr(submodule, "__file__", None)
|
|
318
|
+
setattr(new_module, module_name, new_submodule)
|
|
319
|
+
else:
|
|
320
|
+
submodule = backend
|
|
321
|
+
new_submodule = new_module
|
|
322
|
+
|
|
323
|
+
for attribute_name in attributes:
|
|
324
|
+
try:
|
|
325
|
+
submodule_ = submodule
|
|
326
|
+
if module_name == "" and not hasattr(submodule, attribute_name):
|
|
327
|
+
submodule_ = common
|
|
328
|
+
attribute = getattr(submodule_, attribute_name)
|
|
329
|
+
except AttributeError:
|
|
330
|
+
if module_name:
|
|
331
|
+
raise RuntimeError(
|
|
332
|
+
f"Module '{module_name}' of backend '{backend_name}' "
|
|
333
|
+
f"does not define the required attribute '{attribute_name}'."
|
|
334
|
+
) from None
|
|
335
|
+
else:
|
|
336
|
+
raise RuntimeError(
|
|
337
|
+
f"Backend '{backend_name}' does not define the required "
|
|
338
|
+
f"attribute '{attribute_name}'."
|
|
339
|
+
) from None
|
|
340
|
+
else:
|
|
341
|
+
setattr(new_submodule, attribute_name, attribute)
|
|
342
|
+
|
|
343
|
+
return new_module
|
|
344
|
+
|
|
345
|
+
def find_spec(self, fullname, path=None, target=None):
|
|
346
|
+
"""Find a module spec for the dynamically created backend."""
|
|
347
|
+
if fullname != self._path:
|
|
348
|
+
return None
|
|
349
|
+
return importlib.machinery.ModuleSpec(fullname, self)
|
|
350
|
+
|
|
351
|
+
def create_module(self, spec):
|
|
352
|
+
"""Create the module object but don’t execute it yet."""
|
|
353
|
+
module = self._create_backend_module(BACKEND_NAME)
|
|
354
|
+
module.__loader__ = self
|
|
355
|
+
module.__spec__ = spec
|
|
356
|
+
return module
|
|
357
|
+
|
|
358
|
+
def exec_module(self, module):
|
|
359
|
+
"""Execute the module (initialize attributes, types, etc.)."""
|
|
360
|
+
if hasattr(module, "set_default_dtype"):
|
|
361
|
+
module.set_default_dtype("float64")
|
|
362
|
+
logging.info(f"Using {BACKEND_NAME} backend")
|
|
363
|
+
|
|
364
|
+
TARGET = "pyrecest.backend"
|
|
365
|
+
if not any(isinstance(f, BackendImporter) and getattr(f, "_path", None) == TARGET
|
|
366
|
+
for f in sys.meta_path):
|
|
367
|
+
# put it in front so it intercepts 'pyrecest.backend'
|
|
368
|
+
sys.meta_path.insert(0, BackendImporter(TARGET))
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import math as _math
|
|
2
|
+
|
|
3
|
+
from numpy import pi
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def comb(n, k):
|
|
7
|
+
return _math.factorial(n) // _math.factorial(k) // _math.factorial(n - k)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def size(x, axis=None):
|
|
11
|
+
"""Return the total number of elements or the length of a given axis."""
|
|
12
|
+
if hasattr(x, "numel"):
|
|
13
|
+
if axis is None:
|
|
14
|
+
return x.numel()
|
|
15
|
+
return x.shape[axis]
|
|
16
|
+
|
|
17
|
+
shape = getattr(x, "shape", None)
|
|
18
|
+
if shape is None:
|
|
19
|
+
if axis is not None:
|
|
20
|
+
raise ValueError("axis is only supported for array-like inputs")
|
|
21
|
+
return 1
|
|
22
|
+
|
|
23
|
+
if axis is not None:
|
|
24
|
+
return shape[axis]
|
|
25
|
+
|
|
26
|
+
result = 1
|
|
27
|
+
for dim in shape:
|
|
28
|
+
result *= dim
|
|
29
|
+
return result
|