qairt-visualizer 0.5.1__py3-none-win_amd64.whl → 0.7.0__py3-none-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (311) hide show
  1. qairt_visualizer/core/helpers/version.py +23 -0
  2. qairt_visualizer/core/launchers/base_ui_launcher_context.py +28 -7
  3. qairt_visualizer/core/launchers/electron_launcher_context.py +72 -3
  4. qairt_visualizer/core/parsers/dlc_parser/dlc_parser.py +105 -33
  5. qairt_visualizer/core/parsers/dlc_parser/get_source_topology.py +47 -0
  6. qairt_visualizer/core/parsers/dlc_parser/libDlModelToolsPy.pyd +0 -0
  7. qairt_visualizer/core/parsers/dlc_parser/libDlModelToolsPy.so +0 -0
  8. qairt_visualizer/core/parsers/dlc_parser/libPyIrGraph.pyd +0 -0
  9. qairt_visualizer/core/parsers/dlc_parser/libPyIrGraph.so +0 -0
  10. qairt_visualizer/core/parsers/dlc_parser/models/op_tensor_mappings.py +8 -4
  11. qairt_visualizer/core/ui/dist/browser/__init__.py +47 -0
  12. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/acuity.js → acuity.js} +3 -3
  13. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/app.js → app.js} +63 -57
  14. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/armnn-schema.js → armnn-schema.js} +590 -5
  15. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/armnn.js → armnn.js} +3 -5
  16. qairt_visualizer/core/ui/dist/browser/assets/i18n/common/en.json +8 -2
  17. qairt_visualizer/core/ui/dist/browser/assets/i18n/graph/en.json +44 -36
  18. qairt_visualizer/core/ui/dist/browser/assets/i18n/panels/en.json +9 -3
  19. qairt_visualizer/core/ui/dist/browser/assets/i18n/panels/model-diff/en.json +6 -0
  20. qairt_visualizer/core/ui/dist/browser/assets/i18n/workspaces/en.json +3 -0
  21. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/barracuda.js → barracuda.js} +3 -3
  22. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/base.js → base.js} +20 -16
  23. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/bigdl.js → bigdl.js} +2 -2
  24. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/browser.js → browser.js} +59 -49
  25. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/caffe.js → caffe.js} +3 -3
  26. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/caffe2-proto.js → caffe2-proto.js} +26 -26
  27. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/caffe2.js → caffe2.js} +113 -114
  28. qairt_visualizer/core/ui/dist/browser/chunk-3SMGFPTN.js +11 -0
  29. qairt_visualizer/core/ui/dist/browser/chunk-43LQFSHA.js +1 -0
  30. qairt_visualizer/core/ui/dist/browser/chunk-447NKSFT.js +1 -0
  31. qairt_visualizer/core/ui/dist/browser/chunk-5MAR72QP.js +1 -0
  32. qairt_visualizer/core/ui/dist/browser/chunk-7PTY53DS.js +5 -0
  33. qairt_visualizer/core/ui/dist/browser/chunk-GAUD627J.js +1 -0
  34. qairt_visualizer/core/ui/dist/browser/chunk-H7TLLCSI.js +1 -0
  35. qairt_visualizer/core/ui/dist/browser/chunk-HISUA6LZ.js +4 -0
  36. qairt_visualizer/core/ui/dist/browser/chunk-HXB7IAZI.js +1 -0
  37. qairt_visualizer/core/ui/dist/browser/chunk-JPD5T7FP.js +120 -0
  38. qairt_visualizer/core/ui/dist/browser/chunk-L3QJ7DR2.js +1 -0
  39. qairt_visualizer/core/ui/dist/browser/{chunk-HBP6TEQ6.js → chunk-MCR4N53U.js} +1 -1
  40. qairt_visualizer/core/ui/dist/browser/chunk-QD7PA2I4.js +19 -0
  41. qairt_visualizer/core/ui/dist/browser/chunk-TKZG6FLW.js +12 -0
  42. qairt_visualizer/core/ui/dist/browser/chunk-WFAVWONI.js +5 -0
  43. qairt_visualizer/core/ui/dist/browser/chunk-WRMDGTCT.js +35 -0
  44. qairt_visualizer/core/ui/dist/browser/chunk-X25J6H7V.js +1 -0
  45. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/circle-schema.js → circle-schema.js} +17 -0
  46. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/circle.js → circle.js} +3 -3
  47. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/cntk.js → cntk.js} +1 -1
  48. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/coreml-proto.js → coreml-proto.js} +1 -0
  49. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/coreml.js → coreml.js} +24 -21
  50. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/dagre.js → dagre.js} +5 -5
  51. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/darknet-metadata.json → darknet-metadata.json} +0 -1
  52. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/darknet.js → darknet.js} +3 -3
  53. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/electron.mjs → desktop.mjs} +44 -131
  54. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/dl4j.js → dl4j.js} +5 -2
  55. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/dlc-schema.js → dlc-schema.js} +8 -8
  56. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/dlc.js → dlc.js} +110 -29
  57. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/dnn.js → dnn.js} +2 -4
  58. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/dot.js → dot.js} +1 -1
  59. qairt_visualizer/core/ui/dist/browser/eaix.js +24 -0
  60. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/espresso.js → espresso.js} +1 -1
  61. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/executorch-schema.js → executorch-schema.js} +363 -42
  62. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/executorch.js → executorch.js} +108 -40
  63. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/flatbuffers.js → flatbuffers.js} +1 -1
  64. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/flax.js → flax.js} +1 -1
  65. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/flux.js → flux.js} +2 -2
  66. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/gguf.js → gguf.js} +44 -24
  67. qairt_visualizer/core/ui/dist/browser/grapher.css +145 -0
  68. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/grapher.js → grapher.js} +24 -48
  69. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/hailo.js → hailo.js} +1 -1
  70. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/hickle.js → hickle.js} +1 -1
  71. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/imgdnn.js → imgdnn.js} +1 -1
  72. qairt_visualizer/core/ui/dist/browser/index.html +15 -16
  73. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/index.js → index.js} +2 -24
  74. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/json.js → json.js} +28 -3
  75. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/kann.js → kann.js} +1 -1
  76. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/keras-metadata.json → keras-metadata.json} +15 -7
  77. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/keras.js → keras.js} +13 -7
  78. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/kmodel.js → kmodel.js} +3 -3
  79. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/lasagne.js → lasagne.js} +2 -2
  80. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/lightgbm.js → lightgbm.js} +1 -1
  81. qairt_visualizer/core/ui/dist/browser/main-EVI665MB.js +1 -0
  82. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/mediapipe.js → mediapipe.js} +1 -1
  83. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/megengine.js → megengine.js} +1 -1
  84. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/message.js → message.js} +3 -2
  85. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/mlir.js → mlir.js} +53 -17
  86. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/mlnet.js → mlnet.js} +2 -3
  87. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/mnn-schema.js → mnn-schema.js} +9 -6
  88. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/mnn.js → mnn.js} +2 -2
  89. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/mslite.js → mslite.js} +3 -3
  90. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/mxnet.js → mxnet.js} +2 -2
  91. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/ncnn.js → ncnn.js} +3 -2
  92. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/nnabla.js → nnabla.js} +4 -4
  93. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/nnef.js → nnef.js} +1 -1
  94. qairt_visualizer/core/ui/dist/browser/node.js +102 -0
  95. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/numpy.js → numpy.js} +9 -9
  96. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/om.js → om.js} +2 -2
  97. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/onednn.js → onednn.js} +1 -1
  98. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/onnx-metadata.json → onnx-metadata.json} +3500 -233
  99. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/onnx-proto.js → onnx-proto.js} +436 -4
  100. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/onnx.js → onnx.js} +284 -199
  101. qairt_visualizer/core/ui/dist/browser/onnx.py +231 -0
  102. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/openvino.js → openvino.js} +36 -31
  103. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/paddle-proto.js → paddle-proto.js} +54 -54
  104. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/paddle.js → paddle.js} +22 -3
  105. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/pickle.js → pickle.js} +3 -3
  106. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/python.js → python.js} +743 -325
  107. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/pytorch-metadata.json → pytorch-metadata.json} +3217 -2934
  108. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/pytorch-proto.js → pytorch-proto.js} +4 -4
  109. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/pytorch.js → pytorch.js} +172 -86
  110. qairt_visualizer/core/ui/dist/browser/pytorch.py +304 -0
  111. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/qnn.js → qnn.js} +6 -2
  112. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/rknn.js → rknn.js} +3 -3
  113. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/safetensors.js → safetensors.js} +2 -2
  114. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/sentencepiece.js → sentencepiece.js} +1 -1
  115. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/server.py → server.py} +95 -103
  116. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/sklearn-metadata.json → sklearn-metadata.json} +15 -10
  117. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/sklearn.js → sklearn.js} +5 -5
  118. qairt_visualizer/core/ui/dist/browser/{styles-MRR6DOT2.css → styles-2Z5PB4WZ.css} +1 -1
  119. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/tar.js → tar.js} +18 -1
  120. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/tengine.js → tengine.js} +1 -1
  121. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/tensorrt.js → tensorrt.js} +1 -1
  122. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/tf-metadata.json → tf-metadata.json} +1255 -163
  123. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/tf-proto.js → tf-proto.js} +46 -12
  124. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/tf.js → tf.js} +36 -13
  125. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/tflite.js → tflite.js} +18 -21
  126. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/tnn.js → tnn.js} +1 -3
  127. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/torch.js → torch.js} +1 -1
  128. qairt_visualizer/core/ui/dist/browser/transformers.js +171 -0
  129. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/tvm.js → tvm.js} +2 -2
  130. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/uff.js → uff.js} +2 -2
  131. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/view.js → view.js} +1406 -1115
  132. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/weka.js → weka.js} +3 -4
  133. qairt_visualizer/core/ui/dist/browser/worker-EHYFMTM7.js +1 -0
  134. qairt_visualizer/core/ui/dist/browser/worker-KX5DA6GL.js +4 -0
  135. qairt_visualizer/core/ui/dist/browser/xgboost.js +59 -0
  136. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/xml.js → xml.js} +2 -2
  137. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/xmodel.js → xmodel.js} +1 -1
  138. qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/zip.js → zip.js} +38 -41
  139. qairt_visualizer/core/ui/dist/qairt_visualizer.exe +0 -0
  140. qairt_visualizer/core/ui/dist/resources/app.asar +0 -0
  141. {qairt_visualizer-0.5.1.dist-info → qairt_visualizer-0.7.0.dist-info}/METADATA +1 -1
  142. qairt_visualizer-0.7.0.dist-info/RECORD +265 -0
  143. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/CITATION.cff +0 -10
  144. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/CONTRIBUTING.md +0 -29
  145. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/LICENSE +0 -21
  146. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/README.md +0 -36
  147. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/jenkins/Jenkinsfile +0 -69
  148. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/package-lock.json +0 -5743
  149. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/package.js +0 -689
  150. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/package.json +0 -53
  151. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/package.py +0 -87
  152. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/publish/background.png +0 -0
  153. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/publish/background.svg +0 -5
  154. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/publish/background@2x.png +0 -0
  155. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/publish/electron-builder.json +0 -109
  156. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/publish/eslint.config.js +0 -231
  157. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/publish/forge.config.js +0 -87
  158. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/publish/icon.html +0 -27
  159. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/publish/icon.icns +0 -0
  160. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/publish/icon.icns.svg +0 -175
  161. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/publish/icon.ico +0 -0
  162. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/publish/icon.png +0 -0
  163. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/publish/icon.svg +0 -179
  164. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/publish/notarize.cjs +0 -24
  165. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/publish/pyproject.toml +0 -63
  166. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/publish/setup.py +0 -43
  167. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/resolve_upgrade_merge.sh +0 -10
  168. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/source/__init__.py +0 -41
  169. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/source/cambricon.js +0 -32
  170. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/source/favicon.ico +0 -0
  171. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/source/grapher.css +0 -602
  172. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/source/index.html +0 -2222
  173. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/source/modular.js +0 -81
  174. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/source/onnx.py +0 -227
  175. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/source/pytorch.py +0 -298
  176. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/source/qais/qcontrol.js +0 -207
  177. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/source/qais/qgraph-toolkit.js +0 -123
  178. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/source/qais/qsubgraph.js +0 -226
  179. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/source/qais/qsummary-panel.js +0 -89
  180. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/source/server.js +0 -250
  181. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/test/backend.py +0 -80
  182. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/test/measures.py +0 -27
  183. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/test/models.js +0 -359
  184. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/test/models.json +0 -8523
  185. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/test/worker.js +0 -859
  186. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/tools/armnn +0 -33
  187. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/tools/bigdl +0 -33
  188. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/tools/caffe +0 -37
  189. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/tools/caffe-script.js +0 -12
  190. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/tools/circle +0 -43
  191. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/tools/circle-script.js +0 -87
  192. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/tools/circle_script.js +0 -73
  193. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/tools/cntk +0 -33
  194. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/tools/coreml +0 -49
  195. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/tools/dlc +0 -20
  196. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/tools/dlc.fbs +0 -165
  197. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/tools/dnn +0 -20
  198. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/tools/dnn.proto +0 -79
  199. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/tools/executorch +0 -41
  200. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/tools/flatc.js +0 -1315
  201. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/tools/gguf +0 -22
  202. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/tools/kann +0 -33
  203. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/tools/keras +0 -62
  204. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/tools/keras_metadata.py +0 -205
  205. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/tools/keras_script.py +0 -204
  206. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/tools/mediapipe +0 -72
  207. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/tools/megengine +0 -47
  208. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/tools/megengine-script.js +0 -113
  209. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/tools/megengine_script.js +0 -112
  210. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/tools/mnn +0 -40
  211. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/tools/mslite +0 -45
  212. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/tools/mslite-script.js +0 -83
  213. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/tools/mslite_metadata.js +0 -82
  214. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/tools/nnabla +0 -79
  215. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/tools/nnabla_script.py +0 -145
  216. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/tools/om +0 -26
  217. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/tools/om.proto +0 -204
  218. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/tools/onnx +0 -135
  219. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/tools/onnx_metadata.py +0 -233
  220. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/tools/onnx_script.py +0 -332
  221. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/tools/paddle +0 -38
  222. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/tools/protoc.js +0 -1609
  223. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/tools/pytorch +0 -85
  224. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/tools/pytorch_metadata.py +0 -166
  225. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/tools/pytorch_script.py +0 -404
  226. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/tools/rknn +0 -20
  227. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/tools/rknn.fbs +0 -78
  228. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/tools/sentencepiece +0 -39
  229. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/tools/sklearn +0 -65
  230. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/tools/sklearn_metadata.py +0 -126
  231. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/tools/sklearn_script.py +0 -129
  232. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/tools/tf +0 -97
  233. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/tools/tf_metadata.py +0 -403
  234. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/tools/tf_script.py +0 -422
  235. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/tools/tflite-script.js +0 -87
  236. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/tools/tflite_metadata.js +0 -73
  237. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/tools/uff +0 -20
  238. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/tools/uff.proto +0 -127
  239. qairt_visualizer/core/ui/dist/browser/assets/netron_plugin/tools/xmodel +0 -36
  240. qairt_visualizer/core/ui/dist/browser/chunk-3NAQCYEU.js +0 -1
  241. qairt_visualizer/core/ui/dist/browser/chunk-NFKTPX3Z.js +0 -11
  242. qairt_visualizer/core/ui/dist/browser/chunk-OMI6HJ5Y.js +0 -19
  243. qairt_visualizer/core/ui/dist/browser/chunk-TTZXMRJ5.js +0 -34
  244. qairt_visualizer/core/ui/dist/browser/main-NXPVOKMG.js +0 -1
  245. qairt_visualizer/core/ui/dist/browser/worker-5VPKG2GV.js +0 -4
  246. qairt_visualizer/core/ui/dist/browser/worker-UVGWDZ5K.js +0 -1
  247. qairt_visualizer-0.5.1.dist-info/RECORD +0 -337
  248. /qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/acuity-metadata.json → acuity-metadata.json} +0 -0
  249. /qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/armnn-metadata.json → armnn-metadata.json} +0 -0
  250. /qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/bigdl-metadata.json → bigdl-metadata.json} +0 -0
  251. /qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/bigdl-proto.js → bigdl-proto.js} +0 -0
  252. /qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/caffe-metadata.json → caffe-metadata.json} +0 -0
  253. /qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/caffe-proto.js → caffe-proto.js} +0 -0
  254. /qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/caffe2-metadata.json → caffe2-metadata.json} +0 -0
  255. /qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/catboost.js → catboost.js} +0 -0
  256. /qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/circle-metadata.json → circle-metadata.json} +0 -0
  257. /qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/cntk-metadata.json → cntk-metadata.json} +0 -0
  258. /qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/cntk-proto.js → cntk-proto.js} +0 -0
  259. /qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/coreml-metadata.json → coreml-metadata.json} +0 -0
  260. /qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/dl4j-metadata.json → dl4j-metadata.json} +0 -0
  261. /qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/dlc-metadata.json → dlc-metadata.json} +0 -0
  262. /qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/dnn-metadata.json → dnn-metadata.json} +0 -0
  263. /qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/dnn-proto.js → dnn-proto.js} +0 -0
  264. /qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/espresso-metadata.json → espresso-metadata.json} +0 -0
  265. /qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/flexbuffers.js → flexbuffers.js} +0 -0
  266. /qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/flux-metadata.json → flux-metadata.json} +0 -0
  267. /qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/hailo-metadata.json → hailo-metadata.json} +0 -0
  268. /qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/hdf5.js → hdf5.js} +0 -0
  269. /qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/icon.png → icon.png} +0 -0
  270. /qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/kann-metadata.json → kann-metadata.json} +0 -0
  271. /qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/kann-schema.js → kann-schema.js} +0 -0
  272. /qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/keras-proto.js → keras-proto.js} +0 -0
  273. /qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/lasagne-metadata.json → lasagne-metadata.json} +0 -0
  274. /qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/megengine-metadata.json → megengine-metadata.json} +0 -0
  275. /qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/megengine-schema.js → megengine-schema.js} +0 -0
  276. /qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/mlnet-metadata.json → mlnet-metadata.json} +0 -0
  277. /qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/mnn-metadata.json → mnn-metadata.json} +0 -0
  278. /qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/mslite-metadata.json → mslite-metadata.json} +0 -0
  279. /qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/mslite-schema.js → mslite-schema.js} +0 -0
  280. /qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/mxnet-metadata.json → mxnet-metadata.json} +0 -0
  281. /qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/ncnn-metadata.json → ncnn-metadata.json} +0 -0
  282. /qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/nnabla-metadata.json → nnabla-metadata.json} +0 -0
  283. /qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/nnabla-proto.js → nnabla-proto.js} +0 -0
  284. /qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/nnc.js → nnc.js} +0 -0
  285. /qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/om-metadata.json → om-metadata.json} +0 -0
  286. /qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/om-proto.js → om-proto.js} +0 -0
  287. /qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/onednn-metadata.json → onednn-metadata.json} +0 -0
  288. /qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/onnx-schema.js → onnx-schema.js} +0 -0
  289. /qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/openvino-metadata.json → openvino-metadata.json} +0 -0
  290. /qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/paddle-metadata.json → paddle-metadata.json} +0 -0
  291. /qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/paddle-schema.js → paddle-schema.js} +0 -0
  292. /qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/protobuf.js → protobuf.js} +0 -0
  293. /qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/pytorch-schema.js → pytorch-schema.js} +0 -0
  294. /qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/qnn-metadata.json → qnn-metadata.json} +0 -0
  295. /qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/rknn-metadata.json → rknn-metadata.json} +0 -0
  296. /qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/rknn-schema.js → rknn-schema.js} +0 -0
  297. /qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/sentencepiece-proto.js → sentencepiece-proto.js} +0 -0
  298. /qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/tengine-metadata.json → tengine-metadata.json} +0 -0
  299. /qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/text.js → text.js} +0 -0
  300. /qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/tflite-metadata.json → tflite-metadata.json} +0 -0
  301. /qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/tflite-schema.js → tflite-schema.js} +0 -0
  302. /qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/tnn-metadata.json → tnn-metadata.json} +0 -0
  303. /qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/torch-metadata.json → torch-metadata.json} +0 -0
  304. /qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/uff-metadata.json → uff-metadata.json} +0 -0
  305. /qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/uff-proto.js → uff-proto.js} +0 -0
  306. /qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/worker.js → worker.js} +0 -0
  307. /qairt_visualizer/core/ui/dist/browser/{assets/netron_plugin/source/xmodel-proto.js → xmodel-proto.js} +0 -0
  308. {qairt_visualizer-0.5.1.dist-info → qairt_visualizer-0.7.0.dist-info}/LICENSE.pdf +0 -0
  309. {qairt_visualizer-0.5.1.dist-info → qairt_visualizer-0.7.0.dist-info}/WHEEL +0 -0
  310. {qairt_visualizer-0.5.1.dist-info → qairt_visualizer-0.7.0.dist-info}/entry_points.txt +0 -0
  311. {qairt_visualizer-0.5.1.dist-info → qairt_visualizer-0.7.0.dist-info}/top_level.txt +0 -0
