Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Jul 1, 2024
1 parent 7cef41c commit bb0251a
Show file tree
Hide file tree
Showing 55 changed files with 300 additions and 200 deletions.
1 change: 1 addition & 0 deletions python/taichi/ad/_ad.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
This module supplies two decorators for users to customize their
gradient computation task.
"""

import warnings
from functools import reduce

Expand Down
1 change: 1 addition & 0 deletions python/taichi/aot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Users can use Taichi as a GPU compute shader/kernel compiler by compiling their
Taichi kernels into an AOT module.
"""

import taichi.aot.conventions
from taichi.aot._export import export, export_as
from taichi.aot.conventions.gfxruntime140 import GfxRuntime140
Expand Down
1 change: 1 addition & 0 deletions python/taichi/aot/conventions/gfxruntime140/dr.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Data representation of all JSON data structures following the GfxRuntime140
convention.
"""

from typing import Any, Dict, List, Optional

from taichi.aot.utils import dump_json_data_model, json_data_model
Expand Down
1 change: 1 addition & 0 deletions python/taichi/aot/conventions/gfxruntime140/sr.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Structured representation of all JSON data structures following the
GfxRuntime140.
"""

from abc import ABC
from enum import Enum
from typing import Any, Dict, List, Optional
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Given an input image, redraw it with circle packings.
"""

try:
import cairo
import cv2
Expand Down
1 change: 1 addition & 0 deletions python/taichi/examples/algorithm/marching_squares.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Marching squares algorithm in Taichi.
See "https://en.wikipedia.org/wiki/Marching_squares"
"""

import time

import numpy as np
Expand Down
1 change: 1 addition & 0 deletions python/taichi/examples/algorithm/poisson_disk_sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
1. Click on the window to restart the animation.
2. Press `p` to save screenshot.
"""

import taichi as ti
import taichi.math as tm

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Marching squares algorithm in Taichi.
See "https://en.wikipedia.org/wiki/Marching_squares"
"""

import time

import numpy as np
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
1. Click on the window to restart the animation.
2. Press `p` to save screenshot.
"""

import taichi as ti
import taichi.math as tm
import typing
Expand Down
4 changes: 1 addition & 3 deletions python/taichi/examples/real_func/rendering/taichi_ngp.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,7 @@ def hash_table_init(self):
for i in range(self.level):
resolution = int(np.ceil(self.base_res * np.exp(i * np.log(self.per_level_scales)) - 1.0)) + 1
params_in_level = resolution**3
params_in_level = (
int(resolution**3) if params_in_level % 8 == 0 else int((params_in_level + 8 - 1) / 8) * 8
)
params_in_level = int(resolution**3) if params_in_level % 8 == 0 else int((params_in_level + 8 - 1) / 8) * 8
params_in_level = min(self.max_params, params_in_level)
self.offsets[i] = offset
self.hash_map_sizes[i] = params_in_level
Expand Down
4 changes: 1 addition & 3 deletions python/taichi/examples/rendering/taichi_ngp.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,7 @@ def hash_table_init(self):
for i in range(self.level):
resolution = int(np.ceil(self.base_res * np.exp(i * np.log(self.per_level_scales)) - 1.0)) + 1
params_in_level = resolution**3
params_in_level = (
int(resolution**3) if params_in_level % 8 == 0 else int((params_in_level + 8 - 1) / 8) * 8
)
params_in_level = int(resolution**3) if params_in_level % 8 == 0 else int((params_in_level + 8 - 1) / 8) * 8
params_in_level = min(self.max_params, params_in_level)
self.offsets[i] = offset
self.hash_map_sizes[i] = params_in_level
Expand Down
1 change: 1 addition & 0 deletions python/taichi/examples/simulation/snow_phaseField.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
space discretization: finite difference method, time integration: Runge-Kutta method
repo's link: https://github.com/mo-hanxuan/Snow-PhaseField
more details about physical interpretation refer to [Physica D 63(3-4): 410-423]"""

import numpy as np

import taichi as ti
Expand Down
4 changes: 1 addition & 3 deletions python/taichi/examples/simulation/waterwave.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ def reset():

@ti.func
def laplacian(i, j):
return (-4 * height[i, j] + height[i, j - 1] + height[i, j + 1] + height[i + 1, j] + height[i - 1, j]) / (
4 * dx**2
)
return (-4 * height[i, j] + height[i, j - 1] + height[i, j + 1] + height[i + 1, j] + height[i - 1, j]) / (4 * dx**2)


