-
Notifications
You must be signed in to change notification settings - Fork 2
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
Sourcery refactored master branch #2
Conversation
return [(x[0] * x[1], x[1] - 1) for x in Fx if (x[1]-1) > -1] | ||
return [(x[0] * x[1], x[1] - 1) for x in Fx if x[1] > 0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function FormalDerivative
refactored with the following changes:
- Simplify numeric comparison (
simplify-numeric-comparison
)
if b & 1 == 0: | ||
return gcd(a, b >> 1) | ||
else: | ||
return gcd(abs(a - b), min(a, b)) | ||
return gcd(a, b >> 1) if b & 1 == 0 else gcd(abs(a - b), min(a, b)) | ||
else: | ||
if b & 1 == 1: | ||
return gcd(a >> 1, b) | ||
else: | ||
return 2 * gcd(a >> 1, b >> 1) | ||
return gcd(a >> 1, b) if b & 1 == 1 else 2 * gcd(a >> 1, b >> 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function gcd
refactored with the following changes:
- Replace if statement with if expression [×2] (
assign-if-exp
)
tmp = [] | ||
for n in range(0, N / 2): | ||
tmp.append(histogram[n] * 2) | ||
return tmp | ||
return [histogram[n] * 2 for n in range(0, N / 2)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function nyquist_norm
refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension
) - Inline variable that is immediately returned (
inline-immediately-returned-variable
)
r = (f(x + h / 2) - f(x - h / 2)) / h | ||
return r | ||
return (f(x + h / 2) - f(x - h / 2)) / h |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function __df
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
ret = (1 + (1.0 / x)) ** x | ||
return ret | ||
return (1 + (1.0 / x)) ** x |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function direct_e
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
for i in range(max_iterations): | ||
y = f(x0) | ||
yprime = f_prime(x0) | ||
if abs(yprime) < epsilon: # Stop if the denominator is too small | ||
break | ||
x1 = x0 - y / yprime # Do Newton's computation | ||
if abs(x1 - x0) <= tolerance: # Stop when the result is within the desired tolerance | ||
return x1 # x1 is a solution within tolerance and maximum number of iterations | ||
x0 = x1 # Update x0 to start the process again | ||
return None | ||
for _ in range(max_iterations): | ||
y = f(x0) | ||
yprime = f_prime(x0) | ||
if abs(yprime) < epsilon: # Stop if the denominator is too small | ||
break | ||
x1 = x0 - y / yprime # Do Newton's computation | ||
if abs(x1 - x0) <= tolerance: # Stop when the result is within the desired tolerance | ||
return x1 # x1 is a solution within tolerance and maximum number of iterations | ||
x0 = x1 # Update x0 to start the process again | ||
return None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function newtons_method
refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore
)
if i == 0: | ||
R[i] = P[i] | ||
else: | ||
R[i] = P[i] + Q * R[i - 1] | ||
R[i] = P[i] if i == 0 else P[i] + Q * R[i - 1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function poly_synthetic_div
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
)
tmp2.append(r) | ||
tmp2.append(-r) | ||
tmp2.extend((r, -r)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function get_rationals
refactored with the following changes:
- Merge consecutive list appends into a single extend (
merge-list-appends-into-extend
)
sum_ = 0 | ||
nipi2 = ipi2 * n | ||
for a in range(1, q+1): | ||
if gcd(a,q) == 1: | ||
sum_ += exp(nipi2 * (a/q)) | ||
return sum_ | ||
return sum(exp(nipi2 * (a/q)) for a in range(1, q+1) if gcd(a,q) == 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function c
refactored with the following changes:
- Move assignment closer to its usage within a block (
move-assign-in-block
) - Convert for loop into call to sum() (
sum-comprehension
) - Inline variable that is immediately returned (
inline-immediately-returned-variable
)
for i in range(1,210): | ||
for _ in range(1,210): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function test
refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore
)
for i in range(2, int(n ** 0.5) + 1): | ||
if n % i == 0: | ||
return False | ||
|
||
return True | ||
return all(n % i != 0 for i in range(2, int(n ** 0.5) + 1)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function isPrime
refactored with the following changes:
- Use any() instead of for loop (
use-any
) - Invert any/all to simplify comparisons (
invert-any-all
)
factor = sorted(factor) | ||
return factor | ||
return sorted(factor) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function factors
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
nD.append(-abs(i)) | ||
nD.append(abs(i)) | ||
nD.extend((-abs(i), abs(i))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function addnegatives
refactored with the following changes:
- Merge consecutive list appends into a single extend (
merge-list-appends-into-extend
)
if tmpPoli[len(tmpPoli) - 1] == 0: | ||
if tmpPoli[-1] == 0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function ruffini_step
refactored with the following changes:
- Simplify accessing last index of list (
simplify-negative-index
)
s = list(map(mul, s[0 : l // 2], s[l // 2 :])) | ||
s = list(map(mul, s[:l // 2], s[l // 2 :])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function SeqMult
refactored with the following changes:
- Replace a[0:x] with a[:x] and a[x:len(a)] with a[x:] (
remove-redundant-slice-index
)
if x >= 0: | ||
return x | ||
else: | ||
return -x | ||
return x if x >= 0 else -x |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function _abs
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
)
if x == 0: | ||
return 0 | ||
else: | ||
return x / _abs(x) | ||
return 0 if x == 0 else x / _abs(x) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function sign
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
)
for i in range(2, n): | ||
inv.append((p - p // i) * inv[p % i] % p) | ||
inv.extend((p - p // i) * inv[p % i] % p for i in range(2, n)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function compute_modinv_1_n
refactored with the following changes:
- Replace a for append loop with list extend (
for-append-to-extend
)
for i in range(1, n): | ||
inv.append(int(invert(i, p))) | ||
inv.extend(int(invert(i, p)) for i in range(1, n)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function compute_modinv_gmpy_1_n
refactored with the following changes:
- Replace a for append loop with list extend (
for-append-to-extend
)
res = 0 | ||
for n in range(0, len(vec)): | ||
res += vec[n] * vec[n] | ||
|
||
res = sum(vec[n] * vec[n] for n in range(0, len(vec))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function magnitude
refactored with the following changes:
- Convert for loop into call to sum() (
sum-comprehension
)
d0fbcdc
to
0b15853
Compare
Branch
master
refactored by Sourcery.If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
See our documentation here.
Run Sourcery locally
Reduce the feedback loop during development by using the Sourcery editor plugin:
Review changes via command line
To manually merge these changes, make sure you're on the
master
branch, then run:Help us improve this pull request!