Skip to content

cylint cleanup in calculus #40329

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/sage/calculus/integration.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,8 @@ def numerical_integral(func, a, b=None,
_b = b
W = <gsl_integration_workspace*> gsl_integration_workspace_alloc(n)
sig_on()
gsl_integration_qag(&F,_a,_b,eps_abs,eps_rel,n,rule,W,&result,&abs_err)
gsl_integration_qag(&F, _a, _b, eps_abs, eps_rel,
n, rule, W, &result, &abs_err)
sig_off()

elif algorithm == "qags":
Expand Down
58 changes: 30 additions & 28 deletions src/sage/calculus/riemann.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,10 @@ cdef class Riemann_Map:
if self.exterior and (self.B > 1):
raise ValueError(
"The exterior map is undefined for multiply connected domains")
cdef np.ndarray[COMPLEX_T,ndim=2] cps = np.zeros([self.B, N],
dtype=COMPLEX)
cdef np.ndarray[COMPLEX_T,ndim=2] dps = np.zeros([self.B, N],
dtype=COMPLEX)
cdef np.ndarray[COMPLEX_T, ndim=2] cps = np.zeros([self.B, N],
dtype=COMPLEX)
cdef np.ndarray[COMPLEX_T, ndim=2] dps = np.zeros([self.B, N],
dtype=COMPLEX)
# Find the points on the boundaries and their derivatives.
if self.exterior:
for k in range(self.B):
Expand Down Expand Up @@ -324,11 +324,11 @@ cdef class Riemann_Map:
C = I / N * sadp # equivalent to -TWOPI / N * 1 / (TWOPI * I) * sadp
errinvalid = np.geterr()['invalid'] # checks the current error handling for invalid
errdivide = np.geterr()['divide'] # checks the current error handling for divide
np.seterr(divide='ignore',invalid='ignore')
np.seterr(divide='ignore', invalid='ignore')
K = np.array([C * sadp[t] * (normalized_dp/(cp-cp[t]) -
(normalized_dp[t]/(cp-cp[t])).conjugate())
for t in np.arange(NB)], dtype=np.complex128)
np.seterr(divide=errdivide,invalid=errinvalid) # resets the error handling
np.seterr(divide=errdivide, invalid=errinvalid) # resets the error handling
for i in range(NB):
K[i, i] = 1
# Nystrom Method for solving 2nd kind integrals
Expand Down Expand Up @@ -562,7 +562,7 @@ cdef class Riemann_Map:
p_vector[k, N] = (I / (3*N) * dps[k, 0] *
exp(I * theta_array[k, 0]))
self.p_vector = p_vector.flatten()
cdef np.ndarray[double complex, ndim=1] pq = self.cps[:,list(range(N))+[0]].flatten()
cdef np.ndarray[double complex, ndim=1] pq = self.cps[:, list(range(N))+[0]].flatten()
self.pre_q_vector = pq

cpdef riemann_map(self, COMPLEX_T pt):
Expand Down Expand Up @@ -819,12 +819,12 @@ cdef class Riemann_Map:
for i in range(x_points):
for j in range(y_points):
pt = 1/(xmin + 0.5*xstep + i*xstep + I*(ymin + 0.5*ystep + j*ystep))
z_values[j, i] = 1/(-np.dot(p_vector,1/(pre_q_vector - pt)))
z_values[j, i] = 1/(-np.dot(p_vector, 1/(pre_q_vector - pt)))
else:
for i in range(x_points):
for j in range(y_points):
pt = xmin + 0.5*xstep + i*xstep + I*(ymin + 0.5*ystep + j*ystep)
z_values[j, i] = -np.dot(p_vector,1/(pre_q_vector - pt))
z_values[j, i] = -np.dot(p_vector, 1/(pre_q_vector - pt))
return z_values, xmin, xmax, ymin, ymax

@options(interpolation='catrom')
Expand Down Expand Up @@ -1014,7 +1014,7 @@ cdef class Riemann_Map:
thickness,
withcolor,
min_mag),
(xmin, xmax), (ymin, ymax),options))
(xmin, xmax), (ymin, ymax), options))
return g + self.plot_boundaries(thickness = thickness)

