Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/taichi-dev/taichi
Browse files Browse the repository at this point in the history
  • Loading branch information
squarefk committed Jul 28, 2021
2 parents da3c394 + 70f157a commit 9985bac
Show file tree
Hide file tree
Showing 29 changed files with 3,260 additions and 447 deletions.
15 changes: 2 additions & 13 deletions .github/workflows/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,6 @@ jobs:
- name: Build
shell: powershell
run: |
$env:TAICHI_REPO_DIR = "D:\a\taichi\taichi"
$env:PYTHONPATH = "$env:TAICHI_REPO_DIR\python"
cd C:\
Remove-item alias:curl
curl --retry 10 --retry-delay 5 https://github.com/taichi-dev/taichi_assets/releases/download/llvm10/taichi-llvm-10.0.0-msvc2019.zip -LO
Expand All @@ -216,28 +214,19 @@ jobs:
7z x clang-10.0.0-win.zip -otaichi_clang
$env:PATH += ";C:\taichi_llvm\bin"
$env:PATH += ";C:\taichi_clang\bin"
$env:PATH += ";$env:TAICHI_REPO_DIR\bin"
clang --version
cd D:\a\taichi\taichi
python -m pip install numpy
python -m pip install pybind11
python -m pip install --user numpy pybind11 gitpython
python misc/ci_setup.py ci
mkdir build
cd build
cmake .. -G"Visual Studio 16 2019" -A x64 -DPYTHON_EXECUTABLE="$env:PYTHON" -DLLVM_DIR="C:\taichi_llvm\lib\cmake\llvm"
msbuild /p:Configuration=RelWithDebInfo /p:Platform=x64 /m taichi.sln
cd ..
env:
PYTHON: C:\hostedtoolcache\windows\Python\3.7.9\x64\python.exe
CI_SETUP_CMAKE_ARGS: -G "Visual Studio 16 2019" -A x64 -DLLVM_DIR=C:\taichi_llvm\lib\cmake\llvm

