{"id":795,"date":"2021-01-05T01:50:58","date_gmt":"2021-01-04T17:50:58","guid":{"rendered":"https:\/\/byy3.com\/?p=795"},"modified":"2021-01-09T10:08:03","modified_gmt":"2021-01-09T02:08:03","slug":"python%e5%ba%93taichi%e5%a4%aa%e6%9e%81%e4%ba%ba%e5%b7%a5%e6%99%ba%e8%83%bdtensoflow%e5%9b%be%e5%bd%a2%e5%a4%84%e7%90%86","status":"publish","type":"post","link":"https:\/\/byy3.com\/?p=795","title":{"rendered":"python\u5e93taichi\u592a\u6781\u4eba\u5de5\u667a\u80fdtensoflow\u56fe\u5f62\u5904\u7406"},"content":{"rendered":"<p>Hello, world!<br \/>\nWe introduce the Taichi programming language through a very basic fractal example.<\/p>\n<p>Running the Taichi code below (python3 fractal.py or ti example fractal) will give you an animation of Julia set:<\/p>\n<p>https:\/\/github.com\/yuanming-hu\/public_files\/raw\/master\/graphics\/taichi\/fractal.gif<br \/>\n# fractal.py<\/p>\n<p>import taichi as ti<\/p>\n<p>ti.init(arch=ti.gpu)<\/p>\n<p>n = 320<br \/>\npixels = ti.field(dtype=float, shape=(n * 2, n))<\/p>\n<p>@ti.func<br \/>\ndef complex_sqr(z):<br \/>\nreturn ti.Vector([z[0]**2 - z[1]**2, z[1] * z[0] * 2])<\/p>\n<p>@ti.kernel<br \/>\ndef paint(t: float):<br \/>\nfor i, j in pixels: # Parallized over all pixels<br \/>\nc = ti.Vector([-0.8, ti.cos(t) * 0.2])<br \/>\nz = ti.Vector([i \/ n - 1, j \/ n - 0.5]) * 2<br \/>\niterations = 0<br \/>\nwhile z.norm() &lt; 20 and iterations &lt; 50:<br \/>\nz = complex_sqr(z) + c<br \/>\niterations += 1<br \/>\npixels[i, j] = 1 - iterations * 0.02<\/p>\n<p>gui = ti.GUI(\"Julia Set\", res=(n * 2, n))<\/p>\n<p>for i in range(1000000):<br \/>\npaint(i * 0.03)<br \/>\ngui.set_image(pixels)<br \/>\ngui.show()<\/p>\n<p>&nbsp;<\/p>\n<p>Taichi\uff08\u592a\u6781\uff090.7.1\u00a0\u5df2\u7ecf\u53d1\u5e03\uff0c\u8fd9\u662f\u4e13\u4e3a\u9ad8\u6027\u80fd\u8ba1\u7b97\u673a\u56fe\u5f62\u5b66\u8bbe\u8ba1\u7684\u7f16\u7a0b\u8bed\u8a00\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"zoom-in-cursor\" data-original=\"https:\/\/oscimg.oschina.net\/oscnet\/up-c2ef913d7be64d30991280a902891cc9348.gif\" src=\"https:\/\/byy3.com\/wp-content\/themes\/MNews%20V2.4\/images\/post-loading.gif\" width=\"500\" height=\"280\" title=\"python\u5e93taichi\u592a\u6781\u4eba\u5de5\u667a\u80fdtensoflow\u56fe\u5f62\u5904\u7406\u63d2\u56fe\" alt=\"python\u5e93taichi\u592a\u6781\u4eba\u5de5\u667a\u80fdtensoflow\u56fe\u5f62\u5904\u7406\u63d2\u56fe\" \/><\/p>\n<p>\u6b64\u7248\u672c\u5177\u4f53\u66f4\u65b0\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n<p><strong>Highlights<\/strong><\/p>\n<ul>\n<li><strong>Bug \u4fee\u590d<\/strong>\n<ul>\n<li>\u4fee\u590d\u4e00\u4e9b\u7f3a\u5c11\u7684 operator overrides\uff0c\u4f8b\u5982\u00a0<strong>rlshift\u3002<\/strong><\/li>\n<\/ul>\n<\/li>\n<li><strong>CUDA\u00a0<\/strong><strong>backend<\/strong>\n<ul>\n<li>\u652f\u6301\u00a0 NVIDIA RTX 3000 series GPUs<\/li>\n<\/ul>\n<\/li>\n<li><strong>Language and syntax<\/strong>\n<ul>\n<li>\u6dfb\u52a0 ti.loop_unique(val) \u4ee5\u6539\u5584\u00a0 atomics demotion<\/li>\n<\/ul>\n<\/li>\n<li><strong>Type system<\/strong>\n<ul>\n<li>\u5b9e\u73b0 is_primitive \u5e76\u91cd\u6784\u00a0primitive type equality check<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Hello, world! We introduce the Taichi programming langu [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[33,316,352,313,315,314],"class_list":["post-795","post","type-post","status-publish","format-standard","hentry","category-python","tag-python","tag-python-taichi","tag-taichi"],"_links":{"self":[{"href":"https:\/\/byy3.com\/index.php?rest_route=\/wp\/v2\/posts\/795","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/byy3.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/byy3.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/byy3.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/byy3.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=795"}],"version-history":[{"count":0,"href":"https:\/\/byy3.com\/index.php?rest_route=\/wp\/v2\/posts\/795\/revisions"}],"wp:attachment":[{"href":"https:\/\/byy3.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=795"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/byy3.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=795"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/byy3.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=795"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}