@@ -6,7 +6,9 @@ const python = {};
6
6
  python.Execution = class {
7
7
 
8
8
  constructor(sources) {
9
+ /* eslint-disable consistent-this */
9
10
  const self = this;
11
+ /* eslint-enable consistent-this */
10
12
  const execution = self;
11
13
  this._sources = sources || new Map();
12
14
  this._events = new Map();
@@ -124,7 +126,7 @@ python.Execution = class {
124
126
  const operator = this.register('operator');
125
127
  this.register('_codecs');
126
128
  this.register('argparse');
127
- this._enum = this.register('enum');
129
+ this.enum = this.register('enum');
128
130
  this.register('collections');
129
131
  const copy = this.register('copy');
130
132
  this.register('copy_reg');
@@ -167,6 +169,7 @@ python.Execution = class {
167
169
  const torch = this.register('torch');
168
170
  this.torch = torch;
169
171
  const torchvision = this.register('torchvision');
172
+ const torchao = this.register('torchao');
170
173
  this.register('torch.storage');
171
174
  this.register('torch.nn.parameter');
172
175
  this.register('torch.ops');
@@ -653,7 +656,7 @@ python.Execution = class {
653
656
  const position = this._position();
654
657
  const body = [];
655
658
  while (!this._tokenizer.match('eof')) {
656
- const statement = this._statement();
659
+ const statement = this._parseStatement();
657
660
  if (statement) {
658
661
  body.push(statement);
659
662
  continue;
@@ -670,7 +673,7 @@ python.Execution = class {
670
673
  this._mark(node, position);
671
674
  return node;
672
675
  }
673
- _suite() {
676
+ _parseSuite() {
674
677
  const body = [];
675
678
  let statement = null;
676
679
  if (this._tokenizer.eat('\n')) {
@@ -679,7 +682,7 @@ python.Execution = class {
679
682
  if (this._tokenizer.eat(';')) {
680
683
  continue;
681
684
  }
682
- statement = this._statement();
685
+ statement = this._parseStatement();
683
686
  if (statement) {
684
687
  body.push(statement);
685
688
  continue;
@@ -698,7 +701,7 @@ python.Execution = class {
698
701
  if (this._tokenizer.eat(';')) {
699
702
  continue;
700
703
  }
701
- statement = this._statement();
704
+ statement = this._parseStatement();
702
705
  if (statement) {
703
706
  body.push(statement);
704
707
  continue;
@@ -709,7 +712,7 @@ python.Execution = class {
709
712
  }
710
713
  return body;
711
714
  }
712
- _statement() {
715
+ _parseStatement() {
713
716
  let node = null;
714
717
  let position = this._position();
715
718
  if (this._eat('id', 'break')) {
@@ -721,30 +724,30 @@ python.Execution = class {
721
724
  return this._mark(node, position);
722
725
  }
723
726
  if (this._eat('id', 'return')) {
724
- const value = this._expression(-1, [], true);
727
+ const value = this._parseExpression(-1, [], true);
725
728
  const node = new ast.Return(value);
726
729
  return this._mark(node, position);
727
730
  }
728
731
  if (this._eat('id', 'raise')) {
729
- let exc = this._expression(-1, ['from']);
732
+ let exc = this._parseExpression(-1, ['from']);
730
733
  let cause = null;
731
734
  if (this._tokenizer.eat('id', 'from')) {
732
- cause = this._expression();
735
+ cause = this._parseExpression();
733
736
  } else if (this._tokenizer.eat(',')) {
734
737
  exc = [exc];
735
- exc.push(this._expression());
738
+ exc.push(this._parseExpression());
736
739
  if (this._tokenizer.eat(',')) {
737
- exc.push(this._expression());
740
+ exc.push(this._parseExpression());
738
741
  }
739
742
  }
740
743
  node = new ast.Raise(exc, cause);
741
744
  return this._mark(node, position);
742
745
  }
743
746
  if (this._eat('id', 'assert')) {
744
- const test = this._expression(-1, [',']);
747
+ const test = this._parseExpression(-1, [',']);
745
748
  let msg = null;
746
749
  if (this._tokenizer.eat(',')) {
747
- msg = this._expression();
750
+ msg = this._parseExpression();
748
751
  }
749
752
  node = new ast.Assert(test, msg);
750
753
  return this._mark(node, position);
@@ -752,7 +755,7 @@ python.Execution = class {
752
755
  if (this._eat('id', 'global')) {
753
756
  const names = [];
754
757
  do {
755
- const name = this._name(true);
758
+ const name = this._parseName(true);
756
759
  names.push(name.id);
757
760
  }
758
761
  while (this._tokenizer.eat(','));
@@ -762,7 +765,7 @@ python.Execution = class {
762
765
  if (this._eat('id', 'nonlocal')) {
763
766
  const names = [];
764
767
  do {
765
- const name = this._name(true);
768
+ const name = this._parseName(true);
766
769
  names.push(name.id);
767
770
  }
768
771
  while (this._tokenizer.eat(','));
@@ -772,10 +775,10 @@ python.Execution = class {
772
775
  if (this._eat('id', 'import')) {
773
776
  const names = [];
774
777
  do {
775
- const name = this._dottedName();
778
+ const name = this._parseDottedName();
776
779
  let asname = null;
777
780
  if (this._tokenizer.eat('id', 'as')) {
778
- asname = this._name(true).id;
781
+ asname = this._parseName(true).id;
779
782
  }
780
783
  const node = new ast.alias(name, asname);
781
784
  names.push(node);
@@ -791,15 +794,15 @@ python.Execution = class {
791
794
  this._eat(dots.type);
792
795
  level = Array.from(dots.type).length;
793
796
  }
794
- const module = this._dottedName();
797
+ const module = this._parseDottedName();
795
798
  this._tokenizer.expect('id', 'import');
796
799
  const names = [];
797
800
  const close = this._tokenizer.eat('(');
798
801
  do {
799
- const name = this._name(true).id;
802
+ const name = this._parseName(true).id;
800
803
  let asname = null;
801
804
  if (this._tokenizer.eat('id', 'as')) {
802
- asname = this._name(true).id;
805
+ asname = this._parseName(true).id;
803
806
  }
804
807
  const node = new ast.alias(name, asname);
805
808
  names.push(node);
@@ -814,14 +817,14 @@ python.Execution = class {
814
817
  const decorator_list = this._decorator();
815
818
  position = this._position();
816
819
  if (this._eat('id', 'class')) {
817
- const name = this._name(true);
820
+ const name = this._parseName(true);
818
821
  const bases = [];
819
822
  if (this._tokenizer.eat('(')) {
820
823
  while (!this._tokenizer.eat(')')) {
821
824
  if (this._tokenizer.eat('\n')) {
822
825
  continue;
823
826
  }
824
- const expression = this._expression(-1, [], false);
827
+ const expression = this._parseExpression(-1, [], false);
825
828
  if (expression === null) {
826
829
  throw new python.Error(`Expected expression ${this._location()}`);
827
830
  }
@@ -834,7 +837,7 @@ python.Execution = class {
834
837
  }
835
838
  }
836
839
  this._tokenizer.expect(':');
837
- const body = this._suite();
840
+ const body = this._parseSuite();
838
841
  const node = new ast.ClassDef(name.id, bases, null, body, decorator_list, null);
839
842
  return this._mark(node, position);
840
843
  }
@@ -846,15 +849,15 @@ python.Execution = class {
846
849
  throw new python.Error(`Expected 'def', 'with' or 'for' ${this._location()}`);
847
850
  }
848
851
  if (this._eat('id', 'def')) {
849
- const name = this._name(true);
852
+ const name = this._parseName(true);
850
853
  this._tokenizer.expect('(');
851
- const args = this._arguments(')');
854
+ const args = this._parseArguments(')');
852
855
  let returns = null;
853
856
  if (this._tokenizer.eat('->')) {
854
- returns = this._type();
857
+ returns = this._parseType();
855
858
  }
856
859
  this._tokenizer.expect(':');
857
- const body = this._suite();
860
+ const body = this._parseSuite();
858
861
  const node = new ast.FunctionDef(name.id, args, body, decorator_list, returns, null, null);
859
862
  if (async) {
860
863
  node.async = async;
@@ -865,39 +868,39 @@ python.Execution = class {
865
868
  throw new python.Error('Unexpected decorator.');
866
869
  }
867
870
  if (this._eat('id', 'del')) {
868
- const targets = this._expression(-1, [], true);
871
+ const targets = this._parseExpression(-1, [], true);
869
872
  node = new ast.Del(targets);
870
873
  return this._mark(node, position);
871
874
  }
872
875
  if (this._eat('id', 'if')) {
873
- const test = this._expression();
876
+ const test = this._parseExpression();
874
877
  this._tokenizer.expect(':');
875
- const body = this._suite();
878
+ const body = this._parseSuite();
876
879
  const node = new ast.If(test, body);
877
880
  let current = node;
878
881
  this._tokenizer.eat('\n');
879
882
  while (this._tokenizer.eat('id', 'elif')) {
880
- const test = this._expression();
883
+ const test = this._parseExpression();
881
884
  this._tokenizer.expect(':');
882
- const body = this._suite();
885
+ const body = this._parseSuite();
883
886
  current.orelse = new ast.If(test, body);
884
887
  current = current.orelse;
885
888
  this._tokenizer.eat('\n');
886
889
  }
887
890
  if (this._tokenizer.eat('id', 'else')) {
888
891
  this._tokenizer.expect(':');
889
- current.orelse = this._suite();
892
+ current.orelse = this._parseSuite();
890
893
  }
891
894
  return this._mark(node, position);
892
895
  }
893
896
  if (this._eat('id', 'while')) {
894
- const test = this._expression();
897
+ const test = this._parseExpression();
895
898
  this._tokenizer.expect(':');
896
- const body = this._suite();
899
+ const body = this._parseSuite();
897
900
  let orelse = null;
898
901
  if (this._tokenizer.eat('id', 'else')) {
899
902
  this._tokenizer.expect(':');
900
- orelse = this._suite();
903
+ orelse = this._parseSuite();
901
904
  }
902
905
  const node = new ast.While(test, body, orelse);
903
906
  return this._mark(node, position);
@@ -907,7 +910,7 @@ python.Execution = class {
907
910
  return this._mark(node, position);
908
911
  }
909
912
  if (this._eat('id', 'for')) {
910
- let target = this._expression(-1, ['in']);
913
+ let target = this._parseExpression(-1, ['in']);
911
914
  while (this._tokenizer.eat(',')) {
912
915
  if (target instanceof ast.Tuple === false) {
913
916
  target = new ast.Tuple([target]);
@@ -916,10 +919,10 @@ python.Execution = class {
916
919
  target.elts.push({});
917
920
  break;
918
921
  }
919
- target.elts.push(this._expression(-1, ['in']));
922
+ target.elts.push(this._parseExpression(-1, ['in']));
920
923
  }
921
924
  this._tokenizer.expect('id', 'in');
922
- let iter = this._expression();
925
+ let iter = this._parseExpression();
923
926
  while (this._tokenizer.eat(',')) {
924
927
  if (iter.type !== 'tuple') {
925
928
  iter = new ast.Tuple([iter]);
@@ -928,14 +931,14 @@ python.Execution = class {
928
931
  iter.elts.push({});
929
932
  break;
930
933
  }
931
- iter.elts.push(this._expression(-1, ['in']));
934
+ iter.elts.push(this._parseExpression(-1, ['in']));
932
935
  }
933
936
  this._tokenizer.expect(':');
934
- const body = this._suite();
937
+ const body = this._parseSuite();
935
938
  let orelse = null;
936
939
  if (this._tokenizer.eat('id', 'else')) {
937
940
  this._tokenizer.expect(':');
938
- orelse = this._suite();
941
+ orelse = this._parseSuite();
939
942
  }
940
943
  const node = new ast.For(target, iter, body, orelse);
941
944
  return this._mark(node, position);
@@ -943,17 +946,17 @@ python.Execution = class {
943
946
  if (this._eat('id', 'with')) {
944
947
  const items = [];
945
948
  do {
946
- const context_expr = this._expression();
949
+ const context_expr = this._parseExpression();
947
950
  let optional_vars = null;
948
951
  if (this._tokenizer.eat('id', 'as')) {
949
- optional_vars = this._expression();
952
+ optional_vars = this._parseExpression();
950
953
  }
951
954
  const node = new ast.withitem(context_expr, optional_vars);
952
955
  items.push(node);
953
956
  }
954
957
  while (this._tokenizer.eat(','));
955
958
  this._tokenizer.expect(':');
956
- const body = this._suite();
959
+ const body = this._parseSuite();
957
960
  const node = new ast.With(items, body, null);
958
961
  if (async) {
959
962
  node.async = async;
@@ -962,40 +965,40 @@ python.Execution = class {
962
965
  }
963
966
  if (this._eat('id', 'try')) {
964
967
  this._tokenizer.expect(':');
965
- const body = this._suite();
968
+ const body = this._parseSuite();
966
969
  const handlers = [];
967
970
  let orelse = null;
968
971
  let finalbody = null;
969
972
  while (this._tokenizer.match('id', 'except')) {
970
973
  this._tokenizer.expect('id', 'except');
971
- const type = this._expression();
972
- const name = this._tokenizer.eat('id', 'as') ? this._expression() : null;
974
+ const type = this._parseExpression();
975
+ const name = this._tokenizer.eat('id', 'as') ? this._parseExpression() : null;
973
976
  this._tokenizer.expect(':');
974
- const body = this._suite();
977
+ const body = this._parseSuite();
975
978
  const except = new ast.ExceptHandler(type, name, body);
976
979
  handlers.push(except);
977
980
  }
978
981
  if (this._tokenizer.match('id', 'else')) {
979
982
  this._tokenizer.expect('id', 'else');
980
983
  this._tokenizer.expect(':');
981
- orelse = this._suite();
984
+ orelse = this._parseSuite();
982
985
  }
983
986
  if (this._tokenizer.match('id', 'finally')) {
984
987
  this._tokenizer.expect('id', 'finally');
985
988
  this._tokenizer.expect(':');
986
- finalbody = this._suite();
989
+ finalbody = this._parseSuite();
987
990
  }
988
991
  const node = new ast.Try(body, handlers, orelse, finalbody);
989
992
  return this._mark(node, position);
990
993
  }
991
- const expr = this._expression(-1, [], true);
994
+ const expr = this._parseExpression(-1, [], true);
992
995
  if (expr) {
993
996
  if (expr instanceof ast.Name && this._tokenizer.eat(':')) {
994
997
  const position = this._position();
995
- const annotation = this._expression(-1, ['=']);
998
+ const annotation = this._parseExpression(-1, ['=']);
996
999
  let value = null;
997
1000
  if (this._tokenizer.eat('=')) {
998
- value = this._expression();
1001
+ value = this._parseExpression();
999
1002
  }
1000
1003
  node = new ast.AnnAssign(expr, annotation, value, expr instanceof ast.Name);
1001
1004
  return this._mark(node, position);
@@ -1033,7 +1036,7 @@ python.Execution = class {
1033
1036
  }
1034
1037
  return null;
1035
1038
  }
1036
- _expression(minPrecedence, terminal, tuple) {
1039
+ _parseExpression(minPrecedence, terminal, tuple) {
1037
1040
  minPrecedence = minPrecedence || -1;
1038
1041
  const terminalSet = new Set(terminal);
1039
1042
  const stack = [];
@@ -1073,7 +1076,7 @@ python.Execution = class {
1073
1076
  }
1074
1077
  if (op) {
1075
1078
  const left = stack.pop();
1076
- const right = this._expression(precedence, terminal, tuple === true ? true : false);
1079
+ const right = this._parseExpression(precedence, terminal, tuple === true);
1077
1080
  node = new ast.BinOp(left, op, right);
1078
1081
  } else {
1079
1082
  switch (token.value) {
@@ -1090,14 +1093,14 @@ python.Execution = class {
1090
1093
  default: break;
1091
1094
  }
1092
1095
  const left = stack.pop();
1093
- const comparator = this._expression(precedence, terminal, tuple === true ? true : false);
1096
+ const comparator = this._parseExpression(precedence, ['for', 'if'], tuple === true);
1094
1097
  node = new ast.Compare(left, [op], [comparator]);
1095
1098
  }
1096
1099
  } else if (token.value === '*') {
1097
- const value = this._expression(precedence, terminal, tuple === true ? true : false);
1100
+ const value = this._parseExpression(precedence, terminal, tuple === true);
1098
1101
  node = new ast.Starred(value);
1099
1102
  } else if (token.value === '**') {
1100
- const value = this._expression(precedence, terminal, tuple === true ? true : false);
1103
+ const value = this._parseExpression(precedence, terminal, tuple === true);
1101
1104
  node = new ast.keyword(null, value);
1102
1105
  } else {
1103
1106
  let op = null;
@@ -1108,7 +1111,7 @@ python.Execution = class {
1108
1111
  case 'not': op = new ast.Not(); break;
1109
1112
  default: throw new python.Error(`Unsupported unary operator ${token.value} ${this._location()}`);
1110
1113
  }
1111
- const operand = this._expression(precedence, terminal, tuple === true ? true : false);
1114
+ const operand = this._parseExpression(precedence, terminal, tuple === true);
1112
1115
  node = new ast.UnaryOp(op, operand);
1113
1116
  node = this._mark(node, position);
1114
1117
  }
@@ -1118,7 +1121,7 @@ python.Execution = class {
1118
1121
  }
1119
1122
  if (this._tokenizer.eat(':=')) {
1120
1123
  const target = stack.pop();
1121
- const value = this._expression(-1, terminal, tuple === false ? false : true);
1124
+ const value = this._parseExpression(-1, terminal, tuple !== false);
1122
1125
  const node = new ast.NamedExpr(target, value);
1123
1126
  this._mark(node, position);
1124
1127
  stack.push(node);
@@ -1127,7 +1130,7 @@ python.Execution = class {
1127
1130
  if (this._tokenizer.eat('=')) {
1128
1131
  const position = this._position();
1129
1132
  const targets = stack.pop();
1130
- const value = this._expression(-1, terminal, tuple === false ? false : true);
1133
+ const value = this._parseExpression(-1, terminal, tuple !== false);
1131
1134
  const node = new ast.Assign([targets], value);
1132
1135
  this._mark(node, position);
1133
1136
  stack.push(node);
@@ -1153,7 +1156,7 @@ python.Execution = class {
1153
1156
  if (op) {
1154
1157
  this._tokenizer.expect(token.type);
1155
1158
  const target = stack.pop();
1156
- const value = this._expression(-1, terminal, true);
1159
+ const value = this._parseExpression(-1, terminal, true);
1157
1160
  const node = new ast.AugAssign(target, op, value);
1158
1161
  stack.push(node);
1159
1162
  continue;
@@ -1161,20 +1164,39 @@ python.Execution = class {
1161
1164
  position = this._position();
1162
1165
  if (this._eat('id', 'if')) {
1163
1166
  const body = stack.pop();
1164
- const test = this._expression();
1167
+ const test = this._parseExpression();
1165
1168
  this._tokenizer.expect('id', 'else');
1166
- const orelse = this._expression();
1169
+ const orelse = this._parseExpression();
1167
1170
  const node = new ast.IfExp(test, body, orelse);
1168
1171
  this._mark(node, position);
1169
1172
  stack.push(node);
1170
1173
  continue;
1171
1174
  }
1172
1175
  if (this._tokenizer.match('id', 'for') || this._tokenizer.match('id', 'async')) {
1173
- throw new python.Error('Not implemented.');
1176
+ const position = this._position();
1177
+ const elt = stack.pop();
1178
+ const generators = this._parseGenerators();
1179
+ let node = null;
1180
+ if (elt instanceof ast.Dict) {
1181
+ if (elt.keys.length !== 1 || elt.values.length !== 1) {
1182
+ throw new python.Error(`Invalid dict comprehension ${this._location()}`);
1183
+ }
1184
+ node = new ast.DictComp(elt.keys[0], elt.values[0], generators);
1185
+ } else if (elt instanceof ast.Set) {
1186
+ if (elt.elts.length !== 1) {
1187
+ throw new python.Error(`Invalid set comprehension ${this._location()}`);
1188
+ }
1189
+ node = new ast.SetComp(elt.elts[0], generators);
1190
+ } else {
1191
+ node = new ast.GeneratorExp(elt, generators);
1192
+ }
1193
+ this._mark(node, position);
1194
+ stack.push(node);
1195
+ continue;
1174
1196
  }
1175
1197
  if (this._eat('id', 'lambda')) {
1176
- const args = this._arguments(':');
1177
- const body = this._expression(-1, terminal, false);
1198
+ const args = this._parseArguments(':');
1199
+ const body = this._parseExpression(-1, terminal, false);
1178
1200
  const node = new ast.Lambda(args, body);
1179
1201
  this._mark(node, position);
1180
1202
  stack.push(node);
@@ -1182,13 +1204,13 @@ python.Execution = class {
1182
1204
  }
1183
1205
  if (this._eat('id', 'yield')) {
1184
1206
  if (this._tokenizer.eat('id', 'from')) {
1185
- const value = this._expression(-1, [], true);
1207
+ const value = this._parseExpression(-1, [], true);
1186
1208
  node = new ast.YieldFrom(value);
1187
1209
  stack.push(node);
1188
1210
  } else {
1189
1211
  const value = [];
1190
1212
  do {
1191
- value.push(this._expression(-1, [], false));
1213
+ value.push(this._parseExpression(-1, [], false));
1192
1214
  }
1193
1215
  while (this._tokenizer.eat(','));
1194
1216
  node = new ast.Yield(value);
@@ -1197,7 +1219,7 @@ python.Execution = class {
1197
1219
  continue;
1198
1220
  }
1199
1221
  if (this._eat('id', 'await')) {
1200
- const value = this._expression(minPrecedence, terminal, tuple);
1222
+ const value = this._parseExpression(minPrecedence, terminal, tuple);
1201
1223
  const node = new ast.Await(value);
1202
1224
  this._mark(node, position);
1203
1225
  stack.push(node);
@@ -1205,7 +1227,7 @@ python.Execution = class {
1205
1227
  }
1206
1228
  if (this._eat('.')) {
1207
1229
  const value = stack.pop();
1208
- const attr = this._name().id;
1230
+ const attr = this._parseName().id;
1209
1231
  const node = new ast.Attribute(value, attr);
1210
1232
  this._mark(node, position);
1211
1233
  stack.push(node);
@@ -1222,7 +1244,7 @@ python.Execution = class {
1222
1244
  continue;
1223
1245
  }
1224
1246
  const position = this._position();
1225
- const expr = this._expression(-1, [], false);
1247
+ const expr = this._parseExpression(-1, [], false);
1226
1248
  if (expr === null) {
1227
1249
  throw new python.Error(`Expected expression ${this._location()}`);
1228
1250
  }
@@ -1264,11 +1286,11 @@ python.Execution = class {
1264
1286
  }
1265
1287
  if (this._tokenizer.peek().type === '[') {
1266
1288
  if (stack.length === 0) {
1267
- stack.push(this._expressions());
1289
+ stack.push(this._parseList());
1268
1290
  } else {
1269
1291
  const value = stack.pop();
1270
1292
  const position = this._position();
1271
- const slice = this._slice();
1293
+ const slice = this._parseSlice();
1272
1294
  node = new ast.Subscript(value, slice);
1273
1295
  this._mark(node, position);
1274
1296
  stack.push(node);
@@ -1282,7 +1304,7 @@ python.Execution = class {
1282
1304
  this._tokenizer.expect('{');
1283
1305
  let dict = true;
1284
1306
  while (!this._tokenizer.eat('}')) {
1285
- const item = this._expression(-1, [], false);
1307
+ const item = this._parseExpression(-1, [], false);
1286
1308
  if (item === null) {
1287
1309
  throw new python.Error(`Expected expression ${this._location()}`);
1288
1310
  }
@@ -1290,7 +1312,7 @@ python.Execution = class {
1290
1312
  dict = false;
1291
1313
  }
1292
1314
  if (dict) {
1293
- const value = this._expression(-1, ['for'], false);
1315
+ const value = this._parseExpression(-1, ['for'], false);
1294
1316
  if (value === null) {
1295
1317
  throw new python.Error(`Expected expression ${this._location()}`);
1296
1318
  }
@@ -1298,12 +1320,12 @@ python.Execution = class {
1298
1320
  if (keys.length > 0 || values.length > 0 || elts.length > 0) {
1299
1321
  throw new python.Error(`Invalid list expression ${this._location()}`);
1300
1322
  }
1301
- const target = this._expression(-1, ['in'], true);
1323
+ const target = this._parseExpression(-1, ['in'], true);
1302
1324
  this._tokenizer.expect('id', 'in');
1303
- const iter = this._expression(-1, ['for', 'if'], true);
1325
+ const iter = this._parseExpression(-1, ['for', 'if'], true);
1304
1326
  const ifs = [];
1305
1327
  while (this._tokenizer.eat('id', 'if')) {
1306
- ifs.push(this._expression(-1, ['for', 'if']));
1328
+ ifs.push(this._parseExpression(-1, ['for', 'if']));
1307
1329
  }
1308
1330
  const comprehension = new ast.comprehension(target, iter, ifs /*, async */);
1309
1331
  const generators = [comprehension];
@@ -1328,7 +1350,7 @@ python.Execution = class {
1328
1350
  stack.push(node);
1329
1351
  continue;
1330
1352
  }
1331
- const literal = this._literal();
1353
+ const literal = this._parseLiteral();
1332
1354
  if (literal) {
1333
1355
  if (stack.length > 0 &&
1334
1356
  (literal.type === 'int' || literal.type === 'float' || literal.type === 'complex') &&
@@ -1386,7 +1408,7 @@ python.Execution = class {
1386
1408
  stack.push(node);
1387
1409
  continue;
1388
1410
  }
1389
- const name = this._name();
1411
+ const name = this._parseName();
1390
1412
  if (name) {
1391
1413
  stack.push(name);
1392
1414
  continue;
@@ -1407,7 +1429,7 @@ python.Execution = class {
1407
1429
  }
1408
1430
  if (!this._tokenizer.match('=') && !terminalSet.has(this._tokenizer.peek().value)) {
1409
1431
  const nextTerminal = terminal.slice(0).concat([',', '=']);
1410
- const expression = this._expression(minPrecedence, nextTerminal, tuple);
1432
+ const expression = this._parseExpression(minPrecedence, nextTerminal, tuple);
1411
1433
  if (expression) {
1412
1434
  node.elts.push(expression);
1413
1435
  continue;
@@ -1428,7 +1450,7 @@ python.Execution = class {
1428
1450
  _decorator() {
1429
1451
  const list = [];
1430
1452
  while (this._tokenizer.eat('@')) {
1431
- const value = this._expression();
1453
+ const value = this._parseExpression();
1432
1454
  if (!value || (value instanceof ast.Call === false && value instanceof ast.Name === false && value instanceof ast.Attribute === false)) {
1433
1455
  throw new python.Error(`Invalid decorator ${this._location()}`);
1434
1456
  }
@@ -1437,42 +1459,55 @@ python.Execution = class {
1437
1459
  }
1438
1460
  return list;
1439
1461
  }
1440
- _expressions() {
1462
+ _parseGenerators() {
1463
+ const generators = [];
1464
+ while (this._tokenizer.match('id', 'for') || this._tokenizer.match('id', 'async')) {
1465
+ const is_async = this._eat('id', 'async') ? 1 : 0;
1466
+ this._tokenizer.expect('id', 'for');
1467
+ const target = this._parseExpression(-1, ['in'], true);
1468
+ this._tokenizer.expect('id', 'in');
1469
+ const iter = this._parseExpression(-1, ['for', 'if'], true);
1470
+ const ifs = [];
1471
+ while (this._tokenizer.eat('id', 'if')) {
1472
+ ifs.push(this._parseExpression(-1, ['for', 'if']));
1473
+ }
1474
+ const comprehension = new ast.comprehension(target, iter, ifs, is_async);
1475
+ generators.push(comprehension);
1476
+ }
1477
+ return generators;
1478
+ }
1479
+ _parseList() {
1441
1480
  const elts = [];
1442
1481
  this._tokenizer.expect('[');
1443
- while (!this._tokenizer.eat(']')) {
1444
- const expression = this._expression(-1, ['for']);
1445
- if (this._eat('id', 'for')) {
1446
- if (elts.length > 0) {
1447
- throw new python.Error(`Invalid list expression ${this._location()}`);
1448
- }
1449
- const target = this._expression(-1, ['in'], true);
1450
- this._tokenizer.expect('id', 'in');
1451
- const iter = this._expression(-1, ['for', 'if'], true);
1452
- const ifs = [];
1453
- while (this._tokenizer.eat('id', 'if')) {
1454
- ifs.push(this._expression(-1, ['for', 'if']));
1455
- }
1456
- const comprehension = new ast.comprehension(target, iter, ifs /*, async */);
1457
- const generators = [comprehension];
1482
+ if (!this._tokenizer.match(']')) {
1483
+ const position = this._position();
1484
+ const expr = this._parseExpression(-1, ['for']);
1485
+ if (this._tokenizer.match('id', 'for')) {
1486
+ const generators = this._parseGenerators();
1458
1487
  this._tokenizer.expect(']');
1459
- return new ast.ListComp(expression, generators);
1488
+ const node = new ast.ListComp(expr, generators);
1489
+ this._mark(node, position);
1490
+ return node;
1460
1491
  }
1461
- if (expression === null) {
1492
+ if (expr === null) {
1462
1493
  throw new python.Error(`Expected expression ${this._location()}`);
1463
1494
  }
1464
- elts.push(expression);
1465
- this._tokenizer.eat(',');
1466
- while (this._tokenizer.eat('\n')) {
1467
- // continue
1468
- }
1469
- if (this._tokenizer.eat(']')) {
1470
- break;
1495
+ elts.push(expr);
1496
+ while (this._tokenizer.eat(',')) {
1497
+ if (this._tokenizer.match(']')) {
1498
+ break;
1499
+ }
1500
+ const expr = this._parseExpression(-1, ['for']);
1501
+ if (!expr) {
1502
+ throw new python.Error(`Expected expression ${this._location()}`);
1503
+ }
1504
+ elts.push(expr);
1471
1505
  }
1472
1506
  }
1507
+ this._tokenizer.expect(']');
1473
1508
  return new ast.List(elts);
1474
1509
  }
1475
- _slice() {
1510
+ _parseSlice() {
1476
1511
  const elts = [];
1477
1512
  let slice = [null, null, null];
1478
1513
  let index = 0;
@@ -1494,7 +1529,7 @@ python.Execution = class {
1494
1529
  }
1495
1530
  this._tokenizer.expect(',');
1496
1531
  } else {
1497
- const expression = this._expression();
1532
+ const expression = this._parseExpression();
1498
1533
  if (expression === null) {
1499
1534
  throw new python.Error(`Expected expression ${this._location()}`);
1500
1535
  }
@@ -1507,7 +1542,7 @@ python.Execution = class {
1507
1542
  }
1508
1543
  return elts[0];
1509
1544
  }
1510
- _name(required) {
1545
+ _parseName(required) {
1511
1546
  const token = this._tokenizer.peek();
1512
1547
  if (token.type === 'id' && !token.keyword) {
1513
1548
  const position = this._position();
@@ -1520,16 +1555,16 @@ python.Execution = class {
1520
1555
  }
1521
1556
  return null;
1522
1557
  }
1523
- _dottedName() {
1558
+ _parseDottedName() {
1524
1559
  const list = [];
1525
1560
  do {
1526
- const name = this._name(true);
1561
+ const name = this._parseName(true);
1527
1562
  list.push(name.id);
1528
1563
  }
1529
1564
  while (this._tokenizer.eat('.'));
1530
1565
  return list.join('.');
1531
1566
  }
1532
- _literal() {
1567
+ _parseLiteral() {
1533
1568
  const token = this._tokenizer.peek();
1534
1569
  if (token.type === 'str' || token.type === 'bool' || token.type === 'int' || token.type === 'float' || token.type === 'complex') {
1535
1570
  this._tokenizer.read();
@@ -1537,11 +1572,11 @@ python.Execution = class {
1537
1572
  }
1538
1573
  return null;
1539
1574
  }
1540
- _typeArguments() {
1575
+ _parseTypeArguments() {
1541
1576
  const list = [];
1542
1577
  this._tokenizer.expect('[');
1543
1578
  while (!this._tokenizer.eat(']')) {
1544
- const type = this._type();
1579
+ const type = this._parseType();
1545
1580
  if (type === null) {
1546
1581
  throw new python.Error(`Expected type ${this._location()}`);
1547
1582
  }
@@ -1553,11 +1588,11 @@ python.Execution = class {
1553
1588
  }
1554
1589
  return list;
1555
1590
  }
1556
- _type() {
1557
- const target = this._expression(-1, ['[', '=']);
1591
+ _parseType() {
1592
+ const target = this._parseExpression(-1, ['[', '=']);
1558
1593
  if (target) {
1559
1594
  if (this._tokenizer.peek().value === '[') {
1560
- const list = this._expressions();
1595
+ const list = this._parseList();
1561
1596
  const slice = list.elts.length === 1 ? list.elts[0] : new ast.Tuple(list.elts);
1562
1597
  return new ast.Subscript(target, slice);
1563
1598
  }
@@ -1565,7 +1600,7 @@ python.Execution = class {
1565
1600
  }
1566
1601
  return null;
1567
1602
  }
1568
- _arguments(terminal) {
1603
+ _parseArguments(terminal) {
1569
1604
  let posonlyargs = [];
1570
1605
  let args = [];
1571
1606
  let vararg = null;
@@ -1577,9 +1612,9 @@ python.Execution = class {
1577
1612
  let is_vararg = false; // '*'
1578
1613
  let is_kwarg = false; // '**'
1579
1614
  const read = (required) => {
1580
- const name = this._name(required);
1615
+ const name = this._parseName(required);
1581
1616
  if (name) {
1582
- const annotation = terminal !== ':' && this._tokenizer.eat(':') ? this._type() : null;
1617
+ const annotation = terminal !== ':' && this._tokenizer.eat(':') ? this._parseType() : null;
1583
1618
  return new ast.arg(name.id, annotation, null);
1584
1619
  }
1585
1620
  return null;
@@ -1610,7 +1645,7 @@ python.Execution = class {
1610
1645
  this._tokenizer.expect(terminal);
1611
1646
  break;
1612
1647
  }
1613
- const default_value = this._tokenizer.eat('=') ? this._expression() : null;
1648
+ const default_value = this._tokenizer.eat('=') ? this._parseExpression() : null;
1614
1649
  if (!is_vararg && !is_kwarg) {
1615
1650
  if (is_slash) {
1616
1651
  args.push(arg);
@@ -2200,7 +2235,7 @@ python.Execution = class {
2200
2235
  prefix = c;
2201
2236
  }
2202
2237
  } else if (this._get(i + 2) === "'" || this._get(i + 2) === '"') {
2203
- const c = this._text.substr(this._position, 2);
2238
+ const c = this._text.substring(this._position, this._position + 2);
2204
2239
  const cc = c.toLowerCase();
2205
2240
  if (cc === 'br' || cc === 'fr' || cc === 'rb' || cc === 'rf' || cc === 'ur') {
2206
2241
  prefix = c;
@@ -2335,6 +2370,9 @@ python.Execution = class {
2335
2370
  static __new__(cls, ...args) {
2336
2371
  return execution.invoke(cls, args);
2337
2372
  }
2373
+ static __setattr__(obj, name, value) {
2374
+ builtins.setattr(obj, name, value);
2375
+ }
2338
2376
  });
2339
2377
  this.registerType('builtins.tuple', class extends Array {
2340
2378
  constructor(items) {
@@ -2373,7 +2411,11 @@ python.Execution = class {
2373
2411
  typing.Sequence = Reflect.construct(typing._SpecialGenericAlias, []);
2374
2412
  typing.Tuple = Reflect.construct(typing._TupleType, []);
2375
2413
  typing.Union = Reflect.construct(typing._SpecialForm, []);
2376
- this.registerType('enum.Enum', class {});
2414
+ this.registerType('enum.Enum', class {
2415
+ // __reduce_ex__(proto) {
2416
+ // return self.__class__, (self._value_, )
2417
+ // }
2418
+ });
2377
2419
  this.registerFunction('operator.add');
2378
2420
  this.registerFunction('operator.eq');
2379
2421
  this.registerFunction('operator.ge');
@@ -3029,6 +3071,9 @@ python.Execution = class {
3029
3071
  value.flags = this.flags;
3030
3072
  return value;
3031
3073
  }
3074
+ reshape(shape, order) {
3075
+ return new numpy.ndarray(shape, this.dtype, this.data, this.offset, this.strides, order);
3076
+ }
3032
3077
  tobytes() {
3033
3078
  return this.data;
3034
3079
  }
@@ -3223,7 +3268,53 @@ python.Execution = class {
3223
3268
  this.registerType('pandas.core.arrays.categorical.Categorical', class {});
3224
3269
  this.registerType('pandas.core.arrays.datetimes.DatetimeArray', class {});
3225
3270
  this.registerType('pandas.core.arrays.integer.IntegerArray', class {});
3226
- this.registerType('pandas.core.frame.DataFrame', class {});
3271
+ this.registerType('pandas.core.generic.Flags', class {});
3272
+ this.registerType('pandas.core.generic.NDFrame', class {
3273
+ constructor(data) {
3274
+ this._internal_names = ["_mgr", "_item_cache", "_cache", "_name", "_metadata", "_flags"];
3275
+ this._metadata = [];
3276
+ builtins.object.__setattr__(self, "_mgr", data);
3277
+ builtins.object.__setattr__(self, "_attrs", {});
3278
+ builtins.object.__setattr__(self, "_flags", new pandas.core.generic.Flags(this, true));
3279
+ }
3280
+ __setstate__(state) {
3281
+ if (state instanceof pandas.core.internals.managers.BlockManager) {
3282
+ this._mgr = state;
3283
+ } else if (state instanceof builtins.dict) {
3284
+ if (state.__contains__('_data') && !state.__contains__('_mgr')) {
3285
+ state.__setitem__('_mgr', state.pop('_data'));
3286
+ }
3287
+ const typ = state.get('_typ');
3288
+ if (typ) {
3289
+ let attrs = state.get('_attrs', new builtins.dict());
3290
+ if (!attrs) {
3291
+ attrs = new builtins.dict();
3292
+ }
3293
+ builtins.object.__setattr__(this, '_attrs', attrs);
3294
+ const flags = state.get('_flags', new builtins.dict({ 'allows_duplicate_labels': true }));
3295
+ builtins.object.__setattr__(this, '_flags', new pandas.core.generic.Flags(this, flags));
3296
+ const meta = new builtins.set(this._internal_names.concat(this._metadata));
3297
+ for (const k of meta) {
3298
+ if (state.__contains__(k) && k !== '_flags') {
3299
+ const v = state.__getitem__(k);
3300
+ builtins.object.__setattr__(this, k, v);
3301
+ }
3302
+ }
3303
+ for (const [k, v] of state) {
3304
+ if (!meta.has(k)) {
3305
+ builtins.object.__setattr__(this, k, v);
3306
+ }
3307
+ }
3308
+ } else {
3309
+ throw new python.Error('Pre-0.12 pickles are no longer supported.');
3310
+ }
3311
+ } else if (state.size === 2) {
3312
+ throw new python.Error('Pre-0.12 pickles are no longer supported.');
3313
+ }
3314
+ }
3315
+ });
3316
+ this.registerType('pandas.core.frame.DataFrame', class extends pandas.core.generic.NDFrame {
3317
+ });
3227
3318
  this.registerFunction('pandas.core.indexes.base._new_Index', (cls, d) => {
3228
3319
  return new cls(d);
3229
3320
  });
@@ -3275,8 +3366,11 @@ python.Execution = class {
3275
3366
  pandas.core.internals.BlockManager = pandas.core.internals.managers.BlockManager;
3276
3367
  pandas._libs.tslib.Timestamp = pandas._libs.tslibs.timestamps.Timestamp;
3277
3368
  this.registerType('pathlib.Path', class {});
3278
- this.registerType('pathlib.PosixPath', class {});
3279
- this.registerType('pathlib.WindowsPath', class {});
3369
+ this.registerType('pathlib._local.PosixPath', class {});
3370
+ this.registerType('pathlib._local.WindowsPath', class {});
3371
+ const pathlib = this.register('pathlib');
3372
+ pathlib.PosixPath = pathlib._local.PosixPath;
3373
+ pathlib.WindowsPath = pathlib._local.WindowsPath;
3280
3374
  this.registerType('shap._serializable.Serializable', class {});
3281
3375
  this.registerType('shap.explainers._explainer.Explainer', class extends shap._serializable.Serializable {});
3282
3376
  this.registerType('shap.explainers._linear.LinearExplainer', class extends shap.explainers._explainer.Explainer {});
@@ -3314,6 +3408,7 @@ python.Execution = class {
3314
3408
  this.registerType('sklearn.compose._target.TransformedTargetRegressor', class {});
3315
3409
  this.registerType('sklearn.cross_decomposition._pls.PLSRegression', class {});
3316
3410
  this.registerType('sklearn.decomposition._fastica.FastICA', class {});
3411
+ this.registerType('sklearn.decomposition._incremental_pca.IncrementalPCA', class {});
3317
3412
  this.registerType('sklearn.decomposition._pca.PCA', class {});
3318
3413
  this.registerType('sklearn.decomposition._truncated_svd.TruncatedSVD', class {});
3319
3414
  this.registerType('sklearn.decomposition.pca.PCA', class {});
@@ -3342,6 +3437,7 @@ python.Execution = class {
3342
3437
  this.registerType('sklearn.ensemble._hist_gradient_boosting.predictor.TreePredictor', class {});
3343
3438
  this.registerType('sklearn.ensemble._iforest.IsolationForest', class {});
3344
3439
  this.registerType('sklearn.ensemble._stacking.StackingClassifier', class {});
3440
+ this.registerType('sklearn.ensemble._stacking.StackingRegressor', class {});
3345
3441
  this.registerType('sklearn.ensemble._voting.VotingClassifier', class {});
3346
3442
  this.registerType('sklearn.ensemble._voting.VotingRegressor', class {});
3347
3443
  this.registerType('sklearn.ensemble._weight_boosting.AdaBoostClassifier', class {});
@@ -3407,6 +3503,7 @@ python.Execution = class {
3407
3503
  this.registerType('sklearn.linear_model._sgd_fast.ModifiedHuber', class {});
3408
3504
  this.registerType('sklearn.linear_model._sgd_fast.SquaredHinge', class {});
3409
3505
  this.registerType('sklearn.linear_model._stochastic_gradient.SGDClassifier', class {});
3506
+ this.registerType('sklearn.linear_model._stochastic_gradient.SGDRegressor', class {});
3410
3507
  this.registerType('sklearn.linear_model.base.LinearRegression', class {});
3411
3508
  this.registerType('sklearn.linear_model.sgd_fast.Hinge', class {});
3412
3509
  this.registerType('sklearn.linear_model.LogisticRegression', class {});
@@ -3437,6 +3534,7 @@ python.Execution = class {
3437
3534
  this.registerType('sklearn.model_selection._split.RepeatedKFold', class {});
3438
3535
  this.registerType('sklearn.model_selection._split.StratifiedKFold', class {});
3439
3536
  this.registerType('sklearn.model_selection._split.StratifiedShuffleSplit', class {});
3537
+ this.registerType('sklearn.model_selection._split.TimeSeriesSplit', class {});
3440
3538
  this.registerType('sklearn.multiclass.OneVsRestClassifier', class {});
3441
3539
  this.registerType('sklearn.multioutput.ClassifierChain', class {});
3442
3540
  this.registerType('sklearn.multioutput.MultiOutputClassifier', class {});
@@ -3595,6 +3693,9 @@ python.Execution = class {
3595
3693
  }
3596
3694
  case 112 : { // PUT 'p'
3597
3695
  const index = parseInt(reader.line(), 10);
3696
+ if (stack.length === 0) {
3697
+ throw new python.Error(`Empty stack during 'PUT' operation.`);
3698
+ }
3598
3699
  memo[index] = stack[stack.length - 1];
3599
3700
  size++;
3600
3701
  break;
@@ -3611,6 +3712,9 @@ python.Execution = class {
3611
3712
  stack = marker.pop();
3612
3713
  break;
3613
3714
  case 50: // DUP '2'
3715
+ if (stack.length === 0) {
3716
+ throw new python.Error(`Empty stack during 'DUP' operation.`);
3717
+ }
3614
3718
  stack.push(stack[stack.length - 1]);
3615
3719
  break;
3616
3720
  case 80: // PERSID 'P'
@@ -3661,10 +3765,16 @@ python.Execution = class {
3661
3765
  stack.push(memo[reader.uint32()]);
3662
3766
  break;
3663
3767
  case 113: // BINPUT 'q'
3768
+ if (stack.length === 0) {
3769
+ throw new python.Error(`Empty stack during 'BINPUT' operation.`);
3770
+ }
3664
3771
  memo[reader.byte()] = stack[stack.length - 1];
3665
3772
  size++;
3666
3773
  break;
3667
3774
  case 114: // LONG_BINPUT 'r'
3775
+ if (stack.length === 0) {
3776
+ throw new python.Error(`Empty stack during 'LONG_BINPUT' operation.`);
3777
+ }
3668
3778
  memo[reader.uint32()] = stack[stack.length - 1];
3669
3779
  size++;
3670
3780
  break;
@@ -3812,7 +3922,7 @@ python.Execution = class {
3812
3922
  }
3813
3923
  case 83: { // STRING 'S'
3814
3924
  const str = reader.line();
3815
- stack.push(str.substr(1, str.length - 2));
3925
+ stack.push(str.substring(1, str.length - 1));
3816
3926
  break;
3817
3927
  }
3818
3928
  case 84: // BINSTRING 'T'
@@ -3846,9 +3956,11 @@ python.Execution = class {
3846
3956
  obj.set(key, value);
3847
3957
  }
3848
3958
  } else if (obj instanceof Map) {
3959
+ /* eslint-disable guard-for-in */
3849
3960
  for (const key in state) {
3850
3961
  obj.set(key, state[key]);
3851
3962
  }
3963
+ /* eslint-enable guard-for-in */
3852
3964
  } else if (state instanceof Map) {
3853
3965
  for (const [key, value] of state) {
3854
3966
  obj[key] = value;
@@ -3877,9 +3989,7 @@ python.Execution = class {
3877
3989
  let number = 0;
3878
3990
  switch (data.length) {
3879
3991
  case 0: number = 0; break;
3880
- /* eslint-disable prefer-destructuring */
3881
- case 1: number = data[0]; break;
3882
- /* eslint-enable prefer-destructuring */
3992
+ case 1: [number] = data; break;
3883
3993
  case 2: number = data[1] << 8 | data[0]; break;
3884
3994
  case 3: number = data[2] << 16 | data[1] << 8 | data[0]; break;
3885
3995
  case 4: number = data[3] << 24 | data[2] << 16 | data[1] << 8 | data[0]; break;
@@ -4155,9 +4265,25 @@ python.Execution = class {
4155
4265
  types.TypeType = builtins.type;
4156
4266
  types.CodeType = builtins.code;
4157
4267
  this.registerType('xgboost.compat.XGBoostLabelEncoder', class {});
4158
- this.registerType('xgboost.core.Booster', class {});
4268
+ this.registerType('xgboost.core.Booster', class {
4269
+ load_model(fname) {
4270
+ if (fname instanceof Uint8Array) {
4271
+ // XGBoosterLoadModel()
4272
+ } else {
4273
+ // XGBoosterUnserializeFromBuffer(handle) {
4274
+ }
4275
+ }
4276
+ __setstate__(state) {
4277
+ const handle = state.get('handle');
4278
+ if (handle) {
4279
+ this.handle = handle;
4280
+ // XGBoosterLoadModelFromBuffer()
4281
+ }
4282
+ }
4283
+ });
4159
4284
  this.registerType('xgboost.sklearn.XGBClassifier', class {});
4160
4285
  this.registerType('xgboost.sklearn.XGBRegressor', class {});
4286
+ this.registerType('xgboost.sklearn.XGBRFClassifier', class {});
4161
4287
  this.registerFunction('_codecs.encode', (obj, encoding) => {
4162
4288
  return execution.invoke('builtins.bytearray', [obj, encoding]);
4163
4289
  });
@@ -4303,7 +4429,16 @@ python.Execution = class {
4303
4429
  this.registerFunction('builtins.setattr', (obj, name, value) => {
4304
4430
  obj[name] = value;
4305
4431
  });
4306
- this.registerType('builtins.set', class extends Set {});
4432
+ this.registerType('builtins.set', class extends Set {
4433
+ __contains__(item) {
4434
+ return this.has(item);
4435
+ }
4436
+ update(iterable) {
4437
+ for (const item of iterable) {
4438
+ this.add(item);
4439
+ }
4440
+ }
4441
+ });
4307
4442
  this.registerType('builtins.slice', class {
4308
4443
  constructor(start, stop, step) {
4309
4444
  this.start = start;
@@ -4660,13 +4795,16 @@ python.Execution = class {
4660
4795
  this.registerFunction('nolearn.lasagne.base.objective');
4661
4796
  this.registerFunction('numpy.core._DType_reconstruct');
4662
4797
  this.registerFunction('numpy.core._ufunc_reconstruct');
4663
- this.registerFunction('numpy.core.numeric._frombuffer', (/* buf, dtype, shape, order */) => {
4664
- return {};
4665
- });
4666
4798
  this.registerFunction('numpy.core.multiarray._reconstruct', (subtype, shape, dtype) => {
4667
4799
  return numpy.ndarray.__new__(subtype, shape, dtype);
4668
4800
  });
4669
- this.registerFunction('numpy._core.numeric._frombuffer');
4801
+ this.registerFunction('numpy.core.multiarray.frombuffer', (buf, dtype) => {
4802
+ const shape = [buf.length / dtype.itemsize];
4803
+ return new numpy.ndarray(shape, dtype, buf);
4804
+ });
4805
+ this.registerFunction('numpy._core.numeric._frombuffer', (buf, dtype, shape, order) => {
4806
+ return numpy._core.multiarray.frombuffer(buf, dtype).reshape(shape, order);
4807
+ });
4670
4808
  this.registerFunction('numpy._core._internal._convert_to_stringdtype_kwargs', () => {
4671
4809
  return new numpy.dtypes.StringDType();
4672
4810
  });
@@ -4762,10 +4900,12 @@ python.Execution = class {
4762
4900
  throw new python.Error(`Unsupported scalar type '${dtype.__name__}'.`);
4763
4901
  }
4764
4902
  });
4903
+ this.registerFunction('numpy.core._multiarray_umath.sin');
4765
4904
  this.registerFunction('numpy.core._multiarray_umath.sqrt');
4766
4905
  this.register('numpy._core.multiarray', numpy.core.multiarray);
4767
4906
  this.register('numpy._core._multiarray_umath', numpy.core._multiarray_umath);
4768
4907
  this.register('numpy._core._multiarray_umath', numpy.core._multiarray_umath);
4908
+ this.register('numpy.core.numeric', numpy._core.numeric);
4769
4909
  numpy._core._multiarray_umath._reconstruct = numpy.core.multiarray._reconstruct;
4770
4910
  this.registerFunction('numpy.load', (file) => {
4771
4911
  // https://github.com/numpy/numpy/blob/main/numpy/lib/format.py
@@ -6745,6 +6885,8 @@ python.Execution = class {
6745
6885
  this.registerType('torch.distributions.beta.Beta', class {});
6746
6886
  this.registerType('torch.distributions.binomial.Binomial', class {});
6747
6887
  this.registerType('torch.distributions.categorical.Categorical', class {});
6888
+ this.registerType('torch.distributions.constraints._GreaterThan', class {});
6889
+ this.registerType('torch.distributions.constraints._Interval', class {});
6748
6890
  this.registerType('torch.distributions.constraints._LowerCholesky', class {});
6749
6891
  this.registerType('torch.distributions.constraints._Real', class {});
6750
6892
  this.registerType('torch.distributions.dirichlet.Dirichlet', class {});
@@ -6827,6 +6969,7 @@ python.Execution = class {
6827
6969
  this.registerType('torch.nn.modules.conv.LazyConv2d', class {});
6828
6970
  this.registerType('torch.nn.modules.conv.LazyConv3d', class {});
6829
6971
  this.registerType('torch.nn.modules.conv.LazyConvTranspose2d', class {});
6972
+ this.registerType('torch.nn.modules.conv.LazyConvTranspose3d', class {});
6830
6973
  this.registerType('torch.nn.modules.distance.CosineSimilarity', class extends torch.nn.modules.module.Module {});
6831
6974
  this.registerType('torch.nn.modules.distance.PairwiseDistance', class extends torch.nn.modules.module.Module {});
6832
6975
  this.registerType('torch.nn.modules.dropout._DropoutNd', class extends torch.nn.modules.module.Module {});
@@ -6844,6 +6987,7 @@ python.Execution = class {
6844
6987
  this.registerType('torch.nn.modules.instancenorm.InstanceNorm2d', class {});
6845
6988
  this.registerType('torch.nn.modules.instancenorm.InstanceNorm3d', class {});
6846
6989
  this.registerType('torch.nn.modules.instancenorm.LazyInstanceNorm2d', class {});
6990
+ this.registerType('torch.nn.modules.instancenorm.LazyInstanceNorm3d', class {});
6847
6991
  this.registerType('torch.nn.modules.linear._LinearWithBias', class {});
6848
6992
  this.registerType('torch.nn.modules.linear.Bilinear', class extends torch.nn.modules.module.Module {});
6849
6993
  this.registerType('torch.nn.modules.linear.Identity', class extends torch.nn.modules.module.Module {});
@@ -6892,9 +7036,11 @@ python.Execution = class {
6892
7036
  this.registerType('torch.nn.modules.padding.ReplicationPad3d', class extends torch.nn.modules.padding._ReplicationPadNd {});
6893
7037
  this.registerType('torch.nn.modules.padding.ZeroPad1d', class {});
6894
7038
  this.registerType('torch.nn.modules.padding.ZeroPad2d', class {});
7039
+ this.registerType('torch.nn.modules.padding.ZeroPad3d', class {});
6895
7040
  this.registerType('torch.nn.modules.padding.ConstantPad1d', class {});
6896
7041
  this.registerType('torch.nn.modules.padding.ConstantPad2d', class {});
6897
7042
  this.registerType('torch.nn.modules.padding.ConstantPad3d', class {});
7043
+ this.registerType('torch.nn.modules.padding.CircularPad3d', class {});
6898
7044
  this.registerType('torch.nn.modules.pixelshuffle.PixelShuffle', class {});
6899
7045
  this.registerType('torch.nn.modules.pixelshuffle.PixelUnshuffle', class {});
6900
7046
  this.registerType('torch.nn.modules.pooling._AdaptiveAvgPoolNd', class extends torch.nn.modules.module.Module {});
@@ -6908,8 +7054,10 @@ python.Execution = class {
6908
7054
  this.registerType('torch.nn.modules.pooling.AvgPool2d', class {});
6909
7055
  this.registerType('torch.nn.modules.pooling.AvgPool3d', class {});
6910
7056
  this.registerType('torch.nn.modules.pooling.FractionalMaxPool2d', class {});
7057
+ this.registerType('torch.nn.modules.pooling.FractionalMaxPool3d', class {});
6911
7058
  this.registerType('torch.nn.modules.pooling.LPPool1d', class {});
6912
7059
  this.registerType('torch.nn.modules.pooling.LPPool2d', class {});
7060
+ this.registerType('torch.nn.modules.pooling.LPPool3d', class {});
6913
7061
  this.registerType('torch.nn.modules.pooling._MaxPoolNd', class extends torch.nn.modules.module.Module {});
6914
7062
  this.registerType('torch.nn.modules.pooling.MaxPool1d', class extends torch.nn.modules.pooling._MaxPoolNd {});
6915
7063
  this.registerType('torch.nn.modules.pooling.MaxPool2d', class extends torch.nn.modules.pooling._MaxPoolNd {});
@@ -7011,8 +7159,10 @@ python.Execution = class {
7011
7159
  this.registerType('torch.ao.nn.quantized.reference.modules.linear.Linear', class {});
7012
7160
  this.registerType('torch.ao.nn.qat.modules.conv.Conv2d', class {});
7013
7161
  this.registerType('torch.ao.nn.qat.modules.linear.Linear', class {});
7162
+ this.registerType('torch.ao.nn.intrinsic.quantized.modules.conv_relu.ConvReLU1d', class extends torch.ao.nn.quantized.modules.conv.Conv1d {});
7014
7163
  this.registerType('torch.ao.nn.intrinsic.quantized.modules.conv_relu.ConvReLU2d', class extends torch.ao.nn.quantized.modules.conv.Conv2d {});
7015
7164
  this.registerType('torch.ao.nn.intrinsic.quantized.modules.linear_relu.LinearReLU', class extends torch.ao.nn.quantized.modules.linear.Linear {});
7165
+ this.registerType('torch.ao.nn.intrinsic.quantized.modules.bn_relu.BNReLU2d', class extends torch.ao.nn.quantized.modules.batchnorm.BatchNorm2d {});
7016
7166
  this.registerType('torch.ao.nn.intrinsic.modules.fused._FusedModule', class extends torch.nn.modules.container.Sequential {});
7017
7167
  this.registerType('torch.ao.nn.intrinsic.modules.fused.ConvBn2d', class extends torch.ao.nn.intrinsic.modules.fused._FusedModule {});
7018
7168
  this.registerType('torch.ao.nn.intrinsic.modules.fused.ConvReLU1d', class extends torch.ao.nn.intrinsic.modules.fused._FusedModule {});
@@ -7353,7 +7503,7 @@ python.Execution = class {
7353
7503
  }
7354
7504
  _target_to_str(target) {
7355
7505
  if (typeof target === 'string') {
7356
- if (target.startsWith('__') && target.endswith('__')) {
7506
+ if (target.startsWith('__') && target.endsWith('__')) {
7357
7507
  target = target.substring(2, target.length - 2);
7358
7508
  }
7359
7509
  } else {
@@ -7397,6 +7547,7 @@ python.Execution = class {
7397
7547
  this.registerFunction('torch.fx._symbolic_trace.wrap', (fn_or_name) => {
7398
7548
  return fn_or_name;
7399
7549
  });
7550
+ this.registerFunction('torch.fx._symbolic_trace._assert_is_none');
7400
7551
  this.registerFunction('torchvision.datasets.folder.default_loader');
7401
7552
  this.registerType('torchvision.datasets.folder.ImageFolder', class {});
7402
7553
  this.registerType('torchvision.datasets.mnist.FashionMNIST', class {});
@@ -7485,6 +7636,7 @@ python.Execution = class {
7485
7636
  this.registerType('torchvision.models.inception.InceptionC', class {});
7486
7637
  this.registerType('torchvision.models.inception.InceptionD', class {});
7487
7638
  this.registerType('torchvision.models.inception.InceptionE', class {});
7639
+ this.registerFunction('torchvision.models.inception.inception_v3');
7488
7640
  this.registerType('torchvision.models.mnasnet._InvertedResidual', class {});
7489
7641
  this.registerType('torchvision.models.mnasnet.MNASNet', class {});
7490
7642
  this.registerType('torchvision.models.maxvit.MaxVit', class {});
@@ -7579,7 +7731,10 @@ python.Execution = class {
7579
7731
  this.registerType('torchvision.transforms.transforms.RandomAffine', class extends torch.nn.modules.module.Module {});
7580
7732
  this.registerType('torchvision.transforms.transforms.RandomApply', class extends torch.nn.modules.module.Module {});
7581
7733
  this.registerType('torchvision.transforms.transforms.RandomCrop', class extends torch.nn.modules.module.Module {});
7734
+ this.registerType('torchvision.transforms.transforms.RandomChoice', class {});
7582
7735
  this.registerType('torchvision.transforms.transforms.RandomErasing', class {});
7736
+ this.registerType('torchvision.transforms.transforms.RandomInvert', class {});
7737
+ this.registerType('torchvision.transforms.transforms.RandomPerspective', class {});
7583
7738
  this.registerType('torchvision.transforms.transforms.RandomHorizontalFlip', class extends torch.nn.modules.module.Module {});
7584
7739
  this.registerType('torchvision.transforms.transforms.RandomVerticalFlip', class extends torch.nn.modules.module.Module {});
7585
7740
  this.registerType('torchvision.transforms.transforms.RandomResizedCrop', class extends torch.nn.modules.module.Module {});
@@ -7766,7 +7921,13 @@ python.Execution = class {
7766
7921
  }
7767
7922
  throw new python.Error(`Unsupported sparse tensor layout '${layout ? layout.__str__() : ''}'.`);
7768
7923
  });
7769
- this.registerFunction('torch._utils._rebuild_wrapper_subclass');
7924
+ this.registerFunction('torch._utils._get_restore_location', (device) => {
7925
+ return device;
7926
+ });
7927
+ this.registerFunction('torch._utils._rebuild_wrapper_subclass', (cls, dtype, size, stride, storage_offset, layout, device, requires_grad) => {
7928
+ device = torch._utils._get_restore_location(device);
7929
+ return torch.Tensor._make_wrapper_subclass(cls, size, stride, dtype, storage_offset, layout, device, requires_grad);
7930
+ });
7770
7931
  this.registerFunction('torch.from_numpy', (obj) => {
7771
7932
  const dtypes = new Map([
7772
7933
  ['<f2', torch.float16],
@@ -7801,6 +7962,12 @@ python.Execution = class {
7801
7962
  tensor._shape = size;
7802
7963
  return tensor;
7803
7964
  });
7965
+ this.registerFunction('torch._utils.set_tensor_metadata', (tensor, metadata) => {
7966
+ torch._C._set_tensor_metadata(tensor, metadata);
7967
+ });
7968
+ this.registerFunction('torch._utils._restore_device_fake_mode', (tensor) => {
7969
+ return tensor;
7970
+ });
7804
7971
  this.registerFunction('torch._utils._rebuild_meta_tensor_no_storage', (dtype, size, stride, requires_grad) => {
7805
7972
  return torch.empty_strided(size, stride, dtype, null, 'meta', false, requires_grad);
7806
7973
  });
@@ -7814,13 +7981,24 @@ python.Execution = class {
7814
7981
  tensor.__setstate__([storage, storage_offset, size, stride]);
7815
7982
  return tensor;
7816
7983
  });
7817
- this.registerFunction('torch._utils._rebuild_tensor_v2', (storage, storage_offset, size, stride, requires_grad, backward_hooks) => {
7818
- const tensor = execution.invoke('torch._utils._rebuild_tensor', [storage, storage_offset, size, stride]);
7984
+ this.registerFunction('torch._utils._rebuild_tensor_v2', (storage, storage_offset, size, stride, requires_grad, backward_hooks, metadata) => {
7985
+ const tensor = torch._utils._rebuild_tensor(storage, storage_offset, size, stride);
7819
7986
  tensor.requires_grad = requires_grad;
7987
+ if (metadata) {
7988
+ torch._utils.set_tensor_metadata(tensor, metadata);
7989
+ }
7820
7990
  tensor.backward_hooks = backward_hooks;
7821
7991
  return tensor;
7822
7992
  });
7823
- this.registerFunction('torch._utils._rebuild_tensor_v3');
7993
+ this.registerFunction('torch._utils._rebuild_tensor_v3', (storage, storage_offset, size, stride, requires_grad, backward_hooks, dtype, metadata) => {
7994
+ const t = new torch.Tensor(null, null, dtype);
7995
+ t.set_(storage, storage_offset, size, stride);
7996
+ if (metadata) {
7997
+ torch._utils.set_tensor_metadata(t, metadata);
7998
+ }
7999
+ t._backward_hooks = backward_hooks;
8000
+ return torch._utils._restore_device_fake_mode(t);
8001
+ });
7824
8002
  this.registerFunction('torch._utils._rebuild_parameter', (data, requires_grad, backward_hooks) => {
7825
8003
  const param = new torch.nn.parameter.Parameter(data, requires_grad);
7826
8004
  param.backward_hooks = backward_hooks;
@@ -8552,6 +8730,13 @@ python.Execution = class {
8552
8730
  }
8553
8731
  }
8554
8732
  static get(kind, annotation_str) {
8733
+ torch.Type.cache = torch.Type.cache || new Map();
8734
+ if (!annotation_str) {
8735
+ if (!torch.Type.cache.has(kind)) {
8736
+ torch.Type.cache.set(kind, new torch.Type(kind));
8737
+ }
8738
+ return torch.Type.cache.get(kind);
8739
+ }
8555
8740
  return new torch.Type(kind, annotation_str);
8556
8741
  }
8557
8742
  kind() {
@@ -8788,6 +8973,49 @@ python.Execution = class {
8788
8973
  return this.qualified_name();
8789
8974
  }
8790
8975
  });
8976
+ this.registerType('torch.EnumType', class extends torch.Type {
8977
+ constructor(qualified_class_name, value_type, enum_names_values, cu) {
8978
+ super('EnumType', qualified_class_name);
8979
+ this._name = qualified_class_name;
8980
+ this._value_type = value_type;
8981
+ this._enum_names_values = enum_names_values;
8982
+ this._cu = cu;
8983
+ }
8984
+ static create(qualified_class_name, value, enum_names_values, cu) {
8985
+ if (value instanceof torch.IntType || value instanceof torch.FloatType || value instanceof torch.StringType) {
8986
+ return new torch.EnumType(qualified_class_name, value, enum_names_values, cu);
8987
+ }
8988
+ torch._C.TORCH_CHECK(false);
8989
+ return null;
8990
+ }
8991
+ name() {
8992
+ return this._name;
8993
+ }
8994
+ get annotation_str() {
8995
+ return this._name.qualifiedName();
8996
+ }
8997
+ enumNamesValues() {
8998
+ return this._enum_names_values;
8999
+ }
9000
+ compilation_unit() {
9001
+ return this._cu;
9002
+ }
9003
+ getValueType() {
9004
+ return this._value_type;
9005
+ }
9006
+ equals(rhs) {
9007
+ if (rhs instanceof torch.EnumType) {
9008
+ return this.name() && this.name() === rhs.name() && this.getValueType() === rhs.getValueType() && this.compilation_unit() === rhs.compilation_unit();
9009
+ }
9010
+ return false;
9011
+ }
9012
+ isSubtypeOf(rhs) {
9013
+ if (rhs instanceof torch.AnyType || rhs.kind() === 'AnyEnumType' || this === rhs) {
9014
+ return true;
9015
+ }
9016
+ return super.isSubtypeOf(rhs);
9017
+ }
9018
+ });
8791
9019
  this.registerFunction('torch._C.standardizeVectorForUnion', (...args) => {
8792
9020
  if (args.length === 1) {
8793
9021
  const [to_flatten] = args;
@@ -10402,7 +10630,7 @@ python.Execution = class {
10402
10630
  }
10403
10631
  return torch._C.collectQualname(expr);
10404
10632
  }
10405
- throw new python.Error('Unsupported type.');
10633
+ throw new python.Error(`Unsupported type '${expr.__class__.__name__}'.`);
10406
10634
  }
10407
10635
  parseBroadcastList(/* expr */) {
10408
10636
  return null;
@@ -10659,6 +10887,12 @@ python.Execution = class {
10659
10887
  n.output().setType(typ);
10660
10888
  return n;
10661
10889
  }
10890
+ createEnumValue(e) {
10891
+ const enum_type = e.type().expect(torch.EnumType);
10892
+ const n = this.create('prim::EnumValue', [e]);
10893
+ n.output().setType(enum_type.getValueType());
10894
+ return n;
10895
+ }
10662
10896
  createList(contained_type, values) {
10663
10897
  const n = this.create('prim::ListConstruct', values);
10664
10898
  for (const v of values) {
@@ -11718,6 +11952,8 @@ python.Execution = class {
11718
11952
  this.tag = 'Int';
11719
11953
  } else if (typeof value === 'number') {
11720
11954
  this.tag = 'Double';
11955
+ } else if (value instanceof torch._C.EnumHolder) {
11956
+ this.tag = 'Enum';
11721
11957
  } else {
11722
11958
  throw new python.Error('Unsupported type.');
11723
11959
  }
@@ -11787,9 +12023,15 @@ python.Execution = class {
11787
12023
  isStream() {
11788
12024
  return this.tag === 'Stream';
11789
12025
  }
12026
+ isGenericDict() {
12027
+ return this.tag === 'GenericDict';
12028
+ }
11790
12029
  isEnum() {
11791
12030
  return this.tag === 'Enum';
11792
12031
  }
12032
+ toEnumHolder() {
12033
+ return this.value;
12034
+ }
11793
12035
  isTuple() {
11794
12036
  return this.tag === 'Tuple';
11795
12037
  }
@@ -11800,35 +12042,39 @@ python.Execution = class {
11800
12042
  return torch._C.isCustomClass(this);
11801
12043
  }
11802
12044
  equals(rhs) {
11803
- const lhs = this;
11804
- switch (lhs.tag) {
12045
+ switch (this.tag) {
11805
12046
  case 'None': return rhs.isNone();
11806
- case 'Bool': return rhs.isBool() && lhs.toBool() === rhs.toBool();
11807
- case 'Int': return rhs.isInt() && lhs.toInt() === rhs.toInt();
11808
- case 'Double': return rhs.isDouble() && lhs.toDouble() === rhs.toDouble();
11809
- case 'String': return rhs.isString() && lhs.toString() === rhs.toString();
11810
- case 'Tensor': return rhs.isTensor() && lhs.toTensor() === rhs.toTensor();
11811
- case 'Object': return rhs.isObject() && lhs.toObject() === rhs.toObject();
11812
- case 'Device': return rhs.isObject() && lhs.toDevice() === rhs.toDevice();
12047
+ case 'Bool': return rhs.isBool() && this.toBool() === rhs.toBool();
12048
+ case 'Int': return rhs.isInt() && this.toInt() === rhs.toInt();
12049
+ case 'Double': return rhs.isDouble() && this.toDouble() === rhs.toDouble();
12050
+ case 'String': return rhs.isString() && this.toString() === rhs.toString();
12051
+ case 'Tensor': return rhs.isTensor() && this.toTensor() === rhs.toTensor();
12052
+ case 'Object': return rhs.isObject() && this.toObject() === rhs.toObject();
12053
+ case 'Device': return rhs.isObject() && this.toDevice() === rhs.toDevice();
11813
12054
  case 'GenericList': {
11814
12055
  if (rhs.isList()) {
11815
- const a = lhs.toList();
12056
+ const a = this.toList();
11816
12057
  const b = rhs.toList();
11817
12058
  return (a.length === b.length) && a.every((v, i) => v === b[i]);
11818
12059
  }
11819
12060
  return false;
11820
12061
  }
11821
- default: throw new python.Error(`IValue.equals() not implemented for '${lhs.tag}.`);
12062
+ default: throw new python.Error(`IValue.equals() not implemented for '${this.tag}.`);
11822
12063
  }
11823
12064
  }
11824
12065
  is(rhs) {
11825
- const lhs = this;
11826
- return lhs.equals(rhs);
12066
+ return this.equals(rhs);
11827
12067
  }
11828
12068
  type() {
11829
12069
  switch (this.tag) {
12070
+ case 'None': return torch.NoneType.get();
12071
+ case 'Bool': return torch.BoolType.get();
11830
12072
  case 'Int': return torch.IntType.get();
12073
+ case 'Double': return torch.FloatType.get();
12074
+ case 'String': return torch.StringType.get();
12075
+ case 'Device': return torch.DeviceObjType.get();
11831
12076
  case 'Tuple': return torch.TupleType.create(this.value.elements().map((ivalue) => ivalue.type()));
12077
+ case 'Enum': return this.toEnumHolder().type();
11832
12078
  default: throw new python.Error(`IValue.type('${this.tag}') not implemented.`);
11833
12079
  }
11834
12080
  }
@@ -12064,8 +12310,8 @@ python.Execution = class {
12064
12310
  }
12065
12311
  const graph = m.graph();
12066
12312
  switch (name) {
12067
- case 'inf': return new torch._C.SimpleValue(graph.insertConstant('std::numeric_limits<double>::infinity()', loc));
12068
- case 'nan': return new torch._C.SimpleValue(graph.insertConstant('std::numeric_limits<double>::quiet_NaN()', loc));
12313
+ case 'inf': return new torch._C.SimpleValue(graph.insertConstant(Infinity /* 'std::numeric_limits<double>::infinity()' */, loc));
12314
+ case 'nan': return new torch._C.SimpleValue(graph.insertConstant(NaN /* 'std::numeric_limits<double>::quiet_NaN()' */, loc));
12069
12315
  case 'infj': return new torch._C.SimpleValue(graph.insertConstant('c10::complex<double>(0, std::numeric_limits<double>::infinity())', loc));
12070
12316
  case 'nanj': return new torch._C.SimpleValue(graph.insertConstant('c10::complex<double>(0, std::numeric_limits<double>::quiet_NaN()', loc));
12071
12317
  case '__torch__': return new torch._C.ClassNamespaceValue(new torch._C.QualifiedName(name), this);
@@ -12102,7 +12348,7 @@ python.Execution = class {
12102
12348
  } else if (superclass_name === 'ModuleInterface') {
12103
12349
  // this._cu.define_interface(qualified_name, class_def, shared_from_this(), is_module=true);
12104
12350
  } else if (superclass_name === 'Enum') {
12105
- // importEnum(qualified_name, class_def);
12351
+ this.importEnum(qualified_name, class_def);
12106
12352
  } else {
12107
12353
  throw new python.Error('TorchScript does not support class inheritance.');
12108
12354
  }
@@ -12214,6 +12460,56 @@ python.Execution = class {
12214
12460
  const self = new torch._C.SimpleSelf(class_type);
12215
12461
  this._cu.define(qualified_classname, [], [], methods, method_resolvers, self, false, this._version);
12216
12462
  }
12463
+ importEnum(qualified_name, enum_def) {
12464
+ const names_values = [];
12465
+ let value_type = null;
12466
+ const set_or_check_type = (t) => {
12467
+ if (!value_type) {
12468
+ value_type = t;
12469
+ } else if (value_type !== t) {
12470
+ throw new python.Error('Enum class with varying value types are not supported.');
12471
+ }
12472
+ };
12473
+ for (const stmt of enum_def.body) {
12474
+ if (stmt instanceof ast.Assign === false) {
12475
+ throw new python.Error('Unexpected statement in Enum class body.');
12476
+ }
12477
+ const assign = stmt;
12478
+ const name = assign.targets[0].id;
12479
+ let ivalue = null;
12480
+ const rhs = assign.value;
12481
+ switch (rhs.type) {
12482
+ case 'str':
12483
+ ivalue = new torch._C.IValue(rhs.value);
12484
+ set_or_check_type(torch.StringType.get());
12485
+ break;
12486
+ default:
12487
+ throw new python.Error(`Unsupported enum value type '${rhs.type}'.`);
12488
+ /*
12489
+ case TK_CONST: {
12490
+ auto numeric_const = Const(rhs);
12491
+ if (numeric_const.isFloatingPoint()) {
12492
+ ivalue = IValue(numeric_const.asFloatingPoint());
12493
+ set_or_check_type(FloatType::get(), statement.range());
12494
+ } else if (numeric_const.isIntegral()) {
12495
+ ivalue = IValue(numeric_const.asIntegral());
12496
+ set_or_check_type(IntType::get(), statement.range());
12497
+ }
12498
+ break;
12499
+ }
12500
+ default:
12501
+ throw(ErrorReport(rhs.range()) << "Unsupported enum value type: " << rhs.kind() << ". Only Integers, Floats and Strings are supported.");
12502
+ }
12503
+ */
12504
+ }
12505
+ names_values.push([name, ivalue]);
12506
+ }
12507
+ if (!value_type) {
12508
+ throw new python.Error('No enum values defined.');
12509
+ }
12510
+ const enum_type = torch.EnumType.create(qualified_name, value_type, names_values, this._cu);
12511
+ this._cu.register_type(enum_type);
12512
+ }
12217
12513
  importNamedTuple(qualified_name, named_tuple_def) {
12218
12514
  const type_parser = new torch._C.ScriptTypeParser(this);
12219
12515
  const field_names = [];
@@ -12478,40 +12774,6 @@ python.Execution = class {
12478
12774
  execution.builtins.inf = torch.inf;
12479
12775
  execution.builtins.CONSTANTS = {};
12480
12776
  execution._resolver = this._source_importer;
12481
- const known_types = [
12482
- { name: '__torch__.torch.classes._nnapi.Compilation', methods: [
12483
- '__init__(__torch__.torch.classes._nnapi.Compilation self) -> NoneType',
12484
- 'init(__torch__.torch.classes._nnapi.Compilation self, Tensor serialized_model_tensor, Tensor[] parameter_buffers) -> NoneType',
12485
- 'init2(__torch__.torch.classes._nnapi.Compilation self, Tensor serialized_model_tensor, Tensor[] parameter_buffers, int compilation_preference, bool relax_f32_to_f16) -> NoneType',
12486
- 'run(__torch__.torch.classes._nnapi.Compilation self, Tensor[] inputs, Tensor[] outputs) -> NoneType'
12487
- ] },
12488
- { name: '__torch__.torch.classes.quantized.Conv2dPackedParamsBase', attributes: 'Tensor weight, Tensor bias, int[] stride, int[] padding, int[] dilation, int groups', methods: ['unpack(__torch__.torch.classes.quantized.Conv2dPackedParamsBase self) -> ((Tensor, Tensor?))'] },
12489
- { name: '__torch__.torch.classes.quantized.Conv3dPackedParamsBase', attributes: 'Tensor weight, Tensor bias, int[] stride, int[] padding, int[] dilation, int groups', methods: ['unpack(__torch__.torch.classes.quantized.Conv3dPackedParamsBase self) -> ((Tensor, Tensor?))'] },
12490
- { name: '__torch__.torch.classes.quantized.LinearPackedParamsBase', attributes: 'Tensor weight, Tensor? bias' },
12491
- { name: '__torch__.torch.classes.rnn.CellParamsBase', attributes: 'str type, Tensor[] tensors, float[] doubles, int[] longs, __torch__.torch.classes.quantized.LinearPackedParamsBase[] packed_params' },
12492
- { name: '__torch__.torch.classes.xnnpack.Conv2dOpContext', attributes: 'Tensor weight, Tensor? bias, int[] stride, int[] padding, int[] dilation, int groups, int[] output_min, int[] output_max' },
12493
- { name: '__torch__.torch.classes.xnnpack.LinearOpContext', attributes: 'Tensor weight, Tensor bias, int[] output_min, int[] output_max' },
12494
- { name: '__torch__.torch.classes.xnnpack.TransposeConv2dOpContext', attributes: 'Tensor weight, Tensor? bias, int[] stride, int[] padding, int[] output_padding, int[] dilation, int groups, int[] output_min, int[] output_max' },
12495
- { name: '__torch__.torch.classes.tensorrt.Engine' }
12496
- ];
12497
- for (const known_type of known_types) {
12498
- const prefix = new torch._C.QualifiedName(known_type.name);
12499
- const type = torch.ClassType.create(known_type.name, this._compilation_unit, false);
12500
- for (const known_method of known_type.methods || []) {
12501
- const schema = new torch.FunctionSchema(known_method);
12502
- const name = new torch._C.QualifiedName(prefix, schema.name);
12503
- const fn = new torch._C.BuiltinOpFunction(name, schema);
12504
- type.addMethod(fn);
12505
- }
12506
- if (known_type.attributes) {
12507
- const schema = new torch.FunctionSchema(`(${known_type.attributes}) -> ()`);
12508
- for (const arg of schema.arguments) {
12509
- type.addAttribute(arg.name, arg.real_type);
12510
- }
12511
- }
12512
- torch._C.registerCustomClass(type);
12513
- // this._compilation_unit.register_type(type);
12514
- }
12515
12777
  if (this._reader.has_record('model.json')) {
12516
12778
  return this.LEGACY_deserialize();
12517
12779
  }
@@ -12771,7 +13033,9 @@ python.Execution = class {
12771
13033
  this.error_messages = new Map();
12772
13034
  }
12773
13035
  setVariableTypeError(name, msg) {
13036
+ /* eslint-disable consistent-this */
12774
13037
  let runner = this;
13038
+ /* eslint-enable consistent-this */
12775
13039
  while (runner.next) {
12776
13040
  runner = runner.next;
12777
13041
  }
@@ -12806,7 +13070,10 @@ python.Execution = class {
12806
13070
  this.type_table.set(name, type);
12807
13071
  }
12808
13072
  findInAnyFrame(name) {
12809
- for (let runner = this; runner; runner = runner.next) {
13073
+ /* eslint-disable consistent-this */
13074
+ const self = this;
13075
+ /* eslint-enable consistent-this */
13076
+ for (let runner = self; runner; runner = runner.next) {
12810
13077
  const r = runner.findInThisFrame(name);
12811
13078
  if (r) {
12812
13079
  return r;
@@ -12868,6 +13135,7 @@ python.Execution = class {
12868
13135
  ['hasattr', torch._C.SpecialFormValue.create('prim::HasAttr')],
12869
13136
  ['isinstance', torch._C.SpecialFormValue.create('prim::isinstance')],
12870
13137
  ['range', torch._C.SpecialFormValue.create('prim::range')],
13138
+ ['sorted', new torch._C.BuiltinFunction('aten::sorted', null)],
12871
13139
  ]);
12872
13140
  if (torch._C.Environment.globals.has(ident)) {
12873
13141
  retval = torch._C.Environment.globals.get(ident);
@@ -13117,7 +13385,7 @@ python.Execution = class {
13117
13385
  }
13118
13386
  for (const entry of torch._C.get_operator_version_map()) {
13119
13387
  const old_symbol_name = entry.first;
13120
- const base_name = old_symbol_name.substr(0, old_symbol_name.find('.'));
13388
+ const base_name = old_symbol_name.substring(0, old_symbol_name.find('.'));
13121
13389
  if (base_name === name) {
13122
13390
  const possibleUpgrader = torch._C.findUpgrader(entry.second, version.value());
13123
13391
  if (possibleUpgrader.has_value()) {
@@ -14024,17 +14292,17 @@ python.Execution = class {
14024
14292
  }
14025
14293
  } else if (this._value.type() instanceof torch.InterfaceType) {
14026
14294
  throw new python.Error('Not implemented.');
14027
- } /* else if (this._value.type() instanceof torch.EnumType) {
14295
+ } else if (this._value.type() instanceof torch.EnumType) {
14028
14296
  const g = m.graph();
14029
- if (field == 'name') {
14030
- const n = g.insertNode(g.createEnumName(value_));
14031
- return std::make_shared<SimpleValue>(n->output());
14297
+ if (field === 'name') {
14298
+ const n = g.insertNode(g.createEnumName(this._value));
14299
+ return new torch._C.SimpleValue(n.output());
14032
14300
  }
14033
- if (field == 'value') {
14034
- const n = g.insertNode(g.createEnumValue(value_));
14035
- return std::make_shared<SimpleValue>(n->output());
14301
+ if (field === 'value') {
14302
+ const n = g.insertNode(g.createEnumValue(this._value));
14303
+ return new torch._C.SimpleValue(n.output());
14036
14304
  }
14037
- } */
14305
+ }
14038
14306
  if (field === 'type') {
14039
14307
  const builtin = torch._C.BuiltinFunction.tryCreate('aten::to', new torch._C.NamedValue(loc, 'self', this._value));
14040
14308
  if (builtin) {
@@ -14181,6 +14449,31 @@ python.Execution = class {
14181
14449
  return new torch._C.SimpleValue(self);
14182
14450
  }
14183
14451
  });
14452
+ this.registerType('torch._C.SugaredEnumClass', class extends torch._C.SugaredValue {
14453
+ constructor(enum_type) {
14454
+ super();
14455
+ this._enum_type = enum_type;
14456
+ }
14457
+ attr(loc, m, field) {
14458
+ const names_values = this._enum_type.enumNamesValues();
14459
+ const it = names_values.find((nv) => nv[0] === field);
14460
+ if (it === null) {
14461
+ throw new python.Error(`Enum '${this._enum_type.name()}' has no attribute '${field}'.`);
14462
+ }
14463
+ const enum_holder = new torch._C.EnumHolder(this._enum_type, it[0], it[1]);
14464
+ return new torch._C.SimpleValue(m.graph().insertConstant(new torch._C.IValue(enum_holder), loc));
14465
+ }
14466
+ });
14467
+ this.registerType('torch._C.EnumHolder', class {
14468
+ constructor(type, name, value) {
14469
+ this._type = type;
14470
+ this._name = name;
14471
+ this._value = value;
14472
+ }
14473
+ type() {
14474
+ return this._type;
14475
+ }
14476
+ });
14184
14477
  this.registerType('torch._C.FunctionValue', class extends torch._C.SugaredValue {
14185
14478
  constructor(...args) {
14186
14479
  super();
@@ -14691,6 +14984,8 @@ python.Execution = class {
14691
14984
  this.registerFunction('torch._C._jit_pass_inline', (graph) => {
14692
14985
  torch._C.Inline(graph);
14693
14986
  });
14987
+ this.registerFunction('torch._C._set_tensor_metadata', (/* tensor, metadata */) => {
14988
+ });
14694
14989
  this.registerFunction('torch.jit._script.unpackage_script_module', (importer, script_module_id) => {
14695
14990
  const cu = new torch.jit.CompilationUnit();
14696
14991
  cu.execution = execution;
@@ -14767,6 +15062,17 @@ python.Execution = class {
14767
15062
  _type() {
14768
15063
  return this._typ; // torch.ClassType
14769
15064
  }
15065
+ __setstate__(state) {
15066
+ const [attrs, qualname] = state;
15067
+ this._typ = torch._C.getCustomClass(qualname);
15068
+ if (!this._typ) {
15069
+ throw new python.Error(`Unsupported custom class '${qualname}'.`);
15070
+ }
15071
+ for (let i = 0; i < this._typ.numAttributes(); i++) {
15072
+ const name = this._typ.getAttributeName(i);
15073
+ this.__setattr__(name, attrs[i]);
15074
+ }
15075
+ }
14770
15076
  find_method(basename) {
14771
15077
  for (const fn of this.type().methods()) {
14772
15078
  if (fn.name() === basename) {
@@ -14786,6 +15092,9 @@ python.Execution = class {
14786
15092
  _has_method(name) {
14787
15093
  return this.find_method(name) ? true : false;
14788
15094
  }
15095
+ _method_names() {
15096
+ return this.type().methods().map((fn) => fn.name());
15097
+ }
14789
15098
  __setattr__(name, value) {
14790
15099
  // if (this._type.hasContant(name))
14791
15100
  this._ivalue[name] = value;
@@ -15374,7 +15683,7 @@ python.Execution = class {
15374
15683
  if (save_false.findInAnyFrame(v) || false_exits) {
15375
15684
  mutated_variables.add(v);
15376
15685
  } else {
15377
- this.environment_stack.setVariableTypeError(v, () => 'Value is is not defined in the false branch.');
15686
+ this.environment_stack.setVariableTypeError(v, () => 'Value is not defined in the false branch.');
15378
15687
  }
15379
15688
  insert.dispose();
15380
15689
  }
@@ -15383,7 +15692,7 @@ python.Execution = class {
15383
15692
  if (save_true.findInAnyFrame(v) || true_exits) {
15384
15693
  mutated_variables.add(v);
15385
15694
  } else {
15386
- this.environment_stack.setVariableTypeError(v, () => 'Value is is not defined in the true branch.');
15695
+ this.environment_stack.setVariableTypeError(v, () => 'Value is not defined in the true branch.');
15387
15696
  }
15388
15697
  insert.dispose();
15389
15698
  }
@@ -15448,18 +15757,25 @@ python.Execution = class {
15448
15757
  }
15449
15758
  refineAndSetUnionTypeHintOrPopulateCandidatesVector(type_hint, refined_type_hint_ptr, all_candidates, match_repr, src, type_match, do_if_match, do_if_anytype, is_dict_constructor) {
15450
15759
  is_dict_constructor = is_dict_constructor || false;
15451
- if (refined_type_hint_ptr instanceof torch.UnionType) {
15452
- throw new python.Error('Not implemented.');
15453
- } else if (refined_type_hint_ptr instanceof torch.OptionalType) {
15454
- refined_type_hint_ptr = refined_type_hint_ptr.getElementType();
15760
+ if (refined_type_hint_ptr._ instanceof torch.UnionType) {
15761
+ const candidate_types = refined_type_hint_ptr._.containedTypes().filter((type_ptr) => type_match(type_ptr));
15762
+ if (!is_dict_constructor && candidate_types.length === 0) {
15763
+ throw new python.Error("No matching types found in Union type annotation.");
15764
+ } else if (candidate_types.length === 1) {
15765
+ [refined_type_hint_ptr._] = candidate_types;
15766
+ } else {
15767
+ all_candidates._ = candidate_types;
15768
+ }
15769
+ } else if (refined_type_hint_ptr._ instanceof torch.OptionalType) {
15770
+ refined_type_hint_ptr._ = refined_type_hint_ptr._.getElementType();
15455
15771
  }
15456
15772
  if (is_dict_constructor) {
15457
15773
  return;
15458
15774
  }
15459
- if (all_candidates.length === 0) {
15460
- if (type_match(refined_type_hint_ptr)) {
15775
+ if (all_candidates._.length === 0) {
15776
+ if (type_match(refined_type_hint_ptr._)) {
15461
15777
  do_if_match();
15462
- } else if (refined_type_hint_ptr.kind() === 'AnyType') {
15778
+ } else if (refined_type_hint_ptr._.kind() === 'AnyType') {
15463
15779
  do_if_anytype();
15464
15780
  } else {
15465
15781
  throw new python.Error('Invalid annotation type.');
@@ -15870,14 +16186,14 @@ python.Execution = class {
15870
16186
  rhs_value_type = torch._C.unifyTypes(rhs_value_type, values[i].type(), /*default_to_union=*/true);
15871
16187
  }
15872
16188
  }
15873
- let refined_type_hint = type_hint;
16189
+ const refined_type_hint = { _: type_hint };
15874
16190
  const annotated_union_type = type_hint && type_hint.isUnionType() ? type_hint : null;
15875
- const all_candidates = [];
16191
+ const all_candidates = { _: [] };
15876
16192
  const default_refined_type_hint_setter = () => {
15877
16193
  if (keys.length === 0) {
15878
- refined_type_hint = torch.DictType.create(torch.StringType.get(), torch.TensorType.get());
16194
+ refined_type_hint._ = torch.DictType.create(torch.StringType.get(), torch.TensorType.get());
15879
16195
  } else {
15880
- refined_type_hint = torch.DictType.create(keys[0].type(), rhs_value_type);
16196
+ refined_type_hint._ = torch.DictType.create(keys[0].type(), rhs_value_type);
15881
16197
  if (rhs_value_type instanceof torch.UnionType) {
15882
16198
  throw new python.Error('Dict values consist of heterogeneous types.');
15883
16199
  }
@@ -15886,25 +16202,25 @@ python.Execution = class {
15886
16202
  if (type_hint) {
15887
16203
  const type_match = (t) => t instanceof torch.DictType;
15888
16204
  this.refineAndSetUnionTypeHintOrPopulateCandidatesVector(type_hint, refined_type_hint, all_candidates, 'Dict', dl, type_match, () => [], default_refined_type_hint_setter);
15889
- if (all_candidates.length > 0 && values.length === 0) {
16205
+ if (all_candidates._.length > 0 && values.length === 0) {
15890
16206
  throw new python.Error('Cannot assign an empty dict.');
15891
16207
  }
15892
16208
  } else {
15893
16209
  default_refined_type_hint_setter();
15894
16210
  }
15895
- torch._C.TORCH_INTERNAL_ASSERT(all_candidates.length > 0 || refined_type_hint);
16211
+ torch._C.TORCH_INTERNAL_ASSERT(all_candidates._.length > 0 || refined_type_hint._);
15896
16212
  if (values.length > 0) {
15897
- if (all_candidates.length > 0) {
16213
+ if (all_candidates._.length > 0) {
15898
16214
  this.refineAndSetDictTypeHintFromCandidatesVector(all_candidates, type_hint, refined_type_hint, keys[0].type(), rhs_value_type, dl);
15899
16215
  }
15900
- if (refined_type_hint.getKeyType() !== keys[0].type()) {
16216
+ if (refined_type_hint._.getKeyType() !== keys[0].type()) {
15901
16217
  throw new python.Error('Type annotation does not match key type.');
15902
16218
  }
15903
- if (!rhs_value_type.isSubtypeOf(refined_type_hint.getValueType())) {
16219
+ if (!rhs_value_type.isSubtypeOf(refined_type_hint._.getValueType())) {
15904
16220
  throw new python.Error('Type annotation does not match value type.');
15905
16221
  }
15906
16222
  }
15907
- let result = this.graph.insertNode(this.graph.createDict(refined_type_hint.getKeyType(), refined_type_hint.getValueType(), keys, values));
16223
+ let result = this.graph.insertNode(this.graph.createDict(refined_type_hint._.getKeyType(), refined_type_hint._.getValueType(), keys, values));
15908
16224
  if (annotated_union_type) {
15909
16225
  const n = this.graph.insertNode(this.graph.create('prim::unchecked_cast', [result.output()]));
15910
16226
  n.output().setType(annotated_union_type);
@@ -15932,34 +16248,34 @@ python.Execution = class {
15932
16248
  throw new python.Error('Not implemented.');
15933
16249
  }
15934
16250
  let inferred_elem_type = torch.TensorType.get();
15935
- const refined_type_hint = type_hint;
15936
- const annotated_union_type = refined_type_hint && refined_type_hint.isUnionType() ? refined_type_hint : null;
15937
- const all_candidates = [];
15938
- if (refined_type_hint) {
16251
+ const refined_type_hint = { _: type_hint };
16252
+ const annotated_union_type = refined_type_hint._ && refined_type_hint._.isUnionType() ? refined_type_hint._ : null;
16253
+ const all_candidates = { _: [] };
16254
+ if (refined_type_hint._) {
15939
16255
  const do_if_type_match = () => {
15940
- inferred_elem_type = refined_type_hint.expect(torch.ListType).getElementType();
16256
+ inferred_elem_type = refined_type_hint._.expect(torch.ListType).getElementType();
15941
16257
  };
15942
16258
  const type_match = (t) => t.isSubtypeOf(torch.Type.get('AnyListType'));
15943
16259
  this.refineAndSetUnionTypeHintOrPopulateCandidatesVector(type_hint, refined_type_hint, all_candidates, 'List', ll, type_match, do_if_type_match, do_if_type_match);
15944
- if (all_candidates.length > 0 && values.len === 0) {
16260
+ if (all_candidates._.length > 0 && values.len === 0) {
15945
16261
  throw new python.Error('Cannot assign an empty list.');
15946
16262
  }
15947
16263
  }
15948
16264
  if (values.length !== 0) {
15949
16265
  const types = values.map((v) => v.type());
15950
- const elem_type_hint = refined_type_hint && refined_type_hint.kind() === 'ListType' ? refined_type_hint.getElementType() : null;
16266
+ const elem_type_hint = refined_type_hint._ && refined_type_hint._.kind() === 'ListType' ? refined_type_hint._.getElementType() : null;
15951
16267
  const unified_elem_type = torch._C.unifyTypeList(types, null /*nowhere*/, /*default_to_union=*/true, elem_type_hint);
15952
- if (!refined_type_hint && unified_elem_type.kind() === 'UnionType') {
16268
+ if (!refined_type_hint._ && unified_elem_type.kind() === 'UnionType') {
15953
16269
  throw new python.Error('Not implemented.');
15954
16270
  }
15955
- if (all_candidates.length === 0 && refined_type_hint && !unified_elem_type.isSubtypeOf(inferred_elem_type)) {
16271
+ if (all_candidates._.length === 0 && refined_type_hint._ && !unified_elem_type.isSubtypeOf(inferred_elem_type)) {
15956
16272
  throw new python.Error('Not implemented.');
15957
16273
  }
15958
- if (all_candidates.length !== 0) {
15959
- this.refineAndSetListTypeHintFromCandidatesVector(all_candidates, type_hint, refined_type_hint, unified_elem_type, ll);
15960
- inferred_elem_type = refined_type_hint.expect(torch.ListType).getElementType();
16274
+ if (all_candidates._.length !== 0) {
16275
+ this.refineAndSetListTypeHintFromCandidatesVector(all_candidates, type_hint, refined_type_hint._, unified_elem_type, ll);
16276
+ inferred_elem_type = refined_type_hint._.expect(torch.ListType).getElementType();
15961
16277
  }
15962
- if (!refined_type_hint) {
16278
+ if (!refined_type_hint._) {
15963
16279
  inferred_elem_type = unified_elem_type;
15964
16280
  }
15965
16281
  }
@@ -16368,7 +16684,10 @@ python.Execution = class {
16368
16684
  return null;
16369
16685
  }
16370
16686
  findInAnyFrame(name) {
16371
- for (let runner = this; runner; runner = runner.next) {
16687
+ /* eslint-disable consistent-this */
16688
+ const self = this;
16689
+ /* eslint-enable consistent-this */
16690
+ for (let runner = self; runner; runner = runner.next) {
16372
16691
  const r = runner.findInThisFrame(name);
16373
16692
  if (r) {
16374
16693
  return r;
@@ -17448,29 +17767,25 @@ python.Execution = class {
17448
17767
  this.as_tensor = new torch._export.serde.schema.TensorArgument(this.as_tensor);
17449
17768
  } else if (this.type === 'as_tensors') {
17450
17769
  this.as_tensors = this.as_tensors.map((item) => new torch._export.serde.schema.TensorArgument(item));
17770
+ } else if (this.type === 'as_graph') {
17771
+ this.as_graph = new torch._export.serde.schema.GraphArgument(this.as_graph);
17451
17772
  } else if (this.type === 'as_sym_int') {
17452
17773
  this.as_sym_int = new torch._export.serde.schema.SymIntArgument(this.as_sym_int);
17453
17774
  } else if (this.type === 'as_sym_ints') {
17454
17775
  this.as_sym_ints = this.as_sym_ints.map((item) => new torch._export.serde.schema.SymIntArgument(item));
17776
+ } else if (this.type === 'as_sym_bool') {
17777
+ this.as_sym_bool = new torch._export.serde.schema.SymBoolArgument(this.as_sym_bool);
17778
+ } else if (this.type === 'as_sym_bools') {
17779
+ this.as_sym_bools = this.as_sym_bools.map((item) => new torch._export.serde.schema.SymBoolArgument(item));
17455
17780
  } else if (this.type === 'as_optional_tensors') {
17456
17781
  this.as_optional_tensors = this.as_optional_tensors.map((item) => new torch._export.serde.schema.OptionalTensorArgument(item));
17457
17782
  } else {
17458
17783
  throw new python.Error(`Unsupported argument '${this.type}'.`);
17459
17784
  }
17460
17785
  /*
17461
- as_tensors: List[TensorArgument]
17462
- as_string: str
17463
- as_strings: List[str]
17464
- as_sym_int: SymIntArgument
17465
- as_sym_ints: List[SymIntArgument]
17466
- as_scalar_type: ScalarType
17467
- as_memory_format: MemoryFormat
17468
- as_layout: Layout
17469
- as_bools: List[bool]
17470
17786
  as_sym_bool: SymBoolArgument
17471
17787
  as_sym_bools: List[SymBoolArgument]
17472
17788
  as_graph: GraphArgument
17473
- as_optional_tensors: List[OptionalTensorArgument]
17474
17789
  as_custom_obj: CustomObjArgument
17475
17790
  */
17476
17791
  }
@@ -17711,7 +18026,7 @@ python.Execution = class {
17711
18026
  });
17712
18027
  this.registerType('torch._export.serde.schema.BufferMutationSpec', class {
17713
18028
  constructor(obj) {
17714
- this.arg = new torch._export.serde.schema.Argument(obj.arg);
18029
+ this.arg = new torch._export.serde.schema.TensorArgument(obj.arg);
17715
18030
  this.buffer_name = obj.buffer_name;
17716
18031
  }
17717
18032
  });
@@ -17768,6 +18083,12 @@ python.Execution = class {
17768
18083
  this.name = obj.name;
17769
18084
  }
17770
18085
  });
18086
+ this.registerType('torch._export.serde.schema.GraphArgument', class {
18087
+ constructor(obj) {
18088
+ this.name = obj.name;
18089
+ this.graph = new torch._export.serde.schema.Graph(obj.graph);
18090
+ }
18091
+ });
17771
18092
  this.registerType('torch._export.serde.schema.OptionalTensorArgument', class extends torch._export.serde.union._Union {
17772
18093
  constructor(obj) {
17773
18094
  super(obj);
@@ -17780,13 +18101,22 @@ python.Execution = class {
17780
18101
  }
17781
18102
  }
17782
18103
  });
17783
- this.registerFunction('torch._export.load', (f, expected_opset_version) => {
17784
- const serialized_exported_program = f.get('serialized_exported_program.json');
17785
- const serialized_state_dict = f.get('serialized_state_dict.pt');
17786
- const serialized_constants = f.get('serialized_constants.pt');
17787
- const serialized_example_inputs = f.get('serialized_example_inputs.pt');
17788
- const artifact = new torch._export.serde.serialize.SerializedArtifact(serialized_exported_program, serialized_state_dict, serialized_constants, serialized_example_inputs);
17789
- return torch._export.serde.serialize.deserialize(artifact, expected_opset_version);
18104
+ this.registerFunction('torch.export.pt2_archive._package.load_pt2', (f, expected_opset_version) => {
18105
+ const exported_programs = new Map();
18106
+ for (const name of f.keys()) {
18107
+ const match = name.match(/^models\/([^/]+)\.json$/);
18108
+ if (match) {
18109
+ const [, model_name] = match;
18110
+ const serialized_exported_program = f.get(`models/${model_name}.json`);
18111
+ const serialized_state_dict = f.get(`data/weights/${model_name}.pt`);
18112
+ const serialized_constants = f.get(`data/constants/${model_name}.pt`);
18113
+ const serialized_example_inputs = f.get(`data/sample_inputs/${model_name}.pt`);
18114
+ const artifact = new torch._export.serde.serialize.SerializedArtifact(serialized_exported_program, serialized_state_dict, serialized_constants, serialized_example_inputs);
18115
+ const exported_program = torch._export.serde.serialize.deserialize(artifact, expected_opset_version);
18116
+ exported_programs.set(model_name, exported_program);
18117
+ }
18118
+ }
18119
+ return { exported_programs };
17790
18120
  });
17791
18121
  this.registerFunction('torch._export.serde.serialize._dict_to_dataclass', (cls, data) => {
17792
18122
  if (data === null) {
@@ -18427,10 +18757,23 @@ python.Execution = class {
18427
18757
  this.registerType('torch._dynamo.convert_frame.CatchErrorsWrapper', class {});
18428
18758
  this.registerType('torch._dynamo.convert_frame.ConvertFrameAssert', class {});
18429
18759
  this.registerType('torch._dynamo.convert_frame.ConvertFrame', class {});
18760
+ this.registerType('torch._dynamo.convert_frame.ConvertFrameBox', class {});
18430
18761
  this.registerType('torch._dynamo.eval_frame._TorchDynamoContext', class {});
18431
- this.registerType('torch._dynamo.eval_frame.OptimizedModule', class extends torch.nn.modules.module.Module {});
18762
+ this.registerType('torch._dynamo.eval_frame.OptimizedModule', class extends torch.nn.modules.module.Module {
18763
+ constructor(mod, dynamo_ctx) {
18764
+ builtins.object.__setattr__(self, '_orig_mod', mod);
18765
+ // this._super_module_initialized = false;
18766
+ super();
18767
+ // this._super_module_initialized = true;
18768
+ this._orig_mod = mod;
18769
+ this.dynamo_ctx = dynamo_ctx;
18770
+ // this._initialize();
18771
+ this.training = this._orig_mod.training;
18772
+ }
18773
+ });
18432
18774
  this.registerType('torch._dynamo.eval_frame.OptimizeContext', class extends torch._dynamo.eval_frame._TorchDynamoContext {});
18433
18775
  this.registerType('torch._dynamo.hooks.Hooks', class {});
18776
+ this.registerType('torch._dynamo.output_graph.GraphCompileReason', class {});
18434
18777
  this.registerType('torch._dynamo.repro.after_dynamo.WrapBackendDebug', class {});
18435
18778
  this.registerType('torch._TorchCompileInductorWrapper', class {});
18436
18779
  this.registerFunction('torch._inductor.compile_fx.compile_fx');
@@ -18556,7 +18899,7 @@ python.Execution = class {
18556
18899
  _set_cdata(data) {
18557
18900
  const length = this.size() * this.dtype.itemsize();
18558
18901
  if (length !== data.length) {
18559
- throw new python.Error('Storage data size mismatch.');
18902
+ throw new python.Error('Typed storage data size mismatch.');
18560
18903
  }
18561
18904
  this._cdata = data;
18562
18905
  }
@@ -18564,7 +18907,7 @@ python.Execution = class {
18564
18907
  const buffer = unpickler.read(8);
18565
18908
  const size = buffer.reverse().reduce((a, b) => (a * 256) + b, 0);
18566
18909
  if (size !== this.size()) {
18567
- throw new python.Error('Storage size mismatch.');
18910
+ throw new python.Error('Typed storage size mismatch.');
18568
18911
  }
18569
18912
  const itemsize = this.dtype.itemsize();
18570
18913
  const data = unpickler.stream(itemsize * size);
@@ -18580,19 +18923,28 @@ python.Execution = class {
18580
18923
  return storage;
18581
18924
  }
18582
18925
  });
18583
- this.registerType('torch.storage.UntypedStorage', class extends torch.storage._StorageBase {
18584
- constructor() {
18585
- super();
18586
- throw new python.Error('UntypedStorage not implemented.');
18926
+ this.registerType('torch.storage.UntypedStorage', class {
18927
+ constructor(size) {
18928
+ this._size = size;
18929
+ }
18930
+ _set_cdata(data) {
18931
+ if (this._size !== data.length) {
18932
+ throw new python.Error('Untyped storage data size mismatch.');
18933
+ }
18934
+ this._cdata = data;
18587
18935
  }
18588
18936
  });
18589
18937
  this.registerType('torch.storage.TypedStorage', class {
18590
18938
  constructor(...args) {
18591
- if (args.length >= 2 && Number.isInteger(args[0]) && args[1] instanceof torch.dtype) {
18939
+ if (args.length === 0) {
18940
+ this._size = 0;
18941
+ } else if (args.length === 1 && Number.isInteger(args[0])) {
18942
+ [this._size] = args;
18943
+ } else if (args.length >= 2 && Number.isInteger(args[0]) && args[1] instanceof torch.dtype) {
18592
18944
  if (args[3] instanceof torch.device) {
18593
- [this._size, this._dtype, , this._device] = args;
18945
+ [this._size, this.dtype, , this._device] = args;
18594
18946
  } else {
18595
- [this._size, this._dtype] = args;
18947
+ [this._size, this.dtype] = args;
18596
18948
  }
18597
18949
  } else {
18598
18950
  throw new python.Error(`Unsupported TypedStorage arguments '${JSON.stringify(args)}'.`);
@@ -18604,6 +18956,9 @@ python.Execution = class {
18604
18956
  get dtype() {
18605
18957
  return this._dtype;
18606
18958
  }
18959
+ set dtype(value) {
18960
+ this._dtype = value;
18961
+ }
18607
18962
  element_size() {
18608
18963
  return this._dtype.element_size;
18609
18964
  }
@@ -18641,89 +18996,101 @@ python.Execution = class {
18641
18996
  }
18642
18997
  });
18643
18998
  this.registerType('torch.storage._LegacyStorage', class extends torch.storage.TypedStorage {
18644
- constructor() {
18645
- super();
18646
- throw new python.Error('_LegacyStorage not implemented.');
18647
- }
18648
18999
  });
18649
- this.registerType('torch.BoolStorage', class extends torch.storage._StorageBase {
18650
- constructor(size) {
18651
- super(size, torch.bool);
19000
+ this.registerType('torch.BoolStorage', class extends torch.storage._LegacyStorage {
19001
+ constructor(...args) {
19002
+ super(...args);
19003
+ this.dtype = torch.bool;
18652
19004
  }
18653
19005
  });
18654
- this.registerType('torch.ByteStorage', class extends torch.storage._StorageBase {
18655
- constructor(size) {
18656
- super(size, torch.uint8);
19006
+ this.registerType('torch.ByteStorage', class extends torch.storage._LegacyStorage {
19007
+ constructor(...args) {
19008
+ super(...args);
19009
+ this.dtype = torch.uint8;
18657
19010
  }
18658
19011
  });
18659
- this.registerType('torch.CharStorage', class extends torch.storage._StorageBase {
18660
- constructor(size) {
18661
- super(size, torch.int8);
19012
+ this.registerType('torch.CharStorage', class extends torch.storage._LegacyStorage {
19013
+ constructor(...args) {
19014
+ super(...args);
19015
+ this.dtype = torch.int8;
18662
19016
  }
18663
19017
  });
18664
- this.registerType('torch.ShortStorage', class extends torch.storage._StorageBase {
18665
- constructor(size) {
18666
- super(size, torch.int16);
19018
+ this.registerType('torch.ShortStorage', class extends torch.storage._LegacyStorage {
19019
+ constructor(...args) {
19020
+ super(...args);
19021
+ this.dtype = torch.int16;
18667
19022
  }
18668
19023
  });
18669
- this.registerType('torch.IntStorage', class extends torch.storage._StorageBase {
18670
- constructor(size) {
18671
- super(size, torch.int32);
19024
+ this.registerType('torch.IntStorage', class extends torch.storage._LegacyStorage {
19025
+ constructor(...args) {
19026
+ super(...args);
19027
+ this.dtype = torch.int32;
18672
19028
  }
18673
19029
  });
18674
- this.registerType('torch.LongStorage', class extends torch.storage._StorageBase {
18675
- constructor(size) {
18676
- super(size, torch.int64);
19030
+ this.registerType('torch.LongStorage', class extends torch.storage._LegacyStorage {
19031
+ constructor(...args) {
19032
+ super(...args);
19033
+ this.dtype = torch.int64;
18677
19034
  }
18678
19035
  });
18679
- this.registerType('torch.HalfStorage', class extends torch.storage._StorageBase {
18680
- constructor(size) {
18681
- super(size, torch.float16);
19036
+ this.registerType('torch.HalfStorage', class extends torch.storage._LegacyStorage {
19037
+ constructor(...args) {
19038
+ super(...args);
19039
+ this.dtype = torch.float16;
18682
19040
  }
18683
19041
  });
18684
- this.registerType('torch.FloatStorage', class extends torch.storage._StorageBase {
18685
- constructor(size) {
18686
- super(size, torch.float32);
19042
+ this.registerType('torch.FloatStorage', class extends torch.storage._LegacyStorage {
19043
+ constructor(...args) {
19044
+ super(...args);
19045
+ this.dtype = torch.float32;
18687
19046
  }
18688
19047
  });
18689
- this.registerType('torch.DoubleStorage', class extends torch.storage._StorageBase {
18690
- constructor(size) {
18691
- super(size, torch.float64);
19048
+ this.registerType('torch.DoubleStorage', class extends torch.storage._LegacyStorage {
19049
+ constructor(...args) {
19050
+ super(...args);
19051
+ this.dtype = torch.float64;
18692
19052
  }
18693
19053
  });
18694
- this.registerType('torch.ComplexHalfStorage', class extends torch.storage._StorageBase {
18695
- constructor(size) {
18696
- super(size, torch.complex32);
19054
+ this.registerType('torch.ComplexHalfStorage', class extends torch.storage._LegacyStorage {
19055
+ constructor(...args) {
19056
+ super(...args);
19057
+ this.dtype = torch.complex32;
18697
19058
  }
18698
19059
  });
18699
- this.registerType('torch.ComplexFloatStorage', class extends torch.storage._StorageBase {
18700
- constructor(size) {
18701
- super(size, torch.complex64);
19060
+ this.registerType('torch.ComplexFloatStorage', class extends torch.storage._LegacyStorage {
19061
+ constructor(...args) {
19062
+ super(...args);
19063
+ this.dtype = torch.complex64;
18702
19064
  }
18703
19065
  });
18704
- this.registerType('torch.ComplexDoubleStorage', class extends torch.storage._StorageBase {
18705
- constructor(size) {
18706
- super(size, torch.complex128);
19066
+ this.registerType('torch.ComplexDoubleStorage', class extends torch.storage._LegacyStorage {
19067
+ constructor(...args) {
19068
+ super(...args);
19069
+ this.dtype = torch.complex128;
18707
19070
  }
18708
19071
  });
18709
- this.registerType('torch.QInt8Storage', class extends torch.storage._StorageBase {
18710
- constructor(size) {
18711
- super(size, torch.qint8);
19072
+ this.registerType('torch.QInt8Storage', class extends torch.storage._LegacyStorage {
19073
+ constructor(...args) {
19074
+ super(...args);
19075
+ this.dtype = torch.qint8;
18712
19076
  }
18713
19077
  });
18714
- this.registerType('torch.QUInt8Storage', class extends torch.storage._StorageBase {
18715
- constructor(size) {
18716
- super(size, torch.quint8);
19078
+ this.registerType('torch.QUInt8Storage', class extends torch.storage._LegacyStorage {
19079
+ constructor(...args) {
19080
+ super(...args);
19081
+ this.dtype = torch.quint8;
18717
19082
  }
18718
19083
  });
18719
- this.registerType('torch.QInt32Storage', class extends torch.storage._StorageBase {
18720
- constructor(size) {
18721
- super(size, torch.qint32);
19084
+ this.registerType('torch.QInt32Storage', class extends torch.storage._LegacyStorage {
19085
+ constructor(...args) {
19086
+ super(...args);
19087
+ this.dtype = torch.qint32;
18722
19088
  }
18723
19089
  });
18724
- this.registerType('torch.BFloat16Storage', class extends torch.storage._StorageBase {
18725
- constructor(size) {
18726
- super(size, torch.bfloat16);
19090
+ this.registerType('torch.BFloat16Storage', class extends torch.storage._LegacyStorage {
19091
+ constructor(...args) {
19092
+ super(...args);
19093
+ this.dtype = torch.bfloat16;
18727
19094
  }
18728
19095
  });
18729
19096
  this.registerType('torch.Size', class extends Array {
@@ -18737,16 +19104,42 @@ python.Execution = class {
18737
19104
  return this.length;
18738
19105
  }
18739
19106
  });
18740
- this.registerType('torch.Tensor', class {
18741
- constructor() {
18742
- this._layout = torch.strided;
19107
+ this.registerType('torch._C.TensorMeta', class {
19108
+ });
19109
+ this.registerType('torch._C.TensorBase', class extends torch._C.TensorMeta {
19110
+ });
19111
+ this.registerType('torch.Tensor', class extends torch._C.TensorBase {
19112
+ constructor(storage, shape, dtype, layout, device, requires_grad) {
19113
+ super();
19114
+ if (storage) {
19115
+ this._storage = storage;
19116
+ }
19117
+ if (shape !== null && shape !== undefined) {
19118
+ this._shape = shape;
19119
+ }
19120
+ if (dtype) {
19121
+ this._dtype = dtype;
19122
+ }
19123
+ this._layout = layout || torch.strided;
19124
+ if (device) {
19125
+ this._device = device;
19126
+ }
19127
+ if (requires_grad !== undefined) {
19128
+ this.requires_grad = requires_grad;
19129
+ }
18743
19130
  }
18744
19131
  get device() {
19132
+ if (this._device !== undefined) {
19133
+ return this._device;
19134
+ }
18745
19135
  return this.storage().device;
18746
19136
  }
18747
19137
  get dtype() {
19138
+ if (this._dtype !== undefined) {
19139
+ return this._dtype;
19140
+ }
18748
19141
  if (this._layout === torch.sparse_coo) {
18749
- return this._values.dtype();
19142
+ return this._values.dtype;
18750
19143
  }
18751
19144
  return this.storage().dtype;
18752
19145
  }
@@ -18813,6 +19206,12 @@ python.Execution = class {
18813
19206
  throw new python.Error(`Unsupported tensor state length '${state.length}'.`);
18814
19207
  }
18815
19208
  }
19209
+ set_(source, storage_offset, size, stride) {
19210
+ this._storage = source;
19211
+ this._storage_offset = storage_offset;
19212
+ this._shape = size;
19213
+ this._stride = stride;
19214
+ }
18816
19215
  __bool__() {
18817
19216
  return true;
18818
19217
  }
@@ -18839,6 +19238,11 @@ python.Execution = class {
18839
19238
  __str__() {
18840
19239
  return 'tensor(...)';
18841
19240
  }
19241
+ static _make_wrapper_subclass(cls, size, stride, dtype, storage_offset, layout, device, requires_grad) {
19242
+ const t = new torch.Tensor(null, size, dtype, layout, device, requires_grad);
19243
+ t.__setstate__([null, storage_offset, size, stride]);
19244
+ return t;
19245
+ }
18842
19246
  });
18843
19247
  this.registerType('torch.nn.parameter.Parameter', class extends torch.Tensor {
18844
19248
  constructor(data, requires_grad) {
@@ -18874,6 +19278,13 @@ python.Execution = class {
18874
19278
  this.registerType('torch.cuda.DoubleStorage', class extends torch.cuda._CudaLegacyStorage {});
18875
19279
  this.registerType('torch.cuda.DoubleTensor', class extends torch.Tensor {});
18876
19280
  this.registerType('torch.cuda.amp.grad_scaler.GradScaler', class {});
19281
+ this.registerType('torchao.utils.TorchAOBaseTensor', class extends torch.Tensor {});
19282
+ this.registerType('torchao.dtypes.affine_quantized_tensor.AffineQuantizedTensor', class extends torchao.utils.TorchAOBaseTensor {});
19283
+ this.registerType('torchao.dtypes.utils.Layout', class {});
19284
+ this.registerType('torchao.dtypes.floatx.float8_layout.Float8Layout', class extends torchao.dtypes.utils.Layout {});
19285
+ this.registerType('torchao.dtypes.utils.AQTTensorImpl', class extends torchao.utils.TorchAOBaseTensor {});
19286
+ this.registerType('torchao.dtypes.floatx.float8_layout.Float8AQTTensorImpl', class extends torchao.dtypes.utils.AQTTensorImpl {});
19287
+ this.registerType('torchao.quantization.quant_primitives.ZeroPointDomain', class extends this.enum.Enum {});
18877
19288
  this.registerFunction('torch.cuda.amp.grad_scaler._refresh_per_optimizer_state');
18878
19289
  this.registerType('torch.SymBool', class {
18879
19290
  constructor(node) {
@@ -18977,7 +19388,7 @@ python.Execution = class {
18977
19388
  this.registerType('fastai.basic_train.Recorder', class {});
18978
19389
  this.registerFunction('fastai.torch_core._fa_rebuild_tensor', (cls, ...args) => {
18979
19390
  const tensor = torch._utils._rebuild_tensor_v2(...args);
18980
- return self.invoke(cls, tensor);
19391
+ return self.invoke(cls, [tensor]);
18981
19392
  });
18982
19393
  this.registerFunction('fastai.torch_core.trainable_params');
18983
19394
  this.registerFunction('fastai.torch_core._rebuild_from_type', (func, type, args, dict) => {
@@ -19000,7 +19411,7 @@ python.Execution = class {
19000
19411
  this.registerFunction('fastai.torch_core.uniform');
19001
19412
  this.registerType('fastai.callback.core.Callback', class extends fastcore.basics.GetAttr {});
19002
19413
  this.registerType('fastai.callback.core.TrainEvalCallback', class extends fastai.callback.core.Callback {});
19003
- this.registerType('fastai.callback.fp16.AMPMode', class extends this._enum.Enum {});
19414
+ this.registerType('fastai.callback.fp16.AMPMode', class extends this.enum.Enum {});
19004
19415
  this.registerType('fastai.callback.fp16.MixedPrecision', class {});
19005
19416
  this.registerFunction('fastai.callback.hook._hook_inner');
19006
19417
  this.registerType('fastai.callback.hook.Hook', class extends builtins.object {});
@@ -19101,6 +19512,7 @@ python.Execution = class {
19101
19512
  this.registerType('fastai.vision.augment.Brightness', class {});
19102
19513
  this.registerType('fastai.vision.augment.flip_mat', class {});
19103
19514
  this.registerType('fastai.vision.augment.Flip', class {});
19515
+ this.registerType('fastai.vision.augment.RandomResizedCrop', class {});
19104
19516
  this.registerType('fastai.vision.augment.RandomResizedCropGPU', class {});
19105
19517
  this.registerType('fastai.vision.augment.Resize', class {});
19106
19518
  this.registerType('fastai.vision.augment.rotate_mat', class {});
@@ -19400,7 +19812,9 @@ python.Execution = class {
19400
19812
  return this.expression(stmt.value, context);
19401
19813
  } else if (stmt instanceof ast.FunctionDef) {
19402
19814
  const module = context.get('__name__');
19815
+ /* eslint-disable consistent-this */
19403
19816
  const self = this;
19817
+ /* eslint-enable consistent-this */
19404
19818
  const parent = context.get('__class__');
19405
19819
  const type = (parent === builtins.module) ? builtins.function : builtins.method;
19406
19820
  const func = {
@@ -19415,7 +19829,7 @@ python.Execution = class {
19415
19829
  };
19416
19830
  context.set(stmt.name, func);
19417
19831
  } else if (stmt instanceof ast.ClassDef) {
19418
- const bases = stmt.bases.map((base) => this.expression(base, context));
19832
+ const bases = stmt.bases.map((base) => this.base(base, context));
19419
19833
  if (bases.length > 1) {
19420
19834
  throw new python.Error(`Unsupported multiple bases for class '${stmt.name}'.`);
19421
19835
  }
@@ -19682,6 +20096,10 @@ python.Execution = class {
19682
20096
  return undefined;
19683
20097
  }
19684
20098
 
20099
+ base(expr, context) {
20100
+ return this.expression(expr, context);
20101
+ }
20102
+
19685
20103
  identifier(expr) {
19686
20104
  const ast = this.ast;
19687
20105
  if (expr instanceof ast.Name) {