@options(interpolation='catrom')
Expand Down Expand Up @@ -1153,12 +1153,12 @@ cpdef get_derivatives(np.ndarray[COMPLEX_T, ndim=2] z_values,
cdef np.ndarray[COMPLEX_T, ndim=2] xderiv
cdef np.ndarray[FLOAT_T, ndim = 2] dr, dtheta, zabs
# (f(x+delta)-f(x-delta))/2delta
xderiv = (z_values[1:-1,2:]-z_values[1:-1,:-2])/(2*xstep)
xderiv = (z_values[1:-1, 2:]-z_values[1:-1, :-2]) / (2 * xstep)
# b/c the function is analytic, we know the magnitude of its
# derivative is equal in all directions
dr = np.abs(xderiv)
# the abs(derivative) scaled by distance from origin
zabs = np.abs(z_values[1:-1,1:-1])
zabs = np.abs(z_values[1:-1, 1:-1])
dtheta = np.divide(dr, zabs)
return dr, dtheta

Expand Down Expand Up @@ -1259,26 +1259,26 @@ cpdef complex_to_spiderweb(np.ndarray[COMPLEX_T, ndim = 2] z_values,
circ_radii = []
if spokes != 0:
# both -pi and pi are included
spoke_angles = srange(-PI,PI+TWOPI/spokes,TWOPI/spokes)
spoke_angles = srange(-PI, PI+TWOPI/spokes, TWOPI/spokes)
else:
spoke_angles = []
for i in range(imax-2): # the d arrays are 1 smaller on each side
for j in range(jmax-2):
z = z_values[i+1,j+1]
z = z_values[i+1, j+1]
mag = abs(z)
arg = phase(z)
dmag = dr[i,j]
darg = dtheta[i,j]
dmag = dr[i, j]
darg = dtheta[i, j]
# points that change too rapidly are presumed to be borders
# points that are too small are presumed to be outside
if darg < DMAX and mag > min_mag:
for target in circ_radii:
if abs(mag - target)/dmag < precision:
rgb[i+1,j+1] = rgbcolor
rgb[i+1, j+1] = rgbcolor
break
for target in spoke_angles:
if abs(arg - target)/darg < precision:
rgb[i+1,j+1] = rgbcolor
rgb[i+1, j+1] = rgbcolor
break
return rgb

Expand Down Expand Up @@ -1472,7 +1472,7 @@ cpdef cauchy_kernel(t, args):
cdef COMPLEX_T z = args[1]
cdef int n = args[2]
part = args[3]
result = exp(I*analytic_boundary(t,n, epsilon))/(exp(I*t)+epsilon*exp(-I*t)-z) * \
result = exp(I*analytic_boundary(t, n, epsilon))/(exp(I*t)+epsilon*exp(-I*t)-z) * \
(I*exp(I*t)-I*epsilon*exp(-I*t))
if part == 'c':
return result
Expand All @@ -1486,9 +1486,11 @@ cpdef cauchy_kernel(t, args):

cpdef analytic_interior(COMPLEX_T z, int n, FLOAT_T epsilon):
"""
Provides a nearly exact computation of the Riemann Map of an interior
point of the ellipse with axes 1 + epsilon and 1 - epsilon. It is
primarily useful for testing the accuracy of the numerical Riemann Map.
Provide a nearly exact computation of the Riemann Map of an interior
point of the ellipse with axes 1 + epsilon and 1 - epsilon.

It is primarily useful for testing the accuracy of the numerical
Riemann Map.

INPUT:

Expand All @@ -1511,10 +1513,10 @@ cpdef analytic_interior(COMPLEX_T z, int n, FLOAT_T epsilon):
sage: abs(m.riemann_map(.5)-analytic_interior(.5, 20, .3)) < 10^-6
True
"""
# evaluates the Cauchy integral of the boundary, split into the real
# and imaginary results because numerical_integral can't handle complex data.
rp = 1/(TWOPI)*numerical_integral(cauchy_kernel,0,2*pi,
params = [epsilon,z,n,'i'])[0]
ip = 1/(TWOPI*I)*numerical_integral(cauchy_kernel,0,2*pi,
params = [epsilon,z,n,'r'])[0]
# evaluates the Cauchy integral of the boundary, split into the real and
# imaginary results because numerical_integral cannot handle complex data.
rp = 1 / (TWOPI) * numerical_integral(cauchy_kernel, 0, 2 * pi,
params=[epsilon, z, n, 'i'])[0]
ip = 1 / (TWOPI*I) * numerical_integral(cauchy_kernel, 0, 2 * pi,
params=[epsilon, z, n, 'r'])[0]
return rp + ip
20 changes: 11 additions & 9 deletions src/sage/calculus/transforms/dwt.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def WaveletTransform(n, wavelet_type, wavelet_k):
_k = int(wavelet_k)
if not is2pow(_n):
raise NotImplementedError("discrete wavelet transform only implemented when n is a 2-power")
return DiscreteWaveletTransform(_n,1,wavelet_type,_k)
return DiscreteWaveletTransform(_n, 1, wavelet_type, _k)


DWT = WaveletTransform
Expand All @@ -110,19 +110,19 @@ cdef class DiscreteWaveletTransform(GSLDoubleArray):
def __init__(self, size_t n, size_t stride, wavelet_type, size_t wavelet_k):
if not is2pow(n):
raise NotImplementedError("discrete wavelet transform only implemented when n is a 2-power")
GSLDoubleArray.__init__(self,n,stride)
GSLDoubleArray.__init__(self, n, stride)
if wavelet_type=="daubechies":
self.wavelet = <gsl_wavelet*> gsl_wavelet_alloc(gsl_wavelet_daubechies, wavelet_k)
elif wavelet_type == "daubechies_centered":
self.wavelet = <gsl_wavelet*> gsl_wavelet_alloc(gsl_wavelet_daubechies_centered,wavelet_k)
self.wavelet = <gsl_wavelet*> gsl_wavelet_alloc(gsl_wavelet_daubechies_centered, wavelet_k)
elif wavelet_type == "haar":
self.wavelet = <gsl_wavelet *> gsl_wavelet_alloc(gsl_wavelet_haar,wavelet_k)
self.wavelet = <gsl_wavelet *> gsl_wavelet_alloc(gsl_wavelet_haar, wavelet_k)
elif wavelet_type == "haar_centered":
self.wavelet = <gsl_wavelet*> gsl_wavelet_alloc(gsl_wavelet_haar_centered,wavelet_k)
self.wavelet = <gsl_wavelet*> gsl_wavelet_alloc(gsl_wavelet_haar_centered, wavelet_k)
elif wavelet_type == "bspline":
self.wavelet = <gsl_wavelet*> gsl_wavelet_alloc(gsl_wavelet_bspline,wavelet_k)
self.wavelet = <gsl_wavelet*> gsl_wavelet_alloc(gsl_wavelet_bspline, wavelet_k)
elif wavelet_type == "bspline_centered":
self.wavelet = <gsl_wavelet*> gsl_wavelet_alloc(gsl_wavelet_bspline_centered,wavelet_k)
self.wavelet = <gsl_wavelet*> gsl_wavelet_alloc(gsl_wavelet_bspline_centered, wavelet_k)
self.workspace = <gsl_wavelet_workspace*> gsl_wavelet_workspace_alloc(n)

def __dealloc__(self):
Expand All @@ -131,10 +131,12 @@ cdef class DiscreteWaveletTransform(GSLDoubleArray):
gsl_wavelet_workspace_free(self.workspace)

def forward_transform(self):
gsl_wavelet_transform_forward(self.wavelet,self.data,self.stride,self.n,self.workspace)
gsl_wavelet_transform_forward(self.wavelet, self.data,
self.stride, self.n, self.workspace)

def backward_transform(self):
gsl_wavelet_transform_inverse(self.wavelet,self.data,self.stride,self.n,self.workspace)
gsl_wavelet_transform_inverse(self.wavelet, self.data,
self.stride, self.n, self.workspace)

def plot(self, xmin=None, xmax=None, **args):
from sage.plot.point import point
Expand Down
Loading