numpy 2.4.1__cp314-cp314t-win_arm64.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.
- numpy/__config__.py +170 -0
- numpy/__config__.pyi +108 -0
- numpy/__init__.cython-30.pxd +1242 -0
- numpy/__init__.pxd +1155 -0
- numpy/__init__.py +955 -0
- numpy/__init__.pyi +6202 -0
- numpy/_array_api_info.py +346 -0
- numpy/_array_api_info.pyi +206 -0
- numpy/_configtool.py +39 -0
- numpy/_configtool.pyi +1 -0
- numpy/_core/__init__.py +201 -0
- numpy/_core/__init__.pyi +666 -0
- numpy/_core/_add_newdocs.py +7151 -0
- numpy/_core/_add_newdocs.pyi +2 -0
- numpy/_core/_add_newdocs_scalars.py +381 -0
- numpy/_core/_add_newdocs_scalars.pyi +16 -0
- numpy/_core/_asarray.py +130 -0
- numpy/_core/_asarray.pyi +43 -0
- numpy/_core/_dtype.py +366 -0
- numpy/_core/_dtype.pyi +56 -0
- numpy/_core/_dtype_ctypes.py +120 -0
- numpy/_core/_dtype_ctypes.pyi +83 -0
- numpy/_core/_exceptions.py +162 -0
- numpy/_core/_exceptions.pyi +54 -0
- numpy/_core/_internal.py +968 -0
- numpy/_core/_internal.pyi +61 -0
- numpy/_core/_methods.py +252 -0
- numpy/_core/_methods.pyi +22 -0
- numpy/_core/_multiarray_tests.cp314t-win_arm64.lib +0 -0
- numpy/_core/_multiarray_tests.cp314t-win_arm64.pyd +0 -0
- numpy/_core/_multiarray_umath.cp314t-win_arm64.lib +0 -0
- numpy/_core/_multiarray_umath.cp314t-win_arm64.pyd +0 -0
- numpy/_core/_operand_flag_tests.cp314t-win_arm64.lib +0 -0
- numpy/_core/_operand_flag_tests.cp314t-win_arm64.pyd +0 -0
- numpy/_core/_rational_tests.cp314t-win_arm64.lib +0 -0
- numpy/_core/_rational_tests.cp314t-win_arm64.pyd +0 -0
- numpy/_core/_simd.cp314t-win_arm64.lib +0 -0
- numpy/_core/_simd.cp314t-win_arm64.pyd +0 -0
- numpy/_core/_simd.pyi +35 -0
- numpy/_core/_string_helpers.py +100 -0
- numpy/_core/_string_helpers.pyi +12 -0
- numpy/_core/_struct_ufunc_tests.cp314t-win_arm64.lib +0 -0
- numpy/_core/_struct_ufunc_tests.cp314t-win_arm64.pyd +0 -0
- numpy/_core/_type_aliases.py +131 -0
- numpy/_core/_type_aliases.pyi +86 -0
- numpy/_core/_ufunc_config.py +515 -0
- numpy/_core/_ufunc_config.pyi +69 -0
- numpy/_core/_umath_tests.cp314t-win_arm64.lib +0 -0
- numpy/_core/_umath_tests.cp314t-win_arm64.pyd +0 -0
- numpy/_core/_umath_tests.pyi +47 -0
- numpy/_core/arrayprint.py +1779 -0
- numpy/_core/arrayprint.pyi +158 -0
- numpy/_core/cversions.py +13 -0
- numpy/_core/defchararray.py +1414 -0
- numpy/_core/defchararray.pyi +1150 -0
- numpy/_core/einsumfunc.py +1650 -0
- numpy/_core/einsumfunc.pyi +184 -0
- numpy/_core/fromnumeric.py +4233 -0
- numpy/_core/fromnumeric.pyi +1735 -0
- numpy/_core/function_base.py +547 -0
- numpy/_core/function_base.pyi +276 -0
- numpy/_core/getlimits.py +462 -0
- numpy/_core/getlimits.pyi +124 -0
- numpy/_core/include/numpy/__multiarray_api.c +376 -0
- numpy/_core/include/numpy/__multiarray_api.h +1628 -0
- numpy/_core/include/numpy/__ufunc_api.c +55 -0
- numpy/_core/include/numpy/__ufunc_api.h +349 -0
- numpy/_core/include/numpy/_neighborhood_iterator_imp.h +90 -0
- numpy/_core/include/numpy/_numpyconfig.h +33 -0
- numpy/_core/include/numpy/_public_dtype_api_table.h +86 -0
- numpy/_core/include/numpy/arrayobject.h +7 -0
- numpy/_core/include/numpy/arrayscalars.h +198 -0
- numpy/_core/include/numpy/dtype_api.h +547 -0
- numpy/_core/include/numpy/halffloat.h +70 -0
- numpy/_core/include/numpy/ndarrayobject.h +304 -0
- numpy/_core/include/numpy/ndarraytypes.h +1982 -0
- numpy/_core/include/numpy/npy_2_compat.h +249 -0
- numpy/_core/include/numpy/npy_2_complexcompat.h +28 -0
- numpy/_core/include/numpy/npy_3kcompat.h +374 -0
- numpy/_core/include/numpy/npy_common.h +989 -0
- numpy/_core/include/numpy/npy_cpu.h +126 -0
- numpy/_core/include/numpy/npy_endian.h +79 -0
- numpy/_core/include/numpy/npy_math.h +602 -0
- numpy/_core/include/numpy/npy_no_deprecated_api.h +20 -0
- numpy/_core/include/numpy/npy_os.h +42 -0
- numpy/_core/include/numpy/numpyconfig.h +185 -0
- numpy/_core/include/numpy/random/LICENSE.txt +21 -0
- numpy/_core/include/numpy/random/bitgen.h +20 -0
- numpy/_core/include/numpy/random/distributions.h +209 -0
- numpy/_core/include/numpy/random/libdivide.h +2079 -0
- numpy/_core/include/numpy/ufuncobject.h +343 -0
- numpy/_core/include/numpy/utils.h +37 -0
- numpy/_core/lib/npy-pkg-config/mlib.ini +12 -0
- numpy/_core/lib/npy-pkg-config/npymath.ini +20 -0
- numpy/_core/lib/npymath.lib +0 -0
- numpy/_core/lib/pkgconfig/numpy.pc +7 -0
- numpy/_core/memmap.py +363 -0
- numpy/_core/memmap.pyi +3 -0
- numpy/_core/multiarray.py +1740 -0
- numpy/_core/multiarray.pyi +1316 -0
- numpy/_core/numeric.py +2758 -0
- numpy/_core/numeric.pyi +1276 -0
- numpy/_core/numerictypes.py +633 -0
- numpy/_core/numerictypes.pyi +196 -0
- numpy/_core/overrides.py +188 -0
- numpy/_core/overrides.pyi +47 -0
- numpy/_core/printoptions.py +32 -0
- numpy/_core/printoptions.pyi +28 -0
- numpy/_core/records.py +1088 -0
- numpy/_core/records.pyi +340 -0
- numpy/_core/shape_base.py +996 -0
- numpy/_core/shape_base.pyi +182 -0
- numpy/_core/strings.py +1813 -0
- numpy/_core/strings.pyi +536 -0
- numpy/_core/tests/_locales.py +72 -0
- numpy/_core/tests/_natype.py +144 -0
- numpy/_core/tests/data/astype_copy.pkl +0 -0
- numpy/_core/tests/data/generate_umath_validation_data.cpp +170 -0
- numpy/_core/tests/data/recarray_from_file.fits +0 -0
- numpy/_core/tests/data/umath-validation-set-README.txt +15 -0
- numpy/_core/tests/data/umath-validation-set-arccos.csv +1429 -0
- numpy/_core/tests/data/umath-validation-set-arccosh.csv +1429 -0
- numpy/_core/tests/data/umath-validation-set-arcsin.csv +1429 -0
- numpy/_core/tests/data/umath-validation-set-arcsinh.csv +1429 -0
- numpy/_core/tests/data/umath-validation-set-arctan.csv +1429 -0
- numpy/_core/tests/data/umath-validation-set-arctanh.csv +1429 -0
- numpy/_core/tests/data/umath-validation-set-cbrt.csv +1429 -0
- numpy/_core/tests/data/umath-validation-set-cos.csv +1375 -0
- numpy/_core/tests/data/umath-validation-set-cosh.csv +1429 -0
- numpy/_core/tests/data/umath-validation-set-exp.csv +412 -0
- numpy/_core/tests/data/umath-validation-set-exp2.csv +1429 -0
- numpy/_core/tests/data/umath-validation-set-expm1.csv +1429 -0
- numpy/_core/tests/data/umath-validation-set-log.csv +271 -0
- numpy/_core/tests/data/umath-validation-set-log10.csv +1629 -0
- numpy/_core/tests/data/umath-validation-set-log1p.csv +1429 -0
- numpy/_core/tests/data/umath-validation-set-log2.csv +1629 -0
- numpy/_core/tests/data/umath-validation-set-sin.csv +1370 -0
- numpy/_core/tests/data/umath-validation-set-sinh.csv +1429 -0
- numpy/_core/tests/data/umath-validation-set-tan.csv +1429 -0
- numpy/_core/tests/data/umath-validation-set-tanh.csv +1429 -0
- numpy/_core/tests/examples/cython/checks.pyx +373 -0
- numpy/_core/tests/examples/cython/meson.build +43 -0
- numpy/_core/tests/examples/cython/setup.py +39 -0
- numpy/_core/tests/examples/limited_api/limited_api1.c +17 -0
- numpy/_core/tests/examples/limited_api/limited_api2.pyx +11 -0
- numpy/_core/tests/examples/limited_api/limited_api_latest.c +19 -0
- numpy/_core/tests/examples/limited_api/meson.build +59 -0
- numpy/_core/tests/examples/limited_api/setup.py +24 -0
- numpy/_core/tests/test__exceptions.py +90 -0
- numpy/_core/tests/test_abc.py +54 -0
- numpy/_core/tests/test_api.py +655 -0
- numpy/_core/tests/test_argparse.py +90 -0
- numpy/_core/tests/test_array_api_info.py +113 -0
- numpy/_core/tests/test_array_coercion.py +928 -0
- numpy/_core/tests/test_array_interface.py +222 -0
- numpy/_core/tests/test_arraymethod.py +84 -0
- numpy/_core/tests/test_arrayobject.py +75 -0
- numpy/_core/tests/test_arrayprint.py +1324 -0
- numpy/_core/tests/test_casting_floatingpoint_errors.py +154 -0
- numpy/_core/tests/test_casting_unittests.py +955 -0
- numpy/_core/tests/test_conversion_utils.py +209 -0
- numpy/_core/tests/test_cpu_dispatcher.py +48 -0
- numpy/_core/tests/test_cpu_features.py +450 -0
- numpy/_core/tests/test_custom_dtypes.py +393 -0
- numpy/_core/tests/test_cython.py +352 -0
- numpy/_core/tests/test_datetime.py +2792 -0
- numpy/_core/tests/test_defchararray.py +858 -0
- numpy/_core/tests/test_deprecations.py +460 -0
- numpy/_core/tests/test_dlpack.py +190 -0
- numpy/_core/tests/test_dtype.py +2110 -0
- numpy/_core/tests/test_einsum.py +1351 -0
- numpy/_core/tests/test_errstate.py +131 -0
- numpy/_core/tests/test_extint128.py +217 -0
- numpy/_core/tests/test_finfo.py +86 -0
- numpy/_core/tests/test_function_base.py +504 -0
- numpy/_core/tests/test_getlimits.py +171 -0
- numpy/_core/tests/test_half.py +593 -0
- numpy/_core/tests/test_hashtable.py +36 -0
- numpy/_core/tests/test_indexerrors.py +122 -0
- numpy/_core/tests/test_indexing.py +1692 -0
- numpy/_core/tests/test_item_selection.py +167 -0
- numpy/_core/tests/test_limited_api.py +102 -0
- numpy/_core/tests/test_longdouble.py +370 -0
- numpy/_core/tests/test_mem_overlap.py +933 -0
- numpy/_core/tests/test_mem_policy.py +453 -0
- numpy/_core/tests/test_memmap.py +248 -0
- numpy/_core/tests/test_multiarray.py +11008 -0
- numpy/_core/tests/test_multiprocessing.py +55 -0
- numpy/_core/tests/test_multithreading.py +377 -0
- numpy/_core/tests/test_nditer.py +3533 -0
- numpy/_core/tests/test_nep50_promotions.py +287 -0
- numpy/_core/tests/test_numeric.py +4295 -0
- numpy/_core/tests/test_numerictypes.py +650 -0
- numpy/_core/tests/test_overrides.py +800 -0
- numpy/_core/tests/test_print.py +202 -0
- numpy/_core/tests/test_protocols.py +46 -0
- numpy/_core/tests/test_records.py +544 -0
- numpy/_core/tests/test_regression.py +2677 -0
- numpy/_core/tests/test_scalar_ctors.py +203 -0
- numpy/_core/tests/test_scalar_methods.py +328 -0
- numpy/_core/tests/test_scalarbuffer.py +153 -0
- numpy/_core/tests/test_scalarinherit.py +105 -0
- numpy/_core/tests/test_scalarmath.py +1168 -0
- numpy/_core/tests/test_scalarprint.py +403 -0
- numpy/_core/tests/test_shape_base.py +904 -0
- numpy/_core/tests/test_simd.py +1345 -0
- numpy/_core/tests/test_simd_module.py +105 -0
- numpy/_core/tests/test_stringdtype.py +1855 -0
- numpy/_core/tests/test_strings.py +1523 -0
- numpy/_core/tests/test_ufunc.py +3405 -0
- numpy/_core/tests/test_umath.py +4962 -0
- numpy/_core/tests/test_umath_accuracy.py +132 -0
- numpy/_core/tests/test_umath_complex.py +631 -0
- numpy/_core/tests/test_unicode.py +369 -0
- numpy/_core/umath.py +60 -0
- numpy/_core/umath.pyi +232 -0
- numpy/_distributor_init.py +15 -0
- numpy/_distributor_init.pyi +1 -0
- numpy/_expired_attrs_2_0.py +78 -0
- numpy/_expired_attrs_2_0.pyi +61 -0
- numpy/_globals.py +121 -0
- numpy/_globals.pyi +17 -0
- numpy/_pyinstaller/__init__.py +0 -0
- numpy/_pyinstaller/__init__.pyi +0 -0
- numpy/_pyinstaller/hook-numpy.py +36 -0
- numpy/_pyinstaller/hook-numpy.pyi +6 -0
- numpy/_pyinstaller/tests/__init__.py +16 -0
- numpy/_pyinstaller/tests/pyinstaller-smoke.py +32 -0
- numpy/_pyinstaller/tests/test_pyinstaller.py +35 -0
- numpy/_pytesttester.py +201 -0
- numpy/_pytesttester.pyi +18 -0
- numpy/_typing/__init__.py +173 -0
- numpy/_typing/_add_docstring.py +153 -0
- numpy/_typing/_array_like.py +106 -0
- numpy/_typing/_char_codes.py +213 -0
- numpy/_typing/_dtype_like.py +114 -0
- numpy/_typing/_extended_precision.py +15 -0
- numpy/_typing/_nbit.py +19 -0
- numpy/_typing/_nbit_base.py +94 -0
- numpy/_typing/_nbit_base.pyi +39 -0
- numpy/_typing/_nested_sequence.py +79 -0
- numpy/_typing/_scalars.py +20 -0
- numpy/_typing/_shape.py +8 -0
- numpy/_typing/_ufunc.py +7 -0
- numpy/_typing/_ufunc.pyi +975 -0
- numpy/_utils/__init__.py +95 -0
- numpy/_utils/__init__.pyi +28 -0
- numpy/_utils/_convertions.py +18 -0
- numpy/_utils/_convertions.pyi +4 -0
- numpy/_utils/_inspect.py +192 -0
- numpy/_utils/_inspect.pyi +70 -0
- numpy/_utils/_pep440.py +486 -0
- numpy/_utils/_pep440.pyi +118 -0
- numpy/char/__init__.py +2 -0
- numpy/char/__init__.pyi +111 -0
- numpy/conftest.py +248 -0
- numpy/core/__init__.py +33 -0
- numpy/core/__init__.pyi +0 -0
- numpy/core/_dtype.py +10 -0
- numpy/core/_dtype.pyi +0 -0
- numpy/core/_dtype_ctypes.py +10 -0
- numpy/core/_dtype_ctypes.pyi +0 -0
- numpy/core/_internal.py +27 -0
- numpy/core/_multiarray_umath.py +57 -0
- numpy/core/_utils.py +21 -0
- numpy/core/arrayprint.py +10 -0
- numpy/core/defchararray.py +10 -0
- numpy/core/einsumfunc.py +10 -0
- numpy/core/fromnumeric.py +10 -0
- numpy/core/function_base.py +10 -0
- numpy/core/getlimits.py +10 -0
- numpy/core/multiarray.py +25 -0
- numpy/core/numeric.py +12 -0
- numpy/core/numerictypes.py +10 -0
- numpy/core/overrides.py +10 -0
- numpy/core/overrides.pyi +7 -0
- numpy/core/records.py +10 -0
- numpy/core/shape_base.py +10 -0
- numpy/core/umath.py +10 -0
- numpy/ctypeslib/__init__.py +13 -0
- numpy/ctypeslib/__init__.pyi +15 -0
- numpy/ctypeslib/_ctypeslib.py +603 -0
- numpy/ctypeslib/_ctypeslib.pyi +236 -0
- numpy/doc/ufuncs.py +138 -0
- numpy/dtypes.py +41 -0
- numpy/dtypes.pyi +630 -0
- numpy/exceptions.py +246 -0
- numpy/exceptions.pyi +27 -0
- numpy/f2py/__init__.py +86 -0
- numpy/f2py/__init__.pyi +5 -0
- numpy/f2py/__main__.py +5 -0
- numpy/f2py/__version__.py +1 -0
- numpy/f2py/__version__.pyi +1 -0
- numpy/f2py/_backends/__init__.py +9 -0
- numpy/f2py/_backends/__init__.pyi +5 -0
- numpy/f2py/_backends/_backend.py +44 -0
- numpy/f2py/_backends/_backend.pyi +46 -0
- numpy/f2py/_backends/_distutils.py +76 -0
- numpy/f2py/_backends/_distutils.pyi +13 -0
- numpy/f2py/_backends/_meson.py +244 -0
- numpy/f2py/_backends/_meson.pyi +62 -0
- numpy/f2py/_backends/meson.build.template +58 -0
- numpy/f2py/_isocbind.py +62 -0
- numpy/f2py/_isocbind.pyi +13 -0
- numpy/f2py/_src_pyf.py +247 -0
- numpy/f2py/_src_pyf.pyi +28 -0
- numpy/f2py/auxfuncs.py +1004 -0
- numpy/f2py/auxfuncs.pyi +262 -0
- numpy/f2py/capi_maps.py +811 -0
- numpy/f2py/capi_maps.pyi +33 -0
- numpy/f2py/cb_rules.py +665 -0
- numpy/f2py/cb_rules.pyi +17 -0
- numpy/f2py/cfuncs.py +1563 -0
- numpy/f2py/cfuncs.pyi +31 -0
- numpy/f2py/common_rules.py +143 -0
- numpy/f2py/common_rules.pyi +9 -0
- numpy/f2py/crackfortran.py +3725 -0
- numpy/f2py/crackfortran.pyi +266 -0
- numpy/f2py/diagnose.py +149 -0
- numpy/f2py/diagnose.pyi +1 -0
- numpy/f2py/f2py2e.py +788 -0
- numpy/f2py/f2py2e.pyi +74 -0
- numpy/f2py/f90mod_rules.py +269 -0
- numpy/f2py/f90mod_rules.pyi +16 -0
- numpy/f2py/func2subr.py +329 -0
- numpy/f2py/func2subr.pyi +7 -0
- numpy/f2py/rules.py +1629 -0
- numpy/f2py/rules.pyi +41 -0
- numpy/f2py/setup.cfg +3 -0
- numpy/f2py/src/fortranobject.c +1436 -0
- numpy/f2py/src/fortranobject.h +173 -0
- numpy/f2py/symbolic.py +1518 -0
- numpy/f2py/symbolic.pyi +219 -0
- numpy/f2py/tests/__init__.py +16 -0
- numpy/f2py/tests/src/abstract_interface/foo.f90 +34 -0
- numpy/f2py/tests/src/abstract_interface/gh18403_mod.f90 +6 -0
- numpy/f2py/tests/src/array_from_pyobj/wrapmodule.c +235 -0
- numpy/f2py/tests/src/assumed_shape/.f2py_f2cmap +1 -0
- numpy/f2py/tests/src/assumed_shape/foo_free.f90 +34 -0
- numpy/f2py/tests/src/assumed_shape/foo_mod.f90 +41 -0
- numpy/f2py/tests/src/assumed_shape/foo_use.f90 +19 -0
- numpy/f2py/tests/src/assumed_shape/precision.f90 +4 -0
- numpy/f2py/tests/src/block_docstring/foo.f +6 -0
- numpy/f2py/tests/src/callback/foo.f +62 -0
- numpy/f2py/tests/src/callback/gh17797.f90 +7 -0
- numpy/f2py/tests/src/callback/gh18335.f90 +17 -0
- numpy/f2py/tests/src/callback/gh25211.f +10 -0
- numpy/f2py/tests/src/callback/gh25211.pyf +18 -0
- numpy/f2py/tests/src/callback/gh26681.f90 +18 -0
- numpy/f2py/tests/src/cli/gh_22819.pyf +6 -0
- numpy/f2py/tests/src/cli/hi77.f +3 -0
- numpy/f2py/tests/src/cli/hiworld.f90 +3 -0
- numpy/f2py/tests/src/common/block.f +11 -0
- numpy/f2py/tests/src/common/gh19161.f90 +10 -0
- numpy/f2py/tests/src/crackfortran/accesstype.f90 +13 -0
- numpy/f2py/tests/src/crackfortran/common_with_division.f +17 -0
- numpy/f2py/tests/src/crackfortran/data_common.f +8 -0
- numpy/f2py/tests/src/crackfortran/data_multiplier.f +5 -0
- numpy/f2py/tests/src/crackfortran/data_stmts.f90 +20 -0
- numpy/f2py/tests/src/crackfortran/data_with_comments.f +8 -0
- numpy/f2py/tests/src/crackfortran/foo_deps.f90 +6 -0
- numpy/f2py/tests/src/crackfortran/gh15035.f +16 -0
- numpy/f2py/tests/src/crackfortran/gh17859.f +12 -0
- numpy/f2py/tests/src/crackfortran/gh22648.pyf +7 -0
- numpy/f2py/tests/src/crackfortran/gh23533.f +5 -0
- numpy/f2py/tests/src/crackfortran/gh23598.f90 +4 -0
- numpy/f2py/tests/src/crackfortran/gh23598Warn.f90 +11 -0
- numpy/f2py/tests/src/crackfortran/gh23879.f90 +20 -0
- numpy/f2py/tests/src/crackfortran/gh27697.f90 +12 -0
- numpy/f2py/tests/src/crackfortran/gh2848.f90 +13 -0
- numpy/f2py/tests/src/crackfortran/operators.f90 +49 -0
- numpy/f2py/tests/src/crackfortran/privatemod.f90 +11 -0
- numpy/f2py/tests/src/crackfortran/publicmod.f90 +10 -0
- numpy/f2py/tests/src/crackfortran/pubprivmod.f90 +10 -0
- numpy/f2py/tests/src/crackfortran/unicode_comment.f90 +4 -0
- numpy/f2py/tests/src/f2cmap/.f2py_f2cmap +1 -0
- numpy/f2py/tests/src/f2cmap/isoFortranEnvMap.f90 +9 -0
- numpy/f2py/tests/src/isocintrin/isoCtests.f90 +34 -0
- numpy/f2py/tests/src/kind/foo.f90 +20 -0
- numpy/f2py/tests/src/mixed/foo.f +5 -0
- numpy/f2py/tests/src/mixed/foo_fixed.f90 +8 -0
- numpy/f2py/tests/src/mixed/foo_free.f90 +8 -0
- numpy/f2py/tests/src/modules/gh25337/data.f90 +8 -0
- numpy/f2py/tests/src/modules/gh25337/use_data.f90 +6 -0
- numpy/f2py/tests/src/modules/gh26920/two_mods_with_no_public_entities.f90 +21 -0
- numpy/f2py/tests/src/modules/gh26920/two_mods_with_one_public_routine.f90 +21 -0
- numpy/f2py/tests/src/modules/module_data_docstring.f90 +12 -0
- numpy/f2py/tests/src/modules/use_modules.f90 +20 -0
- numpy/f2py/tests/src/negative_bounds/issue_20853.f90 +7 -0
- numpy/f2py/tests/src/parameter/constant_array.f90 +45 -0
- numpy/f2py/tests/src/parameter/constant_both.f90 +57 -0
- numpy/f2py/tests/src/parameter/constant_compound.f90 +15 -0
- numpy/f2py/tests/src/parameter/constant_integer.f90 +22 -0
- numpy/f2py/tests/src/parameter/constant_non_compound.f90 +23 -0
- numpy/f2py/tests/src/parameter/constant_real.f90 +23 -0
- numpy/f2py/tests/src/quoted_character/foo.f +14 -0
- numpy/f2py/tests/src/regression/AB.inc +1 -0
- numpy/f2py/tests/src/regression/assignOnlyModule.f90 +25 -0
- numpy/f2py/tests/src/regression/datonly.f90 +17 -0
- numpy/f2py/tests/src/regression/f77comments.f +26 -0
- numpy/f2py/tests/src/regression/f77fixedform.f95 +5 -0
- numpy/f2py/tests/src/regression/f90continuation.f90 +9 -0
- numpy/f2py/tests/src/regression/incfile.f90 +5 -0
- numpy/f2py/tests/src/regression/inout.f90 +9 -0
- numpy/f2py/tests/src/regression/lower_f2py_fortran.f90 +5 -0
- numpy/f2py/tests/src/regression/mod_derived_types.f90 +23 -0
- numpy/f2py/tests/src/return_character/foo77.f +45 -0
- numpy/f2py/tests/src/return_character/foo90.f90 +48 -0
- numpy/f2py/tests/src/return_complex/foo77.f +45 -0
- numpy/f2py/tests/src/return_complex/foo90.f90 +48 -0
- numpy/f2py/tests/src/return_integer/foo77.f +56 -0
- numpy/f2py/tests/src/return_integer/foo90.f90 +59 -0
- numpy/f2py/tests/src/return_logical/foo77.f +56 -0
- numpy/f2py/tests/src/return_logical/foo90.f90 +59 -0
- numpy/f2py/tests/src/return_real/foo77.f +45 -0
- numpy/f2py/tests/src/return_real/foo90.f90 +48 -0
- numpy/f2py/tests/src/routines/funcfortranname.f +5 -0
- numpy/f2py/tests/src/routines/funcfortranname.pyf +11 -0
- numpy/f2py/tests/src/routines/subrout.f +4 -0
- numpy/f2py/tests/src/routines/subrout.pyf +10 -0
- numpy/f2py/tests/src/size/foo.f90 +44 -0
- numpy/f2py/tests/src/string/char.f90 +29 -0
- numpy/f2py/tests/src/string/fixed_string.f90 +34 -0
- numpy/f2py/tests/src/string/gh24008.f +8 -0
- numpy/f2py/tests/src/string/gh24662.f90 +7 -0
- numpy/f2py/tests/src/string/gh25286.f90 +14 -0
- numpy/f2py/tests/src/string/gh25286.pyf +12 -0
- numpy/f2py/tests/src/string/gh25286_bc.pyf +12 -0
- numpy/f2py/tests/src/string/scalar_string.f90 +9 -0
- numpy/f2py/tests/src/string/string.f +12 -0
- numpy/f2py/tests/src/value_attrspec/gh21665.f90 +9 -0
- numpy/f2py/tests/test_abstract_interface.py +26 -0
- numpy/f2py/tests/test_array_from_pyobj.py +678 -0
- numpy/f2py/tests/test_assumed_shape.py +50 -0
- numpy/f2py/tests/test_block_docstring.py +20 -0
- numpy/f2py/tests/test_callback.py +263 -0
- numpy/f2py/tests/test_character.py +641 -0
- numpy/f2py/tests/test_common.py +23 -0
- numpy/f2py/tests/test_crackfortran.py +421 -0
- numpy/f2py/tests/test_data.py +71 -0
- numpy/f2py/tests/test_docs.py +66 -0
- numpy/f2py/tests/test_f2cmap.py +17 -0
- numpy/f2py/tests/test_f2py2e.py +983 -0
- numpy/f2py/tests/test_isoc.py +56 -0
- numpy/f2py/tests/test_kind.py +52 -0
- numpy/f2py/tests/test_mixed.py +35 -0
- numpy/f2py/tests/test_modules.py +83 -0
- numpy/f2py/tests/test_parameter.py +129 -0
- numpy/f2py/tests/test_pyf_src.py +43 -0
- numpy/f2py/tests/test_quoted_character.py +18 -0
- numpy/f2py/tests/test_regression.py +187 -0
- numpy/f2py/tests/test_return_character.py +48 -0
- numpy/f2py/tests/test_return_complex.py +67 -0
- numpy/f2py/tests/test_return_integer.py +55 -0
- numpy/f2py/tests/test_return_logical.py +65 -0
- numpy/f2py/tests/test_return_real.py +109 -0
- numpy/f2py/tests/test_routines.py +29 -0
- numpy/f2py/tests/test_semicolon_split.py +75 -0
- numpy/f2py/tests/test_size.py +45 -0
- numpy/f2py/tests/test_string.py +100 -0
- numpy/f2py/tests/test_symbolic.py +500 -0
- numpy/f2py/tests/test_value_attrspec.py +15 -0
- numpy/f2py/tests/util.py +442 -0
- numpy/f2py/use_rules.py +99 -0
- numpy/f2py/use_rules.pyi +9 -0
- numpy/fft/__init__.py +213 -0
- numpy/fft/__init__.pyi +38 -0
- numpy/fft/_helper.py +235 -0
- numpy/fft/_helper.pyi +44 -0
- numpy/fft/_pocketfft.py +1693 -0
- numpy/fft/_pocketfft.pyi +137 -0
- numpy/fft/_pocketfft_umath.cp314t-win_arm64.lib +0 -0
- numpy/fft/_pocketfft_umath.cp314t-win_arm64.pyd +0 -0
- numpy/fft/tests/__init__.py +0 -0
- numpy/fft/tests/test_helper.py +167 -0
- numpy/fft/tests/test_pocketfft.py +589 -0
- numpy/lib/__init__.py +97 -0
- numpy/lib/__init__.pyi +52 -0
- numpy/lib/_array_utils_impl.py +62 -0
- numpy/lib/_array_utils_impl.pyi +10 -0
- numpy/lib/_arraypad_impl.py +926 -0
- numpy/lib/_arraypad_impl.pyi +88 -0
- numpy/lib/_arraysetops_impl.py +1158 -0
- numpy/lib/_arraysetops_impl.pyi +462 -0
- numpy/lib/_arrayterator_impl.py +224 -0
- numpy/lib/_arrayterator_impl.pyi +45 -0
- numpy/lib/_datasource.py +700 -0
- numpy/lib/_datasource.pyi +30 -0
- numpy/lib/_format_impl.py +1036 -0
- numpy/lib/_format_impl.pyi +56 -0
- numpy/lib/_function_base_impl.py +5760 -0
- numpy/lib/_function_base_impl.pyi +2324 -0
- numpy/lib/_histograms_impl.py +1085 -0
- numpy/lib/_histograms_impl.pyi +40 -0
- numpy/lib/_index_tricks_impl.py +1048 -0
- numpy/lib/_index_tricks_impl.pyi +267 -0
- numpy/lib/_iotools.py +900 -0
- numpy/lib/_iotools.pyi +116 -0
- numpy/lib/_nanfunctions_impl.py +2006 -0
- numpy/lib/_nanfunctions_impl.pyi +48 -0
- numpy/lib/_npyio_impl.py +2583 -0
- numpy/lib/_npyio_impl.pyi +299 -0
- numpy/lib/_polynomial_impl.py +1465 -0
- numpy/lib/_polynomial_impl.pyi +338 -0
- numpy/lib/_scimath_impl.py +642 -0
- numpy/lib/_scimath_impl.pyi +93 -0
- numpy/lib/_shape_base_impl.py +1289 -0
- numpy/lib/_shape_base_impl.pyi +236 -0
- numpy/lib/_stride_tricks_impl.py +582 -0
- numpy/lib/_stride_tricks_impl.pyi +73 -0
- numpy/lib/_twodim_base_impl.py +1201 -0
- numpy/lib/_twodim_base_impl.pyi +408 -0
- numpy/lib/_type_check_impl.py +710 -0
- numpy/lib/_type_check_impl.pyi +348 -0
- numpy/lib/_ufunclike_impl.py +199 -0
- numpy/lib/_ufunclike_impl.pyi +60 -0
- numpy/lib/_user_array_impl.py +310 -0
- numpy/lib/_user_array_impl.pyi +226 -0
- numpy/lib/_utils_impl.py +784 -0
- numpy/lib/_utils_impl.pyi +22 -0
- numpy/lib/_version.py +153 -0
- numpy/lib/_version.pyi +17 -0
- numpy/lib/array_utils.py +7 -0
- numpy/lib/array_utils.pyi +6 -0
- numpy/lib/format.py +24 -0
- numpy/lib/format.pyi +24 -0
- numpy/lib/introspect.py +94 -0
- numpy/lib/introspect.pyi +3 -0
- numpy/lib/mixins.py +180 -0
- numpy/lib/mixins.pyi +78 -0
- numpy/lib/npyio.py +1 -0
- numpy/lib/npyio.pyi +5 -0
- numpy/lib/recfunctions.py +1681 -0
- numpy/lib/recfunctions.pyi +444 -0
- numpy/lib/scimath.py +13 -0
- numpy/lib/scimath.pyi +12 -0
- numpy/lib/stride_tricks.py +1 -0
- numpy/lib/stride_tricks.pyi +4 -0
- numpy/lib/tests/__init__.py +0 -0
- numpy/lib/tests/data/py2-np0-objarr.npy +0 -0
- numpy/lib/tests/data/py2-objarr.npy +0 -0
- numpy/lib/tests/data/py2-objarr.npz +0 -0
- numpy/lib/tests/data/py3-objarr.npy +0 -0
- numpy/lib/tests/data/py3-objarr.npz +0 -0
- numpy/lib/tests/data/python3.npy +0 -0
- numpy/lib/tests/data/win64python2.npy +0 -0
- numpy/lib/tests/test__datasource.py +328 -0
- numpy/lib/tests/test__iotools.py +358 -0
- numpy/lib/tests/test__version.py +64 -0
- numpy/lib/tests/test_array_utils.py +32 -0
- numpy/lib/tests/test_arraypad.py +1427 -0
- numpy/lib/tests/test_arraysetops.py +1302 -0
- numpy/lib/tests/test_arrayterator.py +45 -0
- numpy/lib/tests/test_format.py +1054 -0
- numpy/lib/tests/test_function_base.py +4750 -0
- numpy/lib/tests/test_histograms.py +855 -0
- numpy/lib/tests/test_index_tricks.py +693 -0
- numpy/lib/tests/test_io.py +2857 -0
- numpy/lib/tests/test_loadtxt.py +1099 -0
- numpy/lib/tests/test_mixins.py +215 -0
- numpy/lib/tests/test_nanfunctions.py +1438 -0
- numpy/lib/tests/test_packbits.py +376 -0
- numpy/lib/tests/test_polynomial.py +325 -0
- numpy/lib/tests/test_recfunctions.py +1042 -0
- numpy/lib/tests/test_regression.py +231 -0
- numpy/lib/tests/test_shape_base.py +813 -0
- numpy/lib/tests/test_stride_tricks.py +655 -0
- numpy/lib/tests/test_twodim_base.py +559 -0
- numpy/lib/tests/test_type_check.py +473 -0
- numpy/lib/tests/test_ufunclike.py +97 -0
- numpy/lib/tests/test_utils.py +80 -0
- numpy/lib/user_array.py +1 -0
- numpy/lib/user_array.pyi +1 -0
- numpy/linalg/__init__.py +95 -0
- numpy/linalg/__init__.pyi +71 -0
- numpy/linalg/_linalg.py +3657 -0
- numpy/linalg/_linalg.pyi +548 -0
- numpy/linalg/_umath_linalg.cp314t-win_arm64.lib +0 -0
- numpy/linalg/_umath_linalg.cp314t-win_arm64.pyd +0 -0
- numpy/linalg/_umath_linalg.pyi +60 -0
- numpy/linalg/lapack_lite.cp314t-win_arm64.lib +0 -0
- numpy/linalg/lapack_lite.cp314t-win_arm64.pyd +0 -0
- numpy/linalg/lapack_lite.pyi +143 -0
- numpy/linalg/tests/__init__.py +0 -0
- numpy/linalg/tests/test_deprecations.py +21 -0
- numpy/linalg/tests/test_linalg.py +2442 -0
- numpy/linalg/tests/test_regression.py +182 -0
- numpy/ma/API_CHANGES.txt +135 -0
- numpy/ma/LICENSE +24 -0
- numpy/ma/README.rst +236 -0
- numpy/ma/__init__.py +53 -0
- numpy/ma/__init__.pyi +458 -0
- numpy/ma/core.py +8929 -0
- numpy/ma/core.pyi +3720 -0
- numpy/ma/extras.py +2266 -0
- numpy/ma/extras.pyi +297 -0
- numpy/ma/mrecords.py +762 -0
- numpy/ma/mrecords.pyi +96 -0
- numpy/ma/tests/__init__.py +0 -0
- numpy/ma/tests/test_arrayobject.py +40 -0
- numpy/ma/tests/test_core.py +6008 -0
- numpy/ma/tests/test_deprecations.py +65 -0
- numpy/ma/tests/test_extras.py +1945 -0
- numpy/ma/tests/test_mrecords.py +495 -0
- numpy/ma/tests/test_old_ma.py +939 -0
- numpy/ma/tests/test_regression.py +83 -0
- numpy/ma/tests/test_subclassing.py +469 -0
- numpy/ma/testutils.py +294 -0
- numpy/ma/testutils.pyi +69 -0
- numpy/matlib.py +380 -0
- numpy/matlib.pyi +580 -0
- numpy/matrixlib/__init__.py +12 -0
- numpy/matrixlib/__init__.pyi +3 -0
- numpy/matrixlib/defmatrix.py +1119 -0
- numpy/matrixlib/defmatrix.pyi +218 -0
- numpy/matrixlib/tests/__init__.py +0 -0
- numpy/matrixlib/tests/test_defmatrix.py +455 -0
- numpy/matrixlib/tests/test_interaction.py +360 -0
- numpy/matrixlib/tests/test_masked_matrix.py +240 -0
- numpy/matrixlib/tests/test_matrix_linalg.py +110 -0
- numpy/matrixlib/tests/test_multiarray.py +17 -0
- numpy/matrixlib/tests/test_numeric.py +18 -0
- numpy/matrixlib/tests/test_regression.py +31 -0
- numpy/polynomial/__init__.py +187 -0
- numpy/polynomial/__init__.pyi +31 -0
- numpy/polynomial/_polybase.py +1191 -0
- numpy/polynomial/_polybase.pyi +262 -0
- numpy/polynomial/_polytypes.pyi +501 -0
- numpy/polynomial/chebyshev.py +2001 -0
- numpy/polynomial/chebyshev.pyi +180 -0
- numpy/polynomial/hermite.py +1738 -0
- numpy/polynomial/hermite.pyi +106 -0
- numpy/polynomial/hermite_e.py +1640 -0
- numpy/polynomial/hermite_e.pyi +106 -0
- numpy/polynomial/laguerre.py +1673 -0
- numpy/polynomial/laguerre.pyi +100 -0
- numpy/polynomial/legendre.py +1603 -0
- numpy/polynomial/legendre.pyi +100 -0
- numpy/polynomial/polynomial.py +1625 -0
- numpy/polynomial/polynomial.pyi +109 -0
- numpy/polynomial/polyutils.py +759 -0
- numpy/polynomial/polyutils.pyi +307 -0
- numpy/polynomial/tests/__init__.py +0 -0
- numpy/polynomial/tests/test_chebyshev.py +618 -0
- numpy/polynomial/tests/test_classes.py +613 -0
- numpy/polynomial/tests/test_hermite.py +553 -0
- numpy/polynomial/tests/test_hermite_e.py +554 -0
- numpy/polynomial/tests/test_laguerre.py +535 -0
- numpy/polynomial/tests/test_legendre.py +566 -0
- numpy/polynomial/tests/test_polynomial.py +691 -0
- numpy/polynomial/tests/test_polyutils.py +123 -0
- numpy/polynomial/tests/test_printing.py +557 -0
- numpy/polynomial/tests/test_symbol.py +217 -0
- numpy/py.typed +0 -0
- numpy/random/LICENSE.md +71 -0
- numpy/random/__init__.pxd +14 -0
- numpy/random/__init__.py +213 -0
- numpy/random/__init__.pyi +124 -0
- numpy/random/_bounded_integers.cp314t-win_arm64.lib +0 -0
- numpy/random/_bounded_integers.cp314t-win_arm64.pyd +0 -0
- numpy/random/_bounded_integers.pxd +38 -0
- numpy/random/_bounded_integers.pyi +1 -0
- numpy/random/_common.cp314t-win_arm64.lib +0 -0
- numpy/random/_common.cp314t-win_arm64.pyd +0 -0
- numpy/random/_common.pxd +110 -0
- numpy/random/_common.pyi +16 -0
- numpy/random/_examples/cffi/extending.py +44 -0
- numpy/random/_examples/cffi/parse.py +53 -0
- numpy/random/_examples/cython/extending.pyx +77 -0
- numpy/random/_examples/cython/extending_distributions.pyx +117 -0
- numpy/random/_examples/cython/meson.build +53 -0
- numpy/random/_examples/numba/extending.py +86 -0
- numpy/random/_examples/numba/extending_distributions.py +67 -0
- numpy/random/_generator.cp314t-win_arm64.lib +0 -0
- numpy/random/_generator.cp314t-win_arm64.pyd +0 -0
- numpy/random/_generator.pyi +862 -0
- numpy/random/_mt19937.cp314t-win_arm64.lib +0 -0
- numpy/random/_mt19937.cp314t-win_arm64.pyd +0 -0
- numpy/random/_mt19937.pyi +27 -0
- numpy/random/_pcg64.cp314t-win_arm64.lib +0 -0
- numpy/random/_pcg64.cp314t-win_arm64.pyd +0 -0
- numpy/random/_pcg64.pyi +41 -0
- numpy/random/_philox.cp314t-win_arm64.lib +0 -0
- numpy/random/_philox.cp314t-win_arm64.pyd +0 -0
- numpy/random/_philox.pyi +36 -0
- numpy/random/_pickle.py +88 -0
- numpy/random/_pickle.pyi +43 -0
- numpy/random/_sfc64.cp314t-win_arm64.lib +0 -0
- numpy/random/_sfc64.cp314t-win_arm64.pyd +0 -0
- numpy/random/_sfc64.pyi +25 -0
- numpy/random/bit_generator.cp314t-win_arm64.lib +0 -0
- numpy/random/bit_generator.cp314t-win_arm64.pyd +0 -0
- numpy/random/bit_generator.pxd +40 -0
- numpy/random/bit_generator.pyi +123 -0
- numpy/random/c_distributions.pxd +119 -0
- numpy/random/lib/npyrandom.lib +0 -0
- numpy/random/mtrand.cp314t-win_arm64.lib +0 -0
- numpy/random/mtrand.cp314t-win_arm64.pyd +0 -0
- numpy/random/mtrand.pyi +759 -0
- numpy/random/tests/__init__.py +0 -0
- numpy/random/tests/data/__init__.py +0 -0
- numpy/random/tests/data/generator_pcg64_np121.pkl.gz +0 -0
- numpy/random/tests/data/generator_pcg64_np126.pkl.gz +0 -0
- numpy/random/tests/data/mt19937-testset-1.csv +1001 -0
- numpy/random/tests/data/mt19937-testset-2.csv +1001 -0
- numpy/random/tests/data/pcg64-testset-1.csv +1001 -0
- numpy/random/tests/data/pcg64-testset-2.csv +1001 -0
- numpy/random/tests/data/pcg64dxsm-testset-1.csv +1001 -0
- numpy/random/tests/data/pcg64dxsm-testset-2.csv +1001 -0
- numpy/random/tests/data/philox-testset-1.csv +1001 -0
- numpy/random/tests/data/philox-testset-2.csv +1001 -0
- numpy/random/tests/data/sfc64-testset-1.csv +1001 -0
- numpy/random/tests/data/sfc64-testset-2.csv +1001 -0
- numpy/random/tests/data/sfc64_np126.pkl.gz +0 -0
- numpy/random/tests/test_direct.py +595 -0
- numpy/random/tests/test_extending.py +131 -0
- numpy/random/tests/test_generator_mt19937.py +2825 -0
- numpy/random/tests/test_generator_mt19937_regressions.py +221 -0
- numpy/random/tests/test_random.py +1724 -0
- numpy/random/tests/test_randomstate.py +2099 -0
- numpy/random/tests/test_randomstate_regression.py +213 -0
- numpy/random/tests/test_regression.py +175 -0
- numpy/random/tests/test_seed_sequence.py +79 -0
- numpy/random/tests/test_smoke.py +882 -0
- numpy/rec/__init__.py +2 -0
- numpy/rec/__init__.pyi +23 -0
- numpy/strings/__init__.py +2 -0
- numpy/strings/__init__.pyi +97 -0
- numpy/testing/__init__.py +22 -0
- numpy/testing/__init__.pyi +107 -0
- numpy/testing/_private/__init__.py +0 -0
- numpy/testing/_private/__init__.pyi +0 -0
- numpy/testing/_private/extbuild.py +250 -0
- numpy/testing/_private/extbuild.pyi +25 -0
- numpy/testing/_private/utils.py +2830 -0
- numpy/testing/_private/utils.pyi +505 -0
- numpy/testing/overrides.py +84 -0
- numpy/testing/overrides.pyi +10 -0
- numpy/testing/print_coercion_tables.py +207 -0
- numpy/testing/print_coercion_tables.pyi +26 -0
- numpy/testing/tests/__init__.py +0 -0
- numpy/testing/tests/test_utils.py +2123 -0
- numpy/tests/__init__.py +0 -0
- numpy/tests/test__all__.py +10 -0
- numpy/tests/test_configtool.py +51 -0
- numpy/tests/test_ctypeslib.py +383 -0
- numpy/tests/test_lazyloading.py +42 -0
- numpy/tests/test_matlib.py +59 -0
- numpy/tests/test_numpy_config.py +47 -0
- numpy/tests/test_numpy_version.py +54 -0
- numpy/tests/test_public_api.py +807 -0
- numpy/tests/test_reloading.py +76 -0
- numpy/tests/test_scripts.py +48 -0
- numpy/tests/test_warnings.py +79 -0
- numpy/typing/__init__.py +233 -0
- numpy/typing/__init__.pyi +3 -0
- numpy/typing/mypy_plugin.py +200 -0
- numpy/typing/tests/__init__.py +0 -0
- numpy/typing/tests/data/fail/arithmetic.pyi +126 -0
- numpy/typing/tests/data/fail/array_constructors.pyi +34 -0
- numpy/typing/tests/data/fail/array_like.pyi +15 -0
- numpy/typing/tests/data/fail/array_pad.pyi +6 -0
- numpy/typing/tests/data/fail/arrayprint.pyi +15 -0
- numpy/typing/tests/data/fail/arrayterator.pyi +14 -0
- numpy/typing/tests/data/fail/bitwise_ops.pyi +17 -0
- numpy/typing/tests/data/fail/char.pyi +63 -0
- numpy/typing/tests/data/fail/chararray.pyi +61 -0
- numpy/typing/tests/data/fail/comparisons.pyi +27 -0
- numpy/typing/tests/data/fail/constants.pyi +3 -0
- numpy/typing/tests/data/fail/datasource.pyi +16 -0
- numpy/typing/tests/data/fail/dtype.pyi +17 -0
- numpy/typing/tests/data/fail/einsumfunc.pyi +12 -0
- numpy/typing/tests/data/fail/flatiter.pyi +38 -0
- numpy/typing/tests/data/fail/fromnumeric.pyi +148 -0
- numpy/typing/tests/data/fail/histograms.pyi +12 -0
- numpy/typing/tests/data/fail/index_tricks.pyi +14 -0
- numpy/typing/tests/data/fail/lib_function_base.pyi +60 -0
- numpy/typing/tests/data/fail/lib_polynomial.pyi +29 -0
- numpy/typing/tests/data/fail/lib_utils.pyi +3 -0
- numpy/typing/tests/data/fail/lib_version.pyi +6 -0
- numpy/typing/tests/data/fail/linalg.pyi +52 -0
- numpy/typing/tests/data/fail/ma.pyi +155 -0
- numpy/typing/tests/data/fail/memmap.pyi +5 -0
- numpy/typing/tests/data/fail/modules.pyi +17 -0
- numpy/typing/tests/data/fail/multiarray.pyi +52 -0
- numpy/typing/tests/data/fail/ndarray.pyi +11 -0
- numpy/typing/tests/data/fail/ndarray_misc.pyi +49 -0
- numpy/typing/tests/data/fail/nditer.pyi +8 -0
- numpy/typing/tests/data/fail/nested_sequence.pyi +17 -0
- numpy/typing/tests/data/fail/npyio.pyi +24 -0
- numpy/typing/tests/data/fail/numerictypes.pyi +5 -0
- numpy/typing/tests/data/fail/random.pyi +62 -0
- numpy/typing/tests/data/fail/rec.pyi +17 -0
- numpy/typing/tests/data/fail/scalars.pyi +86 -0
- numpy/typing/tests/data/fail/shape.pyi +7 -0
- numpy/typing/tests/data/fail/shape_base.pyi +8 -0
- numpy/typing/tests/data/fail/stride_tricks.pyi +9 -0
- numpy/typing/tests/data/fail/strings.pyi +52 -0
- numpy/typing/tests/data/fail/testing.pyi +28 -0
- numpy/typing/tests/data/fail/twodim_base.pyi +39 -0
- numpy/typing/tests/data/fail/type_check.pyi +12 -0
- numpy/typing/tests/data/fail/ufunc_config.pyi +21 -0
- numpy/typing/tests/data/fail/ufunclike.pyi +21 -0
- numpy/typing/tests/data/fail/ufuncs.pyi +17 -0
- numpy/typing/tests/data/fail/warnings_and_errors.pyi +5 -0
- numpy/typing/tests/data/misc/extended_precision.pyi +9 -0
- numpy/typing/tests/data/mypy.ini +8 -0
- numpy/typing/tests/data/pass/arithmetic.py +614 -0
- numpy/typing/tests/data/pass/array_constructors.py +138 -0
- numpy/typing/tests/data/pass/array_like.py +43 -0
- numpy/typing/tests/data/pass/arrayprint.py +37 -0
- numpy/typing/tests/data/pass/arrayterator.py +28 -0
- numpy/typing/tests/data/pass/bitwise_ops.py +131 -0
- numpy/typing/tests/data/pass/comparisons.py +316 -0
- numpy/typing/tests/data/pass/dtype.py +57 -0
- numpy/typing/tests/data/pass/einsumfunc.py +36 -0
- numpy/typing/tests/data/pass/flatiter.py +26 -0
- numpy/typing/tests/data/pass/fromnumeric.py +272 -0
- numpy/typing/tests/data/pass/index_tricks.py +62 -0
- numpy/typing/tests/data/pass/lib_user_array.py +22 -0
- numpy/typing/tests/data/pass/lib_utils.py +19 -0
- numpy/typing/tests/data/pass/lib_version.py +18 -0
- numpy/typing/tests/data/pass/literal.py +52 -0
- numpy/typing/tests/data/pass/ma.py +199 -0
- numpy/typing/tests/data/pass/mod.py +149 -0
- numpy/typing/tests/data/pass/modules.py +45 -0
- numpy/typing/tests/data/pass/multiarray.py +77 -0
- numpy/typing/tests/data/pass/ndarray_conversion.py +81 -0
- numpy/typing/tests/data/pass/ndarray_misc.py +199 -0
- numpy/typing/tests/data/pass/ndarray_shape_manipulation.py +47 -0
- numpy/typing/tests/data/pass/nditer.py +4 -0
- numpy/typing/tests/data/pass/numeric.py +90 -0
- numpy/typing/tests/data/pass/numerictypes.py +17 -0
- numpy/typing/tests/data/pass/random.py +1498 -0
- numpy/typing/tests/data/pass/recfunctions.py +164 -0
- numpy/typing/tests/data/pass/scalars.py +249 -0
- numpy/typing/tests/data/pass/shape.py +19 -0
- numpy/typing/tests/data/pass/simple.py +170 -0
- numpy/typing/tests/data/pass/ufunc_config.py +64 -0
- numpy/typing/tests/data/pass/ufunclike.py +52 -0
- numpy/typing/tests/data/pass/ufuncs.py +16 -0
- numpy/typing/tests/data/pass/warnings_and_errors.py +6 -0
- numpy/typing/tests/data/reveal/arithmetic.pyi +719 -0
- numpy/typing/tests/data/reveal/array_api_info.pyi +70 -0
- numpy/typing/tests/data/reveal/array_constructors.pyi +277 -0
- numpy/typing/tests/data/reveal/arraypad.pyi +27 -0
- numpy/typing/tests/data/reveal/arrayprint.pyi +25 -0
- numpy/typing/tests/data/reveal/arraysetops.pyi +74 -0
- numpy/typing/tests/data/reveal/arrayterator.pyi +27 -0
- numpy/typing/tests/data/reveal/bitwise_ops.pyi +166 -0
- numpy/typing/tests/data/reveal/char.pyi +225 -0
- numpy/typing/tests/data/reveal/chararray.pyi +138 -0
- numpy/typing/tests/data/reveal/comparisons.pyi +264 -0
- numpy/typing/tests/data/reveal/constants.pyi +14 -0
- numpy/typing/tests/data/reveal/ctypeslib.pyi +81 -0
- numpy/typing/tests/data/reveal/datasource.pyi +23 -0
- numpy/typing/tests/data/reveal/dtype.pyi +132 -0
- numpy/typing/tests/data/reveal/einsumfunc.pyi +39 -0
- numpy/typing/tests/data/reveal/emath.pyi +54 -0
- numpy/typing/tests/data/reveal/fft.pyi +37 -0
- numpy/typing/tests/data/reveal/flatiter.pyi +86 -0
- numpy/typing/tests/data/reveal/fromnumeric.pyi +347 -0
- numpy/typing/tests/data/reveal/getlimits.pyi +53 -0
- numpy/typing/tests/data/reveal/histograms.pyi +25 -0
- numpy/typing/tests/data/reveal/index_tricks.pyi +70 -0
- numpy/typing/tests/data/reveal/lib_function_base.pyi +409 -0
- numpy/typing/tests/data/reveal/lib_polynomial.pyi +147 -0
- numpy/typing/tests/data/reveal/lib_utils.pyi +17 -0
- numpy/typing/tests/data/reveal/lib_version.pyi +20 -0
- numpy/typing/tests/data/reveal/linalg.pyi +154 -0
- numpy/typing/tests/data/reveal/ma.pyi +1098 -0
- numpy/typing/tests/data/reveal/matrix.pyi +73 -0
- numpy/typing/tests/data/reveal/memmap.pyi +19 -0
- numpy/typing/tests/data/reveal/mod.pyi +178 -0
- numpy/typing/tests/data/reveal/modules.pyi +51 -0
- numpy/typing/tests/data/reveal/multiarray.pyi +197 -0
- numpy/typing/tests/data/reveal/nbit_base_example.pyi +20 -0
- numpy/typing/tests/data/reveal/ndarray_assignability.pyi +82 -0
- numpy/typing/tests/data/reveal/ndarray_conversion.pyi +83 -0
- numpy/typing/tests/data/reveal/ndarray_misc.pyi +246 -0
- numpy/typing/tests/data/reveal/ndarray_shape_manipulation.pyi +47 -0
- numpy/typing/tests/data/reveal/nditer.pyi +49 -0
- numpy/typing/tests/data/reveal/nested_sequence.pyi +25 -0
- numpy/typing/tests/data/reveal/npyio.pyi +83 -0
- numpy/typing/tests/data/reveal/numeric.pyi +170 -0
- numpy/typing/tests/data/reveal/numerictypes.pyi +16 -0
- numpy/typing/tests/data/reveal/polynomial_polybase.pyi +217 -0
- numpy/typing/tests/data/reveal/polynomial_polyutils.pyi +218 -0
- numpy/typing/tests/data/reveal/polynomial_series.pyi +138 -0
- numpy/typing/tests/data/reveal/random.pyi +1546 -0
- numpy/typing/tests/data/reveal/rec.pyi +171 -0
- numpy/typing/tests/data/reveal/scalars.pyi +191 -0
- numpy/typing/tests/data/reveal/shape.pyi +13 -0
- numpy/typing/tests/data/reveal/shape_base.pyi +52 -0
- numpy/typing/tests/data/reveal/stride_tricks.pyi +27 -0
- numpy/typing/tests/data/reveal/strings.pyi +196 -0
- numpy/typing/tests/data/reveal/testing.pyi +198 -0
- numpy/typing/tests/data/reveal/twodim_base.pyi +225 -0
- numpy/typing/tests/data/reveal/type_check.pyi +67 -0
- numpy/typing/tests/data/reveal/ufunc_config.pyi +29 -0
- numpy/typing/tests/data/reveal/ufunclike.pyi +31 -0
- numpy/typing/tests/data/reveal/ufuncs.pyi +142 -0
- numpy/typing/tests/data/reveal/warnings_and_errors.pyi +11 -0
- numpy/typing/tests/test_isfile.py +38 -0
- numpy/typing/tests/test_runtime.py +110 -0
- numpy/typing/tests/test_typing.py +205 -0
- numpy/version.py +11 -0
- numpy/version.pyi +9 -0
- numpy-2.4.1.dist-info/DELVEWHEEL +2 -0
- numpy-2.4.1.dist-info/METADATA +139 -0
- numpy-2.4.1.dist-info/RECORD +932 -0
- numpy-2.4.1.dist-info/WHEEL +4 -0
- numpy-2.4.1.dist-info/entry_points.txt +13 -0
- numpy-2.4.1.dist-info/licenses/LICENSE.txt +914 -0
- numpy-2.4.1.dist-info/licenses/numpy/_core/include/numpy/libdivide/LICENSE.txt +21 -0
- numpy-2.4.1.dist-info/licenses/numpy/_core/src/common/pythoncapi-compat/COPYING +14 -0
- numpy-2.4.1.dist-info/licenses/numpy/_core/src/highway/LICENSE +371 -0
- numpy-2.4.1.dist-info/licenses/numpy/_core/src/multiarray/dragon4_LICENSE.txt +27 -0
- numpy-2.4.1.dist-info/licenses/numpy/_core/src/npysort/x86-simd-sort/LICENSE.md +28 -0
- numpy-2.4.1.dist-info/licenses/numpy/_core/src/umath/svml/LICENSE +30 -0
- numpy-2.4.1.dist-info/licenses/numpy/fft/pocketfft/LICENSE.md +25 -0
- numpy-2.4.1.dist-info/licenses/numpy/linalg/lapack_lite/LICENSE.txt +48 -0
- numpy-2.4.1.dist-info/licenses/numpy/ma/LICENSE +24 -0
- numpy-2.4.1.dist-info/licenses/numpy/random/LICENSE.md +71 -0
- numpy-2.4.1.dist-info/licenses/numpy/random/src/distributions/LICENSE.md +61 -0
- numpy-2.4.1.dist-info/licenses/numpy/random/src/mt19937/LICENSE.md +61 -0
- numpy-2.4.1.dist-info/licenses/numpy/random/src/pcg64/LICENSE.md +22 -0
- numpy-2.4.1.dist-info/licenses/numpy/random/src/philox/LICENSE.md +31 -0
- numpy-2.4.1.dist-info/licenses/numpy/random/src/sfc64/LICENSE.md +27 -0
- numpy-2.4.1.dist-info/licenses/numpy/random/src/splitmix64/LICENSE.md +9 -0
- numpy.libs/msvcp140-5f1c5dd31916990d94181e07bc3afb32.dll +0 -0
- numpy.libs/scipy_openblas-7b69cbfd2599e6035f1310f2a72d59a6.dll +0 -0
|
@@ -0,0 +1,2001 @@
|
|
|
1
|
+
"""
|
|
2
|
+
====================================================
|
|
3
|
+
Chebyshev Series (:mod:`numpy.polynomial.chebyshev`)
|
|
4
|
+
====================================================
|
|
5
|
+
|
|
6
|
+
This module provides a number of objects (mostly functions) useful for
|
|
7
|
+
dealing with Chebyshev series, including a `Chebyshev` class that
|
|
8
|
+
encapsulates the usual arithmetic operations. (General information
|
|
9
|
+
on how this module represents and works with such polynomials is in the
|
|
10
|
+
docstring for its "parent" sub-package, `numpy.polynomial`).
|
|
11
|
+
|
|
12
|
+
Classes
|
|
13
|
+
-------
|
|
14
|
+
|
|
15
|
+
.. autosummary::
|
|
16
|
+
:toctree: generated/
|
|
17
|
+
|
|
18
|
+
Chebyshev
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
Constants
|
|
22
|
+
---------
|
|
23
|
+
|
|
24
|
+
.. autosummary::
|
|
25
|
+
:toctree: generated/
|
|
26
|
+
|
|
27
|
+
chebdomain
|
|
28
|
+
chebzero
|
|
29
|
+
chebone
|
|
30
|
+
chebx
|
|
31
|
+
|
|
32
|
+
Arithmetic
|
|
33
|
+
----------
|
|
34
|
+
|
|
35
|
+
.. autosummary::
|
|
36
|
+
:toctree: generated/
|
|
37
|
+
|
|
38
|
+
chebadd
|
|
39
|
+
chebsub
|
|
40
|
+
chebmulx
|
|
41
|
+
chebmul
|
|
42
|
+
chebdiv
|
|
43
|
+
chebpow
|
|
44
|
+
chebval
|
|
45
|
+
chebval2d
|
|
46
|
+
chebval3d
|
|
47
|
+
chebgrid2d
|
|
48
|
+
chebgrid3d
|
|
49
|
+
|
|
50
|
+
Calculus
|
|
51
|
+
--------
|
|
52
|
+
|
|
53
|
+
.. autosummary::
|
|
54
|
+
:toctree: generated/
|
|
55
|
+
|
|
56
|
+
chebder
|
|
57
|
+
chebint
|
|
58
|
+
|
|
59
|
+
Misc Functions
|
|
60
|
+
--------------
|
|
61
|
+
|
|
62
|
+
.. autosummary::
|
|
63
|
+
:toctree: generated/
|
|
64
|
+
|
|
65
|
+
chebfromroots
|
|
66
|
+
chebroots
|
|
67
|
+
chebvander
|
|
68
|
+
chebvander2d
|
|
69
|
+
chebvander3d
|
|
70
|
+
chebgauss
|
|
71
|
+
chebweight
|
|
72
|
+
chebcompanion
|
|
73
|
+
chebfit
|
|
74
|
+
chebpts1
|
|
75
|
+
chebpts2
|
|
76
|
+
chebtrim
|
|
77
|
+
chebline
|
|
78
|
+
cheb2poly
|
|
79
|
+
poly2cheb
|
|
80
|
+
chebinterpolate
|
|
81
|
+
|
|
82
|
+
See also
|
|
83
|
+
--------
|
|
84
|
+
`numpy.polynomial`
|
|
85
|
+
|
|
86
|
+
Notes
|
|
87
|
+
-----
|
|
88
|
+
The implementations of multiplication, division, integration, and
|
|
89
|
+
differentiation use the algebraic identities [1]_:
|
|
90
|
+
|
|
91
|
+
.. math::
|
|
92
|
+
T_n(x) = \\frac{z^n + z^{-n}}{2} \\\\
|
|
93
|
+
z\\frac{dx}{dz} = \\frac{z - z^{-1}}{2}.
|
|
94
|
+
|
|
95
|
+
where
|
|
96
|
+
|
|
97
|
+
.. math:: x = \\frac{z + z^{-1}}{2}.
|
|
98
|
+
|
|
99
|
+
These identities allow a Chebyshev series to be expressed as a finite,
|
|
100
|
+
symmetric Laurent series. In this module, this sort of Laurent series
|
|
101
|
+
is referred to as a "z-series."
|
|
102
|
+
|
|
103
|
+
References
|
|
104
|
+
----------
|
|
105
|
+
.. [1] A. T. Benjamin, et al., "Combinatorial Trigonometry with Chebyshev
|
|
106
|
+
Polynomials," *Journal of Statistical Planning and Inference 14*, 2008
|
|
107
|
+
(https://web.archive.org/web/20080221202153/https://www.math.hmc.edu/~benjamin/papers/CombTrig.pdf, pg. 4)
|
|
108
|
+
|
|
109
|
+
""" # noqa: E501
|
|
110
|
+
import numpy as np
|
|
111
|
+
|
|
112
|
+
from . import polyutils as pu
|
|
113
|
+
from ._polybase import ABCPolyBase
|
|
114
|
+
|
|
115
|
+
__all__ = [
|
|
116
|
+
'chebzero', 'chebone', 'chebx', 'chebdomain', 'chebline', 'chebadd',
|
|
117
|
+
'chebsub', 'chebmulx', 'chebmul', 'chebdiv', 'chebpow', 'chebval',
|
|
118
|
+
'chebder', 'chebint', 'cheb2poly', 'poly2cheb', 'chebfromroots',
|
|
119
|
+
'chebvander', 'chebfit', 'chebtrim', 'chebroots', 'chebpts1',
|
|
120
|
+
'chebpts2', 'Chebyshev', 'chebval2d', 'chebval3d', 'chebgrid2d',
|
|
121
|
+
'chebgrid3d', 'chebvander2d', 'chebvander3d', 'chebcompanion',
|
|
122
|
+
'chebgauss', 'chebweight', 'chebinterpolate']
|
|
123
|
+
|
|
124
|
+
chebtrim = pu.trimcoef
|
|
125
|
+
|
|
126
|
+
#
|
|
127
|
+
# A collection of functions for manipulating z-series. These are private
|
|
128
|
+
# functions and do minimal error checking.
|
|
129
|
+
#
|
|
130
|
+
|
|
131
|
+
def _cseries_to_zseries(c):
|
|
132
|
+
"""Convert Chebyshev series to z-series.
|
|
133
|
+
|
|
134
|
+
Convert a Chebyshev series to the equivalent z-series. The result is
|
|
135
|
+
never an empty array. The dtype of the return is the same as that of
|
|
136
|
+
the input. No checks are run on the arguments as this routine is for
|
|
137
|
+
internal use.
|
|
138
|
+
|
|
139
|
+
Parameters
|
|
140
|
+
----------
|
|
141
|
+
c : 1-D ndarray
|
|
142
|
+
Chebyshev coefficients, ordered from low to high
|
|
143
|
+
|
|
144
|
+
Returns
|
|
145
|
+
-------
|
|
146
|
+
zs : 1-D ndarray
|
|
147
|
+
Odd length symmetric z-series, ordered from low to high.
|
|
148
|
+
|
|
149
|
+
"""
|
|
150
|
+
n = c.size
|
|
151
|
+
zs = np.zeros(2 * n - 1, dtype=c.dtype)
|
|
152
|
+
zs[n - 1:] = c / 2
|
|
153
|
+
return zs + zs[::-1]
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def _zseries_to_cseries(zs):
|
|
157
|
+
"""Convert z-series to a Chebyshev series.
|
|
158
|
+
|
|
159
|
+
Convert a z series to the equivalent Chebyshev series. The result is
|
|
160
|
+
never an empty array. The dtype of the return is the same as that of
|
|
161
|
+
the input. No checks are run on the arguments as this routine is for
|
|
162
|
+
internal use.
|
|
163
|
+
|
|
164
|
+
Parameters
|
|
165
|
+
----------
|
|
166
|
+
zs : 1-D ndarray
|
|
167
|
+
Odd length symmetric z-series, ordered from low to high.
|
|
168
|
+
|
|
169
|
+
Returns
|
|
170
|
+
-------
|
|
171
|
+
c : 1-D ndarray
|
|
172
|
+
Chebyshev coefficients, ordered from low to high.
|
|
173
|
+
|
|
174
|
+
"""
|
|
175
|
+
n = (zs.size + 1) // 2
|
|
176
|
+
c = zs[n - 1:].copy()
|
|
177
|
+
c[1:n] *= 2
|
|
178
|
+
return c
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def _zseries_mul(z1, z2):
|
|
182
|
+
"""Multiply two z-series.
|
|
183
|
+
|
|
184
|
+
Multiply two z-series to produce a z-series.
|
|
185
|
+
|
|
186
|
+
Parameters
|
|
187
|
+
----------
|
|
188
|
+
z1, z2 : 1-D ndarray
|
|
189
|
+
The arrays must be 1-D but this is not checked.
|
|
190
|
+
|
|
191
|
+
Returns
|
|
192
|
+
-------
|
|
193
|
+
product : 1-D ndarray
|
|
194
|
+
The product z-series.
|
|
195
|
+
|
|
196
|
+
Notes
|
|
197
|
+
-----
|
|
198
|
+
This is simply convolution. If symmetric/anti-symmetric z-series are
|
|
199
|
+
denoted by S/A then the following rules apply:
|
|
200
|
+
|
|
201
|
+
S*S, A*A -> S
|
|
202
|
+
S*A, A*S -> A
|
|
203
|
+
|
|
204
|
+
"""
|
|
205
|
+
return np.convolve(z1, z2)
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
def _zseries_div(z1, z2):
|
|
209
|
+
"""Divide the first z-series by the second.
|
|
210
|
+
|
|
211
|
+
Divide `z1` by `z2` and return the quotient and remainder as z-series.
|
|
212
|
+
Warning: this implementation only applies when both z1 and z2 have the
|
|
213
|
+
same symmetry, which is sufficient for present purposes.
|
|
214
|
+
|
|
215
|
+
Parameters
|
|
216
|
+
----------
|
|
217
|
+
z1, z2 : 1-D ndarray
|
|
218
|
+
The arrays must be 1-D and have the same symmetry, but this is not
|
|
219
|
+
checked.
|
|
220
|
+
|
|
221
|
+
Returns
|
|
222
|
+
-------
|
|
223
|
+
|
|
224
|
+
(quotient, remainder) : 1-D ndarrays
|
|
225
|
+
Quotient and remainder as z-series.
|
|
226
|
+
|
|
227
|
+
Notes
|
|
228
|
+
-----
|
|
229
|
+
This is not the same as polynomial division on account of the desired form
|
|
230
|
+
of the remainder. If symmetric/anti-symmetric z-series are denoted by S/A
|
|
231
|
+
then the following rules apply:
|
|
232
|
+
|
|
233
|
+
S/S -> S,S
|
|
234
|
+
A/A -> S,A
|
|
235
|
+
|
|
236
|
+
The restriction to types of the same symmetry could be fixed but seems like
|
|
237
|
+
unneeded generality. There is no natural form for the remainder in the case
|
|
238
|
+
where there is no symmetry.
|
|
239
|
+
|
|
240
|
+
"""
|
|
241
|
+
z1 = z1.copy()
|
|
242
|
+
z2 = z2.copy()
|
|
243
|
+
lc1 = len(z1)
|
|
244
|
+
lc2 = len(z2)
|
|
245
|
+
if lc2 == 1:
|
|
246
|
+
z1 /= z2
|
|
247
|
+
return z1, z1[:1] * 0
|
|
248
|
+
elif lc1 < lc2:
|
|
249
|
+
return z1[:1] * 0, z1
|
|
250
|
+
else:
|
|
251
|
+
dlen = lc1 - lc2
|
|
252
|
+
scl = z2[0]
|
|
253
|
+
z2 /= scl
|
|
254
|
+
quo = np.empty(dlen + 1, dtype=z1.dtype)
|
|
255
|
+
i = 0
|
|
256
|
+
j = dlen
|
|
257
|
+
while i < j:
|
|
258
|
+
r = z1[i]
|
|
259
|
+
quo[i] = z1[i]
|
|
260
|
+
quo[dlen - i] = r
|
|
261
|
+
tmp = r * z2
|
|
262
|
+
z1[i:i + lc2] -= tmp
|
|
263
|
+
z1[j:j + lc2] -= tmp
|
|
264
|
+
i += 1
|
|
265
|
+
j -= 1
|
|
266
|
+
r = z1[i]
|
|
267
|
+
quo[i] = r
|
|
268
|
+
tmp = r * z2
|
|
269
|
+
z1[i:i + lc2] -= tmp
|
|
270
|
+
quo /= scl
|
|
271
|
+
rem = z1[i + 1:i - 1 + lc2].copy()
|
|
272
|
+
return quo, rem
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
def _zseries_der(zs):
|
|
276
|
+
"""Differentiate a z-series.
|
|
277
|
+
|
|
278
|
+
The derivative is with respect to x, not z. This is achieved using the
|
|
279
|
+
chain rule and the value of dx/dz given in the module notes.
|
|
280
|
+
|
|
281
|
+
Parameters
|
|
282
|
+
----------
|
|
283
|
+
zs : z-series
|
|
284
|
+
The z-series to differentiate.
|
|
285
|
+
|
|
286
|
+
Returns
|
|
287
|
+
-------
|
|
288
|
+
derivative : z-series
|
|
289
|
+
The derivative
|
|
290
|
+
|
|
291
|
+
Notes
|
|
292
|
+
-----
|
|
293
|
+
The zseries for x (ns) has been multiplied by two in order to avoid
|
|
294
|
+
using floats that are incompatible with Decimal and likely other
|
|
295
|
+
specialized scalar types. This scaling has been compensated by
|
|
296
|
+
multiplying the value of zs by two also so that the two cancels in the
|
|
297
|
+
division.
|
|
298
|
+
|
|
299
|
+
"""
|
|
300
|
+
n = len(zs) // 2
|
|
301
|
+
ns = np.array([-1, 0, 1], dtype=zs.dtype)
|
|
302
|
+
zs *= np.arange(-n, n + 1) * 2
|
|
303
|
+
d, r = _zseries_div(zs, ns)
|
|
304
|
+
return d
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
def _zseries_int(zs):
|
|
308
|
+
"""Integrate a z-series.
|
|
309
|
+
|
|
310
|
+
The integral is with respect to x, not z. This is achieved by a change
|
|
311
|
+
of variable using dx/dz given in the module notes.
|
|
312
|
+
|
|
313
|
+
Parameters
|
|
314
|
+
----------
|
|
315
|
+
zs : z-series
|
|
316
|
+
The z-series to integrate
|
|
317
|
+
|
|
318
|
+
Returns
|
|
319
|
+
-------
|
|
320
|
+
integral : z-series
|
|
321
|
+
The indefinite integral
|
|
322
|
+
|
|
323
|
+
Notes
|
|
324
|
+
-----
|
|
325
|
+
The zseries for x (ns) has been multiplied by two in order to avoid
|
|
326
|
+
using floats that are incompatible with Decimal and likely other
|
|
327
|
+
specialized scalar types. This scaling has been compensated by
|
|
328
|
+
dividing the resulting zs by two.
|
|
329
|
+
|
|
330
|
+
"""
|
|
331
|
+
n = 1 + len(zs) // 2
|
|
332
|
+
ns = np.array([-1, 0, 1], dtype=zs.dtype)
|
|
333
|
+
zs = _zseries_mul(zs, ns)
|
|
334
|
+
div = np.arange(-n, n + 1) * 2
|
|
335
|
+
zs[:n] /= div[:n]
|
|
336
|
+
zs[n + 1:] /= div[n + 1:]
|
|
337
|
+
zs[n] = 0
|
|
338
|
+
return zs
|
|
339
|
+
|
|
340
|
+
#
|
|
341
|
+
# Chebyshev series functions
|
|
342
|
+
#
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
def poly2cheb(pol):
|
|
346
|
+
"""
|
|
347
|
+
Convert a polynomial to a Chebyshev series.
|
|
348
|
+
|
|
349
|
+
Convert an array representing the coefficients of a polynomial (relative
|
|
350
|
+
to the "standard" basis) ordered from lowest degree to highest, to an
|
|
351
|
+
array of the coefficients of the equivalent Chebyshev series, ordered
|
|
352
|
+
from lowest to highest degree.
|
|
353
|
+
|
|
354
|
+
Parameters
|
|
355
|
+
----------
|
|
356
|
+
pol : array_like
|
|
357
|
+
1-D array containing the polynomial coefficients
|
|
358
|
+
|
|
359
|
+
Returns
|
|
360
|
+
-------
|
|
361
|
+
c : ndarray
|
|
362
|
+
1-D array containing the coefficients of the equivalent Chebyshev
|
|
363
|
+
series.
|
|
364
|
+
|
|
365
|
+
See Also
|
|
366
|
+
--------
|
|
367
|
+
cheb2poly
|
|
368
|
+
|
|
369
|
+
Notes
|
|
370
|
+
-----
|
|
371
|
+
The easy way to do conversions between polynomial basis sets
|
|
372
|
+
is to use the convert method of a class instance.
|
|
373
|
+
|
|
374
|
+
Examples
|
|
375
|
+
--------
|
|
376
|
+
>>> from numpy import polynomial as P
|
|
377
|
+
>>> p = P.Polynomial(range(4))
|
|
378
|
+
>>> p
|
|
379
|
+
Polynomial([0., 1., 2., 3.], domain=[-1., 1.], window=[-1., 1.], symbol='x')
|
|
380
|
+
>>> c = p.convert(kind=P.Chebyshev)
|
|
381
|
+
>>> c
|
|
382
|
+
Chebyshev([1. , 3.25, 1. , 0.75], domain=[-1., 1.], window=[-1., ...
|
|
383
|
+
>>> P.chebyshev.poly2cheb(range(4))
|
|
384
|
+
array([1. , 3.25, 1. , 0.75])
|
|
385
|
+
|
|
386
|
+
"""
|
|
387
|
+
[pol] = pu.as_series([pol])
|
|
388
|
+
deg = len(pol) - 1
|
|
389
|
+
res = 0
|
|
390
|
+
for i in range(deg, -1, -1):
|
|
391
|
+
res = chebadd(chebmulx(res), pol[i])
|
|
392
|
+
return res
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+
def cheb2poly(c):
|
|
396
|
+
"""
|
|
397
|
+
Convert a Chebyshev series to a polynomial.
|
|
398
|
+
|
|
399
|
+
Convert an array representing the coefficients of a Chebyshev series,
|
|
400
|
+
ordered from lowest degree to highest, to an array of the coefficients
|
|
401
|
+
of the equivalent polynomial (relative to the "standard" basis) ordered
|
|
402
|
+
from lowest to highest degree.
|
|
403
|
+
|
|
404
|
+
Parameters
|
|
405
|
+
----------
|
|
406
|
+
c : array_like
|
|
407
|
+
1-D array containing the Chebyshev series coefficients, ordered
|
|
408
|
+
from lowest order term to highest.
|
|
409
|
+
|
|
410
|
+
Returns
|
|
411
|
+
-------
|
|
412
|
+
pol : ndarray
|
|
413
|
+
1-D array containing the coefficients of the equivalent polynomial
|
|
414
|
+
(relative to the "standard" basis) ordered from lowest order term
|
|
415
|
+
to highest.
|
|
416
|
+
|
|
417
|
+
See Also
|
|
418
|
+
--------
|
|
419
|
+
poly2cheb
|
|
420
|
+
|
|
421
|
+
Notes
|
|
422
|
+
-----
|
|
423
|
+
The easy way to do conversions between polynomial basis sets
|
|
424
|
+
is to use the convert method of a class instance.
|
|
425
|
+
|
|
426
|
+
Examples
|
|
427
|
+
--------
|
|
428
|
+
>>> from numpy import polynomial as P
|
|
429
|
+
>>> c = P.Chebyshev(range(4))
|
|
430
|
+
>>> c
|
|
431
|
+
Chebyshev([0., 1., 2., 3.], domain=[-1., 1.], window=[-1., 1.], symbol='x')
|
|
432
|
+
>>> p = c.convert(kind=P.Polynomial)
|
|
433
|
+
>>> p
|
|
434
|
+
Polynomial([-2., -8., 4., 12.], domain=[-1., 1.], window=[-1., 1.], ...
|
|
435
|
+
>>> P.chebyshev.cheb2poly(range(4))
|
|
436
|
+
array([-2., -8., 4., 12.])
|
|
437
|
+
|
|
438
|
+
"""
|
|
439
|
+
from .polynomial import polyadd, polymulx, polysub
|
|
440
|
+
|
|
441
|
+
[c] = pu.as_series([c])
|
|
442
|
+
n = len(c)
|
|
443
|
+
if n < 3:
|
|
444
|
+
return c
|
|
445
|
+
else:
|
|
446
|
+
c0 = c[-2]
|
|
447
|
+
c1 = c[-1]
|
|
448
|
+
# i is the current degree of c1
|
|
449
|
+
for i in range(n - 1, 1, -1):
|
|
450
|
+
tmp = c0
|
|
451
|
+
c0 = polysub(c[i - 2], c1)
|
|
452
|
+
c1 = polyadd(tmp, polymulx(c1) * 2)
|
|
453
|
+
return polyadd(c0, polymulx(c1))
|
|
454
|
+
|
|
455
|
+
|
|
456
|
+
#
|
|
457
|
+
# These are constant arrays are of integer type so as to be compatible
|
|
458
|
+
# with the widest range of other types, such as Decimal.
|
|
459
|
+
#
|
|
460
|
+
|
|
461
|
+
# Chebyshev default domain.
|
|
462
|
+
chebdomain = np.array([-1., 1.])
|
|
463
|
+
|
|
464
|
+
# Chebyshev coefficients representing zero.
|
|
465
|
+
chebzero = np.array([0])
|
|
466
|
+
|
|
467
|
+
# Chebyshev coefficients representing one.
|
|
468
|
+
chebone = np.array([1])
|
|
469
|
+
|
|
470
|
+
# Chebyshev coefficients representing the identity x.
|
|
471
|
+
chebx = np.array([0, 1])
|
|
472
|
+
|
|
473
|
+
|
|
474
|
+
def chebline(off, scl):
|
|
475
|
+
"""
|
|
476
|
+
Chebyshev series whose graph is a straight line.
|
|
477
|
+
|
|
478
|
+
Parameters
|
|
479
|
+
----------
|
|
480
|
+
off, scl : scalars
|
|
481
|
+
The specified line is given by ``off + scl*x``.
|
|
482
|
+
|
|
483
|
+
Returns
|
|
484
|
+
-------
|
|
485
|
+
y : ndarray
|
|
486
|
+
This module's representation of the Chebyshev series for
|
|
487
|
+
``off + scl*x``.
|
|
488
|
+
|
|
489
|
+
See Also
|
|
490
|
+
--------
|
|
491
|
+
numpy.polynomial.polynomial.polyline
|
|
492
|
+
numpy.polynomial.legendre.legline
|
|
493
|
+
numpy.polynomial.laguerre.lagline
|
|
494
|
+
numpy.polynomial.hermite.hermline
|
|
495
|
+
numpy.polynomial.hermite_e.hermeline
|
|
496
|
+
|
|
497
|
+
Examples
|
|
498
|
+
--------
|
|
499
|
+
>>> import numpy.polynomial.chebyshev as C
|
|
500
|
+
>>> C.chebline(3,2)
|
|
501
|
+
array([3, 2])
|
|
502
|
+
>>> C.chebval(-3, C.chebline(3,2)) # should be -3
|
|
503
|
+
-3.0
|
|
504
|
+
|
|
505
|
+
"""
|
|
506
|
+
if scl != 0:
|
|
507
|
+
return np.array([off, scl])
|
|
508
|
+
else:
|
|
509
|
+
return np.array([off])
|
|
510
|
+
|
|
511
|
+
|
|
512
|
+
def chebfromroots(roots):
|
|
513
|
+
"""
|
|
514
|
+
Generate a Chebyshev series with given roots.
|
|
515
|
+
|
|
516
|
+
The function returns the coefficients of the polynomial
|
|
517
|
+
|
|
518
|
+
.. math:: p(x) = (x - r_0) * (x - r_1) * ... * (x - r_n),
|
|
519
|
+
|
|
520
|
+
in Chebyshev form, where the :math:`r_n` are the roots specified in
|
|
521
|
+
`roots`. If a zero has multiplicity n, then it must appear in `roots`
|
|
522
|
+
n times. For instance, if 2 is a root of multiplicity three and 3 is a
|
|
523
|
+
root of multiplicity 2, then `roots` looks something like [2, 2, 2, 3, 3].
|
|
524
|
+
The roots can appear in any order.
|
|
525
|
+
|
|
526
|
+
If the returned coefficients are `c`, then
|
|
527
|
+
|
|
528
|
+
.. math:: p(x) = c_0 + c_1 * T_1(x) + ... + c_n * T_n(x)
|
|
529
|
+
|
|
530
|
+
The coefficient of the last term is not generally 1 for monic
|
|
531
|
+
polynomials in Chebyshev form.
|
|
532
|
+
|
|
533
|
+
Parameters
|
|
534
|
+
----------
|
|
535
|
+
roots : array_like
|
|
536
|
+
Sequence containing the roots.
|
|
537
|
+
|
|
538
|
+
Returns
|
|
539
|
+
-------
|
|
540
|
+
out : ndarray
|
|
541
|
+
1-D array of coefficients. If all roots are real then `out` is a
|
|
542
|
+
real array, if some of the roots are complex, then `out` is complex
|
|
543
|
+
even if all the coefficients in the result are real (see Examples
|
|
544
|
+
below).
|
|
545
|
+
|
|
546
|
+
See Also
|
|
547
|
+
--------
|
|
548
|
+
numpy.polynomial.polynomial.polyfromroots
|
|
549
|
+
numpy.polynomial.legendre.legfromroots
|
|
550
|
+
numpy.polynomial.laguerre.lagfromroots
|
|
551
|
+
numpy.polynomial.hermite.hermfromroots
|
|
552
|
+
numpy.polynomial.hermite_e.hermefromroots
|
|
553
|
+
|
|
554
|
+
Examples
|
|
555
|
+
--------
|
|
556
|
+
>>> import numpy.polynomial.chebyshev as C
|
|
557
|
+
>>> C.chebfromroots((-1,0,1)) # x^3 - x relative to the standard basis
|
|
558
|
+
array([ 0. , -0.25, 0. , 0.25])
|
|
559
|
+
>>> j = complex(0,1)
|
|
560
|
+
>>> C.chebfromroots((-j,j)) # x^2 + 1 relative to the standard basis
|
|
561
|
+
array([1.5+0.j, 0. +0.j, 0.5+0.j])
|
|
562
|
+
|
|
563
|
+
"""
|
|
564
|
+
return pu._fromroots(chebline, chebmul, roots)
|
|
565
|
+
|
|
566
|
+
|
|
567
|
+
def chebadd(c1, c2):
|
|
568
|
+
"""
|
|
569
|
+
Add one Chebyshev series to another.
|
|
570
|
+
|
|
571
|
+
Returns the sum of two Chebyshev series `c1` + `c2`. The arguments
|
|
572
|
+
are sequences of coefficients ordered from lowest order term to
|
|
573
|
+
highest, i.e., [1,2,3] represents the series ``T_0 + 2*T_1 + 3*T_2``.
|
|
574
|
+
|
|
575
|
+
Parameters
|
|
576
|
+
----------
|
|
577
|
+
c1, c2 : array_like
|
|
578
|
+
1-D arrays of Chebyshev series coefficients ordered from low to
|
|
579
|
+
high.
|
|
580
|
+
|
|
581
|
+
Returns
|
|
582
|
+
-------
|
|
583
|
+
out : ndarray
|
|
584
|
+
Array representing the Chebyshev series of their sum.
|
|
585
|
+
|
|
586
|
+
See Also
|
|
587
|
+
--------
|
|
588
|
+
chebsub, chebmulx, chebmul, chebdiv, chebpow
|
|
589
|
+
|
|
590
|
+
Notes
|
|
591
|
+
-----
|
|
592
|
+
Unlike multiplication, division, etc., the sum of two Chebyshev series
|
|
593
|
+
is a Chebyshev series (without having to "reproject" the result onto
|
|
594
|
+
the basis set) so addition, just like that of "standard" polynomials,
|
|
595
|
+
is simply "component-wise."
|
|
596
|
+
|
|
597
|
+
Examples
|
|
598
|
+
--------
|
|
599
|
+
>>> from numpy.polynomial import chebyshev as C
|
|
600
|
+
>>> c1 = (1,2,3)
|
|
601
|
+
>>> c2 = (3,2,1)
|
|
602
|
+
>>> C.chebadd(c1,c2)
|
|
603
|
+
array([4., 4., 4.])
|
|
604
|
+
|
|
605
|
+
"""
|
|
606
|
+
return pu._add(c1, c2)
|
|
607
|
+
|
|
608
|
+
|
|
609
|
+
def chebsub(c1, c2):
|
|
610
|
+
"""
|
|
611
|
+
Subtract one Chebyshev series from another.
|
|
612
|
+
|
|
613
|
+
Returns the difference of two Chebyshev series `c1` - `c2`. The
|
|
614
|
+
sequences of coefficients are from lowest order term to highest, i.e.,
|
|
615
|
+
[1,2,3] represents the series ``T_0 + 2*T_1 + 3*T_2``.
|
|
616
|
+
|
|
617
|
+
Parameters
|
|
618
|
+
----------
|
|
619
|
+
c1, c2 : array_like
|
|
620
|
+
1-D arrays of Chebyshev series coefficients ordered from low to
|
|
621
|
+
high.
|
|
622
|
+
|
|
623
|
+
Returns
|
|
624
|
+
-------
|
|
625
|
+
out : ndarray
|
|
626
|
+
Of Chebyshev series coefficients representing their difference.
|
|
627
|
+
|
|
628
|
+
See Also
|
|
629
|
+
--------
|
|
630
|
+
chebadd, chebmulx, chebmul, chebdiv, chebpow
|
|
631
|
+
|
|
632
|
+
Notes
|
|
633
|
+
-----
|
|
634
|
+
Unlike multiplication, division, etc., the difference of two Chebyshev
|
|
635
|
+
series is a Chebyshev series (without having to "reproject" the result
|
|
636
|
+
onto the basis set) so subtraction, just like that of "standard"
|
|
637
|
+
polynomials, is simply "component-wise."
|
|
638
|
+
|
|
639
|
+
Examples
|
|
640
|
+
--------
|
|
641
|
+
>>> from numpy.polynomial import chebyshev as C
|
|
642
|
+
>>> c1 = (1,2,3)
|
|
643
|
+
>>> c2 = (3,2,1)
|
|
644
|
+
>>> C.chebsub(c1,c2)
|
|
645
|
+
array([-2., 0., 2.])
|
|
646
|
+
>>> C.chebsub(c2,c1) # -C.chebsub(c1,c2)
|
|
647
|
+
array([ 2., 0., -2.])
|
|
648
|
+
|
|
649
|
+
"""
|
|
650
|
+
return pu._sub(c1, c2)
|
|
651
|
+
|
|
652
|
+
|
|
653
|
+
def chebmulx(c):
|
|
654
|
+
"""Multiply a Chebyshev series by x.
|
|
655
|
+
|
|
656
|
+
Multiply the polynomial `c` by x, where x is the independent
|
|
657
|
+
variable.
|
|
658
|
+
|
|
659
|
+
|
|
660
|
+
Parameters
|
|
661
|
+
----------
|
|
662
|
+
c : array_like
|
|
663
|
+
1-D array of Chebyshev series coefficients ordered from low to
|
|
664
|
+
high.
|
|
665
|
+
|
|
666
|
+
Returns
|
|
667
|
+
-------
|
|
668
|
+
out : ndarray
|
|
669
|
+
Array representing the result of the multiplication.
|
|
670
|
+
|
|
671
|
+
See Also
|
|
672
|
+
--------
|
|
673
|
+
chebadd, chebsub, chebmul, chebdiv, chebpow
|
|
674
|
+
|
|
675
|
+
Examples
|
|
676
|
+
--------
|
|
677
|
+
>>> from numpy.polynomial import chebyshev as C
|
|
678
|
+
>>> C.chebmulx([1,2,3])
|
|
679
|
+
array([1. , 2.5, 1. , 1.5])
|
|
680
|
+
|
|
681
|
+
"""
|
|
682
|
+
# c is a trimmed copy
|
|
683
|
+
[c] = pu.as_series([c])
|
|
684
|
+
# The zero series needs special treatment
|
|
685
|
+
if len(c) == 1 and c[0] == 0:
|
|
686
|
+
return c
|
|
687
|
+
|
|
688
|
+
prd = np.empty(len(c) + 1, dtype=c.dtype)
|
|
689
|
+
prd[0] = c[0] * 0
|
|
690
|
+
prd[1] = c[0]
|
|
691
|
+
if len(c) > 1:
|
|
692
|
+
tmp = c[1:] / 2
|
|
693
|
+
prd[2:] = tmp
|
|
694
|
+
prd[0:-2] += tmp
|
|
695
|
+
return prd
|
|
696
|
+
|
|
697
|
+
|
|
698
|
+
def chebmul(c1, c2):
|
|
699
|
+
"""
|
|
700
|
+
Multiply one Chebyshev series by another.
|
|
701
|
+
|
|
702
|
+
Returns the product of two Chebyshev series `c1` * `c2`. The arguments
|
|
703
|
+
are sequences of coefficients, from lowest order "term" to highest,
|
|
704
|
+
e.g., [1,2,3] represents the series ``T_0 + 2*T_1 + 3*T_2``.
|
|
705
|
+
|
|
706
|
+
Parameters
|
|
707
|
+
----------
|
|
708
|
+
c1, c2 : array_like
|
|
709
|
+
1-D arrays of Chebyshev series coefficients ordered from low to
|
|
710
|
+
high.
|
|
711
|
+
|
|
712
|
+
Returns
|
|
713
|
+
-------
|
|
714
|
+
out : ndarray
|
|
715
|
+
Of Chebyshev series coefficients representing their product.
|
|
716
|
+
|
|
717
|
+
See Also
|
|
718
|
+
--------
|
|
719
|
+
chebadd, chebsub, chebmulx, chebdiv, chebpow
|
|
720
|
+
|
|
721
|
+
Notes
|
|
722
|
+
-----
|
|
723
|
+
In general, the (polynomial) product of two C-series results in terms
|
|
724
|
+
that are not in the Chebyshev polynomial basis set. Thus, to express
|
|
725
|
+
the product as a C-series, it is typically necessary to "reproject"
|
|
726
|
+
the product onto said basis set, which typically produces
|
|
727
|
+
"unintuitive live" (but correct) results; see Examples section below.
|
|
728
|
+
|
|
729
|
+
Examples
|
|
730
|
+
--------
|
|
731
|
+
>>> from numpy.polynomial import chebyshev as C
|
|
732
|
+
>>> c1 = (1,2,3)
|
|
733
|
+
>>> c2 = (3,2,1)
|
|
734
|
+
>>> C.chebmul(c1,c2) # multiplication requires "reprojection"
|
|
735
|
+
array([ 6.5, 12. , 12. , 4. , 1.5])
|
|
736
|
+
|
|
737
|
+
"""
|
|
738
|
+
# c1, c2 are trimmed copies
|
|
739
|
+
[c1, c2] = pu.as_series([c1, c2])
|
|
740
|
+
z1 = _cseries_to_zseries(c1)
|
|
741
|
+
z2 = _cseries_to_zseries(c2)
|
|
742
|
+
prd = _zseries_mul(z1, z2)
|
|
743
|
+
ret = _zseries_to_cseries(prd)
|
|
744
|
+
return pu.trimseq(ret)
|
|
745
|
+
|
|
746
|
+
|
|
747
|
+
def chebdiv(c1, c2):
|
|
748
|
+
"""
|
|
749
|
+
Divide one Chebyshev series by another.
|
|
750
|
+
|
|
751
|
+
Returns the quotient-with-remainder of two Chebyshev series
|
|
752
|
+
`c1` / `c2`. The arguments are sequences of coefficients from lowest
|
|
753
|
+
order "term" to highest, e.g., [1,2,3] represents the series
|
|
754
|
+
``T_0 + 2*T_1 + 3*T_2``.
|
|
755
|
+
|
|
756
|
+
Parameters
|
|
757
|
+
----------
|
|
758
|
+
c1, c2 : array_like
|
|
759
|
+
1-D arrays of Chebyshev series coefficients ordered from low to
|
|
760
|
+
high.
|
|
761
|
+
|
|
762
|
+
Returns
|
|
763
|
+
-------
|
|
764
|
+
[quo, rem] : ndarrays
|
|
765
|
+
Of Chebyshev series coefficients representing the quotient and
|
|
766
|
+
remainder.
|
|
767
|
+
|
|
768
|
+
See Also
|
|
769
|
+
--------
|
|
770
|
+
chebadd, chebsub, chebmulx, chebmul, chebpow
|
|
771
|
+
|
|
772
|
+
Notes
|
|
773
|
+
-----
|
|
774
|
+
In general, the (polynomial) division of one C-series by another
|
|
775
|
+
results in quotient and remainder terms that are not in the Chebyshev
|
|
776
|
+
polynomial basis set. Thus, to express these results as C-series, it
|
|
777
|
+
is typically necessary to "reproject" the results onto said basis
|
|
778
|
+
set, which typically produces "unintuitive" (but correct) results;
|
|
779
|
+
see Examples section below.
|
|
780
|
+
|
|
781
|
+
Examples
|
|
782
|
+
--------
|
|
783
|
+
>>> from numpy.polynomial import chebyshev as C
|
|
784
|
+
>>> c1 = (1,2,3)
|
|
785
|
+
>>> c2 = (3,2,1)
|
|
786
|
+
>>> C.chebdiv(c1,c2) # quotient "intuitive," remainder not
|
|
787
|
+
(array([3.]), array([-8., -4.]))
|
|
788
|
+
>>> c2 = (0,1,2,3)
|
|
789
|
+
>>> C.chebdiv(c2,c1) # neither "intuitive"
|
|
790
|
+
(array([0., 2.]), array([-2., -4.]))
|
|
791
|
+
|
|
792
|
+
"""
|
|
793
|
+
# c1, c2 are trimmed copies
|
|
794
|
+
[c1, c2] = pu.as_series([c1, c2])
|
|
795
|
+
if c2[-1] == 0:
|
|
796
|
+
raise ZeroDivisionError # FIXME: add message with details to exception
|
|
797
|
+
|
|
798
|
+
# note: this is more efficient than `pu._div(chebmul, c1, c2)`
|
|
799
|
+
lc1 = len(c1)
|
|
800
|
+
lc2 = len(c2)
|
|
801
|
+
if lc1 < lc2:
|
|
802
|
+
return c1[:1] * 0, c1
|
|
803
|
+
elif lc2 == 1:
|
|
804
|
+
return c1 / c2[-1], c1[:1] * 0
|
|
805
|
+
else:
|
|
806
|
+
z1 = _cseries_to_zseries(c1)
|
|
807
|
+
z2 = _cseries_to_zseries(c2)
|
|
808
|
+
quo, rem = _zseries_div(z1, z2)
|
|
809
|
+
quo = pu.trimseq(_zseries_to_cseries(quo))
|
|
810
|
+
rem = pu.trimseq(_zseries_to_cseries(rem))
|
|
811
|
+
return quo, rem
|
|
812
|
+
|
|
813
|
+
|
|
814
|
+
def chebpow(c, pow, maxpower=16):
|
|
815
|
+
"""Raise a Chebyshev series to a power.
|
|
816
|
+
|
|
817
|
+
Returns the Chebyshev series `c` raised to the power `pow`. The
|
|
818
|
+
argument `c` is a sequence of coefficients ordered from low to high.
|
|
819
|
+
i.e., [1,2,3] is the series ``T_0 + 2*T_1 + 3*T_2.``
|
|
820
|
+
|
|
821
|
+
Parameters
|
|
822
|
+
----------
|
|
823
|
+
c : array_like
|
|
824
|
+
1-D array of Chebyshev series coefficients ordered from low to
|
|
825
|
+
high.
|
|
826
|
+
pow : integer
|
|
827
|
+
Power to which the series will be raised
|
|
828
|
+
maxpower : integer, optional
|
|
829
|
+
Maximum power allowed. This is mainly to limit growth of the series
|
|
830
|
+
to unmanageable size. Default is 16
|
|
831
|
+
|
|
832
|
+
Returns
|
|
833
|
+
-------
|
|
834
|
+
coef : ndarray
|
|
835
|
+
Chebyshev series of power.
|
|
836
|
+
|
|
837
|
+
See Also
|
|
838
|
+
--------
|
|
839
|
+
chebadd, chebsub, chebmulx, chebmul, chebdiv
|
|
840
|
+
|
|
841
|
+
Examples
|
|
842
|
+
--------
|
|
843
|
+
>>> from numpy.polynomial import chebyshev as C
|
|
844
|
+
>>> C.chebpow([1, 2, 3, 4], 2)
|
|
845
|
+
array([15.5, 22. , 16. , ..., 12.5, 12. , 8. ])
|
|
846
|
+
|
|
847
|
+
"""
|
|
848
|
+
# note: this is more efficient than `pu._pow(chebmul, c1, c2)`, as it
|
|
849
|
+
# avoids converting between z and c series repeatedly
|
|
850
|
+
|
|
851
|
+
# c is a trimmed copy
|
|
852
|
+
[c] = pu.as_series([c])
|
|
853
|
+
power = int(pow)
|
|
854
|
+
if power != pow or power < 0:
|
|
855
|
+
raise ValueError("Power must be a non-negative integer.")
|
|
856
|
+
elif maxpower is not None and power > maxpower:
|
|
857
|
+
raise ValueError("Power is too large")
|
|
858
|
+
elif power == 0:
|
|
859
|
+
return np.array([1], dtype=c.dtype)
|
|
860
|
+
elif power == 1:
|
|
861
|
+
return c
|
|
862
|
+
else:
|
|
863
|
+
# This can be made more efficient by using powers of two
|
|
864
|
+
# in the usual way.
|
|
865
|
+
zs = _cseries_to_zseries(c)
|
|
866
|
+
prd = zs
|
|
867
|
+
for i in range(2, power + 1):
|
|
868
|
+
prd = np.convolve(prd, zs)
|
|
869
|
+
return _zseries_to_cseries(prd)
|
|
870
|
+
|
|
871
|
+
|
|
872
|
+
def chebder(c, m=1, scl=1, axis=0):
|
|
873
|
+
"""
|
|
874
|
+
Differentiate a Chebyshev series.
|
|
875
|
+
|
|
876
|
+
Returns the Chebyshev series coefficients `c` differentiated `m` times
|
|
877
|
+
along `axis`. At each iteration the result is multiplied by `scl` (the
|
|
878
|
+
scaling factor is for use in a linear change of variable). The argument
|
|
879
|
+
`c` is an array of coefficients from low to high degree along each
|
|
880
|
+
axis, e.g., [1,2,3] represents the series ``1*T_0 + 2*T_1 + 3*T_2``
|
|
881
|
+
while [[1,2],[1,2]] represents ``1*T_0(x)*T_0(y) + 1*T_1(x)*T_0(y) +
|
|
882
|
+
2*T_0(x)*T_1(y) + 2*T_1(x)*T_1(y)`` if axis=0 is ``x`` and axis=1 is
|
|
883
|
+
``y``.
|
|
884
|
+
|
|
885
|
+
Parameters
|
|
886
|
+
----------
|
|
887
|
+
c : array_like
|
|
888
|
+
Array of Chebyshev series coefficients. If c is multidimensional
|
|
889
|
+
the different axis correspond to different variables with the
|
|
890
|
+
degree in each axis given by the corresponding index.
|
|
891
|
+
m : int, optional
|
|
892
|
+
Number of derivatives taken, must be non-negative. (Default: 1)
|
|
893
|
+
scl : scalar, optional
|
|
894
|
+
Each differentiation is multiplied by `scl`. The end result is
|
|
895
|
+
multiplication by ``scl**m``. This is for use in a linear change of
|
|
896
|
+
variable. (Default: 1)
|
|
897
|
+
axis : int, optional
|
|
898
|
+
Axis over which the derivative is taken. (Default: 0).
|
|
899
|
+
|
|
900
|
+
Returns
|
|
901
|
+
-------
|
|
902
|
+
der : ndarray
|
|
903
|
+
Chebyshev series of the derivative.
|
|
904
|
+
|
|
905
|
+
See Also
|
|
906
|
+
--------
|
|
907
|
+
chebint
|
|
908
|
+
|
|
909
|
+
Notes
|
|
910
|
+
-----
|
|
911
|
+
In general, the result of differentiating a C-series needs to be
|
|
912
|
+
"reprojected" onto the C-series basis set. Thus, typically, the
|
|
913
|
+
result of this function is "unintuitive," albeit correct; see Examples
|
|
914
|
+
section below.
|
|
915
|
+
|
|
916
|
+
Examples
|
|
917
|
+
--------
|
|
918
|
+
>>> from numpy.polynomial import chebyshev as C
|
|
919
|
+
>>> c = (1,2,3,4)
|
|
920
|
+
>>> C.chebder(c)
|
|
921
|
+
array([14., 12., 24.])
|
|
922
|
+
>>> C.chebder(c,3)
|
|
923
|
+
array([96.])
|
|
924
|
+
>>> C.chebder(c,scl=-1)
|
|
925
|
+
array([-14., -12., -24.])
|
|
926
|
+
>>> C.chebder(c,2,-1)
|
|
927
|
+
array([12., 96.])
|
|
928
|
+
|
|
929
|
+
"""
|
|
930
|
+
c = np.array(c, ndmin=1, copy=True)
|
|
931
|
+
if c.dtype.char in '?bBhHiIlLqQpP':
|
|
932
|
+
c = c.astype(np.double)
|
|
933
|
+
cnt = pu._as_int(m, "the order of derivation")
|
|
934
|
+
iaxis = pu._as_int(axis, "the axis")
|
|
935
|
+
if cnt < 0:
|
|
936
|
+
raise ValueError("The order of derivation must be non-negative")
|
|
937
|
+
iaxis = np.lib.array_utils.normalize_axis_index(iaxis, c.ndim)
|
|
938
|
+
|
|
939
|
+
if cnt == 0:
|
|
940
|
+
return c
|
|
941
|
+
|
|
942
|
+
c = np.moveaxis(c, iaxis, 0)
|
|
943
|
+
n = len(c)
|
|
944
|
+
if cnt >= n:
|
|
945
|
+
c = c[:1] * 0
|
|
946
|
+
else:
|
|
947
|
+
for i in range(cnt):
|
|
948
|
+
n = n - 1
|
|
949
|
+
c *= scl
|
|
950
|
+
der = np.empty((n,) + c.shape[1:], dtype=c.dtype)
|
|
951
|
+
for j in range(n, 2, -1):
|
|
952
|
+
der[j - 1] = (2 * j) * c[j]
|
|
953
|
+
c[j - 2] += (j * c[j]) / (j - 2)
|
|
954
|
+
if n > 1:
|
|
955
|
+
der[1] = 4 * c[2]
|
|
956
|
+
der[0] = c[1]
|
|
957
|
+
c = der
|
|
958
|
+
c = np.moveaxis(c, 0, iaxis)
|
|
959
|
+
return c
|
|
960
|
+
|
|
961
|
+
|
|
962
|
+
def chebint(c, m=1, k=[], lbnd=0, scl=1, axis=0):
|
|
963
|
+
"""
|
|
964
|
+
Integrate a Chebyshev series.
|
|
965
|
+
|
|
966
|
+
Returns the Chebyshev series coefficients `c` integrated `m` times from
|
|
967
|
+
`lbnd` along `axis`. At each iteration the resulting series is
|
|
968
|
+
**multiplied** by `scl` and an integration constant, `k`, is added.
|
|
969
|
+
The scaling factor is for use in a linear change of variable. ("Buyer
|
|
970
|
+
beware": note that, depending on what one is doing, one may want `scl`
|
|
971
|
+
to be the reciprocal of what one might expect; for more information,
|
|
972
|
+
see the Notes section below.) The argument `c` is an array of
|
|
973
|
+
coefficients from low to high degree along each axis, e.g., [1,2,3]
|
|
974
|
+
represents the series ``T_0 + 2*T_1 + 3*T_2`` while [[1,2],[1,2]]
|
|
975
|
+
represents ``1*T_0(x)*T_0(y) + 1*T_1(x)*T_0(y) + 2*T_0(x)*T_1(y) +
|
|
976
|
+
2*T_1(x)*T_1(y)`` if axis=0 is ``x`` and axis=1 is ``y``.
|
|
977
|
+
|
|
978
|
+
Parameters
|
|
979
|
+
----------
|
|
980
|
+
c : array_like
|
|
981
|
+
Array of Chebyshev series coefficients. If c is multidimensional
|
|
982
|
+
the different axis correspond to different variables with the
|
|
983
|
+
degree in each axis given by the corresponding index.
|
|
984
|
+
m : int, optional
|
|
985
|
+
Order of integration, must be positive. (Default: 1)
|
|
986
|
+
k : {[], list, scalar}, optional
|
|
987
|
+
Integration constant(s). The value of the first integral at zero
|
|
988
|
+
is the first value in the list, the value of the second integral
|
|
989
|
+
at zero is the second value, etc. If ``k == []`` (the default),
|
|
990
|
+
all constants are set to zero. If ``m == 1``, a single scalar can
|
|
991
|
+
be given instead of a list.
|
|
992
|
+
lbnd : scalar, optional
|
|
993
|
+
The lower bound of the integral. (Default: 0)
|
|
994
|
+
scl : scalar, optional
|
|
995
|
+
Following each integration the result is *multiplied* by `scl`
|
|
996
|
+
before the integration constant is added. (Default: 1)
|
|
997
|
+
axis : int, optional
|
|
998
|
+
Axis over which the integral is taken. (Default: 0).
|
|
999
|
+
|
|
1000
|
+
Returns
|
|
1001
|
+
-------
|
|
1002
|
+
S : ndarray
|
|
1003
|
+
C-series coefficients of the integral.
|
|
1004
|
+
|
|
1005
|
+
Raises
|
|
1006
|
+
------
|
|
1007
|
+
ValueError
|
|
1008
|
+
If ``m < 1``, ``len(k) > m``, ``np.ndim(lbnd) != 0``, or
|
|
1009
|
+
``np.ndim(scl) != 0``.
|
|
1010
|
+
|
|
1011
|
+
See Also
|
|
1012
|
+
--------
|
|
1013
|
+
chebder
|
|
1014
|
+
|
|
1015
|
+
Notes
|
|
1016
|
+
-----
|
|
1017
|
+
Note that the result of each integration is *multiplied* by `scl`.
|
|
1018
|
+
Why is this important to note? Say one is making a linear change of
|
|
1019
|
+
variable :math:`u = ax + b` in an integral relative to `x`. Then
|
|
1020
|
+
:math:`dx = du/a`, so one will need to set `scl` equal to
|
|
1021
|
+
:math:`1/a`- perhaps not what one would have first thought.
|
|
1022
|
+
|
|
1023
|
+
Also note that, in general, the result of integrating a C-series needs
|
|
1024
|
+
to be "reprojected" onto the C-series basis set. Thus, typically,
|
|
1025
|
+
the result of this function is "unintuitive," albeit correct; see
|
|
1026
|
+
Examples section below.
|
|
1027
|
+
|
|
1028
|
+
Examples
|
|
1029
|
+
--------
|
|
1030
|
+
>>> from numpy.polynomial import chebyshev as C
|
|
1031
|
+
>>> c = (1,2,3)
|
|
1032
|
+
>>> C.chebint(c)
|
|
1033
|
+
array([ 0.5, -0.5, 0.5, 0.5])
|
|
1034
|
+
>>> C.chebint(c,3)
|
|
1035
|
+
array([ 0.03125 , -0.1875 , 0.04166667, -0.05208333, 0.01041667, # may vary
|
|
1036
|
+
0.00625 ])
|
|
1037
|
+
>>> C.chebint(c, k=3)
|
|
1038
|
+
array([ 3.5, -0.5, 0.5, 0.5])
|
|
1039
|
+
>>> C.chebint(c,lbnd=-2)
|
|
1040
|
+
array([ 8.5, -0.5, 0.5, 0.5])
|
|
1041
|
+
>>> C.chebint(c,scl=-2)
|
|
1042
|
+
array([-1., 1., -1., -1.])
|
|
1043
|
+
|
|
1044
|
+
"""
|
|
1045
|
+
c = np.array(c, ndmin=1, copy=True)
|
|
1046
|
+
if c.dtype.char in '?bBhHiIlLqQpP':
|
|
1047
|
+
c = c.astype(np.double)
|
|
1048
|
+
if not np.iterable(k):
|
|
1049
|
+
k = [k]
|
|
1050
|
+
cnt = pu._as_int(m, "the order of integration")
|
|
1051
|
+
iaxis = pu._as_int(axis, "the axis")
|
|
1052
|
+
if cnt < 0:
|
|
1053
|
+
raise ValueError("The order of integration must be non-negative")
|
|
1054
|
+
if len(k) > cnt:
|
|
1055
|
+
raise ValueError("Too many integration constants")
|
|
1056
|
+
if np.ndim(lbnd) != 0:
|
|
1057
|
+
raise ValueError("lbnd must be a scalar.")
|
|
1058
|
+
if np.ndim(scl) != 0:
|
|
1059
|
+
raise ValueError("scl must be a scalar.")
|
|
1060
|
+
iaxis = np.lib.array_utils.normalize_axis_index(iaxis, c.ndim)
|
|
1061
|
+
|
|
1062
|
+
if cnt == 0:
|
|
1063
|
+
return c
|
|
1064
|
+
|
|
1065
|
+
c = np.moveaxis(c, iaxis, 0)
|
|
1066
|
+
k = list(k) + [0] * (cnt - len(k))
|
|
1067
|
+
for i in range(cnt):
|
|
1068
|
+
n = len(c)
|
|
1069
|
+
c *= scl
|
|
1070
|
+
if n == 1 and np.all(c[0] == 0):
|
|
1071
|
+
c[0] += k[i]
|
|
1072
|
+
else:
|
|
1073
|
+
tmp = np.empty((n + 1,) + c.shape[1:], dtype=c.dtype)
|
|
1074
|
+
tmp[0] = c[0] * 0
|
|
1075
|
+
tmp[1] = c[0]
|
|
1076
|
+
if n > 1:
|
|
1077
|
+
tmp[2] = c[1] / 4
|
|
1078
|
+
for j in range(2, n):
|
|
1079
|
+
tmp[j + 1] = c[j] / (2 * (j + 1))
|
|
1080
|
+
tmp[j - 1] -= c[j] / (2 * (j - 1))
|
|
1081
|
+
tmp[0] += k[i] - chebval(lbnd, tmp)
|
|
1082
|
+
c = tmp
|
|
1083
|
+
c = np.moveaxis(c, 0, iaxis)
|
|
1084
|
+
return c
|
|
1085
|
+
|
|
1086
|
+
|
|
1087
|
+
def chebval(x, c, tensor=True):
|
|
1088
|
+
"""
|
|
1089
|
+
Evaluate a Chebyshev series at points x.
|
|
1090
|
+
|
|
1091
|
+
If `c` is of length `n + 1`, this function returns the value:
|
|
1092
|
+
|
|
1093
|
+
.. math:: p(x) = c_0 * T_0(x) + c_1 * T_1(x) + ... + c_n * T_n(x)
|
|
1094
|
+
|
|
1095
|
+
The parameter `x` is converted to an array only if it is a tuple or a
|
|
1096
|
+
list, otherwise it is treated as a scalar. In either case, either `x`
|
|
1097
|
+
or its elements must support multiplication and addition both with
|
|
1098
|
+
themselves and with the elements of `c`.
|
|
1099
|
+
|
|
1100
|
+
If `c` is a 1-D array, then ``p(x)`` will have the same shape as `x`. If
|
|
1101
|
+
`c` is multidimensional, then the shape of the result depends on the
|
|
1102
|
+
value of `tensor`. If `tensor` is true the shape will be c.shape[1:] +
|
|
1103
|
+
x.shape. If `tensor` is false the shape will be c.shape[1:]. Note that
|
|
1104
|
+
scalars have shape (,).
|
|
1105
|
+
|
|
1106
|
+
Trailing zeros in the coefficients will be used in the evaluation, so
|
|
1107
|
+
they should be avoided if efficiency is a concern.
|
|
1108
|
+
|
|
1109
|
+
Parameters
|
|
1110
|
+
----------
|
|
1111
|
+
x : array_like, compatible object
|
|
1112
|
+
If `x` is a list or tuple, it is converted to an ndarray, otherwise
|
|
1113
|
+
it is left unchanged and treated as a scalar. In either case, `x`
|
|
1114
|
+
or its elements must support addition and multiplication with
|
|
1115
|
+
themselves and with the elements of `c`.
|
|
1116
|
+
c : array_like
|
|
1117
|
+
Array of coefficients ordered so that the coefficients for terms of
|
|
1118
|
+
degree n are contained in c[n]. If `c` is multidimensional the
|
|
1119
|
+
remaining indices enumerate multiple polynomials. In the two
|
|
1120
|
+
dimensional case the coefficients may be thought of as stored in
|
|
1121
|
+
the columns of `c`.
|
|
1122
|
+
tensor : boolean, optional
|
|
1123
|
+
If True, the shape of the coefficient array is extended with ones
|
|
1124
|
+
on the right, one for each dimension of `x`. Scalars have dimension 0
|
|
1125
|
+
for this action. The result is that every column of coefficients in
|
|
1126
|
+
`c` is evaluated for every element of `x`. If False, `x` is broadcast
|
|
1127
|
+
over the columns of `c` for the evaluation. This keyword is useful
|
|
1128
|
+
when `c` is multidimensional. The default value is True.
|
|
1129
|
+
|
|
1130
|
+
Returns
|
|
1131
|
+
-------
|
|
1132
|
+
values : ndarray, algebra_like
|
|
1133
|
+
The shape of the return value is described above.
|
|
1134
|
+
|
|
1135
|
+
See Also
|
|
1136
|
+
--------
|
|
1137
|
+
chebval2d, chebgrid2d, chebval3d, chebgrid3d
|
|
1138
|
+
|
|
1139
|
+
Notes
|
|
1140
|
+
-----
|
|
1141
|
+
The evaluation uses Clenshaw recursion, aka synthetic division.
|
|
1142
|
+
|
|
1143
|
+
"""
|
|
1144
|
+
c = np.array(c, ndmin=1, copy=True)
|
|
1145
|
+
if c.dtype.char in '?bBhHiIlLqQpP':
|
|
1146
|
+
c = c.astype(np.double)
|
|
1147
|
+
if isinstance(x, (tuple, list)):
|
|
1148
|
+
x = np.asarray(x)
|
|
1149
|
+
if isinstance(x, np.ndarray) and tensor:
|
|
1150
|
+
c = c.reshape(c.shape + (1,) * x.ndim)
|
|
1151
|
+
|
|
1152
|
+
if len(c) == 1:
|
|
1153
|
+
c0 = c[0]
|
|
1154
|
+
c1 = 0
|
|
1155
|
+
elif len(c) == 2:
|
|
1156
|
+
c0 = c[0]
|
|
1157
|
+
c1 = c[1]
|
|
1158
|
+
else:
|
|
1159
|
+
x2 = 2 * x
|
|
1160
|
+
c0 = c[-2]
|
|
1161
|
+
c1 = c[-1]
|
|
1162
|
+
for i in range(3, len(c) + 1):
|
|
1163
|
+
tmp = c0
|
|
1164
|
+
c0 = c[-i] - c1
|
|
1165
|
+
c1 = tmp + c1 * x2
|
|
1166
|
+
return c0 + c1 * x
|
|
1167
|
+
|
|
1168
|
+
|
|
1169
|
+
def chebval2d(x, y, c):
|
|
1170
|
+
"""
|
|
1171
|
+
Evaluate a 2-D Chebyshev series at points (x, y).
|
|
1172
|
+
|
|
1173
|
+
This function returns the values:
|
|
1174
|
+
|
|
1175
|
+
.. math:: p(x,y) = \\sum_{i,j} c_{i,j} * T_i(x) * T_j(y)
|
|
1176
|
+
|
|
1177
|
+
The parameters `x` and `y` are converted to arrays only if they are
|
|
1178
|
+
tuples or a lists, otherwise they are treated as a scalars and they
|
|
1179
|
+
must have the same shape after conversion. In either case, either `x`
|
|
1180
|
+
and `y` or their elements must support multiplication and addition both
|
|
1181
|
+
with themselves and with the elements of `c`.
|
|
1182
|
+
|
|
1183
|
+
If `c` is a 1-D array a one is implicitly appended to its shape to make
|
|
1184
|
+
it 2-D. The shape of the result will be c.shape[2:] + x.shape.
|
|
1185
|
+
|
|
1186
|
+
Parameters
|
|
1187
|
+
----------
|
|
1188
|
+
x, y : array_like, compatible objects
|
|
1189
|
+
The two dimensional series is evaluated at the points ``(x, y)``,
|
|
1190
|
+
where `x` and `y` must have the same shape. If `x` or `y` is a list
|
|
1191
|
+
or tuple, it is first converted to an ndarray, otherwise it is left
|
|
1192
|
+
unchanged and if it isn't an ndarray it is treated as a scalar.
|
|
1193
|
+
c : array_like
|
|
1194
|
+
Array of coefficients ordered so that the coefficient of the term
|
|
1195
|
+
of multi-degree i,j is contained in ``c[i,j]``. If `c` has
|
|
1196
|
+
dimension greater than 2 the remaining indices enumerate multiple
|
|
1197
|
+
sets of coefficients.
|
|
1198
|
+
|
|
1199
|
+
Returns
|
|
1200
|
+
-------
|
|
1201
|
+
values : ndarray, compatible object
|
|
1202
|
+
The values of the two dimensional Chebyshev series at points formed
|
|
1203
|
+
from pairs of corresponding values from `x` and `y`.
|
|
1204
|
+
|
|
1205
|
+
See Also
|
|
1206
|
+
--------
|
|
1207
|
+
chebval, chebgrid2d, chebval3d, chebgrid3d
|
|
1208
|
+
"""
|
|
1209
|
+
return pu._valnd(chebval, c, x, y)
|
|
1210
|
+
|
|
1211
|
+
|
|
1212
|
+
def chebgrid2d(x, y, c):
|
|
1213
|
+
"""
|
|
1214
|
+
Evaluate a 2-D Chebyshev series on the Cartesian product of x and y.
|
|
1215
|
+
|
|
1216
|
+
This function returns the values:
|
|
1217
|
+
|
|
1218
|
+
.. math:: p(a,b) = \\sum_{i,j} c_{i,j} * T_i(a) * T_j(b),
|
|
1219
|
+
|
|
1220
|
+
where the points `(a, b)` consist of all pairs formed by taking
|
|
1221
|
+
`a` from `x` and `b` from `y`. The resulting points form a grid with
|
|
1222
|
+
`x` in the first dimension and `y` in the second.
|
|
1223
|
+
|
|
1224
|
+
The parameters `x` and `y` are converted to arrays only if they are
|
|
1225
|
+
tuples or a lists, otherwise they are treated as a scalars. In either
|
|
1226
|
+
case, either `x` and `y` or their elements must support multiplication
|
|
1227
|
+
and addition both with themselves and with the elements of `c`.
|
|
1228
|
+
|
|
1229
|
+
If `c` has fewer than two dimensions, ones are implicitly appended to
|
|
1230
|
+
its shape to make it 2-D. The shape of the result will be c.shape[2:] +
|
|
1231
|
+
x.shape + y.shape.
|
|
1232
|
+
|
|
1233
|
+
Parameters
|
|
1234
|
+
----------
|
|
1235
|
+
x, y : array_like, compatible objects
|
|
1236
|
+
The two dimensional series is evaluated at the points in the
|
|
1237
|
+
Cartesian product of `x` and `y`. If `x` or `y` is a list or
|
|
1238
|
+
tuple, it is first converted to an ndarray, otherwise it is left
|
|
1239
|
+
unchanged and, if it isn't an ndarray, it is treated as a scalar.
|
|
1240
|
+
c : array_like
|
|
1241
|
+
Array of coefficients ordered so that the coefficient of the term of
|
|
1242
|
+
multi-degree i,j is contained in ``c[i,j]``. If `c` has dimension
|
|
1243
|
+
greater than two the remaining indices enumerate multiple sets of
|
|
1244
|
+
coefficients.
|
|
1245
|
+
|
|
1246
|
+
Returns
|
|
1247
|
+
-------
|
|
1248
|
+
values : ndarray, compatible object
|
|
1249
|
+
The values of the two dimensional Chebyshev series at points in the
|
|
1250
|
+
Cartesian product of `x` and `y`.
|
|
1251
|
+
|
|
1252
|
+
See Also
|
|
1253
|
+
--------
|
|
1254
|
+
chebval, chebval2d, chebval3d, chebgrid3d
|
|
1255
|
+
"""
|
|
1256
|
+
return pu._gridnd(chebval, c, x, y)
|
|
1257
|
+
|
|
1258
|
+
|
|
1259
|
+
def chebval3d(x, y, z, c):
|
|
1260
|
+
"""
|
|
1261
|
+
Evaluate a 3-D Chebyshev series at points (x, y, z).
|
|
1262
|
+
|
|
1263
|
+
This function returns the values:
|
|
1264
|
+
|
|
1265
|
+
.. math:: p(x,y,z) = \\sum_{i,j,k} c_{i,j,k} * T_i(x) * T_j(y) * T_k(z)
|
|
1266
|
+
|
|
1267
|
+
The parameters `x`, `y`, and `z` are converted to arrays only if
|
|
1268
|
+
they are tuples or a lists, otherwise they are treated as a scalars and
|
|
1269
|
+
they must have the same shape after conversion. In either case, either
|
|
1270
|
+
`x`, `y`, and `z` or their elements must support multiplication and
|
|
1271
|
+
addition both with themselves and with the elements of `c`.
|
|
1272
|
+
|
|
1273
|
+
If `c` has fewer than 3 dimensions, ones are implicitly appended to its
|
|
1274
|
+
shape to make it 3-D. The shape of the result will be c.shape[3:] +
|
|
1275
|
+
x.shape.
|
|
1276
|
+
|
|
1277
|
+
Parameters
|
|
1278
|
+
----------
|
|
1279
|
+
x, y, z : array_like, compatible object
|
|
1280
|
+
The three dimensional series is evaluated at the points
|
|
1281
|
+
``(x, y, z)``, where `x`, `y`, and `z` must have the same shape. If
|
|
1282
|
+
any of `x`, `y`, or `z` is a list or tuple, it is first converted
|
|
1283
|
+
to an ndarray, otherwise it is left unchanged and if it isn't an
|
|
1284
|
+
ndarray it is treated as a scalar.
|
|
1285
|
+
c : array_like
|
|
1286
|
+
Array of coefficients ordered so that the coefficient of the term of
|
|
1287
|
+
multi-degree i,j,k is contained in ``c[i,j,k]``. If `c` has dimension
|
|
1288
|
+
greater than 3 the remaining indices enumerate multiple sets of
|
|
1289
|
+
coefficients.
|
|
1290
|
+
|
|
1291
|
+
Returns
|
|
1292
|
+
-------
|
|
1293
|
+
values : ndarray, compatible object
|
|
1294
|
+
The values of the multidimensional polynomial on points formed with
|
|
1295
|
+
triples of corresponding values from `x`, `y`, and `z`.
|
|
1296
|
+
|
|
1297
|
+
See Also
|
|
1298
|
+
--------
|
|
1299
|
+
chebval, chebval2d, chebgrid2d, chebgrid3d
|
|
1300
|
+
"""
|
|
1301
|
+
return pu._valnd(chebval, c, x, y, z)
|
|
1302
|
+
|
|
1303
|
+
|
|
1304
|
+
def chebgrid3d(x, y, z, c):
|
|
1305
|
+
"""
|
|
1306
|
+
Evaluate a 3-D Chebyshev series on the Cartesian product of x, y, and z.
|
|
1307
|
+
|
|
1308
|
+
This function returns the values:
|
|
1309
|
+
|
|
1310
|
+
.. math:: p(a,b,c) = \\sum_{i,j,k} c_{i,j,k} * T_i(a) * T_j(b) * T_k(c)
|
|
1311
|
+
|
|
1312
|
+
where the points ``(a, b, c)`` consist of all triples formed by taking
|
|
1313
|
+
`a` from `x`, `b` from `y`, and `c` from `z`. The resulting points form
|
|
1314
|
+
a grid with `x` in the first dimension, `y` in the second, and `z` in
|
|
1315
|
+
the third.
|
|
1316
|
+
|
|
1317
|
+
The parameters `x`, `y`, and `z` are converted to arrays only if they
|
|
1318
|
+
are tuples or a lists, otherwise they are treated as a scalars. In
|
|
1319
|
+
either case, either `x`, `y`, and `z` or their elements must support
|
|
1320
|
+
multiplication and addition both with themselves and with the elements
|
|
1321
|
+
of `c`.
|
|
1322
|
+
|
|
1323
|
+
If `c` has fewer than three dimensions, ones are implicitly appended to
|
|
1324
|
+
its shape to make it 3-D. The shape of the result will be c.shape[3:] +
|
|
1325
|
+
x.shape + y.shape + z.shape.
|
|
1326
|
+
|
|
1327
|
+
Parameters
|
|
1328
|
+
----------
|
|
1329
|
+
x, y, z : array_like, compatible objects
|
|
1330
|
+
The three dimensional series is evaluated at the points in the
|
|
1331
|
+
Cartesian product of `x`, `y`, and `z`. If `x`, `y`, or `z` is a
|
|
1332
|
+
list or tuple, it is first converted to an ndarray, otherwise it is
|
|
1333
|
+
left unchanged and, if it isn't an ndarray, it is treated as a
|
|
1334
|
+
scalar.
|
|
1335
|
+
c : array_like
|
|
1336
|
+
Array of coefficients ordered so that the coefficients for terms of
|
|
1337
|
+
degree i,j are contained in ``c[i,j]``. If `c` has dimension
|
|
1338
|
+
greater than two the remaining indices enumerate multiple sets of
|
|
1339
|
+
coefficients.
|
|
1340
|
+
|
|
1341
|
+
Returns
|
|
1342
|
+
-------
|
|
1343
|
+
values : ndarray, compatible object
|
|
1344
|
+
The values of the two dimensional polynomial at points in the Cartesian
|
|
1345
|
+
product of `x` and `y`.
|
|
1346
|
+
|
|
1347
|
+
See Also
|
|
1348
|
+
--------
|
|
1349
|
+
chebval, chebval2d, chebgrid2d, chebval3d
|
|
1350
|
+
"""
|
|
1351
|
+
return pu._gridnd(chebval, c, x, y, z)
|
|
1352
|
+
|
|
1353
|
+
|
|
1354
|
+
def chebvander(x, deg):
|
|
1355
|
+
"""Pseudo-Vandermonde matrix of given degree.
|
|
1356
|
+
|
|
1357
|
+
Returns the pseudo-Vandermonde matrix of degree `deg` and sample points
|
|
1358
|
+
`x`. The pseudo-Vandermonde matrix is defined by
|
|
1359
|
+
|
|
1360
|
+
.. math:: V[..., i] = T_i(x),
|
|
1361
|
+
|
|
1362
|
+
where ``0 <= i <= deg``. The leading indices of `V` index the elements of
|
|
1363
|
+
`x` and the last index is the degree of the Chebyshev polynomial.
|
|
1364
|
+
|
|
1365
|
+
If `c` is a 1-D array of coefficients of length ``n + 1`` and `V` is the
|
|
1366
|
+
matrix ``V = chebvander(x, n)``, then ``np.dot(V, c)`` and
|
|
1367
|
+
``chebval(x, c)`` are the same up to roundoff. This equivalence is
|
|
1368
|
+
useful both for least squares fitting and for the evaluation of a large
|
|
1369
|
+
number of Chebyshev series of the same degree and sample points.
|
|
1370
|
+
|
|
1371
|
+
Parameters
|
|
1372
|
+
----------
|
|
1373
|
+
x : array_like
|
|
1374
|
+
Array of points. The dtype is converted to float64 or complex128
|
|
1375
|
+
depending on whether any of the elements are complex. If `x` is
|
|
1376
|
+
scalar it is converted to a 1-D array.
|
|
1377
|
+
deg : int
|
|
1378
|
+
Degree of the resulting matrix.
|
|
1379
|
+
|
|
1380
|
+
Returns
|
|
1381
|
+
-------
|
|
1382
|
+
vander : ndarray
|
|
1383
|
+
The pseudo Vandermonde matrix. The shape of the returned matrix is
|
|
1384
|
+
``x.shape + (deg + 1,)``, where The last index is the degree of the
|
|
1385
|
+
corresponding Chebyshev polynomial. The dtype will be the same as
|
|
1386
|
+
the converted `x`.
|
|
1387
|
+
|
|
1388
|
+
"""
|
|
1389
|
+
ideg = pu._as_int(deg, "deg")
|
|
1390
|
+
if ideg < 0:
|
|
1391
|
+
raise ValueError("deg must be non-negative")
|
|
1392
|
+
|
|
1393
|
+
x = np.array(x, copy=None, ndmin=1) + 0.0
|
|
1394
|
+
dims = (ideg + 1,) + x.shape
|
|
1395
|
+
dtyp = x.dtype
|
|
1396
|
+
v = np.empty(dims, dtype=dtyp)
|
|
1397
|
+
# Use forward recursion to generate the entries.
|
|
1398
|
+
v[0] = x * 0 + 1
|
|
1399
|
+
if ideg > 0:
|
|
1400
|
+
x2 = 2 * x
|
|
1401
|
+
v[1] = x
|
|
1402
|
+
for i in range(2, ideg + 1):
|
|
1403
|
+
v[i] = v[i - 1] * x2 - v[i - 2]
|
|
1404
|
+
return np.moveaxis(v, 0, -1)
|
|
1405
|
+
|
|
1406
|
+
|
|
1407
|
+
def chebvander2d(x, y, deg):
|
|
1408
|
+
"""Pseudo-Vandermonde matrix of given degrees.
|
|
1409
|
+
|
|
1410
|
+
Returns the pseudo-Vandermonde matrix of degrees `deg` and sample
|
|
1411
|
+
points ``(x, y)``. The pseudo-Vandermonde matrix is defined by
|
|
1412
|
+
|
|
1413
|
+
.. math:: V[..., (deg[1] + 1)*i + j] = T_i(x) * T_j(y),
|
|
1414
|
+
|
|
1415
|
+
where ``0 <= i <= deg[0]`` and ``0 <= j <= deg[1]``. The leading indices of
|
|
1416
|
+
`V` index the points ``(x, y)`` and the last index encodes the degrees of
|
|
1417
|
+
the Chebyshev polynomials.
|
|
1418
|
+
|
|
1419
|
+
If ``V = chebvander2d(x, y, [xdeg, ydeg])``, then the columns of `V`
|
|
1420
|
+
correspond to the elements of a 2-D coefficient array `c` of shape
|
|
1421
|
+
(xdeg + 1, ydeg + 1) in the order
|
|
1422
|
+
|
|
1423
|
+
.. math:: c_{00}, c_{01}, c_{02} ... , c_{10}, c_{11}, c_{12} ...
|
|
1424
|
+
|
|
1425
|
+
and ``np.dot(V, c.flat)`` and ``chebval2d(x, y, c)`` will be the same
|
|
1426
|
+
up to roundoff. This equivalence is useful both for least squares
|
|
1427
|
+
fitting and for the evaluation of a large number of 2-D Chebyshev
|
|
1428
|
+
series of the same degrees and sample points.
|
|
1429
|
+
|
|
1430
|
+
Parameters
|
|
1431
|
+
----------
|
|
1432
|
+
x, y : array_like
|
|
1433
|
+
Arrays of point coordinates, all of the same shape. The dtypes
|
|
1434
|
+
will be converted to either float64 or complex128 depending on
|
|
1435
|
+
whether any of the elements are complex. Scalars are converted to
|
|
1436
|
+
1-D arrays.
|
|
1437
|
+
deg : list of ints
|
|
1438
|
+
List of maximum degrees of the form [x_deg, y_deg].
|
|
1439
|
+
|
|
1440
|
+
Returns
|
|
1441
|
+
-------
|
|
1442
|
+
vander2d : ndarray
|
|
1443
|
+
The shape of the returned matrix is ``x.shape + (order,)``, where
|
|
1444
|
+
:math:`order = (deg[0]+1)*(deg[1]+1)`. The dtype will be the same
|
|
1445
|
+
as the converted `x` and `y`.
|
|
1446
|
+
|
|
1447
|
+
See Also
|
|
1448
|
+
--------
|
|
1449
|
+
chebvander, chebvander3d, chebval2d, chebval3d
|
|
1450
|
+
"""
|
|
1451
|
+
return pu._vander_nd_flat((chebvander, chebvander), (x, y), deg)
|
|
1452
|
+
|
|
1453
|
+
|
|
1454
|
+
def chebvander3d(x, y, z, deg):
|
|
1455
|
+
"""Pseudo-Vandermonde matrix of given degrees.
|
|
1456
|
+
|
|
1457
|
+
Returns the pseudo-Vandermonde matrix of degrees `deg` and sample
|
|
1458
|
+
points ``(x, y, z)``. If `l`, `m`, `n` are the given degrees in `x`, `y`, `z`,
|
|
1459
|
+
then The pseudo-Vandermonde matrix is defined by
|
|
1460
|
+
|
|
1461
|
+
.. math:: V[..., (m+1)(n+1)i + (n+1)j + k] = T_i(x)*T_j(y)*T_k(z),
|
|
1462
|
+
|
|
1463
|
+
where ``0 <= i <= l``, ``0 <= j <= m``, and ``0 <= j <= n``. The leading
|
|
1464
|
+
indices of `V` index the points ``(x, y, z)`` and the last index encodes
|
|
1465
|
+
the degrees of the Chebyshev polynomials.
|
|
1466
|
+
|
|
1467
|
+
If ``V = chebvander3d(x, y, z, [xdeg, ydeg, zdeg])``, then the columns
|
|
1468
|
+
of `V` correspond to the elements of a 3-D coefficient array `c` of
|
|
1469
|
+
shape (xdeg + 1, ydeg + 1, zdeg + 1) in the order
|
|
1470
|
+
|
|
1471
|
+
.. math:: c_{000}, c_{001}, c_{002},... , c_{010}, c_{011}, c_{012},...
|
|
1472
|
+
|
|
1473
|
+
and ``np.dot(V, c.flat)`` and ``chebval3d(x, y, z, c)`` will be the
|
|
1474
|
+
same up to roundoff. This equivalence is useful both for least squares
|
|
1475
|
+
fitting and for the evaluation of a large number of 3-D Chebyshev
|
|
1476
|
+
series of the same degrees and sample points.
|
|
1477
|
+
|
|
1478
|
+
Parameters
|
|
1479
|
+
----------
|
|
1480
|
+
x, y, z : array_like
|
|
1481
|
+
Arrays of point coordinates, all of the same shape. The dtypes will
|
|
1482
|
+
be converted to either float64 or complex128 depending on whether
|
|
1483
|
+
any of the elements are complex. Scalars are converted to 1-D
|
|
1484
|
+
arrays.
|
|
1485
|
+
deg : list of ints
|
|
1486
|
+
List of maximum degrees of the form [x_deg, y_deg, z_deg].
|
|
1487
|
+
|
|
1488
|
+
Returns
|
|
1489
|
+
-------
|
|
1490
|
+
vander3d : ndarray
|
|
1491
|
+
The shape of the returned matrix is ``x.shape + (order,)``, where
|
|
1492
|
+
:math:`order = (deg[0]+1)*(deg[1]+1)*(deg[2]+1)`. The dtype will
|
|
1493
|
+
be the same as the converted `x`, `y`, and `z`.
|
|
1494
|
+
|
|
1495
|
+
See Also
|
|
1496
|
+
--------
|
|
1497
|
+
chebvander, chebvander3d, chebval2d, chebval3d
|
|
1498
|
+
"""
|
|
1499
|
+
return pu._vander_nd_flat((chebvander, chebvander, chebvander), (x, y, z), deg)
|
|
1500
|
+
|
|
1501
|
+
|
|
1502
|
+
def chebfit(x, y, deg, rcond=None, full=False, w=None):
|
|
1503
|
+
"""
|
|
1504
|
+
Least squares fit of Chebyshev series to data.
|
|
1505
|
+
|
|
1506
|
+
Return the coefficients of a Chebyshev series of degree `deg` that is the
|
|
1507
|
+
least squares fit to the data values `y` given at points `x`. If `y` is
|
|
1508
|
+
1-D the returned coefficients will also be 1-D. If `y` is 2-D multiple
|
|
1509
|
+
fits are done, one for each column of `y`, and the resulting
|
|
1510
|
+
coefficients are stored in the corresponding columns of a 2-D return.
|
|
1511
|
+
The fitted polynomial(s) are in the form
|
|
1512
|
+
|
|
1513
|
+
.. math:: p(x) = c_0 + c_1 * T_1(x) + ... + c_n * T_n(x),
|
|
1514
|
+
|
|
1515
|
+
where `n` is `deg`.
|
|
1516
|
+
|
|
1517
|
+
Parameters
|
|
1518
|
+
----------
|
|
1519
|
+
x : array_like, shape (M,)
|
|
1520
|
+
x-coordinates of the M sample points ``(x[i], y[i])``.
|
|
1521
|
+
y : array_like, shape (M,) or (M, K)
|
|
1522
|
+
y-coordinates of the sample points. Several data sets of sample
|
|
1523
|
+
points sharing the same x-coordinates can be fitted at once by
|
|
1524
|
+
passing in a 2D-array that contains one dataset per column.
|
|
1525
|
+
deg : int or 1-D array_like
|
|
1526
|
+
Degree(s) of the fitting polynomials. If `deg` is a single integer,
|
|
1527
|
+
all terms up to and including the `deg`'th term are included in the
|
|
1528
|
+
fit. For NumPy versions >= 1.11.0 a list of integers specifying the
|
|
1529
|
+
degrees of the terms to include may be used instead.
|
|
1530
|
+
rcond : float, optional
|
|
1531
|
+
Relative condition number of the fit. Singular values smaller than
|
|
1532
|
+
this relative to the largest singular value will be ignored. The
|
|
1533
|
+
default value is ``len(x)*eps``, where eps is the relative precision of
|
|
1534
|
+
the float type, about 2e-16 in most cases.
|
|
1535
|
+
full : bool, optional
|
|
1536
|
+
Switch determining nature of return value. When it is False (the
|
|
1537
|
+
default) just the coefficients are returned, when True diagnostic
|
|
1538
|
+
information from the singular value decomposition is also returned.
|
|
1539
|
+
w : array_like, shape (`M`,), optional
|
|
1540
|
+
Weights. If not None, the weight ``w[i]`` applies to the unsquared
|
|
1541
|
+
residual ``y[i] - y_hat[i]`` at ``x[i]``. Ideally the weights are
|
|
1542
|
+
chosen so that the errors of the products ``w[i]*y[i]`` all have the
|
|
1543
|
+
same variance. When using inverse-variance weighting, use
|
|
1544
|
+
``w[i] = 1/sigma(y[i])``. The default value is None.
|
|
1545
|
+
|
|
1546
|
+
Returns
|
|
1547
|
+
-------
|
|
1548
|
+
coef : ndarray, shape (M,) or (M, K)
|
|
1549
|
+
Chebyshev coefficients ordered from low to high. If `y` was 2-D,
|
|
1550
|
+
the coefficients for the data in column k of `y` are in column
|
|
1551
|
+
`k`.
|
|
1552
|
+
|
|
1553
|
+
[residuals, rank, singular_values, rcond] : list
|
|
1554
|
+
These values are only returned if ``full == True``
|
|
1555
|
+
|
|
1556
|
+
- residuals -- sum of squared residuals of the least squares fit
|
|
1557
|
+
- rank -- the numerical rank of the scaled Vandermonde matrix
|
|
1558
|
+
- singular_values -- singular values of the scaled Vandermonde matrix
|
|
1559
|
+
- rcond -- value of `rcond`.
|
|
1560
|
+
|
|
1561
|
+
For more details, see `numpy.linalg.lstsq`.
|
|
1562
|
+
|
|
1563
|
+
Warns
|
|
1564
|
+
-----
|
|
1565
|
+
RankWarning
|
|
1566
|
+
The rank of the coefficient matrix in the least-squares fit is
|
|
1567
|
+
deficient. The warning is only raised if ``full == False``. The
|
|
1568
|
+
warnings can be turned off by
|
|
1569
|
+
|
|
1570
|
+
>>> import warnings
|
|
1571
|
+
>>> warnings.simplefilter('ignore', np.exceptions.RankWarning)
|
|
1572
|
+
|
|
1573
|
+
See Also
|
|
1574
|
+
--------
|
|
1575
|
+
numpy.polynomial.polynomial.polyfit
|
|
1576
|
+
numpy.polynomial.legendre.legfit
|
|
1577
|
+
numpy.polynomial.laguerre.lagfit
|
|
1578
|
+
numpy.polynomial.hermite.hermfit
|
|
1579
|
+
numpy.polynomial.hermite_e.hermefit
|
|
1580
|
+
chebval : Evaluates a Chebyshev series.
|
|
1581
|
+
chebvander : Vandermonde matrix of Chebyshev series.
|
|
1582
|
+
chebweight : Chebyshev weight function.
|
|
1583
|
+
numpy.linalg.lstsq : Computes a least-squares fit from the matrix.
|
|
1584
|
+
scipy.interpolate.UnivariateSpline : Computes spline fits.
|
|
1585
|
+
|
|
1586
|
+
Notes
|
|
1587
|
+
-----
|
|
1588
|
+
The solution is the coefficients of the Chebyshev series `p` that
|
|
1589
|
+
minimizes the sum of the weighted squared errors
|
|
1590
|
+
|
|
1591
|
+
.. math:: E = \\sum_j w_j^2 * |y_j - p(x_j)|^2,
|
|
1592
|
+
|
|
1593
|
+
where :math:`w_j` are the weights. This problem is solved by setting up
|
|
1594
|
+
as the (typically) overdetermined matrix equation
|
|
1595
|
+
|
|
1596
|
+
.. math:: V(x) * c = w * y,
|
|
1597
|
+
|
|
1598
|
+
where `V` is the weighted pseudo Vandermonde matrix of `x`, `c` are the
|
|
1599
|
+
coefficients to be solved for, `w` are the weights, and `y` are the
|
|
1600
|
+
observed values. This equation is then solved using the singular value
|
|
1601
|
+
decomposition of `V`.
|
|
1602
|
+
|
|
1603
|
+
If some of the singular values of `V` are so small that they are
|
|
1604
|
+
neglected, then a `~exceptions.RankWarning` will be issued. This means that
|
|
1605
|
+
the coefficient values may be poorly determined. Using a lower order fit
|
|
1606
|
+
will usually get rid of the warning. The `rcond` parameter can also be
|
|
1607
|
+
set to a value smaller than its default, but the resulting fit may be
|
|
1608
|
+
spurious and have large contributions from roundoff error.
|
|
1609
|
+
|
|
1610
|
+
Fits using Chebyshev series are usually better conditioned than fits
|
|
1611
|
+
using power series, but much can depend on the distribution of the
|
|
1612
|
+
sample points and the smoothness of the data. If the quality of the fit
|
|
1613
|
+
is inadequate splines may be a good alternative.
|
|
1614
|
+
|
|
1615
|
+
References
|
|
1616
|
+
----------
|
|
1617
|
+
.. [1] Wikipedia, "Curve fitting",
|
|
1618
|
+
https://en.wikipedia.org/wiki/Curve_fitting
|
|
1619
|
+
|
|
1620
|
+
Examples
|
|
1621
|
+
--------
|
|
1622
|
+
|
|
1623
|
+
"""
|
|
1624
|
+
return pu._fit(chebvander, x, y, deg, rcond, full, w)
|
|
1625
|
+
|
|
1626
|
+
|
|
1627
|
+
def chebcompanion(c):
|
|
1628
|
+
"""Return the scaled companion matrix of c.
|
|
1629
|
+
|
|
1630
|
+
The basis polynomials are scaled so that the companion matrix is
|
|
1631
|
+
symmetric when `c` is a Chebyshev basis polynomial. This provides
|
|
1632
|
+
better eigenvalue estimates than the unscaled case and for basis
|
|
1633
|
+
polynomials the eigenvalues are guaranteed to be real if
|
|
1634
|
+
`numpy.linalg.eigvalsh` is used to obtain them.
|
|
1635
|
+
|
|
1636
|
+
Parameters
|
|
1637
|
+
----------
|
|
1638
|
+
c : array_like
|
|
1639
|
+
1-D array of Chebyshev series coefficients ordered from low to high
|
|
1640
|
+
degree.
|
|
1641
|
+
|
|
1642
|
+
Returns
|
|
1643
|
+
-------
|
|
1644
|
+
mat : ndarray
|
|
1645
|
+
Scaled companion matrix of dimensions (deg, deg).
|
|
1646
|
+
"""
|
|
1647
|
+
# c is a trimmed copy
|
|
1648
|
+
[c] = pu.as_series([c])
|
|
1649
|
+
if len(c) < 2:
|
|
1650
|
+
raise ValueError('Series must have maximum degree of at least 1.')
|
|
1651
|
+
if len(c) == 2:
|
|
1652
|
+
return np.array([[-c[0] / c[1]]])
|
|
1653
|
+
|
|
1654
|
+
n = len(c) - 1
|
|
1655
|
+
mat = np.zeros((n, n), dtype=c.dtype)
|
|
1656
|
+
scl = np.array([1.] + [np.sqrt(.5)] * (n - 1))
|
|
1657
|
+
top = mat.reshape(-1)[1::n + 1]
|
|
1658
|
+
bot = mat.reshape(-1)[n::n + 1]
|
|
1659
|
+
top[0] = np.sqrt(.5)
|
|
1660
|
+
top[1:] = 1 / 2
|
|
1661
|
+
bot[...] = top
|
|
1662
|
+
mat[:, -1] -= (c[:-1] / c[-1]) * (scl / scl[-1]) * .5
|
|
1663
|
+
return mat
|
|
1664
|
+
|
|
1665
|
+
|
|
1666
|
+
def chebroots(c):
|
|
1667
|
+
"""
|
|
1668
|
+
Compute the roots of a Chebyshev series.
|
|
1669
|
+
|
|
1670
|
+
Return the roots (a.k.a. "zeros") of the polynomial
|
|
1671
|
+
|
|
1672
|
+
.. math:: p(x) = \\sum_i c[i] * T_i(x).
|
|
1673
|
+
|
|
1674
|
+
Parameters
|
|
1675
|
+
----------
|
|
1676
|
+
c : 1-D array_like
|
|
1677
|
+
1-D array of coefficients.
|
|
1678
|
+
|
|
1679
|
+
Returns
|
|
1680
|
+
-------
|
|
1681
|
+
out : ndarray
|
|
1682
|
+
Array of the roots of the series. If all the roots are real,
|
|
1683
|
+
then `out` is also real, otherwise it is complex.
|
|
1684
|
+
|
|
1685
|
+
See Also
|
|
1686
|
+
--------
|
|
1687
|
+
numpy.polynomial.polynomial.polyroots
|
|
1688
|
+
numpy.polynomial.legendre.legroots
|
|
1689
|
+
numpy.polynomial.laguerre.lagroots
|
|
1690
|
+
numpy.polynomial.hermite.hermroots
|
|
1691
|
+
numpy.polynomial.hermite_e.hermeroots
|
|
1692
|
+
|
|
1693
|
+
Notes
|
|
1694
|
+
-----
|
|
1695
|
+
The root estimates are obtained as the eigenvalues of the companion
|
|
1696
|
+
matrix, Roots far from the origin of the complex plane may have large
|
|
1697
|
+
errors due to the numerical instability of the series for such
|
|
1698
|
+
values. Roots with multiplicity greater than 1 will also show larger
|
|
1699
|
+
errors as the value of the series near such points is relatively
|
|
1700
|
+
insensitive to errors in the roots. Isolated roots near the origin can
|
|
1701
|
+
be improved by a few iterations of Newton's method.
|
|
1702
|
+
|
|
1703
|
+
The Chebyshev series basis polynomials aren't powers of `x` so the
|
|
1704
|
+
results of this function may seem unintuitive.
|
|
1705
|
+
|
|
1706
|
+
Examples
|
|
1707
|
+
--------
|
|
1708
|
+
>>> import numpy.polynomial.chebyshev as cheb
|
|
1709
|
+
>>> cheb.chebroots((-1, 1,-1, 1)) # T3 - T2 + T1 - T0 has real roots
|
|
1710
|
+
array([ -5.00000000e-01, 2.60860684e-17, 1.00000000e+00]) # may vary
|
|
1711
|
+
|
|
1712
|
+
"""
|
|
1713
|
+
# c is a trimmed copy
|
|
1714
|
+
[c] = pu.as_series([c])
|
|
1715
|
+
if len(c) < 2:
|
|
1716
|
+
return np.array([], dtype=c.dtype)
|
|
1717
|
+
if len(c) == 2:
|
|
1718
|
+
return np.array([-c[0] / c[1]])
|
|
1719
|
+
|
|
1720
|
+
# rotated companion matrix reduces error
|
|
1721
|
+
m = chebcompanion(c)[::-1, ::-1]
|
|
1722
|
+
r = np.linalg.eigvals(m)
|
|
1723
|
+
r.sort()
|
|
1724
|
+
return r
|
|
1725
|
+
|
|
1726
|
+
|
|
1727
|
+
def chebinterpolate(func, deg, args=()):
|
|
1728
|
+
"""Interpolate a function at the Chebyshev points of the first kind.
|
|
1729
|
+
|
|
1730
|
+
Returns the Chebyshev series that interpolates `func` at the Chebyshev
|
|
1731
|
+
points of the first kind in the interval [-1, 1]. The interpolating
|
|
1732
|
+
series tends to a minmax approximation to `func` with increasing `deg`
|
|
1733
|
+
if the function is continuous in the interval.
|
|
1734
|
+
|
|
1735
|
+
Parameters
|
|
1736
|
+
----------
|
|
1737
|
+
func : function
|
|
1738
|
+
The function to be approximated. It must be a function of a single
|
|
1739
|
+
variable of the form ``f(x, a, b, c...)``, where ``a, b, c...`` are
|
|
1740
|
+
extra arguments passed in the `args` parameter.
|
|
1741
|
+
deg : int
|
|
1742
|
+
Degree of the interpolating polynomial
|
|
1743
|
+
args : tuple, optional
|
|
1744
|
+
Extra arguments to be used in the function call. Default is no extra
|
|
1745
|
+
arguments.
|
|
1746
|
+
|
|
1747
|
+
Returns
|
|
1748
|
+
-------
|
|
1749
|
+
coef : ndarray, shape (deg + 1,)
|
|
1750
|
+
Chebyshev coefficients of the interpolating series ordered from low to
|
|
1751
|
+
high.
|
|
1752
|
+
|
|
1753
|
+
Examples
|
|
1754
|
+
--------
|
|
1755
|
+
>>> import numpy.polynomial.chebyshev as C
|
|
1756
|
+
>>> C.chebinterpolate(lambda x: np.tanh(x) + 0.5, 8)
|
|
1757
|
+
array([ 5.00000000e-01, 8.11675684e-01, -9.86864911e-17,
|
|
1758
|
+
-5.42457905e-02, -2.71387850e-16, 4.51658839e-03,
|
|
1759
|
+
2.46716228e-17, -3.79694221e-04, -3.26899002e-16])
|
|
1760
|
+
|
|
1761
|
+
Notes
|
|
1762
|
+
-----
|
|
1763
|
+
The Chebyshev polynomials used in the interpolation are orthogonal when
|
|
1764
|
+
sampled at the Chebyshev points of the first kind. If it is desired to
|
|
1765
|
+
constrain some of the coefficients they can simply be set to the desired
|
|
1766
|
+
value after the interpolation, no new interpolation or fit is needed. This
|
|
1767
|
+
is especially useful if it is known apriori that some of coefficients are
|
|
1768
|
+
zero. For instance, if the function is even then the coefficients of the
|
|
1769
|
+
terms of odd degree in the result can be set to zero.
|
|
1770
|
+
|
|
1771
|
+
"""
|
|
1772
|
+
deg = np.asarray(deg)
|
|
1773
|
+
|
|
1774
|
+
# check arguments.
|
|
1775
|
+
if deg.ndim > 0 or deg.dtype.kind not in 'iu' or deg.size == 0:
|
|
1776
|
+
raise TypeError("deg must be an int")
|
|
1777
|
+
if deg < 0:
|
|
1778
|
+
raise ValueError("expected deg >= 0")
|
|
1779
|
+
|
|
1780
|
+
order = deg + 1
|
|
1781
|
+
xcheb = chebpts1(order)
|
|
1782
|
+
yfunc = func(xcheb, *args)
|
|
1783
|
+
m = chebvander(xcheb, deg)
|
|
1784
|
+
c = np.dot(m.T, yfunc)
|
|
1785
|
+
c[0] /= order
|
|
1786
|
+
c[1:] /= 0.5 * order
|
|
1787
|
+
|
|
1788
|
+
return c
|
|
1789
|
+
|
|
1790
|
+
|
|
1791
|
+
def chebgauss(deg):
|
|
1792
|
+
"""
|
|
1793
|
+
Gauss-Chebyshev quadrature.
|
|
1794
|
+
|
|
1795
|
+
Computes the sample points and weights for Gauss-Chebyshev quadrature.
|
|
1796
|
+
These sample points and weights will correctly integrate polynomials of
|
|
1797
|
+
degree :math:`2*deg - 1` or less over the interval :math:`[-1, 1]` with
|
|
1798
|
+
the weight function :math:`f(x) = 1/\\sqrt{1 - x^2}`.
|
|
1799
|
+
|
|
1800
|
+
Parameters
|
|
1801
|
+
----------
|
|
1802
|
+
deg : int
|
|
1803
|
+
Number of sample points and weights. It must be >= 1.
|
|
1804
|
+
|
|
1805
|
+
Returns
|
|
1806
|
+
-------
|
|
1807
|
+
x : ndarray
|
|
1808
|
+
1-D ndarray containing the sample points.
|
|
1809
|
+
y : ndarray
|
|
1810
|
+
1-D ndarray containing the weights.
|
|
1811
|
+
|
|
1812
|
+
Notes
|
|
1813
|
+
-----
|
|
1814
|
+
The results have only been tested up to degree 100, higher degrees may
|
|
1815
|
+
be problematic. For Gauss-Chebyshev there are closed form solutions for
|
|
1816
|
+
the sample points and weights. If n = `deg`, then
|
|
1817
|
+
|
|
1818
|
+
.. math:: x_i = \\cos(\\pi (2 i - 1) / (2 n))
|
|
1819
|
+
|
|
1820
|
+
.. math:: w_i = \\pi / n
|
|
1821
|
+
|
|
1822
|
+
"""
|
|
1823
|
+
ideg = pu._as_int(deg, "deg")
|
|
1824
|
+
if ideg <= 0:
|
|
1825
|
+
raise ValueError("deg must be a positive integer")
|
|
1826
|
+
|
|
1827
|
+
x = np.cos(np.pi * np.arange(1, 2 * ideg, 2) / (2.0 * ideg))
|
|
1828
|
+
w = np.ones(ideg) * (np.pi / ideg)
|
|
1829
|
+
|
|
1830
|
+
return x, w
|
|
1831
|
+
|
|
1832
|
+
|
|
1833
|
+
def chebweight(x):
|
|
1834
|
+
"""
|
|
1835
|
+
The weight function of the Chebyshev polynomials.
|
|
1836
|
+
|
|
1837
|
+
The weight function is :math:`1/\\sqrt{1 - x^2}` and the interval of
|
|
1838
|
+
integration is :math:`[-1, 1]`. The Chebyshev polynomials are
|
|
1839
|
+
orthogonal, but not normalized, with respect to this weight function.
|
|
1840
|
+
|
|
1841
|
+
Parameters
|
|
1842
|
+
----------
|
|
1843
|
+
x : array_like
|
|
1844
|
+
Values at which the weight function will be computed.
|
|
1845
|
+
|
|
1846
|
+
Returns
|
|
1847
|
+
-------
|
|
1848
|
+
w : ndarray
|
|
1849
|
+
The weight function at `x`.
|
|
1850
|
+
"""
|
|
1851
|
+
w = 1. / (np.sqrt(1. + x) * np.sqrt(1. - x))
|
|
1852
|
+
return w
|
|
1853
|
+
|
|
1854
|
+
|
|
1855
|
+
def chebpts1(npts):
|
|
1856
|
+
"""
|
|
1857
|
+
Chebyshev points of the first kind.
|
|
1858
|
+
|
|
1859
|
+
The Chebyshev points of the first kind are the points ``cos(x)``,
|
|
1860
|
+
where ``x = [pi*(k + .5)/npts for k in range(npts)]``.
|
|
1861
|
+
|
|
1862
|
+
Parameters
|
|
1863
|
+
----------
|
|
1864
|
+
npts : int
|
|
1865
|
+
Number of sample points desired.
|
|
1866
|
+
|
|
1867
|
+
Returns
|
|
1868
|
+
-------
|
|
1869
|
+
pts : ndarray
|
|
1870
|
+
The Chebyshev points of the first kind.
|
|
1871
|
+
|
|
1872
|
+
See Also
|
|
1873
|
+
--------
|
|
1874
|
+
chebpts2
|
|
1875
|
+
"""
|
|
1876
|
+
_npts = int(npts)
|
|
1877
|
+
if _npts != npts:
|
|
1878
|
+
raise ValueError("npts must be integer")
|
|
1879
|
+
if _npts < 1:
|
|
1880
|
+
raise ValueError("npts must be >= 1")
|
|
1881
|
+
|
|
1882
|
+
x = 0.5 * np.pi / _npts * np.arange(-_npts + 1, _npts + 1, 2)
|
|
1883
|
+
return np.sin(x)
|
|
1884
|
+
|
|
1885
|
+
|
|
1886
|
+
def chebpts2(npts):
|
|
1887
|
+
"""
|
|
1888
|
+
Chebyshev points of the second kind.
|
|
1889
|
+
|
|
1890
|
+
The Chebyshev points of the second kind are the points ``cos(x)``,
|
|
1891
|
+
where ``x = [pi*k/(npts - 1) for k in range(npts)]`` sorted in ascending
|
|
1892
|
+
order.
|
|
1893
|
+
|
|
1894
|
+
Parameters
|
|
1895
|
+
----------
|
|
1896
|
+
npts : int
|
|
1897
|
+
Number of sample points desired.
|
|
1898
|
+
|
|
1899
|
+
Returns
|
|
1900
|
+
-------
|
|
1901
|
+
pts : ndarray
|
|
1902
|
+
The Chebyshev points of the second kind.
|
|
1903
|
+
"""
|
|
1904
|
+
_npts = int(npts)
|
|
1905
|
+
if _npts != npts:
|
|
1906
|
+
raise ValueError("npts must be integer")
|
|
1907
|
+
if _npts < 2:
|
|
1908
|
+
raise ValueError("npts must be >= 2")
|
|
1909
|
+
|
|
1910
|
+
x = np.linspace(-np.pi, 0, _npts)
|
|
1911
|
+
return np.cos(x)
|
|
1912
|
+
|
|
1913
|
+
|
|
1914
|
+
#
|
|
1915
|
+
# Chebyshev series class
|
|
1916
|
+
#
|
|
1917
|
+
|
|
1918
|
+
class Chebyshev(ABCPolyBase):
|
|
1919
|
+
"""A Chebyshev series class.
|
|
1920
|
+
|
|
1921
|
+
The Chebyshev class provides the standard Python numerical methods
|
|
1922
|
+
'+', '-', '*', '//', '%', 'divmod', '**', and '()' as well as the
|
|
1923
|
+
attributes and methods listed below.
|
|
1924
|
+
|
|
1925
|
+
Parameters
|
|
1926
|
+
----------
|
|
1927
|
+
coef : array_like
|
|
1928
|
+
Chebyshev coefficients in order of increasing degree, i.e.,
|
|
1929
|
+
``(1, 2, 3)`` gives ``1*T_0(x) + 2*T_1(x) + 3*T_2(x)``.
|
|
1930
|
+
domain : (2,) array_like, optional
|
|
1931
|
+
Domain to use. The interval ``[domain[0], domain[1]]`` is mapped
|
|
1932
|
+
to the interval ``[window[0], window[1]]`` by shifting and scaling.
|
|
1933
|
+
The default value is [-1., 1.].
|
|
1934
|
+
window : (2,) array_like, optional
|
|
1935
|
+
Window, see `domain` for its use. The default value is [-1., 1.].
|
|
1936
|
+
symbol : str, optional
|
|
1937
|
+
Symbol used to represent the independent variable in string
|
|
1938
|
+
representations of the polynomial expression, e.g. for printing.
|
|
1939
|
+
The symbol must be a valid Python identifier. Default value is 'x'.
|
|
1940
|
+
|
|
1941
|
+
.. versionadded:: 1.24
|
|
1942
|
+
|
|
1943
|
+
"""
|
|
1944
|
+
# Virtual Functions
|
|
1945
|
+
_add = staticmethod(chebadd)
|
|
1946
|
+
_sub = staticmethod(chebsub)
|
|
1947
|
+
_mul = staticmethod(chebmul)
|
|
1948
|
+
_div = staticmethod(chebdiv)
|
|
1949
|
+
_pow = staticmethod(chebpow)
|
|
1950
|
+
_val = staticmethod(chebval)
|
|
1951
|
+
_int = staticmethod(chebint)
|
|
1952
|
+
_der = staticmethod(chebder)
|
|
1953
|
+
_fit = staticmethod(chebfit)
|
|
1954
|
+
_line = staticmethod(chebline)
|
|
1955
|
+
_roots = staticmethod(chebroots)
|
|
1956
|
+
_fromroots = staticmethod(chebfromroots)
|
|
1957
|
+
|
|
1958
|
+
@classmethod
|
|
1959
|
+
def interpolate(cls, func, deg, domain=None, args=()):
|
|
1960
|
+
"""Interpolate a function at the Chebyshev points of the first kind.
|
|
1961
|
+
|
|
1962
|
+
Returns the series that interpolates `func` at the Chebyshev points of
|
|
1963
|
+
the first kind scaled and shifted to the `domain`. The resulting series
|
|
1964
|
+
tends to a minmax approximation of `func` when the function is
|
|
1965
|
+
continuous in the domain.
|
|
1966
|
+
|
|
1967
|
+
Parameters
|
|
1968
|
+
----------
|
|
1969
|
+
func : function
|
|
1970
|
+
The function to be interpolated. It must be a function of a single
|
|
1971
|
+
variable of the form ``f(x, a, b, c...)``, where ``a, b, c...`` are
|
|
1972
|
+
extra arguments passed in the `args` parameter.
|
|
1973
|
+
deg : int
|
|
1974
|
+
Degree of the interpolating polynomial.
|
|
1975
|
+
domain : {None, [beg, end]}, optional
|
|
1976
|
+
Domain over which `func` is interpolated. The default is None, in
|
|
1977
|
+
which case the domain is [-1, 1].
|
|
1978
|
+
args : tuple, optional
|
|
1979
|
+
Extra arguments to be used in the function call. Default is no
|
|
1980
|
+
extra arguments.
|
|
1981
|
+
|
|
1982
|
+
Returns
|
|
1983
|
+
-------
|
|
1984
|
+
polynomial : Chebyshev instance
|
|
1985
|
+
Interpolating Chebyshev instance.
|
|
1986
|
+
|
|
1987
|
+
Notes
|
|
1988
|
+
-----
|
|
1989
|
+
See `numpy.polynomial.chebinterpolate` for more details.
|
|
1990
|
+
|
|
1991
|
+
"""
|
|
1992
|
+
if domain is None:
|
|
1993
|
+
domain = cls.domain
|
|
1994
|
+
xfunc = lambda x: func(pu.mapdomain(x, cls.window, domain), *args)
|
|
1995
|
+
coef = chebinterpolate(xfunc, deg)
|
|
1996
|
+
return cls(coef, domain=domain)
|
|
1997
|
+
|
|
1998
|
+
# Virtual properties
|
|
1999
|
+
domain = np.array(chebdomain)
|
|
2000
|
+
window = np.array(chebdomain)
|
|
2001
|
+
basis_name = 'T'
|