Publish 11 evaluated Astra histories with reproducible checkpoint artifacts (part 26)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +30 -0
- shared/package-files/65/6512731e2fb716ccdf6bc9d1a73e84a46619752a4bc867382b7a71af5bb23140/blob +18 -0
- shared/package-files/65/65154ace68128ff3fbe26442d6567408436584d236b02b49f05db6a36b382de9/blob +0 -0
- shared/package-files/65/65195d76a1f8c1eaf87c151a186dc8b0b391a0cb3efda1bbd629d7f43e7e4066/blob +97 -0
- shared/package-files/65/651cd0d9ca28ec9fc297ae69fc5b4c674f76fa849f5fbd4db41cd25dffa62954/blob +43 -0
- shared/package-files/65/651ec2268fdd01e08cf8a95a1afb2482d1d0c91b6b3c8a2573c4443a6728a899/blob +0 -0
- shared/package-files/65/651f27fde7da63b1d6198e979d164a3488915a66acce9354f29db692f01bc844/blob +62 -0
- shared/package-files/65/652009f8f9b89e9fad665f7a61d6cc5c6d98a32e25dbb0818edba4817ae8247d/blob +39 -0
- shared/package-files/65/652016a967fca27d194a33fe30722726137c040b79f79f93f10721ed03b90d5b/blob +22 -0
- shared/package-files/65/65241816cfbd9c205a97fc2222c4db7652ac9bbea7421906b0fc2e8f24f6b7c4/blob +0 -0
- shared/package-files/65/652500877ba19fd08217e718a8ae53366a2c0463dfb2e1c12047ee760cacba7e/blob +8 -0
- shared/package-files/65/652c9b8d7c60b4edc6a3e97d4bc77734c74247fc2028c965122bebf0d0e3c91a/blob +915 -0
- shared/package-files/65/65309a39d3ab82d89f5b1426173ca782b2eaf6ec3307205d8924b9984f830e81/blob +52 -0
- shared/package-files/65/65327f94b5ae5c87675fcd32d4e036df43bc7a9e74a719526b669c6b3bfed60c/blob +12 -0
- shared/package-files/65/65335b1a8e3308414fdf51fa2273128d42ddcdc49bfaf8d112c75eaaf746f8c6/blob +0 -0
- shared/package-files/65/6536ad38eb2d29a5ad11673bf087690eea02298629ea3f544897da41923267e0/blob +0 -0
- shared/package-files/65/6539caf32658a84846de97bc295c2625fe0af3dd1132ef1aeb40389c2feace73/blob +154 -0
- shared/package-files/65/653ad8d50f1c3cb3a0cc4d2876c60aaa40732c42779dea2e1db547639d27b085/blob +168 -0
- shared/package-files/65/653af36faa03ac80cf96b5563f7066b646f3ddf7c769a490a1791f4c6b42b851/blob +45 -0
- shared/package-files/65/6543d52f7eacdc035fe1d8afae22d6a601d8141bdad3dff4f482bb84e4534a7b/blob +47 -0
- shared/package-files/65/654768af0a358adbf8df074b003c954cfdfa888077ce0a1d622adfe034baced2/blob +21 -0
- shared/package-files/65/65489e12e6bf63edf35fa19d1da8de0f7da20bf7d635ac38a21ba2b86493e882/blob +403 -0
- shared/package-files/65/654b5f1cf96836a72f18c1ccc5a2834a5b2184e723c21794c75e37470a467485/blob +573 -0
- shared/package-files/65/654f25a3384d8bb5fb19a60408a60e8ab1ebfaa997699021f0f7b0f0249480c4/blob +3 -0
- shared/package-files/65/65527f26ff875fedd8339b83678ac0fd4e923b10ba9114060887bebf1020623d/blob +212 -0
- shared/package-files/65/6552b64c85b45e35910c17b1d39e329a6565481430f912018442f5c12d990265/blob +12 -0
- shared/package-files/65/6554310415438f47722a6d789aa8a0ffccf4c5f699412c2d69c32cffe6d19cf4/blob +297 -0
- shared/package-files/65/6556137f5f3ab89442327123458e8d6581cd319b7d1cc382b1519dad334d4c2f/blob +784 -0
- shared/package-files/65/655d1425c4b6f9025d86a0eeec8fe7bc3f85f7c0446176dcfc5614cadea7cd15/blob +321 -0
- shared/package-files/65/655f072fc3640e7a1065f9e37bb04fd1fc88a787d216a8cab10738d0f6938207/blob +30 -0
- shared/package-files/65/655fc11bc255b36bda34abe4882dd002df4751fda383120fe40b73ce26af1caa/blob +112 -0
- shared/package-files/65/6561c170208e54dc03c6e25683558fa3492b4c7c759b5c133e2d9c3983ec013e/blob +533 -0
- shared/package-files/65/656751b26fbee66b4f8ed9801ffefed090509af4147c06dafd56d1795c805488/blob +100 -0
- shared/package-files/65/6569586c61e36fe4304691f7490f6ebb19ff5fe1768a1710092e47b53fd6f659/blob +51 -0
- shared/package-files/65/6569619bf0690d6073fd2753ad7b249efd6ff97838f74b008793206dd4a856f9/blob +125 -0
- shared/package-files/65/656cd3a27fe3b73475a1fc9becaf4a4d06d25b482904d8dab14429787a23657d/blob +1 -0
- shared/package-files/65/6570168dd003a845a0766d1a9290a3570b9b5df55fa4381ba9eb7d643a30e37c/blob +0 -0
- shared/package-files/65/65702a9eff6686f57740731d4b0ccaa6b40e4806bead28b7a5c001934698ddae/blob +9 -0
- shared/package-files/65/6571dd3f6ade69c55980dea5a98b31894f9e8f02cb9a1fe650d5f6d8e2f0f076/blob +50 -0
- shared/package-files/65/65720ce3d60b6672e210c490956b7db94cd7e9fc603571f91c843005585c9de2/blob +14 -0
- shared/package-files/65/657312539a4a73294c95f8c0583ea778dc2c6d96cf29aa362b9984bf1e1d4f96/blob +24 -0
- shared/package-files/65/6574e88cfe15e4a95ef7a40e161c42663abe7507fa807bcd3a8ad8c8eb853f52/blob +33 -0
- shared/package-files/65/6576a82fd591eb453c4f3d594ab9fc5e038c2414bbf1d74d070692a3fe48585e/blob +28 -0
- shared/package-files/65/6576ba04d8017df3b1862cf77c8a8a60b68858a27935d77d5b63bcc54f583ec5/blob +694 -0
- shared/package-files/65/6577a652c6bf6f4acbb4f55352480091943511cbb67886716a23524975b43c39/blob +88 -0
- shared/package-files/65/6577b44723d46e5a846f5956d4f6fd7cccac816f1480cabcf26cd7f32675d4b2/blob +182 -0
- shared/package-files/65/65784d7c8e6842e363e76ce4cac43ea12ad00eb5053fe73efc622fd5934df2ff/blob +26 -0
- shared/package-files/65/657977d7f7c5eddc5e48c8e4fd3c4f9d9c2ef5f9270f1e117a1210c161006400/blob +44 -0
- shared/package-files/65/657a9599536399aba131e8935ad082a8e3f7f1bf4c260ed49417596beeda2024/blob +745 -0
- shared/package-files/65/657b2a6520d28ba046425441d6c5d4e05e0bc3b3ce51ba27ca96819eb892eb9b/blob +2 -0
.gitattributes
CHANGED
|
@@ -512,3 +512,33 @@ shared/package-files/64/648d4b2459e15c1d07428fba4ee7db5a71f204ef2d6a1ef1d2af03ae
|
|
| 512 |
shared/package-files/64/649d9eb004a6ce85007014bab15e70a912a8282e5e0986b9b11ae581ddb56728/blob filter=lfs diff=lfs merge=lfs -text
|
| 513 |
shared/package-files/65/650d69a02a6108e36a085bdb8a26b4816c15de9ff0e7579e96a386725f242b03/blob filter=lfs diff=lfs merge=lfs -text
|
| 514 |
shared/package-files/65/650f1d7992e5667f4fbb2fc6a55df254aaeb46f434bbb09fda3f1a25ac5acecd/blob filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 512 |
shared/package-files/64/649d9eb004a6ce85007014bab15e70a912a8282e5e0986b9b11ae581ddb56728/blob filter=lfs diff=lfs merge=lfs -text
|
| 513 |
shared/package-files/65/650d69a02a6108e36a085bdb8a26b4816c15de9ff0e7579e96a386725f242b03/blob filter=lfs diff=lfs merge=lfs -text
|
| 514 |
shared/package-files/65/650f1d7992e5667f4fbb2fc6a55df254aaeb46f434bbb09fda3f1a25ac5acecd/blob filter=lfs diff=lfs merge=lfs -text
|
| 515 |
+
shared/package-files/65/654f25a3384d8bb5fb19a60408a60e8ab1ebfaa997699021f0f7b0f0249480c4/blob filter=lfs diff=lfs merge=lfs -text
|
| 516 |
+
shared/package-files/65/65a762bc0623024c3fbc416ff5df00d8ea275f6c7d691a54c6e0492f459a362f/blob filter=lfs diff=lfs merge=lfs -text
|
| 517 |
+
shared/package-files/65/65d578d79421486df8cb7aa31cd4447392b221c7c564032e745653bc6afdc43d/blob filter=lfs diff=lfs merge=lfs -text
|
| 518 |
+
shared/package-files/66/6662e0d859a88c98d46d24e3097df0f175b63d8d1f82b2e40ee30268dbf805b0/blob filter=lfs diff=lfs merge=lfs -text
|
| 519 |
+
shared/package-files/66/66672c4207e806dd6cf9a6cd527c1f2a33ef354ea272282c8666dcb7d13d4917/blob filter=lfs diff=lfs merge=lfs -text
|
| 520 |
+
shared/package-files/66/66c1b7d4de49394df6ad228e0e7ccc68ad56c4f437a2e84280f907cfb09adb71/blob filter=lfs diff=lfs merge=lfs -text
|
| 521 |
+
shared/package-files/66/66c86ac0034b8aa7970eceeccec4af950c66aa8944c39048bef74d5d8497180d/blob filter=lfs diff=lfs merge=lfs -text
|
| 522 |
+
shared/package-files/66/66db9b0f4a3994a7ace522a4090c3f5ff951b50c47c782f493ff9de2476ba9c0/blob filter=lfs diff=lfs merge=lfs -text
|
| 523 |
+
shared/package-files/66/66ea4dc1422ba30710172ca3d973f154ba083a30fd5e2007b1922757644a3fc1/blob filter=lfs diff=lfs merge=lfs -text
|
| 524 |
+
shared/package-files/67/674852d5b34a530015c2975083f8a8cc5f6aeb1331dfec723bfba6fa9660ee11/blob filter=lfs diff=lfs merge=lfs -text
|
| 525 |
+
shared/package-files/67/674e0d5405223ac96d35d4c3553c705f6ffad82d149917659366bafcf9635bd2/blob filter=lfs diff=lfs merge=lfs -text
|
| 526 |
+
shared/package-files/67/67794cb3e28fb5cd27142e87f1639474952bb39d9ff24bc717f9a6080f6d22ed/blob filter=lfs diff=lfs merge=lfs -text
|
| 527 |
+
shared/package-files/67/67a7403a52ed53c852682f81a40c615503a09d1c32206d7265ff256f4a730c8c/blob filter=lfs diff=lfs merge=lfs -text
|
| 528 |
+
shared/package-files/67/67c96a7dabd179533f0961bfe54f2b97b6a8cc5a8c70516b822f75a1ae4148c1/blob filter=lfs diff=lfs merge=lfs -text
|
| 529 |
+
shared/package-files/68/682258f3d7c9e1c78238338baf0679a032a06924b449500b0bb742c34a0f7258/blob filter=lfs diff=lfs merge=lfs -text
|
| 530 |
+
shared/package-files/68/688c6392bde63a40c1da3f8f2963591934f8fc2dd4786339e018139edfcbcc5f/blob filter=lfs diff=lfs merge=lfs -text
|
| 531 |
+
shared/package-files/69/69a251a1a412dbfefe9eb03f142acc18aba7aab51667b4a064f8a11ed8976792/blob filter=lfs diff=lfs merge=lfs -text
|
| 532 |
+
shared/package-files/69/69aaf1cfa75ab13241117e0b4b28ba59351fd911b353eaf439141575c9f62663/blob filter=lfs diff=lfs merge=lfs -text
|
| 533 |
+
shared/package-files/69/69cd9526b4680f659a38a554fffc22d0a90902ffda74f7e9725661caecb5abf0/blob filter=lfs diff=lfs merge=lfs -text
|
| 534 |
+
shared/package-files/69/69fdbc3183b1036a31ac6e986b3cf607421d85cedd425755b68f5907d9fd283f/blob filter=lfs diff=lfs merge=lfs -text
|
| 535 |
+
shared/package-files/6a/6a12e1a7b13824d14c252d2a4d2e36af467383331a114eb0e7448eecbf02d7b1/blob filter=lfs diff=lfs merge=lfs -text
|
| 536 |
+
shared/package-files/6a/6ab63cf2443420bfa5f2a817a90432dfc969348a8b23b0e6ccf3ffad3c381672/blob filter=lfs diff=lfs merge=lfs -text
|
| 537 |
+
shared/package-files/6a/6ac747a6f79a2e18272f382edf28744b028359e67c95c4b715c882a1f3967a05/blob filter=lfs diff=lfs merge=lfs -text
|
| 538 |
+
shared/package-files/6a/6afab52e0843519329788a5b1115adf9c509ae76346b28a5ff3d02149d50595d/blob filter=lfs diff=lfs merge=lfs -text
|
| 539 |
+
shared/package-files/6b/6bbd6258a97ceb8c5ee9a8a2533fd0ea9eaf2e5b2c055bd941a8697d1e870ffa/blob filter=lfs diff=lfs merge=lfs -text
|
| 540 |
+
shared/package-files/6b/6bd81bd31743dcaef079322ba35c790c90c46a4c07116121f6ffcfa6eedb1d62/blob filter=lfs diff=lfs merge=lfs -text
|
| 541 |
+
shared/package-files/6c/6c0db4aaa524ce9987dd565a1e233347cfd8c4f3747c2662e5a5ce9d6e43e49c/blob filter=lfs diff=lfs merge=lfs -text
|
| 542 |
+
shared/package-files/6c/6c64451a3dd61c66b620aa0e0a0700df041ecdb6409070176ea99dfd075ebee3/blob filter=lfs diff=lfs merge=lfs -text
|
| 543 |
+
shared/package-files/6c/6ca2129b2d9a22c223ddf2cbabea53ded9cea370979fb2462993a83e36a0323c/blob filter=lfs diff=lfs merge=lfs -text
|
| 544 |
+
shared/package-files/6c/6cae7d0e4fd47e56a27acc11bfcb299e858437351abd554cdc25c3aa5b187b0d/blob filter=lfs diff=lfs merge=lfs -text
|
shared/package-files/65/6512731e2fb716ccdf6bc9d1a73e84a46619752a4bc867382b7a71af5bb23140/blob
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
def header_quopri_check(c): ...
|
| 2 |
+
def body_quopri_check(c): ...
|
| 3 |
+
def header_quopri_len(s): ...
|
| 4 |
+
def body_quopri_len(str): ...
|
| 5 |
+
def unquote(s): ...
|
| 6 |
+
def quote(c): ...
|
| 7 |
+
def header_encode(header, charset: str = ..., keep_eols: bool = ..., maxlinelen: int = ..., eol=...): ...
|
| 8 |
+
def encode(body, binary: bool = ..., maxlinelen: int = ..., eol=...): ...
|
| 9 |
+
|
| 10 |
+
body_encode = encode
|
| 11 |
+
encodestring = encode
|
| 12 |
+
|
| 13 |
+
def decode(encoded, eol=...): ...
|
| 14 |
+
|
| 15 |
+
body_decode = decode
|
| 16 |
+
decodestring = decode
|
| 17 |
+
|
| 18 |
+
def header_decode(s): ...
|
shared/package-files/65/65154ace68128ff3fbe26442d6567408436584d236b02b49f05db6a36b382de9/blob
ADDED
|
Binary file (425 Bytes). View file
|
|
|
shared/package-files/65/65195d76a1f8c1eaf87c151a186dc8b0b391a0cb3efda1bbd629d7f43e7e4066/blob
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# tkConfig.sh --
|
| 2 |
+
#
|
| 3 |
+
# This shell script (for sh) is generated automatically by Tk's
|
| 4 |
+
# configure script. It will create shell variables for most of
|
| 5 |
+
# the configuration options discovered by the configure script.
|
| 6 |
+
# This script is intended to be included by the configure scripts
|
| 7 |
+
# for Tk extensions so that they don't have to figure this all
|
| 8 |
+
# out for themselves. This file does not duplicate information
|
| 9 |
+
# already provided by tclConfig.sh, so you may need to use that
|
| 10 |
+
# file in addition to this one.
|
| 11 |
+
#
|
| 12 |
+
# The information in this file is specific to a single platform.
|
| 13 |
+
|
| 14 |
+
# Tk's version number.
|
| 15 |
+
TK_VERSION='8.6'
|
| 16 |
+
TK_MAJOR_VERSION='8'
|
| 17 |
+
TK_MINOR_VERSION='6'
|
| 18 |
+
TK_PATCH_LEVEL='.12'
|
| 19 |
+
|
| 20 |
+
# -D flags for use with the C compiler.
|
| 21 |
+
TK_DEFS='-DPACKAGE_NAME=\"tk\" -DPACKAGE_TARNAME=\"tk\" -DPACKAGE_VERSION=\"8.6\" -DPACKAGE_STRING=\"tk\ 8.6\" -DPACKAGE_BUGREPORT=\"\" -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DUSE_THREAD_ALLOC=1 -D_REENTRANT=1 -D_THREAD_SAFE=1 -DHAVE_PTHREAD_ATTR_SETSTACKSIZE=1 -DHAVE_PTHREAD_ATFORK=1 -DTCL_THREADS=1 -DMODULE_SCOPE=extern\ __attribute__\(\(__visibility__\(\"hidden\"\)\)\) -DHAVE_HIDDEN=1 -DTCL_CFG_DO64BIT=1 -DHAVE_CAST_TO_UNION=1 -DTCL_SHLIB_EXT=\".so\" -DNDEBUG=1 -DTCL_CFG_OPTIMIZED=1 -D_LARGEFILE64_SOURCE=1 -DTCL_WIDE_INT_IS_LONG=1 -DHAVE_SYS_TIME_H=1 -DTIME_WITH_SYS_TIME=1 -DHAVE_INTPTR_T=1 -DHAVE_UINTPTR_T=1 -DHAVE_PW_GECOS=1 -DHAVE_XKBKEYCODETOKEYSYM=1 -DXKEYCODETOKEYSYM_IS_DEPRECATED=1 '
|
| 22 |
+
|
| 23 |
+
# Flag, 1: we built a shared lib, 0 we didn't
|
| 24 |
+
TK_SHARED_BUILD=1
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
# TK_DBGX used to be used to distinguish debug vs. non-debug builds.
|
| 28 |
+
# This was a righteous pain so the core doesn't do that any more.
|
| 29 |
+
TK_DBGX=
|
| 30 |
+
|
| 31 |
+
# The name of the Tk library (may be either a .a file or a shared library):
|
| 32 |
+
TK_LIB_FILE='libtk8.6.so'
|
| 33 |
+
|
| 34 |
+
# Additional libraries to use when linking Tk.
|
| 35 |
+
TK_LIBS='-lX11 -lpthread -ldl -lz -lpthread -lm'
|
| 36 |
+
|
| 37 |
+
# Top-level directory in which Tk's platform-independent files are
|
| 38 |
+
# installed.
|
| 39 |
+
TK_PREFIX='/opt/conda'
|
| 40 |
+
|
| 41 |
+
# Top-level directory in which Tk's platform-specific files (e.g.
|
| 42 |
+
# executables) are installed.
|
| 43 |
+
TK_EXEC_PREFIX='/opt/conda'
|
| 44 |
+
|
| 45 |
+
# -I switch(es) to use to make all of the X11 include files accessible:
|
| 46 |
+
TK_XINCLUDES=''
|
| 47 |
+
|
| 48 |
+
# Linker switch(es) to use to link with the X11 library archive.
|
| 49 |
+
TK_XLIBSW='-lX11'
|
| 50 |
+
|
| 51 |
+
# -l flag to pass to the linker to pick up the Tk library
|
| 52 |
+
TK_LIB_FLAG='-ltk8.6'
|
| 53 |
+
|
| 54 |
+
# String to pass to linker to pick up the Tk library from its
|
| 55 |
+
# build directory.
|
| 56 |
+
TK_BUILD_LIB_SPEC='-L/opt/conda/conda-bld/tk_1654088763175/work/tk8.6.12/unix -ltk8.6'
|
| 57 |
+
|
| 58 |
+
# String to pass to linker to pick up the Tk library from its
|
| 59 |
+
# installed directory.
|
| 60 |
+
TK_LIB_SPEC='-L/opt/conda/lib -ltk8.6'
|
| 61 |
+
|
| 62 |
+
# String to pass to the compiler so that an extension can
|
| 63 |
+
# find installed Tk headers.
|
| 64 |
+
TK_INCLUDE_SPEC='-I/opt/conda/include'
|
| 65 |
+
|
| 66 |
+
# Location of the top-level source directory from which Tk was built.
|
| 67 |
+
# This is the directory that contains a README file as well as
|
| 68 |
+
# subdirectories such as generic, unix, etc. If Tk was compiled in a
|
| 69 |
+
# different place than the directory containing the source files, this
|
| 70 |
+
# points to the location of the sources, not the location where Tk was
|
| 71 |
+
# compiled.
|
| 72 |
+
TK_SRC_DIR='/opt/conda/conda-bld/tk_1654088763175/work/tk8.6.12'
|
| 73 |
+
|
| 74 |
+
# Needed if you want to make a 'fat' shared library library
|
| 75 |
+
# containing tk objects or link a different wish.
|
| 76 |
+
TK_CC_SEARCH_FLAGS='"-Wl,-rpath,${LIB_RUNTIME_DIR}"'
|
| 77 |
+
TK_LD_SEARCH_FLAGS='"-Wl,-rpath,${LIB_RUNTIME_DIR}"'
|
| 78 |
+
|
| 79 |
+
# The name of the Tk stub library (.a):
|
| 80 |
+
TK_STUB_LIB_FILE='libtkstub8.6.a'
|
| 81 |
+
|
| 82 |
+
# -l flag to pass to the linker to pick up the Tk stub library
|
| 83 |
+
TK_STUB_LIB_FLAG='-ltkstub8.6'
|
| 84 |
+
|
| 85 |
+
# String to pass to linker to pick up the Tk stub library from its
|
| 86 |
+
# build directory.
|
| 87 |
+
TK_BUILD_STUB_LIB_SPEC='-L/opt/conda/conda-bld/tk_1654088763175/work/tk8.6.12/unix -ltkstub8.6'
|
| 88 |
+
|
| 89 |
+
# String to pass to linker to pick up the Tk stub library from its
|
| 90 |
+
# installed directory.
|
| 91 |
+
TK_STUB_LIB_SPEC='-L/opt/conda/lib -ltkstub8.6'
|
| 92 |
+
|
| 93 |
+
# Path to the Tk stub library in the build directory.
|
| 94 |
+
TK_BUILD_STUB_LIB_PATH='/opt/conda/conda-bld/tk_1654088763175/work/tk8.6.12/unix/libtkstub8.6.a'
|
| 95 |
+
|
| 96 |
+
# Path to the Tk stub library in the install directory.
|
| 97 |
+
TK_STUB_LIB_PATH='/opt/conda/lib/libtkstub8.6.a'
|
shared/package-files/65/651cd0d9ca28ec9fc297ae69fc5b4c674f76fa849f5fbd4db41cd25dffa62954/blob
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// No "#pragma once" because this is a raw definition that can be copied by jit codegen.
|
| 2 |
+
// Eager mode clients should not include this file directly, instead,
|
| 3 |
+
// they should #include <ATen/cuda/PhiloxCudaState.h>, which has a #pragma once.
|
| 4 |
+
|
| 5 |
+
// Stores RNG state values. Passed as a kernel argument.
|
| 6 |
+
// See Note [CUDA Graph-safe RNG states].
|
| 7 |
+
//
|
| 8 |
+
// The raw definition lives in its own file so jit codegen can easily copy it.
|
| 9 |
+
namespace at {
|
| 10 |
+
|
| 11 |
+
struct PhiloxCudaState {
|
| 12 |
+
PhiloxCudaState() = default;
|
| 13 |
+
// Called if graph capture is not underway
|
| 14 |
+
PhiloxCudaState(uint64_t seed,
|
| 15 |
+
uint64_t offset) {
|
| 16 |
+
seed_.val = seed;
|
| 17 |
+
offset_.val = offset;
|
| 18 |
+
}
|
| 19 |
+
// Called if graph capture is underway
|
| 20 |
+
PhiloxCudaState(int64_t* seed,
|
| 21 |
+
int64_t* offset_extragraph,
|
| 22 |
+
uint32_t offset_intragraph) {
|
| 23 |
+
seed_.ptr = seed;
|
| 24 |
+
offset_.ptr = offset_extragraph;
|
| 25 |
+
offset_intragraph_ = offset_intragraph;
|
| 26 |
+
captured_ = true;
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
// Public members, directly accessible by at::cuda::philox::unpack.
|
| 30 |
+
// If we made them private with getters/setters, the getters/setters
|
| 31 |
+
// would have to be __device__, and we can't declare __device__ in ATen.
|
| 32 |
+
union Payload {
|
| 33 |
+
uint64_t val;
|
| 34 |
+
int64_t* ptr;
|
| 35 |
+
};
|
| 36 |
+
|
| 37 |
+
Payload seed_;
|
| 38 |
+
Payload offset_;
|
| 39 |
+
uint32_t offset_intragraph_ = 0;
|
| 40 |
+
bool captured_ = false;
|
| 41 |
+
};
|
| 42 |
+
|
| 43 |
+
} // namespace at
|
shared/package-files/65/651ec2268fdd01e08cf8a95a1afb2482d1d0c91b6b3c8a2573c4443a6728a899/blob
ADDED
|
Binary file (1.62 kB). View file
|
|
|
shared/package-files/65/651f27fde7da63b1d6198e979d164a3488915a66acce9354f29db692f01bc844/blob
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import pandas._testing as tm
|
| 4 |
+
from pandas.api import types
|
| 5 |
+
from pandas.tests.api.test_api import Base
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class TestTypes(Base):
|
| 9 |
+
allowed = [
|
| 10 |
+
"is_any_real_numeric_dtype",
|
| 11 |
+
"is_bool",
|
| 12 |
+
"is_bool_dtype",
|
| 13 |
+
"is_categorical_dtype",
|
| 14 |
+
"is_complex",
|
| 15 |
+
"is_complex_dtype",
|
| 16 |
+
"is_datetime64_any_dtype",
|
| 17 |
+
"is_datetime64_dtype",
|
| 18 |
+
"is_datetime64_ns_dtype",
|
| 19 |
+
"is_datetime64tz_dtype",
|
| 20 |
+
"is_dtype_equal",
|
| 21 |
+
"is_float",
|
| 22 |
+
"is_float_dtype",
|
| 23 |
+
"is_int64_dtype",
|
| 24 |
+
"is_integer",
|
| 25 |
+
"is_integer_dtype",
|
| 26 |
+
"is_number",
|
| 27 |
+
"is_numeric_dtype",
|
| 28 |
+
"is_object_dtype",
|
| 29 |
+
"is_scalar",
|
| 30 |
+
"is_sparse",
|
| 31 |
+
"is_string_dtype",
|
| 32 |
+
"is_signed_integer_dtype",
|
| 33 |
+
"is_timedelta64_dtype",
|
| 34 |
+
"is_timedelta64_ns_dtype",
|
| 35 |
+
"is_unsigned_integer_dtype",
|
| 36 |
+
"is_period_dtype",
|
| 37 |
+
"is_interval",
|
| 38 |
+
"is_interval_dtype",
|
| 39 |
+
"is_re",
|
| 40 |
+
"is_re_compilable",
|
| 41 |
+
"is_dict_like",
|
| 42 |
+
"is_iterator",
|
| 43 |
+
"is_file_like",
|
| 44 |
+
"is_list_like",
|
| 45 |
+
"is_hashable",
|
| 46 |
+
"is_array_like",
|
| 47 |
+
"is_named_tuple",
|
| 48 |
+
"pandas_dtype",
|
| 49 |
+
"union_categoricals",
|
| 50 |
+
"infer_dtype",
|
| 51 |
+
"is_extension_array_dtype",
|
| 52 |
+
]
|
| 53 |
+
deprecated: list[str] = []
|
| 54 |
+
dtypes = ["CategoricalDtype", "DatetimeTZDtype", "PeriodDtype", "IntervalDtype"]
|
| 55 |
+
|
| 56 |
+
def test_types(self):
|
| 57 |
+
self.check(types, self.allowed + self.dtypes + self.deprecated)
|
| 58 |
+
|
| 59 |
+
def test_deprecated_from_api_types(self):
|
| 60 |
+
for t in self.deprecated:
|
| 61 |
+
with tm.assert_produces_warning(FutureWarning):
|
| 62 |
+
getattr(types, t)(1)
|
shared/package-files/65/652009f8f9b89e9fad665f7a61d6cc5c6d98a32e25dbb0818edba4817ae8247d/blob
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// @generated by torchgen/gen.py from Function.h
|
| 4 |
+
|
| 5 |
+
#include <ATen/Context.h>
|
| 6 |
+
#include <ATen/DeviceGuard.h>
|
| 7 |
+
#include <ATen/TensorUtils.h>
|
| 8 |
+
#include <ATen/TracerMode.h>
|
| 9 |
+
#include <ATen/core/Generator.h>
|
| 10 |
+
#include <ATen/core/Reduction.h>
|
| 11 |
+
#include <ATen/core/Tensor.h>
|
| 12 |
+
#include <c10/core/Scalar.h>
|
| 13 |
+
#include <c10/core/Storage.h>
|
| 14 |
+
#include <c10/core/TensorOptions.h>
|
| 15 |
+
#include <c10/util/Deprecated.h>
|
| 16 |
+
#include <c10/util/Optional.h>
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
#include <ATen/ops/special_expm1_ops.h>
|
| 21 |
+
|
| 22 |
+
namespace at {
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
// aten::special_expm1(Tensor self) -> Tensor
|
| 26 |
+
inline at::Tensor special_expm1(const at::Tensor & self) {
|
| 27 |
+
return at::_ops::special_expm1::call(self);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
// aten::special_expm1.out(Tensor self, *, Tensor(a!) out) -> Tensor(a!)
|
| 31 |
+
inline at::Tensor & special_expm1_out(at::Tensor & out, const at::Tensor & self) {
|
| 32 |
+
return at::_ops::special_expm1_out::call(self, out);
|
| 33 |
+
}
|
| 34 |
+
// aten::special_expm1.out(Tensor self, *, Tensor(a!) out) -> Tensor(a!)
|
| 35 |
+
inline at::Tensor & special_expm1_outf(const at::Tensor & self, at::Tensor & out) {
|
| 36 |
+
return at::_ops::special_expm1_out::call(self, out);
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
}
|
shared/package-files/65/652016a967fca27d194a33fe30722726137c040b79f79f93f10721ed03b90d5b/blob
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <c10/util/Exception.h>
|
| 4 |
+
#include <sycl/sycl.hpp>
|
| 5 |
+
|
| 6 |
+
namespace c10::xpu {
|
| 7 |
+
|
| 8 |
+
static inline sycl::async_handler asyncHandler = [](sycl::exception_list el) {
|
| 9 |
+
if (el.size() == 0) {
|
| 10 |
+
return;
|
| 11 |
+
}
|
| 12 |
+
for (const auto& e : el) {
|
| 13 |
+
try {
|
| 14 |
+
std::rethrow_exception(e);
|
| 15 |
+
} catch (sycl::exception& e) {
|
| 16 |
+
TORCH_WARN("SYCL Exception: ", e.what());
|
| 17 |
+
}
|
| 18 |
+
}
|
| 19 |
+
throw;
|
| 20 |
+
};
|
| 21 |
+
|
| 22 |
+
} // namespace c10::xpu
|
shared/package-files/65/65241816cfbd9c205a97fc2222c4db7652ac9bbea7421906b0fc2e8f24f6b7c4/blob
ADDED
|
Binary file (6.65 kB). View file
|
|
|
shared/package-files/65/652500877ba19fd08217e718a8ae53366a2c0463dfb2e1c12047ee760cacba7e/blob
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
BLOCK DATA PARAM_INI
|
| 2 |
+
COMMON /MYCOM/ MYDATA
|
| 3 |
+
DATA MYDATA /0/
|
| 4 |
+
END
|
| 5 |
+
SUBROUTINE SUB1
|
| 6 |
+
COMMON /MYCOM/ MYDATA
|
| 7 |
+
MYDATA = MYDATA + 1
|
| 8 |
+
END
|
shared/package-files/65/652c9b8d7c60b4edc6a3e97d4bc77734c74247fc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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import copy
|
| 2 |
+
|
| 3 |
+
import numpy as np
|
| 4 |
+
import pytest
|
| 5 |
+
from pytest import raises, warns
|
| 6 |
+
from scipy._lib._array_api import xp_assert_close, xp_assert_equal
|
| 7 |
+
|
| 8 |
+
from scipy.signal._peak_finding import (
|
| 9 |
+
argrelmax,
|
| 10 |
+
argrelmin,
|
| 11 |
+
peak_prominences,
|
| 12 |
+
peak_widths,
|
| 13 |
+
_unpack_condition_args,
|
| 14 |
+
find_peaks,
|
| 15 |
+
find_peaks_cwt,
|
| 16 |
+
_identify_ridge_lines
|
| 17 |
+
)
|
| 18 |
+
from scipy.signal.windows import gaussian
|
| 19 |
+
from scipy.signal._peak_finding_utils import _local_maxima_1d, PeakPropertyWarning
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def _gen_gaussians(center_locs, sigmas, total_length):
|
| 23 |
+
xdata = np.arange(0, total_length).astype(float)
|
| 24 |
+
out_data = np.zeros(total_length, dtype=float)
|
| 25 |
+
for ind, sigma in enumerate(sigmas):
|
| 26 |
+
tmp = (xdata - center_locs[ind]) / sigma
|
| 27 |
+
out_data += np.exp(-(tmp**2))
|
| 28 |
+
return out_data
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def _gen_gaussians_even(sigmas, total_length):
|
| 32 |
+
num_peaks = len(sigmas)
|
| 33 |
+
delta = total_length / (num_peaks + 1)
|
| 34 |
+
center_locs = np.linspace(delta, total_length - delta, num=num_peaks).astype(int)
|
| 35 |
+
out_data = _gen_gaussians(center_locs, sigmas, total_length)
|
| 36 |
+
return out_data, center_locs
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def _gen_ridge_line(start_locs, max_locs, length, distances, gaps):
|
| 40 |
+
"""
|
| 41 |
+
Generate coordinates for a ridge line.
|
| 42 |
+
|
| 43 |
+
Will be a series of coordinates, starting a start_loc (length 2).
|
| 44 |
+
The maximum distance between any adjacent columns will be
|
| 45 |
+
`max_distance`, the max distance between adjacent rows
|
| 46 |
+
will be `map_gap'.
|
| 47 |
+
|
| 48 |
+
`max_locs` should be the size of the intended matrix. The
|
| 49 |
+
ending coordinates are guaranteed to be less than `max_locs`,
|
| 50 |
+
although they may not approach `max_locs` at all.
|
| 51 |
+
"""
|
| 52 |
+
|
| 53 |
+
def keep_bounds(num, max_val):
|
| 54 |
+
out = max(num, 0)
|
| 55 |
+
out = min(out, max_val)
|
| 56 |
+
return out
|
| 57 |
+
|
| 58 |
+
gaps = copy.deepcopy(gaps)
|
| 59 |
+
distances = copy.deepcopy(distances)
|
| 60 |
+
|
| 61 |
+
locs = np.zeros([length, 2], dtype=int)
|
| 62 |
+
locs[0, :] = start_locs
|
| 63 |
+
total_length = max_locs[0] - start_locs[0] - sum(gaps)
|
| 64 |
+
if total_length < length:
|
| 65 |
+
raise ValueError('Cannot generate ridge line according to constraints')
|
| 66 |
+
dist_int = length / len(distances) - 1
|
| 67 |
+
gap_int = length / len(gaps) - 1
|
| 68 |
+
for ind in range(1, length):
|
| 69 |
+
nextcol = locs[ind - 1, 1]
|
| 70 |
+
nextrow = locs[ind - 1, 0] + 1
|
| 71 |
+
if (ind % dist_int == 0) and (len(distances) > 0):
|
| 72 |
+
nextcol += ((-1)**ind)*distances.pop()
|
| 73 |
+
if (ind % gap_int == 0) and (len(gaps) > 0):
|
| 74 |
+
nextrow += gaps.pop()
|
| 75 |
+
nextrow = keep_bounds(nextrow, max_locs[0])
|
| 76 |
+
nextcol = keep_bounds(nextcol, max_locs[1])
|
| 77 |
+
locs[ind, :] = [nextrow, nextcol]
|
| 78 |
+
|
| 79 |
+
return [locs[:, 0], locs[:, 1]]
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
class TestLocalMaxima1d:
|
| 83 |
+
|
| 84 |
+
def test_empty(self):
|
| 85 |
+
"""Test with empty signal."""
|
| 86 |
+
x = np.array([], dtype=np.float64)
|
| 87 |
+
for array in _local_maxima_1d(x):
|
| 88 |
+
xp_assert_equal(array, np.array([]), check_dtype=False)
|
| 89 |
+
assert array.base is None
|
| 90 |
+
|
| 91 |
+
def test_linear(self):
|
| 92 |
+
"""Test with linear signal."""
|
| 93 |
+
x = np.linspace(0, 100)
|
| 94 |
+
for array in _local_maxima_1d(x):
|
| 95 |
+
xp_assert_equal(array, np.array([], dtype=np.intp))
|
| 96 |
+
assert array.base is None
|
| 97 |
+
|
| 98 |
+
def test_simple(self):
|
| 99 |
+
"""Test with simple signal."""
|
| 100 |
+
x = np.linspace(-10, 10, 50)
|
| 101 |
+
x[2::3] += 1
|
| 102 |
+
expected = np.arange(2, 50, 3, dtype=np.intp)
|
| 103 |
+
for array in _local_maxima_1d(x):
|
| 104 |
+
# For plateaus of size 1, the edges are identical with the
|
| 105 |
+
# midpoints
|
| 106 |
+
xp_assert_equal(array, expected, check_dtype=False)
|
| 107 |
+
assert array.base is None
|
| 108 |
+
|
| 109 |
+
def test_flat_maxima(self):
|
| 110 |
+
"""Test if flat maxima are detected correctly."""
|
| 111 |
+
x = np.array([-1.3, 0, 1, 0, 2, 2, 0, 3, 3, 3, 2.99, 4, 4, 4, 4, -10,
|
| 112 |
+
-5, -5, -5, -5, -5, -10])
|
| 113 |
+
midpoints, left_edges, right_edges = _local_maxima_1d(x)
|
| 114 |
+
xp_assert_equal(midpoints, np.array([2, 4, 8, 12, 18]), check_dtype=False)
|
| 115 |
+
xp_assert_equal(left_edges, np.array([2, 4, 7, 11, 16]), check_dtype=False)
|
| 116 |
+
xp_assert_equal(right_edges, np.array([2, 5, 9, 14, 20]), check_dtype=False)
|
| 117 |
+
|
| 118 |
+
@pytest.mark.parametrize('x', [
|
| 119 |
+
np.array([1., 0, 2]),
|
| 120 |
+
np.array([3., 3, 0, 4, 4]),
|
| 121 |
+
np.array([5., 5, 5, 0, 6, 6, 6]),
|
| 122 |
+
])
|
| 123 |
+
def test_signal_edges(self, x):
|
| 124 |
+
"""Test if behavior on signal edges is correct."""
|
| 125 |
+
for array in _local_maxima_1d(x):
|
| 126 |
+
xp_assert_equal(array, np.array([], dtype=np.intp))
|
| 127 |
+
assert array.base is None
|
| 128 |
+
|
| 129 |
+
def test_exceptions(self):
|
| 130 |
+
"""Test input validation and raised exceptions."""
|
| 131 |
+
with raises(ValueError, match="wrong number of dimensions"):
|
| 132 |
+
_local_maxima_1d(np.ones((1, 1)))
|
| 133 |
+
with raises(ValueError, match="expected 'const float64_t'"):
|
| 134 |
+
_local_maxima_1d(np.ones(1, dtype=int))
|
| 135 |
+
with raises(TypeError, match="list"):
|
| 136 |
+
_local_maxima_1d([1., 2.])
|
| 137 |
+
with raises(TypeError, match="'x' must not be None"):
|
| 138 |
+
_local_maxima_1d(None)
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
class TestRidgeLines:
|
| 142 |
+
|
| 143 |
+
def test_empty(self):
|
| 144 |
+
test_matr = np.zeros([20, 100])
|
| 145 |
+
lines = _identify_ridge_lines(test_matr, np.full(20, 2), 1)
|
| 146 |
+
assert len(lines) == 0
|
| 147 |
+
|
| 148 |
+
def test_minimal(self):
|
| 149 |
+
test_matr = np.zeros([20, 100])
|
| 150 |
+
test_matr[0, 10] = 1
|
| 151 |
+
lines = _identify_ridge_lines(test_matr, np.full(20, 2), 1)
|
| 152 |
+
assert len(lines) == 1
|
| 153 |
+
|
| 154 |
+
test_matr = np.zeros([20, 100])
|
| 155 |
+
test_matr[0:2, 10] = 1
|
| 156 |
+
lines = _identify_ridge_lines(test_matr, np.full(20, 2), 1)
|
| 157 |
+
assert len(lines) == 1
|
| 158 |
+
|
| 159 |
+
def test_single_pass(self):
|
| 160 |
+
distances = [0, 1, 2, 5]
|
| 161 |
+
gaps = [0, 1, 2, 0, 1]
|
| 162 |
+
test_matr = np.zeros([20, 50]) + 1e-12
|
| 163 |
+
length = 12
|
| 164 |
+
line = _gen_ridge_line([0, 25], test_matr.shape, length, distances, gaps)
|
| 165 |
+
test_matr[line[0], line[1]] = 1
|
| 166 |
+
max_distances = np.full(20, max(distances))
|
| 167 |
+
identified_lines = _identify_ridge_lines(test_matr,
|
| 168 |
+
max_distances,
|
| 169 |
+
max(gaps) + 1)
|
| 170 |
+
assert len(identified_lines) == 1
|
| 171 |
+
for iline_, line_ in zip(identified_lines[0], line):
|
| 172 |
+
xp_assert_equal(iline_, line_, check_dtype=False)
|
| 173 |
+
|
| 174 |
+
def test_single_bigdist(self):
|
| 175 |
+
distances = [0, 1, 2, 5]
|
| 176 |
+
gaps = [0, 1, 2, 4]
|
| 177 |
+
test_matr = np.zeros([20, 50])
|
| 178 |
+
length = 12
|
| 179 |
+
line = _gen_ridge_line([0, 25], test_matr.shape, length, distances, gaps)
|
| 180 |
+
test_matr[line[0], line[1]] = 1
|
| 181 |
+
max_dist = 3
|
| 182 |
+
max_distances = np.full(20, max_dist)
|
| 183 |
+
#This should get 2 lines, since the distance is too large
|
| 184 |
+
identified_lines = _identify_ridge_lines(test_matr,
|
| 185 |
+
max_distances,
|
| 186 |
+
max(gaps) + 1)
|
| 187 |
+
assert len(identified_lines) == 2
|
| 188 |
+
|
| 189 |
+
for iline in identified_lines:
|
| 190 |
+
adists = np.diff(iline[1])
|
| 191 |
+
np.testing.assert_array_less(np.abs(adists), max_dist)
|
| 192 |
+
|
| 193 |
+
agaps = np.diff(iline[0])
|
| 194 |
+
np.testing.assert_array_less(np.abs(agaps), max(gaps) + 0.1)
|
| 195 |
+
|
| 196 |
+
def test_single_biggap(self):
|
| 197 |
+
distances = [0, 1, 2, 5]
|
| 198 |
+
max_gap = 3
|
| 199 |
+
gaps = [0, 4, 2, 1]
|
| 200 |
+
test_matr = np.zeros([20, 50])
|
| 201 |
+
length = 12
|
| 202 |
+
line = _gen_ridge_line([0, 25], test_matr.shape, length, distances, gaps)
|
| 203 |
+
test_matr[line[0], line[1]] = 1
|
| 204 |
+
max_dist = 6
|
| 205 |
+
max_distances = np.full(20, max_dist)
|
| 206 |
+
#This should get 2 lines, since the gap is too large
|
| 207 |
+
identified_lines = _identify_ridge_lines(test_matr, max_distances, max_gap)
|
| 208 |
+
assert len(identified_lines) == 2
|
| 209 |
+
|
| 210 |
+
for iline in identified_lines:
|
| 211 |
+
adists = np.diff(iline[1])
|
| 212 |
+
np.testing.assert_array_less(np.abs(adists), max_dist)
|
| 213 |
+
|
| 214 |
+
agaps = np.diff(iline[0])
|
| 215 |
+
np.testing.assert_array_less(np.abs(agaps), max(gaps) + 0.1)
|
| 216 |
+
|
| 217 |
+
def test_single_biggaps(self):
|
| 218 |
+
distances = [0]
|
| 219 |
+
max_gap = 1
|
| 220 |
+
gaps = [3, 6]
|
| 221 |
+
test_matr = np.zeros([50, 50])
|
| 222 |
+
length = 30
|
| 223 |
+
line = _gen_ridge_line([0, 25], test_matr.shape, length, distances, gaps)
|
| 224 |
+
test_matr[line[0], line[1]] = 1
|
| 225 |
+
max_dist = 1
|
| 226 |
+
max_distances = np.full(50, max_dist)
|
| 227 |
+
#This should get 3 lines, since the gaps are too large
|
| 228 |
+
identified_lines = _identify_ridge_lines(test_matr, max_distances, max_gap)
|
| 229 |
+
assert len(identified_lines) == 3
|
| 230 |
+
|
| 231 |
+
for iline in identified_lines:
|
| 232 |
+
adists = np.diff(iline[1])
|
| 233 |
+
np.testing.assert_array_less(np.abs(adists), max_dist)
|
| 234 |
+
|
| 235 |
+
agaps = np.diff(iline[0])
|
| 236 |
+
np.testing.assert_array_less(np.abs(agaps), max(gaps) + 0.1)
|
| 237 |
+
|
| 238 |
+
|
| 239 |
+
class TestArgrel:
|
| 240 |
+
|
| 241 |
+
def test_empty(self):
|
| 242 |
+
# Regression test for gh-2832.
|
| 243 |
+
# When there are no relative extrema, make sure that
|
| 244 |
+
# the number of empty arrays returned matches the
|
| 245 |
+
# dimension of the input.
|
| 246 |
+
|
| 247 |
+
empty_array = np.array([], dtype=int)
|
| 248 |
+
|
| 249 |
+
z1 = np.zeros(5)
|
| 250 |
+
|
| 251 |
+
i = argrelmin(z1)
|
| 252 |
+
xp_assert_equal(len(i), 1)
|
| 253 |
+
xp_assert_equal(i[0], empty_array, check_dtype=False)
|
| 254 |
+
|
| 255 |
+
z2 = np.zeros((3, 5))
|
| 256 |
+
|
| 257 |
+
row, col = argrelmin(z2, axis=0)
|
| 258 |
+
xp_assert_equal(row, empty_array, check_dtype=False)
|
| 259 |
+
xp_assert_equal(col, empty_array, check_dtype=False)
|
| 260 |
+
|
| 261 |
+
row, col = argrelmin(z2, axis=1)
|
| 262 |
+
xp_assert_equal(row, empty_array, check_dtype=False)
|
| 263 |
+
xp_assert_equal(col, empty_array, check_dtype=False)
|
| 264 |
+
|
| 265 |
+
def test_basic(self):
|
| 266 |
+
# Note: the docstrings for the argrel{min,max,extrema} functions
|
| 267 |
+
# do not give a guarantee of the order of the indices, so we'll
|
| 268 |
+
# sort them before testing.
|
| 269 |
+
|
| 270 |
+
x = np.array([[1, 2, 2, 3, 2],
|
| 271 |
+
[2, 1, 2, 2, 3],
|
| 272 |
+
[3, 2, 1, 2, 2],
|
| 273 |
+
[2, 3, 2, 1, 2],
|
| 274 |
+
[1, 2, 3, 2, 1]])
|
| 275 |
+
|
| 276 |
+
row, col = argrelmax(x, axis=0)
|
| 277 |
+
order = np.argsort(row)
|
| 278 |
+
xp_assert_equal(row[order], [1, 2, 3], check_dtype=False)
|
| 279 |
+
xp_assert_equal(col[order], [4, 0, 1], check_dtype=False)
|
| 280 |
+
|
| 281 |
+
row, col = argrelmax(x, axis=1)
|
| 282 |
+
order = np.argsort(row)
|
| 283 |
+
xp_assert_equal(row[order], [0, 3, 4], check_dtype=False)
|
| 284 |
+
xp_assert_equal(col[order], [3, 1, 2], check_dtype=False)
|
| 285 |
+
|
| 286 |
+
row, col = argrelmin(x, axis=0)
|
| 287 |
+
order = np.argsort(row)
|
| 288 |
+
xp_assert_equal(row[order], [1, 2, 3], check_dtype=False)
|
| 289 |
+
xp_assert_equal(col[order], [1, 2, 3], check_dtype=False)
|
| 290 |
+
|
| 291 |
+
row, col = argrelmin(x, axis=1)
|
| 292 |
+
order = np.argsort(row)
|
| 293 |
+
xp_assert_equal(row[order], [1, 2, 3], check_dtype=False)
|
| 294 |
+
xp_assert_equal(col[order], [1, 2, 3], check_dtype=False)
|
| 295 |
+
|
| 296 |
+
def test_highorder(self):
|
| 297 |
+
order = 2
|
| 298 |
+
sigmas = [1.0, 2.0, 10.0, 5.0, 15.0]
|
| 299 |
+
test_data, act_locs = _gen_gaussians_even(sigmas, 500)
|
| 300 |
+
test_data[act_locs + order] = test_data[act_locs]*0.99999
|
| 301 |
+
test_data[act_locs - order] = test_data[act_locs]*0.99999
|
| 302 |
+
rel_max_locs = argrelmax(test_data, order=order, mode='clip')[0]
|
| 303 |
+
|
| 304 |
+
assert len(rel_max_locs) == len(act_locs)
|
| 305 |
+
assert (rel_max_locs == act_locs).all()
|
| 306 |
+
|
| 307 |
+
def test_2d_gaussians(self):
|
| 308 |
+
sigmas = [1.0, 2.0, 10.0]
|
| 309 |
+
test_data, act_locs = _gen_gaussians_even(sigmas, 100)
|
| 310 |
+
rot_factor = 20
|
| 311 |
+
rot_range = np.arange(0, len(test_data)) - rot_factor
|
| 312 |
+
test_data_2 = np.vstack([test_data, test_data[rot_range]])
|
| 313 |
+
rel_max_rows, rel_max_cols = argrelmax(test_data_2, axis=1, order=1)
|
| 314 |
+
|
| 315 |
+
for rw in range(0, test_data_2.shape[0]):
|
| 316 |
+
inds = (rel_max_rows == rw)
|
| 317 |
+
|
| 318 |
+
assert len(rel_max_cols[inds]) == len(act_locs)
|
| 319 |
+
assert (act_locs == (rel_max_cols[inds] - rot_factor*rw)).all()
|
| 320 |
+
|
| 321 |
+
|
| 322 |
+
class TestPeakProminences:
|
| 323 |
+
|
| 324 |
+
def test_empty(self):
|
| 325 |
+
"""
|
| 326 |
+
Test if an empty array is returned if no peaks are provided.
|
| 327 |
+
"""
|
| 328 |
+
out = peak_prominences([1, 2, 3], [])
|
| 329 |
+
for arr, dtype in zip(out, [np.float64, np.intp, np.intp]):
|
| 330 |
+
assert arr.size == 0
|
| 331 |
+
assert arr.dtype == dtype
|
| 332 |
+
|
| 333 |
+
out = peak_prominences([], [])
|
| 334 |
+
for arr, dtype in zip(out, [np.float64, np.intp, np.intp]):
|
| 335 |
+
assert arr.size == 0
|
| 336 |
+
assert arr.dtype == dtype
|
| 337 |
+
|
| 338 |
+
def test_basic(self):
|
| 339 |
+
"""
|
| 340 |
+
Test if height of prominences is correctly calculated in signal with
|
| 341 |
+
rising baseline (peak widths are 1 sample).
|
| 342 |
+
"""
|
| 343 |
+
# Prepare basic signal
|
| 344 |
+
x = np.array([-1, 1.2, 1.2, 1, 3.2, 1.3, 2.88, 2.1])
|
| 345 |
+
peaks = np.array([1, 2, 4, 6])
|
| 346 |
+
lbases = np.array([0, 0, 0, 5])
|
| 347 |
+
rbases = np.array([3, 3, 5, 7])
|
| 348 |
+
proms = x[peaks] - np.max([x[lbases], x[rbases]], axis=0)
|
| 349 |
+
# Test if calculation matches handcrafted result
|
| 350 |
+
out = peak_prominences(x, peaks)
|
| 351 |
+
xp_assert_equal(out[0], proms, check_dtype=False)
|
| 352 |
+
xp_assert_equal(out[1], lbases, check_dtype=False)
|
| 353 |
+
xp_assert_equal(out[2], rbases, check_dtype=False)
|
| 354 |
+
|
| 355 |
+
def test_edge_cases(self):
|
| 356 |
+
"""
|
| 357 |
+
Test edge cases.
|
| 358 |
+
"""
|
| 359 |
+
# Peaks have same height, prominence and bases
|
| 360 |
+
x = [0, 2, 1, 2, 1, 2, 0]
|
| 361 |
+
peaks = [1, 3, 5]
|
| 362 |
+
proms, lbases, rbases = peak_prominences(x, peaks)
|
| 363 |
+
xp_assert_equal(proms, np.asarray([2.0, 2, 2]), check_dtype=False)
|
| 364 |
+
xp_assert_equal(lbases, [0, 0, 0], check_dtype=False)
|
| 365 |
+
xp_assert_equal(rbases, [6, 6, 6], check_dtype=False)
|
| 366 |
+
|
| 367 |
+
# Peaks have same height & prominence but different bases
|
| 368 |
+
x = [0, 1, 0, 1, 0, 1, 0]
|
| 369 |
+
peaks = np.array([1, 3, 5])
|
| 370 |
+
proms, lbases, rbases = peak_prominences(x, peaks)
|
| 371 |
+
xp_assert_equal(proms, np.asarray([1.0, 1, 1]))
|
| 372 |
+
xp_assert_equal(lbases, peaks - 1, check_dtype=False)
|
| 373 |
+
xp_assert_equal(rbases, peaks + 1, check_dtype=False)
|
| 374 |
+
|
| 375 |
+
def test_non_contiguous(self):
|
| 376 |
+
"""
|
| 377 |
+
Test with non-C-contiguous input arrays.
|
| 378 |
+
"""
|
| 379 |
+
x = np.repeat([-9, 9, 9, 0, 3, 1], 2)
|
| 380 |
+
peaks = np.repeat([1, 2, 4], 2)
|
| 381 |
+
proms, lbases, rbases = peak_prominences(x[::2], peaks[::2])
|
| 382 |
+
xp_assert_equal(proms, np.asarray([9.0, 9, 2]))
|
| 383 |
+
xp_assert_equal(lbases, [0, 0, 3], check_dtype=False)
|
| 384 |
+
xp_assert_equal(rbases, [3, 3, 5], check_dtype=False)
|
| 385 |
+
|
| 386 |
+
def test_wlen(self):
|
| 387 |
+
"""
|
| 388 |
+
Test if wlen actually shrinks the evaluation range correctly.
|
| 389 |
+
"""
|
| 390 |
+
x = [0, 1, 2, 3, 1, 0, -1]
|
| 391 |
+
peak = [3]
|
| 392 |
+
# Test rounding behavior of wlen
|
| 393 |
+
proms = peak_prominences(x, peak)
|
| 394 |
+
for prom, val in zip(proms, [3.0, 0, 6]):
|
| 395 |
+
assert prom == val
|
| 396 |
+
|
| 397 |
+
for wlen, i in [(8, 0), (7, 0), (6, 0), (5, 1), (3.2, 1), (3, 2), (1.1, 2)]:
|
| 398 |
+
proms = peak_prominences(x, peak, wlen)
|
| 399 |
+
for prom, val in zip(proms, [3. - i, 0 + i, 6 - i]):
|
| 400 |
+
assert prom == val
|
| 401 |
+
|
| 402 |
+
def test_exceptions(self):
|
| 403 |
+
"""
|
| 404 |
+
Verify that exceptions and warnings are raised.
|
| 405 |
+
"""
|
| 406 |
+
# x with dimension > 1
|
| 407 |
+
with raises(ValueError, match='1-D array'):
|
| 408 |
+
peak_prominences([[0, 1, 1, 0]], [1, 2])
|
| 409 |
+
# peaks with dimension > 1
|
| 410 |
+
with raises(ValueError, match='1-D array'):
|
| 411 |
+
peak_prominences([0, 1, 1, 0], [[1, 2]])
|
| 412 |
+
# x with dimension < 1
|
| 413 |
+
with raises(ValueError, match='1-D array'):
|
| 414 |
+
peak_prominences(3, [0,])
|
| 415 |
+
|
| 416 |
+
# empty x with supplied
|
| 417 |
+
with raises(ValueError, match='not a valid index'):
|
| 418 |
+
peak_prominences([], [0])
|
| 419 |
+
# invalid indices with non-empty x
|
| 420 |
+
for p in [-100, -1, 3, 1000]:
|
| 421 |
+
with raises(ValueError, match='not a valid index'):
|
| 422 |
+
peak_prominences([1, 0, 2], [p])
|
| 423 |
+
|
| 424 |
+
# peaks is not cast-able to np.intp
|
| 425 |
+
with raises(TypeError, match='cannot safely cast'):
|
| 426 |
+
peak_prominences([0, 1, 1, 0], [1.1, 2.3])
|
| 427 |
+
|
| 428 |
+
# wlen < 3
|
| 429 |
+
with raises(ValueError, match='wlen'):
|
| 430 |
+
peak_prominences(np.arange(10), [3, 5], wlen=1)
|
| 431 |
+
|
| 432 |
+
@pytest.mark.thread_unsafe
|
| 433 |
+
def test_warnings(self):
|
| 434 |
+
"""
|
| 435 |
+
Verify that appropriate warnings are raised.
|
| 436 |
+
"""
|
| 437 |
+
msg = "some peaks have a prominence of 0"
|
| 438 |
+
for p in [0, 1, 2]:
|
| 439 |
+
with warns(PeakPropertyWarning, match=msg):
|
| 440 |
+
peak_prominences([1, 0, 2], [p,])
|
| 441 |
+
with warns(PeakPropertyWarning, match=msg):
|
| 442 |
+
peak_prominences([0, 1, 1, 1, 0], [2], wlen=2)
|
| 443 |
+
|
| 444 |
+
|
| 445 |
+
class TestPeakWidths:
|
| 446 |
+
|
| 447 |
+
def test_empty(self):
|
| 448 |
+
"""
|
| 449 |
+
Test if an empty array is returned if no peaks are provided.
|
| 450 |
+
"""
|
| 451 |
+
widths = peak_widths([], [])[0]
|
| 452 |
+
assert isinstance(widths, np.ndarray)
|
| 453 |
+
assert widths.size == 0
|
| 454 |
+
widths = peak_widths([1, 2, 3], [])[0]
|
| 455 |
+
assert isinstance(widths, np.ndarray)
|
| 456 |
+
assert widths.size == 0
|
| 457 |
+
out = peak_widths([], [])
|
| 458 |
+
for arr in out:
|
| 459 |
+
assert isinstance(arr, np.ndarray)
|
| 460 |
+
assert arr.size == 0
|
| 461 |
+
|
| 462 |
+
@pytest.mark.filterwarnings("ignore:some peaks have a width of 0")
|
| 463 |
+
def test_basic(self):
|
| 464 |
+
"""
|
| 465 |
+
Test a simple use case with easy to verify results at different relative
|
| 466 |
+
heights.
|
| 467 |
+
"""
|
| 468 |
+
x = np.array([1, 0, 1, 2, 1, 0, -1])
|
| 469 |
+
prominence = 2
|
| 470 |
+
for rel_height, width_true, lip_true, rip_true in [
|
| 471 |
+
(0., 0., 3., 3.), # raises warning
|
| 472 |
+
(0.25, 1., 2.5, 3.5),
|
| 473 |
+
(0.5, 2., 2., 4.),
|
| 474 |
+
(0.75, 3., 1.5, 4.5),
|
| 475 |
+
(1., 4., 1., 5.),
|
| 476 |
+
(2., 5., 1., 6.),
|
| 477 |
+
(3., 5., 1., 6.)
|
| 478 |
+
]:
|
| 479 |
+
width_calc, height, lip_calc, rip_calc = peak_widths(
|
| 480 |
+
x, [3], rel_height)
|
| 481 |
+
xp_assert_close(width_calc, np.asarray([width_true]))
|
| 482 |
+
xp_assert_close(height, np.asarray([2 - rel_height * prominence]))
|
| 483 |
+
xp_assert_close(lip_calc, np.asarray([lip_true]))
|
| 484 |
+
xp_assert_close(rip_calc, np.asarray([rip_true]))
|
| 485 |
+
|
| 486 |
+
def test_non_contiguous(self):
|
| 487 |
+
"""
|
| 488 |
+
Test with non-C-contiguous input arrays.
|
| 489 |
+
"""
|
| 490 |
+
x = np.repeat([0, 100, 50], 4)
|
| 491 |
+
peaks = np.repeat([1], 3)
|
| 492 |
+
result = peak_widths(x[::4], peaks[::3])
|
| 493 |
+
xp_assert_equal(result,
|
| 494 |
+
np.asarray([[0.75], [75], [0.75], [1.5]])
|
| 495 |
+
)
|
| 496 |
+
|
| 497 |
+
def test_exceptions(self):
|
| 498 |
+
"""
|
| 499 |
+
Verify that argument validation works as intended.
|
| 500 |
+
"""
|
| 501 |
+
with raises(ValueError, match='1-D array'):
|
| 502 |
+
# x with dimension > 1
|
| 503 |
+
peak_widths(np.zeros((3, 4)), np.ones(3))
|
| 504 |
+
with raises(ValueError, match='1-D array'):
|
| 505 |
+
# x with dimension < 1
|
| 506 |
+
peak_widths(3, [0])
|
| 507 |
+
with raises(ValueError, match='1-D array'):
|
| 508 |
+
# peaks with dimension > 1
|
| 509 |
+
peak_widths(np.arange(10), np.ones((3, 2), dtype=np.intp))
|
| 510 |
+
with raises(ValueError, match='1-D array'):
|
| 511 |
+
# peaks with dimension < 1
|
| 512 |
+
peak_widths(np.arange(10), 3)
|
| 513 |
+
with raises(ValueError, match='not a valid index'):
|
| 514 |
+
# peak pos exceeds x.size
|
| 515 |
+
peak_widths(np.arange(10), [8, 11])
|
| 516 |
+
with raises(ValueError, match='not a valid index'):
|
| 517 |
+
# empty x with peaks supplied
|
| 518 |
+
peak_widths([], [1, 2])
|
| 519 |
+
with raises(TypeError, match='cannot safely cast'):
|
| 520 |
+
# peak cannot be safely cast to intp
|
| 521 |
+
peak_widths(np.arange(10), [1.1, 2.3])
|
| 522 |
+
with raises(ValueError, match='rel_height'):
|
| 523 |
+
# rel_height is < 0
|
| 524 |
+
peak_widths([0, 1, 0, 1, 0], [1, 3], rel_height=-1)
|
| 525 |
+
with raises(TypeError, match='None'):
|
| 526 |
+
# prominence data contains None
|
| 527 |
+
peak_widths([1, 2, 1], [1], prominence_data=(None, None, None))
|
| 528 |
+
|
| 529 |
+
@pytest.mark.thread_unsafe
|
| 530 |
+
def test_warnings(self):
|
| 531 |
+
"""
|
| 532 |
+
Verify that appropriate warnings are raised.
|
| 533 |
+
"""
|
| 534 |
+
msg = "some peaks have a width of 0"
|
| 535 |
+
with warns(PeakPropertyWarning, match=msg):
|
| 536 |
+
# Case: rel_height is 0
|
| 537 |
+
peak_widths([0, 1, 0], [1], rel_height=0)
|
| 538 |
+
with warns(PeakPropertyWarning, match=msg):
|
| 539 |
+
# Case: prominence is 0 and bases are identical
|
| 540 |
+
peak_widths(
|
| 541 |
+
[0, 1, 1, 1, 0], [2],
|
| 542 |
+
prominence_data=(np.array([0.], np.float64),
|
| 543 |
+
np.array([2], np.intp),
|
| 544 |
+
np.array([2], np.intp))
|
| 545 |
+
)
|
| 546 |
+
|
| 547 |
+
def test_mismatching_prominence_data(self):
|
| 548 |
+
"""Test with mismatching peak and / or prominence data."""
|
| 549 |
+
x = [0, 1, 0]
|
| 550 |
+
peak = [1]
|
| 551 |
+
for i, (prominences, left_bases, right_bases) in enumerate([
|
| 552 |
+
((1.,), (-1,), (2,)), # left base not in x
|
| 553 |
+
((1.,), (0,), (3,)), # right base not in x
|
| 554 |
+
((1.,), (2,), (0,)), # swapped bases same as peak
|
| 555 |
+
((1., 1.), (0, 0), (2, 2)), # array shapes don't match peaks
|
| 556 |
+
((1., 1.), (0,), (2,)), # arrays with different shapes
|
| 557 |
+
((1.,), (0, 0), (2,)), # arrays with different shapes
|
| 558 |
+
((1.,), (0,), (2, 2)) # arrays with different shapes
|
| 559 |
+
]):
|
| 560 |
+
# Make sure input is matches output of signal.peak_prominences
|
| 561 |
+
prominence_data = (np.array(prominences, dtype=np.float64),
|
| 562 |
+
np.array(left_bases, dtype=np.intp),
|
| 563 |
+
np.array(right_bases, dtype=np.intp))
|
| 564 |
+
# Test for correct exception
|
| 565 |
+
if i < 3:
|
| 566 |
+
match = "prominence data is invalid for peak"
|
| 567 |
+
else:
|
| 568 |
+
match = "arrays in `prominence_data` must have the same shape"
|
| 569 |
+
with raises(ValueError, match=match):
|
| 570 |
+
peak_widths(x, peak, prominence_data=prominence_data)
|
| 571 |
+
|
| 572 |
+
@pytest.mark.filterwarnings("ignore:some peaks have a width of 0")
|
| 573 |
+
def test_intersection_rules(self):
|
| 574 |
+
"""Test if x == eval_height counts as an intersection."""
|
| 575 |
+
# Flatt peak with two possible intersection points if evaluated at 1
|
| 576 |
+
x = [0, 1, 2, 1, 3, 3, 3, 1, 2, 1, 0]
|
| 577 |
+
# relative height is 0 -> width is 0 as well, raises warning
|
| 578 |
+
xp_assert_close(peak_widths(x, peaks=[5], rel_height=0),
|
| 579 |
+
[(0.,), (3.,), (5.,), (5.,)])
|
| 580 |
+
# width_height == x counts as intersection -> nearest 1 is chosen
|
| 581 |
+
xp_assert_close(peak_widths(x, peaks=[5], rel_height=2/3),
|
| 582 |
+
[(4.,), (1.,), (3.,), (7.,)])
|
| 583 |
+
|
| 584 |
+
|
| 585 |
+
def test_unpack_condition_args():
|
| 586 |
+
"""
|
| 587 |
+
Verify parsing of condition arguments for `scipy.signal.find_peaks` function.
|
| 588 |
+
"""
|
| 589 |
+
x = np.arange(10)
|
| 590 |
+
amin_true = x
|
| 591 |
+
amax_true = amin_true + 10
|
| 592 |
+
peaks = amin_true[1::2]
|
| 593 |
+
|
| 594 |
+
# Test unpacking with None or interval
|
| 595 |
+
assert (None, None) == _unpack_condition_args((None, None), x, peaks)
|
| 596 |
+
assert (1, None) == _unpack_condition_args(1, x, peaks)
|
| 597 |
+
assert (1, None) == _unpack_condition_args((1, None), x, peaks)
|
| 598 |
+
assert (None, 2) == _unpack_condition_args((None, 2), x, peaks)
|
| 599 |
+
assert (3., 4.5) == _unpack_condition_args((3., 4.5), x, peaks)
|
| 600 |
+
|
| 601 |
+
# Test if borders are correctly reduced with `peaks`
|
| 602 |
+
amin_calc, amax_calc = _unpack_condition_args((amin_true, amax_true), x, peaks)
|
| 603 |
+
xp_assert_equal(amin_calc, amin_true[peaks])
|
| 604 |
+
xp_assert_equal(amax_calc, amax_true[peaks])
|
| 605 |
+
|
| 606 |
+
# Test raises if array borders don't match x
|
| 607 |
+
with raises(ValueError, match="array size of lower"):
|
| 608 |
+
_unpack_condition_args(amin_true, np.arange(11), peaks)
|
| 609 |
+
with raises(ValueError, match="array size of upper"):
|
| 610 |
+
_unpack_condition_args((None, amin_true), np.arange(11), peaks)
|
| 611 |
+
|
| 612 |
+
|
| 613 |
+
class TestFindPeaks:
|
| 614 |
+
|
| 615 |
+
# Keys of optionally returned properties
|
| 616 |
+
property_keys = {'peak_heights', 'left_thresholds', 'right_thresholds',
|
| 617 |
+
'prominences', 'left_bases', 'right_bases', 'widths',
|
| 618 |
+
'width_heights', 'left_ips', 'right_ips'}
|
| 619 |
+
|
| 620 |
+
def test_constant(self):
|
| 621 |
+
"""
|
| 622 |
+
Test behavior for signal without local maxima.
|
| 623 |
+
"""
|
| 624 |
+
open_interval = (None, None)
|
| 625 |
+
peaks, props = find_peaks(np.ones(10),
|
| 626 |
+
height=open_interval, threshold=open_interval,
|
| 627 |
+
prominence=open_interval, width=open_interval)
|
| 628 |
+
assert peaks.size == 0
|
| 629 |
+
for key in self.property_keys:
|
| 630 |
+
assert props[key].size == 0
|
| 631 |
+
|
| 632 |
+
def test_plateau_size(self):
|
| 633 |
+
"""
|
| 634 |
+
Test plateau size condition for peaks.
|
| 635 |
+
"""
|
| 636 |
+
# Prepare signal with peaks with peak_height == plateau_size
|
| 637 |
+
plateau_sizes = np.array([1, 2, 3, 4, 8, 20, 111])
|
| 638 |
+
x = np.zeros(plateau_sizes.size * 2 + 1)
|
| 639 |
+
x[1::2] = plateau_sizes
|
| 640 |
+
repeats = np.ones(x.size, dtype=int)
|
| 641 |
+
repeats[1::2] = x[1::2]
|
| 642 |
+
x = np.repeat(x, repeats)
|
| 643 |
+
|
| 644 |
+
# Test full output
|
| 645 |
+
peaks, props = find_peaks(x, plateau_size=(None, None))
|
| 646 |
+
xp_assert_equal(peaks, [1, 3, 7, 11, 18, 33, 100], check_dtype=False)
|
| 647 |
+
xp_assert_equal(props["plateau_sizes"], plateau_sizes, check_dtype=False)
|
| 648 |
+
xp_assert_equal(props["left_edges"], peaks - (plateau_sizes - 1) // 2,
|
| 649 |
+
check_dtype=False)
|
| 650 |
+
xp_assert_equal(props["right_edges"], peaks + plateau_sizes // 2,
|
| 651 |
+
check_dtype=False)
|
| 652 |
+
|
| 653 |
+
# Test conditions
|
| 654 |
+
xp_assert_equal(find_peaks(x, plateau_size=4)[0], [11, 18, 33, 100],
|
| 655 |
+
check_dtype=False)
|
| 656 |
+
xp_assert_equal(find_peaks(x, plateau_size=(None, 3.5))[0], [1, 3, 7],
|
| 657 |
+
check_dtype=False)
|
| 658 |
+
xp_assert_equal(find_peaks(x, plateau_size=(5, 50))[0], [18, 33],
|
| 659 |
+
check_dtype=False)
|
| 660 |
+
|
| 661 |
+
def test_height_condition(self):
|
| 662 |
+
"""
|
| 663 |
+
Test height condition for peaks.
|
| 664 |
+
"""
|
| 665 |
+
x = (0., 1/3, 0., 2.5, 0, 4., 0)
|
| 666 |
+
peaks, props = find_peaks(x, height=(None, None))
|
| 667 |
+
xp_assert_equal(peaks, np.array([1, 3, 5]), check_dtype=False)
|
| 668 |
+
xp_assert_equal(props['peak_heights'], np.array([1/3, 2.5, 4.]),
|
| 669 |
+
check_dtype=False)
|
| 670 |
+
xp_assert_equal(find_peaks(x, height=0.5)[0], np.array([3, 5]),
|
| 671 |
+
check_dtype=False)
|
| 672 |
+
xp_assert_equal(find_peaks(x, height=(None, 3))[0], np.array([1, 3]),
|
| 673 |
+
check_dtype=False)
|
| 674 |
+
xp_assert_equal(find_peaks(x, height=(2, 3))[0], np.array([3]),
|
| 675 |
+
check_dtype=False)
|
| 676 |
+
|
| 677 |
+
def test_threshold_condition(self):
|
| 678 |
+
"""
|
| 679 |
+
Test threshold condition for peaks.
|
| 680 |
+
"""
|
| 681 |
+
x = (0, 2, 1, 4, -1)
|
| 682 |
+
peaks, props = find_peaks(x, threshold=(None, None))
|
| 683 |
+
xp_assert_equal(peaks, np.array([1, 3]), check_dtype=False)
|
| 684 |
+
xp_assert_equal(props['left_thresholds'], np.array([2.0, 3.0]))
|
| 685 |
+
xp_assert_equal(props['right_thresholds'], np.array([1.0, 5.0]))
|
| 686 |
+
xp_assert_equal(find_peaks(x, threshold=2)[0], np.array([3]),
|
| 687 |
+
check_dtype=False)
|
| 688 |
+
xp_assert_equal(find_peaks(x, threshold=3.5)[0], np.array([], dtype=int),
|
| 689 |
+
check_dtype=False)
|
| 690 |
+
xp_assert_equal(find_peaks(x, threshold=(None, 5))[0], np.array([1, 3]),
|
| 691 |
+
check_dtype=False)
|
| 692 |
+
xp_assert_equal(find_peaks(x, threshold=(None, 4))[0], np.array([1]),
|
| 693 |
+
check_dtype=False)
|
| 694 |
+
xp_assert_equal(find_peaks(x, threshold=(2, 4))[0], np.array([], dtype=int),
|
| 695 |
+
check_dtype=False)
|
| 696 |
+
|
| 697 |
+
def test_distance_condition(self):
|
| 698 |
+
"""
|
| 699 |
+
Test distance condition for peaks.
|
| 700 |
+
"""
|
| 701 |
+
# Peaks of different height with constant distance 3
|
| 702 |
+
peaks_all = np.arange(1, 21, 3)
|
| 703 |
+
x = np.zeros(21)
|
| 704 |
+
x[peaks_all] += np.linspace(1, 2, peaks_all.size)
|
| 705 |
+
|
| 706 |
+
# Test if peaks with "minimal" distance are still selected (distance = 3)
|
| 707 |
+
xp_assert_equal(find_peaks(x, distance=3)[0], peaks_all, check_dtype=False)
|
| 708 |
+
|
| 709 |
+
# Select every second peak (distance > 3)
|
| 710 |
+
peaks_subset = find_peaks(x, distance=3.0001)[0]
|
| 711 |
+
# Test if peaks_subset is subset of peaks_all
|
| 712 |
+
assert np.setdiff1d(peaks_subset, peaks_all, assume_unique=True).size == 0
|
| 713 |
+
|
| 714 |
+
# Test if every second peak was removed
|
| 715 |
+
dfs = np.diff(peaks_subset)
|
| 716 |
+
xp_assert_equal(dfs, 6*np.ones_like(dfs))
|
| 717 |
+
|
| 718 |
+
# Test priority of peak removal
|
| 719 |
+
x = [-2, 1, -1, 0, -3]
|
| 720 |
+
peaks_subset = find_peaks(x, distance=10)[0] # use distance > x size
|
| 721 |
+
assert peaks_subset.size == 1 and peaks_subset[0] == 1
|
| 722 |
+
|
| 723 |
+
def test_prominence_condition(self):
|
| 724 |
+
"""
|
| 725 |
+
Test prominence condition for peaks.
|
| 726 |
+
"""
|
| 727 |
+
x = np.linspace(0, 10, 100)
|
| 728 |
+
peaks_true = np.arange(1, 99, 2)
|
| 729 |
+
offset = np.linspace(1, 10, peaks_true.size)
|
| 730 |
+
x[peaks_true] += offset
|
| 731 |
+
prominences = x[peaks_true] - x[peaks_true + 1]
|
| 732 |
+
interval = (3, 9)
|
| 733 |
+
keep = np.nonzero(
|
| 734 |
+
(interval[0] <= prominences) & (prominences <= interval[1]))
|
| 735 |
+
|
| 736 |
+
peaks_calc, properties = find_peaks(x, prominence=interval)
|
| 737 |
+
xp_assert_equal(peaks_calc, peaks_true[keep], check_dtype=False)
|
| 738 |
+
xp_assert_equal(properties['prominences'], prominences[keep], check_dtype=False)
|
| 739 |
+
xp_assert_equal(properties['left_bases'],
|
| 740 |
+
np.zeros_like(properties['left_bases']))
|
| 741 |
+
xp_assert_equal(properties['right_bases'], peaks_true[keep] + 1,
|
| 742 |
+
check_dtype=False)
|
| 743 |
+
|
| 744 |
+
def test_width_condition(self):
|
| 745 |
+
"""
|
| 746 |
+
Test width condition for peaks.
|
| 747 |
+
"""
|
| 748 |
+
x = np.array([1, 0, 1, 2, 1, 0, -1, 4, 0])
|
| 749 |
+
peaks, props = find_peaks(x, width=(None, 2), rel_height=0.75)
|
| 750 |
+
assert peaks.size == 1
|
| 751 |
+
xp_assert_equal(peaks, 7*np.ones_like(peaks))
|
| 752 |
+
xp_assert_close(props['widths'], np.asarray([1.35]))
|
| 753 |
+
xp_assert_close(props['width_heights'], np.asarray([1.]))
|
| 754 |
+
xp_assert_close(props['left_ips'], np.asarray([6.4]))
|
| 755 |
+
xp_assert_close(props['right_ips'], np.asarray([7.75]))
|
| 756 |
+
|
| 757 |
+
def test_properties(self):
|
| 758 |
+
"""
|
| 759 |
+
Test returned properties.
|
| 760 |
+
"""
|
| 761 |
+
open_interval = (None, None)
|
| 762 |
+
x = [0, 1, 0, 2, 1.5, 0, 3, 0, 5, 9]
|
| 763 |
+
peaks, props = find_peaks(x,
|
| 764 |
+
height=open_interval, threshold=open_interval,
|
| 765 |
+
prominence=open_interval, width=open_interval)
|
| 766 |
+
assert len(props) == len(self.property_keys)
|
| 767 |
+
for key in self.property_keys:
|
| 768 |
+
assert peaks.size == props[key].size
|
| 769 |
+
|
| 770 |
+
def test_raises(self):
|
| 771 |
+
"""
|
| 772 |
+
Test exceptions raised by function.
|
| 773 |
+
"""
|
| 774 |
+
with raises(ValueError, match="1-D array"):
|
| 775 |
+
find_peaks(np.array(1))
|
| 776 |
+
with raises(ValueError, match="1-D array"):
|
| 777 |
+
find_peaks(np.ones((2, 2)))
|
| 778 |
+
with raises(ValueError, match="distance"):
|
| 779 |
+
find_peaks(np.arange(10), distance=-1)
|
| 780 |
+
|
| 781 |
+
@pytest.mark.filterwarnings("ignore:some peaks have a prominence of 0",
|
| 782 |
+
"ignore:some peaks have a width of 0")
|
| 783 |
+
def test_wlen_smaller_plateau(self):
|
| 784 |
+
"""
|
| 785 |
+
Test behavior of prominence and width calculation if the given window
|
| 786 |
+
length is smaller than a peak's plateau size.
|
| 787 |
+
|
| 788 |
+
Regression test for gh-9110.
|
| 789 |
+
"""
|
| 790 |
+
peaks, props = find_peaks([0, 1, 1, 1, 0], prominence=(None, None),
|
| 791 |
+
width=(None, None), wlen=2)
|
| 792 |
+
xp_assert_equal(peaks, 2 * np.ones_like(peaks))
|
| 793 |
+
xp_assert_equal(props["prominences"], np.zeros_like(props["prominences"]))
|
| 794 |
+
xp_assert_equal(props["widths"], np.zeros_like(props["widths"]))
|
| 795 |
+
xp_assert_equal(props["width_heights"], np.ones_like(props["width_heights"]))
|
| 796 |
+
for key in ("left_bases", "right_bases", "left_ips", "right_ips"):
|
| 797 |
+
xp_assert_equal(props[key], peaks, check_dtype=False)
|
| 798 |
+
|
| 799 |
+
@pytest.mark.parametrize("kwargs", [
|
| 800 |
+
{},
|
| 801 |
+
{"distance": 3.0},
|
| 802 |
+
{"prominence": (None, None)},
|
| 803 |
+
{"width": (None, 2)},
|
| 804 |
+
|
| 805 |
+
])
|
| 806 |
+
def test_readonly_array(self, kwargs):
|
| 807 |
+
"""
|
| 808 |
+
Test readonly arrays are accepted.
|
| 809 |
+
"""
|
| 810 |
+
x = np.linspace(0, 10, 15)
|
| 811 |
+
x_readonly = x.copy()
|
| 812 |
+
x_readonly.flags.writeable = False
|
| 813 |
+
|
| 814 |
+
peaks, _ = find_peaks(x)
|
| 815 |
+
peaks_readonly, _ = find_peaks(x_readonly, **kwargs)
|
| 816 |
+
|
| 817 |
+
xp_assert_close(peaks, peaks_readonly)
|
| 818 |
+
|
| 819 |
+
|
| 820 |
+
class TestFindPeaksCwt:
|
| 821 |
+
|
| 822 |
+
def test_find_peaks_exact(self):
|
| 823 |
+
"""
|
| 824 |
+
Generate a series of gaussians and attempt to find the peak locations.
|
| 825 |
+
"""
|
| 826 |
+
sigmas = [5.0, 3.0, 10.0, 20.0, 10.0, 50.0]
|
| 827 |
+
num_points = 500
|
| 828 |
+
test_data, act_locs = _gen_gaussians_even(sigmas, num_points)
|
| 829 |
+
widths = np.arange(0.1, max(sigmas))
|
| 830 |
+
found_locs = find_peaks_cwt(test_data, widths, gap_thresh=2, min_snr=0,
|
| 831 |
+
min_length=None)
|
| 832 |
+
xp_assert_equal(found_locs, act_locs,
|
| 833 |
+
check_dtype=False,
|
| 834 |
+
err_msg="Found maximum locations did not equal those expected"
|
| 835 |
+
)
|
| 836 |
+
|
| 837 |
+
def test_find_peaks_withnoise(self):
|
| 838 |
+
"""
|
| 839 |
+
Verify that peak locations are (approximately) found
|
| 840 |
+
for a series of gaussians with added noise.
|
| 841 |
+
"""
|
| 842 |
+
sigmas = [5.0, 3.0, 10.0, 20.0, 10.0, 50.0]
|
| 843 |
+
num_points = 500
|
| 844 |
+
test_data, act_locs = _gen_gaussians_even(sigmas, num_points)
|
| 845 |
+
widths = np.arange(0.1, max(sigmas))
|
| 846 |
+
noise_amp = 0.07
|
| 847 |
+
np.random.seed(18181911)
|
| 848 |
+
test_data += (np.random.rand(num_points) - 0.5)*(2*noise_amp)
|
| 849 |
+
found_locs = find_peaks_cwt(test_data, widths, min_length=15,
|
| 850 |
+
gap_thresh=1, min_snr=noise_amp / 5)
|
| 851 |
+
|
| 852 |
+
err_msg ='Different number of peaks found than expected'
|
| 853 |
+
assert len(found_locs) == len(act_locs), err_msg
|
| 854 |
+
diffs = np.abs(found_locs - act_locs)
|
| 855 |
+
max_diffs = np.array(sigmas) / 5
|
| 856 |
+
np.testing.assert_array_less(diffs, max_diffs, 'Maximum location differed' +
|
| 857 |
+
f'by more than {max_diffs}')
|
| 858 |
+
|
| 859 |
+
def test_find_peaks_nopeak(self):
|
| 860 |
+
"""
|
| 861 |
+
Verify that no peak is found in
|
| 862 |
+
data that's just noise.
|
| 863 |
+
"""
|
| 864 |
+
noise_amp = 1.0
|
| 865 |
+
num_points = 100
|
| 866 |
+
rng = np.random.RandomState(181819141)
|
| 867 |
+
test_data = (rng.rand(num_points) - 0.5)*(2*noise_amp)
|
| 868 |
+
widths = np.arange(10, 50)
|
| 869 |
+
found_locs = find_peaks_cwt(test_data, widths, min_snr=5, noise_perc=30)
|
| 870 |
+
assert len(found_locs) == 0
|
| 871 |
+
|
| 872 |
+
def test_find_peaks_with_non_default_wavelets(self):
|
| 873 |
+
x = gaussian(200, 2)
|
| 874 |
+
widths = np.array([1, 2, 3, 4])
|
| 875 |
+
a = find_peaks_cwt(x, widths, wavelet=gaussian)
|
| 876 |
+
|
| 877 |
+
xp_assert_equal(a, np.asarray([100]), check_dtype=False)
|
| 878 |
+
|
| 879 |
+
def test_find_peaks_window_size(self):
|
| 880 |
+
"""
|
| 881 |
+
Verify that window_size is passed correctly to private function and
|
| 882 |
+
affects the result.
|
| 883 |
+
"""
|
| 884 |
+
sigmas = [2.0, 2.0]
|
| 885 |
+
num_points = 1000
|
| 886 |
+
test_data, act_locs = _gen_gaussians_even(sigmas, num_points)
|
| 887 |
+
widths = np.arange(0.1, max(sigmas), 0.2)
|
| 888 |
+
noise_amp = 0.05
|
| 889 |
+
rng = np.random.RandomState(18181911)
|
| 890 |
+
test_data += (rng.rand(num_points) - 0.5)*(2*noise_amp)
|
| 891 |
+
|
| 892 |
+
# Possibly contrived negative region to throw off peak finding
|
| 893 |
+
# when window_size is too large
|
| 894 |
+
test_data[250:320] -= 1
|
| 895 |
+
|
| 896 |
+
found_locs = find_peaks_cwt(test_data, widths, gap_thresh=2, min_snr=3,
|
| 897 |
+
min_length=None, window_size=None)
|
| 898 |
+
with pytest.raises(AssertionError):
|
| 899 |
+
assert found_locs.size == act_locs.size
|
| 900 |
+
|
| 901 |
+
found_locs = find_peaks_cwt(test_data, widths, gap_thresh=2, min_snr=3,
|
| 902 |
+
min_length=None, window_size=20)
|
| 903 |
+
assert found_locs.size == act_locs.size
|
| 904 |
+
|
| 905 |
+
def test_find_peaks_with_one_width(self):
|
| 906 |
+
"""
|
| 907 |
+
Verify that the `width` argument
|
| 908 |
+
in `find_peaks_cwt` can be a float
|
| 909 |
+
"""
|
| 910 |
+
xs = np.arange(0, np.pi, 0.05)
|
| 911 |
+
test_data = np.sin(xs)
|
| 912 |
+
widths = 1
|
| 913 |
+
found_locs = find_peaks_cwt(test_data, widths)
|
| 914 |
+
|
| 915 |
+
np.testing.assert_equal(found_locs, 32)
|
shared/package-files/65/65309a39d3ab82d89f5b1426173ca782b2eaf6ec3307205d8924b9984f830e81/blob
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
""" Optimizations of the expression tree representation for better CSE
|
| 2 |
+
opportunities.
|
| 3 |
+
"""
|
| 4 |
+
from sympy.core import Add, Basic, Mul
|
| 5 |
+
from sympy.core.singleton import S
|
| 6 |
+
from sympy.core.sorting import default_sort_key
|
| 7 |
+
from sympy.core.traversal import preorder_traversal
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def sub_pre(e):
|
| 11 |
+
""" Replace y - x with -(x - y) if -1 can be extracted from y - x.
|
| 12 |
+
"""
|
| 13 |
+
# replacing Add, A, from which -1 can be extracted with -1*-A
|
| 14 |
+
adds = [a for a in e.atoms(Add) if a.could_extract_minus_sign()]
|
| 15 |
+
reps = {}
|
| 16 |
+
ignore = set()
|
| 17 |
+
for a in adds:
|
| 18 |
+
na = -a
|
| 19 |
+
if na.is_Mul: # e.g. MatExpr
|
| 20 |
+
ignore.add(a)
|
| 21 |
+
continue
|
| 22 |
+
reps[a] = Mul._from_args([S.NegativeOne, na])
|
| 23 |
+
|
| 24 |
+
e = e.xreplace(reps)
|
| 25 |
+
|
| 26 |
+
# repeat again for persisting Adds but mark these with a leading 1, -1
|
| 27 |
+
# e.g. y - x -> 1*-1*(x - y)
|
| 28 |
+
if isinstance(e, Basic):
|
| 29 |
+
negs = {}
|
| 30 |
+
for a in sorted(e.atoms(Add), key=default_sort_key):
|
| 31 |
+
if a in ignore:
|
| 32 |
+
continue
|
| 33 |
+
if a in reps:
|
| 34 |
+
negs[a] = reps[a]
|
| 35 |
+
elif a.could_extract_minus_sign():
|
| 36 |
+
negs[a] = Mul._from_args([S.One, S.NegativeOne, -a])
|
| 37 |
+
e = e.xreplace(negs)
|
| 38 |
+
return e
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
def sub_post(e):
|
| 42 |
+
""" Replace 1*-1*x with -x.
|
| 43 |
+
"""
|
| 44 |
+
replacements = []
|
| 45 |
+
for node in preorder_traversal(e):
|
| 46 |
+
if isinstance(node, Mul) and \
|
| 47 |
+
node.args[0] is S.One and node.args[1] is S.NegativeOne:
|
| 48 |
+
replacements.append((node, -Mul._from_args(node.args[2:])))
|
| 49 |
+
for node, replacement in replacements:
|
| 50 |
+
e = e.xreplace({node: replacement})
|
| 51 |
+
|
| 52 |
+
return e
|
shared/package-files/65/65327f94b5ae5c87675fcd32d4e036df43bc7a9e74a719526b669c6b3bfed60c/blob
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Any, Callable, List, Optional, TypeVar
|
| 2 |
+
|
| 3 |
+
_F = TypeVar("_F", bound=Callable[..., Any])
|
| 4 |
+
|
| 5 |
+
def conditional_page(_F) -> _F: ...
|
| 6 |
+
def require_http_methods(request_method_list: List[str]) -> Callable: ...
|
| 7 |
+
def require_GET(_F) -> _F: ...
|
| 8 |
+
def require_POST(_F) -> _F: ...
|
| 9 |
+
def require_safe(_F) -> _F: ...
|
| 10 |
+
def condition(etag_func: Optional[Callable] = ..., last_modified_func: Optional[Callable] = ...) -> Callable: ...
|
| 11 |
+
def etag(etag_func: Callable[..., Any]) -> Callable[[_F], _F]: ...
|
| 12 |
+
def last_modified(last_modified_func: Callable[..., Any]) -> Callable[[_F], _F]: ...
|
shared/package-files/65/65335b1a8e3308414fdf51fa2273128d42ddcdc49bfaf8d112c75eaaf746f8c6/blob
ADDED
|
Binary file (606 Bytes). View file
|
|
|
shared/package-files/65/6536ad38eb2d29a5ad11673bf087690eea02298629ea3f544897da41923267e0/blob
ADDED
|
Binary file (1.68 kB). View file
|
|
|
shared/package-files/65/6539caf32658a84846de97bc295c2625fe0af3dd1132ef1aeb40389c2feace73/blob
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import pytest
|
| 3 |
+
|
| 4 |
+
import pandas as pd
|
| 5 |
+
from pandas import (
|
| 6 |
+
DataFrame,
|
| 7 |
+
DatetimeIndex,
|
| 8 |
+
Index,
|
| 9 |
+
Series,
|
| 10 |
+
date_range,
|
| 11 |
+
)
|
| 12 |
+
import pandas._testing as tm
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
class TestDataFrameTruncate:
|
| 16 |
+
def test_truncate(self, datetime_frame, frame_or_series):
|
| 17 |
+
ts = datetime_frame[::3]
|
| 18 |
+
ts = tm.get_obj(ts, frame_or_series)
|
| 19 |
+
|
| 20 |
+
start, end = datetime_frame.index[3], datetime_frame.index[6]
|
| 21 |
+
|
| 22 |
+
start_missing = datetime_frame.index[2]
|
| 23 |
+
end_missing = datetime_frame.index[7]
|
| 24 |
+
|
| 25 |
+
# neither specified
|
| 26 |
+
truncated = ts.truncate()
|
| 27 |
+
tm.assert_equal(truncated, ts)
|
| 28 |
+
|
| 29 |
+
# both specified
|
| 30 |
+
expected = ts[1:3]
|
| 31 |
+
|
| 32 |
+
truncated = ts.truncate(start, end)
|
| 33 |
+
tm.assert_equal(truncated, expected)
|
| 34 |
+
|
| 35 |
+
truncated = ts.truncate(start_missing, end_missing)
|
| 36 |
+
tm.assert_equal(truncated, expected)
|
| 37 |
+
|
| 38 |
+
# start specified
|
| 39 |
+
expected = ts[1:]
|
| 40 |
+
|
| 41 |
+
truncated = ts.truncate(before=start)
|
| 42 |
+
tm.assert_equal(truncated, expected)
|
| 43 |
+
|
| 44 |
+
truncated = ts.truncate(before=start_missing)
|
| 45 |
+
tm.assert_equal(truncated, expected)
|
| 46 |
+
|
| 47 |
+
# end specified
|
| 48 |
+
expected = ts[:3]
|
| 49 |
+
|
| 50 |
+
truncated = ts.truncate(after=end)
|
| 51 |
+
tm.assert_equal(truncated, expected)
|
| 52 |
+
|
| 53 |
+
truncated = ts.truncate(after=end_missing)
|
| 54 |
+
tm.assert_equal(truncated, expected)
|
| 55 |
+
|
| 56 |
+
# corner case, empty series/frame returned
|
| 57 |
+
truncated = ts.truncate(after=ts.index[0] - ts.index.freq)
|
| 58 |
+
assert len(truncated) == 0
|
| 59 |
+
|
| 60 |
+
truncated = ts.truncate(before=ts.index[-1] + ts.index.freq)
|
| 61 |
+
assert len(truncated) == 0
|
| 62 |
+
|
| 63 |
+
msg = "Truncate: 2000-01-06 00:00:00 must be after 2000-05-16 00:00:00"
|
| 64 |
+
with pytest.raises(ValueError, match=msg):
|
| 65 |
+
ts.truncate(
|
| 66 |
+
before=ts.index[-1] - ts.index.freq, after=ts.index[0] + ts.index.freq
|
| 67 |
+
)
|
| 68 |
+
|
| 69 |
+
def test_truncate_nonsortedindex(self, frame_or_series):
|
| 70 |
+
# GH#17935
|
| 71 |
+
|
| 72 |
+
obj = DataFrame({"A": ["a", "b", "c", "d", "e"]}, index=[5, 3, 2, 9, 0])
|
| 73 |
+
obj = tm.get_obj(obj, frame_or_series)
|
| 74 |
+
|
| 75 |
+
msg = "truncate requires a sorted index"
|
| 76 |
+
with pytest.raises(ValueError, match=msg):
|
| 77 |
+
obj.truncate(before=3, after=9)
|
| 78 |
+
|
| 79 |
+
def test_sort_values_nonsortedindex(self):
|
| 80 |
+
rng = date_range("2011-01-01", "2012-01-01", freq="W")
|
| 81 |
+
ts = DataFrame(
|
| 82 |
+
{
|
| 83 |
+
"A": np.random.default_rng(2).standard_normal(len(rng)),
|
| 84 |
+
"B": np.random.default_rng(2).standard_normal(len(rng)),
|
| 85 |
+
},
|
| 86 |
+
index=rng,
|
| 87 |
+
)
|
| 88 |
+
|
| 89 |
+
decreasing = ts.sort_values("A", ascending=False)
|
| 90 |
+
|
| 91 |
+
msg = "truncate requires a sorted index"
|
| 92 |
+
with pytest.raises(ValueError, match=msg):
|
| 93 |
+
decreasing.truncate(before="2011-11", after="2011-12")
|
| 94 |
+
|
| 95 |
+
def test_truncate_nonsortedindex_axis1(self):
|
| 96 |
+
# GH#17935
|
| 97 |
+
|
| 98 |
+
df = DataFrame(
|
| 99 |
+
{
|
| 100 |
+
3: np.random.default_rng(2).standard_normal(5),
|
| 101 |
+
20: np.random.default_rng(2).standard_normal(5),
|
| 102 |
+
2: np.random.default_rng(2).standard_normal(5),
|
| 103 |
+
0: np.random.default_rng(2).standard_normal(5),
|
| 104 |
+
},
|
| 105 |
+
columns=[3, 20, 2, 0],
|
| 106 |
+
)
|
| 107 |
+
msg = "truncate requires a sorted index"
|
| 108 |
+
with pytest.raises(ValueError, match=msg):
|
| 109 |
+
df.truncate(before=2, after=20, axis=1)
|
| 110 |
+
|
| 111 |
+
@pytest.mark.parametrize(
|
| 112 |
+
"before, after, indices",
|
| 113 |
+
[(1, 2, [2, 1]), (None, 2, [2, 1, 0]), (1, None, [3, 2, 1])],
|
| 114 |
+
)
|
| 115 |
+
@pytest.mark.parametrize("dtyp", [*tm.ALL_REAL_NUMPY_DTYPES, "datetime64[ns]"])
|
| 116 |
+
def test_truncate_decreasing_index(
|
| 117 |
+
self, before, after, indices, dtyp, frame_or_series
|
| 118 |
+
):
|
| 119 |
+
# https://github.com/pandas-dev/pandas/issues/33756
|
| 120 |
+
idx = Index([3, 2, 1, 0], dtype=dtyp)
|
| 121 |
+
if isinstance(idx, DatetimeIndex):
|
| 122 |
+
before = pd.Timestamp(before) if before is not None else None
|
| 123 |
+
after = pd.Timestamp(after) if after is not None else None
|
| 124 |
+
indices = [pd.Timestamp(i) for i in indices]
|
| 125 |
+
values = frame_or_series(range(len(idx)), index=idx)
|
| 126 |
+
result = values.truncate(before=before, after=after)
|
| 127 |
+
expected = values.loc[indices]
|
| 128 |
+
tm.assert_equal(result, expected)
|
| 129 |
+
|
| 130 |
+
def test_truncate_multiindex(self, frame_or_series):
|
| 131 |
+
# GH 34564
|
| 132 |
+
mi = pd.MultiIndex.from_product([[1, 2, 3, 4], ["A", "B"]], names=["L1", "L2"])
|
| 133 |
+
s1 = DataFrame(range(mi.shape[0]), index=mi, columns=["col"])
|
| 134 |
+
s1 = tm.get_obj(s1, frame_or_series)
|
| 135 |
+
|
| 136 |
+
result = s1.truncate(before=2, after=3)
|
| 137 |
+
|
| 138 |
+
df = DataFrame.from_dict(
|
| 139 |
+
{"L1": [2, 2, 3, 3], "L2": ["A", "B", "A", "B"], "col": [2, 3, 4, 5]}
|
| 140 |
+
)
|
| 141 |
+
expected = df.set_index(["L1", "L2"])
|
| 142 |
+
expected = tm.get_obj(expected, frame_or_series)
|
| 143 |
+
|
| 144 |
+
tm.assert_equal(result, expected)
|
| 145 |
+
|
| 146 |
+
def test_truncate_index_only_one_unique_value(self, frame_or_series):
|
| 147 |
+
# GH 42365
|
| 148 |
+
obj = Series(0, index=date_range("2021-06-30", "2021-06-30")).repeat(5)
|
| 149 |
+
if frame_or_series is DataFrame:
|
| 150 |
+
obj = obj.to_frame(name="a")
|
| 151 |
+
|
| 152 |
+
truncated = obj.truncate("2021-06-28", "2021-07-01")
|
| 153 |
+
|
| 154 |
+
tm.assert_equal(truncated, obj)
|
shared/package-files/65/653ad8d50f1c3cb3a0cc4d2876c60aaa40732c42779dea2e1db547639d27b085/blob
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Recognize image file formats based on their first few bytes."""
|
| 2 |
+
|
| 3 |
+
from os import PathLike
|
| 4 |
+
|
| 5 |
+
__all__ = ["what"]
|
| 6 |
+
|
| 7 |
+
#-------------------------#
|
| 8 |
+
# Recognize image headers #
|
| 9 |
+
#-------------------------#
|
| 10 |
+
|
| 11 |
+
def what(file, h=None):
|
| 12 |
+
f = None
|
| 13 |
+
try:
|
| 14 |
+
if h is None:
|
| 15 |
+
if isinstance(file, (str, PathLike)):
|
| 16 |
+
f = open(file, 'rb')
|
| 17 |
+
h = f.read(32)
|
| 18 |
+
else:
|
| 19 |
+
location = file.tell()
|
| 20 |
+
h = file.read(32)
|
| 21 |
+
file.seek(location)
|
| 22 |
+
for tf in tests:
|
| 23 |
+
res = tf(h, f)
|
| 24 |
+
if res:
|
| 25 |
+
return res
|
| 26 |
+
finally:
|
| 27 |
+
if f: f.close()
|
| 28 |
+
return None
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
#---------------------------------#
|
| 32 |
+
# Subroutines per image file type #
|
| 33 |
+
#---------------------------------#
|
| 34 |
+
|
| 35 |
+
tests = []
|
| 36 |
+
|
| 37 |
+
def test_jpeg(h, f):
|
| 38 |
+
"""JPEG data in JFIF or Exif format"""
|
| 39 |
+
if h[6:10] in (b'JFIF', b'Exif'):
|
| 40 |
+
return 'jpeg'
|
| 41 |
+
|
| 42 |
+
tests.append(test_jpeg)
|
| 43 |
+
|
| 44 |
+
def test_png(h, f):
|
| 45 |
+
if h.startswith(b'\211PNG\r\n\032\n'):
|
| 46 |
+
return 'png'
|
| 47 |
+
|
| 48 |
+
tests.append(test_png)
|
| 49 |
+
|
| 50 |
+
def test_gif(h, f):
|
| 51 |
+
"""GIF ('87 and '89 variants)"""
|
| 52 |
+
if h[:6] in (b'GIF87a', b'GIF89a'):
|
| 53 |
+
return 'gif'
|
| 54 |
+
|
| 55 |
+
tests.append(test_gif)
|
| 56 |
+
|
| 57 |
+
def test_tiff(h, f):
|
| 58 |
+
"""TIFF (can be in Motorola or Intel byte order)"""
|
| 59 |
+
if h[:2] in (b'MM', b'II'):
|
| 60 |
+
return 'tiff'
|
| 61 |
+
|
| 62 |
+
tests.append(test_tiff)
|
| 63 |
+
|
| 64 |
+
def test_rgb(h, f):
|
| 65 |
+
"""SGI image library"""
|
| 66 |
+
if h.startswith(b'\001\332'):
|
| 67 |
+
return 'rgb'
|
| 68 |
+
|
| 69 |
+
tests.append(test_rgb)
|
| 70 |
+
|
| 71 |
+
def test_pbm(h, f):
|
| 72 |
+
"""PBM (portable bitmap)"""
|
| 73 |
+
if len(h) >= 3 and \
|
| 74 |
+
h[0] == ord(b'P') and h[1] in b'14' and h[2] in b' \t\n\r':
|
| 75 |
+
return 'pbm'
|
| 76 |
+
|
| 77 |
+
tests.append(test_pbm)
|
| 78 |
+
|
| 79 |
+
def test_pgm(h, f):
|
| 80 |
+
"""PGM (portable graymap)"""
|
| 81 |
+
if len(h) >= 3 and \
|
| 82 |
+
h[0] == ord(b'P') and h[1] in b'25' and h[2] in b' \t\n\r':
|
| 83 |
+
return 'pgm'
|
| 84 |
+
|
| 85 |
+
tests.append(test_pgm)
|
| 86 |
+
|
| 87 |
+
def test_ppm(h, f):
|
| 88 |
+
"""PPM (portable pixmap)"""
|
| 89 |
+
if len(h) >= 3 and \
|
| 90 |
+
h[0] == ord(b'P') and h[1] in b'36' and h[2] in b' \t\n\r':
|
| 91 |
+
return 'ppm'
|
| 92 |
+
|
| 93 |
+
tests.append(test_ppm)
|
| 94 |
+
|
| 95 |
+
def test_rast(h, f):
|
| 96 |
+
"""Sun raster file"""
|
| 97 |
+
if h.startswith(b'\x59\xA6\x6A\x95'):
|
| 98 |
+
return 'rast'
|
| 99 |
+
|
| 100 |
+
tests.append(test_rast)
|
| 101 |
+
|
| 102 |
+
def test_xbm(h, f):
|
| 103 |
+
"""X bitmap (X10 or X11)"""
|
| 104 |
+
if h.startswith(b'#define '):
|
| 105 |
+
return 'xbm'
|
| 106 |
+
|
| 107 |
+
tests.append(test_xbm)
|
| 108 |
+
|
| 109 |
+
def test_bmp(h, f):
|
| 110 |
+
if h.startswith(b'BM'):
|
| 111 |
+
return 'bmp'
|
| 112 |
+
|
| 113 |
+
tests.append(test_bmp)
|
| 114 |
+
|
| 115 |
+
def test_webp(h, f):
|
| 116 |
+
if h.startswith(b'RIFF') and h[8:12] == b'WEBP':
|
| 117 |
+
return 'webp'
|
| 118 |
+
|
| 119 |
+
tests.append(test_webp)
|
| 120 |
+
|
| 121 |
+
def test_exr(h, f):
|
| 122 |
+
if h.startswith(b'\x76\x2f\x31\x01'):
|
| 123 |
+
return 'exr'
|
| 124 |
+
|
| 125 |
+
tests.append(test_exr)
|
| 126 |
+
|
| 127 |
+
#--------------------#
|
| 128 |
+
# Small test program #
|
| 129 |
+
#--------------------#
|
| 130 |
+
|
| 131 |
+
def test():
|
| 132 |
+
import sys
|
| 133 |
+
recursive = 0
|
| 134 |
+
if sys.argv[1:] and sys.argv[1] == '-r':
|
| 135 |
+
del sys.argv[1:2]
|
| 136 |
+
recursive = 1
|
| 137 |
+
try:
|
| 138 |
+
if sys.argv[1:]:
|
| 139 |
+
testall(sys.argv[1:], recursive, 1)
|
| 140 |
+
else:
|
| 141 |
+
testall(['.'], recursive, 1)
|
| 142 |
+
except KeyboardInterrupt:
|
| 143 |
+
sys.stderr.write('\n[Interrupted]\n')
|
| 144 |
+
sys.exit(1)
|
| 145 |
+
|
| 146 |
+
def testall(list, recursive, toplevel):
|
| 147 |
+
import sys
|
| 148 |
+
import os
|
| 149 |
+
for filename in list:
|
| 150 |
+
if os.path.isdir(filename):
|
| 151 |
+
print(filename + '/:', end=' ')
|
| 152 |
+
if recursive or toplevel:
|
| 153 |
+
print('recursing down:')
|
| 154 |
+
import glob
|
| 155 |
+
names = glob.glob(os.path.join(glob.escape(filename), '*'))
|
| 156 |
+
testall(names, recursive, 0)
|
| 157 |
+
else:
|
| 158 |
+
print('*** directory (use -r) ***')
|
| 159 |
+
else:
|
| 160 |
+
print(filename + ':', end=' ')
|
| 161 |
+
sys.stdout.flush()
|
| 162 |
+
try:
|
| 163 |
+
print(what(filename))
|
| 164 |
+
except OSError:
|
| 165 |
+
print('*** not found ***')
|
| 166 |
+
|
| 167 |
+
if __name__ == '__main__':
|
| 168 |
+
test()
|
shared/package-files/65/653af36faa03ac80cf96b5563f7066b646f3ddf7c769a490a1791f4c6b42b851/blob
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
function t0(value)
|
| 2 |
+
real value
|
| 3 |
+
real t0
|
| 4 |
+
t0 = value
|
| 5 |
+
end
|
| 6 |
+
function t4(value)
|
| 7 |
+
real*4 value
|
| 8 |
+
real*4 t4
|
| 9 |
+
t4 = value
|
| 10 |
+
end
|
| 11 |
+
function t8(value)
|
| 12 |
+
real*8 value
|
| 13 |
+
real*8 t8
|
| 14 |
+
t8 = value
|
| 15 |
+
end
|
| 16 |
+
function td(value)
|
| 17 |
+
double precision value
|
| 18 |
+
double precision td
|
| 19 |
+
td = value
|
| 20 |
+
end
|
| 21 |
+
|
| 22 |
+
subroutine s0(t0,value)
|
| 23 |
+
real value
|
| 24 |
+
real t0
|
| 25 |
+
cf2py intent(out) t0
|
| 26 |
+
t0 = value
|
| 27 |
+
end
|
| 28 |
+
subroutine s4(t4,value)
|
| 29 |
+
real*4 value
|
| 30 |
+
real*4 t4
|
| 31 |
+
cf2py intent(out) t4
|
| 32 |
+
t4 = value
|
| 33 |
+
end
|
| 34 |
+
subroutine s8(t8,value)
|
| 35 |
+
real*8 value
|
| 36 |
+
real*8 t8
|
| 37 |
+
cf2py intent(out) t8
|
| 38 |
+
t8 = value
|
| 39 |
+
end
|
| 40 |
+
subroutine sd(td,value)
|
| 41 |
+
double precision value
|
| 42 |
+
double precision td
|
| 43 |
+
cf2py intent(out) td
|
| 44 |
+
td = value
|
| 45 |
+
end
|
shared/package-files/65/6543d52f7eacdc035fe1d8afae22d6a601d8141bdad3dff4f482bb84e4534a7b/blob
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
import threading
|
| 3 |
+
from multiprocessing.context import BaseContext
|
| 4 |
+
from typing import Any, Callable, ContextManager, Optional, Union
|
| 5 |
+
|
| 6 |
+
_LockLike = Union[Lock, RLock]
|
| 7 |
+
|
| 8 |
+
class Barrier(threading.Barrier):
|
| 9 |
+
def __init__(
|
| 10 |
+
self, parties: int, action: Optional[Callable[..., Any]] = ..., timeout: Optional[float] = ..., *ctx: BaseContext
|
| 11 |
+
) -> None: ...
|
| 12 |
+
|
| 13 |
+
class BoundedSemaphore(Semaphore):
|
| 14 |
+
def __init__(self, value: int = ..., *, ctx: BaseContext) -> None: ...
|
| 15 |
+
|
| 16 |
+
class Condition(ContextManager[bool]):
|
| 17 |
+
def __init__(self, lock: Optional[_LockLike] = ..., *, ctx: BaseContext) -> None: ...
|
| 18 |
+
if sys.version_info >= (3, 7):
|
| 19 |
+
def notify(self, n: int = ...) -> None: ...
|
| 20 |
+
else:
|
| 21 |
+
def notify(self) -> None: ...
|
| 22 |
+
def notify_all(self) -> None: ...
|
| 23 |
+
def wait(self, timeout: Optional[float] = ...) -> bool: ...
|
| 24 |
+
def wait_for(self, predicate: Callable[[], bool], timeout: Optional[float] = ...) -> bool: ...
|
| 25 |
+
def acquire(self, block: bool = ..., timeout: Optional[float] = ...) -> bool: ...
|
| 26 |
+
def release(self) -> None: ...
|
| 27 |
+
|
| 28 |
+
class Event(ContextManager[bool]):
|
| 29 |
+
def __init__(self, lock: Optional[_LockLike] = ..., *, ctx: BaseContext) -> None: ...
|
| 30 |
+
def is_set(self) -> bool: ...
|
| 31 |
+
def set(self) -> None: ...
|
| 32 |
+
def clear(self) -> None: ...
|
| 33 |
+
def wait(self, timeout: Optional[float] = ...) -> bool: ...
|
| 34 |
+
|
| 35 |
+
class Lock(SemLock):
|
| 36 |
+
def __init__(self, *, ctx: BaseContext) -> None: ...
|
| 37 |
+
|
| 38 |
+
class RLock(SemLock):
|
| 39 |
+
def __init__(self, *, ctx: BaseContext) -> None: ...
|
| 40 |
+
|
| 41 |
+
class Semaphore(SemLock):
|
| 42 |
+
def __init__(self, value: int = ..., *, ctx: BaseContext) -> None: ...
|
| 43 |
+
|
| 44 |
+
# Not part of public API
|
| 45 |
+
class SemLock(ContextManager[bool]):
|
| 46 |
+
def acquire(self, block: bool = ..., timeout: Optional[float] = ...) -> bool: ...
|
| 47 |
+
def release(self) -> None: ...
|
shared/package-files/65/654768af0a358adbf8df074b003c954cfdfa888077ce0a1d622adfe034baced2/blob
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import shutil
|
| 3 |
+
from os.path import isdir, isfile, islink
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def rm_empty_dir(path):
|
| 7 |
+
try:
|
| 8 |
+
os.rmdir(path)
|
| 9 |
+
except OSError: # directory might not exist or not be empty
|
| 10 |
+
pass
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def rm_rf(path):
|
| 14 |
+
if islink(path) or isfile(path):
|
| 15 |
+
# Note that we have to check if the destination is a link because
|
| 16 |
+
# exists('/path/to/dead-link') will return False, although
|
| 17 |
+
# islink('/path/to/dead-link') is True.
|
| 18 |
+
os.unlink(path)
|
| 19 |
+
|
| 20 |
+
elif isdir(path):
|
| 21 |
+
shutil.rmtree(path)
|
shared/package-files/65/65489e12e6bf63edf35fa19d1da8de0f7da20bf7d635ac38a21ba2b86493e882/blob
ADDED
|
@@ -0,0 +1,403 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from torch import Tensor
|
| 3 |
+
|
| 4 |
+
from .optimizer import (Optimizer, _use_grad_for_differentiable, _get_value, _default_to_fused_or_foreach,
|
| 5 |
+
_get_scalar_dtype, _differentiable_doc, _maximize_doc, _foreach_doc, _view_as_real,
|
| 6 |
+
_capturable_doc)
|
| 7 |
+
from typing import List, Optional
|
| 8 |
+
|
| 9 |
+
__all__ = ["Adamax", "adamax"]
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
class Adamax(Optimizer):
|
| 13 |
+
def __init__(
|
| 14 |
+
self,
|
| 15 |
+
params,
|
| 16 |
+
lr=2e-3,
|
| 17 |
+
betas=(0.9, 0.999),
|
| 18 |
+
eps=1e-8,
|
| 19 |
+
weight_decay=0,
|
| 20 |
+
foreach: Optional[bool] = None,
|
| 21 |
+
*,
|
| 22 |
+
maximize: bool = False,
|
| 23 |
+
differentiable: bool = False,
|
| 24 |
+
capturable: bool = False,
|
| 25 |
+
):
|
| 26 |
+
if not 0.0 <= lr:
|
| 27 |
+
raise ValueError(f"Invalid learning rate: {lr}")
|
| 28 |
+
if not 0.0 <= eps:
|
| 29 |
+
raise ValueError(f"Invalid epsilon value: {eps}")
|
| 30 |
+
if not 0.0 <= betas[0] < 1.0:
|
| 31 |
+
raise ValueError(f"Invalid beta parameter at index 0: {betas[0]}")
|
| 32 |
+
if not 0.0 <= betas[1] < 1.0:
|
| 33 |
+
raise ValueError(f"Invalid beta parameter at index 1: {betas[1]}")
|
| 34 |
+
if not 0.0 <= weight_decay:
|
| 35 |
+
raise ValueError(f"Invalid weight_decay value: {weight_decay}")
|
| 36 |
+
|
| 37 |
+
defaults = dict(
|
| 38 |
+
lr=lr,
|
| 39 |
+
betas=betas,
|
| 40 |
+
eps=eps,
|
| 41 |
+
weight_decay=weight_decay,
|
| 42 |
+
foreach=foreach,
|
| 43 |
+
maximize=maximize,
|
| 44 |
+
differentiable=differentiable,
|
| 45 |
+
capturable=capturable,
|
| 46 |
+
)
|
| 47 |
+
super().__init__(params, defaults)
|
| 48 |
+
|
| 49 |
+
def __setstate__(self, state):
|
| 50 |
+
super().__setstate__(state)
|
| 51 |
+
for group in self.param_groups:
|
| 52 |
+
group.setdefault("foreach", None)
|
| 53 |
+
group.setdefault("maximize", False)
|
| 54 |
+
group.setdefault("differentiable", False)
|
| 55 |
+
group.setdefault("capturable", False)
|
| 56 |
+
for p in group["params"]:
|
| 57 |
+
p_state = self.state.get(p, [])
|
| 58 |
+
if len(p_state) != 0 and not torch.is_tensor(p_state['step']):
|
| 59 |
+
step_val = float(p_state["step"])
|
| 60 |
+
p_state["step"] = (torch.tensor(step_val, dtype=_get_scalar_dtype(), device=p.device) if group['capturable']
|
| 61 |
+
else torch.tensor(step_val, dtype=_get_scalar_dtype()))
|
| 62 |
+
|
| 63 |
+
def _init_group(self, group, params_with_grad, grads, exp_avgs, exp_infs, state_steps):
|
| 64 |
+
has_complex = False
|
| 65 |
+
for p in group["params"]:
|
| 66 |
+
if p.grad is None:
|
| 67 |
+
continue
|
| 68 |
+
has_complex |= torch.is_complex(p)
|
| 69 |
+
params_with_grad.append(p)
|
| 70 |
+
if p.grad.is_sparse:
|
| 71 |
+
raise RuntimeError("Adamax does not support sparse gradients")
|
| 72 |
+
grads.append(p.grad)
|
| 73 |
+
|
| 74 |
+
state = self.state[p]
|
| 75 |
+
|
| 76 |
+
# State initialization
|
| 77 |
+
if len(state) == 0:
|
| 78 |
+
state['step'] = (torch.zeros((), dtype=_get_scalar_dtype(), device=p.device)
|
| 79 |
+
if group['capturable'] else torch.tensor(0.0, dtype=_get_scalar_dtype()))
|
| 80 |
+
state["exp_avg"] = torch.zeros_like(
|
| 81 |
+
p, memory_format=torch.preserve_format
|
| 82 |
+
)
|
| 83 |
+
state["exp_inf"] = torch.zeros_like(
|
| 84 |
+
p, memory_format=torch.preserve_format
|
| 85 |
+
)
|
| 86 |
+
|
| 87 |
+
exp_avgs.append(state["exp_avg"])
|
| 88 |
+
exp_infs.append(state["exp_inf"])
|
| 89 |
+
state_steps.append(state["step"])
|
| 90 |
+
|
| 91 |
+
return has_complex
|
| 92 |
+
|
| 93 |
+
@_use_grad_for_differentiable
|
| 94 |
+
def step(self, closure=None):
|
| 95 |
+
"""Performs a single optimization step.
|
| 96 |
+
|
| 97 |
+
Args:
|
| 98 |
+
closure (Callable, optional): A closure that reevaluates the model
|
| 99 |
+
and returns the loss.
|
| 100 |
+
"""
|
| 101 |
+
self._cuda_graph_capture_health_check()
|
| 102 |
+
|
| 103 |
+
loss = None
|
| 104 |
+
if closure is not None:
|
| 105 |
+
with torch.enable_grad():
|
| 106 |
+
loss = closure()
|
| 107 |
+
|
| 108 |
+
for group in self.param_groups:
|
| 109 |
+
params_with_grad = []
|
| 110 |
+
grads = []
|
| 111 |
+
exp_avgs = []
|
| 112 |
+
exp_infs = []
|
| 113 |
+
state_steps = []
|
| 114 |
+
|
| 115 |
+
beta1, beta2 = group["betas"]
|
| 116 |
+
eps = group["eps"]
|
| 117 |
+
lr = group["lr"]
|
| 118 |
+
weight_decay = group["weight_decay"]
|
| 119 |
+
foreach = group["foreach"]
|
| 120 |
+
maximize = group["maximize"]
|
| 121 |
+
differentiable = group["differentiable"]
|
| 122 |
+
capturable = group["capturable"]
|
| 123 |
+
|
| 124 |
+
has_complex = self._init_group(group, params_with_grad, grads, exp_avgs, exp_infs, state_steps)
|
| 125 |
+
|
| 126 |
+
adamax(
|
| 127 |
+
params_with_grad,
|
| 128 |
+
grads,
|
| 129 |
+
exp_avgs,
|
| 130 |
+
exp_infs,
|
| 131 |
+
state_steps,
|
| 132 |
+
eps=eps,
|
| 133 |
+
beta1=beta1,
|
| 134 |
+
beta2=beta2,
|
| 135 |
+
lr=lr,
|
| 136 |
+
weight_decay=weight_decay,
|
| 137 |
+
foreach=foreach,
|
| 138 |
+
maximize=maximize,
|
| 139 |
+
differentiable=differentiable,
|
| 140 |
+
capturable=capturable,
|
| 141 |
+
has_complex=has_complex,
|
| 142 |
+
)
|
| 143 |
+
|
| 144 |
+
return loss
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
Adamax.__doc__ = r"""Implements Adamax algorithm (a variant of Adam based on infinity norm).
|
| 148 |
+
|
| 149 |
+
.. math::
|
| 150 |
+
\begin{aligned}
|
| 151 |
+
&\rule{110mm}{0.4pt} \\
|
| 152 |
+
&\textbf{input} : \gamma \text{ (lr)}, \beta_1, \beta_2
|
| 153 |
+
\text{ (betas)},\theta_0 \text{ (params)},f(\theta) \text{ (objective)},
|
| 154 |
+
\: \lambda \text{ (weight decay)}, \\
|
| 155 |
+
&\hspace{13mm} \epsilon \text{ (epsilon)} \\
|
| 156 |
+
&\textbf{initialize} : m_0 \leftarrow 0 \text{ ( first moment)},
|
| 157 |
+
u_0 \leftarrow 0 \text{ ( infinity norm)} \\[-1.ex]
|
| 158 |
+
&\rule{110mm}{0.4pt} \\
|
| 159 |
+
&\textbf{for} \: t=1 \: \textbf{to} \: \ldots \: \textbf{do} \\
|
| 160 |
+
&\hspace{5mm}g_t \leftarrow \nabla_{\theta} f_t (\theta_{t-1}) \\
|
| 161 |
+
&\hspace{5mm}if \: \lambda \neq 0 \\
|
| 162 |
+
&\hspace{10mm} g_t \leftarrow g_t + \lambda \theta_{t-1} \\
|
| 163 |
+
&\hspace{5mm}m_t \leftarrow \beta_1 m_{t-1} + (1 - \beta_1) g_t \\
|
| 164 |
+
&\hspace{5mm}u_t \leftarrow \mathrm{max}(\beta_2 u_{t-1}, |g_{t}|+\epsilon) \\
|
| 165 |
+
&\hspace{5mm}\theta_t \leftarrow \theta_{t-1} - \frac{\gamma m_t}{(1-\beta^t_1) u_t} \\
|
| 166 |
+
&\rule{110mm}{0.4pt} \\[-1.ex]
|
| 167 |
+
&\bf{return} \: \theta_t \\[-1.ex]
|
| 168 |
+
&\rule{110mm}{0.4pt} \\[-1.ex]
|
| 169 |
+
\end{aligned}
|
| 170 |
+
|
| 171 |
+
For further details regarding the algorithm we refer to `Adam: A Method for Stochastic Optimization`_.
|
| 172 |
+
""" + fr"""
|
| 173 |
+
Args:
|
| 174 |
+
params (iterable): iterable of parameters to optimize or dicts defining
|
| 175 |
+
parameter groups
|
| 176 |
+
lr (float, optional): learning rate (default: 2e-3)
|
| 177 |
+
betas (Tuple[float, float], optional): coefficients used for computing
|
| 178 |
+
running averages of gradient and its square
|
| 179 |
+
eps (float, optional): term added to the denominator to improve
|
| 180 |
+
numerical stability (default: 1e-8)
|
| 181 |
+
weight_decay (float, optional): weight decay (L2 penalty) (default: 0)
|
| 182 |
+
{_foreach_doc}
|
| 183 |
+
{_maximize_doc}
|
| 184 |
+
{_differentiable_doc}
|
| 185 |
+
{_capturable_doc}
|
| 186 |
+
|
| 187 |
+
.. _Adam\: A Method for Stochastic Optimization:
|
| 188 |
+
https://arxiv.org/abs/1412.6980
|
| 189 |
+
|
| 190 |
+
"""
|
| 191 |
+
|
| 192 |
+
|
| 193 |
+
def adamax(
|
| 194 |
+
params: List[Tensor],
|
| 195 |
+
grads: List[Tensor],
|
| 196 |
+
exp_avgs: List[Tensor],
|
| 197 |
+
exp_infs: List[Tensor],
|
| 198 |
+
state_steps: List[Tensor],
|
| 199 |
+
# kwonly args with defaults are not supported by functions compiled with torchscript issue #70627
|
| 200 |
+
# setting this as kwarg for now as functional API is compiled by torch/distributed/optim
|
| 201 |
+
foreach: Optional[bool] = None,
|
| 202 |
+
maximize: bool = False,
|
| 203 |
+
differentiable: bool = False,
|
| 204 |
+
capturable: bool = False,
|
| 205 |
+
has_complex: bool = False,
|
| 206 |
+
*,
|
| 207 |
+
eps: float,
|
| 208 |
+
beta1: float,
|
| 209 |
+
beta2: float,
|
| 210 |
+
lr: float,
|
| 211 |
+
weight_decay: float,
|
| 212 |
+
):
|
| 213 |
+
r"""Functional API that performs adamax algorithm computation.
|
| 214 |
+
|
| 215 |
+
See :class:`~torch.optim.Adamax` for details.
|
| 216 |
+
"""
|
| 217 |
+
|
| 218 |
+
if not all(isinstance(t, torch.Tensor) for t in state_steps):
|
| 219 |
+
raise RuntimeError(
|
| 220 |
+
"API has changed, `state_steps` argument must contain a list of singleton tensors"
|
| 221 |
+
)
|
| 222 |
+
|
| 223 |
+
if foreach is None:
|
| 224 |
+
_, foreach = _default_to_fused_or_foreach(params, differentiable, use_fused=False)
|
| 225 |
+
|
| 226 |
+
if foreach and torch.jit.is_scripting():
|
| 227 |
+
raise RuntimeError("torch.jit.script not supported with foreach optimizers")
|
| 228 |
+
|
| 229 |
+
if foreach and not torch.jit.is_scripting():
|
| 230 |
+
func = _multi_tensor_adamax
|
| 231 |
+
else:
|
| 232 |
+
func = _single_tensor_adamax
|
| 233 |
+
|
| 234 |
+
func(
|
| 235 |
+
params,
|
| 236 |
+
grads,
|
| 237 |
+
exp_avgs,
|
| 238 |
+
exp_infs,
|
| 239 |
+
state_steps,
|
| 240 |
+
eps=eps,
|
| 241 |
+
beta1=beta1,
|
| 242 |
+
beta2=beta2,
|
| 243 |
+
lr=lr,
|
| 244 |
+
weight_decay=weight_decay,
|
| 245 |
+
maximize=maximize,
|
| 246 |
+
differentiable=differentiable,
|
| 247 |
+
has_complex=has_complex,
|
| 248 |
+
capturable=capturable,
|
| 249 |
+
)
|
| 250 |
+
|
| 251 |
+
|
| 252 |
+
def _single_tensor_adamax(
|
| 253 |
+
params: List[Tensor],
|
| 254 |
+
grads: List[Tensor],
|
| 255 |
+
exp_avgs: List[Tensor],
|
| 256 |
+
exp_infs: List[Tensor],
|
| 257 |
+
state_steps: List[Tensor],
|
| 258 |
+
*,
|
| 259 |
+
eps: float,
|
| 260 |
+
beta1: float,
|
| 261 |
+
beta2: float,
|
| 262 |
+
lr: float,
|
| 263 |
+
weight_decay: float,
|
| 264 |
+
maximize: bool,
|
| 265 |
+
differentiable: bool,
|
| 266 |
+
capturable: bool,
|
| 267 |
+
has_complex: bool,
|
| 268 |
+
):
|
| 269 |
+
for i, param in enumerate(params):
|
| 270 |
+
grad = grads[i]
|
| 271 |
+
grad = grad if not maximize else -grad
|
| 272 |
+
exp_avg = exp_avgs[i]
|
| 273 |
+
exp_inf = exp_infs[i]
|
| 274 |
+
step_t = state_steps[i]
|
| 275 |
+
|
| 276 |
+
# If compiling, the compiler will handle cudagraph checks, see note [torch.compile x capturable]
|
| 277 |
+
if not torch._utils.is_compiling() and capturable:
|
| 278 |
+
assert (param.is_cuda and step_t.is_cuda) or (
|
| 279 |
+
param.is_xla and step_t.is_xla
|
| 280 |
+
), "If capturable=True, params and state_steps must be CUDA or XLA tensors."
|
| 281 |
+
|
| 282 |
+
# update step
|
| 283 |
+
step_t += 1
|
| 284 |
+
|
| 285 |
+
if weight_decay != 0:
|
| 286 |
+
grad = grad.add(param, alpha=weight_decay)
|
| 287 |
+
|
| 288 |
+
if torch.is_complex(param):
|
| 289 |
+
param = torch.view_as_real(param)
|
| 290 |
+
grad = torch.view_as_real(grad)
|
| 291 |
+
exp_avg = torch.view_as_real(exp_avg)
|
| 292 |
+
exp_inf = torch.view_as_real(exp_inf)
|
| 293 |
+
|
| 294 |
+
# Update biased first moment estimate.
|
| 295 |
+
exp_avg.lerp_(grad, 1 - beta1)
|
| 296 |
+
# Update the exponentially weighted infinity norm.
|
| 297 |
+
if not differentiable:
|
| 298 |
+
torch.maximum(
|
| 299 |
+
exp_inf.mul_(beta2),
|
| 300 |
+
grad.abs().add_(eps),
|
| 301 |
+
out=exp_inf,
|
| 302 |
+
)
|
| 303 |
+
else:
|
| 304 |
+
norm_buf = torch.cat(
|
| 305 |
+
[exp_inf.mul_(beta2).unsqueeze(0), grad.abs().add_(eps).unsqueeze_(0)], 0
|
| 306 |
+
)
|
| 307 |
+
exp_inf.copy_(torch.amax(norm_buf, 0, keepdim=False))
|
| 308 |
+
|
| 309 |
+
if capturable:
|
| 310 |
+
# why jump through extra hoops and negate bias_correction? check out #121238
|
| 311 |
+
# once fixed, we should use bias_correction with addcdiv value=-1 for readability
|
| 312 |
+
neg_bias_correction = beta1 ** step_t - 1
|
| 313 |
+
neg_bias_correction.div_(lr)
|
| 314 |
+
denom = exp_inf * neg_bias_correction
|
| 315 |
+
param.addcdiv_(exp_avg, denom)
|
| 316 |
+
else:
|
| 317 |
+
bias_correction = 1 - beta1 ** _get_value(step_t)
|
| 318 |
+
clr = lr / bias_correction
|
| 319 |
+
|
| 320 |
+
param.addcdiv_(exp_avg, exp_inf, value=-clr)
|
| 321 |
+
|
| 322 |
+
|
| 323 |
+
def _multi_tensor_adamax(
|
| 324 |
+
params: List[Tensor],
|
| 325 |
+
grads: List[Tensor],
|
| 326 |
+
exp_avgs: List[Tensor],
|
| 327 |
+
exp_infs: List[Tensor],
|
| 328 |
+
state_steps: List[Tensor],
|
| 329 |
+
*,
|
| 330 |
+
beta1: float,
|
| 331 |
+
beta2: float,
|
| 332 |
+
lr: float,
|
| 333 |
+
weight_decay: float,
|
| 334 |
+
eps: float,
|
| 335 |
+
maximize: bool,
|
| 336 |
+
differentiable: bool,
|
| 337 |
+
capturable: bool,
|
| 338 |
+
has_complex: bool,
|
| 339 |
+
):
|
| 340 |
+
|
| 341 |
+
assert not differentiable, "_foreach ops don't support autograd"
|
| 342 |
+
|
| 343 |
+
if len(params) == 0:
|
| 344 |
+
return
|
| 345 |
+
|
| 346 |
+
# If compiling, the compiler will handle cudagraph checks, see note [torch.compile x capturable]
|
| 347 |
+
if (not torch._utils.is_compiling() and capturable
|
| 348 |
+
and not all(p.is_cuda and step.is_cuda for p, step in zip(params, state_steps))):
|
| 349 |
+
raise RuntimeError("If capturable=True, params and state_steps must be CUDA tensors.")
|
| 350 |
+
|
| 351 |
+
grouped_tensors = Optimizer._group_tensors_by_device_and_dtype([params, grads, exp_avgs, exp_infs, state_steps])
|
| 352 |
+
for ((grouped_params, grouped_grads, grouped_exp_avgs, grouped_exp_infs, grouped_state_steps), _) in grouped_tensors.values():
|
| 353 |
+
if has_complex:
|
| 354 |
+
_view_as_real(grouped_params, grouped_grads, grouped_exp_avgs, grouped_exp_infs)
|
| 355 |
+
|
| 356 |
+
if maximize:
|
| 357 |
+
grouped_grads = torch._foreach_neg(grouped_grads)
|
| 358 |
+
|
| 359 |
+
# Update steps
|
| 360 |
+
# If steps are on CPU, foreach will fall back to the slow path, which is a for-loop calling t.add(1) over
|
| 361 |
+
# and over. 1 will then be wrapped into a Tensor over and over again, which is slower than if we just
|
| 362 |
+
# wrapped it once now. The alpha is required to assure we go to the right overload.
|
| 363 |
+
if grouped_state_steps[0].is_cpu:
|
| 364 |
+
torch._foreach_add_(grouped_state_steps, torch.tensor(1.0, device='cpu'), alpha=1.0)
|
| 365 |
+
else:
|
| 366 |
+
torch._foreach_add_(grouped_state_steps, 1)
|
| 367 |
+
|
| 368 |
+
if weight_decay != 0:
|
| 369 |
+
if maximize:
|
| 370 |
+
# Re-use the intermediate memory (grouped_grads) already allocated for maximize
|
| 371 |
+
torch._foreach_add_(grouped_grads, grouped_params, alpha=weight_decay)
|
| 372 |
+
else:
|
| 373 |
+
grouped_grads = torch._foreach_add(grouped_grads, grouped_params, alpha=weight_decay)
|
| 374 |
+
|
| 375 |
+
|
| 376 |
+
# Update biased first moment estimate.
|
| 377 |
+
torch._foreach_lerp_(grouped_exp_avgs, grouped_grads, 1 - beta1)
|
| 378 |
+
|
| 379 |
+
# Update the exponentially weighted infinity norm.
|
| 380 |
+
torch._foreach_mul_(grouped_exp_infs, beta2)
|
| 381 |
+
|
| 382 |
+
# in this case, we need to introduce a copy of the grads
|
| 383 |
+
# since one has not been introduced previously
|
| 384 |
+
if not maximize and weight_decay == 0:
|
| 385 |
+
grouped_grads = torch._foreach_abs(grouped_grads)
|
| 386 |
+
else:
|
| 387 |
+
torch._foreach_abs_(grouped_grads)
|
| 388 |
+
|
| 389 |
+
torch._foreach_add_(grouped_grads, eps)
|
| 390 |
+
torch._foreach_maximum_(grouped_exp_infs, grouped_grads)
|
| 391 |
+
|
| 392 |
+
if capturable:
|
| 393 |
+
bias_corrections = torch._foreach_pow(beta1, grouped_state_steps)
|
| 394 |
+
# foreach_sub doesn't allow a scalar as the first arg
|
| 395 |
+
torch._foreach_sub_(bias_corrections, 1)
|
| 396 |
+
torch._foreach_div_(bias_corrections, lr)
|
| 397 |
+
|
| 398 |
+
denom = torch._foreach_mul(grouped_exp_infs, bias_corrections)
|
| 399 |
+
torch._foreach_addcdiv_(grouped_params, grouped_exp_avgs, denom)
|
| 400 |
+
else:
|
| 401 |
+
bias_corrections = [1 - beta1 ** _get_value(step) for step in grouped_state_steps]
|
| 402 |
+
step_size = [(lr / bc) * -1 for bc in bias_corrections]
|
| 403 |
+
torch._foreach_addcdiv_(grouped_params, grouped_exp_avgs, grouped_exp_infs, step_size)
|
shared/package-files/65/654b5f1cf96836a72f18c1ccc5a2834a5b2184e723c21794c75e37470a467485/blob
ADDED
|
@@ -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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
StartFontMetrics 2.0
|
| 2 |
+
Comment Copyright (c) 1985, 1987, 1989, 1990, 1991 Adobe Systems Incorporated. All Rights Reserved.
|
| 3 |
+
Comment Creation Date: Mon Mar 4 13:37:31 1991
|
| 4 |
+
Comment UniqueID 34364
|
| 5 |
+
Comment VMusage 24225 31117
|
| 6 |
+
FontName AvantGarde-Book
|
| 7 |
+
FullName ITC Avant Garde Gothic Book
|
| 8 |
+
FamilyName ITC Avant Garde Gothic
|
| 9 |
+
Weight Book
|
| 10 |
+
ItalicAngle 0
|
| 11 |
+
IsFixedPitch false
|
| 12 |
+
FontBBox -113 -222 1148 955
|
| 13 |
+
UnderlinePosition -100
|
| 14 |
+
UnderlineThickness 50
|
| 15 |
+
Version 001.006
|
| 16 |
+
Notice Copyright (c) 1985, 1987, 1989, 1990, 1991 Adobe Systems Incorporated. All Rights Reserved.ITC Avant Garde Gothic is a registered trademark of International Typeface Corporation.
|
| 17 |
+
EncodingScheme AdobeStandardEncoding
|
| 18 |
+
CapHeight 740
|
| 19 |
+
XHeight 547
|
| 20 |
+
Ascender 740
|
| 21 |
+
Descender -192
|
| 22 |
+
StartCharMetrics 228
|
| 23 |
+
C 32 ; WX 277 ; N space ; B 0 0 0 0 ;
|
| 24 |
+
C 33 ; WX 295 ; N exclam ; B 111 0 185 740 ;
|
| 25 |
+
C 34 ; WX 309 ; N quotedbl ; B 36 444 273 740 ;
|
| 26 |
+
C 35 ; WX 554 ; N numbersign ; B 33 0 521 740 ;
|
| 27 |
+
C 36 ; WX 554 ; N dollar ; B 70 -70 485 811 ;
|
| 28 |
+
C 37 ; WX 775 ; N percent ; B 21 -13 753 751 ;
|
| 29 |
+
C 38 ; WX 757 ; N ampersand ; B 56 -12 736 753 ;
|
| 30 |
+
C 39 ; WX 351 ; N quoteright ; B 94 546 256 740 ;
|
| 31 |
+
C 40 ; WX 369 ; N parenleft ; B 47 -205 355 757 ;
|
| 32 |
+
C 41 ; WX 369 ; N parenright ; B 14 -205 322 757 ;
|
| 33 |
+
C 42 ; WX 425 ; N asterisk ; B 58 446 367 740 ;
|
| 34 |
+
C 43 ; WX 606 ; N plus ; B 51 0 555 506 ;
|
| 35 |
+
C 44 ; WX 277 ; N comma ; B 14 -67 176 126 ;
|
| 36 |
+
C 45 ; WX 332 ; N hyphen ; B 30 248 302 315 ;
|
| 37 |
+
C 46 ; WX 277 ; N period ; B 102 0 176 126 ;
|
| 38 |
+
C 47 ; WX 437 ; N slash ; B 44 -100 403 740 ;
|
| 39 |
+
C 48 ; WX 554 ; N zero ; B 29 -13 525 753 ;
|
| 40 |
+
C 49 ; WX 554 ; N one ; B 135 0 336 740 ;
|
| 41 |
+
C 50 ; WX 554 ; N two ; B 40 0 514 753 ;
|
| 42 |
+
C 51 ; WX 554 ; N three ; B 34 -13 506 753 ;
|
| 43 |
+
C 52 ; WX 554 ; N four ; B 14 0 528 740 ;
|
| 44 |
+
C 53 ; WX 554 ; N five ; B 26 -13 530 740 ;
|
| 45 |
+
C 54 ; WX 554 ; N six ; B 24 -13 530 739 ;
|
| 46 |
+
C 55 ; WX 554 ; N seven ; B 63 0 491 740 ;
|
| 47 |
+
C 56 ; WX 554 ; N eight ; B 41 -13 513 753 ;
|
| 48 |
+
C 57 ; WX 554 ; N nine ; B 24 0 530 752 ;
|
| 49 |
+
C 58 ; WX 277 ; N colon ; B 102 0 176 548 ;
|
| 50 |
+
C 59 ; WX 277 ; N semicolon ; B 14 -67 176 548 ;
|
| 51 |
+
C 60 ; WX 606 ; N less ; B 46 -8 554 514 ;
|
| 52 |
+
C 61 ; WX 606 ; N equal ; B 51 118 555 388 ;
|
| 53 |
+
C 62 ; WX 606 ; N greater ; B 52 -8 560 514 ;
|
| 54 |
+
C 63 ; WX 591 ; N question ; B 64 0 526 752 ;
|
| 55 |
+
C 64 ; WX 867 ; N at ; B 65 -13 803 753 ;
|
| 56 |
+
C 65 ; WX 740 ; N A ; B 12 0 729 740 ;
|
| 57 |
+
C 66 ; WX 574 ; N B ; B 74 0 544 740 ;
|
| 58 |
+
C 67 ; WX 813 ; N C ; B 43 -13 771 752 ;
|
| 59 |
+
C 68 ; WX 744 ; N D ; B 74 0 699 740 ;
|
| 60 |
+
C 69 ; WX 536 ; N E ; B 70 0 475 740 ;
|
| 61 |
+
C 70 ; WX 485 ; N F ; B 70 0 444 740 ;
|
| 62 |
+
C 71 ; WX 872 ; N G ; B 40 -13 828 753 ;
|
| 63 |
+
C 72 ; WX 683 ; N H ; B 76 0 607 740 ;
|
| 64 |
+
C 73 ; WX 226 ; N I ; B 76 0 150 740 ;
|
| 65 |
+
C 74 ; WX 482 ; N J ; B 6 -13 402 740 ;
|
| 66 |
+
C 75 ; WX 591 ; N K ; B 81 0 591 740 ;
|
| 67 |
+
C 76 ; WX 462 ; N L ; B 82 0 462 740 ;
|
| 68 |
+
C 77 ; WX 919 ; N M ; B 76 0 843 740 ;
|
| 69 |
+
C 78 ; WX 740 ; N N ; B 75 0 664 740 ;
|
| 70 |
+
C 79 ; WX 869 ; N O ; B 43 -13 826 753 ;
|
| 71 |
+
C 80 ; WX 592 ; N P ; B 75 0 564 740 ;
|
| 72 |
+
C 81 ; WX 871 ; N Q ; B 40 -13 837 753 ;
|
| 73 |
+
C 82 ; WX 607 ; N R ; B 70 0 572 740 ;
|
| 74 |
+
C 83 ; WX 498 ; N S ; B 22 -13 473 753 ;
|
| 75 |
+
C 84 ; WX 426 ; N T ; B 6 0 419 740 ;
|
| 76 |
+
C 85 ; WX 655 ; N U ; B 75 -13 579 740 ;
|
| 77 |
+
C 86 ; WX 702 ; N V ; B 8 0 693 740 ;
|
| 78 |
+
C 87 ; WX 960 ; N W ; B 11 0 950 740 ;
|
| 79 |
+
C 88 ; WX 609 ; N X ; B 8 0 602 740 ;
|
| 80 |
+
C 89 ; WX 592 ; N Y ; B 1 0 592 740 ;
|
| 81 |
+
C 90 ; WX 480 ; N Z ; B 12 0 470 740 ;
|
| 82 |
+
C 91 ; WX 351 ; N bracketleft ; B 133 -179 337 753 ;
|
| 83 |
+
C 92 ; WX 605 ; N backslash ; B 118 -100 477 740 ;
|
| 84 |
+
C 93 ; WX 351 ; N bracketright ; B 14 -179 218 753 ;
|
| 85 |
+
C 94 ; WX 606 ; N asciicircum ; B 53 307 553 740 ;
|
| 86 |
+
C 95 ; WX 500 ; N underscore ; B 0 -125 500 -75 ;
|
| 87 |
+
C 96 ; WX 351 ; N quoteleft ; B 95 546 257 740 ;
|
| 88 |
+
C 97 ; WX 683 ; N a ; B 42 -13 621 561 ;
|
| 89 |
+
C 98 ; WX 682 ; N b ; B 68 -13 647 740 ;
|
| 90 |
+
C 99 ; WX 647 ; N c ; B 41 -13 607 561 ;
|
| 91 |
+
C 100 ; WX 685 ; N d ; B 39 -13 618 740 ;
|
| 92 |
+
C 101 ; WX 650 ; N e ; B 38 -13 608 561 ;
|
| 93 |
+
C 102 ; WX 314 ; N f ; B 19 0 314 753 ; L i fi ; L l fl ;
|
| 94 |
+
C 103 ; WX 673 ; N g ; B 37 -215 606 561 ;
|
| 95 |
+
C 104 ; WX 610 ; N h ; B 62 0 543 740 ;
|
| 96 |
+
C 105 ; WX 200 ; N i ; B 65 0 135 740 ;
|
| 97 |
+
C 106 ; WX 203 ; N j ; B -44 -192 137 740 ;
|
| 98 |
+
C 107 ; WX 502 ; N k ; B 70 0 498 740 ;
|
| 99 |
+
C 108 ; WX 200 ; N l ; B 65 0 135 740 ;
|
| 100 |
+
C 109 ; WX 938 ; N m ; B 66 0 872 561 ;
|
| 101 |
+
C 110 ; WX 610 ; N n ; B 65 0 546 561 ;
|
| 102 |
+
C 111 ; WX 655 ; N o ; B 42 -13 614 561 ;
|
| 103 |
+
C 112 ; WX 682 ; N p ; B 64 -192 643 561 ;
|
| 104 |
+
C 113 ; WX 682 ; N q ; B 37 -192 616 561 ;
|
| 105 |
+
C 114 ; WX 301 ; N r ; B 65 0 291 561 ;
|
| 106 |
+
C 115 ; WX 388 ; N s ; B 24 -13 364 561 ;
|
| 107 |
+
C 116 ; WX 339 ; N t ; B 14 0 330 740 ;
|
| 108 |
+
C 117 ; WX 608 ; N u ; B 62 -13 541 547 ;
|
| 109 |
+
C 118 ; WX 554 ; N v ; B 7 0 546 547 ;
|
| 110 |
+
C 119 ; WX 831 ; N w ; B 13 0 820 547 ;
|
| 111 |
+
C 120 ; WX 480 ; N x ; B 12 0 468 547 ;
|
| 112 |
+
C 121 ; WX 536 ; N y ; B 15 -192 523 547 ;
|
| 113 |
+
C 122 ; WX 425 ; N z ; B 10 0 415 547 ;
|
| 114 |
+
C 123 ; WX 351 ; N braceleft ; B 70 -189 331 740 ;
|
| 115 |
+
C 124 ; WX 672 ; N bar ; B 299 -100 373 740 ;
|
| 116 |
+
C 125 ; WX 351 ; N braceright ; B 20 -189 281 740 ;
|
| 117 |
+
C 126 ; WX 606 ; N asciitilde ; B 72 179 534 319 ;
|
| 118 |
+
C 161 ; WX 295 ; N exclamdown ; B 110 -192 184 548 ;
|
| 119 |
+
C 162 ; WX 554 ; N cent ; B 48 62 510 707 ;
|
| 120 |
+
C 163 ; WX 554 ; N sterling ; B 4 0 552 753 ;
|
| 121 |
+
C 164 ; WX 166 ; N fraction ; B -113 0 280 740 ;
|
| 122 |
+
C 165 ; WX 554 ; N yen ; B 4 0 550 740 ;
|
| 123 |
+
C 166 ; WX 554 ; N florin ; B -12 -153 518 818 ;
|
| 124 |
+
C 167 ; WX 615 ; N section ; B 85 -141 529 753 ;
|
| 125 |
+
C 168 ; WX 554 ; N currency ; B 8 42 546 580 ;
|
| 126 |
+
C 169 ; WX 198 ; N quotesingle ; B 59 444 140 740 ;
|
| 127 |
+
C 170 ; WX 502 ; N quotedblleft ; B 97 546 406 740 ;
|
| 128 |
+
C 171 ; WX 425 ; N guillemotleft ; B 40 81 386 481 ;
|
| 129 |
+
C 172 ; WX 251 ; N guilsinglleft ; B 40 81 212 481 ;
|
| 130 |
+
C 173 ; WX 251 ; N guilsinglright ; B 39 81 211 481 ;
|
| 131 |
+
C 174 ; WX 487 ; N fi ; B 19 0 422 753 ;
|
| 132 |
+
C 175 ; WX 485 ; N fl ; B 19 0 420 753 ;
|
| 133 |
+
C 177 ; WX 500 ; N endash ; B 35 248 465 315 ;
|
| 134 |
+
C 178 ; WX 553 ; N dagger ; B 59 -133 493 740 ;
|
| 135 |
+
C 179 ; WX 553 ; N daggerdbl ; B 59 -133 493 740 ;
|
| 136 |
+
C 180 ; WX 277 ; N periodcentered ; B 102 190 176 316 ;
|
| 137 |
+
C 182 ; WX 564 ; N paragraph ; B 22 -110 551 740 ;
|
| 138 |
+
C 183 ; WX 606 ; N bullet ; B 150 222 455 532 ;
|
| 139 |
+
C 184 ; WX 354 ; N quotesinglbase ; B 89 -68 251 126 ;
|
| 140 |
+
C 185 ; WX 502 ; N quotedblbase ; B 89 -68 399 126 ;
|
| 141 |
+
C 186 ; WX 484 ; N quotedblright ; B 96 546 405 740 ;
|
| 142 |
+
C 187 ; WX 425 ; N guillemotright ; B 39 81 385 481 ;
|
| 143 |
+
C 188 ; WX 1000 ; N ellipsis ; B 130 0 870 126 ;
|
| 144 |
+
C 189 ; WX 1174 ; N perthousand ; B 25 -13 1148 751 ;
|
| 145 |
+
C 191 ; WX 591 ; N questiondown ; B 65 -205 527 548 ;
|
| 146 |
+
C 193 ; WX 378 ; N grave ; B 69 619 300 786 ;
|
| 147 |
+
C 194 ; WX 375 ; N acute ; B 78 619 309 786 ;
|
| 148 |
+
C 195 ; WX 502 ; N circumflex ; B 74 639 428 764 ;
|
| 149 |
+
C 196 ; WX 439 ; N tilde ; B 47 651 392 754 ;
|
| 150 |
+
C 197 ; WX 485 ; N macron ; B 73 669 411 736 ;
|
| 151 |
+
C 198 ; WX 453 ; N breve ; B 52 651 401 754 ;
|
| 152 |
+
C 199 ; WX 222 ; N dotaccent ; B 74 639 148 765 ;
|
| 153 |
+
C 200 ; WX 369 ; N dieresis ; B 73 639 295 765 ;
|
| 154 |
+
C 202 ; WX 332 ; N ring ; B 62 600 269 807 ;
|
| 155 |
+
C 203 ; WX 324 ; N cedilla ; B 80 -222 254 0 ;
|
| 156 |
+
C 205 ; WX 552 ; N hungarumlaut ; B 119 605 453 800 ;
|
| 157 |
+
C 206 ; WX 302 ; N ogonek ; B 73 -191 228 0 ;
|
| 158 |
+
C 207 ; WX 502 ; N caron ; B 68 639 423 764 ;
|
| 159 |
+
C 208 ; WX 1000 ; N emdash ; B 35 248 965 315 ;
|
| 160 |
+
C 225 ; WX 992 ; N AE ; B -20 0 907 740 ;
|
| 161 |
+
C 227 ; WX 369 ; N ordfeminine ; B -3 407 356 753 ;
|
| 162 |
+
C 232 ; WX 517 ; N Lslash ; B 59 0 517 740 ;
|
| 163 |
+
C 233 ; WX 868 ; N Oslash ; B 43 -83 826 819 ;
|
| 164 |
+
C 234 ; WX 1194 ; N OE ; B 45 -13 1142 753 ;
|
| 165 |
+
C 235 ; WX 369 ; N ordmasculine ; B 12 407 356 753 ;
|
| 166 |
+
C 241 ; WX 1157 ; N ae ; B 34 -13 1113 561 ;
|
| 167 |
+
C 245 ; WX 200 ; N dotlessi ; B 65 0 135 547 ;
|
| 168 |
+
C 248 ; WX 300 ; N lslash ; B 43 0 259 740 ;
|
| 169 |
+
C 249 ; WX 653 ; N oslash ; B 41 -64 613 614 ;
|
| 170 |
+
C 250 ; WX 1137 ; N oe ; B 34 -13 1104 561 ;
|
| 171 |
+
C 251 ; WX 554 ; N germandbls ; B 61 -13 525 753 ;
|
| 172 |
+
C -1 ; WX 650 ; N ecircumflex ; B 38 -13 608 764 ;
|
| 173 |
+
C -1 ; WX 650 ; N edieresis ; B 38 -13 608 765 ;
|
| 174 |
+
C -1 ; WX 683 ; N aacute ; B 42 -13 621 786 ;
|
| 175 |
+
C -1 ; WX 747 ; N registered ; B -9 -12 755 752 ;
|
| 176 |
+
C -1 ; WX 200 ; N icircumflex ; B -77 0 277 764 ;
|
| 177 |
+
C -1 ; WX 608 ; N udieresis ; B 62 -13 541 765 ;
|
| 178 |
+
C -1 ; WX 655 ; N ograve ; B 42 -13 614 786 ;
|
| 179 |
+
C -1 ; WX 608 ; N uacute ; B 62 -13 541 786 ;
|
| 180 |
+
C -1 ; WX 608 ; N ucircumflex ; B 62 -13 541 764 ;
|
| 181 |
+
C -1 ; WX 740 ; N Aacute ; B 12 0 729 949 ;
|
| 182 |
+
C -1 ; WX 200 ; N igrave ; B -60 0 171 786 ;
|
| 183 |
+
C -1 ; WX 226 ; N Icircumflex ; B -64 0 290 927 ;
|
| 184 |
+
C -1 ; WX 647 ; N ccedilla ; B 41 -222 607 561 ;
|
| 185 |
+
C -1 ; WX 683 ; N adieresis ; B 42 -13 621 765 ;
|
| 186 |
+
C -1 ; WX 536 ; N Ecircumflex ; B 70 0 475 927 ;
|
| 187 |
+
C -1 ; WX 388 ; N scaron ; B 11 -13 366 764 ;
|
| 188 |
+
C -1 ; WX 682 ; N thorn ; B 64 -192 643 740 ;
|
| 189 |
+
C -1 ; WX 1000 ; N trademark ; B 9 296 816 740 ;
|
| 190 |
+
C -1 ; WX 650 ; N egrave ; B 38 -13 608 786 ;
|
| 191 |
+
C -1 ; WX 332 ; N threesuperior ; B 18 289 318 747 ;
|
| 192 |
+
C -1 ; WX 425 ; N zcaron ; B 10 0 415 764 ;
|
| 193 |
+
C -1 ; WX 683 ; N atilde ; B 42 -13 621 754 ;
|
| 194 |
+
C -1 ; WX 683 ; N aring ; B 42 -13 621 807 ;
|
| 195 |
+
C -1 ; WX 655 ; N ocircumflex ; B 42 -13 614 764 ;
|
| 196 |
+
C -1 ; WX 536 ; N Edieresis ; B 70 0 475 928 ;
|
| 197 |
+
C -1 ; WX 831 ; N threequarters ; B 46 0 784 747 ;
|
| 198 |
+
C -1 ; WX 536 ; N ydieresis ; B 15 -192 523 765 ;
|
| 199 |
+
C -1 ; WX 536 ; N yacute ; B 15 -192 523 786 ;
|
| 200 |
+
C -1 ; WX 200 ; N iacute ; B 31 0 262 786 ;
|
| 201 |
+
C -1 ; WX 740 ; N Acircumflex ; B 12 0 729 927 ;
|
| 202 |
+
C -1 ; WX 655 ; N Uacute ; B 75 -13 579 949 ;
|
| 203 |
+
C -1 ; WX 650 ; N eacute ; B 38 -13 608 786 ;
|
| 204 |
+
C -1 ; WX 869 ; N Ograve ; B 43 -13 826 949 ;
|
| 205 |
+
C -1 ; WX 683 ; N agrave ; B 42 -13 621 786 ;
|
| 206 |
+
C -1 ; WX 655 ; N Udieresis ; B 75 -13 579 928 ;
|
| 207 |
+
C -1 ; WX 683 ; N acircumflex ; B 42 -13 621 764 ;
|
| 208 |
+
C -1 ; WX 226 ; N Igrave ; B -47 0 184 949 ;
|
| 209 |
+
C -1 ; WX 332 ; N twosuperior ; B 19 296 318 747 ;
|
| 210 |
+
C -1 ; WX 655 ; N Ugrave ; B 75 -13 579 949 ;
|
| 211 |
+
C -1 ; WX 831 ; N onequarter ; B 100 0 729 740 ;
|
| 212 |
+
C -1 ; WX 655 ; N Ucircumflex ; B 75 -13 579 927 ;
|
| 213 |
+
C -1 ; WX 498 ; N Scaron ; B 22 -13 473 927 ;
|
| 214 |
+
C -1 ; WX 226 ; N Idieresis ; B 2 0 224 928 ;
|
| 215 |
+
C -1 ; WX 200 ; N idieresis ; B -11 0 211 765 ;
|
| 216 |
+
C -1 ; WX 536 ; N Egrave ; B 70 0 475 949 ;
|
| 217 |
+
C -1 ; WX 869 ; N Oacute ; B 43 -13 826 949 ;
|
| 218 |
+
C -1 ; WX 606 ; N divide ; B 51 -13 555 519 ;
|
| 219 |
+
C -1 ; WX 740 ; N Atilde ; B 12 0 729 917 ;
|
| 220 |
+
C -1 ; WX 740 ; N Aring ; B 12 0 729 955 ;
|
| 221 |
+
C -1 ; WX 869 ; N Odieresis ; B 43 -13 826 928 ;
|
| 222 |
+
C -1 ; WX 740 ; N Adieresis ; B 12 0 729 928 ;
|
| 223 |
+
C -1 ; WX 740 ; N Ntilde ; B 75 0 664 917 ;
|
| 224 |
+
C -1 ; WX 480 ; N Zcaron ; B 12 0 470 927 ;
|
| 225 |
+
C -1 ; WX 592 ; N Thorn ; B 60 0 549 740 ;
|
| 226 |
+
C -1 ; WX 226 ; N Iacute ; B 44 0 275 949 ;
|
| 227 |
+
C -1 ; WX 606 ; N plusminus ; B 51 -24 555 518 ;
|
| 228 |
+
C -1 ; WX 606 ; N multiply ; B 74 24 533 482 ;
|
| 229 |
+
C -1 ; WX 536 ; N Eacute ; B 70 0 475 949 ;
|
| 230 |
+
C -1 ; WX 592 ; N Ydieresis ; B 1 0 592 928 ;
|
| 231 |
+
C -1 ; WX 332 ; N onesuperior ; B 63 296 198 740 ;
|
| 232 |
+
C -1 ; WX 608 ; N ugrave ; B 62 -13 541 786 ;
|
| 233 |
+
C -1 ; WX 606 ; N logicalnot ; B 51 109 555 388 ;
|
| 234 |
+
C -1 ; WX 610 ; N ntilde ; B 65 0 546 754 ;
|
| 235 |
+
C -1 ; WX 869 ; N Otilde ; B 43 -13 826 917 ;
|
| 236 |
+
C -1 ; WX 655 ; N otilde ; B 42 -13 614 754 ;
|
| 237 |
+
C -1 ; WX 813 ; N Ccedilla ; B 43 -222 771 752 ;
|
| 238 |
+
C -1 ; WX 740 ; N Agrave ; B 12 0 729 949 ;
|
| 239 |
+
C -1 ; WX 831 ; N onehalf ; B 81 0 750 740 ;
|
| 240 |
+
C -1 ; WX 790 ; N Eth ; B 40 0 739 740 ;
|
| 241 |
+
C -1 ; WX 400 ; N degree ; B 56 421 344 709 ;
|
| 242 |
+
C -1 ; WX 592 ; N Yacute ; B 1 0 592 949 ;
|
| 243 |
+
C -1 ; WX 869 ; N Ocircumflex ; B 43 -13 826 927 ;
|
| 244 |
+
C -1 ; WX 655 ; N oacute ; B 42 -13 614 786 ;
|
| 245 |
+
C -1 ; WX 608 ; N mu ; B 80 -184 527 547 ;
|
| 246 |
+
C -1 ; WX 606 ; N minus ; B 51 219 555 287 ;
|
| 247 |
+
C -1 ; WX 655 ; N eth ; B 42 -12 614 753 ;
|
| 248 |
+
C -1 ; WX 655 ; N odieresis ; B 42 -13 614 765 ;
|
| 249 |
+
C -1 ; WX 747 ; N copyright ; B -9 -12 755 752 ;
|
| 250 |
+
C -1 ; WX 672 ; N brokenbar ; B 299 -100 373 740 ;
|
| 251 |
+
EndCharMetrics
|
| 252 |
+
StartKernData
|
| 253 |
+
StartKernPairs 216
|
| 254 |
+
|
| 255 |
+
KPX A y -62
|
| 256 |
+
KPX A w -65
|
| 257 |
+
KPX A v -70
|
| 258 |
+
KPX A u -20
|
| 259 |
+
KPX A quoteright -100
|
| 260 |
+
KPX A quotedblright -100
|
| 261 |
+
KPX A Y -92
|
| 262 |
+
KPX A W -60
|
| 263 |
+
KPX A V -102
|
| 264 |
+
KPX A U -40
|
| 265 |
+
KPX A T -45
|
| 266 |
+
KPX A Q -40
|
| 267 |
+
KPX A O -50
|
| 268 |
+
KPX A G -40
|
| 269 |
+
KPX A C -40
|
| 270 |
+
|
| 271 |
+
KPX B A -10
|
| 272 |
+
|
| 273 |
+
KPX C A -40
|
| 274 |
+
|
| 275 |
+
KPX D period -20
|
| 276 |
+
KPX D comma -20
|
| 277 |
+
KPX D Y -30
|
| 278 |
+
KPX D W -10
|
| 279 |
+
KPX D V -50
|
| 280 |
+
KPX D A -50
|
| 281 |
+
|
| 282 |
+
KPX F period -160
|
| 283 |
+
KPX F e -20
|
| 284 |
+
KPX F comma -180
|
| 285 |
+
KPX F a -20
|
| 286 |
+
KPX F A -75
|
| 287 |
+
|
| 288 |
+
KPX G period -20
|
| 289 |
+
KPX G comma -20
|
| 290 |
+
KPX G Y -20
|
| 291 |
+
|
| 292 |
+
KPX J period -15
|
| 293 |
+
KPX J a -20
|
| 294 |
+
KPX J A -30
|
| 295 |
+
|
| 296 |
+
KPX K o -15
|
| 297 |
+
KPX K e -20
|
| 298 |
+
KPX K O -20
|
| 299 |
+
|
| 300 |
+
KPX L y -23
|
| 301 |
+
KPX L quoteright -130
|
| 302 |
+
KPX L quotedblright -130
|
| 303 |
+
KPX L Y -91
|
| 304 |
+
KPX L W -67
|
| 305 |
+
KPX L V -113
|
| 306 |
+
KPX L T -46
|
| 307 |
+
|
| 308 |
+
KPX O period -30
|
| 309 |
+
KPX O comma -30
|
| 310 |
+
KPX O Y -30
|
| 311 |
+
KPX O X -30
|
| 312 |
+
KPX O W -20
|
| 313 |
+
KPX O V -60
|
| 314 |
+
KPX O T -30
|
| 315 |
+
KPX O A -60
|
| 316 |
+
|
| 317 |
+
KPX P period -300
|
| 318 |
+
KPX P o -60
|
| 319 |
+
KPX P e -20
|
| 320 |
+
KPX P comma -280
|
| 321 |
+
KPX P a -20
|
| 322 |
+
KPX P A -114
|
| 323 |
+
|
| 324 |
+
KPX Q comma 20
|
| 325 |
+
|
| 326 |
+
KPX R Y -10
|
| 327 |
+
KPX R W 10
|
| 328 |
+
KPX R V -10
|
| 329 |
+
KPX R T 6
|
| 330 |
+
|
| 331 |
+
KPX S comma 20
|
| 332 |
+
|
| 333 |
+
KPX T y -50
|
| 334 |
+
KPX T w -55
|
| 335 |
+
KPX T u -46
|
| 336 |
+
KPX T semicolon -29
|
| 337 |
+
KPX T r -30
|
| 338 |
+
KPX T period -91
|
| 339 |
+
KPX T o -70
|
| 340 |
+
KPX T i 10
|
| 341 |
+
KPX T hyphen -75
|
| 342 |
+
KPX T e -49
|
| 343 |
+
KPX T comma -82
|
| 344 |
+
KPX T colon -15
|
| 345 |
+
KPX T a -90
|
| 346 |
+
KPX T O -30
|
| 347 |
+
KPX T A -45
|
| 348 |
+
|
| 349 |
+
KPX U period -20
|
| 350 |
+
KPX U comma -20
|
| 351 |
+
KPX U A -40
|
| 352 |
+
|
| 353 |
+
KPX V u -40
|
| 354 |
+
KPX V semicolon -33
|
| 355 |
+
KPX V period -165
|
| 356 |
+
KPX V o -101
|
| 357 |
+
KPX V i -5
|
| 358 |
+
KPX V hyphen -75
|
| 359 |
+
KPX V e -101
|
| 360 |
+
KPX V comma -145
|
| 361 |
+
KPX V colon -18
|
| 362 |
+
KPX V a -104
|
| 363 |
+
KPX V O -60
|
| 364 |
+
KPX V G -20
|
| 365 |
+
KPX V A -102
|
| 366 |
+
|
| 367 |
+
KPX W y -2
|
| 368 |
+
KPX W u -30
|
| 369 |
+
KPX W semicolon -33
|
| 370 |
+
KPX W period -106
|
| 371 |
+
KPX W o -46
|
| 372 |
+
KPX W i 6
|
| 373 |
+
KPX W hyphen -35
|
| 374 |
+
KPX W e -47
|
| 375 |
+
KPX W comma -106
|
| 376 |
+
KPX W colon -15
|
| 377 |
+
KPX W a -50
|
| 378 |
+
KPX W O -20
|
| 379 |
+
KPX W A -58
|
| 380 |
+
|
| 381 |
+
KPX Y u -52
|
| 382 |
+
KPX Y semicolon -23
|
| 383 |
+
KPX Y period -175
|
| 384 |
+
KPX Y o -89
|
| 385 |
+
KPX Y hyphen -85
|
| 386 |
+
KPX Y e -89
|
| 387 |
+
KPX Y comma -145
|
| 388 |
+
KPX Y colon -10
|
| 389 |
+
KPX Y a -93
|
| 390 |
+
KPX Y O -30
|
| 391 |
+
KPX Y A -92
|
| 392 |
+
|
| 393 |
+
KPX a p 20
|
| 394 |
+
KPX a b 20
|
| 395 |
+
|
| 396 |
+
KPX b y -20
|
| 397 |
+
KPX b v -20
|
| 398 |
+
|
| 399 |
+
KPX c y -20
|
| 400 |
+
KPX c k -15
|
| 401 |
+
|
| 402 |
+
KPX comma space -110
|
| 403 |
+
KPX comma quoteright -120
|
| 404 |
+
KPX comma quotedblright -120
|
| 405 |
+
|
| 406 |
+
KPX e y -20
|
| 407 |
+
KPX e w -20
|
| 408 |
+
KPX e v -20
|
| 409 |
+
|
| 410 |
+
KPX f period -50
|
| 411 |
+
KPX f o -40
|
| 412 |
+
KPX f l -30
|
| 413 |
+
KPX f i -34
|
| 414 |
+
KPX f f -60
|
| 415 |
+
KPX f e -20
|
| 416 |
+
KPX f dotlessi -34
|
| 417 |
+
KPX f comma -50
|
| 418 |
+
KPX f a -40
|
| 419 |
+
|
| 420 |
+
KPX g a -15
|
| 421 |
+
|
| 422 |
+
KPX h y -30
|
| 423 |
+
|
| 424 |
+
KPX k y -5
|
| 425 |
+
KPX k e -15
|
| 426 |
+
|
| 427 |
+
KPX m y -20
|
| 428 |
+
KPX m u -20
|
| 429 |
+
KPX m a -20
|
| 430 |
+
|
| 431 |
+
KPX n y -15
|
| 432 |
+
KPX n v -20
|
| 433 |
+
|
| 434 |
+
KPX o y -20
|
| 435 |
+
KPX o x -15
|
| 436 |
+
KPX o w -20
|
| 437 |
+
KPX o v -30
|
| 438 |
+
|
| 439 |
+
KPX p y -20
|
| 440 |
+
|
| 441 |
+
KPX period space -110
|
| 442 |
+
KPX period quoteright -120
|
| 443 |
+
KPX period quotedblright -120
|
| 444 |
+
|
| 445 |
+
KPX quotedblleft quoteleft -35
|
| 446 |
+
KPX quotedblleft A -100
|
| 447 |
+
|
| 448 |
+
KPX quotedblright space -110
|
| 449 |
+
|
| 450 |
+
KPX quoteleft quoteleft -203
|
| 451 |
+
KPX quoteleft A -100
|
| 452 |
+
|
| 453 |
+
KPX quoteright v -30
|
| 454 |
+
KPX quoteright t 10
|
| 455 |
+
KPX quoteright space -110
|
| 456 |
+
KPX quoteright s -15
|
| 457 |
+
KPX quoteright r -20
|
| 458 |
+
KPX quoteright quoteright -203
|
| 459 |
+
KPX quoteright quotedblright -35
|
| 460 |
+
KPX quoteright d -110
|
| 461 |
+
|
| 462 |
+
KPX r y 40
|
| 463 |
+
KPX r v 40
|
| 464 |
+
KPX r u 20
|
| 465 |
+
KPX r t 20
|
| 466 |
+
KPX r s 20
|
| 467 |
+
KPX r q -8
|
| 468 |
+
KPX r period -73
|
| 469 |
+
KPX r p 20
|
| 470 |
+
KPX r o -20
|
| 471 |
+
KPX r n 21
|
| 472 |
+
KPX r m 28
|
| 473 |
+
KPX r l 20
|
| 474 |
+
KPX r k 20
|
| 475 |
+
KPX r i 20
|
| 476 |
+
KPX r hyphen -60
|
| 477 |
+
KPX r g -15
|
| 478 |
+
KPX r e -4
|
| 479 |
+
KPX r d -6
|
| 480 |
+
KPX r comma -75
|
| 481 |
+
KPX r c -20
|
| 482 |
+
KPX r a -20
|
| 483 |
+
|
| 484 |
+
KPX s period 20
|
| 485 |
+
KPX s comma 20
|
| 486 |
+
|
| 487 |
+
KPX space quoteleft -110
|
| 488 |
+
KPX space quotedblleft -110
|
| 489 |
+
KPX space Y -60
|
| 490 |
+
KPX space W -25
|
| 491 |
+
KPX space V -50
|
| 492 |
+
KPX space T -25
|
| 493 |
+
KPX space A -20
|
| 494 |
+
|
| 495 |
+
KPX v period -130
|
| 496 |
+
KPX v o -30
|
| 497 |
+
KPX v e -20
|
| 498 |
+
KPX v comma -100
|
| 499 |
+
KPX v a -30
|
| 500 |
+
|
| 501 |
+
KPX w period -100
|
| 502 |
+
KPX w o -30
|
| 503 |
+
KPX w h 15
|
| 504 |
+
KPX w e -20
|
| 505 |
+
KPX w comma -90
|
| 506 |
+
KPX w a -30
|
| 507 |
+
|
| 508 |
+
KPX y period -125
|
| 509 |
+
KPX y o -30
|
| 510 |
+
KPX y e -20
|
| 511 |
+
KPX y comma -110
|
| 512 |
+
KPX y a -30
|
| 513 |
+
EndKernPairs
|
| 514 |
+
EndKernData
|
| 515 |
+
StartComposites 56
|
| 516 |
+
CC Aacute 2 ; PCC A 0 0 ; PCC acute 183 163 ;
|
| 517 |
+
CC Acircumflex 2 ; PCC A 0 0 ; PCC circumflex 119 163 ;
|
| 518 |
+
CC Adieresis 2 ; PCC A 0 0 ; PCC dieresis 186 163 ;
|
| 519 |
+
CC Agrave 2 ; PCC A 0 0 ; PCC grave 181 163 ;
|
| 520 |
+
CC Aring 2 ; PCC A 0 0 ; PCC ring 204 148 ;
|
| 521 |
+
CC Atilde 2 ; PCC A 0 0 ; PCC tilde 151 163 ;
|
| 522 |
+
CC Eacute 2 ; PCC E 0 0 ; PCC acute 81 163 ;
|
| 523 |
+
CC Ecircumflex 2 ; PCC E 0 0 ; PCC circumflex 17 163 ;
|
| 524 |
+
CC Edieresis 2 ; PCC E 0 0 ; PCC dieresis 84 163 ;
|
| 525 |
+
CC Egrave 2 ; PCC E 0 0 ; PCC grave 79 163 ;
|
| 526 |
+
CC Iacute 2 ; PCC I 0 0 ; PCC acute -34 163 ;
|
| 527 |
+
CC Icircumflex 2 ; PCC I 0 0 ; PCC circumflex -138 163 ;
|
| 528 |
+
CC Idieresis 2 ; PCC I 0 0 ; PCC dieresis -71 163 ;
|
| 529 |
+
CC Igrave 2 ; PCC I 0 0 ; PCC grave -116 163 ;
|
| 530 |
+
CC Ntilde 2 ; PCC N 0 0 ; PCC tilde 151 163 ;
|
| 531 |
+
CC Oacute 2 ; PCC O 0 0 ; PCC acute 247 163 ;
|
| 532 |
+
CC Ocircumflex 2 ; PCC O 0 0 ; PCC circumflex 184 163 ;
|
| 533 |
+
CC Odieresis 2 ; PCC O 0 0 ; PCC dieresis 250 163 ;
|
| 534 |
+
CC Ograve 2 ; PCC O 0 0 ; PCC grave 246 163 ;
|
| 535 |
+
CC Otilde 2 ; PCC O 0 0 ; PCC tilde 215 163 ;
|
| 536 |
+
CC Scaron 2 ; PCC S 0 0 ; PCC caron -2 163 ;
|
| 537 |
+
CC Uacute 2 ; PCC U 0 0 ; PCC acute 160 163 ;
|
| 538 |
+
CC Ucircumflex 2 ; PCC U 0 0 ; PCC circumflex 77 163 ;
|
| 539 |
+
CC Udieresis 2 ; PCC U 0 0 ; PCC dieresis 143 163 ;
|
| 540 |
+
CC Ugrave 2 ; PCC U 0 0 ; PCC grave 119 163 ;
|
| 541 |
+
CC Yacute 2 ; PCC Y 0 0 ; PCC acute 129 163 ;
|
| 542 |
+
CC Ydieresis 2 ; PCC Y 0 0 ; PCC dieresis 112 163 ;
|
| 543 |
+
CC Zcaron 2 ; PCC Z 0 0 ; PCC caron -11 163 ;
|
| 544 |
+
CC aacute 2 ; PCC a 0 0 ; PCC acute 154 0 ;
|
| 545 |
+
CC acircumflex 2 ; PCC a 0 0 ; PCC circumflex 91 0 ;
|
| 546 |
+
CC adieresis 2 ; PCC a 0 0 ; PCC dieresis 157 0 ;
|
| 547 |
+
CC agrave 2 ; PCC a 0 0 ; PCC grave 153 0 ;
|
| 548 |
+
CC aring 2 ; PCC a 0 0 ; PCC ring 176 0 ;
|
| 549 |
+
CC atilde 2 ; PCC a 0 0 ; PCC tilde 122 0 ;
|
| 550 |
+
CC eacute 2 ; PCC e 0 0 ; PCC acute 138 0 ;
|
| 551 |
+
CC ecircumflex 2 ; PCC e 0 0 ; PCC circumflex 74 0 ;
|
| 552 |
+
CC edieresis 2 ; PCC e 0 0 ; PCC dieresis 141 0 ;
|
| 553 |
+
CC egrave 2 ; PCC e 0 0 ; PCC grave 136 0 ;
|
| 554 |
+
CC iacute 2 ; PCC dotlessi 0 0 ; PCC acute -47 0 ;
|
| 555 |
+
CC icircumflex 2 ; PCC dotlessi 0 0 ; PCC circumflex -151 0 ;
|
| 556 |
+
CC idieresis 2 ; PCC dotlessi 0 0 ; PCC dieresis -84 0 ;
|
| 557 |
+
CC igrave 2 ; PCC dotlessi 0 0 ; PCC grave -129 0 ;
|
| 558 |
+
CC ntilde 2 ; PCC n 0 0 ; PCC tilde 86 0 ;
|
| 559 |
+
CC oacute 2 ; PCC o 0 0 ; PCC acute 140 0 ;
|
| 560 |
+
CC ocircumflex 2 ; PCC o 0 0 ; PCC circumflex 77 0 ;
|
| 561 |
+
CC odieresis 2 ; PCC o 0 0 ; PCC dieresis 143 0 ;
|
| 562 |
+
CC ograve 2 ; PCC o 0 0 ; PCC grave 139 0 ;
|
| 563 |
+
CC otilde 2 ; PCC o 0 0 ; PCC tilde 108 0 ;
|
| 564 |
+
CC scaron 2 ; PCC s 0 0 ; PCC caron -57 0 ;
|
| 565 |
+
CC uacute 2 ; PCC u 0 0 ; PCC acute 137 0 ;
|
| 566 |
+
CC ucircumflex 2 ; PCC u 0 0 ; PCC circumflex 53 0 ;
|
| 567 |
+
CC udieresis 2 ; PCC u 0 0 ; PCC dieresis 120 0 ;
|
| 568 |
+
CC ugrave 2 ; PCC u 0 0 ; PCC grave 95 0 ;
|
| 569 |
+
CC yacute 2 ; PCC y 0 0 ; PCC acute 101 0 ;
|
| 570 |
+
CC ydieresis 2 ; PCC y 0 0 ; PCC dieresis 84 0 ;
|
| 571 |
+
CC zcaron 2 ; PCC z 0 0 ; PCC caron -38 0 ;
|
| 572 |
+
EndComposites
|
| 573 |
+
EndFontMetrics
|
shared/package-files/65/654f25a3384d8bb5fb19a60408a60e8ab1ebfaa997699021f0f7b0f0249480c4/blob
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:654f25a3384d8bb5fb19a60408a60e8ab1ebfaa997699021f0f7b0f0249480c4
|
| 3 |
+
size 954904
|
shared/package-files/65/65527f26ff875fedd8339b83678ac0fd4e923b10ba9114060887bebf1020623d/blob
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Test truncated SVD transformer."""
|
| 2 |
+
|
| 3 |
+
import numpy as np
|
| 4 |
+
import pytest
|
| 5 |
+
import scipy.sparse as sp
|
| 6 |
+
|
| 7 |
+
from sklearn.decomposition import PCA, TruncatedSVD
|
| 8 |
+
from sklearn.utils import check_random_state
|
| 9 |
+
from sklearn.utils._testing import assert_allclose, assert_array_less
|
| 10 |
+
|
| 11 |
+
SVD_SOLVERS = ["arpack", "randomized"]
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
@pytest.fixture(scope="module")
|
| 15 |
+
def X_sparse():
|
| 16 |
+
# Make an X that looks somewhat like a small tf-idf matrix.
|
| 17 |
+
rng = check_random_state(42)
|
| 18 |
+
X = sp.random(60, 55, density=0.2, format="csr", random_state=rng)
|
| 19 |
+
X.data[:] = 1 + np.log(X.data)
|
| 20 |
+
return X
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
@pytest.mark.parametrize("solver", ["randomized"])
|
| 24 |
+
@pytest.mark.parametrize("kind", ("dense", "sparse"))
|
| 25 |
+
def test_solvers(X_sparse, solver, kind):
|
| 26 |
+
X = X_sparse if kind == "sparse" else X_sparse.toarray()
|
| 27 |
+
svd_a = TruncatedSVD(30, algorithm="arpack")
|
| 28 |
+
svd = TruncatedSVD(30, algorithm=solver, random_state=42, n_oversamples=100)
|
| 29 |
+
|
| 30 |
+
Xa = svd_a.fit_transform(X)[:, :6]
|
| 31 |
+
Xr = svd.fit_transform(X)[:, :6]
|
| 32 |
+
assert_allclose(Xa, Xr, rtol=2e-3)
|
| 33 |
+
|
| 34 |
+
comp_a = np.abs(svd_a.components_)
|
| 35 |
+
comp = np.abs(svd.components_)
|
| 36 |
+
# All elements are equal, but some elements are more equal than others.
|
| 37 |
+
assert_allclose(comp_a[:9], comp[:9], rtol=1e-3)
|
| 38 |
+
assert_allclose(comp_a[9:], comp[9:], atol=1e-2)
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
@pytest.mark.parametrize("n_components", (10, 25, 41, 55))
|
| 42 |
+
def test_attributes(n_components, X_sparse):
|
| 43 |
+
n_features = X_sparse.shape[1]
|
| 44 |
+
tsvd = TruncatedSVD(n_components).fit(X_sparse)
|
| 45 |
+
assert tsvd.n_components == n_components
|
| 46 |
+
assert tsvd.components_.shape == (n_components, n_features)
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
@pytest.mark.parametrize(
|
| 50 |
+
"algorithm, n_components",
|
| 51 |
+
[
|
| 52 |
+
("arpack", 55),
|
| 53 |
+
("arpack", 56),
|
| 54 |
+
("randomized", 56),
|
| 55 |
+
],
|
| 56 |
+
)
|
| 57 |
+
def test_too_many_components(X_sparse, algorithm, n_components):
|
| 58 |
+
tsvd = TruncatedSVD(n_components=n_components, algorithm=algorithm)
|
| 59 |
+
with pytest.raises(ValueError):
|
| 60 |
+
tsvd.fit(X_sparse)
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
@pytest.mark.parametrize("fmt", ("array", "csr", "csc", "coo", "lil"))
|
| 64 |
+
def test_sparse_formats(fmt, X_sparse):
|
| 65 |
+
n_samples = X_sparse.shape[0]
|
| 66 |
+
Xfmt = X_sparse.toarray() if fmt == "dense" else getattr(X_sparse, "to" + fmt)()
|
| 67 |
+
tsvd = TruncatedSVD(n_components=11)
|
| 68 |
+
Xtrans = tsvd.fit_transform(Xfmt)
|
| 69 |
+
assert Xtrans.shape == (n_samples, 11)
|
| 70 |
+
Xtrans = tsvd.transform(Xfmt)
|
| 71 |
+
assert Xtrans.shape == (n_samples, 11)
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
@pytest.mark.parametrize("algo", SVD_SOLVERS)
|
| 75 |
+
def test_inverse_transform(algo, X_sparse):
|
| 76 |
+
# We need a lot of components for the reconstruction to be "almost
|
| 77 |
+
# equal" in all positions. XXX Test means or sums instead?
|
| 78 |
+
tsvd = TruncatedSVD(n_components=52, random_state=42, algorithm=algo)
|
| 79 |
+
Xt = tsvd.fit_transform(X_sparse)
|
| 80 |
+
Xinv = tsvd.inverse_transform(Xt)
|
| 81 |
+
assert_allclose(Xinv, X_sparse.toarray(), rtol=1e-1, atol=2e-1)
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
def test_integers(X_sparse):
|
| 85 |
+
n_samples = X_sparse.shape[0]
|
| 86 |
+
Xint = X_sparse.astype(np.int64)
|
| 87 |
+
tsvd = TruncatedSVD(n_components=6)
|
| 88 |
+
Xtrans = tsvd.fit_transform(Xint)
|
| 89 |
+
assert Xtrans.shape == (n_samples, tsvd.n_components)
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
@pytest.mark.parametrize("kind", ("dense", "sparse"))
|
| 93 |
+
@pytest.mark.parametrize("n_components", [10, 20])
|
| 94 |
+
@pytest.mark.parametrize("solver", SVD_SOLVERS)
|
| 95 |
+
def test_explained_variance(X_sparse, kind, n_components, solver):
|
| 96 |
+
X = X_sparse if kind == "sparse" else X_sparse.toarray()
|
| 97 |
+
svd = TruncatedSVD(n_components, algorithm=solver)
|
| 98 |
+
X_tr = svd.fit_transform(X)
|
| 99 |
+
# Assert that all the values are greater than 0
|
| 100 |
+
assert_array_less(0.0, svd.explained_variance_ratio_)
|
| 101 |
+
|
| 102 |
+
# Assert that total explained variance is less than 1
|
| 103 |
+
assert_array_less(svd.explained_variance_ratio_.sum(), 1.0)
|
| 104 |
+
|
| 105 |
+
# Test that explained_variance is correct
|
| 106 |
+
total_variance = np.var(X_sparse.toarray(), axis=0).sum()
|
| 107 |
+
variances = np.var(X_tr, axis=0)
|
| 108 |
+
true_explained_variance_ratio = variances / total_variance
|
| 109 |
+
|
| 110 |
+
assert_allclose(
|
| 111 |
+
svd.explained_variance_ratio_,
|
| 112 |
+
true_explained_variance_ratio,
|
| 113 |
+
)
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
@pytest.mark.parametrize("kind", ("dense", "sparse"))
|
| 117 |
+
@pytest.mark.parametrize("solver", SVD_SOLVERS)
|
| 118 |
+
def test_explained_variance_components_10_20(X_sparse, kind, solver):
|
| 119 |
+
X = X_sparse if kind == "sparse" else X_sparse.toarray()
|
| 120 |
+
svd_10 = TruncatedSVD(10, algorithm=solver, n_iter=10).fit(X)
|
| 121 |
+
svd_20 = TruncatedSVD(20, algorithm=solver, n_iter=10).fit(X)
|
| 122 |
+
|
| 123 |
+
# Assert the 1st component is equal
|
| 124 |
+
assert_allclose(
|
| 125 |
+
svd_10.explained_variance_ratio_,
|
| 126 |
+
svd_20.explained_variance_ratio_[:10],
|
| 127 |
+
rtol=5e-3,
|
| 128 |
+
)
|
| 129 |
+
|
| 130 |
+
# Assert that 20 components has higher explained variance than 10
|
| 131 |
+
assert (
|
| 132 |
+
svd_20.explained_variance_ratio_.sum() > svd_10.explained_variance_ratio_.sum()
|
| 133 |
+
)
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
@pytest.mark.parametrize("solver", SVD_SOLVERS)
|
| 137 |
+
def test_singular_values_consistency(solver, global_random_seed):
|
| 138 |
+
# Check that the TruncatedSVD output has the correct singular values
|
| 139 |
+
rng = np.random.RandomState(global_random_seed)
|
| 140 |
+
n_samples, n_features = 100, 80
|
| 141 |
+
X = rng.randn(n_samples, n_features)
|
| 142 |
+
|
| 143 |
+
pca = TruncatedSVD(n_components=2, algorithm=solver, random_state=rng).fit(X)
|
| 144 |
+
|
| 145 |
+
# Compare to the Frobenius norm
|
| 146 |
+
X_pca = pca.transform(X)
|
| 147 |
+
assert_allclose(
|
| 148 |
+
np.sum(pca.singular_values_**2.0),
|
| 149 |
+
np.linalg.norm(X_pca, "fro") ** 2.0,
|
| 150 |
+
rtol=1e-2,
|
| 151 |
+
)
|
| 152 |
+
|
| 153 |
+
# Compare to the 2-norms of the score vectors
|
| 154 |
+
assert_allclose(
|
| 155 |
+
pca.singular_values_, np.sqrt(np.sum(X_pca**2.0, axis=0)), rtol=1e-2
|
| 156 |
+
)
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
@pytest.mark.parametrize("solver", SVD_SOLVERS)
|
| 160 |
+
def test_singular_values_expected(solver, global_random_seed):
|
| 161 |
+
# Set the singular values and see what we get back
|
| 162 |
+
rng = np.random.RandomState(global_random_seed)
|
| 163 |
+
n_samples = 100
|
| 164 |
+
n_features = 110
|
| 165 |
+
|
| 166 |
+
X = rng.randn(n_samples, n_features)
|
| 167 |
+
|
| 168 |
+
pca = TruncatedSVD(n_components=3, algorithm=solver, random_state=rng)
|
| 169 |
+
X_pca = pca.fit_transform(X)
|
| 170 |
+
|
| 171 |
+
X_pca /= np.sqrt(np.sum(X_pca**2.0, axis=0))
|
| 172 |
+
X_pca[:, 0] *= 3.142
|
| 173 |
+
X_pca[:, 1] *= 2.718
|
| 174 |
+
|
| 175 |
+
X_hat_pca = np.dot(X_pca, pca.components_)
|
| 176 |
+
pca.fit(X_hat_pca)
|
| 177 |
+
assert_allclose(pca.singular_values_, [3.142, 2.718, 1.0], rtol=1e-14)
|
| 178 |
+
|
| 179 |
+
|
| 180 |
+
def test_truncated_svd_eq_pca(X_sparse):
|
| 181 |
+
# TruncatedSVD should be equal to PCA on centered data
|
| 182 |
+
|
| 183 |
+
X_dense = X_sparse.toarray()
|
| 184 |
+
|
| 185 |
+
X_c = X_dense - X_dense.mean(axis=0)
|
| 186 |
+
|
| 187 |
+
params = dict(n_components=10, random_state=42)
|
| 188 |
+
|
| 189 |
+
svd = TruncatedSVD(algorithm="arpack", **params)
|
| 190 |
+
pca = PCA(svd_solver="arpack", **params)
|
| 191 |
+
|
| 192 |
+
Xt_svd = svd.fit_transform(X_c)
|
| 193 |
+
Xt_pca = pca.fit_transform(X_c)
|
| 194 |
+
|
| 195 |
+
assert_allclose(Xt_svd, Xt_pca, rtol=1e-9)
|
| 196 |
+
assert_allclose(pca.mean_, 0, atol=1e-9)
|
| 197 |
+
assert_allclose(svd.components_, pca.components_)
|
| 198 |
+
|
| 199 |
+
|
| 200 |
+
@pytest.mark.parametrize(
|
| 201 |
+
"algorithm, tol", [("randomized", 0.0), ("arpack", 1e-6), ("arpack", 0.0)]
|
| 202 |
+
)
|
| 203 |
+
@pytest.mark.parametrize("kind", ("dense", "sparse"))
|
| 204 |
+
def test_fit_transform(X_sparse, algorithm, tol, kind):
|
| 205 |
+
# fit_transform(X) should equal fit(X).transform(X)
|
| 206 |
+
X = X_sparse if kind == "sparse" else X_sparse.toarray()
|
| 207 |
+
svd = TruncatedSVD(
|
| 208 |
+
n_components=5, n_iter=7, random_state=42, algorithm=algorithm, tol=tol
|
| 209 |
+
)
|
| 210 |
+
X_transformed_1 = svd.fit_transform(X)
|
| 211 |
+
X_transformed_2 = svd.fit(X).transform(X)
|
| 212 |
+
assert_allclose(X_transformed_1, X_transformed_2)
|
shared/package-files/65/6552b64c85b45e35910c17b1d39e329a6565481430f912018442f5c12d990265/blob
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from sympy.core.symbol import Symbol
|
| 2 |
+
from sympy.matrices.dense import (eye, zeros)
|
| 3 |
+
from sympy.solvers.solvers import solve_linear_system
|
| 4 |
+
|
| 5 |
+
N = 8
|
| 6 |
+
M = zeros(N, N + 1)
|
| 7 |
+
M[:, :N] = eye(N)
|
| 8 |
+
S = [Symbol('A%i' % i) for i in range(N)]
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def timeit_linsolve_trivial():
|
| 12 |
+
solve_linear_system(M, *S)
|
shared/package-files/65/6554310415438f47722a6d789aa8a0ffccf4c5f699412c2d69c32cffe6d19cf4/blob
ADDED
|
@@ -0,0 +1,297 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# megawidget.tcl
|
| 2 |
+
#
|
| 3 |
+
# Basic megawidget support classes. Experimental for any use other than
|
| 4 |
+
# the ::tk::IconList megawdget, which is itself only designed for use in
|
| 5 |
+
# the Unix file dialogs.
|
| 6 |
+
#
|
| 7 |
+
# Copyright (c) 2009-2010 Donal K. Fellows
|
| 8 |
+
#
|
| 9 |
+
# See the file "license.terms" for information on usage and redistribution of
|
| 10 |
+
# this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
| 11 |
+
#
|
| 12 |
+
|
| 13 |
+
package require Tk
|
| 14 |
+
|
| 15 |
+
::oo::class create ::tk::Megawidget {
|
| 16 |
+
superclass ::oo::class
|
| 17 |
+
method unknown {w args} {
|
| 18 |
+
if {[string match .* $w]} {
|
| 19 |
+
[self] create $w {*}$args
|
| 20 |
+
return $w
|
| 21 |
+
}
|
| 22 |
+
next $w {*}$args
|
| 23 |
+
}
|
| 24 |
+
unexport new unknown
|
| 25 |
+
self method create {name superclasses body} {
|
| 26 |
+
next $name [list \
|
| 27 |
+
superclass ::tk::MegawidgetClass {*}$superclasses]\;$body
|
| 28 |
+
}
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
::oo::class create ::tk::MegawidgetClass {
|
| 32 |
+
variable w hull options IdleCallbacks
|
| 33 |
+
constructor args {
|
| 34 |
+
# Extract the "widget name" from the object name
|
| 35 |
+
set w [namespace tail [self]]
|
| 36 |
+
|
| 37 |
+
# Configure things
|
| 38 |
+
tclParseConfigSpec [my varname options] [my GetSpecs] "" $args
|
| 39 |
+
|
| 40 |
+
# Move the object out of the way of the hull widget
|
| 41 |
+
rename [self] _tmp
|
| 42 |
+
|
| 43 |
+
# Make the hull widget(s)
|
| 44 |
+
my CreateHull
|
| 45 |
+
bind $hull <Destroy> [list [namespace which my] destroy]
|
| 46 |
+
|
| 47 |
+
# Rename things into their final places
|
| 48 |
+
rename ::$w theWidget
|
| 49 |
+
rename [self] ::$w
|
| 50 |
+
|
| 51 |
+
# Make the contents
|
| 52 |
+
my Create
|
| 53 |
+
}
|
| 54 |
+
destructor {
|
| 55 |
+
foreach {name cb} [array get IdleCallbacks] {
|
| 56 |
+
after cancel $cb
|
| 57 |
+
unset IdleCallbacks($name)
|
| 58 |
+
}
|
| 59 |
+
if {[winfo exists $w]} {
|
| 60 |
+
bind $hull <Destroy> {}
|
| 61 |
+
destroy $w
|
| 62 |
+
}
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
####################################################################
|
| 66 |
+
#
|
| 67 |
+
# MegawidgetClass::configure --
|
| 68 |
+
#
|
| 69 |
+
# Implementation of 'configure' for megawidgets. Emulates the operation
|
| 70 |
+
# of the standard Tk configure method fairly closely, which makes things
|
| 71 |
+
# substantially more complex than they otherwise would be.
|
| 72 |
+
#
|
| 73 |
+
# This method assumes that the 'GetSpecs' method returns a description
|
| 74 |
+
# of all the specifications of the options (i.e., as Tk returns except
|
| 75 |
+
# with the actual values removed). It also assumes that the 'options'
|
| 76 |
+
# array in the class holds all options; it is up to subclasses to set
|
| 77 |
+
# traces on that array if they want to respond to configuration changes.
|
| 78 |
+
#
|
| 79 |
+
# TODO: allow unambiguous abbreviations.
|
| 80 |
+
#
|
| 81 |
+
method configure args {
|
| 82 |
+
# Configure behaves differently depending on the number of arguments
|
| 83 |
+
set argc [llength $args]
|
| 84 |
+
if {$argc == 0} {
|
| 85 |
+
return [lmap spec [my GetSpecs] {
|
| 86 |
+
lappend spec $options([lindex $spec 0])
|
| 87 |
+
}]
|
| 88 |
+
} elseif {$argc == 1} {
|
| 89 |
+
set opt [lindex $args 0]
|
| 90 |
+
if {[info exists options($opt)]} {
|
| 91 |
+
set spec [lsearch -inline -index 0 -exact [my GetSpecs] $opt]
|
| 92 |
+
return [linsert $spec end $options($opt)]
|
| 93 |
+
}
|
| 94 |
+
} elseif {$argc == 2} {
|
| 95 |
+
# Special case for where we're setting a single option. This
|
| 96 |
+
# avoids some of the costly operations. We still do the [array
|
| 97 |
+
# get] as this gives a sufficiently-consistent trace.
|
| 98 |
+
set opt [lindex $args 0]
|
| 99 |
+
if {[dict exists [array get options] $opt]} {
|
| 100 |
+
# Actually set the new value of the option. Use a catch to
|
| 101 |
+
# allow a megawidget user to throw an error from a write trace
|
| 102 |
+
# on the options array to reject invalid values.
|
| 103 |
+
try {
|
| 104 |
+
array set options $args
|
| 105 |
+
} on error {ret info} {
|
| 106 |
+
# Rethrow the error to get a clean stack trace
|
| 107 |
+
return -code error -errorcode [dict get $info -errorcode] $ret
|
| 108 |
+
}
|
| 109 |
+
return
|
| 110 |
+
}
|
| 111 |
+
} elseif {$argc % 2 == 0} {
|
| 112 |
+
# Check that all specified options exist. Any unknown option will
|
| 113 |
+
# cause the merged dictionary to be bigger than the options array
|
| 114 |
+
set merge [dict merge [array get options] $args]
|
| 115 |
+
if {[dict size $merge] == [array size options]} {
|
| 116 |
+
# Actually set the new values of the options. Use a catch to
|
| 117 |
+
# allow a megawidget user to throw an error from a write trace
|
| 118 |
+
# on the options array to reject invalid values
|
| 119 |
+
try {
|
| 120 |
+
array set options $args
|
| 121 |
+
} on error {ret info} {
|
| 122 |
+
# Rethrow the error to get a clean stack trace
|
| 123 |
+
return -code error -errorcode [dict get $info -errorcode] $ret
|
| 124 |
+
}
|
| 125 |
+
return
|
| 126 |
+
}
|
| 127 |
+
# Due to the order of the merge, the unknown options will be at
|
| 128 |
+
# the end of the dict. This makes the first unknown option easy to
|
| 129 |
+
# find.
|
| 130 |
+
set opt [lindex [dict keys $merge] [array size options]]
|
| 131 |
+
} else {
|
| 132 |
+
set opt [lindex $args end]
|
| 133 |
+
return -code error -errorcode [list TK VALUE_MISSING] \
|
| 134 |
+
"value for \"$opt\" missing"
|
| 135 |
+
}
|
| 136 |
+
return -code error -errorcode [list TK LOOKUP OPTION $opt] \
|
| 137 |
+
"bad option \"$opt\": must be [tclListValidFlags options]"
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
####################################################################
|
| 141 |
+
#
|
| 142 |
+
# MegawidgetClass::cget --
|
| 143 |
+
#
|
| 144 |
+
# Implementation of 'cget' for megawidgets. Emulates the operation of
|
| 145 |
+
# the standard Tk cget method fairly closely.
|
| 146 |
+
#
|
| 147 |
+
# This method assumes that the 'options' array in the class holds all
|
| 148 |
+
# options; it is up to subclasses to set traces on that array if they
|
| 149 |
+
# want to respond to configuration reads.
|
| 150 |
+
#
|
| 151 |
+
# TODO: allow unambiguous abbreviations.
|
| 152 |
+
#
|
| 153 |
+
method cget option {
|
| 154 |
+
return $options($option)
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
####################################################################
|
| 158 |
+
#
|
| 159 |
+
# MegawidgetClass::TraceOption --
|
| 160 |
+
#
|
| 161 |
+
# Sets up the tracing of an element of the options variable.
|
| 162 |
+
#
|
| 163 |
+
method TraceOption {option method args} {
|
| 164 |
+
set callback [list my $method {*}$args]
|
| 165 |
+
trace add variable options($option) write [namespace code $callback]
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
####################################################################
|
| 169 |
+
#
|
| 170 |
+
# MegawidgetClass::GetSpecs --
|
| 171 |
+
#
|
| 172 |
+
# Return a list of descriptions of options supported by this
|
| 173 |
+
# megawidget. Each option is described by the 4-tuple list, consisting
|
| 174 |
+
# of the name of the option, the "option database" name, the "option
|
| 175 |
+
# database" class-name, and the default value of the option. These are
|
| 176 |
+
# the same values returned by calling the configure method of a widget,
|
| 177 |
+
# except without the current values of the options.
|
| 178 |
+
#
|
| 179 |
+
method GetSpecs {} {
|
| 180 |
+
return {
|
| 181 |
+
{-takefocus takeFocus TakeFocus {}}
|
| 182 |
+
}
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
####################################################################
|
| 186 |
+
#
|
| 187 |
+
# MegawidgetClass::CreateHull --
|
| 188 |
+
#
|
| 189 |
+
# Creates the real main widget of the megawidget. This is often a frame
|
| 190 |
+
# or toplevel widget, but isn't always (lightweight megawidgets might
|
| 191 |
+
# use a content widget directly).
|
| 192 |
+
#
|
| 193 |
+
# The name of the hull widget is given by the 'w' instance variable. The
|
| 194 |
+
# name should be written into the 'hull' instance variable. The command
|
| 195 |
+
# created by this method will be renamed.
|
| 196 |
+
#
|
| 197 |
+
method CreateHull {} {
|
| 198 |
+
return -code error -errorcode {TCL OO ABSTRACT_METHOD} \
|
| 199 |
+
"method must be overridden"
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
####################################################################
|
| 203 |
+
#
|
| 204 |
+
# MegawidgetClass::Create --
|
| 205 |
+
#
|
| 206 |
+
# Creates the content of the megawidget. The name of the widget to
|
| 207 |
+
# create the content in will be in the 'hull' instance variable.
|
| 208 |
+
#
|
| 209 |
+
method Create {} {
|
| 210 |
+
return -code error -errorcode {TCL OO ABSTRACT_METHOD} \
|
| 211 |
+
"method must be overridden"
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
####################################################################
|
| 215 |
+
#
|
| 216 |
+
# MegawidgetClass::WhenIdle --
|
| 217 |
+
#
|
| 218 |
+
# Arrange for a method to be called on the current instance when Tk is
|
| 219 |
+
# idle. Only one such method call per method will be queued; subsequent
|
| 220 |
+
# queuing actions before the callback fires will be silently ignored.
|
| 221 |
+
# The additional args will be passed to the callback, and the callbacks
|
| 222 |
+
# will be properly cancelled if the widget is destroyed.
|
| 223 |
+
#
|
| 224 |
+
method WhenIdle {method args} {
|
| 225 |
+
if {![info exists IdleCallbacks($method)]} {
|
| 226 |
+
set IdleCallbacks($method) [after idle [list \
|
| 227 |
+
[namespace which my] DoWhenIdle $method $args]]
|
| 228 |
+
}
|
| 229 |
+
}
|
| 230 |
+
method DoWhenIdle {method arguments} {
|
| 231 |
+
unset IdleCallbacks($method)
|
| 232 |
+
tailcall my $method {*}$arguments
|
| 233 |
+
}
|
| 234 |
+
}
|
| 235 |
+
|
| 236 |
+
####################################################################
|
| 237 |
+
#
|
| 238 |
+
# tk::SimpleWidget --
|
| 239 |
+
#
|
| 240 |
+
# Simple megawidget class that makes it easy create widgets that behave
|
| 241 |
+
# like a ttk widget. It creates the hull as a ttk::frame and maps the
|
| 242 |
+
# state manipulation methods of the overall megawidget to the equivalent
|
| 243 |
+
# operations on the ttk::frame.
|
| 244 |
+
#
|
| 245 |
+
::tk::Megawidget create ::tk::SimpleWidget {} {
|
| 246 |
+
variable w hull options
|
| 247 |
+
method GetSpecs {} {
|
| 248 |
+
return {
|
| 249 |
+
{-cursor cursor Cursor {}}
|
| 250 |
+
{-takefocus takeFocus TakeFocus {}}
|
| 251 |
+
}
|
| 252 |
+
}
|
| 253 |
+
method CreateHull {} {
|
| 254 |
+
set hull [::ttk::frame $w -cursor $options(-cursor)]
|
| 255 |
+
my TraceOption -cursor UpdateCursorOption
|
| 256 |
+
}
|
| 257 |
+
method UpdateCursorOption args {
|
| 258 |
+
$hull configure -cursor $options(-cursor)
|
| 259 |
+
}
|
| 260 |
+
# Not fixed names, so can't forward
|
| 261 |
+
method state args {
|
| 262 |
+
tailcall $hull state {*}$args
|
| 263 |
+
}
|
| 264 |
+
method instate args {
|
| 265 |
+
tailcall $hull instate {*}$args
|
| 266 |
+
}
|
| 267 |
+
}
|
| 268 |
+
|
| 269 |
+
####################################################################
|
| 270 |
+
#
|
| 271 |
+
# tk::FocusableWidget --
|
| 272 |
+
#
|
| 273 |
+
# Simple megawidget class that makes a ttk-like widget that has a focus
|
| 274 |
+
# ring.
|
| 275 |
+
#
|
| 276 |
+
::tk::Megawidget create ::tk::FocusableWidget ::tk::SimpleWidget {
|
| 277 |
+
variable w hull options
|
| 278 |
+
method GetSpecs {} {
|
| 279 |
+
return {
|
| 280 |
+
{-cursor cursor Cursor {}}
|
| 281 |
+
{-takefocus takeFocus TakeFocus ::ttk::takefocus}
|
| 282 |
+
}
|
| 283 |
+
}
|
| 284 |
+
method CreateHull {} {
|
| 285 |
+
ttk::frame $w
|
| 286 |
+
set hull [ttk::entry $w.cHull -takefocus 0 -cursor $options(-cursor)]
|
| 287 |
+
pack $hull -expand yes -fill both -ipadx 2 -ipady 2
|
| 288 |
+
my TraceOption -cursor UpdateCursorOption
|
| 289 |
+
}
|
| 290 |
+
}
|
| 291 |
+
|
| 292 |
+
return
|
| 293 |
+
|
| 294 |
+
# Local Variables:
|
| 295 |
+
# mode: tcl
|
| 296 |
+
# fill-column: 78
|
| 297 |
+
# End:
|
shared/package-files/65/6556137f5f3ab89442327123458e8d6581cd319b7d1cc382b1519dad334d4c2f/blob
ADDED
|
@@ -0,0 +1,784 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# mypy: ignore-errors
|
| 2 |
+
|
| 3 |
+
import unittest
|
| 4 |
+
from functools import partial
|
| 5 |
+
from typing import List
|
| 6 |
+
|
| 7 |
+
import numpy as np
|
| 8 |
+
|
| 9 |
+
import torch
|
| 10 |
+
|
| 11 |
+
from torch.testing import make_tensor
|
| 12 |
+
from torch.testing._internal.common_cuda import SM53OrLater
|
| 13 |
+
from torch.testing._internal.common_device_type import precisionOverride
|
| 14 |
+
from torch.testing._internal.common_dtype import (
|
| 15 |
+
all_types_and,
|
| 16 |
+
all_types_and_complex_and,
|
| 17 |
+
)
|
| 18 |
+
from torch.testing._internal.common_utils import TEST_SCIPY, TEST_WITH_ROCM
|
| 19 |
+
from torch.testing._internal.opinfo.core import (
|
| 20 |
+
DecorateInfo,
|
| 21 |
+
ErrorInput,
|
| 22 |
+
OpInfo,
|
| 23 |
+
sample_inputs_spectral_ops,
|
| 24 |
+
SampleInput,
|
| 25 |
+
SpectralFuncInfo,
|
| 26 |
+
SpectralFuncType,
|
| 27 |
+
)
|
| 28 |
+
from torch.testing._internal.opinfo.refs import (
|
| 29 |
+
_find_referenced_opinfo,
|
| 30 |
+
_inherit_constructor_args,
|
| 31 |
+
PythonRefInfo,
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
has_scipy_fft = False
|
| 35 |
+
if TEST_SCIPY:
|
| 36 |
+
try:
|
| 37 |
+
import scipy.fft
|
| 38 |
+
|
| 39 |
+
has_scipy_fft = True
|
| 40 |
+
except ModuleNotFoundError:
|
| 41 |
+
pass
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
class SpectralFuncPythonRefInfo(SpectralFuncInfo):
|
| 45 |
+
"""
|
| 46 |
+
An OpInfo for a Python reference of an elementwise unary operation.
|
| 47 |
+
"""
|
| 48 |
+
|
| 49 |
+
def __init__(
|
| 50 |
+
self,
|
| 51 |
+
name, # the stringname of the callable Python reference
|
| 52 |
+
*,
|
| 53 |
+
op=None, # the function variant of the operation, populated as torch.<name> if None
|
| 54 |
+
torch_opinfo_name, # the string name of the corresponding torch opinfo
|
| 55 |
+
torch_opinfo_variant="",
|
| 56 |
+
**kwargs,
|
| 57 |
+
): # additional kwargs override kwargs inherited from the torch opinfo
|
| 58 |
+
self.torch_opinfo_name = torch_opinfo_name
|
| 59 |
+
self.torch_opinfo = _find_referenced_opinfo(
|
| 60 |
+
torch_opinfo_name, torch_opinfo_variant, op_db=op_db
|
| 61 |
+
)
|
| 62 |
+
assert isinstance(self.torch_opinfo, SpectralFuncInfo)
|
| 63 |
+
|
| 64 |
+
inherited = self.torch_opinfo._original_spectral_func_args
|
| 65 |
+
ukwargs = _inherit_constructor_args(name, op, inherited, kwargs)
|
| 66 |
+
|
| 67 |
+
super().__init__(**ukwargs)
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
def error_inputs_fft(op_info, device, **kwargs):
|
| 71 |
+
make_arg = partial(make_tensor, device=device, dtype=torch.float32)
|
| 72 |
+
# Zero-dimensional tensor has no dimension to take FFT of
|
| 73 |
+
yield ErrorInput(
|
| 74 |
+
SampleInput(make_arg()),
|
| 75 |
+
error_type=IndexError,
|
| 76 |
+
error_regex="Dimension specified as -1 but tensor has no dimensions",
|
| 77 |
+
)
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def error_inputs_fftn(op_info, device, **kwargs):
|
| 81 |
+
make_arg = partial(make_tensor, device=device, dtype=torch.float32)
|
| 82 |
+
# Specifying a dimension on a zero-dimensional tensor
|
| 83 |
+
yield ErrorInput(
|
| 84 |
+
SampleInput(make_arg(), dim=(0,)),
|
| 85 |
+
error_type=IndexError,
|
| 86 |
+
error_regex="Dimension specified as 0 but tensor has no dimensions",
|
| 87 |
+
)
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
def sample_inputs_fft_with_min(
|
| 91 |
+
op_info, device, dtype, requires_grad=False, *, min_size, **kwargs
|
| 92 |
+
):
|
| 93 |
+
yield from sample_inputs_spectral_ops(
|
| 94 |
+
op_info, device, dtype, requires_grad, **kwargs
|
| 95 |
+
)
|
| 96 |
+
if TEST_WITH_ROCM:
|
| 97 |
+
# FIXME: Causes floating point exception on ROCm
|
| 98 |
+
return
|
| 99 |
+
|
| 100 |
+
# Check the "Invalid number of data points" error isn't too strict
|
| 101 |
+
# https://github.com/pytorch/pytorch/pull/109083
|
| 102 |
+
a = make_tensor(min_size, dtype=dtype, device=device, requires_grad=requires_grad)
|
| 103 |
+
yield SampleInput(a)
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
def sample_inputs_fftshift(op_info, device, dtype, requires_grad, **kwargs):
|
| 107 |
+
def mt(shape, **kwargs):
|
| 108 |
+
return make_tensor(
|
| 109 |
+
shape, device=device, dtype=dtype, requires_grad=requires_grad, **kwargs
|
| 110 |
+
)
|
| 111 |
+
|
| 112 |
+
yield SampleInput(mt((9, 10)))
|
| 113 |
+
yield SampleInput(mt((50,)), kwargs=dict(dim=0))
|
| 114 |
+
yield SampleInput(mt((5, 11)), kwargs=dict(dim=(1,)))
|
| 115 |
+
yield SampleInput(mt((5, 6)), kwargs=dict(dim=(0, 1)))
|
| 116 |
+
yield SampleInput(mt((5, 6, 2)), kwargs=dict(dim=(0, 2)))
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
# Operator database
|
| 120 |
+
op_db: List[OpInfo] = [
|
| 121 |
+
SpectralFuncInfo(
|
| 122 |
+
"fft.fft",
|
| 123 |
+
aten_name="fft_fft",
|
| 124 |
+
decomp_aten_name="_fft_c2c",
|
| 125 |
+
ref=np.fft.fft,
|
| 126 |
+
ndimensional=SpectralFuncType.OneD,
|
| 127 |
+
dtypes=all_types_and_complex_and(torch.bool),
|
| 128 |
+
# CUDA supports Half/ComplexHalf Precision FFT only on SM53 or later archs
|
| 129 |
+
dtypesIfCUDA=all_types_and_complex_and(
|
| 130 |
+
torch.bool,
|
| 131 |
+
*(() if (not SM53OrLater) else (torch.half, torch.complex32)),
|
| 132 |
+
),
|
| 133 |
+
sample_inputs_func=partial(sample_inputs_fft_with_min, min_size=1),
|
| 134 |
+
error_inputs_func=error_inputs_fft,
|
| 135 |
+
# https://github.com/pytorch/pytorch/issues/80411
|
| 136 |
+
gradcheck_fast_mode=True,
|
| 137 |
+
supports_forward_ad=True,
|
| 138 |
+
supports_fwgrad_bwgrad=True,
|
| 139 |
+
# See https://github.com/pytorch/pytorch/pull/78358
|
| 140 |
+
check_batched_forward_grad=False,
|
| 141 |
+
),
|
| 142 |
+
SpectralFuncInfo(
|
| 143 |
+
"fft.fft2",
|
| 144 |
+
aten_name="fft_fft2",
|
| 145 |
+
ref=np.fft.fft2,
|
| 146 |
+
decomp_aten_name="_fft_c2c",
|
| 147 |
+
ndimensional=SpectralFuncType.TwoD,
|
| 148 |
+
dtypes=all_types_and_complex_and(torch.bool),
|
| 149 |
+
# CUDA supports Half/ComplexHalf Precision FFT only on SM53 or later archs
|
| 150 |
+
dtypesIfCUDA=all_types_and_complex_and(
|
| 151 |
+
torch.bool,
|
| 152 |
+
*(() if (not SM53OrLater) else (torch.half, torch.complex32)),
|
| 153 |
+
),
|
| 154 |
+
sample_inputs_func=partial(sample_inputs_fft_with_min, min_size=(1, 1)),
|
| 155 |
+
error_inputs_func=error_inputs_fftn,
|
| 156 |
+
# https://github.com/pytorch/pytorch/issues/80411
|
| 157 |
+
gradcheck_fast_mode=True,
|
| 158 |
+
supports_forward_ad=True,
|
| 159 |
+
supports_fwgrad_bwgrad=True,
|
| 160 |
+
# See https://github.com/pytorch/pytorch/pull/78358
|
| 161 |
+
check_batched_forward_grad=False,
|
| 162 |
+
decorators=[precisionOverride({torch.float: 1e-4, torch.cfloat: 1e-4})],
|
| 163 |
+
skips=(
|
| 164 |
+
DecorateInfo(
|
| 165 |
+
unittest.skip("Skipped!"),
|
| 166 |
+
"TestCommon",
|
| 167 |
+
"test_complex_half_reference_testing",
|
| 168 |
+
device_type="cuda",
|
| 169 |
+
dtypes=[torch.complex32],
|
| 170 |
+
active_if=TEST_WITH_ROCM,
|
| 171 |
+
),
|
| 172 |
+
),
|
| 173 |
+
),
|
| 174 |
+
SpectralFuncInfo(
|
| 175 |
+
"fft.fftn",
|
| 176 |
+
aten_name="fft_fftn",
|
| 177 |
+
decomp_aten_name="_fft_c2c",
|
| 178 |
+
ref=np.fft.fftn,
|
| 179 |
+
ndimensional=SpectralFuncType.ND,
|
| 180 |
+
dtypes=all_types_and_complex_and(torch.bool),
|
| 181 |
+
# CUDA supports Half/ComplexHalf Precision FFT only on SM53 or later archs
|
| 182 |
+
dtypesIfCUDA=all_types_and_complex_and(
|
| 183 |
+
torch.bool,
|
| 184 |
+
*(() if (not SM53OrLater) else (torch.half, torch.complex32)),
|
| 185 |
+
),
|
| 186 |
+
sample_inputs_func=partial(sample_inputs_fft_with_min, min_size=(1, 1)),
|
| 187 |
+
error_inputs_func=error_inputs_fftn,
|
| 188 |
+
# https://github.com/pytorch/pytorch/issues/80411
|
| 189 |
+
gradcheck_fast_mode=True,
|
| 190 |
+
supports_forward_ad=True,
|
| 191 |
+
supports_fwgrad_bwgrad=True,
|
| 192 |
+
# See https://github.com/pytorch/pytorch/pull/78358
|
| 193 |
+
check_batched_forward_grad=False,
|
| 194 |
+
decorators=[precisionOverride({torch.float: 1e-4, torch.cfloat: 1e-4})],
|
| 195 |
+
),
|
| 196 |
+
SpectralFuncInfo(
|
| 197 |
+
"fft.hfft",
|
| 198 |
+
aten_name="fft_hfft",
|
| 199 |
+
decomp_aten_name="_fft_c2r",
|
| 200 |
+
ref=np.fft.hfft,
|
| 201 |
+
ndimensional=SpectralFuncType.OneD,
|
| 202 |
+
dtypes=all_types_and_complex_and(torch.bool),
|
| 203 |
+
# CUDA supports Half/ComplexHalf Precision FFT only on SM53 or later archs
|
| 204 |
+
dtypesIfCUDA=all_types_and_complex_and(
|
| 205 |
+
torch.bool,
|
| 206 |
+
*(() if (not SM53OrLater) else (torch.half, torch.complex32)),
|
| 207 |
+
),
|
| 208 |
+
sample_inputs_func=partial(sample_inputs_fft_with_min, min_size=2),
|
| 209 |
+
error_inputs_func=error_inputs_fft,
|
| 210 |
+
# https://github.com/pytorch/pytorch/issues/80411
|
| 211 |
+
gradcheck_fast_mode=True,
|
| 212 |
+
supports_forward_ad=True,
|
| 213 |
+
supports_fwgrad_bwgrad=True,
|
| 214 |
+
# See https://github.com/pytorch/pytorch/pull/78358
|
| 215 |
+
check_batched_forward_grad=False,
|
| 216 |
+
check_batched_gradgrad=False,
|
| 217 |
+
skips=(
|
| 218 |
+
# Issue with conj and torch dispatch, see https://github.com/pytorch/pytorch/issues/82479
|
| 219 |
+
DecorateInfo(
|
| 220 |
+
unittest.skip("Skipped!"),
|
| 221 |
+
"TestSchemaCheckModeOpInfo",
|
| 222 |
+
"test_schema_correctness",
|
| 223 |
+
dtypes=(torch.complex64, torch.complex128),
|
| 224 |
+
),
|
| 225 |
+
),
|
| 226 |
+
),
|
| 227 |
+
SpectralFuncInfo(
|
| 228 |
+
"fft.hfft2",
|
| 229 |
+
aten_name="fft_hfft2",
|
| 230 |
+
decomp_aten_name="_fft_c2r",
|
| 231 |
+
ref=scipy.fft.hfft2 if has_scipy_fft else None,
|
| 232 |
+
ndimensional=SpectralFuncType.TwoD,
|
| 233 |
+
dtypes=all_types_and_complex_and(torch.bool),
|
| 234 |
+
# CUDA supports Half/ComplexHalf Precision FFT only on SM53 or later archs
|
| 235 |
+
dtypesIfCUDA=all_types_and_complex_and(
|
| 236 |
+
torch.bool,
|
| 237 |
+
*(() if (not SM53OrLater) else (torch.half, torch.complex32)),
|
| 238 |
+
),
|
| 239 |
+
sample_inputs_func=partial(sample_inputs_fft_with_min, min_size=(2, 2)),
|
| 240 |
+
error_inputs_func=error_inputs_fftn,
|
| 241 |
+
# https://github.com/pytorch/pytorch/issues/80411
|
| 242 |
+
gradcheck_fast_mode=True,
|
| 243 |
+
supports_forward_ad=True,
|
| 244 |
+
supports_fwgrad_bwgrad=True,
|
| 245 |
+
check_batched_gradgrad=False,
|
| 246 |
+
# See https://github.com/pytorch/pytorch/pull/78358
|
| 247 |
+
check_batched_forward_grad=False,
|
| 248 |
+
decorators=[
|
| 249 |
+
DecorateInfo(
|
| 250 |
+
precisionOverride({torch.float: 2e-4, torch.cfloat: 2e-4}),
|
| 251 |
+
"TestFFT",
|
| 252 |
+
"test_reference_nd",
|
| 253 |
+
)
|
| 254 |
+
],
|
| 255 |
+
skips=(
|
| 256 |
+
# Issue with conj and torch dispatch, see https://github.com/pytorch/pytorch/issues/82479
|
| 257 |
+
DecorateInfo(
|
| 258 |
+
unittest.skip("Skipped!"),
|
| 259 |
+
"TestSchemaCheckModeOpInfo",
|
| 260 |
+
"test_schema_correctness",
|
| 261 |
+
),
|
| 262 |
+
),
|
| 263 |
+
),
|
| 264 |
+
SpectralFuncInfo(
|
| 265 |
+
"fft.hfftn",
|
| 266 |
+
aten_name="fft_hfftn",
|
| 267 |
+
decomp_aten_name="_fft_c2r",
|
| 268 |
+
ref=scipy.fft.hfftn if has_scipy_fft else None,
|
| 269 |
+
ndimensional=SpectralFuncType.ND,
|
| 270 |
+
dtypes=all_types_and_complex_and(torch.bool),
|
| 271 |
+
# CUDA supports Half/ComplexHalf Precision FFT only on SM53 or later archs
|
| 272 |
+
dtypesIfCUDA=all_types_and_complex_and(
|
| 273 |
+
torch.bool,
|
| 274 |
+
*(() if (not SM53OrLater) else (torch.half, torch.complex32)),
|
| 275 |
+
),
|
| 276 |
+
sample_inputs_func=partial(sample_inputs_fft_with_min, min_size=(2, 2)),
|
| 277 |
+
error_inputs_func=error_inputs_fftn,
|
| 278 |
+
# https://github.com/pytorch/pytorch/issues/80411
|
| 279 |
+
gradcheck_fast_mode=True,
|
| 280 |
+
supports_forward_ad=True,
|
| 281 |
+
supports_fwgrad_bwgrad=True,
|
| 282 |
+
check_batched_gradgrad=False,
|
| 283 |
+
# See https://github.com/pytorch/pytorch/pull/78358
|
| 284 |
+
check_batched_forward_grad=False,
|
| 285 |
+
decorators=[
|
| 286 |
+
DecorateInfo(
|
| 287 |
+
precisionOverride({torch.float: 2e-4, torch.cfloat: 2e-4}),
|
| 288 |
+
"TestFFT",
|
| 289 |
+
"test_reference_nd",
|
| 290 |
+
),
|
| 291 |
+
],
|
| 292 |
+
skips=(
|
| 293 |
+
# Issue with conj and torch dispatch, see https://github.com/pytorch/pytorch/issues/82479
|
| 294 |
+
DecorateInfo(
|
| 295 |
+
unittest.skip("Skipped!"),
|
| 296 |
+
"TestSchemaCheckModeOpInfo",
|
| 297 |
+
"test_schema_correctness",
|
| 298 |
+
),
|
| 299 |
+
),
|
| 300 |
+
),
|
| 301 |
+
SpectralFuncInfo(
|
| 302 |
+
"fft.rfft",
|
| 303 |
+
aten_name="fft_rfft",
|
| 304 |
+
decomp_aten_name="_fft_r2c",
|
| 305 |
+
ref=np.fft.rfft,
|
| 306 |
+
ndimensional=SpectralFuncType.OneD,
|
| 307 |
+
dtypes=all_types_and(torch.bool),
|
| 308 |
+
# CUDA supports Half/ComplexHalf Precision FFT only on SM53 or later archs
|
| 309 |
+
dtypesIfCUDA=all_types_and(
|
| 310 |
+
torch.bool, *(() if (not SM53OrLater) else (torch.half,))
|
| 311 |
+
),
|
| 312 |
+
sample_inputs_func=partial(sample_inputs_fft_with_min, min_size=1),
|
| 313 |
+
error_inputs_func=error_inputs_fft,
|
| 314 |
+
# https://github.com/pytorch/pytorch/issues/80411
|
| 315 |
+
gradcheck_fast_mode=True,
|
| 316 |
+
supports_forward_ad=True,
|
| 317 |
+
supports_fwgrad_bwgrad=True,
|
| 318 |
+
check_batched_grad=False,
|
| 319 |
+
skips=(),
|
| 320 |
+
check_batched_gradgrad=False,
|
| 321 |
+
),
|
| 322 |
+
SpectralFuncInfo(
|
| 323 |
+
"fft.rfft2",
|
| 324 |
+
aten_name="fft_rfft2",
|
| 325 |
+
decomp_aten_name="_fft_r2c",
|
| 326 |
+
ref=np.fft.rfft2,
|
| 327 |
+
ndimensional=SpectralFuncType.TwoD,
|
| 328 |
+
dtypes=all_types_and(torch.bool),
|
| 329 |
+
# CUDA supports Half/ComplexHalf Precision FFT only on SM53 or later archs
|
| 330 |
+
dtypesIfCUDA=all_types_and(
|
| 331 |
+
torch.bool, *(() if (not SM53OrLater) else (torch.half,))
|
| 332 |
+
),
|
| 333 |
+
sample_inputs_func=partial(sample_inputs_fft_with_min, min_size=(1, 1)),
|
| 334 |
+
error_inputs_func=error_inputs_fftn,
|
| 335 |
+
# https://github.com/pytorch/pytorch/issues/80411
|
| 336 |
+
gradcheck_fast_mode=True,
|
| 337 |
+
supports_forward_ad=True,
|
| 338 |
+
supports_fwgrad_bwgrad=True,
|
| 339 |
+
check_batched_grad=False,
|
| 340 |
+
check_batched_gradgrad=False,
|
| 341 |
+
decorators=[
|
| 342 |
+
precisionOverride({torch.float: 1e-4}),
|
| 343 |
+
],
|
| 344 |
+
),
|
| 345 |
+
SpectralFuncInfo(
|
| 346 |
+
"fft.rfftn",
|
| 347 |
+
aten_name="fft_rfftn",
|
| 348 |
+
decomp_aten_name="_fft_r2c",
|
| 349 |
+
ref=np.fft.rfftn,
|
| 350 |
+
ndimensional=SpectralFuncType.ND,
|
| 351 |
+
dtypes=all_types_and(torch.bool),
|
| 352 |
+
# CUDA supports Half/ComplexHalf Precision FFT only on SM53 or later archs
|
| 353 |
+
dtypesIfCUDA=all_types_and(
|
| 354 |
+
torch.bool, *(() if (not SM53OrLater) else (torch.half,))
|
| 355 |
+
),
|
| 356 |
+
sample_inputs_func=partial(sample_inputs_fft_with_min, min_size=(1, 1)),
|
| 357 |
+
error_inputs_func=error_inputs_fftn,
|
| 358 |
+
# https://github.com/pytorch/pytorch/issues/80411
|
| 359 |
+
gradcheck_fast_mode=True,
|
| 360 |
+
supports_forward_ad=True,
|
| 361 |
+
supports_fwgrad_bwgrad=True,
|
| 362 |
+
check_batched_grad=False,
|
| 363 |
+
check_batched_gradgrad=False,
|
| 364 |
+
decorators=[
|
| 365 |
+
precisionOverride({torch.float: 1e-4}),
|
| 366 |
+
],
|
| 367 |
+
),
|
| 368 |
+
SpectralFuncInfo(
|
| 369 |
+
"fft.ifft",
|
| 370 |
+
aten_name="fft_ifft",
|
| 371 |
+
decomp_aten_name="_fft_c2c",
|
| 372 |
+
ref=np.fft.ifft,
|
| 373 |
+
ndimensional=SpectralFuncType.OneD,
|
| 374 |
+
sample_inputs_func=partial(sample_inputs_fft_with_min, min_size=1),
|
| 375 |
+
error_inputs_func=error_inputs_fft,
|
| 376 |
+
# https://github.com/pytorch/pytorch/issues/80411
|
| 377 |
+
gradcheck_fast_mode=True,
|
| 378 |
+
supports_forward_ad=True,
|
| 379 |
+
supports_fwgrad_bwgrad=True,
|
| 380 |
+
# See https://github.com/pytorch/pytorch/pull/78358
|
| 381 |
+
check_batched_forward_grad=False,
|
| 382 |
+
dtypes=all_types_and_complex_and(torch.bool),
|
| 383 |
+
# CUDA supports Half/ComplexHalf Precision FFT only on SM53 or later archs
|
| 384 |
+
dtypesIfCUDA=all_types_and_complex_and(
|
| 385 |
+
torch.bool,
|
| 386 |
+
*(() if (not SM53OrLater) else (torch.half, torch.complex32)),
|
| 387 |
+
),
|
| 388 |
+
),
|
| 389 |
+
SpectralFuncInfo(
|
| 390 |
+
"fft.ifft2",
|
| 391 |
+
aten_name="fft_ifft2",
|
| 392 |
+
decomp_aten_name="_fft_c2c",
|
| 393 |
+
ref=np.fft.ifft2,
|
| 394 |
+
ndimensional=SpectralFuncType.TwoD,
|
| 395 |
+
sample_inputs_func=partial(sample_inputs_fft_with_min, min_size=(1, 1)),
|
| 396 |
+
error_inputs_func=error_inputs_fftn,
|
| 397 |
+
# https://github.com/pytorch/pytorch/issues/80411
|
| 398 |
+
gradcheck_fast_mode=True,
|
| 399 |
+
supports_forward_ad=True,
|
| 400 |
+
supports_fwgrad_bwgrad=True,
|
| 401 |
+
# See https://github.com/pytorch/pytorch/pull/78358
|
| 402 |
+
check_batched_forward_grad=False,
|
| 403 |
+
dtypes=all_types_and_complex_and(torch.bool),
|
| 404 |
+
# CUDA supports Half/ComplexHalf Precision FFT only on SM53 or later archs
|
| 405 |
+
dtypesIfCUDA=all_types_and_complex_and(
|
| 406 |
+
torch.bool,
|
| 407 |
+
*(() if (not SM53OrLater) else (torch.half, torch.complex32)),
|
| 408 |
+
),
|
| 409 |
+
decorators=[
|
| 410 |
+
DecorateInfo(
|
| 411 |
+
precisionOverride({torch.float: 1e-4, torch.cfloat: 1e-4}),
|
| 412 |
+
"TestFFT",
|
| 413 |
+
"test_reference_nd",
|
| 414 |
+
)
|
| 415 |
+
],
|
| 416 |
+
),
|
| 417 |
+
SpectralFuncInfo(
|
| 418 |
+
"fft.ifftn",
|
| 419 |
+
aten_name="fft_ifftn",
|
| 420 |
+
decomp_aten_name="_fft_c2c",
|
| 421 |
+
ref=np.fft.ifftn,
|
| 422 |
+
ndimensional=SpectralFuncType.ND,
|
| 423 |
+
sample_inputs_func=partial(sample_inputs_fft_with_min, min_size=(1, 1)),
|
| 424 |
+
error_inputs_func=error_inputs_fftn,
|
| 425 |
+
# https://github.com/pytorch/pytorch/issues/80411
|
| 426 |
+
gradcheck_fast_mode=True,
|
| 427 |
+
supports_forward_ad=True,
|
| 428 |
+
supports_fwgrad_bwgrad=True,
|
| 429 |
+
# See https://github.com/pytorch/pytorch/pull/78358
|
| 430 |
+
check_batched_forward_grad=False,
|
| 431 |
+
dtypes=all_types_and_complex_and(torch.bool),
|
| 432 |
+
# CUDA supports Half/ComplexHalf Precision FFT only on SM53 or later archs
|
| 433 |
+
dtypesIfCUDA=all_types_and_complex_and(
|
| 434 |
+
torch.bool,
|
| 435 |
+
*(() if (not SM53OrLater) else (torch.half, torch.complex32)),
|
| 436 |
+
),
|
| 437 |
+
decorators=[
|
| 438 |
+
DecorateInfo(
|
| 439 |
+
precisionOverride({torch.float: 1e-4, torch.cfloat: 1e-4}),
|
| 440 |
+
"TestFFT",
|
| 441 |
+
"test_reference_nd",
|
| 442 |
+
)
|
| 443 |
+
],
|
| 444 |
+
),
|
| 445 |
+
SpectralFuncInfo(
|
| 446 |
+
"fft.ihfft",
|
| 447 |
+
aten_name="fft_ihfft",
|
| 448 |
+
decomp_aten_name="_fft_r2c",
|
| 449 |
+
ref=np.fft.ihfft,
|
| 450 |
+
ndimensional=SpectralFuncType.OneD,
|
| 451 |
+
sample_inputs_func=partial(sample_inputs_fft_with_min, min_size=(1, 1)),
|
| 452 |
+
error_inputs_func=error_inputs_fft,
|
| 453 |
+
supports_forward_ad=True,
|
| 454 |
+
supports_fwgrad_bwgrad=True,
|
| 455 |
+
# See https://github.com/pytorch/pytorch/pull/78358
|
| 456 |
+
check_batched_forward_grad=False,
|
| 457 |
+
dtypes=all_types_and(torch.bool),
|
| 458 |
+
# CUDA supports Half/ComplexHalf Precision FFT only on SM53 or later archs
|
| 459 |
+
dtypesIfCUDA=all_types_and(
|
| 460 |
+
torch.bool, *(() if (not SM53OrLater) else (torch.half,))
|
| 461 |
+
),
|
| 462 |
+
skips=(),
|
| 463 |
+
check_batched_grad=False,
|
| 464 |
+
),
|
| 465 |
+
SpectralFuncInfo(
|
| 466 |
+
"fft.ihfft2",
|
| 467 |
+
aten_name="fft_ihfft2",
|
| 468 |
+
decomp_aten_name="_fft_r2c",
|
| 469 |
+
ref=scipy.fft.ihfftn if has_scipy_fft else None,
|
| 470 |
+
ndimensional=SpectralFuncType.TwoD,
|
| 471 |
+
sample_inputs_func=partial(sample_inputs_fft_with_min, min_size=(1, 1)),
|
| 472 |
+
error_inputs_func=error_inputs_fftn,
|
| 473 |
+
# https://github.com/pytorch/pytorch/issues/80411
|
| 474 |
+
gradcheck_fast_mode=True,
|
| 475 |
+
supports_forward_ad=True,
|
| 476 |
+
supports_fwgrad_bwgrad=True,
|
| 477 |
+
# See https://github.com/pytorch/pytorch/pull/78358
|
| 478 |
+
check_batched_forward_grad=False,
|
| 479 |
+
dtypes=all_types_and(torch.bool),
|
| 480 |
+
# CUDA supports Half/ComplexHalf Precision FFT only on SM53 or later archs
|
| 481 |
+
dtypesIfCUDA=all_types_and(
|
| 482 |
+
torch.bool, *(() if (not SM53OrLater) else (torch.half,))
|
| 483 |
+
),
|
| 484 |
+
check_batched_grad=False,
|
| 485 |
+
check_batched_gradgrad=False,
|
| 486 |
+
decorators=(
|
| 487 |
+
# The values for attribute 'shape' do not match: torch.Size([5, 6, 5]) != torch.Size([5, 6, 6]).
|
| 488 |
+
DecorateInfo(unittest.expectedFailure, "TestCommon", "test_out_warning"),
|
| 489 |
+
DecorateInfo(
|
| 490 |
+
precisionOverride({torch.float: 2e-4}), "TestFFT", "test_reference_nd"
|
| 491 |
+
),
|
| 492 |
+
# Mismatched elements!
|
| 493 |
+
DecorateInfo(unittest.expectedFailure, "TestCommon", "test_out"),
|
| 494 |
+
DecorateInfo(unittest.expectedFailure, "TestCommon", "test_out_warnings"),
|
| 495 |
+
),
|
| 496 |
+
),
|
| 497 |
+
SpectralFuncInfo(
|
| 498 |
+
"fft.ihfftn",
|
| 499 |
+
aten_name="fft_ihfftn",
|
| 500 |
+
decomp_aten_name="_fft_r2c",
|
| 501 |
+
ref=scipy.fft.ihfftn if has_scipy_fft else None,
|
| 502 |
+
ndimensional=SpectralFuncType.ND,
|
| 503 |
+
sample_inputs_func=partial(sample_inputs_fft_with_min, min_size=(1, 1)),
|
| 504 |
+
error_inputs_func=error_inputs_fftn,
|
| 505 |
+
# https://github.com/pytorch/pytorch/issues/80411
|
| 506 |
+
gradcheck_fast_mode=True,
|
| 507 |
+
supports_forward_ad=True,
|
| 508 |
+
supports_fwgrad_bwgrad=True,
|
| 509 |
+
# See https://github.com/pytorch/pytorch/pull/78358
|
| 510 |
+
check_batched_forward_grad=False,
|
| 511 |
+
dtypes=all_types_and(torch.bool),
|
| 512 |
+
# CUDA supports Half/ComplexHalf Precision FFT only on SM53 or later archss
|
| 513 |
+
dtypesIfCUDA=all_types_and(
|
| 514 |
+
torch.bool, *(() if (not SM53OrLater) else (torch.half,))
|
| 515 |
+
),
|
| 516 |
+
check_batched_grad=False,
|
| 517 |
+
check_batched_gradgrad=False,
|
| 518 |
+
decorators=[
|
| 519 |
+
# The values for attribute 'shape' do not match: torch.Size([5, 6, 5]) != torch.Size([5, 6, 6]).
|
| 520 |
+
DecorateInfo(unittest.expectedFailure, "TestCommon", "test_out_warning"),
|
| 521 |
+
# Mismatched elements!
|
| 522 |
+
DecorateInfo(unittest.expectedFailure, "TestCommon", "test_out"),
|
| 523 |
+
DecorateInfo(
|
| 524 |
+
precisionOverride({torch.float: 2e-4}), "TestFFT", "test_reference_nd"
|
| 525 |
+
),
|
| 526 |
+
],
|
| 527 |
+
),
|
| 528 |
+
SpectralFuncInfo(
|
| 529 |
+
"fft.irfft",
|
| 530 |
+
aten_name="fft_irfft",
|
| 531 |
+
decomp_aten_name="_fft_c2r",
|
| 532 |
+
ref=np.fft.irfft,
|
| 533 |
+
ndimensional=SpectralFuncType.OneD,
|
| 534 |
+
sample_inputs_func=partial(sample_inputs_fft_with_min, min_size=(1, 2)),
|
| 535 |
+
error_inputs_func=error_inputs_fft,
|
| 536 |
+
# https://github.com/pytorch/pytorch/issues/80411
|
| 537 |
+
gradcheck_fast_mode=True,
|
| 538 |
+
supports_forward_ad=True,
|
| 539 |
+
supports_fwgrad_bwgrad=True,
|
| 540 |
+
# See https://github.com/pytorch/pytorch/pull/78358
|
| 541 |
+
check_batched_forward_grad=False,
|
| 542 |
+
dtypes=all_types_and_complex_and(torch.bool),
|
| 543 |
+
# CUDA supports Half/ComplexHalf Precision FFT only on SM53 or later archs
|
| 544 |
+
dtypesIfCUDA=all_types_and_complex_and(
|
| 545 |
+
torch.bool,
|
| 546 |
+
*(() if (not SM53OrLater) else (torch.half, torch.complex32)),
|
| 547 |
+
),
|
| 548 |
+
check_batched_gradgrad=False,
|
| 549 |
+
),
|
| 550 |
+
SpectralFuncInfo(
|
| 551 |
+
"fft.irfft2",
|
| 552 |
+
aten_name="fft_irfft2",
|
| 553 |
+
decomp_aten_name="_fft_c2r",
|
| 554 |
+
ref=np.fft.irfft2,
|
| 555 |
+
ndimensional=SpectralFuncType.TwoD,
|
| 556 |
+
sample_inputs_func=partial(sample_inputs_fft_with_min, min_size=(1, 2)),
|
| 557 |
+
error_inputs_func=error_inputs_fftn,
|
| 558 |
+
# https://github.com/pytorch/pytorch/issues/80411
|
| 559 |
+
gradcheck_fast_mode=True,
|
| 560 |
+
supports_forward_ad=True,
|
| 561 |
+
supports_fwgrad_bwgrad=True,
|
| 562 |
+
# See https://github.com/pytorch/pytorch/pull/78358
|
| 563 |
+
check_batched_forward_grad=False,
|
| 564 |
+
dtypes=all_types_and_complex_and(torch.bool),
|
| 565 |
+
# CUDA supports Half/ComplexHalf Precision FFT only on SM53 or later archs
|
| 566 |
+
dtypesIfCUDA=all_types_and_complex_and(
|
| 567 |
+
torch.bool,
|
| 568 |
+
*(() if (not SM53OrLater) else (torch.half, torch.complex32)),
|
| 569 |
+
),
|
| 570 |
+
check_batched_gradgrad=False,
|
| 571 |
+
decorators=[
|
| 572 |
+
DecorateInfo(
|
| 573 |
+
precisionOverride({torch.float: 1e-4, torch.cfloat: 1e-4}),
|
| 574 |
+
"TestFFT",
|
| 575 |
+
"test_reference_nd",
|
| 576 |
+
)
|
| 577 |
+
],
|
| 578 |
+
),
|
| 579 |
+
SpectralFuncInfo(
|
| 580 |
+
"fft.irfftn",
|
| 581 |
+
aten_name="fft_irfftn",
|
| 582 |
+
decomp_aten_name="_fft_c2r",
|
| 583 |
+
ref=np.fft.irfftn,
|
| 584 |
+
ndimensional=SpectralFuncType.ND,
|
| 585 |
+
sample_inputs_func=partial(sample_inputs_fft_with_min, min_size=(1, 2)),
|
| 586 |
+
error_inputs_func=error_inputs_fftn,
|
| 587 |
+
# https://github.com/pytorch/pytorch/issues/80411
|
| 588 |
+
gradcheck_fast_mode=True,
|
| 589 |
+
supports_forward_ad=True,
|
| 590 |
+
supports_fwgrad_bwgrad=True,
|
| 591 |
+
# See https://github.com/pytorch/pytorch/pull/78358
|
| 592 |
+
check_batched_forward_grad=False,
|
| 593 |
+
dtypes=all_types_and_complex_and(torch.bool),
|
| 594 |
+
# CUDA supports Half/ComplexHalf Precision FFT only on SM53 or later archs
|
| 595 |
+
dtypesIfCUDA=all_types_and_complex_and(
|
| 596 |
+
torch.bool,
|
| 597 |
+
*(() if (not SM53OrLater) else (torch.half, torch.complex32)),
|
| 598 |
+
),
|
| 599 |
+
check_batched_gradgrad=False,
|
| 600 |
+
decorators=[
|
| 601 |
+
DecorateInfo(
|
| 602 |
+
precisionOverride({torch.float: 1e-4, torch.cfloat: 1e-4}),
|
| 603 |
+
"TestFFT",
|
| 604 |
+
"test_reference_nd",
|
| 605 |
+
)
|
| 606 |
+
],
|
| 607 |
+
),
|
| 608 |
+
OpInfo(
|
| 609 |
+
"fft.fftshift",
|
| 610 |
+
dtypes=all_types_and_complex_and(
|
| 611 |
+
torch.bool, torch.bfloat16, torch.half, torch.chalf
|
| 612 |
+
),
|
| 613 |
+
sample_inputs_func=sample_inputs_fftshift,
|
| 614 |
+
supports_out=False,
|
| 615 |
+
supports_forward_ad=True,
|
| 616 |
+
supports_fwgrad_bwgrad=True,
|
| 617 |
+
),
|
| 618 |
+
OpInfo(
|
| 619 |
+
"fft.ifftshift",
|
| 620 |
+
dtypes=all_types_and_complex_and(
|
| 621 |
+
torch.bool, torch.bfloat16, torch.half, torch.chalf
|
| 622 |
+
),
|
| 623 |
+
sample_inputs_func=sample_inputs_fftshift,
|
| 624 |
+
supports_out=False,
|
| 625 |
+
supports_forward_ad=True,
|
| 626 |
+
supports_fwgrad_bwgrad=True,
|
| 627 |
+
),
|
| 628 |
+
]
|
| 629 |
+
|
| 630 |
+
python_ref_db: List[OpInfo] = [
|
| 631 |
+
SpectralFuncPythonRefInfo(
|
| 632 |
+
"_refs.fft.fft",
|
| 633 |
+
torch_opinfo_name="fft.fft",
|
| 634 |
+
),
|
| 635 |
+
SpectralFuncPythonRefInfo(
|
| 636 |
+
"_refs.fft.ifft",
|
| 637 |
+
torch_opinfo_name="fft.ifft",
|
| 638 |
+
),
|
| 639 |
+
SpectralFuncPythonRefInfo(
|
| 640 |
+
"_refs.fft.rfft",
|
| 641 |
+
torch_opinfo_name="fft.rfft",
|
| 642 |
+
),
|
| 643 |
+
SpectralFuncPythonRefInfo(
|
| 644 |
+
"_refs.fft.irfft",
|
| 645 |
+
torch_opinfo_name="fft.irfft",
|
| 646 |
+
),
|
| 647 |
+
SpectralFuncPythonRefInfo(
|
| 648 |
+
"_refs.fft.hfft",
|
| 649 |
+
torch_opinfo_name="fft.hfft",
|
| 650 |
+
),
|
| 651 |
+
SpectralFuncPythonRefInfo(
|
| 652 |
+
"_refs.fft.ihfft",
|
| 653 |
+
torch_opinfo_name="fft.ihfft",
|
| 654 |
+
),
|
| 655 |
+
SpectralFuncPythonRefInfo(
|
| 656 |
+
"_refs.fft.fftn",
|
| 657 |
+
torch_opinfo_name="fft.fftn",
|
| 658 |
+
decorators=[
|
| 659 |
+
DecorateInfo(
|
| 660 |
+
precisionOverride({torch.float: 1e-4, torch.cfloat: 1e-4}),
|
| 661 |
+
"TestFFT",
|
| 662 |
+
"test_reference_nd",
|
| 663 |
+
)
|
| 664 |
+
],
|
| 665 |
+
),
|
| 666 |
+
SpectralFuncPythonRefInfo(
|
| 667 |
+
"_refs.fft.ifftn",
|
| 668 |
+
torch_opinfo_name="fft.ifftn",
|
| 669 |
+
decorators=[
|
| 670 |
+
DecorateInfo(
|
| 671 |
+
precisionOverride({torch.float: 1e-4, torch.cfloat: 1e-4}),
|
| 672 |
+
"TestFFT",
|
| 673 |
+
"test_reference_nd",
|
| 674 |
+
)
|
| 675 |
+
],
|
| 676 |
+
),
|
| 677 |
+
SpectralFuncPythonRefInfo(
|
| 678 |
+
"_refs.fft.rfftn",
|
| 679 |
+
torch_opinfo_name="fft.rfftn",
|
| 680 |
+
),
|
| 681 |
+
SpectralFuncPythonRefInfo(
|
| 682 |
+
"_refs.fft.irfftn",
|
| 683 |
+
torch_opinfo_name="fft.irfftn",
|
| 684 |
+
decorators=[
|
| 685 |
+
DecorateInfo(
|
| 686 |
+
precisionOverride({torch.float: 1e-4, torch.cfloat: 1e-4}),
|
| 687 |
+
"TestFFT",
|
| 688 |
+
"test_reference_nd",
|
| 689 |
+
)
|
| 690 |
+
],
|
| 691 |
+
),
|
| 692 |
+
SpectralFuncPythonRefInfo(
|
| 693 |
+
"_refs.fft.hfftn",
|
| 694 |
+
torch_opinfo_name="fft.hfftn",
|
| 695 |
+
decorators=[
|
| 696 |
+
DecorateInfo(
|
| 697 |
+
precisionOverride({torch.float: 2e-4, torch.cfloat: 2e-4}),
|
| 698 |
+
"TestFFT",
|
| 699 |
+
"test_reference_nd",
|
| 700 |
+
)
|
| 701 |
+
],
|
| 702 |
+
),
|
| 703 |
+
SpectralFuncPythonRefInfo(
|
| 704 |
+
"_refs.fft.ihfftn",
|
| 705 |
+
torch_opinfo_name="fft.ihfftn",
|
| 706 |
+
decorators=[
|
| 707 |
+
DecorateInfo(
|
| 708 |
+
precisionOverride({torch.float: 2e-4}),
|
| 709 |
+
"TestFFT",
|
| 710 |
+
"test_reference_nd",
|
| 711 |
+
)
|
| 712 |
+
],
|
| 713 |
+
),
|
| 714 |
+
SpectralFuncPythonRefInfo(
|
| 715 |
+
"_refs.fft.fft2",
|
| 716 |
+
torch_opinfo_name="fft.fft2",
|
| 717 |
+
),
|
| 718 |
+
SpectralFuncPythonRefInfo(
|
| 719 |
+
"_refs.fft.ifft2",
|
| 720 |
+
torch_opinfo_name="fft.ifft2",
|
| 721 |
+
decorators=[
|
| 722 |
+
DecorateInfo(
|
| 723 |
+
precisionOverride({torch.float: 1e-4, torch.cfloat: 1e-4}),
|
| 724 |
+
"TestFFT",
|
| 725 |
+
"test_reference_nd",
|
| 726 |
+
)
|
| 727 |
+
],
|
| 728 |
+
),
|
| 729 |
+
SpectralFuncPythonRefInfo(
|
| 730 |
+
"_refs.fft.rfft2",
|
| 731 |
+
torch_opinfo_name="fft.rfft2",
|
| 732 |
+
),
|
| 733 |
+
SpectralFuncPythonRefInfo(
|
| 734 |
+
"_refs.fft.irfft2",
|
| 735 |
+
torch_opinfo_name="fft.irfft2",
|
| 736 |
+
decorators=[
|
| 737 |
+
DecorateInfo(
|
| 738 |
+
precisionOverride({torch.float: 1e-4, torch.cfloat: 1e-4}),
|
| 739 |
+
"TestFFT",
|
| 740 |
+
"test_reference_nd",
|
| 741 |
+
)
|
| 742 |
+
],
|
| 743 |
+
),
|
| 744 |
+
SpectralFuncPythonRefInfo(
|
| 745 |
+
"_refs.fft.hfft2",
|
| 746 |
+
torch_opinfo_name="fft.hfft2",
|
| 747 |
+
decorators=[
|
| 748 |
+
DecorateInfo(
|
| 749 |
+
precisionOverride({torch.float: 2e-4, torch.cfloat: 2e-4}),
|
| 750 |
+
"TestFFT",
|
| 751 |
+
"test_reference_nd",
|
| 752 |
+
)
|
| 753 |
+
],
|
| 754 |
+
),
|
| 755 |
+
SpectralFuncPythonRefInfo(
|
| 756 |
+
"_refs.fft.ihfft2",
|
| 757 |
+
torch_opinfo_name="fft.ihfft2",
|
| 758 |
+
decorators=[
|
| 759 |
+
DecorateInfo(
|
| 760 |
+
precisionOverride({torch.float: 2e-4}),
|
| 761 |
+
"TestFFT",
|
| 762 |
+
"test_reference_nd",
|
| 763 |
+
)
|
| 764 |
+
],
|
| 765 |
+
),
|
| 766 |
+
PythonRefInfo(
|
| 767 |
+
"_refs.fft.fftshift",
|
| 768 |
+
op_db=op_db,
|
| 769 |
+
torch_opinfo_name="fft.fftshift",
|
| 770 |
+
skips=(
|
| 771 |
+
# TODO Move fftshift to decomps
|
| 772 |
+
DecorateInfo(unittest.expectedFailure, "TestCommon", "test_python_ref"),
|
| 773 |
+
),
|
| 774 |
+
),
|
| 775 |
+
PythonRefInfo(
|
| 776 |
+
"_refs.fft.ifftshift",
|
| 777 |
+
op_db=op_db,
|
| 778 |
+
torch_opinfo_name="fft.ifftshift",
|
| 779 |
+
skips=(
|
| 780 |
+
# TODO Move ifftshift to decomps
|
| 781 |
+
DecorateInfo(unittest.expectedFailure, "TestCommon", "test_python_ref"),
|
| 782 |
+
),
|
| 783 |
+
),
|
| 784 |
+
]
|
shared/package-files/65/655d1425c4b6f9025d86a0eeec8fe7bc3f85f7c0446176dcfc5614cadea7cd15/blob
ADDED
|
@@ -0,0 +1,321 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <c10/util/Optional.h>
|
| 4 |
+
#include <c10/util/string_view.h>
|
| 5 |
+
#include <ATen/Config.h>
|
| 6 |
+
#include <ATen/native/DispatchStub.h>
|
| 7 |
+
|
| 8 |
+
// Forward declare TI
|
| 9 |
+
namespace at {
|
| 10 |
+
class Tensor;
|
| 11 |
+
struct TensorIterator;
|
| 12 |
+
|
| 13 |
+
namespace native {
|
| 14 |
+
enum class TransposeType;
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
namespace at::native {
|
| 20 |
+
|
| 21 |
+
enum class LapackLstsqDriverType : int64_t { Gels, Gelsd, Gelsy, Gelss};
|
| 22 |
+
|
| 23 |
+
#if AT_BUILD_WITH_LAPACK()
|
| 24 |
+
// Define per-batch functions to be used in the implementation of batched
|
| 25 |
+
// linear algebra operations
|
| 26 |
+
|
| 27 |
+
template <class scalar_t>
|
| 28 |
+
void lapackCholesky(char uplo, int n, scalar_t *a, int lda, int *info);
|
| 29 |
+
|
| 30 |
+
template <class scalar_t>
|
| 31 |
+
void lapackCholeskyInverse(char uplo, int n, scalar_t *a, int lda, int *info);
|
| 32 |
+
|
| 33 |
+
template <class scalar_t, class value_t=scalar_t>
|
| 34 |
+
void lapackEig(char jobvl, char jobvr, int n, scalar_t *a, int lda, scalar_t *w, scalar_t* vl, int ldvl, scalar_t *vr, int ldvr, scalar_t *work, int lwork, value_t *rwork, int *info);
|
| 35 |
+
|
| 36 |
+
template <class scalar_t>
|
| 37 |
+
void lapackGeqrf(int m, int n, scalar_t *a, int lda, scalar_t *tau, scalar_t *work, int lwork, int *info);
|
| 38 |
+
|
| 39 |
+
template <class scalar_t>
|
| 40 |
+
void lapackOrgqr(int m, int n, int k, scalar_t *a, int lda, scalar_t *tau, scalar_t *work, int lwork, int *info);
|
| 41 |
+
|
| 42 |
+
template <class scalar_t>
|
| 43 |
+
void lapackOrmqr(char side, char trans, int m, int n, int k, scalar_t *a, int lda, scalar_t *tau, scalar_t *c, int ldc, scalar_t *work, int lwork, int *info);
|
| 44 |
+
|
| 45 |
+
template <class scalar_t, class value_t = scalar_t>
|
| 46 |
+
void lapackSyevd(char jobz, char uplo, int n, scalar_t* a, int lda, value_t* w, scalar_t* work, int lwork, value_t* rwork, int lrwork, int* iwork, int liwork, int* info);
|
| 47 |
+
|
| 48 |
+
template <class scalar_t>
|
| 49 |
+
void lapackGels(char trans, int m, int n, int nrhs,
|
| 50 |
+
scalar_t *a, int lda, scalar_t *b, int ldb,
|
| 51 |
+
scalar_t *work, int lwork, int *info);
|
| 52 |
+
|
| 53 |
+
template <class scalar_t, class value_t = scalar_t>
|
| 54 |
+
void lapackGelsd(int m, int n, int nrhs,
|
| 55 |
+
scalar_t *a, int lda, scalar_t *b, int ldb,
|
| 56 |
+
value_t *s, value_t rcond, int *rank,
|
| 57 |
+
scalar_t* work, int lwork,
|
| 58 |
+
value_t *rwork, int* iwork, int *info);
|
| 59 |
+
|
| 60 |
+
template <class scalar_t, class value_t = scalar_t>
|
| 61 |
+
void lapackGelsy(int m, int n, int nrhs,
|
| 62 |
+
scalar_t *a, int lda, scalar_t *b, int ldb,
|
| 63 |
+
int *jpvt, value_t rcond, int *rank,
|
| 64 |
+
scalar_t *work, int lwork, value_t* rwork, int *info);
|
| 65 |
+
|
| 66 |
+
template <class scalar_t, class value_t = scalar_t>
|
| 67 |
+
void lapackGelss(int m, int n, int nrhs,
|
| 68 |
+
scalar_t *a, int lda, scalar_t *b, int ldb,
|
| 69 |
+
value_t *s, value_t rcond, int *rank,
|
| 70 |
+
scalar_t *work, int lwork,
|
| 71 |
+
value_t *rwork, int *info);
|
| 72 |
+
|
| 73 |
+
template <LapackLstsqDriverType, class scalar_t, class value_t = scalar_t>
|
| 74 |
+
struct lapackLstsq_impl;
|
| 75 |
+
|
| 76 |
+
template <class scalar_t, class value_t>
|
| 77 |
+
struct lapackLstsq_impl<LapackLstsqDriverType::Gels, scalar_t, value_t> {
|
| 78 |
+
static void call(
|
| 79 |
+
char trans, int m, int n, int nrhs,
|
| 80 |
+
scalar_t *a, int lda, scalar_t *b, int ldb,
|
| 81 |
+
scalar_t *work, int lwork, int *info, // Gels flavor
|
| 82 |
+
int *jpvt, value_t rcond, int *rank, value_t* rwork, // Gelsy flavor
|
| 83 |
+
value_t *s, // Gelss flavor
|
| 84 |
+
int *iwork // Gelsd flavor
|
| 85 |
+
) {
|
| 86 |
+
lapackGels<scalar_t>(
|
| 87 |
+
trans, m, n, nrhs,
|
| 88 |
+
a, lda, b, ldb,
|
| 89 |
+
work, lwork, info);
|
| 90 |
+
}
|
| 91 |
+
};
|
| 92 |
+
|
| 93 |
+
template <class scalar_t, class value_t>
|
| 94 |
+
struct lapackLstsq_impl<LapackLstsqDriverType::Gelsy, scalar_t, value_t> {
|
| 95 |
+
static void call(
|
| 96 |
+
char trans, int m, int n, int nrhs,
|
| 97 |
+
scalar_t *a, int lda, scalar_t *b, int ldb,
|
| 98 |
+
scalar_t *work, int lwork, int *info, // Gels flavor
|
| 99 |
+
int *jpvt, value_t rcond, int *rank, value_t* rwork, // Gelsy flavor
|
| 100 |
+
value_t *s, // Gelss flavor
|
| 101 |
+
int *iwork // Gelsd flavor
|
| 102 |
+
) {
|
| 103 |
+
lapackGelsy<scalar_t, value_t>(
|
| 104 |
+
m, n, nrhs,
|
| 105 |
+
a, lda, b, ldb,
|
| 106 |
+
jpvt, rcond, rank,
|
| 107 |
+
work, lwork, rwork, info);
|
| 108 |
+
}
|
| 109 |
+
};
|
| 110 |
+
|
| 111 |
+
template <class scalar_t, class value_t>
|
| 112 |
+
struct lapackLstsq_impl<LapackLstsqDriverType::Gelsd, scalar_t, value_t> {
|
| 113 |
+
static void call(
|
| 114 |
+
char trans, int m, int n, int nrhs,
|
| 115 |
+
scalar_t *a, int lda, scalar_t *b, int ldb,
|
| 116 |
+
scalar_t *work, int lwork, int *info, // Gels flavor
|
| 117 |
+
int *jpvt, value_t rcond, int *rank, value_t* rwork, // Gelsy flavor
|
| 118 |
+
value_t *s, // Gelss flavor
|
| 119 |
+
int *iwork // Gelsd flavor
|
| 120 |
+
) {
|
| 121 |
+
lapackGelsd<scalar_t, value_t>(
|
| 122 |
+
m, n, nrhs,
|
| 123 |
+
a, lda, b, ldb,
|
| 124 |
+
s, rcond, rank,
|
| 125 |
+
work, lwork,
|
| 126 |
+
rwork, iwork, info);
|
| 127 |
+
}
|
| 128 |
+
};
|
| 129 |
+
|
| 130 |
+
template <class scalar_t, class value_t>
|
| 131 |
+
struct lapackLstsq_impl<LapackLstsqDriverType::Gelss, scalar_t, value_t> {
|
| 132 |
+
static void call(
|
| 133 |
+
char trans, int m, int n, int nrhs,
|
| 134 |
+
scalar_t *a, int lda, scalar_t *b, int ldb,
|
| 135 |
+
scalar_t *work, int lwork, int *info, // Gels flavor
|
| 136 |
+
int *jpvt, value_t rcond, int *rank, value_t* rwork, // Gelsy flavor
|
| 137 |
+
value_t *s, // Gelss flavor
|
| 138 |
+
int *iwork // Gelsd flavor
|
| 139 |
+
) {
|
| 140 |
+
lapackGelss<scalar_t, value_t>(
|
| 141 |
+
m, n, nrhs,
|
| 142 |
+
a, lda, b, ldb,
|
| 143 |
+
s, rcond, rank,
|
| 144 |
+
work, lwork,
|
| 145 |
+
rwork, info);
|
| 146 |
+
}
|
| 147 |
+
};
|
| 148 |
+
|
| 149 |
+
template <LapackLstsqDriverType driver_type, class scalar_t, class value_t = scalar_t>
|
| 150 |
+
void lapackLstsq(
|
| 151 |
+
char trans, int m, int n, int nrhs,
|
| 152 |
+
scalar_t *a, int lda, scalar_t *b, int ldb,
|
| 153 |
+
scalar_t *work, int lwork, int *info, // Gels flavor
|
| 154 |
+
int *jpvt, value_t rcond, int *rank, value_t* rwork, // Gelsy flavor
|
| 155 |
+
value_t *s, // Gelss flavor
|
| 156 |
+
int *iwork // Gelsd flavor
|
| 157 |
+
) {
|
| 158 |
+
lapackLstsq_impl<driver_type, scalar_t, value_t>::call(
|
| 159 |
+
trans, m, n, nrhs,
|
| 160 |
+
a, lda, b, ldb,
|
| 161 |
+
work, lwork, info,
|
| 162 |
+
jpvt, rcond, rank, rwork,
|
| 163 |
+
s,
|
| 164 |
+
iwork);
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
template <class scalar_t>
|
| 168 |
+
void lapackLuSolve(char trans, int n, int nrhs, scalar_t *a, int lda, int *ipiv, scalar_t *b, int ldb, int *info);
|
| 169 |
+
|
| 170 |
+
template <class scalar_t>
|
| 171 |
+
void lapackLu(int m, int n, scalar_t *a, int lda, int *ipiv, int *info);
|
| 172 |
+
|
| 173 |
+
template <class scalar_t>
|
| 174 |
+
void lapackLdlHermitian(
|
| 175 |
+
char uplo,
|
| 176 |
+
int n,
|
| 177 |
+
scalar_t* a,
|
| 178 |
+
int lda,
|
| 179 |
+
int* ipiv,
|
| 180 |
+
scalar_t* work,
|
| 181 |
+
int lwork,
|
| 182 |
+
int* info);
|
| 183 |
+
|
| 184 |
+
template <class scalar_t>
|
| 185 |
+
void lapackLdlSymmetric(
|
| 186 |
+
char uplo,
|
| 187 |
+
int n,
|
| 188 |
+
scalar_t* a,
|
| 189 |
+
int lda,
|
| 190 |
+
int* ipiv,
|
| 191 |
+
scalar_t* work,
|
| 192 |
+
int lwork,
|
| 193 |
+
int* info);
|
| 194 |
+
|
| 195 |
+
template <class scalar_t>
|
| 196 |
+
void lapackLdlSolveHermitian(
|
| 197 |
+
char uplo,
|
| 198 |
+
int n,
|
| 199 |
+
int nrhs,
|
| 200 |
+
scalar_t* a,
|
| 201 |
+
int lda,
|
| 202 |
+
int* ipiv,
|
| 203 |
+
scalar_t* b,
|
| 204 |
+
int ldb,
|
| 205 |
+
int* info);
|
| 206 |
+
|
| 207 |
+
template <class scalar_t>
|
| 208 |
+
void lapackLdlSolveSymmetric(
|
| 209 |
+
char uplo,
|
| 210 |
+
int n,
|
| 211 |
+
int nrhs,
|
| 212 |
+
scalar_t* a,
|
| 213 |
+
int lda,
|
| 214 |
+
int* ipiv,
|
| 215 |
+
scalar_t* b,
|
| 216 |
+
int ldb,
|
| 217 |
+
int* info);
|
| 218 |
+
|
| 219 |
+
template<class scalar_t, class value_t=scalar_t>
|
| 220 |
+
void lapackSvd(char jobz, int m, int n, scalar_t *a, int lda, value_t *s, scalar_t *u, int ldu, scalar_t *vt, int ldvt, scalar_t *work, int lwork, value_t *rwork, int *iwork, int *info);
|
| 221 |
+
#endif
|
| 222 |
+
|
| 223 |
+
#if AT_BUILD_WITH_BLAS()
|
| 224 |
+
template <class scalar_t>
|
| 225 |
+
void blasTriangularSolve(char side, char uplo, char trans, char diag, int n, int nrhs, scalar_t* a, int lda, scalar_t* b, int ldb);
|
| 226 |
+
#endif
|
| 227 |
+
|
| 228 |
+
using cholesky_fn = void (*)(const Tensor& /*input*/, const Tensor& /*info*/, bool /*upper*/);
|
| 229 |
+
DECLARE_DISPATCH(cholesky_fn, cholesky_stub);
|
| 230 |
+
|
| 231 |
+
using cholesky_inverse_fn = Tensor& (*)(Tensor& /*result*/, Tensor& /*infos*/, bool /*upper*/);
|
| 232 |
+
|
| 233 |
+
DECLARE_DISPATCH(cholesky_inverse_fn, cholesky_inverse_stub);
|
| 234 |
+
|
| 235 |
+
using linalg_eig_fn = void (*)(Tensor& /*eigenvalues*/, Tensor& /*eigenvectors*/, Tensor& /*infos*/, const Tensor& /*input*/, bool /*compute_eigenvectors*/);
|
| 236 |
+
|
| 237 |
+
DECLARE_DISPATCH(linalg_eig_fn, linalg_eig_stub);
|
| 238 |
+
|
| 239 |
+
using geqrf_fn = void (*)(const Tensor& /*input*/, const Tensor& /*tau*/);
|
| 240 |
+
DECLARE_DISPATCH(geqrf_fn, geqrf_stub);
|
| 241 |
+
|
| 242 |
+
using orgqr_fn = Tensor& (*)(Tensor& /*result*/, const Tensor& /*tau*/);
|
| 243 |
+
DECLARE_DISPATCH(orgqr_fn, orgqr_stub);
|
| 244 |
+
|
| 245 |
+
using ormqr_fn = void (*)(const Tensor& /*input*/, const Tensor& /*tau*/, const Tensor& /*other*/, bool /*left*/, bool /*transpose*/);
|
| 246 |
+
DECLARE_DISPATCH(ormqr_fn, ormqr_stub);
|
| 247 |
+
|
| 248 |
+
using linalg_eigh_fn = void (*)(
|
| 249 |
+
const Tensor& /*eigenvalues*/,
|
| 250 |
+
const Tensor& /*eigenvectors*/,
|
| 251 |
+
const Tensor& /*infos*/,
|
| 252 |
+
bool /*upper*/,
|
| 253 |
+
bool /*compute_eigenvectors*/);
|
| 254 |
+
DECLARE_DISPATCH(linalg_eigh_fn, linalg_eigh_stub);
|
| 255 |
+
|
| 256 |
+
using lstsq_fn = void (*)(
|
| 257 |
+
const Tensor& /*a*/,
|
| 258 |
+
Tensor& /*b*/,
|
| 259 |
+
Tensor& /*rank*/,
|
| 260 |
+
Tensor& /*singular_values*/,
|
| 261 |
+
Tensor& /*infos*/,
|
| 262 |
+
double /*rcond*/,
|
| 263 |
+
std::string /*driver_name*/);
|
| 264 |
+
DECLARE_DISPATCH(lstsq_fn, lstsq_stub);
|
| 265 |
+
|
| 266 |
+
using triangular_solve_fn = void (*)(
|
| 267 |
+
const Tensor& /*A*/,
|
| 268 |
+
const Tensor& /*B*/,
|
| 269 |
+
bool /*left*/,
|
| 270 |
+
bool /*upper*/,
|
| 271 |
+
TransposeType /*transpose*/,
|
| 272 |
+
bool /*unitriangular*/);
|
| 273 |
+
DECLARE_DISPATCH(triangular_solve_fn, triangular_solve_stub);
|
| 274 |
+
|
| 275 |
+
using lu_factor_fn = void (*)(
|
| 276 |
+
const Tensor& /*input*/,
|
| 277 |
+
const Tensor& /*pivots*/,
|
| 278 |
+
const Tensor& /*infos*/,
|
| 279 |
+
bool /*compute_pivots*/);
|
| 280 |
+
DECLARE_DISPATCH(lu_factor_fn, lu_factor_stub);
|
| 281 |
+
|
| 282 |
+
using unpack_pivots_fn = void(*)(
|
| 283 |
+
TensorIterator& iter,
|
| 284 |
+
const int64_t dim_size,
|
| 285 |
+
const int64_t max_pivot);
|
| 286 |
+
DECLARE_DISPATCH(unpack_pivots_fn, unpack_pivots_stub);
|
| 287 |
+
|
| 288 |
+
using lu_solve_fn = void (*)(
|
| 289 |
+
const Tensor& /*LU*/,
|
| 290 |
+
const Tensor& /*pivots*/,
|
| 291 |
+
const Tensor& /*B*/,
|
| 292 |
+
TransposeType /*trans*/);
|
| 293 |
+
DECLARE_DISPATCH(lu_solve_fn, lu_solve_stub);
|
| 294 |
+
|
| 295 |
+
using ldl_factor_fn = void (*)(
|
| 296 |
+
const Tensor& /*LD*/,
|
| 297 |
+
const Tensor& /*pivots*/,
|
| 298 |
+
const Tensor& /*info*/,
|
| 299 |
+
bool /*upper*/,
|
| 300 |
+
bool /*hermitian*/);
|
| 301 |
+
DECLARE_DISPATCH(ldl_factor_fn, ldl_factor_stub);
|
| 302 |
+
|
| 303 |
+
using svd_fn = void (*)(
|
| 304 |
+
const Tensor& /*A*/,
|
| 305 |
+
const bool /*full_matrices*/,
|
| 306 |
+
const bool /*compute_uv*/,
|
| 307 |
+
const c10::optional<c10::string_view>& /*driver*/,
|
| 308 |
+
const Tensor& /*U*/,
|
| 309 |
+
const Tensor& /*S*/,
|
| 310 |
+
const Tensor& /*Vh*/,
|
| 311 |
+
const Tensor& /*info*/);
|
| 312 |
+
DECLARE_DISPATCH(svd_fn, svd_stub);
|
| 313 |
+
|
| 314 |
+
using ldl_solve_fn = void (*)(
|
| 315 |
+
const Tensor& /*LD*/,
|
| 316 |
+
const Tensor& /*pivots*/,
|
| 317 |
+
const Tensor& /*result*/,
|
| 318 |
+
bool /*upper*/,
|
| 319 |
+
bool /*hermitian*/);
|
| 320 |
+
DECLARE_DISPATCH(ldl_solve_fn, ldl_solve_stub);
|
| 321 |
+
} // namespace at::native
|
shared/package-files/65/655f072fc3640e7a1065f9e37bb04fd1fc88a787d216a8cab10738d0f6938207/blob
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pytest
|
| 2 |
+
|
| 3 |
+
import random
|
| 4 |
+
from numpy.core._multiarray_tests import identityhash_tester
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
@pytest.mark.parametrize("key_length", [1, 3, 6])
|
| 8 |
+
@pytest.mark.parametrize("length", [1, 16, 2000])
|
| 9 |
+
def test_identity_hashtable(key_length, length):
|
| 10 |
+
# use a 30 object pool for everything (duplicates will happen)
|
| 11 |
+
pool = [object() for i in range(20)]
|
| 12 |
+
keys_vals = []
|
| 13 |
+
for i in range(length):
|
| 14 |
+
keys = tuple(random.choices(pool, k=key_length))
|
| 15 |
+
keys_vals.append((keys, random.choice(pool)))
|
| 16 |
+
|
| 17 |
+
dictionary = dict(keys_vals)
|
| 18 |
+
|
| 19 |
+
# add a random item at the end:
|
| 20 |
+
keys_vals.append(random.choice(keys_vals))
|
| 21 |
+
# the expected one could be different with duplicates:
|
| 22 |
+
expected = dictionary[keys_vals[-1][0]]
|
| 23 |
+
|
| 24 |
+
res = identityhash_tester(key_length, keys_vals, replace=True)
|
| 25 |
+
assert res is expected
|
| 26 |
+
|
| 27 |
+
# check that ensuring one duplicate definitely raises:
|
| 28 |
+
keys_vals.insert(0, keys_vals[-2])
|
| 29 |
+
with pytest.raises(RuntimeError):
|
| 30 |
+
identityhash_tester(key_length, keys_vals)
|
shared/package-files/65/655fc11bc255b36bda34abe4882dd002df4751fda383120fe40b73ce26af1caa/blob
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Dict, Tuple, Any
|
| 2 |
+
|
| 3 |
+
import torch
|
| 4 |
+
from torch.fx.passes.infra.pass_base import PassBase, PassResult
|
| 5 |
+
from torch.utils._pytree import tree_flatten
|
| 6 |
+
|
| 7 |
+
from torch.fx import GraphModule, Graph
|
| 8 |
+
from torch.fx import Node
|
| 9 |
+
|
| 10 |
+
aten = torch.ops.aten
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
# stateful ops are banned from CSE
|
| 14 |
+
rand_ops = {aten.dropout, aten._fused_dropout, aten._standard_gamma, aten.bernoulli, aten.multinomial, aten.native_dropout, aten.normal, aten.poisson, aten.binomial, aten.rrelu, aten.rand_like, aten.rand, aten.randint, aten.randn, aten.randperm} # noqa: E501,B950
|
| 15 |
+
|
| 16 |
+
inplace_ops = {aten.add_, aten.sub_, aten.mul_, aten.div_, aten.pow_, aten.lerp_, aten.relu_, aten.sigmoid_, aten.tanh_} # noqa: E501
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
@torch.fx._compatibility.compatibility(is_backward_compatible=False)
|
| 20 |
+
def get_CSE_banned_ops():
|
| 21 |
+
return rand_ops.union(inplace_ops)
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
@torch.fx._compatibility.compatibility(is_backward_compatible=False)
|
| 25 |
+
class CSEPass(PassBase):
|
| 26 |
+
|
| 27 |
+
def __init__(self, banned_ops=None):
|
| 28 |
+
"""
|
| 29 |
+
This version of CSE Pass aims to be dialect agnostic, and it's implemented purely based on the connectivity between fx.Node.
|
| 30 |
+
|
| 31 |
+
For functional dialects, user would only need to specify the random ops in ban list.
|
| 32 |
+
|
| 33 |
+
Warning: CSE Pass cannot be safely applied on a FX graph in non-functional dialects.
|
| 34 |
+
If your dialect contains stateful operators, please customized the banned_ops.
|
| 35 |
+
|
| 36 |
+
"""
|
| 37 |
+
if banned_ops is None:
|
| 38 |
+
banned_ops = set()
|
| 39 |
+
self.banned_ops = banned_ops
|
| 40 |
+
super().__init__()
|
| 41 |
+
|
| 42 |
+
def call(self, graph_module: GraphModule) -> PassResult:
|
| 43 |
+
"""
|
| 44 |
+
Return a new copy of torch.fx.GraphModule with CSE applied to the input graph
|
| 45 |
+
|
| 46 |
+
Example usage:
|
| 47 |
+
|
| 48 |
+
from torch.fx.experimental.proxy_tensor import make_fx
|
| 49 |
+
def f(a):
|
| 50 |
+
b = a * a
|
| 51 |
+
c = a * a
|
| 52 |
+
return b+c
|
| 53 |
+
|
| 54 |
+
p = CSEPass()
|
| 55 |
+
traced_graph = make_fx(f)(torch.tensor(1))
|
| 56 |
+
print(traced_graph)
|
| 57 |
+
result = p(traced_graph)
|
| 58 |
+
print(result.graph_module)
|
| 59 |
+
"""
|
| 60 |
+
def get_aten_target(node):
|
| 61 |
+
if hasattr(node.target, 'overloadpacket'):
|
| 62 |
+
return node.target.overloadpacket
|
| 63 |
+
return node.target
|
| 64 |
+
|
| 65 |
+
modified = False
|
| 66 |
+
new_graph = Graph()
|
| 67 |
+
env: Dict[Node, Node] = {} # map from node in the old graph to node in the new graph
|
| 68 |
+
hash_env: Dict[Tuple[torch._ops.OpOverload, int], Node] = {} # map from hash to a node in the new graph
|
| 69 |
+
token_map: Dict[Tuple[torch._ops.OpOverload, int], Dict[str, Any]] = {} # map from hash to token
|
| 70 |
+
for n in graph_module.graph.nodes:
|
| 71 |
+
# The placeholder, output, and get_attr nodes are copied to the new graph without change
|
| 72 |
+
# do not CSE away random operations
|
| 73 |
+
if n.op == 'placeholder' or n.op == 'output' or n.op == 'get_attr' or get_aten_target(n) in self.banned_ops:
|
| 74 |
+
new_node = new_graph.node_copy(n, lambda x: env[x])
|
| 75 |
+
env[n] = new_node
|
| 76 |
+
else: # n.op == 'call_function', should never see n.op == 'call_module' or 'call_method'
|
| 77 |
+
# substitute args and kwargs members to their mapping in env if exists
|
| 78 |
+
# specs can be used to reconstruct nested list/dictionaries
|
| 79 |
+
def substitute(arg_list):
|
| 80 |
+
arg_list, spec = tree_flatten(arg_list)
|
| 81 |
+
for i in range(len(arg_list)):
|
| 82 |
+
v = arg_list[i]
|
| 83 |
+
if isinstance(v, Node) and v in env:
|
| 84 |
+
arg_list[i] = env[v]
|
| 85 |
+
return tuple(arg_list), spec
|
| 86 |
+
args, args_spec = substitute(n.args)
|
| 87 |
+
kwargs, kwargs_spec = substitute(n.kwargs)
|
| 88 |
+
|
| 89 |
+
# each token corresponds to a unique node
|
| 90 |
+
# nodes with the same token can be substituted
|
| 91 |
+
token = {"target": n.target, "args": args, "args_spec": args_spec,
|
| 92 |
+
"kwargs": kwargs, "kwargs_spec": kwargs_spec}
|
| 93 |
+
|
| 94 |
+
# hash substituted args to a number, do not hash specs because specs are not hashable
|
| 95 |
+
hash_arg = hash((args, kwargs))
|
| 96 |
+
hash_val = (n.target, hash_arg)
|
| 97 |
+
|
| 98 |
+
# check if a node has a substitute and can be eliminated
|
| 99 |
+
hash_val_in_hash_env = hash_val in hash_env
|
| 100 |
+
if hash_val_in_hash_env and token_map[hash_val] == token:
|
| 101 |
+
modified = True # substitution happens and the graph is modified
|
| 102 |
+
env[n] = hash_env[hash_val]
|
| 103 |
+
continue
|
| 104 |
+
|
| 105 |
+
new_node = new_graph.node_copy(n, lambda x: env[x])
|
| 106 |
+
env[n] = new_node
|
| 107 |
+
if not hash_val_in_hash_env:
|
| 108 |
+
hash_env[hash_val] = new_node
|
| 109 |
+
token_map[hash_val] = token
|
| 110 |
+
|
| 111 |
+
csed_gm = GraphModule(graph_module, new_graph)
|
| 112 |
+
return PassResult(csed_gm, modified)
|
shared/package-files/65/6561c170208e54dc03c6e25683558fa3492b4c7c759b5c133e2d9c3983ec013e/blob
ADDED
|
@@ -0,0 +1,533 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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_rewritable_or_comparable,
|
| 7 |
+
Sign, Polyn, Num, s_poly, f5_reduce,
|
| 8 |
+
groebner_lcm, groebner_gcd, is_groebner,
|
| 9 |
+
is_reduced
|
| 10 |
+
)
|
| 11 |
+
|
| 12 |
+
from sympy.polys.fglmtools import _representing_matrices
|
| 13 |
+
from sympy.polys.orderings import lex, grlex
|
| 14 |
+
|
| 15 |
+
from sympy.polys.rings import ring, xring
|
| 16 |
+
from sympy.polys.domains import ZZ, QQ
|
| 17 |
+
|
| 18 |
+
from sympy.testing.pytest import slow
|
| 19 |
+
from sympy.polys import polyconfig as config
|
| 20 |
+
|
| 21 |
+
def _do_test_groebner():
|
| 22 |
+
R, x,y = ring("x,y", QQ, lex)
|
| 23 |
+
f = x**2 + 2*x*y**2
|
| 24 |
+
g = x*y + 2*y**3 - 1
|
| 25 |
+
|
| 26 |
+
assert groebner([f, g], R) == [x, y**3 - QQ(1,2)]
|
| 27 |
+
|
| 28 |
+
R, y,x = ring("y,x", QQ, lex)
|
| 29 |
+
f = 2*x**2*y + y**2
|
| 30 |
+
g = 2*x**3 + x*y - 1
|
| 31 |
+
|
| 32 |
+
assert groebner([f, g], R) == [y, x**3 - QQ(1,2)]
|
| 33 |
+
|
| 34 |
+
R, x,y,z = ring("x,y,z", QQ, lex)
|
| 35 |
+
f = x - z**2
|
| 36 |
+
g = y - z**3
|
| 37 |
+
|
| 38 |
+
assert groebner([f, g], R) == [f, g]
|
| 39 |
+
|
| 40 |
+
R, x,y = ring("x,y", QQ, grlex)
|
| 41 |
+
f = x**3 - 2*x*y
|
| 42 |
+
g = x**2*y + x - 2*y**2
|
| 43 |
+
|
| 44 |
+
assert groebner([f, g], R) == [x**2, x*y, -QQ(1,2)*x + y**2]
|
| 45 |
+
|
| 46 |
+
R, x,y,z = ring("x,y,z", QQ, lex)
|
| 47 |
+
f = -x**2 + y
|
| 48 |
+
g = -x**3 + z
|
| 49 |
+
|
| 50 |
+
assert groebner([f, g], R) == [x**2 - y, x*y - z, x*z - y**2, y**3 - z**2]
|
| 51 |
+
|
| 52 |
+
R, x,y,z = ring("x,y,z", QQ, grlex)
|
| 53 |
+
f = -x**2 + y
|
| 54 |
+
g = -x**3 + z
|
| 55 |
+
|
| 56 |
+
assert groebner([f, g], R) == [y**3 - z**2, x**2 - y, x*y - z, x*z - y**2]
|
| 57 |
+
|
| 58 |
+
R, x,y,z = ring("x,y,z", QQ, lex)
|
| 59 |
+
f = -x**2 + z
|
| 60 |
+
g = -x**3 + y
|
| 61 |
+
|
| 62 |
+
assert groebner([f, g], R) == [x**2 - z, x*y - z**2, x*z - y, y**2 - z**3]
|
| 63 |
+
|
| 64 |
+
R, x,y,z = ring("x,y,z", QQ, grlex)
|
| 65 |
+
f = -x**2 + z
|
| 66 |
+
g = -x**3 + y
|
| 67 |
+
|
| 68 |
+
assert groebner([f, g], R) == [-y**2 + z**3, x**2 - z, x*y - z**2, x*z - y]
|
| 69 |
+
|
| 70 |
+
R, x,y,z = ring("x,y,z", QQ, lex)
|
| 71 |
+
f = x - y**2
|
| 72 |
+
g = -y**3 + z
|
| 73 |
+
|
| 74 |
+
assert groebner([f, g], R) == [x - y**2, y**3 - z]
|
| 75 |
+
|
| 76 |
+
R, x,y,z = ring("x,y,z", QQ, grlex)
|
| 77 |
+
f = x - y**2
|
| 78 |
+
g = -y**3 + z
|
| 79 |
+
|
| 80 |
+
assert groebner([f, g], R) == [x**2 - y*z, x*y - z, -x + y**2]
|
| 81 |
+
|
| 82 |
+
R, x,y,z = ring("x,y,z", QQ, lex)
|
| 83 |
+
f = x - z**2
|
| 84 |
+
g = y - z**3
|
| 85 |
+
|
| 86 |
+
assert groebner([f, g], R) == [x - z**2, y - z**3]
|
| 87 |
+
|
| 88 |
+
R, x,y,z = ring("x,y,z", QQ, grlex)
|
| 89 |
+
f = x - z**2
|
| 90 |
+
g = y - z**3
|
| 91 |
+
|
| 92 |
+
assert groebner([f, g], R) == [x**2 - y*z, x*z - y, -x + z**2]
|
| 93 |
+
|
| 94 |
+
R, x,y,z = ring("x,y,z", QQ, lex)
|
| 95 |
+
f = -y**2 + z
|
| 96 |
+
g = x - y**3
|
| 97 |
+
|
| 98 |
+
assert groebner([f, g], R) == [x - y*z, y**2 - z]
|
| 99 |
+
|
| 100 |
+
R, x,y,z = ring("x,y,z", QQ, grlex)
|
| 101 |
+
f = -y**2 + z
|
| 102 |
+
g = x - y**3
|
| 103 |
+
|
| 104 |
+
assert groebner([f, g], R) == [-x**2 + z**3, x*y - z**2, y**2 - z, -x + y*z]
|
| 105 |
+
|
| 106 |
+
R, x,y,z = ring("x,y,z", QQ, lex)
|
| 107 |
+
f = y - z**2
|
| 108 |
+
g = x - z**3
|
| 109 |
+
|
| 110 |
+
assert groebner([f, g], R) == [x - z**3, y - z**2]
|
| 111 |
+
|
| 112 |
+
R, x,y,z = ring("x,y,z", QQ, grlex)
|
| 113 |
+
f = y - z**2
|
| 114 |
+
g = x - z**3
|
| 115 |
+
|
| 116 |
+
assert groebner([f, g], R) == [-x**2 + y**3, x*z - y**2, -x + y*z, -y + z**2]
|
| 117 |
+
|
| 118 |
+
R, x,y,z = ring("x,y,z", QQ, lex)
|
| 119 |
+
f = 4*x**2*y**2 + 4*x*y + 1
|
| 120 |
+
g = x**2 + y**2 - 1
|
| 121 |
+
|
| 122 |
+
assert groebner([f, g], R) == [
|
| 123 |
+
x - 4*y**7 + 8*y**5 - 7*y**3 + 3*y,
|
| 124 |
+
y**8 - 2*y**6 + QQ(3,2)*y**4 - QQ(1,2)*y**2 + QQ(1,16),
|
| 125 |
+
]
|
| 126 |
+
|
| 127 |
+
def test_groebner_buchberger():
|
| 128 |
+
with config.using(groebner='buchberger'):
|
| 129 |
+
_do_test_groebner()
|
| 130 |
+
|
| 131 |
+
def test_groebner_f5b():
|
| 132 |
+
with config.using(groebner='f5b'):
|
| 133 |
+
_do_test_groebner()
|
| 134 |
+
|
| 135 |
+
def _do_test_benchmark_minpoly():
|
| 136 |
+
R, x,y,z = ring("x,y,z", QQ, lex)
|
| 137 |
+
|
| 138 |
+
F = [x**3 + x + 1, y**2 + y + 1, (x + y) * z - (x**2 + y)]
|
| 139 |
+
G = [x + QQ(155,2067)*z**5 - QQ(355,689)*z**4 + QQ(6062,2067)*z**3 - QQ(3687,689)*z**2 + QQ(6878,2067)*z - QQ(25,53),
|
| 140 |
+
y + QQ(4,53)*z**5 - QQ(91,159)*z**4 + QQ(523,159)*z**3 - QQ(387,53)*z**2 + QQ(1043,159)*z - QQ(308,159),
|
| 141 |
+
z**6 - 7*z**5 + 41*z**4 - 82*z**3 + 89*z**2 - 46*z + 13]
|
| 142 |
+
|
| 143 |
+
assert groebner(F, R) == G
|
| 144 |
+
|
| 145 |
+
def test_benchmark_minpoly_buchberger():
|
| 146 |
+
with config.using(groebner='buchberger'):
|
| 147 |
+
_do_test_benchmark_minpoly()
|
| 148 |
+
|
| 149 |
+
def test_benchmark_minpoly_f5b():
|
| 150 |
+
with config.using(groebner='f5b'):
|
| 151 |
+
_do_test_benchmark_minpoly()
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
def test_benchmark_coloring():
|
| 155 |
+
V = range(1, 12 + 1)
|
| 156 |
+
E = [(1, 2), (2, 3), (1, 4), (1, 6), (1, 12), (2, 5), (2, 7), (3, 8), (3, 10),
|
| 157 |
+
(4, 11), (4, 9), (5, 6), (6, 7), (7, 8), (8, 9), (9, 10), (10, 11),
|
| 158 |
+
(11, 12), (5, 12), (5, 9), (6, 10), (7, 11), (8, 12), (3, 4)]
|
| 159 |
+
|
| 160 |
+
R, V = xring([ "x%d" % v for v in V ], QQ, lex)
|
| 161 |
+
E = [(V[i - 1], V[j - 1]) for i, j in E]
|
| 162 |
+
|
| 163 |
+
x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12 = V
|
| 164 |
+
|
| 165 |
+
I3 = [x**3 - 1 for x in V]
|
| 166 |
+
Ig = [x**2 + x*y + y**2 for x, y in E]
|
| 167 |
+
|
| 168 |
+
I = I3 + Ig
|
| 169 |
+
|
| 170 |
+
assert groebner(I[:-1], R) == [
|
| 171 |
+
x1 + x11 + x12,
|
| 172 |
+
x2 - x11,
|
| 173 |
+
x3 - x12,
|
| 174 |
+
x4 - x12,
|
| 175 |
+
x5 + x11 + x12,
|
| 176 |
+
x6 - x11,
|
| 177 |
+
x7 - x12,
|
| 178 |
+
x8 + x11 + x12,
|
| 179 |
+
x9 - x11,
|
| 180 |
+
x10 + x11 + x12,
|
| 181 |
+
x11**2 + x11*x12 + x12**2,
|
| 182 |
+
x12**3 - 1,
|
| 183 |
+
]
|
| 184 |
+
|
| 185 |
+
assert groebner(I, R) == [1]
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
def _do_test_benchmark_katsura_3():
|
| 189 |
+
R, x0,x1,x2 = ring("x:3", ZZ, lex)
|
| 190 |
+
I = [x0 + 2*x1 + 2*x2 - 1,
|
| 191 |
+
x0**2 + 2*x1**2 + 2*x2**2 - x0,
|
| 192 |
+
2*x0*x1 + 2*x1*x2 - x1]
|
| 193 |
+
|
| 194 |
+
assert groebner(I, R) == [
|
| 195 |
+
-7 + 7*x0 + 8*x2 + 158*x2**2 - 420*x2**3,
|
| 196 |
+
7*x1 + 3*x2 - 79*x2**2 + 210*x2**3,
|
| 197 |
+
x2 + x2**2 - 40*x2**3 + 84*x2**4,
|
| 198 |
+
]
|
| 199 |
+
|
| 200 |
+
R, x0,x1,x2 = ring("x:3", ZZ, grlex)
|
| 201 |
+
I = [ i.set_ring(R) for i in I ]
|
| 202 |
+
|
| 203 |
+
assert groebner(I, R) == [
|
| 204 |
+
7*x1 + 3*x2 - 79*x2**2 + 210*x2**3,
|
| 205 |
+
-x1 + x2 - 3*x2**2 + 5*x1**2,
|
| 206 |
+
-x1 - 4*x2 + 10*x1*x2 + 12*x2**2,
|
| 207 |
+
-1 + x0 + 2*x1 + 2*x2,
|
| 208 |
+
]
|
| 209 |
+
|
| 210 |
+
def test_benchmark_katsura3_buchberger():
|
| 211 |
+
with config.using(groebner='buchberger'):
|
| 212 |
+
_do_test_benchmark_katsura_3()
|
| 213 |
+
|
| 214 |
+
def test_benchmark_katsura3_f5b():
|
| 215 |
+
with config.using(groebner='f5b'):
|
| 216 |
+
_do_test_benchmark_katsura_3()
|
| 217 |
+
|
| 218 |
+
def _do_test_benchmark_katsura_4():
|
| 219 |
+
R, x0,x1,x2,x3 = ring("x:4", ZZ, lex)
|
| 220 |
+
I = [x0 + 2*x1 + 2*x2 + 2*x3 - 1,
|
| 221 |
+
x0**2 + 2*x1**2 + 2*x2**2 + 2*x3**2 - x0,
|
| 222 |
+
2*x0*x1 + 2*x1*x2 + 2*x2*x3 - x1,
|
| 223 |
+
x1**2 + 2*x0*x2 + 2*x1*x3 - x2]
|
| 224 |
+
|
| 225 |
+
assert groebner(I, R) == [
|
| 226 |
+
5913075*x0 - 159690237696*x3**7 + 31246269696*x3**6 + 27439610544*x3**5 - 6475723368*x3**4 - 838935856*x3**3 + 275119624*x3**2 + 4884038*x3 - 5913075,
|
| 227 |
+
1971025*x1 - 97197721632*x3**7 + 73975630752*x3**6 - 12121915032*x3**5 - 2760941496*x3**4 + 814792828*x3**3 - 1678512*x3**2 - 9158924*x3,
|
| 228 |
+
5913075*x2 + 371438283744*x3**7 - 237550027104*x3**6 + 22645939824*x3**5 + 11520686172*x3**4 - 2024910556*x3**3 - 132524276*x3**2 + 30947828*x3,
|
| 229 |
+
128304*x3**8 - 93312*x3**7 + 15552*x3**6 + 3144*x3**5 -
|
| 230 |
+
1120*x3**4 + 36*x3**3 + 15*x3**2 - x3,
|
| 231 |
+
]
|
| 232 |
+
|
| 233 |
+
R, x0,x1,x2,x3 = ring("x:4", ZZ, grlex)
|
| 234 |
+
I = [ i.set_ring(R) for i in I ]
|
| 235 |
+
|
| 236 |
+
assert groebner(I, R) == [
|
| 237 |
+
393*x1 - 4662*x2**2 + 4462*x2*x3 - 59*x2 + 224532*x3**4 - 91224*x3**3 - 678*x3**2 + 2046*x3,
|
| 238 |
+
-x1 + 196*x2**3 - 21*x2**2 + 60*x2*x3 - 18*x2 - 168*x3**3 + 83*x3**2 - 9*x3,
|
| 239 |
+
-6*x1 + 1134*x2**2*x3 - 189*x2**2 - 466*x2*x3 + 32*x2 - 630*x3**3 + 57*x3**2 + 51*x3,
|
| 240 |
+
33*x1 + 63*x2**2 + 2268*x2*x3**2 - 188*x2*x3 + 34*x2 + 2520*x3**3 - 849*x3**2 + 3*x3,
|
| 241 |
+
7*x1**2 - x1 - 7*x2**2 - 24*x2*x3 + 3*x2 - 15*x3**2 + 5*x3,
|
| 242 |
+
14*x1*x2 - x1 + 14*x2**2 + 18*x2*x3 - 4*x2 + 6*x3**2 - 2*x3,
|
| 243 |
+
14*x1*x3 - x1 + 7*x2**2 + 32*x2*x3 - 4*x2 + 27*x3**2 - 9*x3,
|
| 244 |
+
x0 + 2*x1 + 2*x2 + 2*x3 - 1,
|
| 245 |
+
]
|
| 246 |
+
|
| 247 |
+
def test_benchmark_kastura_4_buchberger():
|
| 248 |
+
with config.using(groebner='buchberger'):
|
| 249 |
+
_do_test_benchmark_katsura_4()
|
| 250 |
+
|
| 251 |
+
def test_benchmark_kastura_4_f5b():
|
| 252 |
+
with config.using(groebner='f5b'):
|
| 253 |
+
_do_test_benchmark_katsura_4()
|
| 254 |
+
|
| 255 |
+
def _do_test_benchmark_czichowski():
|
| 256 |
+
R, x,t = ring("x,t", ZZ, lex)
|
| 257 |
+
I = [9*x**8 + 36*x**7 - 32*x**6 - 252*x**5 - 78*x**4 + 468*x**3 + 288*x**2 - 108*x + 9,
|
| 258 |
+
(-72 - 72*t)*x**7 + (-256 - 252*t)*x**6 + (192 + 192*t)*x**5 + (1280 + 1260*t)*x**4 + (312 + 312*t)*x**3 + (-404*t)*x**2 + (-576 - 576*t)*x + 96 + 108*t]
|
| 259 |
+
|
| 260 |
+
assert groebner(I, R) == [
|
| 261 |
+
3725588592068034903797967297424801242396746870413359539263038139343329273586196480000*x -
|
| 262 |
+
160420835591776763325581422211936558925462474417709511019228211783493866564923546661604487873*t**7 -
|
| 263 |
+
1406108495478033395547109582678806497509499966197028487131115097902188374051595011248311352864*t**6 -
|
| 264 |
+
5241326875850889518164640374668786338033653548841427557880599579174438246266263602956254030352*t**5 -
|
| 265 |
+
10758917262823299139373269714910672770004760114329943852726887632013485035262879510837043892416*t**4 -
|
| 266 |
+
13119383576444715672578819534846747735372132018341964647712009275306635391456880068261130581248*t**3 -
|
| 267 |
+
9491412317016197146080450036267011389660653495578680036574753839055748080962214787557853941760*t**2 -
|
| 268 |
+
3767520915562795326943800040277726397326609797172964377014046018280260848046603967211258368000*t -
|
| 269 |
+
632314652371226552085897259159210286886724229880266931574701654721512325555116066073245696000,
|
| 270 |
+
610733380717522355121*t**8 +
|
| 271 |
+
6243748742141230639968*t**7 +
|
| 272 |
+
27761407182086143225024*t**6 +
|
| 273 |
+
70066148869420956398592*t**5 +
|
| 274 |
+
109701225644313784229376*t**4 +
|
| 275 |
+
109009005495588442152960*t**3 +
|
| 276 |
+
67072101084384786432000*t**2 +
|
| 277 |
+
23339979742629593088000*t +
|
| 278 |
+
3513592776846090240000,
|
| 279 |
+
]
|
| 280 |
+
|
| 281 |
+
R, x,t = ring("x,t", ZZ, grlex)
|
| 282 |
+
I = [ i.set_ring(R) for i in I ]
|
| 283 |
+
|
| 284 |
+
assert groebner(I, R) == [
|
| 285 |
+
16996618586000601590732959134095643086442*t**3*x -
|
| 286 |
+
32936701459297092865176560282688198064839*t**3 +
|
| 287 |
+
78592411049800639484139414821529525782364*t**2*x -
|
| 288 |
+
120753953358671750165454009478961405619916*t**2 +
|
| 289 |
+
120988399875140799712152158915653654637280*t*x -
|
| 290 |
+
144576390266626470824138354942076045758736*t +
|
| 291 |
+
60017634054270480831259316163620768960*x**2 +
|
| 292 |
+
61976058033571109604821862786675242894400*x -
|
| 293 |
+
56266268491293858791834120380427754600960,
|
| 294 |
+
576689018321912327136790519059646508441672750656050290242749*t**4 +
|
| 295 |
+
2326673103677477425562248201573604572527893938459296513327336*t**3 +
|
| 296 |
+
110743790416688497407826310048520299245819959064297990236000*t**2*x +
|
| 297 |
+
3308669114229100853338245486174247752683277925010505284338016*t**2 +
|
| 298 |
+
323150205645687941261103426627818874426097912639158572428800*t*x +
|
| 299 |
+
1914335199925152083917206349978534224695445819017286960055680*t +
|
| 300 |
+
861662882561803377986838989464278045397192862768588480000*x**2 +
|
| 301 |
+
235296483281783440197069672204341465480107019878814196672000*x +
|
| 302 |
+
361850798943225141738895123621685122544503614946436727532800,
|
| 303 |
+
-117584925286448670474763406733005510014188341867*t**3 +
|
| 304 |
+
68566565876066068463853874568722190223721653044*t**2*x -
|
| 305 |
+
435970731348366266878180788833437896139920683940*t**2 +
|
| 306 |
+
196297602447033751918195568051376792491869233408*t*x -
|
| 307 |
+
525011527660010557871349062870980202067479780112*t +
|
| 308 |
+
517905853447200553360289634770487684447317120*x**3 +
|
| 309 |
+
569119014870778921949288951688799397569321920*x**2 +
|
| 310 |
+
138877356748142786670127389526667463202210102080*x -
|
| 311 |
+
205109210539096046121625447192779783475018619520,
|
| 312 |
+
-3725142681462373002731339445216700112264527*t**3 +
|
| 313 |
+
583711207282060457652784180668273817487940*t**2*x -
|
| 314 |
+
12381382393074485225164741437227437062814908*t**2 +
|
| 315 |
+
151081054097783125250959636747516827435040*t*x**2 +
|
| 316 |
+
1814103857455163948531448580501928933873280*t*x -
|
| 317 |
+
13353115629395094645843682074271212731433648*t +
|
| 318 |
+
236415091385250007660606958022544983766080*x**2 +
|
| 319 |
+
1390443278862804663728298060085399578417600*x -
|
| 320 |
+
4716885828494075789338754454248931750698880,
|
| 321 |
+
]
|
| 322 |
+
|
| 323 |
+
# NOTE: This is very slow (> 2 minutes on 3.4 GHz) without GMPY
|
| 324 |
+
@slow
|
| 325 |
+
def test_benchmark_czichowski_buchberger():
|
| 326 |
+
with config.using(groebner='buchberger'):
|
| 327 |
+
_do_test_benchmark_czichowski()
|
| 328 |
+
|
| 329 |
+
def test_benchmark_czichowski_f5b():
|
| 330 |
+
with config.using(groebner='f5b'):
|
| 331 |
+
_do_test_benchmark_czichowski()
|
| 332 |
+
|
| 333 |
+
def _do_test_benchmark_cyclic_4():
|
| 334 |
+
R, a,b,c,d = ring("a,b,c,d", ZZ, lex)
|
| 335 |
+
|
| 336 |
+
I = [a + b + c + d,
|
| 337 |
+
a*b + a*d + b*c + b*d,
|
| 338 |
+
a*b*c + a*b*d + a*c*d + b*c*d,
|
| 339 |
+
a*b*c*d - 1]
|
| 340 |
+
|
| 341 |
+
assert groebner(I, R) == [
|
| 342 |
+
4*a + 3*d**9 - 4*d**5 - 3*d,
|
| 343 |
+
4*b + 4*c - 3*d**9 + 4*d**5 + 7*d,
|
| 344 |
+
4*c**2 + 3*d**10 - 4*d**6 - 3*d**2,
|
| 345 |
+
4*c*d**4 + 4*c - d**9 + 4*d**5 + 5*d, d**12 - d**8 - d**4 + 1
|
| 346 |
+
]
|
| 347 |
+
|
| 348 |
+
R, a,b,c,d = ring("a,b,c,d", ZZ, grlex)
|
| 349 |
+
I = [ i.set_ring(R) for i in I ]
|
| 350 |
+
|
| 351 |
+
assert groebner(I, R) == [
|
| 352 |
+
3*b*c - c**2 + d**6 - 3*d**2,
|
| 353 |
+
-b + 3*c**2*d**3 - c - d**5 - 4*d,
|
| 354 |
+
-b + 3*c*d**4 + 2*c + 2*d**5 + 2*d,
|
| 355 |
+
c**4 + 2*c**2*d**2 - d**4 - 2,
|
| 356 |
+
c**3*d + c*d**3 + d**4 + 1,
|
| 357 |
+
b*c**2 - c**3 - c**2*d - 2*c*d**2 - d**3,
|
| 358 |
+
b**2 - c**2, b*d + c**2 + c*d + d**2,
|
| 359 |
+
a + b + c + d
|
| 360 |
+
]
|
| 361 |
+
|
| 362 |
+
def test_benchmark_cyclic_4_buchberger():
|
| 363 |
+
with config.using(groebner='buchberger'):
|
| 364 |
+
_do_test_benchmark_cyclic_4()
|
| 365 |
+
|
| 366 |
+
def test_benchmark_cyclic_4_f5b():
|
| 367 |
+
with config.using(groebner='f5b'):
|
| 368 |
+
_do_test_benchmark_cyclic_4()
|
| 369 |
+
|
| 370 |
+
def test_sig_key():
|
| 371 |
+
s1 = sig((0,) * 3, 2)
|
| 372 |
+
s2 = sig((1,) * 3, 4)
|
| 373 |
+
s3 = sig((2,) * 3, 2)
|
| 374 |
+
|
| 375 |
+
assert sig_key(s1, lex) > sig_key(s2, lex)
|
| 376 |
+
assert sig_key(s2, lex) < sig_key(s3, lex)
|
| 377 |
+
|
| 378 |
+
|
| 379 |
+
def test_lbp_key():
|
| 380 |
+
R, x,y,z,t = ring("x,y,z,t", ZZ, lex)
|
| 381 |
+
|
| 382 |
+
p1 = lbp(sig((0,) * 4, 3), R.zero, 12)
|
| 383 |
+
p2 = lbp(sig((0,) * 4, 4), R.zero, 13)
|
| 384 |
+
p3 = lbp(sig((0,) * 4, 4), R.zero, 12)
|
| 385 |
+
|
| 386 |
+
assert lbp_key(p1) > lbp_key(p2)
|
| 387 |
+
assert lbp_key(p2) < lbp_key(p3)
|
| 388 |
+
|
| 389 |
+
|
| 390 |
+
def test_critical_pair():
|
| 391 |
+
# from cyclic4 with grlex
|
| 392 |
+
R, x,y,z,t = ring("x,y,z,t", QQ, grlex)
|
| 393 |
+
|
| 394 |
+
p1 = (((0, 0, 0, 0), 4), y*z*t**2 + z**2*t**2 - t**4 - 1, 4)
|
| 395 |
+
q1 = (((0, 0, 0, 0), 2), -y**2 - y*t - z*t - t**2, 2)
|
| 396 |
+
|
| 397 |
+
p2 = (((0, 0, 0, 2), 3), z**3*t**2 + z**2*t**3 - z - t, 5)
|
| 398 |
+
q2 = (((0, 0, 2, 2), 2), y*z + z*t**5 + z*t + t**6, 13)
|
| 399 |
+
|
| 400 |
+
assert critical_pair(p1, q1, R) == (
|
| 401 |
+
((0, 0, 1, 2), 2), ((0, 0, 1, 2), QQ(-1, 1)), (((0, 0, 0, 0), 2), -y**2 - y*t - z*t - t**2, 2),
|
| 402 |
+
((0, 1, 0, 0), 4), ((0, 1, 0, 0), QQ(1, 1)), (((0, 0, 0, 0), 4), y*z*t**2 + z**2*t**2 - t**4 - 1, 4)
|
| 403 |
+
)
|
| 404 |
+
assert critical_pair(p2, q2, R) == (
|
| 405 |
+
((0, 0, 4, 2), 2), ((0, 0, 2, 0), QQ(1, 1)), (((0, 0, 2, 2), 2), y*z + z*t**5 + z*t + t**6, 13),
|
| 406 |
+
((0, 0, 0, 5), 3), ((0, 0, 0, 3), QQ(1, 1)), (((0, 0, 0, 2), 3), z**3*t**2 + z**2*t**3 - z - t, 5)
|
| 407 |
+
)
|
| 408 |
+
|
| 409 |
+
def test_cp_key():
|
| 410 |
+
# from cyclic4 with grlex
|
| 411 |
+
R, x,y,z,t = ring("x,y,z,t", QQ, grlex)
|
| 412 |
+
|
| 413 |
+
p1 = (((0, 0, 0, 0), 4), y*z*t**2 + z**2*t**2 - t**4 - 1, 4)
|
| 414 |
+
q1 = (((0, 0, 0, 0), 2), -y**2 - y*t - z*t - t**2, 2)
|
| 415 |
+
|
| 416 |
+
p2 = (((0, 0, 0, 2), 3), z**3*t**2 + z**2*t**3 - z - t, 5)
|
| 417 |
+
q2 = (((0, 0, 2, 2), 2), y*z + z*t**5 + z*t + t**6, 13)
|
| 418 |
+
|
| 419 |
+
cp1 = critical_pair(p1, q1, R)
|
| 420 |
+
cp2 = critical_pair(p2, q2, R)
|
| 421 |
+
|
| 422 |
+
assert cp_key(cp1, R) < cp_key(cp2, R)
|
| 423 |
+
|
| 424 |
+
cp1 = critical_pair(p1, p2, R)
|
| 425 |
+
cp2 = critical_pair(q1, q2, R)
|
| 426 |
+
|
| 427 |
+
assert cp_key(cp1, R) < cp_key(cp2, R)
|
| 428 |
+
|
| 429 |
+
|
| 430 |
+
def test_is_rewritable_or_comparable():
|
| 431 |
+
# from katsura4 with grlex
|
| 432 |
+
R, x,y,z,t = ring("x,y,z,t", QQ, grlex)
|
| 433 |
+
|
| 434 |
+
p = lbp(sig((0, 0, 2, 1), 2), R.zero, 2)
|
| 435 |
+
B = [lbp(sig((0, 0, 0, 1), 2), QQ(2,45)*y**2 + QQ(1,5)*y*z + QQ(5,63)*y*t + z**2*t + QQ(4,45)*z**2 + QQ(76,35)*z*t**2 - QQ(32,105)*z*t + QQ(13,7)*t**3 - QQ(13,21)*t**2, 6)]
|
| 436 |
+
|
| 437 |
+
# rewritable:
|
| 438 |
+
assert is_rewritable_or_comparable(Sign(p), Num(p), B) is True
|
| 439 |
+
|
| 440 |
+
p = lbp(sig((0, 1, 1, 0), 2), R.zero, 7)
|
| 441 |
+
B = [lbp(sig((0, 0, 0, 0), 3), QQ(10,3)*y*z + QQ(4,3)*y*t - QQ(1,3)*y + 4*z**2 + QQ(22,3)*z*t - QQ(4,3)*z + 4*t**2 - QQ(4,3)*t, 3)]
|
| 442 |
+
|
| 443 |
+
# comparable:
|
| 444 |
+
assert is_rewritable_or_comparable(Sign(p), Num(p), B) is True
|
| 445 |
+
|
| 446 |
+
|
| 447 |
+
def test_f5_reduce():
|
| 448 |
+
# katsura3 with lex
|
| 449 |
+
R, x,y,z = ring("x,y,z", QQ, lex)
|
| 450 |
+
|
| 451 |
+
F = [(((0, 0, 0), 1), x + 2*y + 2*z - 1, 1),
|
| 452 |
+
(((0, 0, 0), 2), 6*y**2 + 8*y*z - 2*y + 6*z**2 - 2*z, 2),
|
| 453 |
+
(((0, 0, 0), 3), QQ(10,3)*y*z - QQ(1,3)*y + 4*z**2 - QQ(4,3)*z, 3),
|
| 454 |
+
(((0, 0, 1), 2), y + 30*z**3 - QQ(79,7)*z**2 + QQ(3,7)*z, 4),
|
| 455 |
+
(((0, 0, 2), 2), z**4 - QQ(10,21)*z**3 + QQ(1,84)*z**2 + QQ(1,84)*z, 5)]
|
| 456 |
+
|
| 457 |
+
cp = critical_pair(F[0], F[1], R)
|
| 458 |
+
s = s_poly(cp)
|
| 459 |
+
|
| 460 |
+
assert f5_reduce(s, F) == (((0, 2, 0), 1), R.zero, 1)
|
| 461 |
+
|
| 462 |
+
s = lbp(sig(Sign(s)[0], 100), Polyn(s), Num(s))
|
| 463 |
+
assert f5_reduce(s, F) == s
|
| 464 |
+
|
| 465 |
+
|
| 466 |
+
def test_representing_matrices():
|
| 467 |
+
R, x,y = ring("x,y", QQ, grlex)
|
| 468 |
+
|
| 469 |
+
basis = [(0, 0), (0, 1), (1, 0), (1, 1)]
|
| 470 |
+
F = [x**2 - x - 3*y + 1, -2*x + y**2 + y - 1]
|
| 471 |
+
|
| 472 |
+
assert _representing_matrices(basis, F, R) == [
|
| 473 |
+
[[QQ(0, 1), QQ(0, 1),-QQ(1, 1), QQ(3, 1)],
|
| 474 |
+
[QQ(0, 1), QQ(0, 1), QQ(3, 1),-QQ(4, 1)],
|
| 475 |
+
[QQ(1, 1), QQ(0, 1), QQ(1, 1), QQ(6, 1)],
|
| 476 |
+
[QQ(0, 1), QQ(1, 1), QQ(0, 1), QQ(1, 1)]],
|
| 477 |
+
[[QQ(0, 1), QQ(1, 1), QQ(0, 1),-QQ(2, 1)],
|
| 478 |
+
[QQ(1, 1),-QQ(1, 1), QQ(0, 1), QQ(6, 1)],
|
| 479 |
+
[QQ(0, 1), QQ(2, 1), QQ(0, 1), QQ(3, 1)],
|
| 480 |
+
[QQ(0, 1), QQ(0, 1), QQ(1, 1),-QQ(1, 1)]]]
|
| 481 |
+
|
| 482 |
+
def test_groebner_lcm():
|
| 483 |
+
R, x,y,z = ring("x,y,z", ZZ)
|
| 484 |
+
|
| 485 |
+
assert groebner_lcm(x**2 - y**2, x - y) == x**2 - y**2
|
| 486 |
+
assert groebner_lcm(2*x**2 - 2*y**2, 2*x - 2*y) == 2*x**2 - 2*y**2
|
| 487 |
+
|
| 488 |
+
R, x,y,z = ring("x,y,z", QQ)
|
| 489 |
+
|
| 490 |
+
assert groebner_lcm(x**2 - y**2, x - y) == x**2 - y**2
|
| 491 |
+
assert groebner_lcm(2*x**2 - 2*y**2, 2*x - 2*y) == 2*x**2 - 2*y**2
|
| 492 |
+
|
| 493 |
+
R, x,y = ring("x,y", ZZ)
|
| 494 |
+
|
| 495 |
+
assert groebner_lcm(x**2*y, x*y**2) == x**2*y**2
|
| 496 |
+
|
| 497 |
+
f = 2*x*y**5 - 3*x*y**4 - 2*x*y**3 + 3*x*y**2
|
| 498 |
+
g = y**5 - 2*y**3 + y
|
| 499 |
+
h = 2*x*y**7 - 3*x*y**6 - 4*x*y**5 + 6*x*y**4 + 2*x*y**3 - 3*x*y**2
|
| 500 |
+
|
| 501 |
+
assert groebner_lcm(f, g) == h
|
| 502 |
+
|
| 503 |
+
f = x**3 - 3*x**2*y - 9*x*y**2 - 5*y**3
|
| 504 |
+
g = x**4 + 6*x**3*y + 12*x**2*y**2 + 10*x*y**3 + 3*y**4
|
| 505 |
+
h = x**5 + x**4*y - 18*x**3*y**2 - 50*x**2*y**3 - 47*x*y**4 - 15*y**5
|
| 506 |
+
|
| 507 |
+
assert groebner_lcm(f, g) == h
|
| 508 |
+
|
| 509 |
+
def test_groebner_gcd():
|
| 510 |
+
R, x,y,z = ring("x,y,z", ZZ)
|
| 511 |
+
|
| 512 |
+
assert groebner_gcd(x**2 - y**2, x - y) == x - y
|
| 513 |
+
assert groebner_gcd(2*x**2 - 2*y**2, 2*x - 2*y) == 2*x - 2*y
|
| 514 |
+
|
| 515 |
+
R, x,y,z = ring("x,y,z", QQ)
|
| 516 |
+
|
| 517 |
+
assert groebner_gcd(x**2 - y**2, x - y) == x - y
|
| 518 |
+
assert groebner_gcd(2*x**2 - 2*y**2, 2*x - 2*y) == x - y
|
| 519 |
+
|
| 520 |
+
def test_is_groebner():
|
| 521 |
+
R, x,y = ring("x,y", QQ, grlex)
|
| 522 |
+
valid_groebner = [x**2, x*y, -QQ(1,2)*x + y**2]
|
| 523 |
+
invalid_groebner = [x**3, x*y, -QQ(1,2)*x + y**2]
|
| 524 |
+
assert is_groebner(valid_groebner, R) is True
|
| 525 |
+
assert is_groebner(invalid_groebner, R) is False
|
| 526 |
+
|
| 527 |
+
def test_is_reduced():
|
| 528 |
+
R, x, y = ring("x,y", QQ, lex)
|
| 529 |
+
f = x**2 + 2*x*y**2
|
| 530 |
+
g = x*y + 2*y**3 - 1
|
| 531 |
+
assert is_reduced([f, g], R) == False
|
| 532 |
+
G = groebner([f, g], R)
|
| 533 |
+
assert is_reduced(G, R) == True
|
shared/package-files/65/656751b26fbee66b4f8ed9801ffefed090509af4147c06dafd56d1795c805488/blob
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Any, Optional
|
| 2 |
+
|
| 3 |
+
def release_local(local): ...
|
| 4 |
+
|
| 5 |
+
class Local:
|
| 6 |
+
def __init__(self): ...
|
| 7 |
+
def __iter__(self): ...
|
| 8 |
+
def __call__(self, proxy): ...
|
| 9 |
+
def __release_local__(self): ...
|
| 10 |
+
def __getattr__(self, name): ...
|
| 11 |
+
def __setattr__(self, name, value): ...
|
| 12 |
+
def __delattr__(self, name): ...
|
| 13 |
+
|
| 14 |
+
class LocalStack:
|
| 15 |
+
def __init__(self): ...
|
| 16 |
+
def __release_local__(self): ...
|
| 17 |
+
def _get__ident_func__(self): ...
|
| 18 |
+
def _set__ident_func__(self, value): ...
|
| 19 |
+
__ident_func__: Any
|
| 20 |
+
def __call__(self): ...
|
| 21 |
+
def push(self, obj): ...
|
| 22 |
+
def pop(self): ...
|
| 23 |
+
@property
|
| 24 |
+
def top(self): ...
|
| 25 |
+
|
| 26 |
+
class LocalManager:
|
| 27 |
+
locals: Any
|
| 28 |
+
ident_func: Any
|
| 29 |
+
def __init__(self, locals: Optional[Any] = ..., ident_func: Optional[Any] = ...): ...
|
| 30 |
+
def get_ident(self): ...
|
| 31 |
+
def cleanup(self): ...
|
| 32 |
+
def make_middleware(self, app): ...
|
| 33 |
+
def middleware(self, func): ...
|
| 34 |
+
|
| 35 |
+
class LocalProxy:
|
| 36 |
+
def __init__(self, local, name: Optional[Any] = ...): ...
|
| 37 |
+
@property
|
| 38 |
+
def __dict__(self): ...
|
| 39 |
+
def __bool__(self): ...
|
| 40 |
+
def __unicode__(self): ...
|
| 41 |
+
def __dir__(self): ...
|
| 42 |
+
def __getattr__(self, name): ...
|
| 43 |
+
def __setitem__(self, key, value): ...
|
| 44 |
+
def __delitem__(self, key): ...
|
| 45 |
+
__getslice__: Any
|
| 46 |
+
def __setslice__(self, i, j, seq): ...
|
| 47 |
+
def __delslice__(self, i, j): ...
|
| 48 |
+
__setattr__: Any
|
| 49 |
+
__delattr__: Any
|
| 50 |
+
__lt__: Any
|
| 51 |
+
__le__: Any
|
| 52 |
+
__eq__: Any
|
| 53 |
+
__ne__: Any
|
| 54 |
+
__gt__: Any
|
| 55 |
+
__ge__: Any
|
| 56 |
+
__cmp__: Any
|
| 57 |
+
__hash__: Any
|
| 58 |
+
__call__: Any
|
| 59 |
+
__len__: Any
|
| 60 |
+
__getitem__: Any
|
| 61 |
+
__iter__: Any
|
| 62 |
+
__contains__: Any
|
| 63 |
+
__add__: Any
|
| 64 |
+
__sub__: Any
|
| 65 |
+
__mul__: Any
|
| 66 |
+
__floordiv__: Any
|
| 67 |
+
__mod__: Any
|
| 68 |
+
__divmod__: Any
|
| 69 |
+
__pow__: Any
|
| 70 |
+
__lshift__: Any
|
| 71 |
+
__rshift__: Any
|
| 72 |
+
__and__: Any
|
| 73 |
+
__xor__: Any
|
| 74 |
+
__or__: Any
|
| 75 |
+
__div__: Any
|
| 76 |
+
__truediv__: Any
|
| 77 |
+
__neg__: Any
|
| 78 |
+
__pos__: Any
|
| 79 |
+
__abs__: Any
|
| 80 |
+
__invert__: Any
|
| 81 |
+
__complex__: Any
|
| 82 |
+
__int__: Any
|
| 83 |
+
__long__: Any
|
| 84 |
+
__float__: Any
|
| 85 |
+
__oct__: Any
|
| 86 |
+
__hex__: Any
|
| 87 |
+
__index__: Any
|
| 88 |
+
__coerce__: Any
|
| 89 |
+
__enter__: Any
|
| 90 |
+
__exit__: Any
|
| 91 |
+
__radd__: Any
|
| 92 |
+
__rsub__: Any
|
| 93 |
+
__rmul__: Any
|
| 94 |
+
__rdiv__: Any
|
| 95 |
+
__rtruediv__: Any
|
| 96 |
+
__rfloordiv__: Any
|
| 97 |
+
__rmod__: Any
|
| 98 |
+
__rdivmod__: Any
|
| 99 |
+
__copy__: Any
|
| 100 |
+
__deepcopy__: Any
|
shared/package-files/65/6569586c61e36fe4304691f7490f6ebb19ff5fe1768a1710092e47b53fd6f659/blob
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
def disable_importlib_metadata_finder(metadata):
|
| 5 |
+
"""
|
| 6 |
+
Ensure importlib_metadata doesn't provide older, incompatible
|
| 7 |
+
Distributions.
|
| 8 |
+
|
| 9 |
+
Workaround for #3102.
|
| 10 |
+
"""
|
| 11 |
+
try:
|
| 12 |
+
import importlib_metadata
|
| 13 |
+
except ImportError:
|
| 14 |
+
return
|
| 15 |
+
except AttributeError:
|
| 16 |
+
from .warnings import SetuptoolsWarning
|
| 17 |
+
|
| 18 |
+
SetuptoolsWarning.emit(
|
| 19 |
+
"Incompatibility problem.",
|
| 20 |
+
"""
|
| 21 |
+
`importlib-metadata` version is incompatible with `setuptools`.
|
| 22 |
+
This problem is likely to be solved by installing an updated version of
|
| 23 |
+
`importlib-metadata`.
|
| 24 |
+
""",
|
| 25 |
+
see_url="https://github.com/python/importlib_metadata/issues/396",
|
| 26 |
+
) # Ensure a descriptive message is shown.
|
| 27 |
+
raise # This exception can be suppressed by _distutils_hack
|
| 28 |
+
|
| 29 |
+
if importlib_metadata is metadata:
|
| 30 |
+
return
|
| 31 |
+
to_remove = [
|
| 32 |
+
ob
|
| 33 |
+
for ob in sys.meta_path
|
| 34 |
+
if isinstance(ob, importlib_metadata.MetadataPathFinder)
|
| 35 |
+
]
|
| 36 |
+
for item in to_remove:
|
| 37 |
+
sys.meta_path.remove(item)
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
if sys.version_info < (3, 10):
|
| 41 |
+
from setuptools.extern import importlib_metadata as metadata
|
| 42 |
+
|
| 43 |
+
disable_importlib_metadata_finder(metadata)
|
| 44 |
+
else:
|
| 45 |
+
import importlib.metadata as metadata # noqa: F401
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
if sys.version_info < (3, 9):
|
| 49 |
+
from setuptools.extern import importlib_resources as resources
|
| 50 |
+
else:
|
| 51 |
+
import importlib.resources as resources # noqa: F401
|
shared/package-files/65/6569619bf0690d6073fd2753ad7b249efd6ff97838f74b008793206dd4a856f9/blob
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Dict
|
| 2 |
+
|
| 3 |
+
import torch
|
| 4 |
+
from torch.distributions import constraints
|
| 5 |
+
from torch.distributions.distribution import Distribution
|
| 6 |
+
from torch.distributions.utils import _sum_rightmost
|
| 7 |
+
|
| 8 |
+
__all__ = ["Independent"]
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
class Independent(Distribution):
|
| 12 |
+
r"""
|
| 13 |
+
Reinterprets some of the batch dims of a distribution as event dims.
|
| 14 |
+
|
| 15 |
+
This is mainly useful for changing the shape of the result of
|
| 16 |
+
:meth:`log_prob`. For example to create a diagonal Normal distribution with
|
| 17 |
+
the same shape as a Multivariate Normal distribution (so they are
|
| 18 |
+
interchangeable), you can::
|
| 19 |
+
|
| 20 |
+
>>> from torch.distributions.multivariate_normal import MultivariateNormal
|
| 21 |
+
>>> from torch.distributions.normal import Normal
|
| 22 |
+
>>> loc = torch.zeros(3)
|
| 23 |
+
>>> scale = torch.ones(3)
|
| 24 |
+
>>> mvn = MultivariateNormal(loc, scale_tril=torch.diag(scale))
|
| 25 |
+
>>> [mvn.batch_shape, mvn.event_shape]
|
| 26 |
+
[torch.Size([]), torch.Size([3])]
|
| 27 |
+
>>> normal = Normal(loc, scale)
|
| 28 |
+
>>> [normal.batch_shape, normal.event_shape]
|
| 29 |
+
[torch.Size([3]), torch.Size([])]
|
| 30 |
+
>>> diagn = Independent(normal, 1)
|
| 31 |
+
>>> [diagn.batch_shape, diagn.event_shape]
|
| 32 |
+
[torch.Size([]), torch.Size([3])]
|
| 33 |
+
|
| 34 |
+
Args:
|
| 35 |
+
base_distribution (torch.distributions.distribution.Distribution): a
|
| 36 |
+
base distribution
|
| 37 |
+
reinterpreted_batch_ndims (int): the number of batch dims to
|
| 38 |
+
reinterpret as event dims
|
| 39 |
+
"""
|
| 40 |
+
arg_constraints: Dict[str, constraints.Constraint] = {}
|
| 41 |
+
|
| 42 |
+
def __init__(
|
| 43 |
+
self, base_distribution, reinterpreted_batch_ndims, validate_args=None
|
| 44 |
+
):
|
| 45 |
+
if reinterpreted_batch_ndims > len(base_distribution.batch_shape):
|
| 46 |
+
raise ValueError(
|
| 47 |
+
"Expected reinterpreted_batch_ndims <= len(base_distribution.batch_shape), "
|
| 48 |
+
f"actual {reinterpreted_batch_ndims} vs {len(base_distribution.batch_shape)}"
|
| 49 |
+
)
|
| 50 |
+
shape = base_distribution.batch_shape + base_distribution.event_shape
|
| 51 |
+
event_dim = reinterpreted_batch_ndims + len(base_distribution.event_shape)
|
| 52 |
+
batch_shape = shape[: len(shape) - event_dim]
|
| 53 |
+
event_shape = shape[len(shape) - event_dim :]
|
| 54 |
+
self.base_dist = base_distribution
|
| 55 |
+
self.reinterpreted_batch_ndims = reinterpreted_batch_ndims
|
| 56 |
+
super().__init__(batch_shape, event_shape, validate_args=validate_args)
|
| 57 |
+
|
| 58 |
+
def expand(self, batch_shape, _instance=None):
|
| 59 |
+
new = self._get_checked_instance(Independent, _instance)
|
| 60 |
+
batch_shape = torch.Size(batch_shape)
|
| 61 |
+
new.base_dist = self.base_dist.expand(
|
| 62 |
+
batch_shape + self.event_shape[: self.reinterpreted_batch_ndims]
|
| 63 |
+
)
|
| 64 |
+
new.reinterpreted_batch_ndims = self.reinterpreted_batch_ndims
|
| 65 |
+
super(Independent, new).__init__(
|
| 66 |
+
batch_shape, self.event_shape, validate_args=False
|
| 67 |
+
)
|
| 68 |
+
new._validate_args = self._validate_args
|
| 69 |
+
return new
|
| 70 |
+
|
| 71 |
+
@property
|
| 72 |
+
def has_rsample(self):
|
| 73 |
+
return self.base_dist.has_rsample
|
| 74 |
+
|
| 75 |
+
@property
|
| 76 |
+
def has_enumerate_support(self):
|
| 77 |
+
if self.reinterpreted_batch_ndims > 0:
|
| 78 |
+
return False
|
| 79 |
+
return self.base_dist.has_enumerate_support
|
| 80 |
+
|
| 81 |
+
@constraints.dependent_property
|
| 82 |
+
def support(self):
|
| 83 |
+
result = self.base_dist.support
|
| 84 |
+
if self.reinterpreted_batch_ndims:
|
| 85 |
+
result = constraints.independent(result, self.reinterpreted_batch_ndims)
|
| 86 |
+
return result
|
| 87 |
+
|
| 88 |
+
@property
|
| 89 |
+
def mean(self):
|
| 90 |
+
return self.base_dist.mean
|
| 91 |
+
|
| 92 |
+
@property
|
| 93 |
+
def mode(self):
|
| 94 |
+
return self.base_dist.mode
|
| 95 |
+
|
| 96 |
+
@property
|
| 97 |
+
def variance(self):
|
| 98 |
+
return self.base_dist.variance
|
| 99 |
+
|
| 100 |
+
def sample(self, sample_shape=torch.Size()):
|
| 101 |
+
return self.base_dist.sample(sample_shape)
|
| 102 |
+
|
| 103 |
+
def rsample(self, sample_shape=torch.Size()):
|
| 104 |
+
return self.base_dist.rsample(sample_shape)
|
| 105 |
+
|
| 106 |
+
def log_prob(self, value):
|
| 107 |
+
log_prob = self.base_dist.log_prob(value)
|
| 108 |
+
return _sum_rightmost(log_prob, self.reinterpreted_batch_ndims)
|
| 109 |
+
|
| 110 |
+
def entropy(self):
|
| 111 |
+
entropy = self.base_dist.entropy()
|
| 112 |
+
return _sum_rightmost(entropy, self.reinterpreted_batch_ndims)
|
| 113 |
+
|
| 114 |
+
def enumerate_support(self, expand=True):
|
| 115 |
+
if self.reinterpreted_batch_ndims > 0:
|
| 116 |
+
raise NotImplementedError(
|
| 117 |
+
"Enumeration over cartesian product is not implemented"
|
| 118 |
+
)
|
| 119 |
+
return self.base_dist.enumerate_support(expand=expand)
|
| 120 |
+
|
| 121 |
+
def __repr__(self):
|
| 122 |
+
return (
|
| 123 |
+
self.__class__.__name__
|
| 124 |
+
+ f"({self.base_dist}, {self.reinterpreted_batch_ndims})"
|
| 125 |
+
)
|
shared/package-files/65/656cd3a27fe3b73475a1fc9becaf4a4d06d25b482904d8dab14429787a23657d/blob
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
4.6.0
|
shared/package-files/65/6570168dd003a845a0766d1a9290a3570b9b5df55fa4381ba9eb7d643a30e37c/blob
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
shared/package-files/65/65702a9eff6686f57740731d4b0ccaa6b40e4806bead28b7a5c001934698ddae/blob
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/utils/pybind.h>
|
| 4 |
+
|
| 5 |
+
namespace torch::onnx {
|
| 6 |
+
|
| 7 |
+
void initONNXBindings(PyObject* module);
|
| 8 |
+
|
| 9 |
+
} // namespace torch::onnx
|
shared/package-files/65/6571dd3f6ade69c55980dea5a98b31894f9e8f02cb9a1fe650d5f6d8e2f0f076/blob
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// @generated by torchgen/gen.py from Operator.h
|
| 4 |
+
|
| 5 |
+
#include <tuple>
|
| 6 |
+
#include <vector>
|
| 7 |
+
|
| 8 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 9 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 10 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 11 |
+
#include <ATen/core/ATen_fwd.h>
|
| 12 |
+
|
| 13 |
+
namespace at {
|
| 14 |
+
namespace _ops {
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
struct TORCH_API hypot_out {
|
| 18 |
+
using schema = at::Tensor & (const at::Tensor &, const at::Tensor &, at::Tensor &);
|
| 19 |
+
using ptr_schema = schema*;
|
| 20 |
+
// See Note [static constexpr char* members for windows NVCC]
|
| 21 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::hypot")
|
| 22 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "out")
|
| 23 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "hypot.out(Tensor self, Tensor other, *, Tensor(a!) out) -> Tensor(a!)")
|
| 24 |
+
static at::Tensor & call(const at::Tensor & self, const at::Tensor & other, at::Tensor & out);
|
| 25 |
+
static at::Tensor & redispatch(c10::DispatchKeySet dispatchKeySet, const at::Tensor & self, const at::Tensor & other, at::Tensor & out);
|
| 26 |
+
};
|
| 27 |
+
|
| 28 |
+
struct TORCH_API hypot {
|
| 29 |
+
using schema = at::Tensor (const at::Tensor &, const at::Tensor &);
|
| 30 |
+
using ptr_schema = schema*;
|
| 31 |
+
// See Note [static constexpr char* members for windows NVCC]
|
| 32 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::hypot")
|
| 33 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "")
|
| 34 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "hypot(Tensor self, Tensor other) -> Tensor")
|
| 35 |
+
static at::Tensor call(const at::Tensor & self, const at::Tensor & other);
|
| 36 |
+
static at::Tensor redispatch(c10::DispatchKeySet dispatchKeySet, const at::Tensor & self, const at::Tensor & other);
|
| 37 |
+
};
|
| 38 |
+
|
| 39 |
+
struct TORCH_API hypot_ {
|
| 40 |
+
using schema = at::Tensor & (at::Tensor &, const at::Tensor &);
|
| 41 |
+
using ptr_schema = schema*;
|
| 42 |
+
// See Note [static constexpr char* members for windows NVCC]
|
| 43 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::hypot_")
|
| 44 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "")
|
| 45 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "hypot_(Tensor(a!) self, Tensor other) -> Tensor(a!)")
|
| 46 |
+
static at::Tensor & call(at::Tensor & self, const at::Tensor & other);
|
| 47 |
+
static at::Tensor & redispatch(c10::DispatchKeySet dispatchKeySet, at::Tensor & self, const at::Tensor & other);
|
| 48 |
+
};
|
| 49 |
+
|
| 50 |
+
}} // namespace at::_ops
|
shared/package-files/65/65720ce3d60b6672e210c490956b7db94cd7e9fc603571f91c843005585c9de2/blob
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from _typeshed import SupportsLessThan
|
| 2 |
+
from typing import Any, Callable, Iterable, List, Optional, TypeVar
|
| 3 |
+
|
| 4 |
+
_T = TypeVar("_T")
|
| 5 |
+
|
| 6 |
+
def heappush(__heap: List[_T], __item: _T) -> None: ...
|
| 7 |
+
def heappop(__heap: List[_T]) -> _T: ...
|
| 8 |
+
def heappushpop(__heap: List[_T], __item: _T) -> _T: ...
|
| 9 |
+
def heapify(__heap: List[_T]) -> None: ...
|
| 10 |
+
def heapreplace(__heap: List[_T], __item: _T) -> _T: ...
|
| 11 |
+
def merge(*iterables: Iterable[_T], key: Optional[Callable[[_T], Any]] = ..., reverse: bool = ...) -> Iterable[_T]: ...
|
| 12 |
+
def nlargest(n: int, iterable: Iterable[_T], key: Optional[Callable[[_T], SupportsLessThan]] = ...) -> List[_T]: ...
|
| 13 |
+
def nsmallest(n: int, iterable: Iterable[_T], key: Optional[Callable[[_T], SupportsLessThan]] = ...) -> List[_T]: ...
|
| 14 |
+
def _heapify_max(__x: List[_T]) -> None: ... # undocumented
|
shared/package-files/65/657312539a4a73294c95f8c0583ea778dc2c6d96cf29aa362b9984bf1e1d4f96/blob
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
// @generated by torchgen/gen.py from DispatchKeyFunction.h
|
| 3 |
+
|
| 4 |
+
// NB: The implementing C++ file is RegisterDispatchKey.cpp
|
| 5 |
+
|
| 6 |
+
// The only #includes we need are for custom classes that have defaults in the C++ API
|
| 7 |
+
#include <c10/core/MemoryFormat.h>
|
| 8 |
+
#include <c10/core/Scalar.h>
|
| 9 |
+
#include <ATen/core/Reduction.h>
|
| 10 |
+
|
| 11 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 12 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 13 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 14 |
+
#include <ATen/core/ATen_fwd.h>
|
| 15 |
+
|
| 16 |
+
namespace at {
|
| 17 |
+
|
| 18 |
+
namespace compositeexplicitautograd {
|
| 19 |
+
|
| 20 |
+
TORCH_API ::std::tuple<at::Tensor &,at::Tensor &> fake_quantize_per_channel_affine_cachemask_out(at::Tensor & out0, at::Tensor & out1, const at::Tensor & self, const at::Tensor & scale, const at::Tensor & zero_point, int64_t axis, int64_t quant_min, int64_t quant_max);
|
| 21 |
+
TORCH_API ::std::tuple<at::Tensor &,at::Tensor &> fake_quantize_per_channel_affine_cachemask_outf(const at::Tensor & self, const at::Tensor & scale, const at::Tensor & zero_point, int64_t axis, int64_t quant_min, int64_t quant_max, at::Tensor & out0, at::Tensor & out1);
|
| 22 |
+
|
| 23 |
+
} // namespace compositeexplicitautograd
|
| 24 |
+
} // namespace at
|
shared/package-files/65/6574e88cfe15e4a95ef7a40e161c42663abe7507fa807bcd3a8ad8c8eb853f52/blob
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from types import SimpleNamespace
|
| 2 |
+
|
| 3 |
+
import pytest
|
| 4 |
+
|
| 5 |
+
from pandas.core.dtypes.common import is_float
|
| 6 |
+
|
| 7 |
+
import pandas._testing as tm
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def test_assert_attr_equal(nulls_fixture):
|
| 11 |
+
obj = SimpleNamespace()
|
| 12 |
+
obj.na_value = nulls_fixture
|
| 13 |
+
tm.assert_attr_equal("na_value", obj, obj)
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def test_assert_attr_equal_different_nulls(nulls_fixture, nulls_fixture2):
|
| 17 |
+
obj = SimpleNamespace()
|
| 18 |
+
obj.na_value = nulls_fixture
|
| 19 |
+
|
| 20 |
+
obj2 = SimpleNamespace()
|
| 21 |
+
obj2.na_value = nulls_fixture2
|
| 22 |
+
|
| 23 |
+
if nulls_fixture is nulls_fixture2:
|
| 24 |
+
tm.assert_attr_equal("na_value", obj, obj2)
|
| 25 |
+
elif is_float(nulls_fixture) and is_float(nulls_fixture2):
|
| 26 |
+
# we consider float("nan") and np.float64("nan") to be equivalent
|
| 27 |
+
tm.assert_attr_equal("na_value", obj, obj2)
|
| 28 |
+
elif type(nulls_fixture) is type(nulls_fixture2):
|
| 29 |
+
# e.g. Decimal("NaN")
|
| 30 |
+
tm.assert_attr_equal("na_value", obj, obj2)
|
| 31 |
+
else:
|
| 32 |
+
with pytest.raises(AssertionError, match='"na_value" are different'):
|
| 33 |
+
tm.assert_attr_equal("na_value", obj, obj2)
|
shared/package-files/65/6576a82fd591eb453c4f3d594ab9fc5e038c2414bbf1d74d070692a3fe48585e/blob
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// @generated by torchgen/gen.py from Operator.h
|
| 4 |
+
|
| 5 |
+
#include <tuple>
|
| 6 |
+
#include <vector>
|
| 7 |
+
|
| 8 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 9 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 10 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 11 |
+
#include <ATen/core/ATen_fwd.h>
|
| 12 |
+
|
| 13 |
+
namespace at {
|
| 14 |
+
namespace _ops {
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
struct TORCH_API _fake_quantize_learnable_per_channel_affine_backward {
|
| 18 |
+
using schema = ::std::tuple<at::Tensor,at::Tensor,at::Tensor> (const at::Tensor &, const at::Tensor &, const at::Tensor &, const at::Tensor &, int64_t, int64_t, int64_t, double);
|
| 19 |
+
using ptr_schema = schema*;
|
| 20 |
+
// See Note [static constexpr char* members for windows NVCC]
|
| 21 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::_fake_quantize_learnable_per_channel_affine_backward")
|
| 22 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "")
|
| 23 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "_fake_quantize_learnable_per_channel_affine_backward(Tensor grad, Tensor self, Tensor scale, Tensor zero_point, int axis, int quant_min, int quant_max, float grad_factor=1.0) -> (Tensor, Tensor, Tensor)")
|
| 24 |
+
static ::std::tuple<at::Tensor,at::Tensor,at::Tensor> call(const at::Tensor & grad, const at::Tensor & self, const at::Tensor & scale, const at::Tensor & zero_point, int64_t axis, int64_t quant_min, int64_t quant_max, double grad_factor);
|
| 25 |
+
static ::std::tuple<at::Tensor,at::Tensor,at::Tensor> redispatch(c10::DispatchKeySet dispatchKeySet, const at::Tensor & grad, const at::Tensor & self, const at::Tensor & scale, const at::Tensor & zero_point, int64_t axis, int64_t quant_min, int64_t quant_max, double grad_factor);
|
| 26 |
+
};
|
| 27 |
+
|
| 28 |
+
}} // namespace at::_ops
|
shared/package-files/65/6576ba04d8017df3b1862cf77c8a8a60b68858a27935d77d5b63bcc54f583ec5/blob
ADDED
|
@@ -0,0 +1,694 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import datetime as dt
|
| 4 |
+
from decimal import Decimal
|
| 5 |
+
from functools import wraps
|
| 6 |
+
from typing import TYPE_CHECKING, Any, Literal, TypeVar, overload
|
| 7 |
+
|
| 8 |
+
from narwhals import plugins
|
| 9 |
+
from narwhals._constants import EPOCH, MS_PER_SECOND
|
| 10 |
+
from narwhals._native import (
|
| 11 |
+
is_native_arrow,
|
| 12 |
+
is_native_pandas_like,
|
| 13 |
+
is_native_polars,
|
| 14 |
+
is_native_spark_like,
|
| 15 |
+
)
|
| 16 |
+
from narwhals._utils import (
|
| 17 |
+
Implementation,
|
| 18 |
+
Version,
|
| 19 |
+
has_native_namespace,
|
| 20 |
+
is_compliant_dataframe,
|
| 21 |
+
is_compliant_lazyframe,
|
| 22 |
+
is_compliant_series,
|
| 23 |
+
)
|
| 24 |
+
from narwhals.dependencies import (
|
| 25 |
+
get_dask_expr,
|
| 26 |
+
get_numpy,
|
| 27 |
+
get_pandas,
|
| 28 |
+
is_cupy_scalar,
|
| 29 |
+
is_dask_dataframe,
|
| 30 |
+
is_duckdb_relation,
|
| 31 |
+
is_ibis_table,
|
| 32 |
+
is_numpy_scalar,
|
| 33 |
+
is_pandas_like_dataframe,
|
| 34 |
+
is_polars_lazyframe,
|
| 35 |
+
is_polars_series,
|
| 36 |
+
is_pyarrow_scalar,
|
| 37 |
+
is_pyarrow_table,
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
if TYPE_CHECKING:
|
| 41 |
+
from collections.abc import Callable
|
| 42 |
+
|
| 43 |
+
from typing_extensions import Unpack
|
| 44 |
+
|
| 45 |
+
from narwhals._translate import (
|
| 46 |
+
AllowAny,
|
| 47 |
+
AllowLazy,
|
| 48 |
+
AllowSeries,
|
| 49 |
+
ExcludeSeries,
|
| 50 |
+
OnlySeries,
|
| 51 |
+
PassThroughUnknown,
|
| 52 |
+
)
|
| 53 |
+
from narwhals.dataframe import DataFrame, LazyFrame
|
| 54 |
+
from narwhals.series import Series
|
| 55 |
+
from narwhals.typing import (
|
| 56 |
+
DataFrameT,
|
| 57 |
+
Frame,
|
| 58 |
+
IntoDataFrameT,
|
| 59 |
+
IntoFrame,
|
| 60 |
+
IntoLazyFrameT,
|
| 61 |
+
IntoSeries,
|
| 62 |
+
IntoSeriesT,
|
| 63 |
+
LazyFrameT,
|
| 64 |
+
SeriesT,
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
T = TypeVar("T")
|
| 68 |
+
|
| 69 |
+
NON_TEMPORAL_SCALAR_TYPES = (bool, bytes, str, int, float, complex, Decimal)
|
| 70 |
+
TEMPORAL_SCALAR_TYPES = (dt.date, dt.timedelta, dt.time)
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
@overload
|
| 74 |
+
def to_native(
|
| 75 |
+
narwhals_object: DataFrame[IntoDataFrameT], *, pass_through: Literal[False] = ...
|
| 76 |
+
) -> IntoDataFrameT: ...
|
| 77 |
+
@overload
|
| 78 |
+
def to_native(
|
| 79 |
+
narwhals_object: LazyFrame[IntoLazyFrameT], *, pass_through: Literal[False] = ...
|
| 80 |
+
) -> IntoLazyFrameT: ...
|
| 81 |
+
@overload
|
| 82 |
+
def to_native(
|
| 83 |
+
narwhals_object: Series[IntoSeriesT], *, pass_through: Literal[False] = ...
|
| 84 |
+
) -> IntoSeriesT: ...
|
| 85 |
+
@overload
|
| 86 |
+
def to_native(narwhals_object: Any, *, pass_through: bool) -> Any: ...
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
def to_native(
|
| 90 |
+
narwhals_object: DataFrame[IntoDataFrameT]
|
| 91 |
+
| LazyFrame[IntoLazyFrameT]
|
| 92 |
+
| Series[IntoSeriesT],
|
| 93 |
+
*,
|
| 94 |
+
pass_through: bool = False,
|
| 95 |
+
) -> IntoDataFrameT | IntoLazyFrameT | IntoSeriesT | Any:
|
| 96 |
+
"""Convert Narwhals object to native one.
|
| 97 |
+
|
| 98 |
+
Arguments:
|
| 99 |
+
narwhals_object: Narwhals object.
|
| 100 |
+
pass_through: Determine what happens if `narwhals_object` isn't a Narwhals class
|
| 101 |
+
|
| 102 |
+
- `False` (default): raise an error
|
| 103 |
+
- `True`: pass object through as-is
|
| 104 |
+
|
| 105 |
+
Returns:
|
| 106 |
+
Object of class that user started with.
|
| 107 |
+
"""
|
| 108 |
+
from narwhals.dataframe import BaseFrame
|
| 109 |
+
from narwhals.series import Series
|
| 110 |
+
|
| 111 |
+
if isinstance(narwhals_object, BaseFrame):
|
| 112 |
+
return narwhals_object._compliant_frame._native_frame
|
| 113 |
+
if isinstance(narwhals_object, Series):
|
| 114 |
+
return narwhals_object._compliant_series.native
|
| 115 |
+
|
| 116 |
+
if not pass_through:
|
| 117 |
+
msg = f"Expected Narwhals object, got {type(narwhals_object)}."
|
| 118 |
+
raise TypeError(msg)
|
| 119 |
+
return narwhals_object
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
@overload
|
| 123 |
+
def from_native(native_object: SeriesT, **kwds: Unpack[OnlySeries]) -> SeriesT: ...
|
| 124 |
+
@overload
|
| 125 |
+
def from_native(native_object: SeriesT, **kwds: Unpack[AllowSeries]) -> SeriesT: ...
|
| 126 |
+
@overload
|
| 127 |
+
def from_native(
|
| 128 |
+
native_object: DataFrameT, **kwds: Unpack[ExcludeSeries]
|
| 129 |
+
) -> DataFrameT: ...
|
| 130 |
+
# Closer to *intended* than https://github.com/narwhals-dev/narwhals/issues/3226
|
| 131 |
+
@overload
|
| 132 |
+
def from_native(native_object: LazyFrameT, **kwds: Unpack[AllowLazy]) -> LazyFrameT: ...
|
| 133 |
+
@overload
|
| 134 |
+
def from_native(
|
| 135 |
+
native_object: IntoDataFrameT, **kwds: Unpack[ExcludeSeries]
|
| 136 |
+
) -> DataFrame[IntoDataFrameT]: ...
|
| 137 |
+
@overload
|
| 138 |
+
def from_native(
|
| 139 |
+
native_object: IntoSeriesT, **kwds: Unpack[OnlySeries]
|
| 140 |
+
) -> Series[IntoSeriesT]: ...
|
| 141 |
+
@overload
|
| 142 |
+
def from_native(
|
| 143 |
+
native_object: IntoSeriesT, **kwds: Unpack[AllowSeries]
|
| 144 |
+
) -> Series[IntoSeriesT]: ...
|
| 145 |
+
@overload
|
| 146 |
+
def from_native(
|
| 147 |
+
native_object: IntoLazyFrameT, **kwds: Unpack[AllowLazy]
|
| 148 |
+
) -> LazyFrame[IntoLazyFrameT]: ...
|
| 149 |
+
@overload
|
| 150 |
+
def from_native(
|
| 151 |
+
native_object: IntoDataFrameT | IntoSeriesT, **kwds: Unpack[AllowSeries]
|
| 152 |
+
) -> DataFrame[IntoDataFrameT] | Series[IntoSeriesT]: ...
|
| 153 |
+
@overload
|
| 154 |
+
def from_native(
|
| 155 |
+
native_object: IntoDataFrameT | IntoLazyFrameT | IntoSeriesT, **kwds: Unpack[AllowAny]
|
| 156 |
+
) -> DataFrame[IntoDataFrameT] | LazyFrame[IntoLazyFrameT] | Series[IntoSeriesT]: ...
|
| 157 |
+
@overload
|
| 158 |
+
def from_native(native_object: T, **kwds: Unpack[PassThroughUnknown]) -> T: ...
|
| 159 |
+
# All params passed in as variables
|
| 160 |
+
@overload
|
| 161 |
+
def from_native(
|
| 162 |
+
native_object: Any,
|
| 163 |
+
*,
|
| 164 |
+
pass_through: bool,
|
| 165 |
+
eager_only: bool,
|
| 166 |
+
series_only: bool,
|
| 167 |
+
allow_series: bool | None,
|
| 168 |
+
) -> Any: ...
|
| 169 |
+
def from_native(
|
| 170 |
+
native_object: IntoLazyFrameT
|
| 171 |
+
| IntoDataFrameT
|
| 172 |
+
| IntoSeriesT
|
| 173 |
+
| IntoFrame
|
| 174 |
+
| IntoSeries
|
| 175 |
+
| T,
|
| 176 |
+
*,
|
| 177 |
+
pass_through: bool = False,
|
| 178 |
+
eager_only: bool = False,
|
| 179 |
+
series_only: bool = False,
|
| 180 |
+
allow_series: bool | None = None,
|
| 181 |
+
) -> LazyFrame[IntoLazyFrameT] | DataFrame[IntoDataFrameT] | Series[IntoSeriesT] | T:
|
| 182 |
+
"""Convert `native_object` to Narwhals Dataframe, Lazyframe, or Series.
|
| 183 |
+
|
| 184 |
+
Arguments:
|
| 185 |
+
native_object: Raw object from user.
|
| 186 |
+
Depending on the other arguments, input object can be
|
| 187 |
+
|
| 188 |
+
- a Dataframe / Lazyframe / Series supported by Narwhals (pandas, Polars, PyArrow, ...)
|
| 189 |
+
- an object which implements `__narwhals_dataframe__`, `__narwhals_lazyframe__`,
|
| 190 |
+
or `__narwhals_series__`
|
| 191 |
+
pass_through: Determine what happens if the object can't be converted to Narwhals
|
| 192 |
+
|
| 193 |
+
- `False` (default): raise an error
|
| 194 |
+
- `True`: pass object through as-is
|
| 195 |
+
eager_only: Whether to only allow eager objects
|
| 196 |
+
|
| 197 |
+
- `False` (default): don't require `native_object` to be eager
|
| 198 |
+
- `True`: only convert to Narwhals if `native_object` is eager
|
| 199 |
+
series_only: Whether to only allow Series
|
| 200 |
+
|
| 201 |
+
- `False` (default): don't require `native_object` to be a Series
|
| 202 |
+
- `True`: only convert to Narwhals if `native_object` is a Series
|
| 203 |
+
allow_series: Whether to allow Series (default is only Dataframe / Lazyframe)
|
| 204 |
+
|
| 205 |
+
- `False` or `None` (default): don't convert to Narwhals if `native_object` is a Series
|
| 206 |
+
- `True`: allow `native_object` to be a Series
|
| 207 |
+
|
| 208 |
+
Returns:
|
| 209 |
+
DataFrame, LazyFrame, Series, or original object, depending
|
| 210 |
+
on which combination of parameters was passed.
|
| 211 |
+
"""
|
| 212 |
+
return _from_native_impl( # type: ignore[no-any-return]
|
| 213 |
+
native_object,
|
| 214 |
+
pass_through=pass_through,
|
| 215 |
+
eager_only=eager_only,
|
| 216 |
+
eager_or_interchange_only=False,
|
| 217 |
+
series_only=series_only,
|
| 218 |
+
allow_series=allow_series,
|
| 219 |
+
version=Version.MAIN,
|
| 220 |
+
)
|
| 221 |
+
|
| 222 |
+
|
| 223 |
+
def _translate_if_compliant( # noqa: C901,PLR0911
|
| 224 |
+
compliant_object: Any,
|
| 225 |
+
*,
|
| 226 |
+
pass_through: bool = False,
|
| 227 |
+
eager_only: bool = False,
|
| 228 |
+
# Interchange-level was removed after v1
|
| 229 |
+
eager_or_interchange_only: bool,
|
| 230 |
+
series_only: bool,
|
| 231 |
+
allow_series: bool | None,
|
| 232 |
+
version: Version,
|
| 233 |
+
) -> Any:
|
| 234 |
+
if is_compliant_dataframe(compliant_object):
|
| 235 |
+
if series_only:
|
| 236 |
+
if not pass_through:
|
| 237 |
+
msg = "Cannot only use `series_only` with dataframe"
|
| 238 |
+
raise TypeError(msg)
|
| 239 |
+
return compliant_object
|
| 240 |
+
return version.dataframe(
|
| 241 |
+
compliant_object.__narwhals_dataframe__()._with_version(version), level="full"
|
| 242 |
+
)
|
| 243 |
+
if is_compliant_lazyframe(compliant_object):
|
| 244 |
+
if series_only:
|
| 245 |
+
if not pass_through:
|
| 246 |
+
msg = "Cannot only use `series_only` with lazyframe"
|
| 247 |
+
raise TypeError(msg)
|
| 248 |
+
return compliant_object
|
| 249 |
+
if eager_only or eager_or_interchange_only:
|
| 250 |
+
if not pass_through:
|
| 251 |
+
msg = "Cannot only use `eager_only` or `eager_or_interchange_only` with lazyframe"
|
| 252 |
+
raise TypeError(msg)
|
| 253 |
+
return compliant_object
|
| 254 |
+
return version.lazyframe(
|
| 255 |
+
compliant_object.__narwhals_lazyframe__()._with_version(version), level="full"
|
| 256 |
+
)
|
| 257 |
+
if is_compliant_series(compliant_object):
|
| 258 |
+
if not allow_series:
|
| 259 |
+
if not pass_through:
|
| 260 |
+
msg = "Please set `allow_series=True` or `series_only=True`"
|
| 261 |
+
raise TypeError(msg)
|
| 262 |
+
return compliant_object
|
| 263 |
+
return version.series(
|
| 264 |
+
compliant_object.__narwhals_series__()._with_version(version), level="full"
|
| 265 |
+
)
|
| 266 |
+
# Object wasn't compliant, can't translate here.
|
| 267 |
+
return None
|
| 268 |
+
|
| 269 |
+
|
| 270 |
+
def _from_native_impl( # noqa: C901, PLR0911, PLR0912, PLR0915
|
| 271 |
+
native_object: Any,
|
| 272 |
+
*,
|
| 273 |
+
pass_through: bool = False,
|
| 274 |
+
eager_only: bool = False,
|
| 275 |
+
# Interchange-level was removed after v1
|
| 276 |
+
eager_or_interchange_only: bool,
|
| 277 |
+
series_only: bool,
|
| 278 |
+
allow_series: bool | None,
|
| 279 |
+
version: Version,
|
| 280 |
+
) -> Any:
|
| 281 |
+
from narwhals._interchange.dataframe import supports_dataframe_interchange
|
| 282 |
+
from narwhals.dataframe import DataFrame, LazyFrame
|
| 283 |
+
from narwhals.series import Series
|
| 284 |
+
|
| 285 |
+
# Early returns
|
| 286 |
+
if isinstance(native_object, (DataFrame, LazyFrame)) and not series_only:
|
| 287 |
+
if native_object._version is version:
|
| 288 |
+
return native_object
|
| 289 |
+
|
| 290 |
+
real_native_object = native_object.to_native()
|
| 291 |
+
return (
|
| 292 |
+
version.namespace.from_native_object(real_native_object)
|
| 293 |
+
.compliant.from_native(real_native_object)
|
| 294 |
+
.to_narwhals()
|
| 295 |
+
)
|
| 296 |
+
if isinstance(native_object, Series) and (series_only or allow_series):
|
| 297 |
+
if native_object._version is version:
|
| 298 |
+
return native_object
|
| 299 |
+
|
| 300 |
+
real_native_object = native_object.to_native()
|
| 301 |
+
return (
|
| 302 |
+
version.namespace.from_native_object(real_native_object)
|
| 303 |
+
.compliant.from_native(real_native_object)
|
| 304 |
+
.to_narwhals()
|
| 305 |
+
)
|
| 306 |
+
|
| 307 |
+
if series_only:
|
| 308 |
+
if allow_series is False:
|
| 309 |
+
msg = "Invalid parameter combination: `series_only=True` and `allow_series=False`"
|
| 310 |
+
raise ValueError(msg)
|
| 311 |
+
allow_series = True
|
| 312 |
+
if eager_only and eager_or_interchange_only:
|
| 313 |
+
msg = "Invalid parameter combination: `eager_only=True` and `eager_or_interchange_only=True`"
|
| 314 |
+
raise ValueError(msg)
|
| 315 |
+
|
| 316 |
+
# Extensions
|
| 317 |
+
if (
|
| 318 |
+
translated := _translate_if_compliant(
|
| 319 |
+
native_object,
|
| 320 |
+
pass_through=pass_through,
|
| 321 |
+
eager_only=eager_only,
|
| 322 |
+
eager_or_interchange_only=eager_or_interchange_only,
|
| 323 |
+
series_only=series_only,
|
| 324 |
+
allow_series=allow_series,
|
| 325 |
+
version=version,
|
| 326 |
+
)
|
| 327 |
+
) is not None:
|
| 328 |
+
return translated
|
| 329 |
+
|
| 330 |
+
# Polars
|
| 331 |
+
if is_native_polars(native_object):
|
| 332 |
+
if series_only and not is_polars_series(native_object):
|
| 333 |
+
if not pass_through:
|
| 334 |
+
msg = f"Cannot only use `series_only` with {type(native_object).__qualname__}"
|
| 335 |
+
raise TypeError(msg)
|
| 336 |
+
return native_object
|
| 337 |
+
if (eager_only or eager_or_interchange_only) and is_polars_lazyframe(
|
| 338 |
+
native_object
|
| 339 |
+
):
|
| 340 |
+
if not pass_through:
|
| 341 |
+
msg = "Cannot only use `eager_only` or `eager_or_interchange_only` with polars.LazyFrame"
|
| 342 |
+
raise TypeError(msg)
|
| 343 |
+
return native_object
|
| 344 |
+
if (not allow_series) and is_polars_series(native_object):
|
| 345 |
+
if not pass_through:
|
| 346 |
+
msg = "Please set `allow_series=True` or `series_only=True`"
|
| 347 |
+
raise TypeError(msg)
|
| 348 |
+
return native_object
|
| 349 |
+
return (
|
| 350 |
+
version.namespace.from_native_object(native_object)
|
| 351 |
+
.compliant.from_native(native_object)
|
| 352 |
+
.to_narwhals()
|
| 353 |
+
)
|
| 354 |
+
|
| 355 |
+
# PandasLike
|
| 356 |
+
if is_native_pandas_like(native_object):
|
| 357 |
+
if is_pandas_like_dataframe(native_object):
|
| 358 |
+
if series_only:
|
| 359 |
+
if not pass_through:
|
| 360 |
+
msg = f"Cannot only use `series_only` with {type(native_object).__qualname__}"
|
| 361 |
+
raise TypeError(msg)
|
| 362 |
+
return native_object
|
| 363 |
+
elif not allow_series:
|
| 364 |
+
if not pass_through:
|
| 365 |
+
msg = "Please set `allow_series=True` or `series_only=True`"
|
| 366 |
+
raise TypeError(msg)
|
| 367 |
+
return native_object
|
| 368 |
+
return (
|
| 369 |
+
version.namespace.from_native_object(native_object)
|
| 370 |
+
.compliant.from_native(native_object)
|
| 371 |
+
.to_narwhals()
|
| 372 |
+
)
|
| 373 |
+
|
| 374 |
+
# PyArrow
|
| 375 |
+
if is_native_arrow(native_object):
|
| 376 |
+
if is_pyarrow_table(native_object):
|
| 377 |
+
if series_only:
|
| 378 |
+
if not pass_through:
|
| 379 |
+
msg = f"Cannot only use `series_only` with {type(native_object).__qualname__}"
|
| 380 |
+
raise TypeError(msg)
|
| 381 |
+
return native_object
|
| 382 |
+
elif not allow_series:
|
| 383 |
+
if not pass_through:
|
| 384 |
+
msg = "Please set `allow_series=True` or `series_only=True`"
|
| 385 |
+
raise TypeError(msg)
|
| 386 |
+
return native_object
|
| 387 |
+
return (
|
| 388 |
+
version.namespace.from_native_object(native_object)
|
| 389 |
+
.compliant.from_native(native_object)
|
| 390 |
+
.to_narwhals()
|
| 391 |
+
)
|
| 392 |
+
|
| 393 |
+
# Dask
|
| 394 |
+
if is_dask_dataframe(native_object):
|
| 395 |
+
if series_only:
|
| 396 |
+
if not pass_through:
|
| 397 |
+
msg = "Cannot only use `series_only` with dask DataFrame"
|
| 398 |
+
raise TypeError(msg)
|
| 399 |
+
return native_object
|
| 400 |
+
if eager_only or eager_or_interchange_only:
|
| 401 |
+
if not pass_through:
|
| 402 |
+
msg = "Cannot only use `eager_only` or `eager_or_interchange_only` with dask DataFrame"
|
| 403 |
+
raise TypeError(msg)
|
| 404 |
+
return native_object
|
| 405 |
+
if (
|
| 406 |
+
Implementation.DASK._backend_version() <= (2024, 12, 1)
|
| 407 |
+
and get_dask_expr() is None
|
| 408 |
+
): # pragma: no cover
|
| 409 |
+
msg = "Please install dask-expr"
|
| 410 |
+
raise ImportError(msg)
|
| 411 |
+
return (
|
| 412 |
+
version.namespace.from_backend(Implementation.DASK)
|
| 413 |
+
.compliant.from_native(native_object)
|
| 414 |
+
.to_narwhals()
|
| 415 |
+
)
|
| 416 |
+
|
| 417 |
+
# DuckDB
|
| 418 |
+
if is_duckdb_relation(native_object):
|
| 419 |
+
if eager_only or series_only: # pragma: no cover
|
| 420 |
+
if not pass_through:
|
| 421 |
+
msg = "Cannot only use `series_only=True` or `eager_only=False` with DuckDBPyRelation"
|
| 422 |
+
raise TypeError(msg)
|
| 423 |
+
return native_object
|
| 424 |
+
return (
|
| 425 |
+
version.namespace.from_native_object(native_object)
|
| 426 |
+
.compliant.from_native(native_object)
|
| 427 |
+
.to_narwhals()
|
| 428 |
+
)
|
| 429 |
+
|
| 430 |
+
# Ibis
|
| 431 |
+
if is_ibis_table(native_object):
|
| 432 |
+
if eager_only or series_only: # pragma: no cover
|
| 433 |
+
if not pass_through:
|
| 434 |
+
msg = "Cannot only use `series_only=True` or `eager_only=False` with ibis.Table"
|
| 435 |
+
raise TypeError(msg)
|
| 436 |
+
return native_object
|
| 437 |
+
return (
|
| 438 |
+
version.namespace.from_native_object(native_object)
|
| 439 |
+
.compliant.from_native(native_object)
|
| 440 |
+
.to_narwhals()
|
| 441 |
+
)
|
| 442 |
+
|
| 443 |
+
# PySpark
|
| 444 |
+
if is_native_spark_like(native_object): # pragma: no cover
|
| 445 |
+
ns_spark = version.namespace.from_native_object(native_object)
|
| 446 |
+
if series_only or eager_only or eager_or_interchange_only:
|
| 447 |
+
if not pass_through:
|
| 448 |
+
msg = (
|
| 449 |
+
"Cannot only use `series_only`, `eager_only` or `eager_or_interchange_only` "
|
| 450 |
+
f"with {ns_spark.implementation} DataFrame"
|
| 451 |
+
)
|
| 452 |
+
raise TypeError(msg)
|
| 453 |
+
return native_object
|
| 454 |
+
return ns_spark.compliant.from_native(native_object).to_narwhals()
|
| 455 |
+
|
| 456 |
+
# Interchange protocol
|
| 457 |
+
if version is Version.V1 and supports_dataframe_interchange(native_object):
|
| 458 |
+
from narwhals._interchange.dataframe import InterchangeFrame
|
| 459 |
+
|
| 460 |
+
if eager_only or series_only:
|
| 461 |
+
if not pass_through:
|
| 462 |
+
msg = (
|
| 463 |
+
"Cannot only use `series_only=True` or `eager_only=False` "
|
| 464 |
+
"with object which only implements __dataframe__"
|
| 465 |
+
)
|
| 466 |
+
raise TypeError(msg)
|
| 467 |
+
return native_object
|
| 468 |
+
return Version.V1.dataframe(InterchangeFrame(native_object), level="interchange")
|
| 469 |
+
|
| 470 |
+
if (compliant_object := plugins.from_native(native_object, version)) is not None:
|
| 471 |
+
return _translate_if_compliant(
|
| 472 |
+
compliant_object,
|
| 473 |
+
pass_through=pass_through,
|
| 474 |
+
eager_only=eager_only,
|
| 475 |
+
eager_or_interchange_only=eager_or_interchange_only,
|
| 476 |
+
series_only=series_only,
|
| 477 |
+
allow_series=allow_series,
|
| 478 |
+
version=version,
|
| 479 |
+
)
|
| 480 |
+
|
| 481 |
+
if not pass_through:
|
| 482 |
+
msg = f"Unsupported dataframe type, got: {type(native_object)}"
|
| 483 |
+
if hint := plugins._show_suggestions(type(native_object)): # pragma: no cover
|
| 484 |
+
msg += "\n\n" + hint
|
| 485 |
+
raise TypeError(msg)
|
| 486 |
+
return native_object
|
| 487 |
+
|
| 488 |
+
|
| 489 |
+
def get_native_namespace(*obj: Frame | Series[Any] | IntoFrame | IntoSeries) -> Any:
|
| 490 |
+
"""Get native namespace from object.
|
| 491 |
+
|
| 492 |
+
Arguments:
|
| 493 |
+
obj: Dataframe, Lazyframe, or Series. Multiple objects can be
|
| 494 |
+
passed positionally, in which case they must all have the
|
| 495 |
+
same native namespace (else an error is raised).
|
| 496 |
+
|
| 497 |
+
Returns:
|
| 498 |
+
Native module.
|
| 499 |
+
|
| 500 |
+
Examples:
|
| 501 |
+
>>> import polars as pl
|
| 502 |
+
>>> import pandas as pd
|
| 503 |
+
>>> import narwhals as nw
|
| 504 |
+
>>> df = nw.from_native(pd.DataFrame({"a": [1, 2, 3]}))
|
| 505 |
+
>>> nw.get_native_namespace(df)
|
| 506 |
+
<module 'pandas'...>
|
| 507 |
+
>>> df = nw.from_native(pl.DataFrame({"a": [1, 2, 3]}))
|
| 508 |
+
>>> nw.get_native_namespace(df)
|
| 509 |
+
<module 'polars'...>
|
| 510 |
+
"""
|
| 511 |
+
if not obj:
|
| 512 |
+
msg = "At least one object must be passed to `get_native_namespace`."
|
| 513 |
+
raise ValueError(msg)
|
| 514 |
+
result = {_get_native_namespace_single_obj(x) for x in obj}
|
| 515 |
+
if len(result) != 1:
|
| 516 |
+
msg = f"Found objects with different native namespaces: {result}."
|
| 517 |
+
raise ValueError(msg)
|
| 518 |
+
return result.pop()
|
| 519 |
+
|
| 520 |
+
|
| 521 |
+
def _get_native_namespace_single_obj(
|
| 522 |
+
obj: Frame | Series[Any] | IntoFrame | IntoSeries,
|
| 523 |
+
) -> Any:
|
| 524 |
+
if has_native_namespace(obj):
|
| 525 |
+
return obj.__native_namespace__()
|
| 526 |
+
return Version.MAIN.namespace.from_native_object(
|
| 527 |
+
obj
|
| 528 |
+
).implementation.to_native_namespace()
|
| 529 |
+
|
| 530 |
+
|
| 531 |
+
def narwhalify(
|
| 532 |
+
func: Callable[..., Any] | None = None,
|
| 533 |
+
*,
|
| 534 |
+
pass_through: bool = True,
|
| 535 |
+
eager_only: bool = False,
|
| 536 |
+
series_only: bool = False,
|
| 537 |
+
allow_series: bool | None = True,
|
| 538 |
+
) -> Callable[..., Any]:
|
| 539 |
+
"""Decorate function so it becomes dataframe-agnostic.
|
| 540 |
+
|
| 541 |
+
This will try to convert any dataframe/series-like object into the Narwhals
|
| 542 |
+
respective DataFrame/Series, while leaving the other parameters as they are.
|
| 543 |
+
Similarly, if the output of the function is a Narwhals DataFrame or Series, it will be
|
| 544 |
+
converted back to the original dataframe/series type, while if the output is another
|
| 545 |
+
type it will be left as is.
|
| 546 |
+
By setting `pass_through=False`, then every input and every output will be required to be a
|
| 547 |
+
dataframe/series-like object.
|
| 548 |
+
|
| 549 |
+
Arguments:
|
| 550 |
+
func: Function to wrap in a `from_native`-`to_native` block.
|
| 551 |
+
pass_through: Determine what happens if the object can't be converted to Narwhals
|
| 552 |
+
|
| 553 |
+
- `False`: raise an error
|
| 554 |
+
- `True` (default): pass object through as-is
|
| 555 |
+
eager_only: Whether to only allow eager objects
|
| 556 |
+
|
| 557 |
+
- `False` (default): don't require `native_object` to be eager
|
| 558 |
+
- `True`: only convert to Narwhals if `native_object` is eager
|
| 559 |
+
series_only: Whether to only allow Series
|
| 560 |
+
|
| 561 |
+
- `False` (default): don't require `native_object` to be a Series
|
| 562 |
+
- `True`: only convert to Narwhals if `native_object` is a Series
|
| 563 |
+
allow_series: Whether to allow Series (default is only Dataframe / Lazyframe)
|
| 564 |
+
|
| 565 |
+
- `False` or `None`: don't convert to Narwhals if `native_object` is a Series
|
| 566 |
+
- `True` (default): allow `native_object` to be a Series
|
| 567 |
+
|
| 568 |
+
Returns:
|
| 569 |
+
Decorated function.
|
| 570 |
+
|
| 571 |
+
Examples:
|
| 572 |
+
Instead of writing
|
| 573 |
+
|
| 574 |
+
>>> import narwhals as nw
|
| 575 |
+
>>> def agnostic_group_by_sum(df):
|
| 576 |
+
... df = nw.from_native(df, pass_through=True)
|
| 577 |
+
... df = df.group_by("a").agg(nw.col("b").sum())
|
| 578 |
+
... return nw.to_native(df)
|
| 579 |
+
|
| 580 |
+
you can just write
|
| 581 |
+
|
| 582 |
+
>>> @nw.narwhalify
|
| 583 |
+
... def agnostic_group_by_sum(df):
|
| 584 |
+
... return df.group_by("a").agg(nw.col("b").sum())
|
| 585 |
+
"""
|
| 586 |
+
|
| 587 |
+
def decorator(func: Callable[..., Any]) -> Callable[..., Any]:
|
| 588 |
+
@wraps(func)
|
| 589 |
+
def wrapper(*args: Any, **kwargs: Any) -> Any:
|
| 590 |
+
args_nw = [
|
| 591 |
+
from_native(
|
| 592 |
+
arg,
|
| 593 |
+
pass_through=pass_through,
|
| 594 |
+
eager_only=eager_only,
|
| 595 |
+
series_only=series_only,
|
| 596 |
+
allow_series=allow_series,
|
| 597 |
+
)
|
| 598 |
+
for arg in args
|
| 599 |
+
]
|
| 600 |
+
|
| 601 |
+
kwargs_nw = {
|
| 602 |
+
name: from_native(
|
| 603 |
+
value,
|
| 604 |
+
pass_through=pass_through,
|
| 605 |
+
eager_only=eager_only,
|
| 606 |
+
series_only=series_only,
|
| 607 |
+
allow_series=allow_series,
|
| 608 |
+
)
|
| 609 |
+
for name, value in kwargs.items()
|
| 610 |
+
}
|
| 611 |
+
|
| 612 |
+
backends = {
|
| 613 |
+
b()
|
| 614 |
+
for v in (*args_nw, *kwargs_nw.values())
|
| 615 |
+
if (b := getattr(v, "__native_namespace__", None))
|
| 616 |
+
}
|
| 617 |
+
|
| 618 |
+
if len(backends) > 1:
|
| 619 |
+
msg = "Found multiple backends. Make sure that all dataframe/series inputs come from the same backend."
|
| 620 |
+
raise ValueError(msg)
|
| 621 |
+
|
| 622 |
+
result = func(*args_nw, **kwargs_nw)
|
| 623 |
+
|
| 624 |
+
return to_native(result, pass_through=pass_through)
|
| 625 |
+
|
| 626 |
+
return wrapper
|
| 627 |
+
|
| 628 |
+
if func is None:
|
| 629 |
+
return decorator
|
| 630 |
+
# If func is not None, it means the decorator is used without arguments
|
| 631 |
+
return decorator(func)
|
| 632 |
+
|
| 633 |
+
|
| 634 |
+
def to_py_scalar(scalar_like: Any) -> Any:
|
| 635 |
+
"""If a scalar is not Python native, converts it to Python native.
|
| 636 |
+
|
| 637 |
+
Arguments:
|
| 638 |
+
scalar_like: Scalar-like value.
|
| 639 |
+
|
| 640 |
+
Raises:
|
| 641 |
+
ValueError: If the object is not convertible to a scalar.
|
| 642 |
+
|
| 643 |
+
Examples:
|
| 644 |
+
>>> import narwhals as nw
|
| 645 |
+
>>> import pandas as pd
|
| 646 |
+
>>> df = nw.from_native(pd.DataFrame({"a": [1, 2, 3]}))
|
| 647 |
+
>>> nw.to_py_scalar(df["a"].item(0))
|
| 648 |
+
1
|
| 649 |
+
>>> import pyarrow as pa
|
| 650 |
+
>>> df = nw.from_native(pa.table({"a": [1, 2, 3]}))
|
| 651 |
+
>>> nw.to_py_scalar(df["a"].item(0))
|
| 652 |
+
1
|
| 653 |
+
>>> nw.to_py_scalar(1)
|
| 654 |
+
1
|
| 655 |
+
"""
|
| 656 |
+
scalar: Any
|
| 657 |
+
pd = get_pandas()
|
| 658 |
+
if scalar_like is None or isinstance(scalar_like, NON_TEMPORAL_SCALAR_TYPES):
|
| 659 |
+
scalar = scalar_like
|
| 660 |
+
elif (
|
| 661 |
+
(np := get_numpy())
|
| 662 |
+
and isinstance(scalar_like, np.datetime64)
|
| 663 |
+
and scalar_like.dtype == "datetime64[ns]"
|
| 664 |
+
):
|
| 665 |
+
ms = scalar_like.item() // MS_PER_SECOND
|
| 666 |
+
scalar = EPOCH + dt.timedelta(microseconds=ms)
|
| 667 |
+
elif is_numpy_scalar(scalar_like) or is_cupy_scalar(scalar_like):
|
| 668 |
+
scalar = scalar_like.item()
|
| 669 |
+
elif pd and isinstance(scalar_like, pd.Timestamp):
|
| 670 |
+
scalar = scalar_like.to_pydatetime()
|
| 671 |
+
elif pd and isinstance(scalar_like, pd.Timedelta):
|
| 672 |
+
scalar = scalar_like.to_pytimedelta()
|
| 673 |
+
# pd.Timestamp and pd.Timedelta subclass datetime and timedelta,
|
| 674 |
+
# so we need to check this separately
|
| 675 |
+
elif isinstance(scalar_like, TEMPORAL_SCALAR_TYPES):
|
| 676 |
+
scalar = scalar_like
|
| 677 |
+
elif _is_pandas_na(scalar_like):
|
| 678 |
+
scalar = None
|
| 679 |
+
elif is_pyarrow_scalar(scalar_like):
|
| 680 |
+
scalar = scalar_like.as_py()
|
| 681 |
+
else:
|
| 682 |
+
msg = (
|
| 683 |
+
f"Expected object convertible to a scalar, found {type(scalar_like)}.\n"
|
| 684 |
+
f"{scalar_like!r}"
|
| 685 |
+
)
|
| 686 |
+
raise ValueError(msg)
|
| 687 |
+
return scalar
|
| 688 |
+
|
| 689 |
+
|
| 690 |
+
def _is_pandas_na(obj: Any) -> bool:
|
| 691 |
+
return bool((pd := get_pandas()) and pd.api.types.is_scalar(obj) and pd.isna(obj))
|
| 692 |
+
|
| 693 |
+
|
| 694 |
+
__all__ = ["get_native_namespace", "narwhalify", "to_native", "to_py_scalar"]
|
shared/package-files/65/6577a652c6bf6f4acbb4f55352480091943511cbb67886716a23524975b43c39/blob
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from sympy.core import S, pi, Rational
|
| 2 |
+
from sympy.functions import hermite, sqrt, exp, factorial, Abs
|
| 3 |
+
from sympy.physics.quantum.constants import hbar
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def psi_n(n, x, m, omega):
|
| 7 |
+
"""
|
| 8 |
+
Returns the wavefunction psi_{n} for the One-dimensional harmonic oscillator.
|
| 9 |
+
|
| 10 |
+
Parameters
|
| 11 |
+
==========
|
| 12 |
+
|
| 13 |
+
n :
|
| 14 |
+
the "nodal" quantum number. Corresponds to the number of nodes in the
|
| 15 |
+
wavefunction. ``n >= 0``
|
| 16 |
+
x :
|
| 17 |
+
x coordinate.
|
| 18 |
+
m :
|
| 19 |
+
Mass of the particle.
|
| 20 |
+
omega :
|
| 21 |
+
Angular frequency of the oscillator.
|
| 22 |
+
|
| 23 |
+
Examples
|
| 24 |
+
========
|
| 25 |
+
|
| 26 |
+
>>> from sympy.physics.qho_1d import psi_n
|
| 27 |
+
>>> from sympy.abc import m, x, omega
|
| 28 |
+
>>> psi_n(0, x, m, omega)
|
| 29 |
+
(m*omega)**(1/4)*exp(-m*omega*x**2/(2*hbar))/(hbar**(1/4)*pi**(1/4))
|
| 30 |
+
|
| 31 |
+
"""
|
| 32 |
+
|
| 33 |
+
# sympify arguments
|
| 34 |
+
n, x, m, omega = map(S, [n, x, m, omega])
|
| 35 |
+
nu = m * omega / hbar
|
| 36 |
+
# normalization coefficient
|
| 37 |
+
C = (nu/pi)**Rational(1, 4) * sqrt(1/(2**n*factorial(n)))
|
| 38 |
+
|
| 39 |
+
return C * exp(-nu* x**2 /2) * hermite(n, sqrt(nu)*x)
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
def E_n(n, omega):
|
| 43 |
+
"""
|
| 44 |
+
Returns the Energy of the One-dimensional harmonic oscillator.
|
| 45 |
+
|
| 46 |
+
Parameters
|
| 47 |
+
==========
|
| 48 |
+
|
| 49 |
+
n :
|
| 50 |
+
The "nodal" quantum number.
|
| 51 |
+
omega :
|
| 52 |
+
The harmonic oscillator angular frequency.
|
| 53 |
+
|
| 54 |
+
Notes
|
| 55 |
+
=====
|
| 56 |
+
|
| 57 |
+
The unit of the returned value matches the unit of hw, since the energy is
|
| 58 |
+
calculated as:
|
| 59 |
+
|
| 60 |
+
E_n = hbar * omega*(n + 1/2)
|
| 61 |
+
|
| 62 |
+
Examples
|
| 63 |
+
========
|
| 64 |
+
|
| 65 |
+
>>> from sympy.physics.qho_1d import E_n
|
| 66 |
+
>>> from sympy.abc import x, omega
|
| 67 |
+
>>> E_n(x, omega)
|
| 68 |
+
hbar*omega*(x + 1/2)
|
| 69 |
+
"""
|
| 70 |
+
|
| 71 |
+
return hbar * omega * (n + S.Half)
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
def coherent_state(n, alpha):
|
| 75 |
+
"""
|
| 76 |
+
Returns <n|alpha> for the coherent states of 1D harmonic oscillator.
|
| 77 |
+
See https://en.wikipedia.org/wiki/Coherent_states
|
| 78 |
+
|
| 79 |
+
Parameters
|
| 80 |
+
==========
|
| 81 |
+
|
| 82 |
+
n :
|
| 83 |
+
The "nodal" quantum number.
|
| 84 |
+
alpha :
|
| 85 |
+
The eigen value of annihilation operator.
|
| 86 |
+
"""
|
| 87 |
+
|
| 88 |
+
return exp(- Abs(alpha)**2/2)*(alpha**n)/sqrt(factorial(n))
|
shared/package-files/65/6577b44723d46e5a846f5956d4f6fd7cccac816f1480cabcf26cd7f32675d4b2/blob
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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STL
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
@pytest.fixture
|
| 11 |
+
def mstl_results():
|
| 12 |
+
cur_dir = Path(__file__).parent.resolve()
|
| 13 |
+
file_path = cur_dir / "results/mstl_test_results.csv"
|
| 14 |
+
return pd.read_csv(file_path)
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
@pytest.fixture
|
| 18 |
+
def data_pd():
|
| 19 |
+
cur_dir = Path(__file__).parent.resolve()
|
| 20 |
+
file_path = cur_dir / "results/mstl_elec_vic.csv"
|
| 21 |
+
return pd.read_csv(file_path, index_col=["ds"], parse_dates=["ds"])
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
@pytest.fixture
|
| 25 |
+
def data(data_pd):
|
| 26 |
+
return data_pd["y"].values
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def test_return_pandas_series_when_input_pandas_and_len_periods_one(data_pd):
|
| 30 |
+
mod = MSTL(endog=data_pd, periods=5)
|
| 31 |
+
res = mod.fit()
|
| 32 |
+
assert isinstance(res.trend, pd.Series)
|
| 33 |
+
assert isinstance(res.seasonal, pd.Series)
|
| 34 |
+
assert isinstance(res.resid, pd.Series)
|
| 35 |
+
assert isinstance(res.weights, pd.Series)
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def test_seasonal_is_datafame_when_input_pandas_and_multiple_periods(data_pd):
|
| 39 |
+
mod = MSTL(endog=data_pd, periods=(3, 5))
|
| 40 |
+
res = mod.fit()
|
| 41 |
+
assert isinstance(res.seasonal, pd.DataFrame)
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
@pytest.mark.parametrize(
|
| 45 |
+
"data, periods, windows, expected",
|
| 46 |
+
[
|
| 47 |
+
(data, 3, None, 1),
|
| 48 |
+
(data, (3, 6), None, 2),
|
| 49 |
+
(data, (3, 6, 1e6), None, 2),
|
| 50 |
+
],
|
| 51 |
+
indirect=["data"],
|
| 52 |
+
)
|
| 53 |
+
def test_number_of_seasonal_components(data, periods, windows, expected):
|
| 54 |
+
mod = MSTL(endog=data, periods=periods, windows=windows)
|
| 55 |
+
res = mod.fit()
|
| 56 |
+
n_seasonal_components = (
|
| 57 |
+
res.seasonal.shape[1] if res.seasonal.ndim > 1 else res.seasonal.ndim
|
| 58 |
+
)
|
| 59 |
+
assert n_seasonal_components == expected
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
@pytest.mark.parametrize(
|
| 63 |
+
"periods, windows",
|
| 64 |
+
[((3, 5), 1), (7, (3, 5))],
|
| 65 |
+
)
|
| 66 |
+
def test_raise_value_error_when_periods_and_windows_diff_lengths(periods, windows):
|
| 67 |
+
with pytest.raises(ValueError, match="Periods and windows must have same length"):
|
| 68 |
+
MSTL(endog=[1, 2, 3, 4, 5], periods=periods, windows=windows)
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
@pytest.mark.parametrize(
|
| 72 |
+
"data, lmbda",
|
| 73 |
+
[(data, 0.1), (data, 1), (data, -3.0), (data, "auto")],
|
| 74 |
+
indirect=["data"],
|
| 75 |
+
)
|
| 76 |
+
def test_fit_with_box_cox(data, lmbda):
|
| 77 |
+
periods = (5, 6, 7)
|
| 78 |
+
mod = MSTL(endog=data, periods=periods, lmbda=lmbda)
|
| 79 |
+
mod.fit()
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
def test_auto_fit_with_box_cox(data):
|
| 83 |
+
periods = (5, 6, 7)
|
| 84 |
+
mod = MSTL(endog=data, periods=periods, lmbda="auto")
|
| 85 |
+
mod.fit()
|
| 86 |
+
assert hasattr(mod, "est_lmbda")
|
| 87 |
+
assert isinstance(mod.est_lmbda, float)
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
def test_stl_kwargs_smoke(data):
|
| 91 |
+
stl_kwargs = {
|
| 92 |
+
"period": 12,
|
| 93 |
+
"seasonal": 15,
|
| 94 |
+
"trend": 17,
|
| 95 |
+
"low_pass": 15,
|
| 96 |
+
"seasonal_deg": 0,
|
| 97 |
+
"trend_deg": 1,
|
| 98 |
+
"low_pass_deg": 1,
|
| 99 |
+
"seasonal_jump": 2,
|
| 100 |
+
"trend_jump": 2,
|
| 101 |
+
"low_pass_jump": 3,
|
| 102 |
+
"robust": False,
|
| 103 |
+
"inner_iter": 3,
|
| 104 |
+
"outer_iter": 3,
|
| 105 |
+
}
|
| 106 |
+
periods = (5, 6, 7)
|
| 107 |
+
mod = MSTL(endog=data, periods=periods, lmbda="auto", stl_kwargs=stl_kwargs)
|
| 108 |
+
mod.fit()
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
@pytest.mark.thread_unsafe(reason="Uses matplotlib")
|
| 112 |
+
@pytest.mark.matplotlib
|
| 113 |
+
def test_plot(data, data_pd, close_figures):
|
| 114 |
+
mod = MSTL(endog=data, periods=5)
|
| 115 |
+
res = mod.fit()
|
| 116 |
+
res.plot()
|
| 117 |
+
|
| 118 |
+
mod = MSTL(endog=data_pd, periods=5)
|
| 119 |
+
res = mod.fit()
|
| 120 |
+
res.plot()
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
def test_output_similar_to_R_implementation(data_pd, mstl_results):
|
| 124 |
+
mod = MSTL(
|
| 125 |
+
endog=data_pd,
|
| 126 |
+
periods=(24, 24 * 7),
|
| 127 |
+
stl_kwargs={
|
| 128 |
+
"seasonal_deg": 0,
|
| 129 |
+
"seasonal_jump": 1,
|
| 130 |
+
"trend_jump": 1,
|
| 131 |
+
"trend_deg": 1,
|
| 132 |
+
"low_pass_jump": 1,
|
| 133 |
+
"low_pass_deg": 1,
|
| 134 |
+
"inner_iter": 2,
|
| 135 |
+
"outer_iter": 0,
|
| 136 |
+
},
|
| 137 |
+
)
|
| 138 |
+
res = mod.fit()
|
| 139 |
+
|
| 140 |
+
expected_observed = mstl_results["Data"]
|
| 141 |
+
expected_trend = mstl_results["Trend"]
|
| 142 |
+
expected_seasonal = mstl_results[["Seasonal24", "Seasonal168"]]
|
| 143 |
+
expected_resid = mstl_results["Remainder"]
|
| 144 |
+
|
| 145 |
+
assert_allclose(res.observed, expected_observed)
|
| 146 |
+
assert_allclose(res.trend, expected_trend)
|
| 147 |
+
assert_allclose(res.seasonal, expected_seasonal)
|
| 148 |
+
assert_allclose(res.resid, expected_resid)
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
@pytest.mark.parametrize(
|
| 152 |
+
"data, periods_ordered, windows_ordered, periods_not_ordered, "
|
| 153 |
+
"windows_not_ordered",
|
| 154 |
+
[
|
| 155 |
+
(data, (12, 24, 24 * 7), (11, 15, 19), (12, 24 * 7, 24), (11, 19, 15)),
|
| 156 |
+
(
|
| 157 |
+
data,
|
| 158 |
+
(12, 24, 24 * 7 * 1e6),
|
| 159 |
+
(11, 15, 19),
|
| 160 |
+
(12, 24 * 7 * 1e6, 24),
|
| 161 |
+
(11, 19, 15),
|
| 162 |
+
),
|
| 163 |
+
(data, (12, 24, 24 * 7), None, (12, 24 * 7, 24), None),
|
| 164 |
+
],
|
| 165 |
+
indirect=["data"],
|
| 166 |
+
)
|
| 167 |
+
def test_output_invariant_to_period_order(
|
| 168 |
+
data,
|
| 169 |
+
periods_ordered,
|
| 170 |
+
windows_ordered,
|
| 171 |
+
periods_not_ordered,
|
| 172 |
+
windows_not_ordered,
|
| 173 |
+
):
|
| 174 |
+
mod1 = MSTL(endog=data, periods=periods_ordered, windows=windows_ordered)
|
| 175 |
+
res1 = mod1.fit()
|
| 176 |
+
mod2 = MSTL(endog=data, periods=periods_not_ordered, windows=windows_not_ordered)
|
| 177 |
+
res2 = mod2.fit()
|
| 178 |
+
|
| 179 |
+
assert_equal(res1.observed, res2.observed)
|
| 180 |
+
assert_equal(res1.trend, res2.trend)
|
| 181 |
+
assert_equal(res1.seasonal, res2.seasonal)
|
| 182 |
+
assert_equal(res1.resid, res2.resid)
|
shared/package-files/65/65784d7c8e6842e363e76ce4cac43ea12ad00eb5053fe73efc622fd5934df2ff/blob
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
// @generated by torchgen/gen.py from DispatchKeyFunction.h
|
| 3 |
+
|
| 4 |
+
// NB: The implementing C++ file is RegisterDispatchKey.cpp
|
| 5 |
+
|
| 6 |
+
// The only #includes we need are for custom classes that have defaults in the C++ API
|
| 7 |
+
#include <c10/core/MemoryFormat.h>
|
| 8 |
+
#include <c10/core/Scalar.h>
|
| 9 |
+
#include <ATen/core/Reduction.h>
|
| 10 |
+
|
| 11 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 12 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 13 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 14 |
+
#include <ATen/core/ATen_fwd.h>
|
| 15 |
+
|
| 16 |
+
namespace at {
|
| 17 |
+
|
| 18 |
+
namespace meta {
|
| 19 |
+
|
| 20 |
+
TORCH_API at::Tensor sin(const at::Tensor & self);
|
| 21 |
+
TORCH_API at::Tensor & sin_out(at::Tensor & out, const at::Tensor & self);
|
| 22 |
+
TORCH_API at::Tensor & sin_outf(const at::Tensor & self, at::Tensor & out);
|
| 23 |
+
TORCH_API at::Tensor & sin_(at::Tensor & self);
|
| 24 |
+
|
| 25 |
+
} // namespace meta
|
| 26 |
+
} // namespace at
|
shared/package-files/65/657977d7f7c5eddc5e48c8e4fd3c4f9d9c2ef5f9270f1e117a1210c161006400/blob
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// @generated by torchgen/gen.py from Function.h
|
| 4 |
+
|
| 5 |
+
#include <ATen/Context.h>
|
| 6 |
+
#include <ATen/DeviceGuard.h>
|
| 7 |
+
#include <ATen/TensorUtils.h>
|
| 8 |
+
#include <ATen/TracerMode.h>
|
| 9 |
+
#include <ATen/core/Generator.h>
|
| 10 |
+
#include <ATen/core/Reduction.h>
|
| 11 |
+
#include <ATen/core/Tensor.h>
|
| 12 |
+
#include <c10/core/Scalar.h>
|
| 13 |
+
#include <c10/core/Storage.h>
|
| 14 |
+
#include <c10/core/TensorOptions.h>
|
| 15 |
+
#include <c10/util/Deprecated.h>
|
| 16 |
+
#include <c10/util/Optional.h>
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
#include <ATen/ops/_amp_update_scale_ops.h>
|
| 21 |
+
|
| 22 |
+
namespace at {
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
// aten::_amp_update_scale_(Tensor(a!) self, Tensor(b!) growth_tracker, Tensor found_inf, float scale_growth_factor, float scale_backoff_factor, int growth_interval) -> Tensor(a!)
|
| 26 |
+
inline at::Tensor & _amp_update_scale_(at::Tensor & self, at::Tensor & growth_tracker, const at::Tensor & found_inf, double scale_growth_factor, double scale_backoff_factor, int64_t growth_interval) {
|
| 27 |
+
return at::_ops::_amp_update_scale_::call(self, growth_tracker, found_inf, scale_growth_factor, scale_backoff_factor, growth_interval);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
// aten::_amp_update_scale.out(Tensor self, Tensor(b!) growth_tracker, Tensor found_inf, float scale_growth_factor, float scale_backoff_factor, int growth_interval, *, Tensor(a!) out) -> Tensor(a!)
|
| 31 |
+
inline at::Tensor & _amp_update_scale_out(at::Tensor & out, const at::Tensor & self, at::Tensor & growth_tracker, const at::Tensor & found_inf, double scale_growth_factor, double scale_backoff_factor, int64_t growth_interval) {
|
| 32 |
+
return at::_ops::_amp_update_scale_out::call(self, growth_tracker, found_inf, scale_growth_factor, scale_backoff_factor, growth_interval, out);
|
| 33 |
+
}
|
| 34 |
+
// aten::_amp_update_scale.out(Tensor self, Tensor(b!) growth_tracker, Tensor found_inf, float scale_growth_factor, float scale_backoff_factor, int growth_interval, *, Tensor(a!) out) -> Tensor(a!)
|
| 35 |
+
inline at::Tensor & _amp_update_scale_outf(const at::Tensor & self, at::Tensor & growth_tracker, const at::Tensor & found_inf, double scale_growth_factor, double scale_backoff_factor, int64_t growth_interval, at::Tensor & out) {
|
| 36 |
+
return at::_ops::_amp_update_scale_out::call(self, growth_tracker, found_inf, scale_growth_factor, scale_backoff_factor, growth_interval, out);
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
// aten::_amp_update_scale(Tensor self, Tensor growth_tracker, Tensor found_inf, float scale_growth_factor, float scale_backoff_factor, int growth_interval) -> (Tensor, Tensor growth_tracker_out)
|
| 40 |
+
inline ::std::tuple<at::Tensor,at::Tensor> _amp_update_scale(const at::Tensor & self, const at::Tensor & growth_tracker, const at::Tensor & found_inf, double scale_growth_factor, double scale_backoff_factor, int64_t growth_interval) {
|
| 41 |
+
return at::_ops::_amp_update_scale::call(self, growth_tracker, found_inf, scale_growth_factor, scale_backoff_factor, growth_interval);
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
}
|
shared/package-files/65/657a9599536399aba131e8935ad082a8e3f7f1bf4c260ed49417596beeda2024/blob
ADDED
|
@@ -0,0 +1,745 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from sympy.core import Basic, Dict, sympify, Tuple
|
| 2 |
+
from sympy.core.numbers import Integer
|
| 3 |
+
from sympy.core.sorting import default_sort_key
|
| 4 |
+
from sympy.core.sympify import _sympify
|
| 5 |
+
from sympy.functions.combinatorial.numbers import bell
|
| 6 |
+
from sympy.matrices import zeros
|
| 7 |
+
from sympy.sets.sets import FiniteSet, Union
|
| 8 |
+
from sympy.utilities.iterables import flatten, group
|
| 9 |
+
from sympy.utilities.misc import as_int
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
from collections import defaultdict
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
class Partition(FiniteSet):
|
| 16 |
+
"""
|
| 17 |
+
This class represents an abstract partition.
|
| 18 |
+
|
| 19 |
+
A partition is a set of disjoint sets whose union equals a given set.
|
| 20 |
+
|
| 21 |
+
See Also
|
| 22 |
+
========
|
| 23 |
+
|
| 24 |
+
sympy.utilities.iterables.partitions,
|
| 25 |
+
sympy.utilities.iterables.multiset_partitions
|
| 26 |
+
"""
|
| 27 |
+
|
| 28 |
+
_rank = None
|
| 29 |
+
_partition = None
|
| 30 |
+
|
| 31 |
+
def __new__(cls, *partition):
|
| 32 |
+
"""
|
| 33 |
+
Generates a new partition object.
|
| 34 |
+
|
| 35 |
+
This method also verifies if the arguments passed are
|
| 36 |
+
valid and raises a ValueError if they are not.
|
| 37 |
+
|
| 38 |
+
Examples
|
| 39 |
+
========
|
| 40 |
+
|
| 41 |
+
Creating Partition from Python lists:
|
| 42 |
+
|
| 43 |
+
>>> from sympy.combinatorics import Partition
|
| 44 |
+
>>> a = Partition([1, 2], [3])
|
| 45 |
+
>>> a
|
| 46 |
+
Partition({3}, {1, 2})
|
| 47 |
+
>>> a.partition
|
| 48 |
+
[[1, 2], [3]]
|
| 49 |
+
>>> len(a)
|
| 50 |
+
2
|
| 51 |
+
>>> a.members
|
| 52 |
+
(1, 2, 3)
|
| 53 |
+
|
| 54 |
+
Creating Partition from Python sets:
|
| 55 |
+
|
| 56 |
+
>>> Partition({1, 2, 3}, {4, 5})
|
| 57 |
+
Partition({4, 5}, {1, 2, 3})
|
| 58 |
+
|
| 59 |
+
Creating Partition from SymPy finite sets:
|
| 60 |
+
|
| 61 |
+
>>> from sympy import FiniteSet
|
| 62 |
+
>>> a = FiniteSet(1, 2, 3)
|
| 63 |
+
>>> b = FiniteSet(4, 5)
|
| 64 |
+
>>> Partition(a, b)
|
| 65 |
+
Partition({4, 5}, {1, 2, 3})
|
| 66 |
+
"""
|
| 67 |
+
args = []
|
| 68 |
+
dups = False
|
| 69 |
+
for arg in partition:
|
| 70 |
+
if isinstance(arg, list):
|
| 71 |
+
as_set = set(arg)
|
| 72 |
+
if len(as_set) < len(arg):
|
| 73 |
+
dups = True
|
| 74 |
+
break # error below
|
| 75 |
+
arg = as_set
|
| 76 |
+
args.append(_sympify(arg))
|
| 77 |
+
|
| 78 |
+
if not all(isinstance(part, FiniteSet) for part in args):
|
| 79 |
+
raise ValueError(
|
| 80 |
+
"Each argument to Partition should be " \
|
| 81 |
+
"a list, set, or a FiniteSet")
|
| 82 |
+
|
| 83 |
+
# sort so we have a canonical reference for RGS
|
| 84 |
+
U = Union(*args)
|
| 85 |
+
if dups or len(U) < sum(len(arg) for arg in args):
|
| 86 |
+
raise ValueError("Partition contained duplicate elements.")
|
| 87 |
+
|
| 88 |
+
obj = FiniteSet.__new__(cls, *args)
|
| 89 |
+
obj.members = tuple(U)
|
| 90 |
+
obj.size = len(U)
|
| 91 |
+
return obj
|
| 92 |
+
|
| 93 |
+
def sort_key(self, order=None):
|
| 94 |
+
"""Return a canonical key that can be used for sorting.
|
| 95 |
+
|
| 96 |
+
Ordering is based on the size and sorted elements of the partition
|
| 97 |
+
and ties are broken with the rank.
|
| 98 |
+
|
| 99 |
+
Examples
|
| 100 |
+
========
|
| 101 |
+
|
| 102 |
+
>>> from sympy import default_sort_key
|
| 103 |
+
>>> from sympy.combinatorics import Partition
|
| 104 |
+
>>> from sympy.abc import x
|
| 105 |
+
>>> a = Partition([1, 2])
|
| 106 |
+
>>> b = Partition([3, 4])
|
| 107 |
+
>>> c = Partition([1, x])
|
| 108 |
+
>>> d = Partition(list(range(4)))
|
| 109 |
+
>>> l = [d, b, a + 1, a, c]
|
| 110 |
+
>>> l.sort(key=default_sort_key); l
|
| 111 |
+
[Partition({1, 2}), Partition({1}, {2}), Partition({1, x}), Partition({3, 4}), Partition({0, 1, 2, 3})]
|
| 112 |
+
"""
|
| 113 |
+
if order is None:
|
| 114 |
+
members = self.members
|
| 115 |
+
else:
|
| 116 |
+
members = tuple(sorted(self.members,
|
| 117 |
+
key=lambda w: default_sort_key(w, order)))
|
| 118 |
+
return tuple(map(default_sort_key, (self.size, members, self.rank)))
|
| 119 |
+
|
| 120 |
+
@property
|
| 121 |
+
def partition(self):
|
| 122 |
+
"""Return partition as a sorted list of lists.
|
| 123 |
+
|
| 124 |
+
Examples
|
| 125 |
+
========
|
| 126 |
+
|
| 127 |
+
>>> from sympy.combinatorics import Partition
|
| 128 |
+
>>> Partition([1], [2, 3]).partition
|
| 129 |
+
[[1], [2, 3]]
|
| 130 |
+
"""
|
| 131 |
+
if self._partition is None:
|
| 132 |
+
self._partition = sorted([sorted(p, key=default_sort_key)
|
| 133 |
+
for p in self.args])
|
| 134 |
+
return self._partition
|
| 135 |
+
|
| 136 |
+
def __add__(self, other):
|
| 137 |
+
"""
|
| 138 |
+
Return permutation whose rank is ``other`` greater than current rank,
|
| 139 |
+
(mod the maximum rank for the set).
|
| 140 |
+
|
| 141 |
+
Examples
|
| 142 |
+
========
|
| 143 |
+
|
| 144 |
+
>>> from sympy.combinatorics import Partition
|
| 145 |
+
>>> a = Partition([1, 2], [3])
|
| 146 |
+
>>> a.rank
|
| 147 |
+
1
|
| 148 |
+
>>> (a + 1).rank
|
| 149 |
+
2
|
| 150 |
+
>>> (a + 100).rank
|
| 151 |
+
1
|
| 152 |
+
"""
|
| 153 |
+
other = as_int(other)
|
| 154 |
+
offset = self.rank + other
|
| 155 |
+
result = RGS_unrank((offset) %
|
| 156 |
+
RGS_enum(self.size),
|
| 157 |
+
self.size)
|
| 158 |
+
return Partition.from_rgs(result, self.members)
|
| 159 |
+
|
| 160 |
+
def __sub__(self, other):
|
| 161 |
+
"""
|
| 162 |
+
Return permutation whose rank is ``other`` less than current rank,
|
| 163 |
+
(mod the maximum rank for the set).
|
| 164 |
+
|
| 165 |
+
Examples
|
| 166 |
+
========
|
| 167 |
+
|
| 168 |
+
>>> from sympy.combinatorics import Partition
|
| 169 |
+
>>> a = Partition([1, 2], [3])
|
| 170 |
+
>>> a.rank
|
| 171 |
+
1
|
| 172 |
+
>>> (a - 1).rank
|
| 173 |
+
0
|
| 174 |
+
>>> (a - 100).rank
|
| 175 |
+
1
|
| 176 |
+
"""
|
| 177 |
+
return self.__add__(-other)
|
| 178 |
+
|
| 179 |
+
def __le__(self, other):
|
| 180 |
+
"""
|
| 181 |
+
Checks if a partition is less than or equal to
|
| 182 |
+
the other based on rank.
|
| 183 |
+
|
| 184 |
+
Examples
|
| 185 |
+
========
|
| 186 |
+
|
| 187 |
+
>>> from sympy.combinatorics import Partition
|
| 188 |
+
>>> a = Partition([1, 2], [3, 4, 5])
|
| 189 |
+
>>> b = Partition([1], [2, 3], [4], [5])
|
| 190 |
+
>>> a.rank, b.rank
|
| 191 |
+
(9, 34)
|
| 192 |
+
>>> a <= a
|
| 193 |
+
True
|
| 194 |
+
>>> a <= b
|
| 195 |
+
True
|
| 196 |
+
"""
|
| 197 |
+
return self.sort_key() <= sympify(other).sort_key()
|
| 198 |
+
|
| 199 |
+
def __lt__(self, other):
|
| 200 |
+
"""
|
| 201 |
+
Checks if a partition is less than the other.
|
| 202 |
+
|
| 203 |
+
Examples
|
| 204 |
+
========
|
| 205 |
+
|
| 206 |
+
>>> from sympy.combinatorics import Partition
|
| 207 |
+
>>> a = Partition([1, 2], [3, 4, 5])
|
| 208 |
+
>>> b = Partition([1], [2, 3], [4], [5])
|
| 209 |
+
>>> a.rank, b.rank
|
| 210 |
+
(9, 34)
|
| 211 |
+
>>> a < b
|
| 212 |
+
True
|
| 213 |
+
"""
|
| 214 |
+
return self.sort_key() < sympify(other).sort_key()
|
| 215 |
+
|
| 216 |
+
@property
|
| 217 |
+
def rank(self):
|
| 218 |
+
"""
|
| 219 |
+
Gets the rank of a partition.
|
| 220 |
+
|
| 221 |
+
Examples
|
| 222 |
+
========
|
| 223 |
+
|
| 224 |
+
>>> from sympy.combinatorics import Partition
|
| 225 |
+
>>> a = Partition([1, 2], [3], [4, 5])
|
| 226 |
+
>>> a.rank
|
| 227 |
+
13
|
| 228 |
+
"""
|
| 229 |
+
if self._rank is not None:
|
| 230 |
+
return self._rank
|
| 231 |
+
self._rank = RGS_rank(self.RGS)
|
| 232 |
+
return self._rank
|
| 233 |
+
|
| 234 |
+
@property
|
| 235 |
+
def RGS(self):
|
| 236 |
+
"""
|
| 237 |
+
Returns the "restricted growth string" of the partition.
|
| 238 |
+
|
| 239 |
+
Explanation
|
| 240 |
+
===========
|
| 241 |
+
|
| 242 |
+
The RGS is returned as a list of indices, L, where L[i] indicates
|
| 243 |
+
the block in which element i appears. For example, in a partition
|
| 244 |
+
of 3 elements (a, b, c) into 2 blocks ([c], [a, b]) the RGS is
|
| 245 |
+
[1, 1, 0]: "a" is in block 1, "b" is in block 1 and "c" is in block 0.
|
| 246 |
+
|
| 247 |
+
Examples
|
| 248 |
+
========
|
| 249 |
+
|
| 250 |
+
>>> from sympy.combinatorics import Partition
|
| 251 |
+
>>> a = Partition([1, 2], [3], [4, 5])
|
| 252 |
+
>>> a.members
|
| 253 |
+
(1, 2, 3, 4, 5)
|
| 254 |
+
>>> a.RGS
|
| 255 |
+
(0, 0, 1, 2, 2)
|
| 256 |
+
>>> a + 1
|
| 257 |
+
Partition({3}, {4}, {5}, {1, 2})
|
| 258 |
+
>>> _.RGS
|
| 259 |
+
(0, 0, 1, 2, 3)
|
| 260 |
+
"""
|
| 261 |
+
rgs = {}
|
| 262 |
+
partition = self.partition
|
| 263 |
+
for i, part in enumerate(partition):
|
| 264 |
+
for j in part:
|
| 265 |
+
rgs[j] = i
|
| 266 |
+
return tuple([rgs[i] for i in sorted(
|
| 267 |
+
[i for p in partition for i in p], key=default_sort_key)])
|
| 268 |
+
|
| 269 |
+
@classmethod
|
| 270 |
+
def from_rgs(self, rgs, elements):
|
| 271 |
+
"""
|
| 272 |
+
Creates a set partition from a restricted growth string.
|
| 273 |
+
|
| 274 |
+
Explanation
|
| 275 |
+
===========
|
| 276 |
+
|
| 277 |
+
The indices given in rgs are assumed to be the index
|
| 278 |
+
of the element as given in elements *as provided* (the
|
| 279 |
+
elements are not sorted by this routine). Block numbering
|
| 280 |
+
starts from 0. If any block was not referenced in ``rgs``
|
| 281 |
+
an error will be raised.
|
| 282 |
+
|
| 283 |
+
Examples
|
| 284 |
+
========
|
| 285 |
+
|
| 286 |
+
>>> from sympy.combinatorics import Partition
|
| 287 |
+
>>> Partition.from_rgs([0, 1, 2, 0, 1], list('abcde'))
|
| 288 |
+
Partition({c}, {a, d}, {b, e})
|
| 289 |
+
>>> Partition.from_rgs([0, 1, 2, 0, 1], list('cbead'))
|
| 290 |
+
Partition({e}, {a, c}, {b, d})
|
| 291 |
+
>>> a = Partition([1, 4], [2], [3, 5])
|
| 292 |
+
>>> Partition.from_rgs(a.RGS, a.members)
|
| 293 |
+
Partition({2}, {1, 4}, {3, 5})
|
| 294 |
+
"""
|
| 295 |
+
if len(rgs) != len(elements):
|
| 296 |
+
raise ValueError('mismatch in rgs and element lengths')
|
| 297 |
+
max_elem = max(rgs) + 1
|
| 298 |
+
partition = [[] for i in range(max_elem)]
|
| 299 |
+
j = 0
|
| 300 |
+
for i in rgs:
|
| 301 |
+
partition[i].append(elements[j])
|
| 302 |
+
j += 1
|
| 303 |
+
if not all(p for p in partition):
|
| 304 |
+
raise ValueError('some blocks of the partition were empty.')
|
| 305 |
+
return Partition(*partition)
|
| 306 |
+
|
| 307 |
+
|
| 308 |
+
class IntegerPartition(Basic):
|
| 309 |
+
"""
|
| 310 |
+
This class represents an integer partition.
|
| 311 |
+
|
| 312 |
+
Explanation
|
| 313 |
+
===========
|
| 314 |
+
|
| 315 |
+
In number theory and combinatorics, a partition of a positive integer,
|
| 316 |
+
``n``, also called an integer partition, is a way of writing ``n`` as a
|
| 317 |
+
list of positive integers that sum to n. Two partitions that differ only
|
| 318 |
+
in the order of summands are considered to be the same partition; if order
|
| 319 |
+
matters then the partitions are referred to as compositions. For example,
|
| 320 |
+
4 has five partitions: [4], [3, 1], [2, 2], [2, 1, 1], and [1, 1, 1, 1];
|
| 321 |
+
the compositions [1, 2, 1] and [1, 1, 2] are the same as partition
|
| 322 |
+
[2, 1, 1].
|
| 323 |
+
|
| 324 |
+
See Also
|
| 325 |
+
========
|
| 326 |
+
|
| 327 |
+
sympy.utilities.iterables.partitions,
|
| 328 |
+
sympy.utilities.iterables.multiset_partitions
|
| 329 |
+
|
| 330 |
+
References
|
| 331 |
+
==========
|
| 332 |
+
|
| 333 |
+
.. [1] https://en.wikipedia.org/wiki/Partition_%28number_theory%29
|
| 334 |
+
"""
|
| 335 |
+
|
| 336 |
+
_dict = None
|
| 337 |
+
_keys = None
|
| 338 |
+
|
| 339 |
+
def __new__(cls, partition, integer=None):
|
| 340 |
+
"""
|
| 341 |
+
Generates a new IntegerPartition object from a list or dictionary.
|
| 342 |
+
|
| 343 |
+
Explanation
|
| 344 |
+
===========
|
| 345 |
+
|
| 346 |
+
The partition can be given as a list of positive integers or a
|
| 347 |
+
dictionary of (integer, multiplicity) items. If the partition is
|
| 348 |
+
preceded by an integer an error will be raised if the partition
|
| 349 |
+
does not sum to that given integer.
|
| 350 |
+
|
| 351 |
+
Examples
|
| 352 |
+
========
|
| 353 |
+
|
| 354 |
+
>>> from sympy.combinatorics.partitions import IntegerPartition
|
| 355 |
+
>>> a = IntegerPartition([5, 4, 3, 1, 1])
|
| 356 |
+
>>> a
|
| 357 |
+
IntegerPartition(14, (5, 4, 3, 1, 1))
|
| 358 |
+
>>> print(a)
|
| 359 |
+
[5, 4, 3, 1, 1]
|
| 360 |
+
>>> IntegerPartition({1:3, 2:1})
|
| 361 |
+
IntegerPartition(5, (2, 1, 1, 1))
|
| 362 |
+
|
| 363 |
+
If the value that the partition should sum to is given first, a check
|
| 364 |
+
will be made to see n error will be raised if there is a discrepancy:
|
| 365 |
+
|
| 366 |
+
>>> IntegerPartition(10, [5, 4, 3, 1])
|
| 367 |
+
Traceback (most recent call last):
|
| 368 |
+
...
|
| 369 |
+
ValueError: The partition is not valid
|
| 370 |
+
|
| 371 |
+
"""
|
| 372 |
+
if integer is not None:
|
| 373 |
+
integer, partition = partition, integer
|
| 374 |
+
if isinstance(partition, (dict, Dict)):
|
| 375 |
+
_ = []
|
| 376 |
+
for k, v in sorted(partition.items(), reverse=True):
|
| 377 |
+
if not v:
|
| 378 |
+
continue
|
| 379 |
+
k, v = as_int(k), as_int(v)
|
| 380 |
+
_.extend([k]*v)
|
| 381 |
+
partition = tuple(_)
|
| 382 |
+
else:
|
| 383 |
+
partition = tuple(sorted(map(as_int, partition), reverse=True))
|
| 384 |
+
sum_ok = False
|
| 385 |
+
if integer is None:
|
| 386 |
+
integer = sum(partition)
|
| 387 |
+
sum_ok = True
|
| 388 |
+
else:
|
| 389 |
+
integer = as_int(integer)
|
| 390 |
+
|
| 391 |
+
if not sum_ok and sum(partition) != integer:
|
| 392 |
+
raise ValueError("Partition did not add to %s" % integer)
|
| 393 |
+
if any(i < 1 for i in partition):
|
| 394 |
+
raise ValueError("All integer summands must be greater than one")
|
| 395 |
+
|
| 396 |
+
obj = Basic.__new__(cls, Integer(integer), Tuple(*partition))
|
| 397 |
+
obj.partition = list(partition)
|
| 398 |
+
obj.integer = integer
|
| 399 |
+
return obj
|
| 400 |
+
|
| 401 |
+
def prev_lex(self):
|
| 402 |
+
"""Return the previous partition of the integer, n, in lexical order,
|
| 403 |
+
wrapping around to [1, ..., 1] if the partition is [n].
|
| 404 |
+
|
| 405 |
+
Examples
|
| 406 |
+
========
|
| 407 |
+
|
| 408 |
+
>>> from sympy.combinatorics.partitions import IntegerPartition
|
| 409 |
+
>>> p = IntegerPartition([4])
|
| 410 |
+
>>> print(p.prev_lex())
|
| 411 |
+
[3, 1]
|
| 412 |
+
>>> p.partition > p.prev_lex().partition
|
| 413 |
+
True
|
| 414 |
+
"""
|
| 415 |
+
d = defaultdict(int)
|
| 416 |
+
d.update(self.as_dict())
|
| 417 |
+
keys = self._keys
|
| 418 |
+
if keys == [1]:
|
| 419 |
+
return IntegerPartition({self.integer: 1})
|
| 420 |
+
if keys[-1] != 1:
|
| 421 |
+
d[keys[-1]] -= 1
|
| 422 |
+
if keys[-1] == 2:
|
| 423 |
+
d[1] = 2
|
| 424 |
+
else:
|
| 425 |
+
d[keys[-1] - 1] = d[1] = 1
|
| 426 |
+
else:
|
| 427 |
+
d[keys[-2]] -= 1
|
| 428 |
+
left = d[1] + keys[-2]
|
| 429 |
+
new = keys[-2]
|
| 430 |
+
d[1] = 0
|
| 431 |
+
while left:
|
| 432 |
+
new -= 1
|
| 433 |
+
if left - new >= 0:
|
| 434 |
+
d[new] += left//new
|
| 435 |
+
left -= d[new]*new
|
| 436 |
+
return IntegerPartition(self.integer, d)
|
| 437 |
+
|
| 438 |
+
def next_lex(self):
|
| 439 |
+
"""Return the next partition of the integer, n, in lexical order,
|
| 440 |
+
wrapping around to [n] if the partition is [1, ..., 1].
|
| 441 |
+
|
| 442 |
+
Examples
|
| 443 |
+
========
|
| 444 |
+
|
| 445 |
+
>>> from sympy.combinatorics.partitions import IntegerPartition
|
| 446 |
+
>>> p = IntegerPartition([3, 1])
|
| 447 |
+
>>> print(p.next_lex())
|
| 448 |
+
[4]
|
| 449 |
+
>>> p.partition < p.next_lex().partition
|
| 450 |
+
True
|
| 451 |
+
"""
|
| 452 |
+
d = defaultdict(int)
|
| 453 |
+
d.update(self.as_dict())
|
| 454 |
+
key = self._keys
|
| 455 |
+
a = key[-1]
|
| 456 |
+
if a == self.integer:
|
| 457 |
+
d.clear()
|
| 458 |
+
d[1] = self.integer
|
| 459 |
+
elif a == 1:
|
| 460 |
+
if d[a] > 1:
|
| 461 |
+
d[a + 1] += 1
|
| 462 |
+
d[a] -= 2
|
| 463 |
+
else:
|
| 464 |
+
b = key[-2]
|
| 465 |
+
d[b + 1] += 1
|
| 466 |
+
d[1] = (d[b] - 1)*b
|
| 467 |
+
d[b] = 0
|
| 468 |
+
else:
|
| 469 |
+
if d[a] > 1:
|
| 470 |
+
if len(key) == 1:
|
| 471 |
+
d.clear()
|
| 472 |
+
d[a + 1] = 1
|
| 473 |
+
d[1] = self.integer - a - 1
|
| 474 |
+
else:
|
| 475 |
+
a1 = a + 1
|
| 476 |
+
d[a1] += 1
|
| 477 |
+
d[1] = d[a]*a - a1
|
| 478 |
+
d[a] = 0
|
| 479 |
+
else:
|
| 480 |
+
b = key[-2]
|
| 481 |
+
b1 = b + 1
|
| 482 |
+
d[b1] += 1
|
| 483 |
+
need = d[b]*b + d[a]*a - b1
|
| 484 |
+
d[a] = d[b] = 0
|
| 485 |
+
d[1] = need
|
| 486 |
+
return IntegerPartition(self.integer, d)
|
| 487 |
+
|
| 488 |
+
def as_dict(self):
|
| 489 |
+
"""Return the partition as a dictionary whose keys are the
|
| 490 |
+
partition integers and the values are the multiplicity of that
|
| 491 |
+
integer.
|
| 492 |
+
|
| 493 |
+
Examples
|
| 494 |
+
========
|
| 495 |
+
|
| 496 |
+
>>> from sympy.combinatorics.partitions import IntegerPartition
|
| 497 |
+
>>> IntegerPartition([1]*3 + [2] + [3]*4).as_dict()
|
| 498 |
+
{1: 3, 2: 1, 3: 4}
|
| 499 |
+
"""
|
| 500 |
+
if self._dict is None:
|
| 501 |
+
groups = group(self.partition, multiple=False)
|
| 502 |
+
self._keys = [g[0] for g in groups]
|
| 503 |
+
self._dict = dict(groups)
|
| 504 |
+
return self._dict
|
| 505 |
+
|
| 506 |
+
@property
|
| 507 |
+
def conjugate(self):
|
| 508 |
+
"""
|
| 509 |
+
Computes the conjugate partition of itself.
|
| 510 |
+
|
| 511 |
+
Examples
|
| 512 |
+
========
|
| 513 |
+
|
| 514 |
+
>>> from sympy.combinatorics.partitions import IntegerPartition
|
| 515 |
+
>>> a = IntegerPartition([6, 3, 3, 2, 1])
|
| 516 |
+
>>> a.conjugate
|
| 517 |
+
[5, 4, 3, 1, 1, 1]
|
| 518 |
+
"""
|
| 519 |
+
j = 1
|
| 520 |
+
temp_arr = list(self.partition) + [0]
|
| 521 |
+
k = temp_arr[0]
|
| 522 |
+
b = [0]*k
|
| 523 |
+
while k > 0:
|
| 524 |
+
while k > temp_arr[j]:
|
| 525 |
+
b[k - 1] = j
|
| 526 |
+
k -= 1
|
| 527 |
+
j += 1
|
| 528 |
+
return b
|
| 529 |
+
|
| 530 |
+
def __lt__(self, other):
|
| 531 |
+
"""Return True if self is less than other when the partition
|
| 532 |
+
is listed from smallest to biggest.
|
| 533 |
+
|
| 534 |
+
Examples
|
| 535 |
+
========
|
| 536 |
+
|
| 537 |
+
>>> from sympy.combinatorics.partitions import IntegerPartition
|
| 538 |
+
>>> a = IntegerPartition([3, 1])
|
| 539 |
+
>>> a < a
|
| 540 |
+
False
|
| 541 |
+
>>> b = a.next_lex()
|
| 542 |
+
>>> a < b
|
| 543 |
+
True
|
| 544 |
+
>>> a == b
|
| 545 |
+
False
|
| 546 |
+
"""
|
| 547 |
+
return list(reversed(self.partition)) < list(reversed(other.partition))
|
| 548 |
+
|
| 549 |
+
def __le__(self, other):
|
| 550 |
+
"""Return True if self is less than other when the partition
|
| 551 |
+
is listed from smallest to biggest.
|
| 552 |
+
|
| 553 |
+
Examples
|
| 554 |
+
========
|
| 555 |
+
|
| 556 |
+
>>> from sympy.combinatorics.partitions import IntegerPartition
|
| 557 |
+
>>> a = IntegerPartition([4])
|
| 558 |
+
>>> a <= a
|
| 559 |
+
True
|
| 560 |
+
"""
|
| 561 |
+
return list(reversed(self.partition)) <= list(reversed(other.partition))
|
| 562 |
+
|
| 563 |
+
def as_ferrers(self, char='#'):
|
| 564 |
+
"""
|
| 565 |
+
Prints the ferrer diagram of a partition.
|
| 566 |
+
|
| 567 |
+
Examples
|
| 568 |
+
========
|
| 569 |
+
|
| 570 |
+
>>> from sympy.combinatorics.partitions import IntegerPartition
|
| 571 |
+
>>> print(IntegerPartition([1, 1, 5]).as_ferrers())
|
| 572 |
+
#####
|
| 573 |
+
#
|
| 574 |
+
#
|
| 575 |
+
"""
|
| 576 |
+
return "\n".join([char*i for i in self.partition])
|
| 577 |
+
|
| 578 |
+
def __str__(self):
|
| 579 |
+
return str(list(self.partition))
|
| 580 |
+
|
| 581 |
+
|
| 582 |
+
def random_integer_partition(n, seed=None):
|
| 583 |
+
"""
|
| 584 |
+
Generates a random integer partition summing to ``n`` as a list
|
| 585 |
+
of reverse-sorted integers.
|
| 586 |
+
|
| 587 |
+
Examples
|
| 588 |
+
========
|
| 589 |
+
|
| 590 |
+
>>> from sympy.combinatorics.partitions import random_integer_partition
|
| 591 |
+
|
| 592 |
+
For the following, a seed is given so a known value can be shown; in
|
| 593 |
+
practice, the seed would not be given.
|
| 594 |
+
|
| 595 |
+
>>> random_integer_partition(100, seed=[1, 1, 12, 1, 2, 1, 85, 1])
|
| 596 |
+
[85, 12, 2, 1]
|
| 597 |
+
>>> random_integer_partition(10, seed=[1, 2, 3, 1, 5, 1])
|
| 598 |
+
[5, 3, 1, 1]
|
| 599 |
+
>>> random_integer_partition(1)
|
| 600 |
+
[1]
|
| 601 |
+
"""
|
| 602 |
+
from sympy.core.random import _randint
|
| 603 |
+
|
| 604 |
+
n = as_int(n)
|
| 605 |
+
if n < 1:
|
| 606 |
+
raise ValueError('n must be a positive integer')
|
| 607 |
+
|
| 608 |
+
randint = _randint(seed)
|
| 609 |
+
|
| 610 |
+
partition = []
|
| 611 |
+
while (n > 0):
|
| 612 |
+
k = randint(1, n)
|
| 613 |
+
mult = randint(1, n//k)
|
| 614 |
+
partition.append((k, mult))
|
| 615 |
+
n -= k*mult
|
| 616 |
+
partition.sort(reverse=True)
|
| 617 |
+
partition = flatten([[k]*m for k, m in partition])
|
| 618 |
+
return partition
|
| 619 |
+
|
| 620 |
+
|
| 621 |
+
def RGS_generalized(m):
|
| 622 |
+
"""
|
| 623 |
+
Computes the m + 1 generalized unrestricted growth strings
|
| 624 |
+
and returns them as rows in matrix.
|
| 625 |
+
|
| 626 |
+
Examples
|
| 627 |
+
========
|
| 628 |
+
|
| 629 |
+
>>> from sympy.combinatorics.partitions import RGS_generalized
|
| 630 |
+
>>> RGS_generalized(6)
|
| 631 |
+
Matrix([
|
| 632 |
+
[ 1, 1, 1, 1, 1, 1, 1],
|
| 633 |
+
[ 1, 2, 3, 4, 5, 6, 0],
|
| 634 |
+
[ 2, 5, 10, 17, 26, 0, 0],
|
| 635 |
+
[ 5, 15, 37, 77, 0, 0, 0],
|
| 636 |
+
[ 15, 52, 151, 0, 0, 0, 0],
|
| 637 |
+
[ 52, 203, 0, 0, 0, 0, 0],
|
| 638 |
+
[203, 0, 0, 0, 0, 0, 0]])
|
| 639 |
+
"""
|
| 640 |
+
d = zeros(m + 1)
|
| 641 |
+
for i in range(m + 1):
|
| 642 |
+
d[0, i] = 1
|
| 643 |
+
|
| 644 |
+
for i in range(1, m + 1):
|
| 645 |
+
for j in range(m):
|
| 646 |
+
if j <= m - i:
|
| 647 |
+
d[i, j] = j * d[i - 1, j] + d[i - 1, j + 1]
|
| 648 |
+
else:
|
| 649 |
+
d[i, j] = 0
|
| 650 |
+
return d
|
| 651 |
+
|
| 652 |
+
|
| 653 |
+
def RGS_enum(m):
|
| 654 |
+
"""
|
| 655 |
+
RGS_enum computes the total number of restricted growth strings
|
| 656 |
+
possible for a superset of size m.
|
| 657 |
+
|
| 658 |
+
Examples
|
| 659 |
+
========
|
| 660 |
+
|
| 661 |
+
>>> from sympy.combinatorics.partitions import RGS_enum
|
| 662 |
+
>>> from sympy.combinatorics import Partition
|
| 663 |
+
>>> RGS_enum(4)
|
| 664 |
+
15
|
| 665 |
+
>>> RGS_enum(5)
|
| 666 |
+
52
|
| 667 |
+
>>> RGS_enum(6)
|
| 668 |
+
203
|
| 669 |
+
|
| 670 |
+
We can check that the enumeration is correct by actually generating
|
| 671 |
+
the partitions. Here, the 15 partitions of 4 items are generated:
|
| 672 |
+
|
| 673 |
+
>>> a = Partition(list(range(4)))
|
| 674 |
+
>>> s = set()
|
| 675 |
+
>>> for i in range(20):
|
| 676 |
+
... s.add(a)
|
| 677 |
+
... a += 1
|
| 678 |
+
...
|
| 679 |
+
>>> assert len(s) == 15
|
| 680 |
+
|
| 681 |
+
"""
|
| 682 |
+
if (m < 1):
|
| 683 |
+
return 0
|
| 684 |
+
elif (m == 1):
|
| 685 |
+
return 1
|
| 686 |
+
else:
|
| 687 |
+
return bell(m)
|
| 688 |
+
|
| 689 |
+
|
| 690 |
+
def RGS_unrank(rank, m):
|
| 691 |
+
"""
|
| 692 |
+
Gives the unranked restricted growth string for a given
|
| 693 |
+
superset size.
|
| 694 |
+
|
| 695 |
+
Examples
|
| 696 |
+
========
|
| 697 |
+
|
| 698 |
+
>>> from sympy.combinatorics.partitions import RGS_unrank
|
| 699 |
+
>>> RGS_unrank(14, 4)
|
| 700 |
+
[0, 1, 2, 3]
|
| 701 |
+
>>> RGS_unrank(0, 4)
|
| 702 |
+
[0, 0, 0, 0]
|
| 703 |
+
"""
|
| 704 |
+
if m < 1:
|
| 705 |
+
raise ValueError("The superset size must be >= 1")
|
| 706 |
+
if rank < 0 or RGS_enum(m) <= rank:
|
| 707 |
+
raise ValueError("Invalid arguments")
|
| 708 |
+
|
| 709 |
+
L = [1] * (m + 1)
|
| 710 |
+
j = 1
|
| 711 |
+
D = RGS_generalized(m)
|
| 712 |
+
for i in range(2, m + 1):
|
| 713 |
+
v = D[m - i, j]
|
| 714 |
+
cr = j*v
|
| 715 |
+
if cr <= rank:
|
| 716 |
+
L[i] = j + 1
|
| 717 |
+
rank -= cr
|
| 718 |
+
j += 1
|
| 719 |
+
else:
|
| 720 |
+
L[i] = int(rank / v + 1)
|
| 721 |
+
rank %= v
|
| 722 |
+
return [x - 1 for x in L[1:]]
|
| 723 |
+
|
| 724 |
+
|
| 725 |
+
def RGS_rank(rgs):
|
| 726 |
+
"""
|
| 727 |
+
Computes the rank of a restricted growth string.
|
| 728 |
+
|
| 729 |
+
Examples
|
| 730 |
+
========
|
| 731 |
+
|
| 732 |
+
>>> from sympy.combinatorics.partitions import RGS_rank, RGS_unrank
|
| 733 |
+
>>> RGS_rank([0, 1, 2, 1, 3])
|
| 734 |
+
42
|
| 735 |
+
>>> RGS_rank(RGS_unrank(4, 7))
|
| 736 |
+
4
|
| 737 |
+
"""
|
| 738 |
+
rgs_size = len(rgs)
|
| 739 |
+
rank = 0
|
| 740 |
+
D = RGS_generalized(rgs_size)
|
| 741 |
+
for i in range(1, rgs_size):
|
| 742 |
+
n = len(rgs[(i + 1):])
|
| 743 |
+
m = max(rgs[0:i])
|
| 744 |
+
rank += D[n, m + 1] * rgs[i]
|
| 745 |
+
return rank
|
shared/package-files/65/657b2a6520d28ba046425441d6c5d4e05e0bc3b3ce51ba27ca96819eb892eb9b/blob
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
30.68705738,46.94755747,29.4834133,62.90543926
|
| 2 |
+
46.94755747,256.9386831,62.90543926,240.4775051
|