Showing 591 of 591 total issues
Consider using '{backward
: 1, forward
: 1}' instead of a call to 'dict'. Open
order = dict(backward=1, forward=1).get(method, 2)
- Read upRead up
- Exclude checks
Emitted when using dict() to create a dictionary instead of a literal '{ ... }'. The literal is faster as it avoids an additional function call.
Consider using Python 3 style super() without arguments Open
super(Hessian, self).__init__(f, step=step, method=method, order=order, **options)
- Read upRead up
- Exclude checks
Emitted when calling the super() builtin with the current class and instance. On Python 3 these arguments are the default and they can be omitted.
This 'tryexcept' is too complex. The McCabe rating is 16 Open
try:
- Read upRead up
- Exclude checks
Used when a method or function is too complex based on McCabe Complexity Cyclomatic
Variable name t1
doesn't conform to '[a-z_][a-z0-9_]{2,30}$' pattern ('[a-z_][a-z0-9_]{2,30}$' pattern) Open
t1 = timer()
- Read upRead up
- Exclude checks
Used when the name doesn't conform to naming rules associated to its type (constant, variable, class...).
Too many arguments (7/5) Open
def _plot(plot, problem_sizes, objects, symbols, ylabel='', loc=2, logx=False):
- Read upRead up
- Exclude checks
Used when a function or method takes too many arguments.
Formatting a regular string which could be a f-string Open
header = 'method="{}", order={}, x_values={}:'.format(method, order, str(x_values))
- Read upRead up
- Exclude checks
Used when we detect a string that is being formatted with format() or % which could potentially be a f-string. The use of f-strings is preferred. Requires Python 3.6 and py-version >= 3.6
.
Using open without explicitly specifying an encoding Open
with open(file_path, 'r') as fp:
- Read upRead up
- Exclude checks
It is better to specify an encoding when opening documents. Using the system default implicitly can create problems on other operating systems. See https://peps.python.org/pep-0597/
Similar lines in 2 files Open
#!/usr/bin/env python
- Read upRead up
- Exclude checks
Indicates that a set of similar lines has been detected among multiple file. This usually means that the code should be refactored to avoid this duplication. ==numdifftools.ndscipy:[86:143] ==numdifftools.ndstatsmodels:[298:355] class Gradient(Jacobian): ``` Calculate Gradient with finite difference approximation
Parameters
fun : function
function of one array fun(x, *args
, **kwds
)
step : float, optional
Stepsize, if None, optimal stepsize is used, i.e.,
x * _EPS for method==complex
x * _EPS(1/2) for method==forward
x * _EPS(1/3) for method==central
.
method : {'central', 'complex', 'forward', 'backward'}
defines the method used in the approximation.
Examples
import numpy as np import numdifftools.nd_statsmodels as nd fun = lambda x: np.sum(x**2) dfun = nd.Gradient(fun) np.allclose(dfun([1,2,3]), [ 2., 4., 6.]) True
# At [x,y] = [1,1], compute the numerical gradient # of the function sin(x-y) + y*exp(x)
sin = np.sin; exp = np.exp z = lambda xy: sin(xy[0]-xy[1]) + xy[1]*exp(xy[0]) dz = nd.Gradient(z) grad2 = dz([1, 1]) np.allclose(grad2, [ 3.71828183, 1.71828183]) True
# At the global minimizer (1,1) of the Rosenbrock function, # compute the gradient. It should be essentially zero.
rosen = lambda x : (1-x[0])2 + 105.*(x[1]-x[0]2)**2 rd = nd.Gradient(rosen) grad3 = rd([1,1]) np.allclose(grad3,[0, 0]) True
See also
Hessian, Jacobian ```
def call(self, x, args, *kwds): return super(Gradient, self).call(np.atleast_1d(x).ravel(), args, *kwds).squeeze()
if name == 'main': from numdifftools.testing import testdocstrings testdocstrings(file)
Consider using '{forward
: 1, above
: 1, backward
: -1, below
: -1}' instead of a call to 'dict'. Open
sign = dict(forward=1, above=1, backward=-1, below=-1)[self.method]
- Read upRead up
- Exclude checks
Emitted when using dict() to create a dictionary instead of a literal '{ ... }'. The literal is faster as it avoids an additional function call.
Unable to import 'scipy.optimize' Open
from scipy.optimize import approx_fprime
- Read upRead up
- Exclude checks
Used when pylint has been unable to import a module.
Class '_Common' inherits from object, can be safely removed from bases in python3 Open
class _Common(object):
- Read upRead up
- Exclude checks
Used when a class inherit from object, which under python3 is implicit, hence can be safely removed from bases.
Too many arguments (7/5) Open
def __init__(self, fun, step=None, method='central', order=2,
- Read upRead up
- Exclude checks
Used when a function or method takes too many arguments.
Line too long (119/100) Open
- **Hessian**: Compute the Hessian matrix of all 2nd partial derivatives of a scalar function of one or more variables.
- Read upRead up
- Exclude checks
Used when a line is longer than a given number of characters.
Line too long (108/100) Open
pkg_resources.require('setuptools>=39.2') # setuptools >=38.3.0 # version with most `setup.cfg` bugfixes
- Read upRead up
- Exclude checks
Used when a line is longer than a given number of characters.
Missing function or method docstring Open
def setup_package():
- Read upRead up
- Exclude checks
Used when a function or method has no docstring. Some special methods like init do not require a docstring.
Formatting a regular string which could be a f-string Open
print("Version: {}".format(version))
- Read upRead up
- Exclude checks
Used when we detect a string that is being formatted with format() or % which could potentially be a f-string. The use of f-strings is preferred. Requires Python 3.6 and py-version >= 3.6
.
Argument name fd
doesn't conform to '[a-z_][a-z0-9_]{2,30}$' pattern ('[a-z_][a-z0-9_]{2,30}$' pattern) Open
def benchmark(x=0.0001, dfun=None, fd=None, name='', scales=None, show_plot=True):
- Read upRead up
- Exclude checks
Used when the name doesn't conform to naming rules associated to its type (constant, variable, class...).
Too few public methods (1/2) Open
class Jacobian(_Common):
- Read upRead up
- Exclude checks
Used when class has too few public methods, so be sure it's really worth it.
Missing function or method docstring Open
def run(self):
- Read upRead up
- Exclude checks
Used when a function or method has no docstring. Some special methods like init do not require a docstring.
third party import import numpy as np
should be placed before from numdifftools.example_functions import get_function, function_names
Open
import numpy as np
- Read upRead up
- Exclude checks
Used when PEP8 import order is not respected (standard imports first, then third-party libraries, then local imports).