Skip to content

Commit

Permalink
[Refactor] Fix typo and type in docstring, and format too long string (
Browse files Browse the repository at this point in the history
…#3530)

* fix typo and type in docstring, and format too long string

* format type
  • Loading branch information
gaoxinge committed Nov 17, 2021
1 parent c21fa24 commit fcbe8c9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
12 changes: 7 additions & 5 deletions python/taichi/lang/kernel_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,14 +286,14 @@ def extract_arg(arg, anno):
shape = tuple(arg.shape)
if len(shape) < element_dim:
raise ValueError(
f"Invalid argument into ti.any_arr() - required element_dim={element_dim}, but the argument has only {len(shape)} dimensions"
)
f"Invalid argument into ti.any_arr() - required element_dim={element_dim}, "
f"but the argument has only {len(shape)} dimensions")
element_shape = (
) if element_dim == 0 else shape[:
element_dim] if layout == Layout.SOA else shape[
-element_dim:]
return to_taichi_type(arg.dtype), len(shape), element_shape, layout
return (type(arg).__name__, )
return type(arg).__name__,

def extract(self, args):
extracted = []
Expand Down Expand Up @@ -451,8 +451,10 @@ def taichi_ast_generator():
_taichi_skip_traceback = 1
if self.runtime.inside_kernel:
raise TaichiSyntaxError(
"Kernels cannot call other kernels. I.e., nested kernels are not allowed. Please check if you have direct/indirect invocation of kernels within kernels. Note that some methods provided by the Taichi standard library may invoke kernels, and please move their invocations to Python-scope."
)
"Kernels cannot call other kernels. I.e., nested kernels are not allowed. "
"Please check if you have direct/indirect invocation of kernels within kernels. "
"Note that some methods provided by the Taichi standard library may invoke kernels, "
"and please move their invocations to Python-scope.")
self.runtime.inside_kernel = True
self.runtime.current_kernel = self
try:
Expand Down
18 changes: 9 additions & 9 deletions python/taichi/lang/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class Matrix(TaichiOperations):
"""The matrix class.
Args:
n (int): the first dimension of a matrix.
n (Union[int, list, tuple], np.ndarray): the first dimension of a matrix.
m (int): the second dimension of a matrix.
dt (DataType): the elmement data type.
dt (DataType): the element data type.
keep_raw (Bool, optional): Keep the contents in `n` as is.
"""
is_taichi_class = True
Expand Down Expand Up @@ -143,8 +143,8 @@ def __init__(self,
self.m = m
else:
raise ValueError(
"Declaring matrix fields using `ti.Matrix(n, m, dt, shape)` is no longer supported. Use `ti.Matrix.field(n, m, dtype, shape)` instead."
)
"Declaring matrix fields using `ti.Matrix(n, m, dt, shape)` is no longer supported. "
"Use `ti.Matrix.field(n, m, dtype, shape)` instead.")

if self.n * self.m > 32 and not suppress_warning:
warning(
Expand Down Expand Up @@ -587,7 +587,7 @@ def diag(dim, val):
Args:
dim (int): the dimension of a square matrix.
val (TypeVar): the diagonal elment value.
val (TypeVar): the diagonal element value.
Returns:
The constructed diagonal square matrix.
Expand Down Expand Up @@ -654,7 +654,7 @@ def max(self):

@kern_mod.pyfunc
def min(self):
"""Return the minumum element value."""
"""Return the minimum element value."""
return ops_mod.ti_min(*self.entries)

def any(self):
Expand Down Expand Up @@ -970,7 +970,7 @@ def _Vector_ndarray(cls, n, dtype, shape, layout=Layout.AOS):

@staticmethod
def rows(rows):
"""Construct a Matrix instance by concactinating Vectors/lists row by row.
"""Construct a Matrix instance by concatenating Vectors/lists row by row.
Args:
rows (List): A list of Vector (1-D Matrix) or a list of list.
Expand Down Expand Up @@ -1003,7 +1003,7 @@ def rows(rows):

@staticmethod
def cols(cols):
"""Construct a Matrix instance by concactinating Vectors/lists column by column.
"""Construct a Matrix instance by concatenating Vectors/lists column by column.
Args:
cols (List): A list of Vector (1-D Matrix) or a list of list.
Expand Down Expand Up @@ -1124,7 +1124,7 @@ def Vector(n, dt=None, **kwargs):
"""Construct a `Vector` instance i.e. 1-D Matrix.
Args:
n (int): The desired number of entries of the Vector.
n (Union[int, list, tuple], np.ndarray): The desired number of entries of the Vector.
dt (DataType, optional): The desired data type of the Vector.
Returns:
Expand Down
3 changes: 2 additions & 1 deletion python/taichi/misc/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def core_vec(*args):
assert False, type(args[0])


class Tee():
class Tee:
def __init__(self, name):
with open(name, 'w') as self.file:
self.stdout = sys.stdout
Expand Down Expand Up @@ -256,6 +256,7 @@ def print_async_stats(include_kernel_profiler=False):
'core_vec',
'core_veci',
'deprecated',
'warning',
'dump_dot',
'dot_to_pdf',
'obsolete',
Expand Down

0 comments on commit fcbe8c9

Please sign in to comment.