Skip to content

Commit 9ff9276

Browse files
committed
using python-style for loops in calculus
1 parent 0fd5967 commit 9ff9276

File tree

5 files changed

+35
-35
lines changed

5 files changed

+35
-35
lines changed

src/sage/calculus/interpolation.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ cdef class Spline:
135135
if i < len(self.v):
136136
self.v[i] = xy
137137
else:
138-
for j from len(self.v) <= j <= i:
138+
for j in range(len(self.v), i + 1):
139139
self.v.append((0, 0))
140140
self.v[i] = xy
141141
self.stop_interp()
@@ -262,7 +262,7 @@ cdef class Spline:
262262
raise MemoryError
263263

264264
cdef int i
265-
for i from 0 <= i < n:
265+
for i in range(n):
266266
self.x[i] = v[i][0]
267267
self.y[i] = v[i][1]
268268

src/sage/calculus/ode.pyx

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,20 @@ cdef int c_jac(double t,double *y,double *dfdy,double *dfdt,void *params):
6464
cdef int param_n
6565
cdef PyFunctionWrapper wrapper
6666
wrapper = <PyFunctionWrapper > params
67-
y_n=wrapper.y_n
68-
y_list=[]
69-
for i from 0<=i<y_n:
67+
y_n = wrapper.y_n
68+
y_list = []
69+
for i in range(y_n):
7070
y_list.append(y[i])
7171
try:
7272
if len(wrapper.the_parameters)==0:
7373
jac_list=wrapper.the_jacobian(t,y_list)
7474
else:
7575
jac_list=wrapper.the_jacobian(t,y_list,wrapper.the_parameters)
76-
for i from 0<=i<y_n:
77-
for j from 0<=j<y_n:
76+
for i in range(y_n):
77+
for j in range(y_n):
7878
dfdy[i*y_n+j]=jac_list[i][j]
7979

80-
for i from 0 <=i<y_n:
80+
for i in range(y_n):
8181
dfdt[i]=jac_list[y_n][i]
8282

8383
return GSL_SUCCESS
@@ -91,17 +91,17 @@ cdef int c_f(double t,double* y, double* dydt,void *params):
9191

9292
cdef PyFunctionWrapper wrapper
9393
wrapper = <PyFunctionWrapper> params
94-
y_n= wrapper.y_n
95-
y_list=[]
96-
for i from 0<=i<y_n:
94+
y_n = wrapper.y_n
95+
y_list = []
96+
for i in range(y_n):
9797
y_list.append(y[i])
9898
try:
9999
if len(wrapper.the_parameters)!=0:
100100
dydt_list=wrapper.the_function(t,y_list,wrapper.the_parameters)
101101
else:
102102
dydt_list=wrapper.the_function(t,y_list)
103-
for i from 0<=i<y_n:
104-
dydt[i]=dydt_list[i]
103+
for i in range(y_n):
104+
dydt[i] = dydt_list[i]
105105
return GSL_SUCCESS
106106
except Exception:
107107
return -1
@@ -453,15 +453,15 @@ class ode_solver():
453453
cdef double * scale_abs_array
454454
scale_abs_array=NULL
455455

456-
y= <double*> sig_malloc(sizeof(double)*(dim))
457-
if y==NULL:
456+
y = <double*> sig_malloc(sizeof(double)*(dim))
457+
if y == NULL:
458458
raise MemoryError("error allocating memory")
459-
result=[]
460-
v=[0]*dim
459+
result = []
460+
v = [0]*dim
461461
cdef gsl_odeiv_step_type * T
462462

463-
for i from 0 <=i< dim: #copy initial conditions into C array
464-
y[i]=self.y_0[i]
463+
for i in range(dim): # copy initial conditions into C array
464+
y[i] = self.y_0[i]
465465

