gstaichi 0.1.21.dev0__cp310-cp310-win_amd64.whl → 0.1.25.dev0__cp310-cp310-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.
- gstaichi/CHANGELOG.md +9 -0
- {taichi → gstaichi}/__init__.py +9 -13
- {taichi → gstaichi}/_funcs.py +8 -8
- {taichi → gstaichi}/_kernels.py +19 -19
- gstaichi/_lib/__init__.py +3 -0
- taichi/_lib/core/taichi_python.cp310-win_amd64.pyd → gstaichi/_lib/core/gstaichi_python.cp310-win_amd64.pyd +0 -0
- taichi/_lib/core/taichi_python.pyi → gstaichi/_lib/core/gstaichi_python.pyi +382 -522
- {taichi → gstaichi}/_lib/runtime/runtime_cuda.bc +0 -0
- {taichi → gstaichi}/_lib/runtime/runtime_x64.bc +0 -0
- {taichi → gstaichi}/_lib/utils.py +15 -15
- {taichi → gstaichi}/_logging.py +1 -1
- {taichi → gstaichi}/_main.py +24 -31
- gstaichi/_snode/__init__.py +5 -0
- {taichi → gstaichi}/_snode/fields_builder.py +27 -29
- {taichi → gstaichi}/_snode/snode_tree.py +5 -5
- gstaichi/_test_tools/__init__.py +0 -0
- gstaichi/_test_tools/load_kernel_string.py +30 -0
- gstaichi/_version.py +1 -0
- {taichi → gstaichi}/_version_check.py +8 -5
- gstaichi/ad/__init__.py +3 -0
- {taichi → gstaichi}/ad/_ad.py +26 -26
- {taichi → gstaichi}/algorithms/_algorithms.py +7 -7
- {taichi → gstaichi}/examples/minimal.py +1 -1
- {taichi → gstaichi}/experimental.py +1 -1
- gstaichi/lang/__init__.py +50 -0
- {taichi → gstaichi}/lang/_ndarray.py +30 -26
- {taichi → gstaichi}/lang/_ndrange.py +8 -8
- gstaichi/lang/_template_mapper.py +199 -0
- {taichi → gstaichi}/lang/_texture.py +19 -19
- {taichi → gstaichi}/lang/_wrap_inspect.py +7 -7
- {taichi → gstaichi}/lang/any_array.py +13 -13
- {taichi → gstaichi}/lang/argpack.py +29 -29
- gstaichi/lang/ast/__init__.py +5 -0
- {taichi → gstaichi}/lang/ast/ast_transformer.py +94 -582
- {taichi → gstaichi}/lang/ast/ast_transformer_utils.py +54 -41
- gstaichi/lang/ast/ast_transformers/__init__.py +0 -0
- gstaichi/lang/ast/ast_transformers/call_transformer.py +267 -0
- gstaichi/lang/ast/ast_transformers/function_def_transformer.py +320 -0
- {taichi → gstaichi}/lang/ast/checkers.py +5 -5
- gstaichi/lang/ast/transform.py +9 -0
- {taichi → gstaichi}/lang/common_ops.py +12 -12
- gstaichi/lang/exception.py +80 -0
- {taichi → gstaichi}/lang/expr.py +22 -22
- {taichi → gstaichi}/lang/field.py +29 -27
- {taichi → gstaichi}/lang/impl.py +116 -121
- {taichi → gstaichi}/lang/kernel_arguments.py +16 -16
- {taichi → gstaichi}/lang/kernel_impl.py +330 -363
- {taichi → gstaichi}/lang/matrix.py +119 -115
- {taichi → gstaichi}/lang/matrix_ops.py +6 -6
- {taichi → gstaichi}/lang/matrix_ops_utils.py +4 -4
- {taichi → gstaichi}/lang/mesh.py +22 -22
- {taichi → gstaichi}/lang/misc.py +39 -68
- {taichi → gstaichi}/lang/ops.py +146 -141
- {taichi → gstaichi}/lang/runtime_ops.py +2 -2
- {taichi → gstaichi}/lang/shell.py +3 -3
- {taichi → gstaichi}/lang/simt/__init__.py +1 -1
- {taichi → gstaichi}/lang/simt/block.py +7 -7
- {taichi → gstaichi}/lang/simt/grid.py +1 -1
- {taichi → gstaichi}/lang/simt/subgroup.py +1 -1
- {taichi → gstaichi}/lang/simt/warp.py +1 -1
- {taichi → gstaichi}/lang/snode.py +46 -44
- {taichi → gstaichi}/lang/source_builder.py +13 -13
- {taichi → gstaichi}/lang/struct.py +33 -33
- {taichi → gstaichi}/lang/util.py +24 -24
- gstaichi/linalg/__init__.py +8 -0
- {taichi → gstaichi}/linalg/matrixfree_cg.py +14 -14
- {taichi → gstaichi}/linalg/sparse_cg.py +10 -10
- {taichi → gstaichi}/linalg/sparse_matrix.py +23 -23
- {taichi → gstaichi}/linalg/sparse_solver.py +21 -21
- {taichi → gstaichi}/math/__init__.py +1 -1
- {taichi → gstaichi}/math/_complex.py +21 -20
- {taichi → gstaichi}/math/mathimpl.py +56 -56
- gstaichi/profiler/__init__.py +6 -0
- {taichi → gstaichi}/profiler/kernel_metrics.py +11 -11
- {taichi → gstaichi}/profiler/kernel_profiler.py +30 -36
- {taichi → gstaichi}/profiler/memory_profiler.py +1 -1
- {taichi → gstaichi}/profiler/scoped_profiler.py +2 -2
- {taichi → gstaichi}/sparse/_sparse_grid.py +7 -7
- {taichi → gstaichi}/tools/__init__.py +4 -4
- {taichi → gstaichi}/tools/diagnose.py +10 -17
- gstaichi/types/__init__.py +19 -0
- {taichi → gstaichi}/types/annotations.py +1 -1
- {taichi → gstaichi}/types/compound_types.py +8 -8
- {taichi → gstaichi}/types/enums.py +1 -1
- {taichi → gstaichi}/types/ndarray_type.py +7 -7
- {taichi → gstaichi}/types/primitive_types.py +17 -14
- {taichi → gstaichi}/types/quant.py +9 -9
- {taichi → gstaichi}/types/texture_type.py +5 -5
- {taichi → gstaichi}/types/utils.py +1 -1
- {gstaichi-0.1.21.dev0.data → gstaichi-0.1.25.dev0.data}/data/bin/SPIRV-Tools-shared.dll +0 -0
- {gstaichi-0.1.21.dev0.data → gstaichi-0.1.25.dev0.data}/data/lib/SPIRV-Tools-diff.lib +0 -0
- {gstaichi-0.1.21.dev0.data → gstaichi-0.1.25.dev0.data}/data/lib/SPIRV-Tools-link.lib +0 -0
- {gstaichi-0.1.21.dev0.data → gstaichi-0.1.25.dev0.data}/data/lib/SPIRV-Tools-lint.lib +0 -0
- {gstaichi-0.1.21.dev0.data → gstaichi-0.1.25.dev0.data}/data/lib/SPIRV-Tools-opt.lib +0 -0
- {gstaichi-0.1.21.dev0.data → gstaichi-0.1.25.dev0.data}/data/lib/SPIRV-Tools-reduce.lib +0 -0
- {gstaichi-0.1.21.dev0.data → gstaichi-0.1.25.dev0.data}/data/lib/SPIRV-Tools-shared.lib +0 -0
- {gstaichi-0.1.21.dev0.data → gstaichi-0.1.25.dev0.data}/data/lib/SPIRV-Tools.lib +0 -0
- {gstaichi-0.1.21.dev0.dist-info → gstaichi-0.1.25.dev0.dist-info}/METADATA +13 -16
- gstaichi-0.1.25.dev0.dist-info/RECORD +138 -0
- gstaichi-0.1.25.dev0.dist-info/entry_points.txt +2 -0
- gstaichi-0.1.25.dev0.dist-info/top_level.txt +1 -0
- gstaichi-0.1.21.dev0.data/data/include/GLFW/glfw3.h +0 -6389
- gstaichi-0.1.21.dev0.data/data/include/GLFW/glfw3native.h +0 -594
- gstaichi-0.1.21.dev0.data/data/lib/cmake/glfw3/glfw3Config.cmake +0 -3
- gstaichi-0.1.21.dev0.data/data/lib/cmake/glfw3/glfw3ConfigVersion.cmake +0 -65
- gstaichi-0.1.21.dev0.data/data/lib/cmake/glfw3/glfw3Targets-release.cmake +0 -19
- gstaichi-0.1.21.dev0.data/data/lib/cmake/glfw3/glfw3Targets.cmake +0 -107
- gstaichi-0.1.21.dev0.data/data/lib/glfw3.lib +0 -0
- gstaichi-0.1.21.dev0.dist-info/RECORD +0 -198
- gstaichi-0.1.21.dev0.dist-info/entry_points.txt +0 -2
- gstaichi-0.1.21.dev0.dist-info/top_level.txt +0 -1
- taichi/CHANGELOG.md +0 -17
- taichi/_lib/__init__.py +0 -3
- taichi/_lib/c_api/bin/taichi_c_api.dll +0 -0
- taichi/_lib/c_api/include/taichi/cpp/taichi.hpp +0 -1401
- taichi/_lib/c_api/include/taichi/taichi.h +0 -29
- taichi/_lib/c_api/include/taichi/taichi_core.h +0 -1111
- taichi/_lib/c_api/include/taichi/taichi_cpu.h +0 -29
- taichi/_lib/c_api/include/taichi/taichi_cuda.h +0 -36
- taichi/_lib/c_api/include/taichi/taichi_platform.h +0 -55
- taichi/_lib/c_api/include/taichi/taichi_unity.h +0 -64
- taichi/_lib/c_api/include/taichi/taichi_vulkan.h +0 -151
- taichi/_lib/c_api/lib/taichi_c_api.lib +0 -0
- taichi/_lib/c_api/runtime/runtime_cuda.bc +0 -0
- taichi/_lib/c_api/runtime/runtime_x64.bc +0 -0
- taichi/_lib/c_api/taichi/lib/cmake/taichi/TaichiConfig.cmake +0 -29
- taichi/_lib/c_api/taichi/lib/cmake/taichi/TaichiConfigVersion.cmake +0 -65
- taichi/_lib/c_api/taichi/lib/cmake/taichi/TaichiTargets.cmake +0 -121
- taichi/_lib/runtime/slim_libdevice.10.bc +0 -0
- taichi/_snode/__init__.py +0 -5
- taichi/_ti_module/__init__.py +0 -3
- taichi/_ti_module/cppgen.py +0 -309
- taichi/_ti_module/module.py +0 -145
- taichi/_version.py +0 -1
- taichi/ad/__init__.py +0 -3
- taichi/aot/__init__.py +0 -12
- taichi/aot/_export.py +0 -28
- taichi/aot/conventions/__init__.py +0 -3
- taichi/aot/conventions/gfxruntime140/__init__.py +0 -38
- taichi/aot/conventions/gfxruntime140/dr.py +0 -244
- taichi/aot/conventions/gfxruntime140/sr.py +0 -613
- taichi/aot/module.py +0 -253
- taichi/aot/utils.py +0 -151
- taichi/graph/__init__.py +0 -3
- taichi/graph/_graph.py +0 -292
- taichi/lang/__init__.py +0 -50
- taichi/lang/ast/__init__.py +0 -5
- taichi/lang/ast/transform.py +0 -9
- taichi/lang/exception.py +0 -80
- taichi/linalg/__init__.py +0 -8
- taichi/profiler/__init__.py +0 -6
- taichi/shaders/Circles_vk.frag +0 -29
- taichi/shaders/Circles_vk.vert +0 -45
- taichi/shaders/Circles_vk_frag.spv +0 -0
- taichi/shaders/Circles_vk_vert.spv +0 -0
- taichi/shaders/Lines_vk.frag +0 -9
- taichi/shaders/Lines_vk.vert +0 -11
- taichi/shaders/Lines_vk_frag.spv +0 -0
- taichi/shaders/Lines_vk_vert.spv +0 -0
- taichi/shaders/Mesh_vk.frag +0 -71
- taichi/shaders/Mesh_vk.vert +0 -68
- taichi/shaders/Mesh_vk_frag.spv +0 -0
- taichi/shaders/Mesh_vk_vert.spv +0 -0
- taichi/shaders/Particles_vk.frag +0 -95
- taichi/shaders/Particles_vk.vert +0 -73
- taichi/shaders/Particles_vk_frag.spv +0 -0
- taichi/shaders/Particles_vk_vert.spv +0 -0
- taichi/shaders/SceneLines2quad_vk_comp.spv +0 -0
- taichi/shaders/SceneLines_vk.frag +0 -9
- taichi/shaders/SceneLines_vk.vert +0 -12
- taichi/shaders/SceneLines_vk_frag.spv +0 -0
- taichi/shaders/SceneLines_vk_vert.spv +0 -0
- taichi/shaders/SetImage_vk.frag +0 -21
- taichi/shaders/SetImage_vk.vert +0 -15
- taichi/shaders/SetImage_vk_frag.spv +0 -0
- taichi/shaders/SetImage_vk_vert.spv +0 -0
- taichi/shaders/Triangles_vk.frag +0 -16
- taichi/shaders/Triangles_vk.vert +0 -29
- taichi/shaders/Triangles_vk_frag.spv +0 -0
- taichi/shaders/Triangles_vk_vert.spv +0 -0
- taichi/shaders/lines2quad_vk_comp.spv +0 -0
- taichi/types/__init__.py +0 -19
- {taichi → gstaichi}/__main__.py +0 -0
- {taichi → gstaichi}/_lib/core/__init__.py +0 -0
- {taichi → gstaichi}/_lib/core/py.typed +0 -0
- {taichi/_lib/c_api → gstaichi/_lib}/runtime/slim_libdevice.10.bc +0 -0
- {taichi → gstaichi}/algorithms/__init__.py +0 -0
- {taichi → gstaichi}/assets/.git +0 -0
- {taichi → gstaichi}/assets/Go-Regular.ttf +0 -0
- {taichi → gstaichi}/assets/static/imgs/ti_gallery.png +0 -0
- {taichi → gstaichi}/lang/ast/symbol_resolver.py +0 -0
- {taichi → gstaichi}/sparse/__init__.py +0 -0
- {taichi → gstaichi}/tools/np2ply.py +0 -0
- {taichi → gstaichi}/tools/vtk.py +0 -0
- {gstaichi-0.1.21.dev0.data → gstaichi-0.1.25.dev0.data}/data/SPIRV-Tools/cmake/SPIRV-ToolsConfig.cmake +0 -0
- {gstaichi-0.1.21.dev0.data → gstaichi-0.1.25.dev0.data}/data/SPIRV-Tools/cmake/SPIRV-ToolsTarget-release.cmake +0 -0
- {gstaichi-0.1.21.dev0.data → gstaichi-0.1.25.dev0.data}/data/SPIRV-Tools/cmake/SPIRV-ToolsTarget.cmake +0 -0
- {gstaichi-0.1.21.dev0.data → gstaichi-0.1.25.dev0.data}/data/SPIRV-Tools-diff/cmake/SPIRV-Tools-diffConfig.cmake +0 -0
- {gstaichi-0.1.21.dev0.data → gstaichi-0.1.25.dev0.data}/data/SPIRV-Tools-diff/cmake/SPIRV-Tools-diffTargets-release.cmake +0 -0
- {gstaichi-0.1.21.dev0.data → gstaichi-0.1.25.dev0.data}/data/SPIRV-Tools-diff/cmake/SPIRV-Tools-diffTargets.cmake +0 -0
- {gstaichi-0.1.21.dev0.data → gstaichi-0.1.25.dev0.data}/data/SPIRV-Tools-link/cmake/SPIRV-Tools-linkConfig.cmake +0 -0
- {gstaichi-0.1.21.dev0.data → gstaichi-0.1.25.dev0.data}/data/SPIRV-Tools-link/cmake/SPIRV-Tools-linkTargets-release.cmake +0 -0
- {gstaichi-0.1.21.dev0.data → gstaichi-0.1.25.dev0.data}/data/SPIRV-Tools-link/cmake/SPIRV-Tools-linkTargets.cmake +0 -0
- {gstaichi-0.1.21.dev0.data → gstaichi-0.1.25.dev0.data}/data/SPIRV-Tools-lint/cmake/SPIRV-Tools-lintConfig.cmake +0 -0
- {gstaichi-0.1.21.dev0.data → gstaichi-0.1.25.dev0.data}/data/SPIRV-Tools-lint/cmake/SPIRV-Tools-lintTargets-release.cmake +0 -0
- {gstaichi-0.1.21.dev0.data → gstaichi-0.1.25.dev0.data}/data/SPIRV-Tools-lint/cmake/SPIRV-Tools-lintTargets.cmake +0 -0
- {gstaichi-0.1.21.dev0.data → gstaichi-0.1.25.dev0.data}/data/SPIRV-Tools-opt/cmake/SPIRV-Tools-optConfig.cmake +0 -0
- {gstaichi-0.1.21.dev0.data → gstaichi-0.1.25.dev0.data}/data/SPIRV-Tools-opt/cmake/SPIRV-Tools-optTargets-release.cmake +0 -0
- {gstaichi-0.1.21.dev0.data → gstaichi-0.1.25.dev0.data}/data/SPIRV-Tools-opt/cmake/SPIRV-Tools-optTargets.cmake +0 -0
- {gstaichi-0.1.21.dev0.data → gstaichi-0.1.25.dev0.data}/data/SPIRV-Tools-reduce/cmake/SPIRV-Tools-reduceConfig.cmake +0 -0
- {gstaichi-0.1.21.dev0.data → gstaichi-0.1.25.dev0.data}/data/SPIRV-Tools-reduce/cmake/SPIRV-Tools-reduceTarget-release.cmake +0 -0
- {gstaichi-0.1.21.dev0.data → gstaichi-0.1.25.dev0.data}/data/SPIRV-Tools-reduce/cmake/SPIRV-Tools-reduceTarget.cmake +0 -0
- {gstaichi-0.1.21.dev0.data → gstaichi-0.1.25.dev0.data}/data/include/spirv-tools/instrument.hpp +0 -0
- {gstaichi-0.1.21.dev0.data → gstaichi-0.1.25.dev0.data}/data/include/spirv-tools/libspirv.h +0 -0
- {gstaichi-0.1.21.dev0.data → gstaichi-0.1.25.dev0.data}/data/include/spirv-tools/libspirv.hpp +0 -0
- {gstaichi-0.1.21.dev0.data → gstaichi-0.1.25.dev0.data}/data/include/spirv-tools/linker.hpp +0 -0
- {gstaichi-0.1.21.dev0.data → gstaichi-0.1.25.dev0.data}/data/include/spirv-tools/optimizer.hpp +0 -0
- {gstaichi-0.1.21.dev0.dist-info → gstaichi-0.1.25.dev0.dist-info}/WHEEL +0 -0
- {gstaichi-0.1.21.dev0.dist-info → gstaichi-0.1.25.dev0.dist-info}/licenses/LICENSE +0 -0
@@ -1,18 +1,18 @@
|
|
1
1
|
# type: ignore
|
2
2
|
|
3
|
-
from
|
3
|
+
from gstaichi._kernels import (
|
4
4
|
blit_from_field_to_field,
|
5
5
|
scan_add_inclusive,
|
6
6
|
sort_stage,
|
7
7
|
uniform_add,
|
8
8
|
warp_shfl_up_i32,
|
9
9
|
)
|
10
|
-
from
|
11
|
-
from
|
12
|
-
from
|
13
|
-
from
|
14
|
-
from
|
15
|
-
from
|
10
|
+
from gstaichi.lang.impl import current_cfg, field
|
11
|
+
from gstaichi.lang.kernel_impl import data_oriented
|
12
|
+
from gstaichi.lang.misc import cuda, vulkan
|
13
|
+
from gstaichi.lang.runtime_ops import sync
|
14
|
+
from gstaichi.lang.simt import subgroup
|
15
|
+
from gstaichi.types.primitive_types import i32
|
16
16
|
|
17
17
|
|
18
18
|
def parallel_sort(keys, values=None):
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# type: ignore
|
2
|
+
|
3
|
+
from gstaichi.lang import impl, simt
|
4
|
+
from gstaichi.lang._ndarray import *
|
5
|
+
from gstaichi.lang._ndrange import ndrange
|
6
|
+
from gstaichi.lang._texture import Texture
|
7
|
+
from gstaichi.lang.argpack import *
|
8
|
+
from gstaichi.lang.exception import *
|
9
|
+
from gstaichi.lang.field import *
|
10
|
+
from gstaichi.lang.impl import *
|
11
|
+
from gstaichi.lang.kernel_impl import *
|
12
|
+
from gstaichi.lang.matrix import *
|
13
|
+
from gstaichi.lang.mesh import *
|
14
|
+
from gstaichi.lang.misc import * # pylint: disable=W0622
|
15
|
+
from gstaichi.lang.ops import * # pylint: disable=W0622
|
16
|
+
from gstaichi.lang.runtime_ops import *
|
17
|
+
from gstaichi.lang.snode import *
|
18
|
+
from gstaichi.lang.source_builder import *
|
19
|
+
from gstaichi.lang.struct import *
|
20
|
+
from gstaichi.types.enums import DeviceCapability, Format, Layout
|
21
|
+
|
22
|
+
__all__ = [
|
23
|
+
s
|
24
|
+
for s in dir()
|
25
|
+
if not s.startswith("_")
|
26
|
+
and s
|
27
|
+
not in [
|
28
|
+
"any_array",
|
29
|
+
"ast",
|
30
|
+
"common_ops",
|
31
|
+
"enums",
|
32
|
+
"exception",
|
33
|
+
"expr",
|
34
|
+
"impl",
|
35
|
+
"inspect",
|
36
|
+
"kernel_arguments",
|
37
|
+
"kernel_impl",
|
38
|
+
"matrix",
|
39
|
+
"mesh",
|
40
|
+
"misc",
|
41
|
+
"ops",
|
42
|
+
"platform",
|
43
|
+
"runtime_ops",
|
44
|
+
"shell",
|
45
|
+
"snode",
|
46
|
+
"source_builder",
|
47
|
+
"struct",
|
48
|
+
"util",
|
49
|
+
]
|
50
|
+
]
|
@@ -1,19 +1,26 @@
|
|
1
1
|
# type: ignore
|
2
2
|
|
3
|
+
from typing import TYPE_CHECKING, Union
|
4
|
+
|
3
5
|
import numpy as np
|
4
6
|
|
5
|
-
from
|
6
|
-
from
|
7
|
-
from
|
8
|
-
from
|
9
|
-
from
|
10
|
-
from
|
11
|
-
from
|
12
|
-
from
|
7
|
+
from gstaichi._lib import core as _ti_core
|
8
|
+
from gstaichi.lang import impl
|
9
|
+
from gstaichi.lang.exception import GsTaichiIndexError
|
10
|
+
from gstaichi.lang.util import cook_dtype, get_traceback, python_scope, to_numpy_type
|
11
|
+
from gstaichi.types import primitive_types
|
12
|
+
from gstaichi.types.enums import Layout
|
13
|
+
from gstaichi.types.ndarray_type import NdarrayTypeMetadata
|
14
|
+
from gstaichi.types.utils import is_real, is_signed
|
15
|
+
|
16
|
+
if TYPE_CHECKING:
|
17
|
+
from gstaichi.lang.matrix import MatrixNdarray, VectorNdarray
|
18
|
+
|
19
|
+
TensorNdarray = Union["ScalarNdarray", VectorNdarray, MatrixNdarray]
|
13
20
|
|
14
21
|
|
15
22
|
class Ndarray:
|
16
|
-
"""
|
23
|
+
"""GsTaichi ndarray class.
|
17
24
|
|
18
25
|
Args:
|
19
26
|
dtype (DataType): Data type of each value.
|
@@ -27,7 +34,7 @@ class Ndarray:
|
|
27
34
|
self.dtype = None
|
28
35
|
self.arr = None
|
29
36
|
self.layout = Layout.AOS
|
30
|
-
self.grad = None
|
37
|
+
self.grad: "TensorNdarray | None" = None
|
31
38
|
|
32
39
|
def get_type(self):
|
33
40
|
return NdarrayTypeMetadata(self.element_type, self.shape, self.grad is not None)
|
@@ -91,7 +98,7 @@ class Ndarray:
|
|
91
98
|
numpy.ndarray: The result numpy array.
|
92
99
|
"""
|
93
100
|
arr = np.zeros(shape=self.arr.total_shape(), dtype=to_numpy_type(self.dtype))
|
94
|
-
from
|
101
|
+
from gstaichi._kernels import ndarray_to_ext_arr # pylint: disable=C0415
|
95
102
|
|
96
103
|
ndarray_to_ext_arr(self, arr)
|
97
104
|
impl.get_runtime().sync()
|
@@ -105,7 +112,7 @@ class Ndarray:
|
|
105
112
|
numpy.ndarray: The result numpy array.
|
106
113
|
"""
|
107
114
|
arr = np.zeros(shape=self.arr.total_shape(), dtype=to_numpy_type(self.dtype))
|
108
|
-
from
|
115
|
+
from gstaichi._kernels import ndarray_matrix_to_ext_arr # pylint: disable=C0415
|
109
116
|
|
110
117
|
layout_is_aos = 1
|
111
118
|
ndarray_matrix_to_ext_arr(self, arr, layout_is_aos, as_vector)
|
@@ -126,7 +133,7 @@ class Ndarray:
|
|
126
133
|
if not arr.flags.c_contiguous:
|
127
134
|
arr = np.ascontiguousarray(arr)
|
128
135
|
|
129
|
-
from
|
136
|
+
from gstaichi._kernels import ext_arr_to_ndarray # pylint: disable=C0415
|
130
137
|
|
131
138
|
ext_arr_to_ndarray(arr, self)
|
132
139
|
impl.get_runtime().sync()
|
@@ -147,7 +154,7 @@ class Ndarray:
|
|
147
154
|
if not arr.flags.c_contiguous:
|
148
155
|
arr = np.ascontiguousarray(arr)
|
149
156
|
|
150
|
-
from
|
157
|
+
from gstaichi._kernels import ext_arr_to_ndarray_matrix # pylint: disable=C0415
|
151
158
|
|
152
159
|
layout_is_aos = 1
|
153
160
|
ext_arr_to_ndarray_matrix(arr, self, layout_is_aos, as_vector)
|
@@ -182,12 +189,12 @@ class Ndarray:
|
|
182
189
|
"""
|
183
190
|
assert isinstance(other, Ndarray)
|
184
191
|
assert tuple(self.arr.shape) == tuple(other.arr.shape)
|
185
|
-
from
|
192
|
+
from gstaichi._kernels import ndarray_to_ndarray # pylint: disable=C0415
|
186
193
|
|
187
194
|
ndarray_to_ndarray(self, other)
|
188
195
|
impl.get_runtime().sync()
|
189
196
|
|
190
|
-
def _set_grad(self, grad):
|
197
|
+
def _set_grad(self, grad: "TensorNdarray"):
|
191
198
|
"""Sets the gradient ndarray.
|
192
199
|
|
193
200
|
Args:
|
@@ -218,7 +225,7 @@ class Ndarray:
|
|
218
225
|
if not isinstance(key, (tuple, list)):
|
219
226
|
key = (key,)
|
220
227
|
if len(key) != len(self.arr.total_shape()):
|
221
|
-
raise
|
228
|
+
raise GsTaichiIndexError(f"{len(self.arr.total_shape())}d ndarray indexed with {len(key)}d indices: {key}")
|
222
229
|
return key
|
223
230
|
|
224
231
|
@python_scope
|
@@ -230,7 +237,7 @@ class Ndarray:
|
|
230
237
|
|
231
238
|
|
232
239
|
class ScalarNdarray(Ndarray):
|
233
|
-
"""
|
240
|
+
"""GsTaichi ndarray with scalar elements.
|
234
241
|
|
235
242
|
Args:
|
236
243
|
dtype (DataType): Data type of each value.
|
@@ -247,13 +254,10 @@ class ScalarNdarray(Ndarray):
|
|
247
254
|
self.element_type = dtype
|
248
255
|
|
249
256
|
def __del__(self):
|
250
|
-
if (
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
and impl.get_runtime().prog is not None
|
255
|
-
):
|
256
|
-
impl.get_runtime().prog.delete_ndarray(self.arr)
|
257
|
+
if impl is not None and impl.get_runtime is not None and impl.get_runtime() is not None:
|
258
|
+
prog = impl.get_runtime()._prog
|
259
|
+
if prog is not None:
|
260
|
+
prog.delete_ndarray(self.arr)
|
257
261
|
|
258
262
|
@property
|
259
263
|
def element_shape(self):
|
@@ -283,7 +287,7 @@ class ScalarNdarray(Ndarray):
|
|
283
287
|
return ret_arr
|
284
288
|
|
285
289
|
def _fill_by_kernel(self, val):
|
286
|
-
from
|
290
|
+
from gstaichi._kernels import fill_ndarray # pylint: disable=C0415
|
287
291
|
|
288
292
|
fill_ndarray(self, val)
|
289
293
|
|
@@ -5,11 +5,11 @@ from typing import Iterable
|
|
5
5
|
|
6
6
|
import numpy as np
|
7
7
|
|
8
|
-
from
|
9
|
-
from
|
10
|
-
from
|
11
|
-
from
|
12
|
-
from
|
8
|
+
from gstaichi.lang import ops
|
9
|
+
from gstaichi.lang.exception import GsTaichiSyntaxError, GsTaichiTypeError
|
10
|
+
from gstaichi.lang.expr import Expr
|
11
|
+
from gstaichi.lang.matrix import Matrix
|
12
|
+
from gstaichi.types.utils import is_integral
|
13
13
|
|
14
14
|
|
15
15
|
class _Ndrange:
|
@@ -19,7 +19,7 @@ class _Ndrange:
|
|
19
19
|
if not isinstance(arg, collections.abc.Sequence):
|
20
20
|
args[i] = (0, arg)
|
21
21
|
if len(args[i]) != 2:
|
22
|
-
raise
|
22
|
+
raise GsTaichiSyntaxError(
|
23
23
|
"Every argument of ndrange should be a scalar or a tuple/list like (begin, end)"
|
24
24
|
)
|
25
25
|
args[i] = (args[i][0], ops.max(args[i][0], args[i][1]))
|
@@ -28,7 +28,7 @@ class _Ndrange:
|
|
28
28
|
if not isinstance(bound, (int, np.integer)) and not (
|
29
29
|
isinstance(bound, Expr) and is_integral(bound.ptr.get_rvalue_type())
|
30
30
|
):
|
31
|
-
raise
|
31
|
+
raise GsTaichiTypeError(
|
32
32
|
"Every argument of ndrange should be an integer scalar or a tuple/list of (int, int)"
|
33
33
|
)
|
34
34
|
self.bounds = args
|
@@ -129,7 +129,7 @@ def ndrange(*args) -> Iterable:
|
|
129
129
|
|
130
130
|
A typical usage of `ndrange` is when you want to loop over a tensor and process
|
131
131
|
its entries in parallel. You should avoid writing nested `for` loops here since
|
132
|
-
only top level `for` loops are paralleled in
|
132
|
+
only top level `for` loops are paralleled in gstaichi, instead you can use `ndrange`
|
133
133
|
to hold all entries in one top level loop:
|
134
134
|
|
135
135
|
>>> @ti.kernel
|
@@ -0,0 +1,199 @@
|
|
1
|
+
import dataclasses
|
2
|
+
import weakref
|
3
|
+
from typing import Any, Union
|
4
|
+
|
5
|
+
import gstaichi.lang
|
6
|
+
import gstaichi.lang._ndarray
|
7
|
+
import gstaichi.lang._texture
|
8
|
+
import gstaichi.lang.expr
|
9
|
+
import gstaichi.lang.snode
|
10
|
+
from gstaichi._lib import core as _ti_core
|
11
|
+
from gstaichi.lang.any_array import AnyArray
|
12
|
+
from gstaichi.lang.argpack import ArgPack, ArgPackType
|
13
|
+
from gstaichi.lang.exception import (
|
14
|
+
GsTaichiRuntimeTypeError,
|
15
|
+
)
|
16
|
+
from gstaichi.lang.kernel_arguments import KernelArgument
|
17
|
+
from gstaichi.lang.matrix import MatrixType
|
18
|
+
from gstaichi.lang.util import to_gstaichi_type
|
19
|
+
from gstaichi.types import (
|
20
|
+
ndarray_type,
|
21
|
+
sparse_matrix_builder,
|
22
|
+
template,
|
23
|
+
texture_type,
|
24
|
+
)
|
25
|
+
|
26
|
+
AnnotationType = Union[
|
27
|
+
template,
|
28
|
+
ArgPackType,
|
29
|
+
"texture_type.TextureType",
|
30
|
+
"texture_type.RWTextureType",
|
31
|
+
ndarray_type.NdarrayType,
|
32
|
+
sparse_matrix_builder,
|
33
|
+
Any,
|
34
|
+
]
|
35
|
+
|
36
|
+
|
37
|
+
class GsTaichiCallableTemplateMapper:
|
38
|
+
"""
|
39
|
+
This should probably be renamed to sometihng like FeatureMapper, or
|
40
|
+
FeatureExtractor, since:
|
41
|
+
- it's not specific to templates
|
42
|
+
- it extracts what are later called 'features', for example for ndarray this includes:
|
43
|
+
- element type
|
44
|
+
- number dimensions
|
45
|
+
- needs grad (or not)
|
46
|
+
- these are returned as a heterogeneous tuple, whose contents depends on the type
|
47
|
+
"""
|
48
|
+
|
49
|
+
def __init__(self, arguments: list[KernelArgument], template_slot_locations: list[int]) -> None:
|
50
|
+
self.arguments: list[KernelArgument] = arguments
|
51
|
+
self.num_args: int = len(arguments)
|
52
|
+
self.template_slot_locations: list[int] = template_slot_locations
|
53
|
+
self.mapping: dict[tuple[Any, ...], int] = {}
|
54
|
+
|
55
|
+
@staticmethod
|
56
|
+
def extract_arg(arg, annotation: AnnotationType, arg_name: str) -> Any:
|
57
|
+
if annotation == template or isinstance(annotation, template):
|
58
|
+
if isinstance(arg, gstaichi.lang.snode.SNode):
|
59
|
+
return arg.ptr
|
60
|
+
if isinstance(arg, gstaichi.lang.expr.Expr):
|
61
|
+
return arg.ptr.get_underlying_ptr_address()
|
62
|
+
if isinstance(arg, _ti_core.ExprCxx):
|
63
|
+
return arg.get_underlying_ptr_address()
|
64
|
+
if isinstance(arg, tuple):
|
65
|
+
return tuple(GsTaichiCallableTemplateMapper.extract_arg(item, annotation, arg_name) for item in arg)
|
66
|
+
if isinstance(arg, gstaichi.lang._ndarray.Ndarray):
|
67
|
+
raise GsTaichiRuntimeTypeError(
|
68
|
+
"Ndarray shouldn't be passed in via `ti.template()`, please annotate your kernel using `ti.types.ndarray(...)` instead"
|
69
|
+
)
|
70
|
+
|
71
|
+
if isinstance(arg, (list, tuple, dict, set)) or hasattr(arg, "_data_oriented"):
|
72
|
+
# [Composite arguments] Return weak reference to the object
|
73
|
+
# GsTaichi kernel will cache the extracted arguments, thus we can't simply return the original argument.
|
74
|
+
# Instead, a weak reference to the original value is returned to avoid memory leak.
|
75
|
+
|
76
|
+
# TODO(zhanlue): replacing "tuple(args)" with "hash of argument values"
|
77
|
+
# This can resolve the following issues:
|
78
|
+
# 1. Invalid weak-ref will leave a dead(dangling) entry in both caches: "self.mapping" and "self.compiled_functions"
|
79
|
+
# 2. Different argument instances with same type and same value, will get templatized into seperate kernels.
|
80
|
+
return weakref.ref(arg)
|
81
|
+
|
82
|
+
# [Primitive arguments] Return the value
|
83
|
+
return arg
|
84
|
+
if isinstance(annotation, ArgPackType):
|
85
|
+
if not isinstance(arg, ArgPack):
|
86
|
+
raise GsTaichiRuntimeTypeError(f"Argument {arg_name} must be a argument pack, got {type(arg)}")
|
87
|
+
return tuple(
|
88
|
+
GsTaichiCallableTemplateMapper.extract_arg(arg[name], dtype, arg_name)
|
89
|
+
for index, (name, dtype) in enumerate(annotation.members.items())
|
90
|
+
)
|
91
|
+
if dataclasses.is_dataclass(annotation):
|
92
|
+
_res_l = []
|
93
|
+
for field in dataclasses.fields(annotation):
|
94
|
+
field_value = getattr(arg, field.name)
|
95
|
+
arg_name = f"__ti_{arg_name}_{field.name}"
|
96
|
+
field_extracted = GsTaichiCallableTemplateMapper.extract_arg(field_value, field.type, arg_name)
|
97
|
+
_res_l.append(field_extracted)
|
98
|
+
return tuple(_res_l)
|
99
|
+
if isinstance(annotation, texture_type.TextureType):
|
100
|
+
if not isinstance(arg, gstaichi.lang._texture.Texture):
|
101
|
+
raise GsTaichiRuntimeTypeError(f"Argument {arg_name} must be a texture, got {type(arg)}")
|
102
|
+
if arg.num_dims != annotation.num_dimensions:
|
103
|
+
raise GsTaichiRuntimeTypeError(
|
104
|
+
f"TextureType dimension mismatch for argument {arg_name}: expected {annotation.num_dimensions}, got {arg.num_dims}"
|
105
|
+
)
|
106
|
+
return (arg.num_dims,)
|
107
|
+
if isinstance(annotation, texture_type.RWTextureType):
|
108
|
+
if not isinstance(arg, gstaichi.lang._texture.Texture):
|
109
|
+
raise GsTaichiRuntimeTypeError(f"Argument {arg_name} must be a texture, got {type(arg)}")
|
110
|
+
if arg.num_dims != annotation.num_dimensions:
|
111
|
+
raise GsTaichiRuntimeTypeError(
|
112
|
+
f"RWTextureType dimension mismatch for argument {arg_name}: expected {annotation.num_dimensions}, got {arg.num_dims}"
|
113
|
+
)
|
114
|
+
if arg.fmt != annotation.fmt:
|
115
|
+
raise GsTaichiRuntimeTypeError(
|
116
|
+
f"RWTextureType format mismatch for argument {arg_name}: expected {annotation.fmt}, got {arg.fmt}"
|
117
|
+
)
|
118
|
+
# (penguinliong) '0' is the assumed LOD level. We currently don't
|
119
|
+
# support mip-mapping.
|
120
|
+
return arg.num_dims, arg.fmt, 0
|
121
|
+
if isinstance(annotation, ndarray_type.NdarrayType):
|
122
|
+
if isinstance(arg, gstaichi.lang._ndarray.Ndarray):
|
123
|
+
annotation.check_matched(arg.get_type(), arg_name)
|
124
|
+
needs_grad = (arg.grad is not None) if annotation.needs_grad is None else annotation.needs_grad
|
125
|
+
assert arg.shape is not None
|
126
|
+
return arg.element_type, len(arg.shape), needs_grad, annotation.boundary
|
127
|
+
if isinstance(arg, AnyArray):
|
128
|
+
ty = arg.get_type()
|
129
|
+
annotation.check_matched(arg.get_type(), arg_name)
|
130
|
+
return ty.element_type, len(arg.shape), ty.needs_grad, annotation.boundary
|
131
|
+
# external arrays
|
132
|
+
shape = getattr(arg, "shape", None)
|
133
|
+
if shape is None:
|
134
|
+
raise GsTaichiRuntimeTypeError(f"Invalid type for argument {arg_name}, got {arg}")
|
135
|
+
shape = tuple(shape)
|
136
|
+
element_shape: tuple[int, ...] = ()
|
137
|
+
dtype = to_gstaichi_type(arg.dtype)
|
138
|
+
if isinstance(annotation.dtype, MatrixType):
|
139
|
+
if annotation.ndim is not None:
|
140
|
+
if len(shape) != annotation.dtype.ndim + annotation.ndim:
|
141
|
+
raise ValueError(
|
142
|
+
f"Invalid value for argument {arg_name} - required array has ndim={annotation.ndim} element_dim={annotation.dtype.ndim}, "
|
143
|
+
f"array with {len(shape)} dimensions is provided"
|
144
|
+
)
|
145
|
+
else:
|
146
|
+
if len(shape) < annotation.dtype.ndim:
|
147
|
+
raise ValueError(
|
148
|
+
f"Invalid value for argument {arg_name} - required element_dim={annotation.dtype.ndim}, "
|
149
|
+
f"array with {len(shape)} dimensions is provided"
|
150
|
+
)
|
151
|
+
element_shape = shape[-annotation.dtype.ndim :]
|
152
|
+
anno_element_shape = annotation.dtype.get_shape()
|
153
|
+
if None not in anno_element_shape and element_shape != anno_element_shape:
|
154
|
+
raise ValueError(
|
155
|
+
f"Invalid value for argument {arg_name} - required element_shape={anno_element_shape}, "
|
156
|
+
f"array with element shape of {element_shape} is provided"
|
157
|
+
)
|
158
|
+
elif annotation.dtype is not None:
|
159
|
+
# User specified scalar dtype
|
160
|
+
if annotation.dtype != dtype:
|
161
|
+
raise ValueError(
|
162
|
+
f"Invalid value for argument {arg_name} - required array has dtype={annotation.dtype.to_string()}, "
|
163
|
+
f"array with dtype={dtype.to_string()} is provided"
|
164
|
+
)
|
165
|
+
|
166
|
+
if annotation.ndim is not None and len(shape) != annotation.ndim:
|
167
|
+
raise ValueError(
|
168
|
+
f"Invalid value for argument {arg_name} - required array has ndim={annotation.ndim}, "
|
169
|
+
f"array with {len(shape)} dimensions is provided"
|
170
|
+
)
|
171
|
+
needs_grad = (
|
172
|
+
getattr(arg, "requires_grad", False) if annotation.needs_grad is None else annotation.needs_grad
|
173
|
+
)
|
174
|
+
element_type = (
|
175
|
+
_ti_core.get_type_factory_instance().get_tensor_type(element_shape, dtype)
|
176
|
+
if len(element_shape) != 0
|
177
|
+
else arg.dtype
|
178
|
+
)
|
179
|
+
return element_type, len(shape) - len(element_shape), needs_grad, annotation.boundary
|
180
|
+
if isinstance(annotation, sparse_matrix_builder):
|
181
|
+
return arg.dtype
|
182
|
+
# Use '#' as a placeholder because other kinds of arguments are not involved in template instantiation
|
183
|
+
return "#"
|
184
|
+
|
185
|
+
def extract(self, args: tuple[Any, ...]) -> tuple[Any, ...]:
|
186
|
+
extracted: list[Any] = []
|
187
|
+
for arg, kernel_arg in zip(args, self.arguments):
|
188
|
+
extracted.append(self.extract_arg(arg, kernel_arg.annotation, kernel_arg.name))
|
189
|
+
return tuple(extracted)
|
190
|
+
|
191
|
+
def lookup(self, args: tuple[Any, ...]) -> tuple[int, tuple[Any, ...]]:
|
192
|
+
if len(args) != self.num_args:
|
193
|
+
raise TypeError(f"{self.num_args} argument(s) needed but {len(args)} provided.")
|
194
|
+
|
195
|
+
key = self.extract(args)
|
196
|
+
if key not in self.mapping:
|
197
|
+
count = len(self.mapping)
|
198
|
+
self.mapping[key] = count
|
199
|
+
return self.mapping[key], key
|
@@ -2,13 +2,13 @@
|
|
2
2
|
|
3
3
|
import numpy as np
|
4
4
|
|
5
|
-
from
|
6
|
-
from
|
7
|
-
from
|
8
|
-
from
|
9
|
-
from
|
10
|
-
from
|
11
|
-
from
|
5
|
+
from gstaichi._lib import core as _ti_core
|
6
|
+
from gstaichi.lang import impl
|
7
|
+
from gstaichi.lang.expr import Expr, make_expr_group
|
8
|
+
from gstaichi.lang.matrix import Matrix
|
9
|
+
from gstaichi.lang.util import gstaichi_scope
|
10
|
+
from gstaichi.types import vector
|
11
|
+
from gstaichi.types.primitive_types import f32
|
12
12
|
|
13
13
|
|
14
14
|
def _get_entries(mat):
|
@@ -22,7 +22,7 @@ class TextureSampler:
|
|
22
22
|
self.ptr_expr = ptr_expr
|
23
23
|
self.num_dims = num_dims
|
24
24
|
|
25
|
-
@
|
25
|
+
@gstaichi_scope
|
26
26
|
def sample_lod(self, uv, lod):
|
27
27
|
ast_builder = impl.get_runtime().compiling_callable.ast_builder()
|
28
28
|
dbg_info = _ti_core.DebugInfo(impl.get_runtime().get_current_src_info())
|
@@ -34,7 +34,7 @@ class TextureSampler:
|
|
34
34
|
a = impl.call_internal("composite_extract_3", v, with_runtime_context=False)
|
35
35
|
return vector(4, f32)([r, g, b, a])
|
36
36
|
|
37
|
-
@
|
37
|
+
@gstaichi_scope
|
38
38
|
def fetch(self, index, lod):
|
39
39
|
ast_builder = impl.get_runtime().compiling_callable.ast_builder()
|
40
40
|
dbg_info = _ti_core.DebugInfo(impl.get_runtime().get_current_src_info())
|
@@ -49,11 +49,11 @@ class TextureSampler:
|
|
49
49
|
|
50
50
|
class RWTextureAccessor:
|
51
51
|
def __init__(self, ptr_expr, num_dims) -> None:
|
52
|
-
#
|
52
|
+
# gstaichi_python.TexturePtrExpression.
|
53
53
|
self.ptr_expr = ptr_expr
|
54
54
|
self.num_dims = num_dims
|
55
55
|
|
56
|
-
@
|
56
|
+
@gstaichi_scope
|
57
57
|
def load(self, index):
|
58
58
|
ast_builder = impl.get_runtime().compiling_callable.ast_builder()
|
59
59
|
dbg_info = _ti_core.DebugInfo(impl.get_runtime().get_current_src_info())
|
@@ -65,7 +65,7 @@ class RWTextureAccessor:
|
|
65
65
|
a = impl.call_internal("composite_extract_3", v, with_runtime_context=False)
|
66
66
|
return vector(4, f32)([r, g, b, a])
|
67
67
|
|
68
|
-
@
|
68
|
+
@gstaichi_scope
|
69
69
|
def store(self, index, value):
|
70
70
|
ast_builder = impl.get_runtime().compiling_callable.ast_builder()
|
71
71
|
dbg_info = _ti_core.DebugInfo(impl.get_runtime().get_current_src_info())
|
@@ -75,7 +75,7 @@ class RWTextureAccessor:
|
|
75
75
|
)
|
76
76
|
|
77
77
|
@property
|
78
|
-
@
|
78
|
+
@gstaichi_scope
|
79
79
|
def shape(self):
|
80
80
|
"""A list containing sizes for each dimension. Note that element shape will be excluded.
|
81
81
|
|
@@ -87,18 +87,18 @@ class RWTextureAccessor:
|
|
87
87
|
ret = [Expr(_ti_core.get_external_tensor_shape_along_axis(self.ptr_expr, i, dbg_info)) for i in range(dim)]
|
88
88
|
return ret
|
89
89
|
|
90
|
-
@
|
90
|
+
@gstaichi_scope
|
91
91
|
def _loop_range(self):
|
92
|
-
"""Gets the corresponding
|
92
|
+
"""Gets the corresponding gstaichi_python.Expr to serve as loop range.
|
93
93
|
|
94
94
|
Returns:
|
95
|
-
|
95
|
+
gstaichi_python.Expr: See above.
|
96
96
|
"""
|
97
97
|
return self.ptr_expr
|
98
98
|
|
99
99
|
|
100
100
|
class Texture:
|
101
|
-
"""
|
101
|
+
"""GsTaichi Texture class.
|
102
102
|
|
103
103
|
Args:
|
104
104
|
fmt (ti.Format): Color format of the texture.
|
@@ -148,7 +148,7 @@ class Texture:
|
|
148
148
|
# Don't use transpose method since its enums are too new
|
149
149
|
image = image.rotate(90, expand=True)
|
150
150
|
arr = np.asarray(image)
|
151
|
-
from
|
151
|
+
from gstaichi._kernels import ( # pylint: disable=import-outside-toplevel
|
152
152
|
load_texture_from_numpy,
|
153
153
|
)
|
154
154
|
|
@@ -164,7 +164,7 @@ class Texture:
|
|
164
164
|
from PIL import Image # pylint: disable=import-outside-toplevel
|
165
165
|
|
166
166
|
res = np.zeros(self.shape + (3,), np.uint8)
|
167
|
-
from
|
167
|
+
from gstaichi._kernels import ( # pylint: disable=import-outside-toplevel
|
168
168
|
save_texture_to_numpy,
|
169
169
|
)
|
170
170
|
|
@@ -1,19 +1,19 @@
|
|
1
1
|
# type: ignore
|
2
2
|
|
3
|
-
#
|
4
|
-
# This module is used by
|
3
|
+
# GsTaichi's custom inspect module.
|
4
|
+
# This module is used by GsTaichi's ast transformer to parse the source code.
|
5
5
|
# Currently this module is aimed for working in the following modes:
|
6
6
|
# 1. Usual Python/IPython mode, e.g. python script.py
|
7
7
|
# In this case we mainly rely on the built-in `inspect` module, except
|
8
8
|
# we need some hacks when we are in IPython mode and there is a cell magic.
|
9
|
-
# 2. Blender's scripting mode, e.g. Users write
|
9
|
+
# 2. Blender's scripting mode, e.g. Users write GsTaichi code in the scripting
|
10
10
|
# window in Blender and press the run button. In this case we need to
|
11
11
|
# retrieve the source using Blender's `bpy.data.texts` and write it to a temp
|
12
12
|
# file so that the inspect module can parse.
|
13
13
|
# 3. The interactive shell mode, e.g. Users directly type their code in the
|
14
14
|
# interactive shell. In this case we use `dill` to get the source.
|
15
15
|
#
|
16
|
-
# NB: Running
|
16
|
+
# NB: Running GsTaichi in other modes are likely not supported.
|
17
17
|
|
18
18
|
import atexit
|
19
19
|
import inspect
|
@@ -137,7 +137,7 @@ def _Python_IPython_findsource(obj):
|
|
137
137
|
pass
|
138
138
|
raise IOError(
|
139
139
|
f"Cannot find source code for Object: {obj}, it's likely \
|
140
|
-
you are not running
|
140
|
+
you are not running GsTaichi from command line or IPython."
|
141
141
|
)
|
142
142
|
|
143
143
|
|
@@ -158,9 +158,9 @@ def _custom_findsource(obj):
|
|
158
158
|
except:
|
159
159
|
raise IOError(
|
160
160
|
f"Cannot find source code for Object: {obj}, this \
|
161
|
-
is possibly because of you are running
|
161
|
+
is possibly because of you are running GsTaichi in an environment that GsTaichi's own \
|
162
162
|
inspect module cannot find the source. Please report an issue to help us fix: \
|
163
|
-
https://github.com/taichi-dev/
|
163
|
+
https://github.com/taichi-dev/gstaichi/issues"
|
164
164
|
)
|
165
165
|
|
166
166
|
|