- name: Test
shell: powershell
run: |
$env:TAICHI_REPO_DIR = "D:\a\taichi\taichi"
$env:PYTHONPATH = "$env:TAICHI_REPO_DIR\python"
$env:PATH += ";C:\taichi_llvm\bin"
$env:PATH += ";C:\taichi_clang\bin"
$env:PATH += ";$env:TAICHI_REPO_DIR\bin"
python -c "import taichi"
python examples/algorithm/laplace.py
python bin/taichi diagnose
Expand Down
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ include python/*.py
include *.cfg
include python/taichi/*.md
include python/taichi/assets/*
include python/taichi/examples/*
recursive-include python/taichi/examples *.py
include python/taichi/tests/*
include python/taichi/lib/*.so
include python/taichi/lib/*.pyd
Expand Down
11 changes: 4 additions & 7 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,13 @@ build_script:
- 7z x clang-10.0.0-win.zip -otaichi_clang
- set PATH=C:\taichi_llvm\bin;%PATH%;
- set PATH=C:\taichi_clang\bin;%PATH%
- set PYTHONPATH=%TAICHI_REPO_DIR%/python
- set PATH=%TAICHI_REPO_DIR%\bin;%PATH%
- clang --version
- cd C:\taichi
- set CI_SETUP_CMAKE_ARGS=-G "Visual Studio 16 2019" -A x64 -DLLVM_DIR=C:\taichi_llvm\lib\cmake\llvm
# This is to fix the bug caused by execnet 1.2, the library xdist uses to schedule tests.
# Reverting to v1.1 solves this bug(Python Fatal Error: IOError).
- "%PYTHON% -m pip install -U execnet==1.1"
- "%PYTHON% misc/ci_setup.py ci"
- mkdir build
- cd build
- cmake .. -G"Visual Studio 16 2019" -A x64 -DPYTHON_EXECUTABLE="%PYTHON%" -DLLVM_DIR="C:\taichi_llvm\lib\cmake\llvm"
- msbuild /p:Configuration=RelWithDebInfo /p:Platform=x64 /m taichi.sln
- cd ..
- '%PYTHON% -c "import taichi"'
- "%PYTHON% examples/algorithm/laplace.py"
- "%PYTHON% bin/taichi diagnose"
Expand Down
18 changes: 8 additions & 10 deletions misc/ci_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,23 +255,21 @@ def run(self):
print('PYTHONPATH={}'.format(os.environ['PYTHONPATH']))

execute_command('echo $PYTHONPATH')
elif get_os_name() != 'win':
else:
# compile ..
arg = environ.get('CI_SETUP_CMAKE_ARGS', '')
os.environ['TAICHI_CMAKE_ARGS'] = arg
os.makedirs('build', exist_ok=True)
execute_command(
f'TAICHI_CMAKE_ARGS="{arg}" {sys.executable} setup.py install --user'
)
execute_command(f'{sys.executable} setup.py install --user')
return
if test_installation():
print(' Successfully Installed Taichi at {}.'.format(
self.repo_dir))
if get_os_name() != 'win':
if execute_command('ti') != 0:
print(' Warning: shortcut "ti" does not work.')
print(' Please execute')
print(' source ', get_shell_rc_name())
print(' or restart your terminal.')
if execute_command('ti') != 0:
print(' Warning: shortcut "ti" does not work.')
print(' Please execute')
print(' source ', get_shell_rc_name())
print(' or restart your terminal.')
else:
print(' Error: installation failed.')
exit(-1)
Expand Down
111 changes: 80 additions & 31 deletions python/taichi/lang/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,19 @@ def memory_profiler_print():


extension = _ti_core.Extension
is_extension_supported = _ti_core.is_extension_supported


def is_extension_supported(arch, ext):
"""Checks whether an extension is supported on an arch.
Args:
arch (taichi_core.Arch): Specified arch.
ext (taichi_core.Extension): Specified extension.
Returns:
bool: Whether `ext` is supported on `arch`.
"""
return _ti_core.is_extension_supported(arch, ext)


def reset():
Expand Down Expand Up @@ -289,13 +301,37 @@ def loop_unique(val, covers=None):


def polar_decompose(A, dt=None):
"""Perform polar decomposition (A=UP) for arbitrary size matrix.
Mathematical concept refers to https://en.wikipedia.org/wiki/Polar_decomposition.
This is only a wrapper for :func:`taichi.lang.linalg.polar_decompose`.
Args:
A (ti.Matrix(n, n)): input nxn matrix `A`.
dt (DataType): date type of elements in matrix `A`, typically accepts ti.f32 or ti.f64.
Returns:
Decomposed nxn matrices `U` and `P`.
"""
if dt is None:
dt = impl.get_runtime().default_fp
from .linalg import polar_decompose
return polar_decompose(A, dt)


def svd(A, dt=None):
"""Perform singular value decomposition (A=USV^T) for arbitrary size matrix.
Mathematical concept refers to https://en.wikipedia.org/wiki/Singular_value_decomposition.
This is only a wrappers for :func:`taichi.lang.linalg.svd`.
Args:
A (ti.Matrix(n, n)): input nxn matrix `A`.
dt (DataType): date type of elements in matrix `A`, typically accepts ti.f32 or ti.f64.
Returns:
Decomposed nxn matrices `U`, 'S' and `V`.
"""
if dt is None:
dt = impl.get_runtime().default_fp
from .linalg import svd
Expand All @@ -305,23 +341,16 @@ def svd(A, dt=None):
def eig(A, dt=None):
"""Compute the eigenvalues and right eigenvectors of a real matrix.
Parameters
----------
A: ti.Matrix(n, n)
2D Matrix for which the eigenvalues and right eigenvectors will be computed.
dt: Optional[DataType]
The datatype for the eigenvalues and right eigenvectors
Returns
-------
eigenvalues: ti.Matrix(n, 2)
The eigenvalues in complex form. Each row stores one eigenvalue. The first number
of the eigenvalue represents the real part and the second number represents the
imaginary part.
eigenvectors: ti.Matrix(n*2, n)
The eigenvectors in complex form. Each column stores one eigenvector. Each eigenvector
consists of n entries, each of which is represented by two numbers for its real part
and imaginary part.
Mathematical concept refers to https://en.wikipedia.org/wiki/Eigendecomposition_of_a_matrix.
2D implementation refers to :func:`taichi.lang.linalg.eig2x2`.
Args:
A (ti.Matrix(n, n)): 2D Matrix for which the eigenvalues and right eigenvectors will be computed.
dt (DataType): The datatype for the eigenvalues and right eigenvectors.
Returns:
eigenvalues (ti.Matrix(n, 2)): The eigenvalues in complex form. Each row stores one eigenvalue. The first number of the eigenvalue represents the real part and the second number represents the imaginary part.
eigenvectors (ti.Matrix(n*2, n)): The eigenvectors in complex form. Each column stores one eigenvector. Each eigenvector consists of n entries, each of which is represented by two numbers for its real part and imaginary part.
"""
if dt is None:
dt = impl.get_runtime().default_fp
Expand All @@ -334,19 +363,16 @@ def eig(A, dt=None):
def sym_eig(A, dt=None):
"""Compute the eigenvalues and right eigenvectors of a real symmetric matrix.
Parameters
----------
A: ti.Matrix(n, n)
Symmetric Matrix for which the eigenvalues and right eigenvectors will be computed.
dt: Optional[DataType]
The datatype for the eigenvalues and right eigenvectors
Returns
-------
eigenvalues: ti.Vector(n)
The eigenvalues. Each entry store one eigen value.
eigenvectors: ti.Matrix(n, n)
The eigenvectors. Each column stores one eigenvector.
Mathematical concept refers to https://en.wikipedia.org/wiki/Eigendecomposition_of_a_matrix.
2D implementation refers to :func:`taichi.lang.linalg.sym_eig2x2`.
Args:
A (ti.Matrix(n, n)): Symmetric Matrix for which the eigenvalues and right eigenvectors will be computed.
dt (DataType): The datatype for the eigenvalues and right eigenvectors.
Returns:
eigenvalues (ti.Vector(n)): The eigenvalues. Each entry store one eigen value.
eigenvectors (ti.Matrix(n, n)): The eigenvectors. Each column stores one eigenvector.
"""
assert all(A == A.transpose()), "A needs to be symmetric"
if dt is None:
Expand All @@ -358,6 +384,16 @@ def sym_eig(A, dt=None):


def randn(dt=None):
"""Generates a random number from standard normal distribution.
Implementation refers to :func:`taichi.lang.random.randn`.
Args:
dt (DataType): The datatype for the generated random number.
Returns:
The generated random number.
"""
if dt is None:
dt = impl.get_runtime().default_fp
from .random import randn
Expand Down Expand Up @@ -609,6 +645,14 @@ def stat_write(key, value):


def is_arch_supported(arch):
"""Checks whether an arch is supported on the machine.
Args:
arch (taichi_core.Arch): Specified arch.
Returns:
bool: Whether `arch` is supported on the machine.
"""
arch_table = {
cuda: _ti_core.with_cuda,
metal: _ti_core.with_metal,
Expand All @@ -631,6 +675,11 @@ def is_arch_supported(arch):


def supported_archs():
"""Gets all supported archs on the machine.
Returns:
List[taichi_core.Arch]: All supported archs on the machine.
"""
archs = [cpu, cuda, metal, opengl, cc]

wanted_archs = os.environ.get('TI_WANTED_ARCHS', '')
Expand Down
Loading

0 comments on commit 9985bac

Please sign in to comment.