gstaichi 0.1.18.dev1__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.
Files changed (198) hide show
  1. gstaichi-0.1.18.dev1.data/data/SPIRV-Tools/cmake/SPIRV-ToolsConfig.cmake +5 -0
  2. gstaichi-0.1.18.dev1.data/data/SPIRV-Tools/cmake/SPIRV-ToolsTarget-release.cmake +29 -0
  3. gstaichi-0.1.18.dev1.data/data/SPIRV-Tools/cmake/SPIRV-ToolsTarget.cmake +113 -0
  4. gstaichi-0.1.18.dev1.data/data/SPIRV-Tools-diff/cmake/SPIRV-Tools-diffConfig.cmake +5 -0
  5. gstaichi-0.1.18.dev1.data/data/SPIRV-Tools-diff/cmake/SPIRV-Tools-diffTargets-release.cmake +19 -0
  6. gstaichi-0.1.18.dev1.data/data/SPIRV-Tools-diff/cmake/SPIRV-Tools-diffTargets.cmake +122 -0
  7. gstaichi-0.1.18.dev1.data/data/SPIRV-Tools-link/cmake/SPIRV-Tools-linkConfig.cmake +5 -0
  8. gstaichi-0.1.18.dev1.data/data/SPIRV-Tools-link/cmake/SPIRV-Tools-linkTargets-release.cmake +19 -0
  9. gstaichi-0.1.18.dev1.data/data/SPIRV-Tools-link/cmake/SPIRV-Tools-linkTargets.cmake +122 -0
  10. gstaichi-0.1.18.dev1.data/data/SPIRV-Tools-lint/cmake/SPIRV-Tools-lintConfig.cmake +5 -0
  11. gstaichi-0.1.18.dev1.data/data/SPIRV-Tools-lint/cmake/SPIRV-Tools-lintTargets-release.cmake +19 -0
  12. gstaichi-0.1.18.dev1.data/data/SPIRV-Tools-lint/cmake/SPIRV-Tools-lintTargets.cmake +122 -0
  13. gstaichi-0.1.18.dev1.data/data/SPIRV-Tools-opt/cmake/SPIRV-Tools-optConfig.cmake +5 -0
  14. gstaichi-0.1.18.dev1.data/data/SPIRV-Tools-opt/cmake/SPIRV-Tools-optTargets-release.cmake +19 -0
  15. gstaichi-0.1.18.dev1.data/data/SPIRV-Tools-opt/cmake/SPIRV-Tools-optTargets.cmake +122 -0
  16. gstaichi-0.1.18.dev1.data/data/SPIRV-Tools-reduce/cmake/SPIRV-Tools-reduceConfig.cmake +5 -0
  17. gstaichi-0.1.18.dev1.data/data/SPIRV-Tools-reduce/cmake/SPIRV-Tools-reduceTarget-release.cmake +19 -0
  18. gstaichi-0.1.18.dev1.data/data/SPIRV-Tools-reduce/cmake/SPIRV-Tools-reduceTarget.cmake +122 -0
  19. gstaichi-0.1.18.dev1.data/data/bin/SPIRV-Tools-shared.dll +0 -0
  20. gstaichi-0.1.18.dev1.data/data/include/GLFW/glfw3.h +6389 -0
  21. gstaichi-0.1.18.dev1.data/data/include/GLFW/glfw3native.h +594 -0
  22. gstaichi-0.1.18.dev1.data/data/include/spirv-tools/instrument.hpp +268 -0
  23. gstaichi-0.1.18.dev1.data/data/include/spirv-tools/libspirv.h +907 -0
  24. gstaichi-0.1.18.dev1.data/data/include/spirv-tools/libspirv.hpp +375 -0
  25. gstaichi-0.1.18.dev1.data/data/include/spirv-tools/linker.hpp +97 -0
  26. gstaichi-0.1.18.dev1.data/data/include/spirv-tools/optimizer.hpp +970 -0
  27. gstaichi-0.1.18.dev1.data/data/lib/SPIRV-Tools-diff.lib +0 -0
  28. gstaichi-0.1.18.dev1.data/data/lib/SPIRV-Tools-link.lib +0 -0
  29. gstaichi-0.1.18.dev1.data/data/lib/SPIRV-Tools-lint.lib +0 -0
  30. gstaichi-0.1.18.dev1.data/data/lib/SPIRV-Tools-opt.lib +0 -0
  31. gstaichi-0.1.18.dev1.data/data/lib/SPIRV-Tools-reduce.lib +0 -0
  32. gstaichi-0.1.18.dev1.data/data/lib/SPIRV-Tools-shared.lib +0 -0
  33. gstaichi-0.1.18.dev1.data/data/lib/SPIRV-Tools.lib +0 -0
  34. gstaichi-0.1.18.dev1.data/data/lib/cmake/glfw3/glfw3Config.cmake +3 -0
  35. gstaichi-0.1.18.dev1.data/data/lib/cmake/glfw3/glfw3ConfigVersion.cmake +65 -0
  36. gstaichi-0.1.18.dev1.data/data/lib/cmake/glfw3/glfw3Targets-release.cmake +19 -0
  37. gstaichi-0.1.18.dev1.data/data/lib/cmake/glfw3/glfw3Targets.cmake +107 -0
  38. gstaichi-0.1.18.dev1.data/data/lib/glfw3.lib +0 -0
  39. gstaichi-0.1.18.dev1.dist-info/METADATA +108 -0
  40. gstaichi-0.1.18.dev1.dist-info/RECORD +198 -0
  41. gstaichi-0.1.18.dev1.dist-info/WHEEL +5 -0
  42. gstaichi-0.1.18.dev1.dist-info/entry_points.txt +2 -0
  43. gstaichi-0.1.18.dev1.dist-info/licenses/LICENSE +201 -0
  44. gstaichi-0.1.18.dev1.dist-info/top_level.txt +1 -0
  45. taichi/CHANGELOG.md +15 -0
  46. taichi/__init__.py +44 -0
  47. taichi/__main__.py +5 -0
  48. taichi/_funcs.py +706 -0
  49. taichi/_kernels.py +420 -0
  50. taichi/_lib/__init__.py +3 -0
  51. taichi/_lib/c_api/bin/taichi_c_api.dll +0 -0
  52. taichi/_lib/c_api/include/taichi/cpp/taichi.hpp +1401 -0
  53. taichi/_lib/c_api/include/taichi/taichi.h +29 -0
  54. taichi/_lib/c_api/include/taichi/taichi_core.h +1111 -0
  55. taichi/_lib/c_api/include/taichi/taichi_cpu.h +29 -0
  56. taichi/_lib/c_api/include/taichi/taichi_cuda.h +36 -0
  57. taichi/_lib/c_api/include/taichi/taichi_platform.h +55 -0
  58. taichi/_lib/c_api/include/taichi/taichi_unity.h +64 -0
  59. taichi/_lib/c_api/include/taichi/taichi_vulkan.h +151 -0
  60. taichi/_lib/c_api/lib/taichi_c_api.lib +0 -0
  61. taichi/_lib/c_api/runtime/runtime_cuda.bc +0 -0
  62. taichi/_lib/c_api/runtime/runtime_x64.bc +0 -0
  63. taichi/_lib/c_api/runtime/slim_libdevice.10.bc +0 -0
  64. taichi/_lib/c_api/taichi/lib/cmake/taichi/TaichiConfig.cmake +29 -0
  65. taichi/_lib/c_api/taichi/lib/cmake/taichi/TaichiConfigVersion.cmake +65 -0
  66. taichi/_lib/c_api/taichi/lib/cmake/taichi/TaichiTargets.cmake +121 -0
  67. taichi/_lib/core/__init__.py +0 -0
  68. taichi/_lib/core/py.typed +0 -0
  69. taichi/_lib/core/taichi_python.cp310-win_amd64.pyd +0 -0
  70. taichi/_lib/core/taichi_python.pyi +3077 -0
  71. taichi/_lib/runtime/runtime_cuda.bc +0 -0
  72. taichi/_lib/runtime/runtime_x64.bc +0 -0
  73. taichi/_lib/runtime/slim_libdevice.10.bc +0 -0
  74. taichi/_lib/utils.py +249 -0
  75. taichi/_logging.py +131 -0
  76. taichi/_main.py +552 -0
  77. taichi/_snode/__init__.py +5 -0
  78. taichi/_snode/fields_builder.py +189 -0
  79. taichi/_snode/snode_tree.py +34 -0
  80. taichi/_ti_module/__init__.py +3 -0
  81. taichi/_ti_module/cppgen.py +309 -0
  82. taichi/_ti_module/module.py +145 -0
  83. taichi/_version.py +1 -0
  84. taichi/_version_check.py +100 -0
  85. taichi/ad/__init__.py +3 -0
  86. taichi/ad/_ad.py +530 -0
  87. taichi/algorithms/__init__.py +3 -0
  88. taichi/algorithms/_algorithms.py +117 -0
  89. taichi/aot/__init__.py +12 -0
  90. taichi/aot/_export.py +28 -0
  91. taichi/aot/conventions/__init__.py +3 -0
  92. taichi/aot/conventions/gfxruntime140/__init__.py +38 -0
  93. taichi/aot/conventions/gfxruntime140/dr.py +244 -0
  94. taichi/aot/conventions/gfxruntime140/sr.py +613 -0
  95. taichi/aot/module.py +253 -0
  96. taichi/aot/utils.py +151 -0
  97. taichi/assets/.git +1 -0
  98. taichi/assets/Go-Regular.ttf +0 -0
  99. taichi/assets/static/imgs/ti_gallery.png +0 -0
  100. taichi/examples/minimal.py +28 -0
  101. taichi/experimental.py +16 -0
  102. taichi/graph/__init__.py +3 -0
  103. taichi/graph/_graph.py +292 -0
  104. taichi/lang/__init__.py +50 -0
  105. taichi/lang/_ndarray.py +348 -0
  106. taichi/lang/_ndrange.py +152 -0
  107. taichi/lang/_texture.py +172 -0
  108. taichi/lang/_wrap_inspect.py +189 -0
  109. taichi/lang/any_array.py +99 -0
  110. taichi/lang/argpack.py +411 -0
  111. taichi/lang/ast/__init__.py +5 -0
  112. taichi/lang/ast/ast_transformer.py +1806 -0
  113. taichi/lang/ast/ast_transformer_utils.py +328 -0
  114. taichi/lang/ast/checkers.py +106 -0
  115. taichi/lang/ast/symbol_resolver.py +57 -0
  116. taichi/lang/ast/transform.py +9 -0
  117. taichi/lang/common_ops.py +310 -0
  118. taichi/lang/exception.py +80 -0
  119. taichi/lang/expr.py +180 -0
  120. taichi/lang/field.py +464 -0
  121. taichi/lang/impl.py +1246 -0
  122. taichi/lang/kernel_arguments.py +157 -0
  123. taichi/lang/kernel_impl.py +1415 -0
  124. taichi/lang/matrix.py +1877 -0
  125. taichi/lang/matrix_ops.py +341 -0
  126. taichi/lang/matrix_ops_utils.py +190 -0
  127. taichi/lang/mesh.py +687 -0
  128. taichi/lang/misc.py +807 -0
  129. taichi/lang/ops.py +1489 -0
  130. taichi/lang/runtime_ops.py +13 -0
  131. taichi/lang/shell.py +35 -0
  132. taichi/lang/simt/__init__.py +5 -0
  133. taichi/lang/simt/block.py +94 -0
  134. taichi/lang/simt/grid.py +7 -0
  135. taichi/lang/simt/subgroup.py +191 -0
  136. taichi/lang/simt/warp.py +96 -0
  137. taichi/lang/snode.py +487 -0
  138. taichi/lang/source_builder.py +150 -0
  139. taichi/lang/struct.py +855 -0
  140. taichi/lang/util.py +381 -0
  141. taichi/linalg/__init__.py +8 -0
  142. taichi/linalg/matrixfree_cg.py +310 -0
  143. taichi/linalg/sparse_cg.py +59 -0
  144. taichi/linalg/sparse_matrix.py +303 -0
  145. taichi/linalg/sparse_solver.py +123 -0
  146. taichi/math/__init__.py +11 -0
  147. taichi/math/_complex.py +204 -0
  148. taichi/math/mathimpl.py +886 -0
  149. taichi/profiler/__init__.py +6 -0
  150. taichi/profiler/kernel_metrics.py +260 -0
  151. taichi/profiler/kernel_profiler.py +592 -0
  152. taichi/profiler/memory_profiler.py +15 -0
  153. taichi/profiler/scoped_profiler.py +36 -0
  154. taichi/shaders/Circles_vk.frag +29 -0
  155. taichi/shaders/Circles_vk.vert +45 -0
  156. taichi/shaders/Circles_vk_frag.spv +0 -0
  157. taichi/shaders/Circles_vk_vert.spv +0 -0
  158. taichi/shaders/Lines_vk.frag +9 -0
  159. taichi/shaders/Lines_vk.vert +11 -0
  160. taichi/shaders/Lines_vk_frag.spv +0 -0
  161. taichi/shaders/Lines_vk_vert.spv +0 -0
  162. taichi/shaders/Mesh_vk.frag +71 -0
  163. taichi/shaders/Mesh_vk.vert +68 -0
  164. taichi/shaders/Mesh_vk_frag.spv +0 -0
  165. taichi/shaders/Mesh_vk_vert.spv +0 -0
  166. taichi/shaders/Particles_vk.frag +95 -0
  167. taichi/shaders/Particles_vk.vert +73 -0
  168. taichi/shaders/Particles_vk_frag.spv +0 -0
  169. taichi/shaders/Particles_vk_vert.spv +0 -0
  170. taichi/shaders/SceneLines2quad_vk_comp.spv +0 -0
  171. taichi/shaders/SceneLines_vk.frag +9 -0
  172. taichi/shaders/SceneLines_vk.vert +12 -0
  173. taichi/shaders/SceneLines_vk_frag.spv +0 -0
  174. taichi/shaders/SceneLines_vk_vert.spv +0 -0
  175. taichi/shaders/SetImage_vk.frag +21 -0
  176. taichi/shaders/SetImage_vk.vert +15 -0
  177. taichi/shaders/SetImage_vk_frag.spv +0 -0
  178. taichi/shaders/SetImage_vk_vert.spv +0 -0
  179. taichi/shaders/Triangles_vk.frag +16 -0
  180. taichi/shaders/Triangles_vk.vert +29 -0
  181. taichi/shaders/Triangles_vk_frag.spv +0 -0
  182. taichi/shaders/Triangles_vk_vert.spv +0 -0
  183. taichi/shaders/lines2quad_vk_comp.spv +0 -0
  184. taichi/sparse/__init__.py +3 -0
  185. taichi/sparse/_sparse_grid.py +77 -0
  186. taichi/tools/__init__.py +12 -0
  187. taichi/tools/diagnose.py +124 -0
  188. taichi/tools/np2ply.py +364 -0
  189. taichi/tools/vtk.py +38 -0
  190. taichi/types/__init__.py +19 -0
  191. taichi/types/annotations.py +47 -0
  192. taichi/types/compound_types.py +90 -0
  193. taichi/types/enums.py +49 -0
  194. taichi/types/ndarray_type.py +147 -0
  195. taichi/types/primitive_types.py +203 -0
  196. taichi/types/quant.py +88 -0
  197. taichi/types/texture_type.py +85 -0
  198. taichi/types/utils.py +13 -0