@ti.func
Expand Down
1 change: 1 addition & 0 deletions python/taichi/lang/ast/symbol_resolver.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Provides helpers to resolve AST nodes."""

import ast


Expand Down
10 changes: 5 additions & 5 deletions python/taichi/lang/struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,11 @@ def to_dict(self, include_methods=False, include_ndim=False):
Dict: The result dictionary.
"""
res_dict = {
k: v.to_dict(include_methods=include_methods, include_ndim=include_ndim)
if isinstance(v, Struct)
else v.to_list()
if isinstance(v, Matrix)
else v
k: (
v.to_dict(include_methods=include_methods, include_ndim=include_ndim)
if isinstance(v, Struct)
else v.to_list() if isinstance(v, Matrix) else v
)
for k, v in self.__entries.items()
}
if include_methods:
Expand Down
1 change: 1 addition & 0 deletions python/taichi/linalg/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Taichi support module for sparse matrix operations.
"""

from taichi.linalg.sparse_cg import SparseCG
from taichi.linalg.sparse_matrix import *
from taichi.linalg.sparse_solver import SparseSolver
Expand Down
1 change: 1 addition & 0 deletions python/taichi/math/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
The math module supports glsl-style vectors, matrices and functions.
"""

from ._complex import *
from .mathimpl import * # pylint: disable=W0622

Expand Down
1 change: 1 addition & 0 deletions python/taichi/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- `video` submodule for exporting results to video files.
- `diagnose` submodule for printing system environment information.
"""

from taichi.tools.diagnose import *
from taichi.tools.image import *
from taichi.tools.np2ply import *
Expand Down
1 change: 1 addition & 0 deletions python/taichi/types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- ndarray: for arbitrary arrays.
- quant: for quantized types, see "https://yuanming.taichi.graphics/publication/2021-quantaichi/quantaichi.pdf"
"""

from taichi.types import quant
from taichi.types.annotations import *
from taichi.types.compound_types import *
Expand Down
1 change: 1 addition & 0 deletions python/taichi/types/quant.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
This module defines generators of quantized types.
For more details, read https://yuanming.taichi.graphics/publication/2021-quantaichi/quantaichi.pdf.
"""

from taichi._lib.utils import ti_python_core as _ti_python_core
from taichi.lang import impl
from taichi.types.primitive_types import i32
Expand Down
1 change: 1 addition & 0 deletions python/taichi/ui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
This module contains a cpu based GUI system, a vulkan based GGUI system,
and other helper utilities like adding widgets and exporting video files.
"""

from .gui import *
from .ui import *
4 changes: 3 additions & 1 deletion taichi/analysis/gen_offline_cache_key.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,9 @@ class ASTSerializer : public IRVisitor, public ExpressionVisitor {
}

#define DEFINE_EMIT_ENUM(EnumType) \
void emit(EnumType type) { emit_pod(type); }
void emit(EnumType type) { \
emit_pod(type); \
}

DEFINE_EMIT_ENUM(ExprOpCode);
DEFINE_EMIT_ENUM(StmtOpCode);
Expand Down
2 changes: 1 addition & 1 deletion taichi/codegen/llvm/llvm_compiled_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class OffloadedTask {
: name(name),
block_dim(block_dim),
grid_dim(grid_dim),
dynamic_shared_array_bytes(dynamic_shared_array_bytes){};
dynamic_shared_array_bytes(dynamic_shared_array_bytes) {};
TI_IO_DEF(name, block_dim, grid_dim, dynamic_shared_array_bytes);
};