466466
if self.algorithm == "rkf45":
467467
T=gsl_odeiv_step_rkf45
@@ -502,9 +502,9 @@ class ode_solver():
502502
if not self.scale_abs:
503503
c = gsl_odeiv_control_standard_new(self.error_abs,self.error_rel,self.a,self.a_dydt)
504504
elif hasattr(self.scale_abs,'__len__'):
505-
if len(self.scale_abs)==dim:
505+
if len(self.scale_abs) == dim:
506506
scale_abs_array =<double *> sig_malloc(dim*sizeof(double))
507-
for i from 0 <=i<dim:
507+
for i in range(dim):
508508
scale_abs_array[i]=self.scale_abs[i]
509509
c = gsl_odeiv_control_scaled_new(self.error_abs,self.error_rel,self.a,self.a_dydt,scale_abs_array,dim)
510510

@@ -551,11 +551,11 @@ class ode_solver():
551551
sig_free(y)
552552
sig_free(scale_abs_array)
553553
raise TypeError("numpoints must be integer")
554-
result.append( (self.t_span[0],self.y_0))
554+
result.append((self.t_span[0], self.y_0))
555555
delta = (self.t_span[1]-self.t_span[0])/(1.0*num_points)
556-
t =self.t_span[0]
557-
t_end=self.t_span[0]+delta
558-
for i from 0<i<=n:
556+
t = self.t_span[0]
557+
t_end = self.t_span[0]+delta
558+
for i in range(1, n + 1):
559559
while (t < t_end):
560560
try:
561561
sig_on()
@@ -571,17 +571,17 @@ class ode_solver():
571571
sig_free(scale_abs_array)
572572
raise ValueError("error solving")
573573

574-
for j from 0<=j<dim:
574+
for j in range(dim):
575575
v[j]=<double> y[j]
576576
result.append( (t,copy.copy(v)) )
577577
t = t_end
578578
t_end= t+delta
579579

580580
else:
581581
n = len(self.t_span)
582-
result.append((self.t_span[0],self.y_0))
583-
t=self.t_span[0]
584-
for i from 0<i<n:
582+
result.append((self.t_span[0], self.y_0))
583+
t = self.t_span[0]
584+
for i in range(1, n):
585585
t_end=self.t_span[i]
586586
while (t < t_end):
587587
try:

src/sage/calculus/riemann.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1412,7 +1412,7 @@ cpdef analytic_boundary(FLOAT_T t, int n, FLOAT_T epsilon):
14121412
"""
14131413
cdef FLOAT_T i
14141414
cdef FLOAT_T result = t
1415-
for i from 1 <= i < n+1:
1415+
for i in range(1, n + 1):
14161416
result += (2*(-1)**i/i)*(epsilon**i/(1+epsilon**(2*i)))*sin(2*i*t)
14171417
return result
14181418

src/sage/calculus/transforms/dwt.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ cdef class DiscreteWaveletTransform(GSLDoubleArray):
147147
x_min = 0
148148
if xmax is None:
149149
x_max = self.n
150-
for i from x_min <= i < x_max:
150+
for i in range(x_min, x_max):
151151
x = self.data[i]
152152
if i > 0:
153153
v.append(point([(i, x)], hue=(1, 1, 1), **args))

src/sage/calculus/transforms/fft.pyx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ AUTHORS:
1010
- L.F. Tabera Alonso (2013-3): Documentation
1111
"""
1212

13-
#*****************************************************************************
13+
# ****************************************************************************
1414
# Copyright (C) 2006 William Stein <[email protected]>
1515
#
1616
# This program is free software: you can redistribute it and/or modify
1717
# it under the terms of the GNU General Public License as published by
1818
# the Free Software Foundation, either version 2 of the License, or
1919
# (at your option) any later version.
20-
# http://www.gnu.org/licenses/
21-
#*****************************************************************************
20+
# https://www.gnu.org/licenses/
21+
# ****************************************************************************
2222

2323
from cysignals.memory cimport sig_malloc, sig_free
2424

@@ -257,7 +257,7 @@ cdef class FastFourierTransform_complex(FastFourierTransform_base):
257257
I = I.n()
258258
s = 1/(3*pi) # so arg gets scaled between -1/3 and 1/3.
259259

260-
for i from xmin <= i < xmax:
260+
for i in range(xmin, xmax):
261261
z = self.data[2*i] + I*self.data[2*i+1]
262262
mag = z.abs()
263263
arg = z.arg()*s

0 commit comments

Comments
 (0)