Skip to content

Commit

Permalink
Merge pull request #26722 from haru-44/while_for
Browse files Browse the repository at this point in the history
use a `for` statement
  • Loading branch information
smichr committed Jun 18, 2024
2 parents 619ede1 + 81bf9ef commit 6b8e209
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 52 deletions.
4 changes: 1 addition & 3 deletions sympy/geometry/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,10 +336,9 @@ def hypot(x, y):

rv = [(0, 1)]
best_dist = hypot(p[1].x - p[0].x, p[1].y - p[0].y)
i = 2
left = 0
box = deque([0, 1])
while i < len(p):
for i in range(2, len(p)):
while left < i and p[i][0] - p[left][0] > best_dist:
box.popleft()
left += 1
Expand All @@ -354,7 +353,6 @@ def hypot(x, y):
continue
best_dist = d
box.append(i)
i += 1

return {tuple([p[i] for i in pair]) for pair in rv}

Expand Down
4 changes: 1 addition & 3 deletions sympy/liealgebras/type_a.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,9 @@ def cartan_matrix(self):

n = self.n
m = 2 * eye(n)
i = 1
while i < n-1:
for i in range(1, n - 1):
m[i, i+1] = -1
m[i, i-1] = -1
i += 1
m[0,1] = -1
m[n-1, n-2] = -1
return m
Expand Down
4 changes: 1 addition & 3 deletions sympy/liealgebras/type_b.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,9 @@ def cartan_matrix(self):

n = self.n
m = 2* eye(n)
i = 1
while i < n-1:
for i in range(1, n - 1):
m[i, i+1] = -1
m[i, i-1] = -1
i += 1
m[0, 1] = -1
m[n-2, n-1] = -2
m[n-1, n-2] = -1
Expand Down
4 changes: 1 addition & 3 deletions sympy/liealgebras/type_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,9 @@ def cartan_matrix(self):

n = self.n
m = 2 * eye(n)
i = 1
while i < n-1:
for i in range(1, n - 1):
m[i, i+1] = -1
m[i, i-1] = -1
i += 1
m[0,1] = -1
m[n-1, n-2] = -2
return m
Expand Down
4 changes: 1 addition & 3 deletions sympy/liealgebras/type_d.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,9 @@ def cartan_matrix(self):

n = self.n
m = 2*eye(n)
i = 1
while i < n-2:
for i in range(1, n - 2):
m[i,i+1] = -1
m[i,i-1] = -1
i += 1
m[n-2, n-3] = -1
m[n-3, n-1] = -1
m[n-1, n-3] = -1
Expand Down
4 changes: 1 addition & 3 deletions sympy/liealgebras/type_e.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,9 @@ def cartan_matrix(self):

n = self.n
m = 2*eye(n)
i = 3
while i < n-1:
for i in range(3, n - 1):
m[i, i+1] = -1
m[i, i-1] = -1
i += 1
m[0, 2] = m[2, 0] = -1
m[1, 3] = m[3, 1] = -1
m[2, 3] = -1
Expand Down
15 changes: 5 additions & 10 deletions sympy/matrices/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,24 +225,19 @@ def _eval_get_diag_blocks(self):
sub_blocks = []

def recurse_sub_blocks(M):
i = 1
while i <= M.shape[0]:
for i in range(1, M.shape[0] + 1):
if i == 1:
to_the_right = M[0, i:]
to_the_bottom = M[i:, 0]
else:
to_the_right = M[:i, i:]
to_the_bottom = M[i:, :i]
if any(to_the_right) or any(to_the_bottom):
i += 1
continue
else:
sub_blocks.append(M[:i, :i])
if M.shape == M[:i, :i].shape:
return
else:
recurse_sub_blocks(M[i:, i:])
return
sub_blocks.append(M[:i, :i])
if M.shape != M[:i, :i].shape:
recurse_sub_blocks(M[i:, i:])
return

recurse_sub_blocks(self)
return sub_blocks
Expand Down
15 changes: 5 additions & 10 deletions sympy/matrices/matrixbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,24 +188,19 @@ def _eval_get_diag_blocks(self):
sub_blocks = []

def recurse_sub_blocks(M):
i = 1
while i <= M.shape[0]:
for i in range(1, M.shape[0] + 1):
if i == 1:
to_the_right = M[0, i:]
to_the_bottom = M[i:, 0]
else:
to_the_right = M[:i, i:]
to_the_bottom = M[i:, :i]
if any(to_the_right) or any(to_the_bottom):
i += 1
continue
else:
sub_blocks.append(M[:i, :i])
if M.shape == M[:i, :i].shape:
return
else:
recurse_sub_blocks(M[i:, i:])
return
sub_blocks.append(M[:i, :i])
if M.shape != M[:i, :i].shape:
recurse_sub_blocks(M[i:, i:])
return

recurse_sub_blocks(self)
return sub_blocks
Expand Down
5 changes: 2 additions & 3 deletions sympy/simplify/radsimp.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,8 @@ def make_expression(terms):
for term, rat, sym, deriv in terms:
if deriv is not None:
var, order = deriv

while order > 0:
term, order = Derivative(term, var), order - 1
for _ in range(order):
term = Derivative(term, var)

if sym is None:
if rat is S.One:
Expand Down
4 changes: 1 addition & 3 deletions sympy/utilities/enumerative.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,9 @@ def multiset_partitions_taocp(multiplicities):
while True:
while True:
# Step M2 (Subtract v from u)
j = a
k = b
x = False
while j < b:
for j in range(a, b):
pstack[k].u = pstack[j].u - pstack[j].v
if pstack[k].u == 0:
x = True
Expand All @@ -259,7 +258,6 @@ def multiset_partitions_taocp(multiplicities):
pstack[k].c = pstack[j].c
pstack[k].v = pstack[k].u
k = k + 1
j = j + 1
# Note: x is True iff v has changed

# Step M3 (Push if nonzero.)
Expand Down
5 changes: 1 addition & 4 deletions sympy/vector/coordsysrect.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,13 +517,10 @@ def rotation_matrix(self, other):
# Else, use tree to calculate position
rootindex, path = _path(self, other)
result = eye(3)
i = -1
for i in range(rootindex):
result *= path[i]._parent_rotation_matrix
i += 2
while i < len(path):
for i in range(rootindex + 1, len(path)):
result *= path[i]._parent_rotation_matrix.T
i += 1
return result

@cacheit
Expand Down
5 changes: 1 addition & 4 deletions sympy/vector/point.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,10 @@ def position_wrt(self, other):
# Else, use point tree to calculate position
rootindex, path = _path(self, other)
result = Vector.zero
i = -1
for i in range(rootindex):
result += path[i]._pos
i += 2
while i < len(path):
for i in range(rootindex + 1, len(path)):
result -= path[i]._pos
i += 1
return result

def locate_new(self, name, position):
Expand Down

0 comments on commit 6b8e209

Please sign in to comment.