Expand Down
4 changes: 2 additions & 2 deletions taichi/codegen/spirv/kernel_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,8 @@ class KernelContextAttributes {
/**
* Get all argpacks.
*/
inline const std::vector<std::pair<std::vector<int>, const Type *>>
&argpack_types() const {
inline const std::vector<std::pair<std::vector<int>, const Type *>> &
argpack_types() const {
return argpack_types_;
}

Expand Down
4 changes: 2 additions & 2 deletions taichi/common/dict.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ class Dict {
}

template <typename T>
std::enable_if_t<std::is_reference<T>::value, std::remove_reference_t<T>>
&get(std::string key) const {
std::enable_if_t<std::is_reference<T>::value, std::remove_reference_t<T>> &
get(std::string key) const {
return *get_ptr<std::remove_reference_t<T>>(key);
}

Expand Down
4 changes: 2 additions & 2 deletions taichi/common/exceptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ struct ErrorEmitter {
std::string>>>
ErrorEmitter(E &&error, T p_dbg_info, std::string &&error_msg) {
if constexpr ((std::is_same_v<std::decay_t<T>, DebugInfo *> ||
std::is_same_v<std::decay_t<T>, const DebugInfo *>)&&std::
is_base_of_v<TaichiError, std::decay_t<E>>) {
std::is_same_v<std::decay_t<T>, const DebugInfo *>) &&
std::is_base_of_v<TaichiError, std::decay_t<E>>) {
// Indicates a failed C++ API call from Python side, we should not print
// tb here
error.msg_ = error_msg;
Expand Down
10 changes: 7 additions & 3 deletions taichi/common/interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,12 @@ class InterfaceHolder {
} \
} ImplementationInjector_##base_class_name##class_name##instance;

#define TI_NAME(alias) \
virtual std::string get_name() const override { return get_name_static(); } \
static std::string get_name_static() { return alias; }
#define TI_NAME(alias) \
virtual std::string get_name() const override { \
return get_name_static(); \
} \
static std::string get_name_static() { \
return alias; \
}

} // namespace taichi
13 changes: 7 additions & 6 deletions taichi/common/json_serde.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,13 @@ using remove_cvref_t = typename remove_cvref<T>::type;
template <typename T>
struct has_ptr_serde {
template <typename T_>
static constexpr auto helper(T_ *) -> std::is_same<
decltype((T_::jsonserde_ptr_io(std::declval<const T_ *&>(),
std::declval<JsonValue &>(),
std::declval<bool>(),
std::declval<bool>()))),
void>;
static constexpr auto helper(T_ *)
-> std::is_same<
decltype((T_::jsonserde_ptr_io(std::declval<const T_ *&>(),
std::declval<JsonValue &>(),
std::declval<bool>(),
std::declval<bool>()))),
void>;

template <typename>
static constexpr auto helper(...) -> std::false_type;
Expand Down
7 changes: 4 additions & 3 deletions taichi/common/serialization.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,10 @@ class Serializer {
template <typename T>
struct has_io {
template <typename T_>
static constexpr auto helper(T_ *) -> std::is_same<
decltype((std::declval<T_>().io(std::declval<Serializer &>()))),
void>;
static constexpr auto helper(T_ *)
-> std::is_same<
decltype((std::declval<T_>().io(std::declval<Serializer &>()))),
void>;

template <typename>
static constexpr auto helper(...) -> std::false_type;
Expand Down
6 changes: 4 additions & 2 deletions taichi/ir/expression.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,9 @@ class ExpressionVisitor {
bool invoke_default_visitor_{false};
};

#define TI_DEFINE_ACCEPT_FOR_EXPRESSION \
void accept(ExpressionVisitor *visitor) override { visitor->visit(this); }
#define TI_DEFINE_ACCEPT_FOR_EXPRESSION \
void accept(ExpressionVisitor *visitor) override { \
visitor->visit(this); \
}

} // namespace taichi::lang
12 changes: 9 additions & 3 deletions taichi/ir/expression_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,25 @@
Expr expr_##opname(const Expr &expr) { \
return Expr::make<UnaryOpExpression>(UnaryOpType::opname, expr); \
} \
Expr operator op(const Expr &expr) { return expr_##opname(expr); }
Expr operator op(const Expr &expr) { \
return expr_##opname(expr); \
}

#define DEFINE_EXPRESSION_FUNC_UNARY(opname) \
Expr opname(const Expr &expr) { \
return Expr::make<UnaryOpExpression>(UnaryOpType::opname, expr); \
} \
Expr expr_##opname(const Expr &expr) { return opname(expr); }
Expr expr_##opname(const Expr &expr) { \
return opname(expr); \
}

#define DEFINE_EXPRESSION_OP_BINARY(op, opname) \
Expr operator op(const Expr &lhs, const Expr &rhs) { \
return Expr::make<BinaryOpExpression>(BinaryOpType::opname, lhs, rhs); \
} \
Expr expr_##opname(const Expr &lhs, const Expr &rhs) { return lhs op rhs; }
Expr expr_##opname(const Expr &lhs, const Expr &rhs) { \
return lhs op rhs; \
}

#define DEFINE_EXPRESSION_FUNC_BINARY(opname) \
Expr opname(const Expr &lhs, const Expr &rhs) { \
Expand Down
5 changes: 3 additions & 2 deletions taichi/ir/ir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ class StatementTypeNameVisitor : public IRVisitor {
StatementTypeNameVisitor() {
}

#define PER_STATEMENT(x) \
void visit(x *stmt) override { type_name = #x; }
#define PER_STATEMENT(x) \
void visit(x *stmt) override{type_name = #x; \
}
#include "taichi/inc/statements.inc.h"

#undef PER_STATEMENT
Expand Down
6 changes: 4 additions & 2 deletions taichi/ir/ir.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,10 @@ class IRNode {
std::unique_ptr<IRNode> clone();
};

#define TI_DEFINE_ACCEPT \
void accept(IRVisitor *visitor) override { visitor->visit(this); }
#define TI_DEFINE_ACCEPT \
void accept(IRVisitor *visitor) override { \
visitor->visit(this); \
}

#define TI_DEFINE_CLONE \
std::unique_ptr<Stmt> clone() const override { \
Expand Down
Loading

0 comments on commit bb0251a

Please sign in to comment.