Skip to content

Commit

Permalink
Merge pull request #26555 from haru-44/enumerate
Browse files Browse the repository at this point in the history
Remove unnecessary `enumerate`
  • Loading branch information
oscarbenjamin committed Apr 30, 2024
2 parents e8ffa81 + 14f14ba commit 7c4f580
Show file tree
Hide file tree
Showing 22 changed files with 48 additions and 48 deletions.
2 changes: 1 addition & 1 deletion sympy/combinatorics/polyhedron.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ def _pgroup_of_double(polyh, ordered_faces, pgroup):
range(len(ordered_faces))))
flat_faces = flatten(ordered_faces)
new_pgroup = []
for i, p in enumerate(pgroup):
for p in pgroup:
h = polyh.copy()
h.rotate(p)
c = h.corners
Expand Down
2 changes: 1 addition & 1 deletion sympy/combinatorics/tensor_can.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ def canonical_free(base, gens, g, num_free):
if x not in base:
base.append(x)
h = g
for i, transv in enumerate(transversals):
for transv in transversals:
h_i = [size]*num_free
# find the element s in transversals[i] such that
# _af_rmul(h, s) has its free elements with the lowest position in h
Expand Down
2 changes: 1 addition & 1 deletion sympy/concrete/summations.py
Original file line number Diff line number Diff line change
Expand Up @@ -1602,7 +1602,7 @@ def get_residue_factor(numer, denom, alternating):

def _eval_matrix_sum(expression):
f = expression.function
for n, limit in enumerate(expression.limits):
for limit in expression.limits:
i, a, b = limit
dif = b - a
if dif.is_Integer:
Expand Down
6 changes: 3 additions & 3 deletions sympy/holonomic/holonomic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2626,9 +2626,9 @@ def _extend_y0(Holonomic, n):
R = annihilator.parent.base
K = R.get_field()

for i, j in enumerate(annihilator.listofpoly):
if isinstance(j, annihilator.parent.base.dtype):
listofpoly.append(K.new(j.to_list()))
for j in annihilator.listofpoly:
if isinstance(j, annihilator.parent.base.dtype):
listofpoly.append(K.new(j.to_list()))

