From d782336b92e510d2b025878159f852e08f3c96a5 Mon Sep 17 00:00:00 2001 From: Pablo Winant Date: Thu, 7 Nov 2024 13:49:11 +0100 Subject: [PATCH] Black --- dolo/algos/ergodic.py | 2 ++ dolo/algos/improved_time_iteration.py | 1 - dolo/algos/invert.py | 34 +++++++++++++------ dolo/algos/perfect_foresight.py | 2 +- dolo/algos/time_iteration.py | 1 - dolo/compiler/eval_formula.py | 2 +- dolo/compiler/objects.py | 2 +- dolo/misc/multimethod.py | 4 +-- dolo/numeric/discretization/discretization.py | 1 - dolo/numeric/discretization/quadrature.py | 1 + dolo/numeric/distribution.py | 2 +- dolo/numeric/extern/lmmcp.py | 2 +- dolo/numeric/matrix_equations.py | 1 + dolo/numeric/optimize/newton.py | 1 - dolo/numeric/processes.py | 2 +- dolo/tests/test_complementarity_problems.py | 6 ++-- dolo/tests/test_iid_processes.py | 1 + dolo/tests/test_serial_ncpsolve.py | 6 ++-- 18 files changed, 41 insertions(+), 30 deletions(-) diff --git a/dolo/algos/ergodic.py b/dolo/algos/ergodic.py index 44f81ef1..d5393a6d 100644 --- a/dolo/algos/ergodic.py +++ b/dolo/algos/ergodic.py @@ -4,6 +4,7 @@ # from multipledispatch import dispatch # multimethod = dispatch() from dolo.misc.multimethod import multimethod + # from numba import generated_jit import xarray @@ -17,6 +18,7 @@ # @generated_jit(nopython=True) + @jit def trembling_hand(A: "N*n1*...*nd", x: "N*d", w: "float"): diff --git a/dolo/algos/improved_time_iteration.py b/dolo/algos/improved_time_iteration.py index d2adac6e..e39697b6 100644 --- a/dolo/algos/improved_time_iteration.py +++ b/dolo/algos/improved_time_iteration.py @@ -120,7 +120,6 @@ def d_filt_dx(π, M_ij, S_ij, n_m, N, n_x, dumdr): class Operator(LinearOperator): - """Special Linear Operator""" def __init__(self, M_ij, S_ij, dumdr): diff --git a/dolo/algos/invert.py b/dolo/algos/invert.py index 7dac8503..ac27d591 100644 --- a/dolo/algos/invert.py +++ b/dolo/algos/invert.py @@ -6,6 +6,7 @@ import numpy + @jit def swaplines_tensor(i, j, M): n0, n1, n2 = M.shape @@ -15,6 +16,7 @@ def swaplines_tensor(i, j, M): M[i, k, l] = M[j, k, l] M[j, k, l] = t + @jit def swaplines_matrix(i, j, M): n = M.shape[1] @@ -23,6 +25,7 @@ def swaplines_matrix(i, j, M): M[i, k] = M[j, k] M[j, k] = t + @jit def swaplines_vector(i, j, M): n = M.shape[0] @@ -34,11 +37,12 @@ def swaplines_vector(i, j, M): @jit(cache=True) def swaplines(i, j, M): if M.ndim == 1: - return swaplines_vector(i,j,M) + return swaplines_vector(i, j, M) elif M.ndim == 2: - return swaplines_matrix(i,j,M) + return swaplines_matrix(i, j, M) elif M.ndim == 3: - return swaplines_tensor(i,j,M) + return swaplines_tensor(i, j, M) + @jit def substract_tensor(i, j, c, M): @@ -48,6 +52,7 @@ def substract_tensor(i, j, c, M): for l in range(n2): M[i, k, l] = M[i, k, l] - c * M[j, k, l] + @jit def substract_matrix(i, j, c, M): # Li <- Li - c*Lj @@ -55,21 +60,24 @@ def substract_matrix(i, j, c, M): for k in range(n): M[i, k] = M[i, k] - c * M[j, k] + @jit def substract_vector(i, j, c, M): # Li <- Li - c*Lj # n = M.shape[0] M[i] = M[i] - c * M[j] + @jit -def substract(i,j,c,M): +def substract(i, j, c, M): if M.ndim == 1: - return substract_vector(i,j,c,M) + return substract_vector(i, j, c, M) elif M.ndim == 2: - return substract_matrix(i,j,c,M) + return substract_matrix(i, j, c, M) elif M.ndim == 3: - return substract_tensor(i,j,c,M) - + return substract_tensor(i, j, c, M) + + # @overload(substract) # def substract_jit(i, j, c, M): # if M.ndim == 1: @@ -79,6 +87,7 @@ def substract(i,j,c,M): # elif M.ndim == 3: # return substract_tensor + @jit def divide_tensor(i, c, M): # Li <- Li - c*Lj @@ -87,6 +96,7 @@ def divide_tensor(i, c, M): for l in range(n2): M[i, k, l] /= c + @jit def divide_matrix(i, c, M): # Li <- Li - c*Lj @@ -94,19 +104,21 @@ def divide_matrix(i, c, M): for k in range(n): M[i, k] /= c + @jit def divide_vector(i, c, M): # Li <- Li - c*Lj M[i] /= c + @jit def divide(i, c, M): if M.ndim == 1: - return divide_vector(i,c,M) + return divide_vector(i, c, M) elif M.ndim == 2: - return divide_matrix(i,c,M) + return divide_matrix(i, c, M) elif M.ndim == 3: - return divide_tensor(i,c,M) + return divide_tensor(i, c, M) # def divide(i, c, M): diff --git a/dolo/algos/perfect_foresight.py b/dolo/algos/perfect_foresight.py index c8a8ca42..9950d555 100644 --- a/dolo/algos/perfect_foresight.py +++ b/dolo/algos/perfect_foresight.py @@ -22,7 +22,7 @@ def _shocks_to_epsilons(model, shocks, T): # value arrays are not the same length if isinstance(shocks, dict): epsilons = np.zeros((T + 1, n_e)) - for (i, k) in enumerate(model.symbols["exogenous"]): + for i, k in enumerate(model.symbols["exogenous"]): if k in shocks: this_shock = shocks[k] epsilons[: len(this_shock), i] = this_shock diff --git a/dolo/algos/time_iteration.py b/dolo/algos/time_iteration.py index fd18fb2b..ae47e44d 100644 --- a/dolo/algos/time_iteration.py +++ b/dolo/algos/time_iteration.py @@ -54,7 +54,6 @@ def time_iteration( # obsolete with_complementarities=None, ) -> TimeIterationResult: - """Finds a global solution for ``model`` using backward time-iteration. diff --git a/dolo/compiler/eval_formula.py b/dolo/compiler/eval_formula.py index 8eb65f5e..ffc08a9a 100644 --- a/dolo/compiler/eval_formula.py +++ b/dolo/compiler/eval_formula.py @@ -40,7 +40,7 @@ def eval_formula(expr: str, dataframe=None, context=None): import pandas as pd - for (k, t) in variables: + for k, t in variables: dd[stringify_symbol((k, t))] = dataframe[k].shift(t) dd["t_"] = pd.Series(dataframe.index, index=dataframe.index) diff --git a/dolo/compiler/objects.py b/dolo/compiler/objects.py index 2b538a69..8e7ce47f 100644 --- a/dolo/compiler/objects.py +++ b/dolo/compiler/objects.py @@ -65,7 +65,7 @@ def max(self): # signature = {'Mu': 'list(float)', 'Sigma': 'Matrix'} -#%% +# %% @language_element diff --git a/dolo/misc/multimethod.py b/dolo/misc/multimethod.py index 681c9938..2608d856 100644 --- a/dolo/misc/multimethod.py +++ b/dolo/misc/multimethod.py @@ -231,9 +231,7 @@ class multidispatch(multimethod): get_type = multimethod(type) get_type.__doc__ = """Return a generic `subtype` which checks subscripts.""" for atomic in (Iterator, str, bytes): - get_type[ - atomic, - ] = type + get_type[atomic,] = type @multimethod # type: ignore[no-redef] diff --git a/dolo/numeric/discretization/discretization.py b/dolo/numeric/discretization/discretization.py index 532dd836..3345bb49 100644 --- a/dolo/numeric/discretization/discretization.py +++ b/dolo/numeric/discretization/discretization.py @@ -2,7 +2,6 @@ Discretization of continuous processes as markov chain """ - import scipy as sp import scipy.stats import numpy as np diff --git a/dolo/numeric/discretization/quadrature.py b/dolo/numeric/discretization/quadrature.py index 809bc19e..b92c37f7 100644 --- a/dolo/numeric/discretization/quadrature.py +++ b/dolo/numeric/discretization/quadrature.py @@ -3,6 +3,7 @@ import numpy from dolo.numeric.misc import cartesian + # Credits : both routines below are ported from the Compecon Toolbox # by Paul L Fackler and Mario J. Miranda. # It is downloadable at http://www4.ncsu.edu/~pfackler/compecon/toolbox.html diff --git a/dolo/numeric/distribution.py b/dolo/numeric/distribution.py index 1ec0f5c6..5b3132d8 100644 --- a/dolo/numeric/distribution.py +++ b/dolo/numeric/distribution.py @@ -550,7 +550,7 @@ def ppf(self, quantiles): # Probability associated with each point in grid (nodes) -#% +# % ### diff --git a/dolo/numeric/extern/lmmcp.py b/dolo/numeric/extern/lmmcp.py index 9e5cfe58..ed5dbf83 100644 --- a/dolo/numeric/extern/lmmcp.py +++ b/dolo/numeric/extern/lmmcp.py @@ -418,7 +418,7 @@ def Phi3MCPPFB(x, Fx, lb, ub, lambda1, lambda2, n, Indexset): def DPhi3MCPPFB(x, Fx, DFx, lb, ub, lambda1, lambda2, n, Indexset): - #% we evaluate an element of the C-subdifferential of operator Phi3MCPPFB + # % we evaluate an element of the C-subdifferential of operator Phi3MCPPFB null = 1e-8 beta_l = np.zeros(n) beta_u = np.zeros(n) diff --git a/dolo/numeric/matrix_equations.py b/dolo/numeric/matrix_equations.py index ebc66b3b..d9c5e44f 100644 --- a/dolo/numeric/matrix_equations.py +++ b/dolo/numeric/matrix_equations.py @@ -4,6 +4,7 @@ TOL = 1e-10 + # credits : second_order_solver is adapted from Sven Schreiber's port of Uhlig's Toolkit. def second_order_solver(FF, GG, HH, eigmax=1.0 + 1e-6): diff --git a/dolo/numeric/optimize/newton.py b/dolo/numeric/optimize/newton.py index be54a751..29471552 100644 --- a/dolo/numeric/optimize/newton.py +++ b/dolo/numeric/optimize/newton.py @@ -82,7 +82,6 @@ def serial_solve(A, B, diagnose=True): def newton(f, x, verbose=False, tol=1e-6, maxit=5, jactype="serial"): - """Solve nonlinear system using safeguarded Newton iterations diff --git a/dolo/numeric/processes.py b/dolo/numeric/processes.py index f61b1b00..fa934ece 100644 --- a/dolo/numeric/processes.py +++ b/dolo/numeric/processes.py @@ -291,7 +291,7 @@ def simulate(self, N, T, i0=0, m0=None, stochastic=True): return self.values[inds] -#%% +# %% @language_element diff --git a/dolo/tests/test_complementarity_problems.py b/dolo/tests/test_complementarity_problems.py index a004cde7..9fca2e6e 100644 --- a/dolo/tests/test_complementarity_problems.py +++ b/dolo/tests/test_complementarity_problems.py @@ -17,9 +17,9 @@ def josephy(x): def Djosephy(x): # Local Variables: x, DFx, n # Function calls: Djosephy, zeros, length - #% - #% Computes the Jacobian DF(x) of the NCP-example by Josephy - #% + # % + # % Computes the Jacobian DF(x) of the NCP-example by Josephy + # % n = len(x) DFx = np.zeros((n, n)) DFx[0, 0] = 6.0 * x[0] + 2.0 * x[1] diff --git a/dolo/tests/test_iid_processes.py b/dolo/tests/test_iid_processes.py index b2139ad7..0d21af88 100644 --- a/dolo/tests/test_iid_processes.py +++ b/dolo/tests/test_iid_processes.py @@ -5,6 +5,7 @@ from dolo.numeric.distribution import * from dolo.numeric.processes import ConstantProcess + ## Polynomial def f(x): return x**2 diff --git a/dolo/tests/test_serial_ncpsolve.py b/dolo/tests/test_serial_ncpsolve.py index 01b4a541..d34d9962 100644 --- a/dolo/tests/test_serial_ncpsolve.py +++ b/dolo/tests/test_serial_ncpsolve.py @@ -19,9 +19,9 @@ def josephy(x): def Djosephy(x): # Local Variables: x, DFx, n # Function calls: Djosephy, zeros, length - #% - #% Computes the Jacobian DF(x) of the NCP-example by Josephy - #% + # % + # % Computes the Jacobian DF(x) of the NCP-example by Josephy + # % n = len(x) DFx = np.zeros((n, n)) DFx[0, 0] = 6.0 * x[0] + 2.0 * x[1]