From bb5665b2db269406976c38633405ea7c50c7b4fd Mon Sep 17 00:00:00 2001 From: FantasyVR Date: Fri, 8 Oct 2021 17:06:45 +0800 Subject: [PATCH 1/3] [Lang] Move sparse matrix/solver into subfolder --- python/taichi/lang/__init__.py | 4 ++-- python/taichi/lang/kernel_arguments.py | 2 +- python/taichi/lang/{ => sparse_matrix}/sparse_matrix.py | 0 python/taichi/lang/{ => sparse_matrix}/sparse_solver.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) rename python/taichi/lang/{ => sparse_matrix}/sparse_matrix.py (100%) rename python/taichi/lang/{ => sparse_matrix}/sparse_solver.py (96%) diff --git a/python/taichi/lang/__init__.py b/python/taichi/lang/__init__.py index 3368bf629c0ae..a57fd880fdb7f 100644 --- a/python/taichi/lang/__init__.py +++ b/python/taichi/lang/__init__.py @@ -18,8 +18,8 @@ from taichi.lang.ops import * from taichi.lang.quant_impl import quant from taichi.lang.runtime_ops import async_flush, sync -from taichi.lang.sparse_matrix import SparseMatrix, SparseMatrixBuilder -from taichi.lang.sparse_solver import SparseSolver +from taichi.lang.sparse_matrix.sparse_matrix import SparseMatrix, SparseMatrixBuilder +from taichi.lang.sparse_matrix.sparse_solver import SparseSolver from taichi.lang.struct import Struct from taichi.lang.type_factory_impl import type_factory from taichi.lang.util import (has_pytorch, is_taichi_class, python_scope, diff --git a/python/taichi/lang/kernel_arguments.py b/python/taichi/lang/kernel_arguments.py index a2029160324d9..deae64ec54ce6 100644 --- a/python/taichi/lang/kernel_arguments.py +++ b/python/taichi/lang/kernel_arguments.py @@ -3,7 +3,7 @@ from taichi.lang.enums import Layout from taichi.lang.expr import Expr from taichi.lang.snode import SNode -from taichi.lang.sparse_matrix import SparseMatrixBuilder +from taichi.lang.sparse_matrix.sparse_matrix import SparseMatrixBuilder from taichi.lang.util import cook_dtype, to_taichi_type from taichi.type.primitive_types import u64 diff --git a/python/taichi/lang/sparse_matrix.py b/python/taichi/lang/sparse_matrix/sparse_matrix.py similarity index 100% rename from python/taichi/lang/sparse_matrix.py rename to python/taichi/lang/sparse_matrix/sparse_matrix.py diff --git a/python/taichi/lang/sparse_solver.py b/python/taichi/lang/sparse_matrix/sparse_solver.py similarity index 96% rename from python/taichi/lang/sparse_solver.py rename to python/taichi/lang/sparse_matrix/sparse_solver.py index 225faa58594e6..e535a59431e0d 100644 --- a/python/taichi/lang/sparse_solver.py +++ b/python/taichi/lang/sparse_matrix/sparse_solver.py @@ -1,4 +1,4 @@ -from taichi.lang.sparse_matrix import SparseMatrix +from taichi.lang.sparse_matrix.sparse_matrix import SparseMatrix class SparseSolver: From 6a634ff3bff59f7e0737c6dae4c554aa593cfb5d Mon Sep 17 00:00:00 2001 From: FantasyVR Date: Sat, 9 Oct 2021 10:06:01 +0800 Subject: [PATCH 2/3] Move sparse_matrix/solver to python/taichi/linalg/ --- python/taichi/lang/__init__.py | 4 +--- python/taichi/lang/kernel_arguments.py | 2 +- python/taichi/linalg/__init__.py | 3 +++ .../taichi/{lang/sparse_matrix => linalg}/sparse_matrix.py | 0 .../taichi/{lang/sparse_matrix => linalg}/sparse_solver.py | 6 +++--- 5 files changed, 8 insertions(+), 7 deletions(-) create mode 100644 python/taichi/linalg/__init__.py rename python/taichi/{lang/sparse_matrix => linalg}/sparse_matrix.py (100%) rename python/taichi/{lang/sparse_matrix => linalg}/sparse_solver.py (93%) diff --git a/python/taichi/lang/__init__.py b/python/taichi/lang/__init__.py index 440b3ccf73f00..169947b863034 100644 --- a/python/taichi/lang/__init__.py +++ b/python/taichi/lang/__init__.py @@ -24,14 +24,12 @@ from taichi.lang.ops import * from taichi.lang.quant_impl import quant from taichi.lang.runtime_ops import async_flush, sync -from taichi.lang.sparse_matrix.sparse_matrix import (SparseMatrix, - SparseMatrixBuilder) -from taichi.lang.sparse_matrix.sparse_solver import SparseSolver from taichi.lang.struct import Struct from taichi.lang.type_factory_impl import type_factory from taichi.lang.util import (has_pytorch, is_taichi_class, python_scope, taichi_scope, to_numpy_type, to_pytorch_type, to_taichi_type) +from taichi.linalg import SparseMatrix, SparseMatrixBuilder, SparseSolver from taichi.misc.util import deprecated from taichi.profiler import KernelProfiler, get_default_kernel_profiler from taichi.snode.fields_builder import FieldsBuilder diff --git a/python/taichi/lang/kernel_arguments.py b/python/taichi/lang/kernel_arguments.py index c823c13b26f58..d25228649925e 100644 --- a/python/taichi/lang/kernel_arguments.py +++ b/python/taichi/lang/kernel_arguments.py @@ -4,8 +4,8 @@ from taichi.lang.expr import Expr from taichi.lang.ndarray import ScalarNdarray from taichi.lang.snode import SNode -from taichi.lang.sparse_matrix.sparse_matrix import SparseMatrixBuilder from taichi.lang.util import cook_dtype, to_taichi_type +from taichi.linalg import SparseMatrixBuilder from taichi.type.primitive_types import u64 diff --git a/python/taichi/linalg/__init__.py b/python/taichi/linalg/__init__.py new file mode 100644 index 0000000000000..3d94d7c09d38f --- /dev/null +++ b/python/taichi/linalg/__init__.py @@ -0,0 +1,3 @@ +from taichi.linalg.sparse_matrix import SparseMatrix +from taichi.linalg.sparse_matrix import SparseMatrixBuilder +from taichi.linalg.sparse_solver import SparseSolver \ No newline at end of file diff --git a/python/taichi/lang/sparse_matrix/sparse_matrix.py b/python/taichi/linalg/sparse_matrix.py similarity index 100% rename from python/taichi/lang/sparse_matrix/sparse_matrix.py rename to python/taichi/linalg/sparse_matrix.py diff --git a/python/taichi/lang/sparse_matrix/sparse_solver.py b/python/taichi/linalg/sparse_solver.py similarity index 93% rename from python/taichi/lang/sparse_matrix/sparse_solver.py rename to python/taichi/linalg/sparse_solver.py index fb8c326b13de0..bcad5e4553a0a 100644 --- a/python/taichi/lang/sparse_matrix/sparse_solver.py +++ b/python/taichi/linalg/sparse_solver.py @@ -1,12 +1,11 @@ import numpy as np from taichi.core.util import ti_core as _ti_core -from taichi.lang import Field -from taichi.lang.impl import get_runtime -from taichi.lang.sparse_matrix.sparse_matrix import SparseMatrix +from taichi.linalg import SparseMatrix class SparseSolver: def __init__(self, solver_type="LLT", ordering="AMD"): + from taichi.lang.impl import get_runtime solver_type_list = ["LLT", "LDLT", "LU"] solver_ordering = ['AMD', 'COLAMD'] if solver_type in solver_type_list and ordering in solver_ordering: @@ -39,6 +38,7 @@ def factorize(self, sparse_matrix): self.type_assert(sparse_matrix) def solve(self, b): + from taichi.lang import Field if isinstance(b, Field): return self.solver.solve(b.to_numpy()) elif isinstance(b, np.ndarray): From 393e9c2c39f586a692c4a4ccda8d19dc90f777be Mon Sep 17 00:00:00 2001 From: Taichi Gardener Date: Sat, 9 Oct 2021 02:10:10 +0000 Subject: [PATCH 3/3] Auto Format --- python/taichi/lang/kernel_arguments.py | 2 +- python/taichi/linalg/__init__.py | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/python/taichi/lang/kernel_arguments.py b/python/taichi/lang/kernel_arguments.py index 30e318ecf2617..864d821f21a12 100644 --- a/python/taichi/lang/kernel_arguments.py +++ b/python/taichi/lang/kernel_arguments.py @@ -2,8 +2,8 @@ from taichi.lang.any_array import AnyArray from taichi.lang.enums import Layout from taichi.lang.expr import Expr -from taichi.linalg import SparseMatrixBuilder from taichi.lang.util import cook_dtype +from taichi.linalg import SparseMatrixBuilder from taichi.type.primitive_types import u64 diff --git a/python/taichi/linalg/__init__.py b/python/taichi/linalg/__init__.py index 3d94d7c09d38f..2bf35da5974fc 100644 --- a/python/taichi/linalg/__init__.py +++ b/python/taichi/linalg/__init__.py @@ -1,3 +1,2 @@ -from taichi.linalg.sparse_matrix import SparseMatrix -from taichi.linalg.sparse_matrix import SparseMatrixBuilder -from taichi.linalg.sparse_solver import SparseSolver \ No newline at end of file +from taichi.linalg.sparse_matrix import SparseMatrix, SparseMatrixBuilder +from taichi.linalg.sparse_solver import SparseSolver