text
stringlengths
24
1.04M
metadata
stringlengths
233
497
### File: towr_ros/bash/play_all.sh #!/bin/bash #title :Plays back all rosbag files in a specific folder #author :Alexander W. Winkler # change to directory where the script is stored so relative paths are correct my_dir="$(dirname "$0")" cd $my_dir speed=1.0 video_folder=$my_dir/video1/* for bag_file in $...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Shell", "repo_name": "minhanghuang/towr", "path": "towr_ros/bash/play_all.sh", "license": "bsd-3-clause", "size": 593}
### File: towr_ros/bash/playbag.sh #!/bin/bash #title :Plays back rosbag files of optimization iterations #author :Alexander W. Winkler # change to directory where the script is stored to relative paths are correct my_dir="$(dirname "$0")" cd $my_dir speed=2.0 # publish the optimization parameters, b...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Shell", "repo_name": "minhanghuang/towr", "path": "towr_ros/bash/playbag.sh", "license": "bsd-3-clause", "size": 845}
### File: towr_ros/bash/remap_bag.sh #!/bin/bash #title :Remaps xpp/state_des in a bag file to another name #input :the name of the bag file #author :Alexander W. Winkler new_topic_name=xpp/state_curr bag_file=$1 rosrun rosbag topic_renamer.py xpp/state_des ${bag_file}.bag $new_topic_name ${bag_...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Shell", "repo_name": "minhanghuang/towr", "path": "towr_ros/bash/remap_bag.sh", "license": "bsd-3-clause", "size": 328}
### File: towr_ros/include/towr_ros/topic_names.h /****************************************************************************** Copyright (c) 2018, Alexander W. Winkler. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following con...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/towr", "path": "towr_ros/include/towr_ros/topic_names.h", "license": "bsd-3-clause", "size": 2212}
### File: towr_ros/include/towr_ros/towr_ros_interface.h /****************************************************************************** Copyright (c) 2018, Alexander W. Winkler. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the follow...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/towr", "path": "towr_ros/include/towr_ros/towr_ros_interface.h", "license": "bsd-3-clause", "size": 4656}
### File: towr_ros/include/towr_ros/towr_user_interface.h /****************************************************************************** Copyright (c) 2018, Alexander W. Winkler. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the follo...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/towr", "path": "towr_ros/include/towr_ros/towr_user_interface.h", "license": "bsd-3-clause", "size": 3033}
### File: towr_ros/include/towr_ros/towr_xpp_ee_map.h /****************************************************************************** Copyright (c) 2017, Alexander W. Winkler. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/towr", "path": "towr_ros/include/towr_ros/towr_xpp_ee_map.h", "license": "bsd-3-clause", "size": 4018}
### File: towr_ros/msg/TowrCommand.msg # The command for the robot specified by the user xpp_msgs/StateLin3d goal_lin # the linear state to reach (x,y,z and derivatives) xpp_msgs/StateLin3d goal_ang # the angular state to reach (roll, pitch, yaw and derivatives) float64 ...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "omnetpp-msg", "repo_name": "minhanghuang/towr", "path": "towr_ros/msg/TowrCommand.msg", "license": "bsd-3-clause", "size": 1193}
### File: towr_ros/src/goal_pose_publisher.cc /****************************************************************************** Copyright (c) 2018, Alexander W. Winkler. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditi...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/towr", "path": "towr_ros/src/goal_pose_publisher.cc", "license": "bsd-3-clause", "size": 3172}
### File: towr_ros/src/rosbag_geom_msg_extractor.cc /****************************************************************************** Copyright (c) 2018, Alexander W. Winkler. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following c...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/towr", "path": "towr_ros/src/rosbag_geom_msg_extractor.cc", "license": "bsd-3-clause", "size": 3569}
### File: towr_ros/src/rosbag_traj_combiner.cc /****************************************************************************** Copyright (c) 2018, Alexander W. Winkler. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following condit...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/towr", "path": "towr_ros/src/rosbag_traj_combiner.cc", "license": "bsd-3-clause", "size": 4237}
### File: towr_ros/src/rviz_terrain_publisher.cc /****************************************************************************** Copyright (c) 2018, Alexander W. Winkler. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following cond...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/towr", "path": "towr_ros/src/rviz_terrain_publisher.cc", "license": "bsd-3-clause", "size": 3795}
### File: towr_ros/src/towr_ros_app.cc /****************************************************************************** Copyright (c) 2018, Alexander W. Winkler. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/towr", "path": "towr_ros/src/towr_ros_app.cc", "license": "bsd-3-clause", "size": 5183}
### File: towr_ros/src/towr_ros_interface.cc /****************************************************************************** Copyright (c) 2018, Alexander W. Winkler. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditio...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/towr", "path": "towr_ros/src/towr_ros_interface.cc", "license": "bsd-3-clause", "size": 9710}
### File: towr_ros/src/towr_user_interface.cc /****************************************************************************** Copyright (c) 2018, Alexander W. Winkler. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditi...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/towr", "path": "towr_ros/src/towr_user_interface.cc", "license": "bsd-3-clause", "size": 10549}
### File: .travis/install.sh #!/bin/bash # use brew & pyenv to build specific python on osx if [[ $TRAVIS_OS_NAME == 'osx' ]]; then export PATH="$HOME/.pyenv/bin:$PATH" eval "${MATRIX_EVAL}" echo "python version: $PYTHON_VERSION" brew update > /dev/null brew upgrade pyenv # use pyenv to build p...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Shell", "repo_name": "minhanghuang/Taichi", "path": ".travis/install.sh", "license": "mit", "size": 411}
### File: CMakeLists.txt #********************************************************************* # The Taichi Programming Language #********************************************************************* cmake_minimum_required(VERSION 3.12) project(taichi) SET(TI_VERSION_MAJOR 0) SET(TI_VERSION_MINOR 7) SET(TI_VERSION_...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "CMake", "repo_name": "minhanghuang/Taichi", "path": "CMakeLists.txt", "license": "mit", "size": 2664}
### File: Dockerfile # Taichi Dockerfile for development FROM nvidia/cuda:10.0-devel-ubuntu18.04 LABEL maintainer="https://github.com/taichi-dev" # This installs Python 3.6.9 by default. Once the # docker image is upgraded to Ubuntu 20.04 this will # install Python 3.8 by default RUN apt-get update && \ apt-get i...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Dockerfile", "repo_name": "minhanghuang/Taichi", "path": "Dockerfile", "license": "mit", "size": 2220}
### File: benchmarks/async_advection.py import math from utils import benchmark_async import taichi as ti # TODO: staggerred grid @benchmark_async def simple_advection(scale): n = 256 * 2**int((math.log(scale, 2)) // 2) x = ti.Vector.field(3, dtype=ti.f32, shape=(n, n)) new_x = ti.Vector.field(3, dtype...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "benchmarks/async_advection.py", "license": "mit", "size": 3075}
### File: benchmarks/async_cases.py import math import os import sys import taichi as ti sys.path.append(os.path.join(ti.core.get_repo_dir(), 'tests', 'python')) from fuse_test_template import (template_fuse_dense_x2y2z, template_fuse_reduction) from utils import * @benchmark_async ...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "benchmarks/async_cases.py", "license": "mit", "size": 11336}
### File: benchmarks/benchmark_async.py from async_advection import * from async_cases import * import taichi as ti rerun = True cases = [ chain_copy, increments, fill_array, sparse_saxpy, autodiff, stencil_reduction, mpm_splitted, simple_advection, multires, deep_hierarchy ] if rerun: for c in cases: ...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "benchmarks/benchmark_async.py", "license": "mit", "size": 1079}
### File: benchmarks/fill_dense.py import taichi as ti # originally by @KLozes @ti.all_archs def benchmark_flat_struct(): N = 4096 a = ti.field(dtype=ti.f32, shape=(N, N)) @ti.kernel def fill(): for i, j in a: a[i, j] = 2.0 return ti.benchmark(fill, repeat=500) @ti.all_arc...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "benchmarks/fill_dense.py", "license": "mit", "size": 2482}
### File: benchmarks/fill_sparse.py import taichi as ti @ti.archs_support_sparse def benchmark_nested_struct(): a = ti.field(dtype=ti.f32) N = 512 ti.root.pointer(ti.ij, [N, N]).dense(ti.ij, [8, 8]).place(a) @ti.kernel def fill(): for i, j in ti.ndrange(N * 8, N * 8): a[i, j]...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "benchmarks/fill_sparse.py", "license": "mit", "size": 830}
### File: benchmarks/memory_bound.py import taichi as ti N = 1024**3 // 4 # 1 GB per buffer # 4 B/it @ti.archs_excluding(ti.opengl) def benchmark_memset(): a = ti.field(dtype=ti.f32, shape=N) @ti.kernel def memset(): for i in a: a[i] = 1.0 return ti.benchmark(memset, repeat=10)...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "benchmarks/memory_bound.py", "license": "mit", "size": 1116}
### File: benchmarks/minimal.py import taichi as ti @ti.all_archs def benchmark_fill_scalar(): a = ti.field(dtype=ti.f32, shape=()) @ti.kernel def fill(): a[None] = 1.0 return ti.benchmark(fill, repeat=1000)
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "benchmarks/minimal.py", "license": "mit", "size": 204}
### File: benchmarks/mpm2d.py import time import numpy as np import taichi as ti @ti.all_archs def benchmark_range(): quality = 1 # Use a larger value for higher-res simulations n_particles, n_grid = 9000 * quality**2, 128 * quality dx, inv_dx = 1 / n_grid, float(n_grid) dt = 1e-4 / quality p_v...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "benchmarks/mpm2d.py", "license": "mit", "size": 10884}
### File: benchmarks/run.py import os import taichi as ti def get_benchmark_dir(): return os.path.join(ti.core.get_repo_dir(), 'benchmarks') class Case: def __init__(self, name, func): self.name = name self.func = func self.records = {} def __lt__(self, other): return s...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "benchmarks/run.py", "license": "mit", "size": 1750}
### File: benchmarks/summarize_async.py import math import yaml with open('benchmark.yml') as f: data = yaml.load(f) records = {} for case in data: for metrics in ['exec_t', 'launched_tasks']: for arch in ['x64', 'cuda']: key = metrics, arch d = [] for scheme in ...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "benchmarks/summarize_async.py", "license": "mit", "size": 641}
### File: benchmarks/utils.py import functools import os import taichi as ti def benchmark_async(func): @functools.wraps(func) def body(): for arch in [ti.cpu, ti.cuda]: for async_mode in [True, False]: os.environ['TI_CURRENT_BENCHMARK'] = func.__name__ ti....
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "benchmarks/utils.py", "license": "mit", "size": 728}
### File: cmake/PythonNumpyPybind11.cmake # Python, numpy, and pybind11 if (PYTHON_EXECUTABLE) message("Using ${PYTHON_EXECUTABLE} as python executable.") else () if (WIN32) message("Using 'python' as python interpreter.") set(PYTHON_EXECUTABLE python) else () message("Using 'python...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "CMake", "repo_name": "minhanghuang/Taichi", "path": "cmake/PythonNumpyPybind11.cmake", "license": "mit", "size": 3495}
### File: cmake/TaichiCXXFlags.cmake message("Using C++ compiler: " ${CMAKE_CXX_COMPILER}) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTI_ISE_NONE") option(BUILD_WITH_ADDRESS_SANITIZER "Build with clang address sanitizer" OFF) if (BUILD_WITH_ADDRESS_SANITIZER) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=add...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "CMake", "repo_name": "minhanghuang/Taichi", "path": "cmake/TaichiCXXFlags.cmake", "license": "mit", "size": 3225}
### File: cmake/TaichiCore.cmake option(USE_STDCPP "Use -stdlib=libc++" OFF) option(TI_WITH_CUDA "Build with the CUDA backend" ON) option(TI_WITH_OPENGL "Build with the OpenGL backend" ON) option(TI_WITH_CC "Build with the C backend" ON) if (APPLE) if (TI_WITH_CUDA) set(TI_WITH_CUDA OFF) message(WA...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "CMake", "repo_name": "minhanghuang/Taichi", "path": "cmake/TaichiCore.cmake", "license": "mit", "size": 7979}
### File: cmake/TaichiMain.cmake if (WIN32) message("Added executable 'ti' for Windows") # On Windows, generate a ti.exe as entry add_executable(ti python/ti.cpp) set_target_properties(ti PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin") set_target_properties(ti PROPERTIES RUNTI...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "CMake", "repo_name": "minhanghuang/Taichi", "path": "cmake/TaichiMain.cmake", "license": "mit", "size": 691}
### File: cmake/TaichiTests.cmake cmake_minimum_required(VERSION 3.0) set(TESTS_NAME taichi_cpp_tests) if (WIN32) # Prevent overriding the parent project's compiler/linker # settings on Windows set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) endif() # TODO(#2195): # 1. "cpp" -> "cpp_legacy", "cpp_new" ...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "CMake", "repo_name": "minhanghuang/Taichi", "path": "cmake/TaichiTests.cmake", "license": "mit", "size": 699}
### File: docs/conf.py # -*- coding: utf-8 -*- # # Configuration file for the Sphinx documentation builder. # # This file does only contain a selection of the most common options. For a # full list see the documentation: # http://www.sphinx-doc.org/en/stable/config # -- Path setup -------------------------------------...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "docs/conf.py", "license": "mit", "size": 7456}
### File: docs/make.bat @ECHO OFF pushd %~dp0 REM Command file for Sphinx documentation if "%SPHINXBUILD%" == "" ( set SPHINXBUILD=sphinx-build ) set SOURCEDIR=. set BUILDDIR=build set SPHINXPROJ=taichi if "%1" == "" goto help %SPHINXBUILD% >NUL 2>NUL if errorlevel 9009 ( echo. echo.The 'sphin...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Batchfile", "repo_name": "minhanghuang/Taichi", "path": "docs/make.bat", "license": "mit", "size": 809}
### File: examples/ad_gravity.py import taichi as ti ti.init() N = 8 dt = 1e-5 x = ti.Vector.field(2, float, N, needs_grad=True) # position of particles v = ti.Vector.field(2, float, N) # velocity of particles U = ti.field(float, (), needs_grad=True) # potential energy @ti.kernel def compute_U(): for i, j i...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "examples/ad_gravity.py", "license": "mit", "size": 1234}
### File: examples/autodiff_minimization.py import taichi as ti import random n = 8 x = ti.field(dtype=ti.f32, shape=n, needs_grad=True) y = ti.field(dtype=ti.f32, shape=n) L = ti.field(dtype=ti.f32, shape=(), needs_grad=True) @ti.kernel def reduce(): for i in range(n): L[None] += 0.5 * (x[i] - y[i])**2 ...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "examples/autodiff_minimization.py", "license": "mit", "size": 718}
### File: examples/autodiff_regression.py import taichi as ti import taichi as tc import matplotlib.pyplot as plt import random import numpy as np tc.set_gdb_trigger(True) number_coeffs = 4 learning_rate = 1e-4 N = 32 x, y = ti.field(ti.f32, shape=N, needs_grad=True), ti.field(ti.f32, ...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "examples/autodiff_regression.py", "license": "mit", "size": 1987}
### File: examples/cg_possion.py import taichi as ti import math ti.init(arch=ti.cuda) n = 512 steps = 32 eps = 1e-5 b = ti.field(float, (n, n)) x = ti.field(float, (n, n)) d = ti.field(float, (n, n)) r = ti.field(float, (n, n)) @ti.func def c(x: ti.template(), i, j): return x[i, j] if 0 <= i < n and 0 <= j < n...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "examples/cg_possion.py", "license": "mit", "size": 1305}
### File: examples/comet.py import taichi as ti import taichi_glsl as tl ti.init(arch=[ti.cuda, ti.metal]) dim = 3 N = 1024 * 8 dt = 2e-4 steps = 7 sun = ti.Vector([0.5, 0.5] if dim == 2 else [0.5, 0.5, 0.0]) gravity = 0.5 pressure = 0.3 pps_scale = 0.4 colorinit = 0.3 colordeg = 1.6 initvel = 0.07 res = 640 inv_m = ...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "examples/comet.py", "license": "mit", "size": 1852}
### File: examples/cornell_box.py import taichi as ti import time import math import numpy as np from renderer_utils import ray_aabb_intersection, intersect_sphere, ray_plane_intersect, reflect, refract ti.init(arch=ti.gpu) res = (800, 800) color_buffer = ti.Vector.field(3, dtype=ti.f32, shape=res) count_var = ti.fiel...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "examples/cornell_box.py", "license": "mit", "size": 13707}
### File: examples/euler.py import taichi as ti import matplotlib.cm as cm # A compressible euler equation solver using two methods # 1: 2nd order muscl # 2: thinc BVD, ref: "Limiter-free discontinuity-capturing scheme # for compressible gas dynamics with reactive fronts" real = ti.f32 ti.init(arc...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "examples/euler.py", "license": "mit", "size": 15194}
### File: examples/export_mesh.py import taichi as ti import numpy as np import os # A 2D grid with quad faces # y # | # z---/ # x # 19---15---11---07---03 # | | | | | # 18---14---10---06---02 # | | | | | # 17---13---19---05---01 # | ...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "examples/export_mesh.py", "license": "mit", "size": 3473}
### File: examples/export_ply.py import taichi as ti import numpy as np import random import os ti.init(arch=ti.cpu) num_vertices = 1000 pos = ti.Vector.field(3, dtype=ti.f32, shape=(10, 10, 10)) rgba = ti.Vector.field(4, dtype=ti.f32, shape=(10, 10, 10)) @ti.kernel def place_pos(): for i, j, k in pos: ...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "examples/export_ply.py", "license": "mit", "size": 1331}
### File: examples/export_videos.py import taichi as ti ti.init() pixels = ti.field(ti.u8, shape=(512, 512, 3)) @ti.kernel def paint(): for i, j, k in pixels: pixels[i, j, k] = ti.random() * 255 result_dir = "./results" video_manager = ti.VideoManager(output_dir=result_dir, ...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "examples/export_videos.py", "license": "mit", "size": 769}
### File: examples/fem128.py import taichi as ti ti.init(arch=ti.gpu) N = 12 dt = 5e-5 dx = 1 / N rho = 4e1 NF = 2 * N ** 2 # number of faces NV = (N + 1) ** 2 # number of vertices E, nu = 4e4, 0.2 # Young's modulus and Poisson's ratio mu, lam = E / 2 / (1 + nu), E * nu / (1 + nu) / (1 - 2 * nu) # Lame parameters b...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "examples/fem128.py", "license": "mit", "size": 4191}
### File: examples/fem99.py import taichi as ti ti.init(arch=ti.gpu) N = 32 dt = 1e-4 dx = 1 / N rho = 4e1 NF = 2 * N ** 2 # number of faces NV = (N + 1) ** 2 # number of vertices E, nu = 4e4, 0.2 # Young's modulus and Poisson's ratio mu, lam = E / 2 / (1 + nu), E * nu / (1 + nu) / (1 - 2 * nu) # Lame parameters ba...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "examples/fem99.py", "license": "mit", "size": 3025}
### File: examples/fractal.py import taichi as ti ti.init(arch=ti.gpu) n = 320 pixels = ti.field(dtype=float, shape=(n * 2, n)) @ti.func def complex_sqr(z): return ti.Vector([z[0]**2 - z[1]**2, z[1] * z[0] * 2]) @ti.kernel def paint(t: float): for i, j in pixels: # Parallized over all pixels c = ...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "examples/fractal.py", "license": "mit", "size": 688}
### File: examples/fullscreen.py import taichi as ti import numpy as np ti.init(ti.gpu) res = (1920, 1080) img = ti.Vector.field(3, float, res) @ti.kernel def render(t: float): for i, j in img: a = ti.Vector([i / res[0], j / res[1] + 2, i / res[0] + 4]) img[i, j] = ti.cos(a + t) * 0.5 + 0.5 gu...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "examples/fullscreen.py", "license": "mit", "size": 448}
### File: examples/game_of_life.py # Game of Life written in 100 lines of Taichi # In memory of John Horton Conway (1937 - 2020) import taichi as ti import numpy as np ti.init() n = 64 cell_size = 8 img_size = n * cell_size alive = ti.field(int, shape=(n, n)) # alive = 1, dead = 0 count = ti.field(int, shape=(n, n)...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "examples/game_of_life.py", "license": "mit", "size": 1987}
### File: examples/gui_image_io.py import taichi as ti import os pixel = ti.field(ti.u8, shape=(512, 512, 3)) @ti.kernel def paint(): for I in ti.grouped(pixel): pixel[I] = ti.random() * 255 paint() pixel = pixel.to_numpy() ti.imshow(pixel, 'Random Generated') for ext in ['bmp', 'png', 'jpg']: fn =...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "examples/gui_image_io.py", "license": "mit", "size": 511}
### File: examples/gui_widgets.py import taichi as ti gui = ti.GUI('GUI widgets') radius = gui.slider('Radius', 1, 50, step=1) xcoor = gui.label('X-coordinate') okay = gui.button('OK') xcoor.value = 0.5 radius.value = 10 while gui.running: for e in gui.get_events(gui.PRESS): if e.key == gui.ESCAPE: ...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "examples/gui_widgets.py", "license": "mit", "size": 678}
### File: examples/keyboard.py import taichi as ti x, y = 0.5, 0.5 delta = 0.01 radius = 8 gui = ti.GUI("Keyboard", res=(400, 400)) while gui.running: while gui.get_event(ti.GUI.PRESS, ti.GUI.MOTION): if gui.event.key == ti.GUI.ESCAPE: gui.running = False elif gui.event.key == ti.GUI....
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "examples/keyboard.py", "license": "mit", "size": 1116}
### File: examples/laplace.py import taichi as ti ti.init(arch=ti.cpu) x, y = ti.field(ti.f32), ti.field(ti.f32) ti.root.dense(ti.ij, 16).place(x, y) @ti.kernel def laplace(): for i, j in x: if (i + j) % 3 == 0: y[i, j] = 4.0 * x[i, j] - x[i - 1, j] - ...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "examples/laplace.py", "license": "mit", "size": 516}
### File: examples/mass_spring_3d.py import taichi as ti import numpy as np try: import taichi_glsl as tl import taichi_three as t3 except ImportError: print('This example needs the extension library Taichi THREE to work.' 'Please run `pip install taichi_three==0.0.5` to install it.') if t3.__vers...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "examples/mass_spring_3d.py", "license": "mit", "size": 3643}
### File: examples/mass_spring_game.py # Tutorials (Chinese): # - https://www.bilibili.com/video/BV1UK4y177iH # - https://www.bilibili.com/video/BV1DK411A771 import taichi as ti ti.init(arch=ti.cpu) spring_Y = ti.field(dtype=ti.f32, shape=()) # Young's modulus paused = ti.field(dtype=ti.i32, shape=()) drag_damping ...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "examples/mass_spring_game.py", "license": "mit", "size": 5988}
### File: examples/mciso.py import taichi as ti import numpy as np ti.init() N = 128 _et = np.array( [ [[-1, -1], [-1, -1]], # [[0, 1], [-1, -1]], #a [[0, 2], [-1, -1]], #b [[1, 2], [-1, -1]], #ab [[1, 3], [-1, -1]], #c [[0, 3], [-1, -1]], #ca [[2, 3],...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "examples/mciso.py", "license": "mit", "size": 2286}
### File: examples/mciso_advanced.py import taichi as ti import numpy as np @ti.data_oriented class MCISO: et2 = np.array( [ [[-1, -1], [-1, -1]], # [[0, 1], [-1, -1]], #a [[0, 2], [-1, -1]], #b [[1, 2], [-1, -1]], #ab [[1, 3], [-1, -1]], #c...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "examples/mciso_advanced.py", "license": "mit", "size": 28318}
### File: examples/mgpcg.py # Solve Poisson's equation on an NxN grid using MGPCG import numpy as np import taichi as ti real = ti.f32 ti.init(default_fp=real, arch=ti.x64, kernel_profiler=True) # grid parameters N = 128 N_gui = 512 # gui resolution n_mg_levels = 4 pre_and_post_smoothing = 2 bottom_smoothing = 50 ...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "examples/mgpcg.py", "license": "mit", "size": 5236}
### File: examples/mgpcg_advanced.py import numpy as np import taichi as ti import time import math @ti.data_oriented class MGPCG: ''' Grid-based MGPCG solver for the possion equation. See `examples/stable_fluid.py <https://github.com/taichi-dev/taichi/blob/master/examples/stable_fluid.py>`_ for a usage example....
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "examples/mgpcg_advanced.py", "license": "mit", "size": 9078}
### File: examples/minimal.py import taichi as ti ti.init() @ti.kernel def p(): print(42) p()
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "examples/minimal.py", "license": "mit", "size": 73}
### File: examples/mnist.py import numpy as np import random import taichi as ti import pickle # ti.runtime.print_preprocessed = True # ti.cfg.print_ir = True input = ti.field(ti.f32) weight1 = ti.field(ti.f32) output1 = ti.field(ti.f32) output1_nonlinear = ti.field(ti.f32) weight2 = ti.field(ti.f32) output = ti.fi...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "examples/mnist.py", "license": "mit", "size": 5363}
### File: examples/mnist_download_data.py # https://github.com/hsjeong5/MNIST-for-Numpy import numpy as np from urllib import request import gzip import pickle filename = [["training_images", "train-images-idx3-ubyte.gz"], ["test_images", "t10k-images-idx3-ubyte.gz"], ["training_labels", "trai...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "examples/mnist_download_data.py", "license": "mit", "size": 1383}
### File: examples/mpm128.py import taichi as ti import numpy as np ti.init(arch=ti.gpu) # Try to run on GPU quality = 1 # Use a larger value for higher-res simulations n_particles, n_grid = 9000 * quality ** 2, 128 * quality dx, inv_dx = 1 / n_grid, float(n_grid) dt = 1e-4 / quality p_vol, p_rho = (dx * 0.5)**2, 1 p...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "examples/mpm128.py", "license": "mit", "size": 5997}
### File: examples/mpm3d.py export_file = '' # use '/tmp/mpm3d.ply' for exporting result to disk import taichi as ti import numpy as np ti.init(arch=ti.gpu) #dim, n_grid, steps, dt = 2, 128, 20, 2e-4 #dim, n_grid, steps, dt = 2, 256, 32, 1e-4 dim, n_grid, steps, dt = 3, 32, 25, 4e-4 #dim, n_grid, steps, dt = 3, 64,...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "examples/mpm3d.py", "license": "mit", "size": 3501}
### File: examples/mpm88.py # MPM-MLS in 88 lines of Taichi code, originally created by @yuanming-hu import taichi as ti ti.init(arch=ti.gpu) n_particles = 8192 n_grid = 128 dx = 1 / n_grid dt = 2e-4 p_rho = 1 p_vol = (dx * 0.5)**2 p_mass = p_vol * p_rho gravity = 9.8 bound = 3 E = 400 x = ti.Vector.field(2, float, ...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "examples/mpm88.py", "license": "mit", "size": 2720}
### File: examples/mpm99.py import taichi as ti import numpy as np ti.init(arch=ti.gpu) # Try to run on GPU quality = 1 # Use a larger value for higher-res simulations n_particles, n_grid = 9000 * quality ** 2, 128 * quality dx, inv_dx = 1 / n_grid, float(n_grid) dt = 1e-4 / quality p_vol, p_rho = (dx * 0.5)**2, 1 p_ma...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "examples/mpm99.py", "license": "mit", "size": 4761}
### File: examples/mpm_lagrangian_forces.py import taichi as ti import numpy as np ti.init(arch=ti.gpu) dim = 2 quality = 1 # Use a larger integral number for higher quality n_particle_x = 100 * quality n_particle_y = 8 * quality n_particles = n_particle_x * n_particle_y n_elements = (n_particle_x - 1) * (n_particle...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "examples/mpm_lagrangian_forces.py", "license": "mit", "size": 6013}
### File: examples/nbody_oscillator.py import taichi as ti import math ti.init(arch=ti.gpu) N = 1600 r0 = 0.05 dt = 1e-5 steps = 160 eps = 1e-3 G = -1e1 pos = ti.Vector.var(2, ti.f32, N) vel = ti.Vector.var(2, ti.f32, N) @ti.kernel def initialize(): for i in range(N): a = ti.random() * math.tau ...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "examples/nbody_oscillator.py", "license": "mit", "size": 1108}
### File: examples/odop_solar.py import taichi as ti import math ti.init() @ti.data_oriented class SolarSystem: def __init__(self, n, dt): # Initializer of the solar system simulator self.n = n self.dt = dt self.x = ti.Vector.field(2, dtype=ti.f32, shape=n) self.v = ti.Vector.fie...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "examples/odop_solar.py", "license": "mit", "size": 2048}
### File: examples/particle_renderer.py import taichi as ti import numpy as np import math import time from renderer_utils import out_dir, ray_aabb_intersection, inf, eps, \ intersect_sphere, sphere_aabb_intersect_motion, inside_taichi ti.init(arch=ti.cuda, device_memory_GB=4) res = 1280, 720 num_spheres = 1024 col...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "examples/particle_renderer.py", "license": "mit", "size": 15394}
### File: examples/pbf2d.py # Macklin, M. and Müller, M., 2013. Position based fluids. ACM Transactions on Graphics (TOG), 32(4), p.104. # Taichi implementation by Ye Kuang (k-ye) import taichi as ti import numpy as np import math ti.init(arch=ti.gpu) screen_res = (800, 400) screen_to_world_ratio = 10.0 boundary = (...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "examples/pbf2d.py", "license": "mit", "size": 8926}
### File: examples/physarum.py '''Physarum simulation example. See https://sagejenson.com/physarum for the details.''' import numpy as np import taichi as ti ti.init(arch=ti.gpu) PARTICLE_N = 1024 GRID_SIZE = 512 SENSE_ANGLE = 0.20 * np.pi SENSE_DIST = 4.0 EVAPORATION = 0.95 MOVE_ANGLE = 0.1 * np.pi MOVE_STEP = 2.0 ...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "examples/physarum.py", "license": "mit", "size": 2172}
### File: examples/quadtree.py import taichi as ti import numpy as np ti.init(arch=ti.cpu) RES = 1024 K = 2 R = 7 N = K**R Broot = ti.root B = ti.root for r in range(R): B = B.bitmasked(ti.ij, (K, K)) qt = ti.field(ti.f32) B.place(qt) img = ti.Vector.field(3, dtype=ti.f32, shape=(RES, RES)) print('The quad tr...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "examples/quadtree.py", "license": "mit", "size": 1419}
### File: examples/renderer_utils.py import taichi as ti import math eps = 1e-4 inf = 1e10 @ti.func def out_dir(n): u = ti.Vector([1.0, 0.0, 0.0]) if ti.abs(n[1]) < 1 - 1e-3: u = n.cross(ti.Vector([0.0, 1.0, 0.0])).normalized() v = n.cross(u) phi = 2 * math.pi * ti.random(ti.f32) r = ti.r...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "examples/renderer_utils.py", "license": "mit", "size": 4511}
### File: examples/revert_image_color.py import taichi as ti ti.init() ## Load the image: input_file_name = input('Enter the input image file name: ') input_image = ti.imread(input_file_name) ## Process the image: image = ti.field(ti.u8, input_image.shape) image.from_numpy(input_image) @ti.kernel def process(): ...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "examples/revert_image_color.py", "license": "mit", "size": 561}
### File: examples/sdf2d.py import taichi as ti from math import tau from renderer_utils import reflect, refract ti.init(arch=ti.opengl) N = 512 img = ti.field(dtype=ti.f32, shape=(N, N)) light_pos = ti.Vector.field(2, dtype=ti.f32, shape=()) @ti.func def vres(distance, emission, reflection, refraction): return ...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "examples/sdf2d.py", "license": "mit", "size": 3448}
### File: examples/sdf_renderer.py import taichi as ti import time import math import numpy as np ti.init(arch=ti.gpu) res = 1280, 720 color_buffer = ti.Vector.field(3, dtype=ti.f32, shape=res) max_ray_depth = 6 eps = 1e-4 inf = 1e10 fov = 0.23 dist_limit = 100 camera_pos = ti.Vector([0.0, 0.32, 3.7]) light_pos = [-...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "examples/sdf_renderer.py", "license": "mit", "size": 4495}
### File: examples/simple_uv.py import taichi as ti import numpy as np ti.init() res = (512, 512) pixels = ti.Vector.field(3, dtype=float, shape=res) @ti.kernel def paint(): for i, j in pixels: u = i / res[0] v = j / res[1] pixels[i, j] = [u, v, 0] gui = ti.GUI('UV', res) while not gui...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "examples/simple_uv.py", "license": "mit", "size": 368}
### File: examples/stable_fluid.py # References: # http://developer.download.nvidia.com/books/HTML/gpugems/gpugems_ch38.html # https://github.com/PavelDoGreat/WebGL-Fluid-Simulation # https://www.bilibili.com/video/BV1ZK411H7Hc?p=4 # https://github.com/ShaneFX/GAMES201/tree/master/HW01 import taichi as ti import numpy...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "examples/stable_fluid.py", "license": "mit", "size": 10906}
### File: examples/taichi_autodiff.py import taichi as ti import matplotlib.pyplot as plt N = 2048 x, y = ti.field(ti.f32), ti.field(ti.f32) ti.root.dense(ti.i, N).place(x, x.grad, y, y.grad) @ti.kernel def poly(): for i in x: v = x[i] ret = 0.0 guard = 0.2 if v < -guard or v > g...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "examples/taichi_autodiff.py", "license": "mit", "size": 949}
### File: examples/taichi_bitmasked.py import taichi as ti import math ti.init(arch=ti.gpu) n = 256 x = ti.field(ti.f32) # `bitmasked` is a field that supports sparsity, in that each element can be # activated individually. (It can be viewed as `dense`, with an extra bit for each # element to mark its activation). As...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "examples/taichi_bitmasked.py", "license": "mit", "size": 1341}
### File: examples/taichi_dynamic.py import taichi as ti x = ti.field(ti.i32) l = ti.field(ti.i32) n = 16 ti.init() ti.root.dense(ti.i, n).dynamic(ti.j, n).place(x) ti.root.dense(ti.i, n).place(l) @ti.kernel def make_lists(): for i in range(n): for j in range(i): ti.append(x.parent(), i, j ...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "examples/taichi_dynamic.py", "license": "mit", "size": 457}
### File: examples/taichi_logo.py import taichi as ti n = 512 x = ti.field(ti.f32, shape=(n, n)) @ti.kernel def paint(): for i, j in ti.ndrange(n * 4, n * 4): # 4x4 super sampling: ret = ti.taichi_logo(ti.Vector([i, j]) / (n * 4)) x[i // 4, j // 4] += ret / 16 paint() gui = ti.GUI('Log...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "examples/taichi_logo.py", "license": "mit", "size": 353}
### File: examples/taichi_sparse.py import taichi as ti ti.init(arch=ti.cuda) n = 512 x = ti.field(ti.f32) res = n + n // 4 + n // 16 + n // 64 img = ti.field(ti.f32, shape=(res, res)) block1 = ti.root.pointer(ti.ij, n // 64) block2 = block1.pointer(ti.ij, 4) block3 = block2.pointer(ti.ij, 4) block3.dense(ti.ij, 4)....
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "examples/taichi_sparse.py", "license": "mit", "size": 1033}
### File: examples/tree_gravity.py # N-body gravity simulation in 300 lines of Taichi, tree method, no multipole, O(N log N) # Author: archibate <1931127624@qq.com>, all left reserved import taichi as ti import taichi_glsl as tl ti.init() if not hasattr(ti, 'jkl'): ti.jkl = ti.indices(1, 2, 3) kUseTree = True #kDi...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "examples/tree_gravity.py", "license": "mit", "size": 11569}
### File: examples/vortex_rings.py # C++ reference and tutorial (Chinese): https://zhuanlan.zhihu.com/p/26882619 import taichi as ti import numpy as np import math ti.init(arch=ti.gpu) eps = 0.01 dt = 0.1 n_vortex = 4 n_tracer = 200000 pos = ti.Vector.field(2, ti.f32, shape=n_vortex) new_pos = ti.Vector.field(2, ti...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "examples/vortex_rings.py", "license": "mit", "size": 1968}
### File: examples/waterwave.py import taichi as ti import numpy as np ti.init(arch=ti.gpu) light_color = 1 kappa = 2 gamma = 0.2 eta = 1.333 depth = 4 dx = 0.02 dt = 0.01 shape = 512, 512 pixels = ti.field(dtype=float, shape=shape) background = ti.field(dtype=float, shape=shape) height = ti.field(dtype=float, shape=...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "examples/waterwave.py", "license": "mit", "size": 2791}
### File: misc/appveyor_filter.py import os import sys msg = os.environ["APPVEYOR_REPO_COMMIT_MESSAGE"] if msg.startswith('[release]') or sys.version_info[1] == 6: exit( 0 ) # Build for this configuration (starts with '[release]', or python version is 3.6) else: print( f'[appveyor_filer] N...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "misc/appveyor_filter.py", "license": "mit", "size": 409}
### File: misc/async_mgpcg.py import time import numpy as np import taichi as ti real = ti.f32 ti.init(default_fp=real, arch=ti.cuda, async_mode=True, async_opt_listgen=True, async_opt_dse=True, async_opt_activation_demotion=True, async_opt_fusion=True, kernel_...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Python", "repo_name": "minhanghuang/Taichi", "path": "misc/async_mgpcg.py", "license": "mit", "size": 5301}
### File: misc/baselines/Makefile ma: kernel_malloc.cu nvcc kernel_malloc.cu -std=c++14 -O3 -o ma rand_nvcc: rand.cu nvcc rand.cu -o rand_nvcc rand_clang: rand.cu clang++-8 -std=c++14 rand.cu -o rand_clang --cuda-gpu-arch=sm_61 -L/usr/local/cuda/lib64 -lcudart_static -ldl -lrt -pthread assert: assert.cu clang++-...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Makefile", "repo_name": "minhanghuang/Taichi", "path": "misc/baselines/Makefile", "license": "mit", "size": 994}
### File: misc/baselines/assert.cu // clang-format off #include <cstdio> #include <cassert> __global__ void init_random_numbers(unsigned int seed) { printf("seed = %d\n", seed); atomicAdd((int *)(12312433432), 123); atomicAdd((float *)(12312433432), 123.0f); __threadfence_block(); // membar.cta __threadfence...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Cuda", "repo_name": "minhanghuang/Taichi", "path": "misc/baselines/assert.cu", "license": "mit", "size": 2972}
### File: misc/baselines/atomics.cpp #include <atomic> #include <cstdio> int glo; long long tot; float fglo; int main() { glo = 0; #pragma omp parallel for for (int i = 0; i < 100000000; i++) { glo += 1; } printf("%d\n", glo); glo = 0; tot = 0; #pragma omp parallel for for (int i = 0; i < 100000000...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/Taichi", "path": "misc/baselines/atomics.cpp", "license": "mit", "size": 1011}
### File: misc/baselines/bandwidth.cu #include <iostream> #include <cstdlib> #include <cstdio> #include <cuda_runtime.h> #include <sys/time.h> double get_time() { struct timeval tv; gettimeofday(&tv, nullptr); return tv.tv_sec + 1e-6 * tv.tv_usec; } constexpr int m = 256; inline __device__ int indirect(int *c,...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Cuda", "repo_name": "minhanghuang/Taichi", "path": "misc/baselines/bandwidth.cu", "license": "mit", "size": 2825}
### File: misc/baselines/containers.cpp #include <atomic> #include <cstdio> #include <vector> #include <unordered_map> #include <map> #include <sys/time.h> double get_time() { struct timeval tv; gettimeofday(&tv, nullptr); return tv.tv_sec + 1e-6 * tv.tv_usec; } int main() { int n = 1024; int N = 100000000;...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/Taichi", "path": "misc/baselines/containers.cpp", "license": "mit", "size": 1065}
### File: misc/baselines/cpu_memory_bound.cpp // #include <mkl.h> #include <cstdlib> #include <cstdio> #include <cmath> #include <vector> #include <unistd.h> #include <cstring> #include <sys/time.h> double get_time() { struct timeval tv; gettimeofday(&tv, nullptr); return tv.tv_sec + 1e-6 * tv.tv_usec; } constex...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C++", "repo_name": "minhanghuang/Taichi", "path": "misc/baselines/cpu_memory_bound.cpp", "license": "mit", "size": 959}
### File: misc/baselines/cuda_atomic_reduce.cu #include <iostream> #include <cstdlib> #include <cstdio> #include <cuda_runtime.h> #include "get_time.h" __global__ void reduce(int *a, int *b, int n) { unsigned int i = blockIdx.x * blockDim.x + threadIdx.x; atomicAdd(b, a[i]); } int main() { // int n = 512 * 512;...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Cuda", "repo_name": "minhanghuang/Taichi", "path": "misc/baselines/cuda_atomic_reduce.cu", "license": "mit", "size": 798}
### File: misc/baselines/fill.cu #include <iostream> #include <cstdlib> #include <cstdio> #include <cuda_runtime.h> #include <sys/time.h> double get_time() { struct timeval tv; gettimeofday(&tv, nullptr); return tv.tv_sec + 1e-6 * tv.tv_usec; } constexpr int m = 256; constexpr int n = m * m * m; constexpr int b...
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "Cuda", "repo_name": "minhanghuang/Taichi", "path": "misc/baselines/fill.cu", "license": "mit", "size": 1358}
### File: misc/baselines/get_time.h #pragma once #include <sys/time.h> double get_time() { struct timeval tv; gettimeofday(&tv, nullptr); return tv.tv_sec + 1e-6 * tv.tv_usec; }
{"idx": "gitee_code", "domain": "code", "domain2": "gitee-permissive", "header_footer": "", "lang": "en", "source": "gitee_code-0.jsonl", "prog_lang": "C", "repo_name": "minhanghuang/Taichi", "path": "misc/baselines/get_time.h", "license": "mit", "size": 150}