Skip to content

Commit

Permalink
Auto Format
Browse files Browse the repository at this point in the history
  • Loading branch information
taichi-gardener committed Nov 16, 2021
1 parent f0fb3f4 commit 17b2f12
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions python/taichi/lang/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,8 @@ def inverse(self):
return Matrix([1 / self(0, 0)])
if self.n == 2:
inv_determinant = impl.expr_init(1.0 / self.determinant())
return inv_determinant * Matrix([[self(1, 1), -self(0, 1)],
[-self(1, 0), self(0, 0)]])
return inv_determinant * Matrix([[self(
1, 1), -self(0, 1)], [-self(1, 0), self(0, 0)]])
if self.n == 3:
n = 3
inv_determinant = impl.expr_init(1.0 / self.determinant())
Expand All @@ -508,16 +508,14 @@ def E(x, y):

for i in range(n):
for j in range(n):
entries[j][i] = inv_determinant * (-1)**(i + j) * (
(E(i + 1, j + 1) *
(E(i + 2, j + 2) * E(i + 3, j + 3) -
E(i + 3, j + 2) * E(i + 2, j + 3)) -
E(i + 2, j + 1) *
(E(i + 1, j + 2) * E(i + 3, j + 3) -
E(i + 3, j + 2) * E(i + 1, j + 3)) +
E(i + 3, j + 1) *
(E(i + 1, j + 2) * E(i + 2, j + 3) -
E(i + 2, j + 2) * E(i + 1, j + 3))))
entries[j][i] = inv_determinant * (-1)**(i + j) * ((
E(i + 1, j + 1) *
(E(i + 2, j + 2) * E(i + 3, j + 3) -
E(i + 3, j + 2) * E(i + 2, j + 3)) - E(i + 2, j + 1) *
(E(i + 1, j + 2) * E(i + 3, j + 3) -
E(i + 3, j + 2) * E(i + 1, j + 3)) + E(i + 3, j + 1) *
(E(i + 1, j + 2) * E(i + 2, j + 3) -
E(i + 2, j + 2) * E(i + 1, j + 3))))
return Matrix(entries)
raise Exception(
"Inversions of matrices with sizes >= 5 are not supported")
Expand Down Expand Up @@ -564,7 +562,8 @@ def transpose(self):
Get the transpose of a matrix.
"""
return Matrix([[self[i, j] for i in range(self.n)] for j in range(self.m)])
return Matrix([[self[i, j] for i in range(self.n)]
for j in range(self.m)])

@taichi_scope
def determinant(a):
Expand Down Expand Up @@ -837,7 +836,8 @@ def identity(dt, n):
:class:`~taichi.lang.matrix.Matrix`: A n x n identity :class:`~taichi.lang.matrix.Matrix` instance.
"""
return Matrix([[ti.cast(int(i == j), dt) for j in range(n)] for i in range(n)])
return Matrix([[ti.cast(int(i == j), dt) for j in range(n)]
for i in range(n)])

@staticmethod
def rotation2d(alpha):
Expand Down Expand Up @@ -1140,7 +1140,8 @@ def outer_product(self, other):
impl.static(
impl.static_assert(other.m == 1,
"rhs for outer_product is not a vector"))
return Matrix([[self[i] * other[j] for j in range(other.n)] for i in range(self.n)])
return Matrix([[self[i] * other[j] for j in range(other.n)]
for i in range(self.n)])


def Vector(n, dt=None, **kwargs):
Expand Down

0 comments on commit 17b2f12

Please sign in to comment.