if len(y0) < a or n <= len(y0):
return y0
Expand Down
2 changes: 1 addition & 1 deletion sympy/ntheory/qs.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def _initialize_first_polynomial(N, M, factor_base, idx_1000, idx_5000, seed=Non
q = best_q

B = []
for idx, val in enumerate(q):
for val in q:
q_l = factor_base[val].prime
gamma = factor_base[val].tmem_p * invert(a // q_l, q_l) % q_l
if gamma > q_l / 2:
Expand Down
4 changes: 2 additions & 2 deletions sympy/physics/control/lti.py
Original file line number Diff line number Diff line change
Expand Up @@ -3256,9 +3256,9 @@ def __new__(cls, arg):
`arg` param in TransferFunctionMatrix should
strictly be a nested list containing TransferFunction
objects."""))
for row_index, row in enumerate(arg):
for row in arg:
temp = []
for col_index, element in enumerate(row):
for element in row:
if not isinstance(element, SISOLinearTimeInvariant):
raise TypeError(filldedent("""
Each element is expected to be of
Expand Down
8 changes: 4 additions & 4 deletions sympy/physics/vector/dyadic.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,13 @@ def dot(self, other):
if isinstance(other, Dyadic):
other = _check_dyadic(other)
ol = Dyadic(0)
for i, v in enumerate(self.args):
for i2, v2 in enumerate(other.args):
for v in self.args:
for v2 in other.args:
ol += v[0] * v2[0] * (v[2].dot(v2[1])) * (v[1].outer(v2[2]))
else:
other = _check_vector(other)
ol = Vector(0)
for i, v in enumerate(self.args):
for v in self.args:
ol += v[0] * v[1] * (v[2].dot(other))
return ol

Expand Down Expand Up @@ -320,7 +320,7 @@ def cross(self, other):
from sympy.physics.vector.vector import _check_vector
other = _check_vector(other)
ol = Dyadic(0)
for i, v in enumerate(self.args):
for v in self.args:
ol += v[0] * (v[1].outer((v[2].cross(other))))
return ol

Expand Down
8 changes: 4 additions & 4 deletions sympy/physics/vector/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def express(expr, frame, frame2=None, variables=False):
expr = expr.subs(subs_dict)
# Re-express in this frame
outvec = Vector([])
for i, v in enumerate(expr.args):
for v in expr.args:
if v[1] != frame:
temp = frame.dcm(v[1]) * v[0]
if Vector.simp:
Expand All @@ -118,7 +118,7 @@ def express(expr, frame, frame2=None, variables=False):
frame2 = frame
_check_frame(frame2)
ol = Dyadic(0)
for i, v in enumerate(expr.args):
for v in expr.args:
ol += express(v[0], frame, variables=variables) * \
(express(v[1], frame, variables=variables) |
express(v[2], frame2, variables=variables))
Expand Down Expand Up @@ -198,7 +198,7 @@ def time_derivative(expr, frame, order=1):

if isinstance(expr, Vector):
outlist = []
for i, v in enumerate(expr.args):
for v in expr.args:
if v[1] == frame:
outlist += [(express(v[0], frame, variables=True).diff(t),
frame)]
Expand All @@ -210,7 +210,7 @@ def time_derivative(expr, frame, order=1):

if isinstance(expr, Dyadic):
ol = Dyadic(0)
for i, v in enumerate(expr.args):
for v in expr.args:
ol += (v[0].diff(t) * (v[1] | v[2]))
ol += (v[0] * (time_derivative(v[1], frame) | v[2]))
ol += (v[0] * (v[1] | time_derivative(v[2], frame)))
Expand Down
6 changes: 3 additions & 3 deletions sympy/physics/vector/point.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ def _pdict_list(self, other, num):
oldlist = [[]]
while outlist != oldlist:
oldlist = outlist[:]
for i, v in enumerate(outlist):
for v in outlist:
templist = v[-1]._pdlist[num].keys()
for i2, v2 in enumerate(templist):
for v2 in templist:
if not v.__contains__(v2):
littletemplist = v + [v2]
if not outlist.__contains__(littletemplist):
outlist.append(littletemplist)
for i, v in enumerate(oldlist):
for v in oldlist:
if v[-1] != other:
outlist.remove(v)
outlist.sort(key=len)
Expand Down
10 changes: 5 additions & 5 deletions sympy/physics/vector/vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,13 @@ def dot(self, other):
if isinstance(other, Dyadic):
other = _check_dyadic(other)
ol = Vector(0)
for i, v in enumerate(other.args):
for v in other.args:
ol += v[0] * v[2] * (v[1].dot(self))
return ol
other = _check_vector(other)
out = S.Zero
for i, v1 in enumerate(self.args):
for j, v2 in enumerate(other.args):
for v1 in self.args:
for v2 in other.args:
out += ((v2[0].T) * (v2[1].dcm(v1[1])) * (v1[0]))[0]
if Vector.simp:
return trigsimp(out, recursive=True)
Expand Down Expand Up @@ -205,8 +205,8 @@ def outer(self, other):
from sympy.physics.vector.dyadic import Dyadic
other = _check_vector(other)
ol = Dyadic(0)
for i, v in enumerate(self.args):
for i2, v2 in enumerate(other.args):
for v in self.args:
for v2 in other.args:
# it looks this way because if we are in the same frame and
# use the enumerate function on the same frame in a nested
# fashion, then bad things happen
Expand Down
2 changes: 1 addition & 1 deletion sympy/polys/matrices/linsolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def _linear_eq_to_dict(eqs, syms):
coeffs = []
ind = []
symset = set(syms)
for i, e in enumerate(eqs):
for e in eqs:
if e.is_Equality:
coeff, terms = _lin_eq2dict(e.lhs, symset)
cR, tR = _lin_eq2dict(e.rhs, symset)
Expand Down
4 changes: 2 additions & 2 deletions sympy/printing/pretty/pretty.py
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,7 @@ def _print_MIMOSeries(self, expr):
from sympy.physics.control.lti import MIMOParallel
args = list(expr.args)
pretty_args = []
for i, a in enumerate(reversed(args)):
for a in reversed(args):
if (isinstance(a, MIMOParallel) and len(expr.args) > 1):
expression = self._print(a)
expression.baseline = expression.height()//2
Expand Down Expand Up @@ -1257,7 +1257,7 @@ def _printer_tensor_indices(self, name, indices, index_map={}):
last_valence = None
prev_map = None

for i, index in enumerate(indices):
for index in indices:
indpic = self._print(index.args[0])
if ((index in index_map) or prev_map) and last_valence == index.is_up:
if index.is_up:
Expand Down
2 changes: 1 addition & 1 deletion sympy/solvers/diophantine/diophantine.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ def solve(self, parameters=None, limit=None):
for Ai, Bi in zip(A, B):
tot_x, tot_y = [], []

for j, arg in enumerate(Add.make_args(c)):
for arg in Add.make_args(c):
if arg.is_Integer:
# example: 5 -> k = 5
k, p = arg, S.One
Expand Down
2 changes: 1 addition & 1 deletion sympy/solvers/ode/systems.py
Original file line number Diff line number Diff line change
Expand Up @@ -1746,7 +1746,7 @@ def _weak_component_solver(wcc, t):

sol = []

for j, scc in enumerate(wcc):
for scc in wcc:
eqs = scc
funcs = _get_funcs_from_canon(eqs)

Expand Down
2 changes: 1 addition & 1 deletion sympy/solvers/pde.py
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ def _simplify_variable_coeff(sol, syms, func, funcarg):
final = sol.subs(sym, func(funcarg))

else:
for key, sym in enumerate(syms):
for sym in syms:
final = sol.subs(sym, func(funcarg))

return simplify(final.subs(eta, funcarg))
Expand Down
4 changes: 2 additions & 2 deletions sympy/solvers/solvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def recast_to_symbols(eqs, symbols):
symbols = list(ordered(symbols))
swap_sym = {}
i = 0
for j, s in enumerate(symbols):
for s in symbols:
if not isinstance(s, Symbol) and s not in swap_sym:
swap_sym[s] = Dummy('X%d' % i)
i += 1
Expand Down Expand Up @@ -1418,7 +1418,7 @@ def _solve(f, *symbols, **flags):
f = f.simplify() # failure imminent w/o help

cond = neg = True
for i, (expr, cnd) in enumerate(f.args):
for expr, cnd in f.args:
# the explicit condition for this expr is the current cond
# and none of the previous conditions
cond = And(neg, cnd)
Expand Down
4 changes: 2 additions & 2 deletions sympy/tensor/array/expressions/array_expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,7 @@ def _lower_contraction_to_addends(cls, expr, contraction_indices):
contraction_indices_remaining = []
contraction_indices_args = [[] for i in expr.args]
backshift = set()
for i, contraction_group in enumerate(contraction_indices):
for contraction_group in contraction_indices:
for j in range(len(expr.args)):
if not isinstance(expr.args[j], ArrayAdd):
continue
Expand Down Expand Up @@ -1795,7 +1795,7 @@ def to_array_contraction(self):
def get_contraction_indices(self) -> List[List[int]]:
contraction_indices: List[List[int]] = [[] for i in range(self.number_of_contraction_indices)]
current_position: int = 0
for i, arg_with_ind in enumerate(self.args_with_ind):
for arg_with_ind in self.args_with_ind:
for j in arg_with_ind.indices:
if j is not None:
contraction_indices[j].append(current_position)
Expand Down
4 changes: 2 additions & 2 deletions sympy/tensor/array/expressions/from_array_to_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def _find_trivial_kronecker_products_broadcast(expr: ArrayTensorProduct):
newargs: List[Basic] = []
removed = []
count_dims = 0
for i, arg in enumerate(expr.args):
for arg in expr.args:
count_dims += get_rank(arg)
shape = get_shape(arg)
current_range = [count_dims-i for i in range(len(shape), 0, -1)]
Expand Down Expand Up @@ -443,7 +443,7 @@ def _(expr: PermuteDims):
pinv = _af_invert(expr.permutation.array_form)
shift = list(accumulate([1 if i in subremoved else 0 for i in range(len(p))]))
premoved = [pinv[i] for i in subremoved]
p2 = [e - shift[e] for i, e in enumerate(p) if e not in subremoved]
p2 = [e - shift[e] for e in p if e not in subremoved]
# TODO: check if subremoved should be permuted as well...
newexpr = _permute_dims(subexpr, p2)
premoved = sorted(premoved)
Expand Down
2 changes: 1 addition & 1 deletion sympy/tensor/array/ndim_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def _parse_index(self, index):

def _get_tuple_index(self, integer_index):
index = []
for i, sh in enumerate(reversed(self.shape)):
for sh in reversed(self.shape):
index.append(integer_index % sh)
integer_index //= sh
index.reverse()
Expand Down
6 changes: 3 additions & 3 deletions sympy/tensor/tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3323,7 +3323,7 @@ def _indices_to_free_dum(args_indices):

for pos1, arg_indices in enumerate(args_indices):

for index_pos, index in enumerate(arg_indices):
for index in arg_indices:
if not isinstance(index, TensorIndex):
raise TypeError("expected TensorIndex")
if -index in free2pos1:
Expand Down Expand Up @@ -3498,7 +3498,7 @@ def _get_dummy_indices_set(self):
def _get_position_offset_for_indices(self):
arg_offset = [None for i in range(self.ext_rank)]
counter = 0
for i, arg in enumerate(self.args):
for arg in self.args:
if not isinstance(arg, TensExpr):
continue
for j in range(arg.ext_rank):
Expand Down Expand Up @@ -3927,7 +3927,7 @@ def contract_metric(self, g):
continue
shifts[i] = shift
free = [(ind, p - shifts[pos_map[p]]) for (ind, p) in free if pos_map[p] not in elim]
dum = [(p0 - shifts[pos_map[p0]], p1 - shifts[pos_map[p1]]) for i, (p0, p1) in enumerate(dum) if pos_map[p0] not in elim and pos_map[p1] not in elim]
dum = [(p0 - shifts[pos_map[p0]], p1 - shifts[pos_map[p1]]) for p0, p1 in dum if pos_map[p0] not in elim and pos_map[p1] not in elim]

res = sign*TensMul(*args).doit()
if not isinstance(res, TensExpr):
Expand Down
12 changes: 6 additions & 6 deletions sympy/utilities/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -1428,7 +1428,7 @@ def _get_routine_opening(self, routine):

# Inputs
args = []
for i, arg in enumerate(routine.arguments):
for arg in routine.arguments:
if isinstance(arg, OutputArgument):
raise CodeGenError("Julia: invalid argument of type %s" %
str(type(arg)))
Expand Down Expand Up @@ -1463,7 +1463,7 @@ def _get_routine_ending(self, routine):
def _call_printer(self, routine):
declarations = []
code_lines = []
for i, result in enumerate(routine.results):
for result in routine.results:
if isinstance(result, Result):
assign_to = result.result_var
else:
Expand Down Expand Up @@ -1636,7 +1636,7 @@ def _get_routine_opening(self, routine):

# Outputs
outs = []
for i, result in enumerate(routine.results):
for result in routine.results:
if isinstance(result, Result):
# Note: name not result_var; want `y` not `y(i)` for Indexed
s = self._get_symbol(result.name)
Expand All @@ -1651,7 +1651,7 @@ def _get_routine_opening(self, routine):

# Inputs
args = []
for i, arg in enumerate(routine.arguments):
for arg in routine.arguments:
if isinstance(arg, (OutputArgument, InOutArgument)):
raise CodeGenError("Octave: invalid argument of type %s" %
str(type(arg)))
Expand Down Expand Up @@ -1681,7 +1681,7 @@ def _get_routine_ending(self, routine):
def _call_printer(self, routine):
declarations = []
code_lines = []
for i, result in enumerate(routine.results):
for result in routine.results:
if isinstance(result, Result):
assign_to = result.result_var
else:
Expand Down Expand Up @@ -1920,7 +1920,7 @@ def _call_printer(self, routine):
if isinstance(arg, ResultBase) and not arg.dimensions:
dereference.append(arg.name)

for i, result in enumerate(routine.results):
for result in routine.results:
if isinstance(result, Result):
assign_to = result.result_var
returns.append(str(result.result_var))
Expand Down
2 changes: 1 addition & 1 deletion sympy/vector/basisdependent.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def __new__(cls, *args, **options):
components = {}

# Check each arg and simultaneously learn the components
for i, arg in enumerate(args):
for arg in args:
if not isinstance(arg, cls._expr_type):
if isinstance(arg, Mul):
arg = cls._mul_func(*(arg.args))
Expand Down

0 comments on commit 7c4f580

Please sign in to comment.