Skip to content

Commit

Permalink
run black
Browse files Browse the repository at this point in the history
  • Loading branch information
marianolten committed Aug 14, 2024
1 parent eed3ebd commit 41656d1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 56 deletions.
12 changes: 7 additions & 5 deletions pymrio/tools/iomath.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@ def calc_B(Z, x):
# return np.diagflat(recix).dot(Z)
if type(Z) is pd.DataFrame:
return pd.DataFrame(
np.transpose(np.transpose(Z.values) * recix), index=Z.index, columns=Z.columns
np.transpose(np.transpose(Z.values) * recix),
index=Z.index,
columns=Z.columns,
)
else:
return np.transpose(np.transpose(Z) * recix)
Expand Down Expand Up @@ -271,7 +273,9 @@ def calc_G(B, L=None, x=None):

if type(L) is pd.DataFrame:
return pd.DataFrame(
np.transpose(recix * np.transpose(L.values * x)), index=Z.index, columns=Z.columns
np.transpose(recix * np.transpose(L.values * x)),
index=Z.index,
columns=Z.columns,
)
else:
# G = hat(x) * L * hat(x)^{-1} in mathematical form hatx.dot(L.transpose()).dot(np.linalg.inv(hatx)).
Expand All @@ -280,9 +284,7 @@ def calc_G(B, L=None, x=None):
else: # calculation of the inverse of I-As has a high computational cost.
I = np.eye(B.shape[0]) # noqa
if type(B) is pd.DataFrame:
return pd.DataFrame(
np.linalg.inv(I - B), index=B.index, columns=B.columns
)
return pd.DataFrame(np.linalg.inv(I - B), index=B.index, columns=B.columns)
else:
return np.linalg.inv(I - B) # G = inverse matrix of (I - B)

Expand Down
74 changes: 23 additions & 51 deletions tests/test_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,48 +243,20 @@ class IO_Data:
0.01960784,
0.11764706,
0.09803922,
0.1372549
], # noqa
[
0.0,
0.13333333,
0.0,
0.0,
0.33333333,
0.2
0.1372549,
], # noqa
[0.0, 0.13333333, 0.0, 0.0, 0.33333333, 0.2], # noqa
[
0.17241379,
0.05172414,
0.34482759,
0.06896552,
0.03448276,
0.
], # noqa
[
0.1,
0.0,
0.0,
0.02,
0.2,
0.18
], # noqa
[
0.0,
0.19230769,
0.01923077,
0.0,
0.38461538,
0.01923077
], # noqa
[
0.12820513,
0.0,
0.0,
0.02564103,
0.25641026,
0.25641026
]
[0.1, 0.0, 0.0, 0.02, 0.2, 0.18], # noqa
[0.0, 0.19230769, 0.01923077, 0.0, 0.38461538, 0.01923077], # noqa
[0.12820513, 0.0, 0.0, 0.02564103, 0.25641026, 0.25641026],
],
index=_Z_multiindex,
columns=_Z_multiindex,
Expand Down Expand Up @@ -351,50 +323,50 @@ class IO_Data:
1.33871463,
0.28499301,
0.05727924,
0.1747153 ,
0.1747153,
0.58648041,
0.38121958
], # noqa
[
0.38121958,
], # noqa
[
0.07482651,
1.37164729,
0.02969614,
0.02185805,
0.93542302,
0.41222074
], # noqa
[
0.38065717,
0.22311379,
1.54929428,
0.15941084,
0.39473223,
0.17907022
], # noqa
0.41222074,
], # noqa
[
0.38065717,
0.22311379,
1.54929428,
0.15941084,
0.39473223,
0.17907022,
], # noqa
[
0.19175489,
0.15732254,
0.02349465,
1.05420074,
0.60492361,
0.34854312
0.34854312,
], # noqa
[
0.04316348,
0.44208094,
0.05866155,
0.01404088,
1.95452858,
0.18081884
0.18081884,
], # noqa
[
0.25230906,
0.20700334,
0.03091401,
0.07131676,
0.79595212,
1.48492515
]
1.48492515,
],
],
index=_Z_multiindex,
columns=_Z_multiindex,
Expand Down

0 comments on commit 41656d1

Please sign in to comment.