@@ -0,0 +1,124 @@
1
+ # type: ignore
2
+
3
+ import locale
4
+ import os
5
+ import platform
6
+ import subprocess
7
+ import sys
8
+
9
+
10
+ def main():
11
+ print("Taichi system diagnose:")
12
+ print("")
13
+ executable = sys.executable
14
+
15
+ print(f"python: {sys.version}")
16
+ print(f"system: {sys.platform}")
17
+ print(f"executable: {executable}")
18
+ print(f"platform: {platform.platform()}")
19
+ print(f'architecture: {" ".join(platform.architecture())}')
20
+ print(f"uname: {platform.uname()}")
21
+
22
+ print(f'locale: {".".join(locale.getdefaultlocale())}')
23
+ print(f'PATH: {os.environ.get("PATH")}')
24
+ print(f"PYTHONPATH: {sys.path}")
25
+ print("")
26
+
27
+ try:
28
+ lsb_release = subprocess.check_output(["lsb_release", "-a"])
29
+ except Exception as e:
30
+ print(f"`lsb_release` not available: {e}")
31
+ else:
32
+ print(f"{lsb_release.decode()}")
33
+
34
+ for k, v in os.environ.items():
35
+ if k.startswith("TI_"):
36
+ print(f"{k}={v}")
37
+ print("")
38
+
39
+ def try_print(tag, expr):
40
+ try:
41
+ cmd = f'import taichi as ti; print("===="); print({expr}, end="")'
42
+ ret = subprocess.check_output([executable, "-c", cmd]).decode()
43
+ ret = ret.split("====" + os.linesep, maxsplit=1)[1]
44
+ print(f"{tag}: {ret}")
45
+ except Exception as e:
46
+ print(f"{tag}: ERROR {e}")
47
+
48
+ print("")
49
+ try_print("import", "ti")
50
+ print("")
51
+ for arch in ["cpu", "metal", "opengl", "cuda", "vulkan"]:
52
+ try_print(arch, f"ti.lang.misc.is_arch_supported(ti.{arch})")
53
+ print("")
54
+
55
+ try:
56
+ glewinfo = subprocess.check_output(["glewinfo"])
57
+ except Exception as e:
58
+ print(f"`glewinfo` not available: {e}")
59
+ else:
60
+ for line in glewinfo.decode().splitlines():
61
+ if line.startswith("OpenGL version"):
62
+ print(line)
63
+ continue
64
+
65
+ exts = [
66
+ "GL_ARB_compute_shader",
67
+ "GL_ARB_gpu_shader_int64",
68
+ "GL_NV_shader_atomic_float",
69
+ "GL_NV_shader_atomic_float64",
70
+ "GL_NV_shader_atomic_int64",
71
+ ]
72
+ if line.split(":")[0] in exts:
73
+ print(line)
74
+
75
+ print("")
76
+ try:
77
+ nvidia_smi = subprocess.check_output(["nvidia-smi"])
78
+ except Exception as e:
79
+ print(f"`nvidia-smi` not available: {e}")
80
+ else:
81
+ print(f"{nvidia_smi.decode()}")
82
+
83
+ try:
84
+ ti_header = subprocess.check_output([executable, "-c", "import taichi"])
85
+ except Exception as e:
86
+ print(f"`import taichi` failed: {e}")
87
+ else:
88
+ print(f"{ti_header.decode()}")
89
+
90
+ try:
91
+ ti_init_test = subprocess.check_output([executable, "-c", "import taichi as ti; ti.init()"])
92
+ except Exception as e:
93
+ print(f"`ti.init()` failed: {e}")
94
+ else:
95
+ print(f"{ti_init_test.decode()}")
96
+
97
+ try:
98
+ ti_opengl_test = subprocess.check_output([executable, "-c", "import taichi as ti; ti.init(arch=ti.opengl)"])
99
+ except Exception as e:
100
+ print(f"Taichi OpenGL test failed: {e}")
101
+ else:
102
+ print(f"{ti_opengl_test.decode()}")
103
+
104
+ try:
105
+ ti_cuda_test = subprocess.check_output([executable, "-c", "import taichi as ti; ti.init(arch=ti.cuda)"])
106
+ except Exception as e:
107
+ print(f"Taichi CUDA test failed: {e}")
108
+ else:
109
+ print(f"{ti_cuda_test.decode()}")
110
+
111
+ try:
112
+ ti_laplace = subprocess.check_output([executable, "-m", "taichi", "example", "minimal"])
113
+ except Exception as e:
114
+ print(f"`python/taichi/examples/algorithm/laplace.py` failed: {e}")
115
+ else:
116
+ print(f"{ti_laplace.decode()}")
117
+
118
+ print("Consider attaching this log when maintainers ask about system information.")
119
+
120
+
121
+ if __name__ == "__main__":
122
+ main()
123
+
124
+ __all__ = []
taichi/tools/np2ply.py ADDED
@@ -0,0 +1,364 @@
1
+ # type: ignore
2
+
3
+ # convert numpy array to ply files
4
+ import sys
5
+
6
+ import numpy as np
7
+
8
+
9
+ class PLYWriter:
10
+ """Writes `numpy.array` data to `ply` files.
11
+
12
+ Args:
13
+ num_vertices (int): number of vertices.
14
+ num_faces (int, optional): number of faces.
15
+ face_type (str): `tri` or `quad`.
16
+ comment (str): comment message.
17
+ """
18
+
19
+ def __init__(
20
+ self,
21
+ num_vertices: int,
22
+ num_faces=0,
23
+ face_type="tri",
24
+ comment="created by PLYWriter",
25
+ ):
26
+ assert num_vertices > 0, "num_vertices should be greater than 0"
27
+ assert num_faces >= 0, "num_faces shouldn't be less than 0"
28
+ assert face_type == "tri" or face_type == "quad", "Only tri and quad faces are supported for now"
29
+
30
+ self.ply_supported_types = [
31
+ "char",
32
+ "uchar",
33
+ "short",
34
+ "ushort",
35
+ "int",
36
+ "uint",
37
+ "float",
38
+ "double",
39
+ ]
40
+ self.corresponding_numpy_types = [
41
+ np.int8,
42
+ np.uint8,
43
+ np.int16,
44
+ np.uint16,
45
+ np.int32,
46
+ np.uint32,
47
+ np.float32,
48
+ np.float64,
49
+ ]
50
+ self.type_map = {}
51
+ for i, ply_type in enumerate(self.ply_supported_types):
52
+ self.type_map[ply_type] = self.corresponding_numpy_types[i]
53
+
54
+ self.num_vertices = num_vertices
55
+ self.num_vertex_channels = 0
56
+ self.vertex_channels = []
57
+ self.vertex_data_type = []
58
+ self.vertex_data = []
59
+ self.num_faces = num_faces
60
+ self.num_face_channels = 0
61
+ self.face_channels = []
62
+ self.face_data_type = []
63
+ self.face_data = []
64
+ self.face_type = face_type
65
+ if face_type == "tri":
66
+ self.face_indices = -np.ones((self.num_faces, 3), dtype=np.int32)
67
+ elif face_type == "quad":
68
+ self.face_indices = -np.ones((self.num_faces, 4), dtype=np.int32)
69
+ self.comment = comment
70
+
71
+ def add_vertex_channel(self, key: str, data_type: str, data: np.array):
72
+ if data_type not in self.ply_supported_types:
73
+ print("Unknown type " + data_type + " detected, skipping this channel")
74
+ return
75
+ if data.ndim == 1:
76
+ assert data.size == self.num_vertices, "The dimension of the vertex channel is not correct"
77
+ self.num_vertex_channels += 1
78
+ if key in self.vertex_channels:
79
+ print("WARNING: duplicate key " + key + " detected")
80
+ self.vertex_channels.append(key)
81
+ self.vertex_data_type.append(data_type)
82
+ self.vertex_data.append(self.type_map[data_type](data))
83
+ else:
84
+ num_col = data.size // self.num_vertices
85
+ assert (
86
+ data.ndim == 2 and data.size == num_col * self.num_vertices
87
+ ), "The dimension of the vertex channel is not correct"
88
+ data.shape = (self.num_vertices, num_col)
89
+ self.num_vertex_channels += num_col
90
+ for i in range(num_col):
91
+ item_key = key + "_" + str(i + 1)
92
+ if item_key in self.vertex_channels:
93
+ print("WARNING: duplicate key " + item_key + " detected")
94
+ self.vertex_channels.append(item_key)
95
+ self.vertex_data_type.append(data_type)
96
+ self.vertex_data.append(self.type_map[data_type](data[:, i]))
97
+
98
+ def add_vertex_pos(self, x: np.array, y: np.array, z: np.array):
99
+ """Set the (x, y, z) coordinates of the vertices.
100
+
101
+ Args:
102
+ x (`numpy.array(float)`): x-coordinates of the vertices.
103
+ y (`numpy.array(float)`): y-coordinates of the vertices.
104
+ z (`numpy.array(float)`): z-coordinates of the vertices.
105
+ """
106
+ self.add_vertex_channel("x", "float", x)
107
+ self.add_vertex_channel("y", "float", y)
108
+ self.add_vertex_channel("z", "float", z)
109
+
110
+ # TODO active and refactor later if user feedback indicates the necessity for a compact the input list
111
+ # pass ti vector/matrix field directly
112
+ # def add_vertex_pos(self, pos):
113
+ # assert isinstance(pos, (np.ndarray, ti.Matrix))
114
+ # if not isinstance(pos, np.ndarray):
115
+ # pos = pos.to_numpy()
116
+ # dim = pos.shape[pos.ndim-1]
117
+ # assert dim == 2 or dim == 3, "Only 2D and 3D positions are supported"
118
+ # n = pos.size // dim
119
+ # assert n == self.num_vertices, "Size of the input is not correct"
120
+ # pos = np.reshape(pos, (n, dim))
121
+ # self.add_vertex_channel("x", "float", pos[:, 0])
122
+ # self.add_vertex_channel("y", "float", pos[:, 1])
123
+ # if(dim == 3):
124
+ # self.add_vertex_channel("z", "float", pos[:, 2])
125
+ # if(dim == 2):
126
+ # self.add_vertex_channel("z", "float", np.zeros(n))
127
+
128
+ def add_vertex_normal(self, nx: np.array, ny: np.array, nz: np.array):
129
+ """Add normal vectors at the vertices.
130
+
131
+ The three arguments are all numpy arrays of float type and have
132
+ the same length.
133
+
134
+ Args:
135
+ nx (`numpy.array(float)`): x-coordinates of the normal vectors.
136
+ ny (`numpy.array(float)`): y-coordinates of the normal vectors.
137
+ nz (`numpy.array(float)`): z-coordinates of the normal vectors.
138
+ """
139
+ self.add_vertex_channel("nx", "float", nx)
140
+ self.add_vertex_channel("ny", "float", ny)
141
+ self.add_vertex_channel("nz", "float", nz)
142
+
143
+ # TODO active and refactor later if user feedback indicates the necessity for a compact the input list
144
+ # pass ti vector/matrix field directly
145
+ # def add_vertex_normal(self, normal):
146
+ # assert isinstance(normal, (np.ndarray, ti.Matrix))
147
+ # if not isinstance(normal, np.ndarray):
148
+ # normal = normal.to_numpy()
149
+ # dim = normal.shape[normal.ndim-1]
150
+ # assert dim == 3, "Only 3D normal is supported"
151
+ # n = normal.size // dim
152
+ # assert n == self.num_vertices, "Size of the input is not correct"
153
+ # normal = np.reshape(normal, (n, dim))
154
+ # self.add_vertex_channel("nx", "float", normal[:, 0])
155
+ # self.add_vertex_channel("ny", "float", normal[:, 1])
156
+ # self.add_vertex_channel("nz", "float", normal[:, 2])
157
+
158
+ def add_vertex_vel(self, vx: np.array, vy: np.array, vz: np.array):
159
+ """Add velocity vectors at the vertices.
160
+
161
+ Args:
162
+ vx (`numpy.array(float)`): x-coordinates of the velocity vectors.
163
+ vy (`numpy.array(float)`): y-coordinates of the velocity vectors.
164
+ vz (`numpy.array(float)`): z-coordinates of the velocity vectors.
165
+ """
166
+ self.add_vertex_channel("vx", "float", vx)
167
+ self.add_vertex_channel("vy", "float", vy)
168
+ self.add_vertex_channel("vz", "float", vz)
169
+
170
+ def add_vertex_color(self, r: np.array, g: np.array, b: np.array):
171
+ """Sets the (r, g, b) channels of the colors at the vertices.
172
+
173
+ The three arguments are all numpy arrays of float type and have
174
+ the same length.
175
+
176
+ Args:
177
+ r (`numpy.array(float)`): the r-channel (red) of the colors.
178
+ g (`numpy.array(float)`): the g-channel (green) of the color.
179
+ b (`numpy.array(float)`): the b-channel (blue) of the colors.
180
+ """
181
+ self.add_vertex_channel("red", "float", r)
182
+ self.add_vertex_channel("green", "float", g)
183
+ self.add_vertex_channel("blue", "float", b)
184
+
185
+ def add_vertex_alpha(self, alpha: np.array):
186
+ """Sets the alpha-channel (transparent) of the vertex colors.
187
+
188
+ Args:
189
+ alpha (`numpy.array(float)`): the alpha-channel (transparent) of the colors.
190
+ """
191
+ self.add_vertex_channel("Alpha", "float", alpha)
192
+
193
+ def add_vertex_rgba(self, r: np.array, g: np.array, b: np.array, a: np.array):
194
+ """Sets the (r, g, b, a) channels of the colors at the vertices.
195
+
196
+ Args:
197
+ r (`numpy.array(float)`): the r-channel (red) of the colors.
198
+ g (`numpy.array(float)`): the g-channel (green) of the color.
199
+ b (`numpy.array(float)`): the b-channel (blue) of the colors.
200
+ a (`numpy.array(float)`): the a-channel (alpha) of the colors.
201
+ """
202
+ self.add_vertex_channel("red", "float", r)
203
+ self.add_vertex_channel("green", "float", g)
204
+ self.add_vertex_channel("blue", "float", b)
205
+ self.add_vertex_channel("Alpha", "float", a)
206
+
207
+ # TODO active and refactor later if user feedback indicates the necessity for a compact the input list
208
+ # pass ti vector/matrix field directly
209
+ # def add_vertex_color(self, color):
210
+ # assert isinstance(color, (np.ndarray, ti.Matrix))
211
+ # if not isinstance(color, np.ndarray):
212
+ # color = color.to_numpy()
213
+ # channels = color.shape[color.ndim-1]
214
+ # assert channels == 3 or channels == 4, "The dimension for color should be either be 3 (rgb) or 4 (rgba)"
215
+ # n = color.size // channels
216
+ # assert n == self.num_vertices, "Size of the input is not correct"
217
+ # color = np.reshape(color, (n, channels))
218
+ # self.add_vertex_channel("red", "float", color[:, 0])
219
+ # self.add_vertex_channel("green", "float", color[:, 1])
220
+ # self.add_vertex_channel("blue", "float", color[:, 2])
221
+ # if channels == 4:
222
+ # self.add_vertex_channel("Alpha", "float", color[:, 3])
223
+
224
+ def add_vertex_id(self):
225
+ """Sets the ids of the vertices.
226
+
227
+ The id of a vertex is equal to its index in the vertex array.
228
+ """
229
+ self.add_vertex_channel("id", "int", np.arange(self.num_vertices))
230
+
231
+ def add_vertex_piece(self, piece: np.array):
232
+ self.add_vertex_channel("piece", "int", piece)
233
+
234
+ def add_faces(self, indices: np.array):
235
+ if self.face_type == "tri":
236
+ vert_per_face = 3
237
+ else:
238
+ vert_per_face = 4
239
+ assert vert_per_face * self.num_faces == indices.size, "The dimension of the face vertices is not correct"
240
+ self.face_indices = np.reshape(indices, (self.num_faces, vert_per_face))
241
+ self.face_indices = self.face_indices.astype(np.int32)
242
+
243
+ def add_face_channel(self, key: str, data_type: str, data: np.array):
244
+ if data_type not in self.ply_supported_types:
245
+ print("Unknown type " + data_type + " detected, skipping this channel")
246
+ return
247
+ if data.ndim == 1:
248
+ assert data.size == self.num_faces, "The dimension of the face channel is not correct"
249
+ self.num_face_channels += 1
250
+ if key in self.face_channels:
251
+ print("WARNING: duplicate key " + key + " detected")
252
+ self.face_channels.append(key)
253
+ self.face_data_type.append(data_type)
254
+ self.face_data.append(self.type_map[data_type](data))
255
+ else:
256
+ num_col = data.size // self.num_faces
257
+ assert (
258
+ data.ndim == 2 and data.size == num_col * self.num_faces
259
+ ), "The dimension of the face channel is not correct"
260
+ data.shape = (self.num_faces, num_col)
261
+ self.num_face_channels += num_col
262
+ for i in range(num_col):
263
+ item_key = key + "_" + str(i + 1)
264
+ if item_key in self.face_channels:
265
+ print("WARNING: duplicate key " + item_key + " detected")
266
+ self.face_channels.append(item_key)
267
+ self.face_data_type.append(data_type)
268
+ self.face_data.append(self.type_map[data_type](data[:, i]))
269
+
270
+ def add_face_id(self):
271
+ self.add_face_channel("id", "int", np.arange(self.num_faces))
272
+
273
+ def add_face_piece(self, piece: np.array):
274
+ self.add_face_channel("piece", "int", piece)
275
+
276
+ def sanity_check(self):
277
+ assert "x" in self.vertex_channels, "The vertex pos channel is missing"
278
+ assert "y" in self.vertex_channels, "The vertex pos channel is missing"
279
+ assert "z" in self.vertex_channels, "The vertex pos channel is missing"
280
+ if self.num_faces > 0:
281
+ for idx in self.face_indices.flatten():
282
+ assert idx >= 0 and idx < self.num_vertices, "The face indices are invalid"
283
+
284
+ def print_header(self, path: str, _format: str):
285
+ with open(path, "w") as f:
286
+ f.writelines(
287
+ [
288
+ "ply\n",
289
+ "format " + _format + " 1.0\n",
290
+ "comment " + self.comment + "\n",
291
+ ]
292
+ )
293
+ f.write("element vertex " + str(self.num_vertices) + "\n")
294
+ for i in range(self.num_vertex_channels):
295
+ f.write("property " + self.vertex_data_type[i] + " " + self.vertex_channels[i] + "\n")
296
+ if self.num_faces != 0:
297
+ f.write("element face " + str(self.num_faces) + "\n")
298
+ f.write("property list uchar int vertex_indices\n")
299
+ for i in range(self.num_face_channels):
300
+ f.write("property " + self.face_data_type[i] + " " + self.face_channels[i] + "\n")
301
+ f.write("end_header\n")
302
+
303
+ def export(self, path):
304
+ self.sanity_check()
305
+ self.print_header(path, "binary_" + sys.byteorder + "_endian")
306
+ with open(path, "ab") as f:
307
+ for i in range(self.num_vertices):
308
+ for j in range(self.num_vertex_channels):
309
+ f.write(self.vertex_data[j][i])
310
+ if self.face_type == "tri":
311
+ vert_per_face = np.uint8(3)
312
+ else:
313
+ vert_per_face = np.uint8(4)
314
+ for i in range(self.num_faces):
315
+ f.write(vert_per_face)
316
+ for j in range(vert_per_face):
317
+ f.write(self.face_indices[i, j])
318
+ for j in range(self.num_face_channels):
319
+ f.write(self.face_data[j][i])
320
+
321
+ def export_ascii(self, path):
322
+ self.sanity_check()
323
+ self.print_header(path, "ascii")
324
+ with open(path, "a") as f:
325
+ for i in range(self.num_vertices):
326
+ for j in range(self.num_vertex_channels):
327
+ f.write(str(self.vertex_data[j][i]) + " ")
328
+ f.write("\n")
329
+ if self.face_type == "tri":
330
+ vert_per_face = 3
331
+ else:
332
+ vert_per_face = 4
333
+ for i in range(self.num_faces):
334
+ f.writelines(
335
+ [
336
+ str(vert_per_face) + " ",
337
+ " ".join(map(str, self.face_indices[i, :])),
338
+ " ",
339
+ ]
340
+ )
341
+ for j in range(self.num_face_channels):
342
+ f.write(str(self.face_data[j][i]) + " ")
343
+ f.write("\n")
344
+
345
+ def export_frame_ascii(self, series_num: int, path: str):
346
+ # if path has ply ending
347
+ last_4_char = path[-4:]
348
+ if last_4_char == ".ply":
349
+ path = path[:-4]
350
+
351
+ real_path = path + "_" + f"{series_num:0=6d}" + ".ply"
352
+ self.export_ascii(real_path)
353
+
354
+ def export_frame(self, series_num: int, path: str):
355
+ # if path has ply ending
356
+ last_4_char = path[-4:]
357
+ if last_4_char == ".ply":
358
+ path = path[:-4]
359
+
360
+ real_path = path + "_" + f"{series_num:0=6d}" + ".ply"
361
+ self.export(real_path)
362
+
363
+
364
+ __all__ = ["PLYWriter"]
taichi/tools/vtk.py ADDED
@@ -0,0 +1,38 @@
1
+ # type: ignore
2
+
3
+ import numpy as np
4
+
5
+
6
+ def write_vtk(scalar_field, filename):
7
+ try:
8
+ from pyevtk.hl import gridToVTK # pylint: disable=import-outside-toplevel
9
+ except ImportError:
10
+ raise RuntimeError(
11
+ "Failed to import pyevtk. Please install it via /\
12
+ `pip install pyevtk` first. "
13
+ )
14
+
15
+ scalar_field_np = scalar_field.to_numpy()
16
+ field_shape = scalar_field_np.shape
17
+ dimensions = len(field_shape)
18
+
19
+ if dimensions not in (2, 3):
20
+ raise ValueError("The input field must be a 2D or 3D scalar field.")
21
+
22
+ if dimensions == 2:
23
+ scalar_field_np = scalar_field_np[np.newaxis, :, :]
24
+ zcoords = np.array([0, 1])
25
+ elif dimensions == 3:
26
+ zcoords = np.arange(0, field_shape[2])
27
+ else:
28
+ raise ValueError("dimensions should be 2 or 3")
29
+ gridToVTK(
30
+ filename,
31
+ x=np.arange(0, field_shape[0]),
32
+ y=np.arange(0, field_shape[1]),
33
+ z=zcoords,
34
+ cellData={filename: scalar_field_np},
35
+ )
36
+
37
+
38
+ __all__ = ["write_vtk"]
@@ -0,0 +1,19 @@
1
+ # type: ignore
2
+
3
+ """
4
+ This module defines data types in Taichi:
5
+
6
+ - primitive: int, float, etc.
7
+ - compound: matrix, vector, struct.
8
+ - template: for reference types.
9
+ - ndarray: for arbitrary arrays.
10
+ - quant: for quantized types, see "https://yuanming.taichi.graphics/publication/2021-quantaichi/quantaichi.pdf"
11
+ """
12
+
13
+ from taichi.types import quant
14
+ from taichi.types.annotations import *
15
+ from taichi.types.compound_types import *
16
+ from taichi.types.ndarray_type import *
17
+ from taichi.types.primitive_types import *
18
+ from taichi.types.texture_type import *
19
+ from taichi.types.utils import *
@@ -0,0 +1,47 @@
1
+ # type: ignore
2
+
3
+
4
+ class Template:
5
+ """Type annotation for template kernel parameter.
6
+ Useful for passing parameters to kernels by reference.
7
+
8
+ See also https://docs.taichi-lang.org/docs/meta.
9
+
10
+ Args:
11
+ tensor (Any): unused
12
+ dim (Any): unused
13
+
14
+ Example::
15
+
16
+ >>> a = 1
17
+ >>>
18
+ >>> @ti.kernel
19
+ >>> def test():
20
+ >>> print(a)
21
+ >>>
22
+ >>> @ti.kernel
23
+ >>> def test_template(a: ti.template()):
24
+ >>> print(a)
25
+ >>>
26
+ >>> test(a) # will print 1
27
+ >>> test_template(a) # will also print 1
28
+ >>> a = 2
29
+ >>> test(a) # will still print 1
30
+ >>> test_template(a) # will print 2
31
+ """
32
+
33
+ def __init__(self, tensor=None, dim=None):
34
+ self.tensor = tensor
35
+ self.dim = dim
36
+
37
+
38
+ template = Template
39
+ """Alias for :class:`~taichi.types.annotations.Template`.
40
+ """
41
+
42
+
43
+ class sparse_matrix_builder:
44
+ pass
45
+
46
+
47
+ __all__ = ["template", "sparse_matrix_builder", "Template"]
@@ -0,0 +1,90 @@
1
+ # type: ignore
2
+
3
+ import taichi
4
+ from taichi._lib.utils import ti_python_core as _ti_python_core
5
+
6
+ _type_factory = _ti_python_core.get_type_factory_instance()
7
+
8
+
9
+ class CompoundType:
10
+ def from_kernel_struct_ret(self, launch_ctx, index: tuple):
11
+ raise NotImplementedError()
12
+
13
+
14
+ # TODO: maybe move MatrixType, StructType here to avoid the circular import?
15
+ def matrix(n=None, m=None, dtype=None):
16
+ """Creates a matrix type with given shape and data type.
17
+
18
+ Args:
19
+ n (int): number of rows of the matrix.
20
+ m (int): number of columns of the matrix.
21
+ dtype (:mod:`~taichi.types.primitive_types`): matrix data type.
22
+
23
+ Returns:
24
+ A matrix type.
25
+
26
+ Example::
27
+
28
+ >>> mat2x2 = ti.types.matrix(2, 2, ti.f32) # 2x2 matrix type
29
+ >>> M = mat2x2([[1., 2.], [3., 4.]]) # an instance of this type
30
+ """
31
+ return taichi.lang.matrix.MatrixType(n, m, 2, dtype)
32
+
33
+
34
+ def vector(n=None, dtype=None):
35
+ """Creates a vector type with given shape and data type.
36
+
37
+ Args:
38
+ n (int): dimension of the vector.
39
+ dtype (:mod:`~taichi.types.primitive_types`): vector data type.
40
+
41
+ Returns:
42
+ A vector type.
43
+
44
+ Example::
45
+
46
+ >>> vec3 = ti.types.vector(3, ti.f32) # 3d vector type
47
+ >>> v = vec3([1., 2., 3.]) # an instance of this type
48
+ """
49
+ return taichi.lang.matrix.VectorType(n, dtype)
50
+
51
+
52
+ def struct(**kwargs):
53
+ """Creates a struct type with given members.
54
+
55
+ Args:
56
+ kwargs (dict): a dictionary contains the names and types of the
57
+ struct members.
58
+
59
+ Returns:
60
+ A struct type.
61
+
62
+ Example::
63
+
64
+ >>> vec3 = ti.types.vector(3, ti.f32)
65
+ >>> sphere = ti.types.struct(center=vec3, radius=float)
66
+ >>> s = sphere(center=vec3([0., 0., 0.]), radius=1.0)
67
+ """
68
+ return taichi.lang.struct.StructType(**kwargs)
69
+
70
+
71
+ def argpack(**kwargs):
72
+ """Creates an argument pack type with given members.
73
+
74
+ Args:
75
+ kwargs (dict): a dictionary contains the names and types of the
76
+ argument pack members.
77
+
78
+ Returns:
79
+ A argument pack type.
80
+
81
+ Example::
82
+
83
+ >>> vec3 = ti.types.vector(3, ti.f32)
84
+ >>> sphere = ti.types.argpack(center=vec3, radius=float)
85
+ >>> s = sphere(center=vec3([0., 0., 0.]), radius=1.0)
86
+ """
87
+ return taichi.lang.argpack.ArgPackType(**kwargs)
88
+
89
+
90
+ __all__ = ["matrix", "vector", "struct", "argpack"]