Skip to content

Commit

Permalink
Black
Browse files Browse the repository at this point in the history
  • Loading branch information
albop committed Nov 7, 2024
1 parent 0e3b6c3 commit d782336
Show file tree
Hide file tree
Showing 18 changed files with 41 additions and 30 deletions.
2 changes: 2 additions & 0 deletions dolo/algos/ergodic.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# from multipledispatch import dispatch
# multimethod = dispatch()
from dolo.misc.multimethod import multimethod

# from numba import generated_jit
import xarray

Expand All @@ -17,6 +18,7 @@

# @generated_jit(nopython=True)


@jit
def trembling_hand(A: "N*n1*...*nd", x: "N*d", w: "float"):

Expand Down
1 change: 0 additions & 1 deletion dolo/algos/improved_time_iteration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
34 changes: 23 additions & 11 deletions dolo/algos/invert.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import numpy


@jit
def swaplines_tensor(i, j, M):
n0, n1, n2 = M.shape
Expand All @@ -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]
Expand All @@ -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]
Expand All @@ -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):
Expand All @@ -48,28 +52,32 @@ 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
n = M.shape[0]
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:
Expand All @@ -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
Expand All @@ -87,26 +96,29 @@ 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
n = M.shape[0]
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):
Expand Down
2 changes: 1 addition & 1 deletion dolo/algos/perfect_foresight.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion dolo/algos/time_iteration.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ def time_iteration(
# obsolete
with_complementarities=None,
) -> TimeIterationResult:

"""Finds a global solution for ``model`` using backward time-iteration.
Expand Down
2 changes: 1 addition & 1 deletion dolo/compiler/eval_formula.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion dolo/compiler/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def max(self):
# signature = {'Mu': 'list(float)', 'Sigma': 'Matrix'}


#%%
# %%


@language_element
Expand Down
4 changes: 1 addition & 3 deletions dolo/misc/multimethod.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
1 change: 0 additions & 1 deletion dolo/numeric/discretization/discretization.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Discretization of continuous processes as markov chain
"""


import scipy as sp
import scipy.stats
import numpy as np
Expand Down
1 change: 1 addition & 0 deletions dolo/numeric/discretization/quadrature.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion dolo/numeric/distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ def ppf(self, quantiles):
# Probability associated with each point in grid (nodes)


#%
# %


###
Expand Down
2 changes: 1 addition & 1 deletion dolo/numeric/extern/lmmcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions dolo/numeric/matrix_equations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down
1 change: 0 additions & 1 deletion dolo/numeric/optimize/newton.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion dolo/numeric/processes.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def simulate(self, N, T, i0=0, m0=None, stochastic=True):
return self.values[inds]


#%%
# %%


@language_element
Expand Down
6 changes: 3 additions & 3 deletions dolo/tests/test_complementarity_problems.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
1 change: 1 addition & 0 deletions dolo/tests/test_iid_processes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from dolo.numeric.distribution import *
from dolo.numeric.processes import ConstantProcess


## Polynomial
def f(x):
return x**2
Expand Down
6 changes: 3 additions & 3 deletions dolo/tests/test_serial_ncpsolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit d782336

Please sign in to comment.