Skip to content

Commit 677e00b

Browse files
suda-yugammcky
andauthored
Replace np.sum(a * b) with a @ b (#213)
Co-authored-by: Matt McKay <mmcky@users.noreply.github.com>
1 parent e7e8d05 commit 677e00b

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

β€Žlectures/BCG_complete_mkts.mdβ€Ž

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -985,7 +985,7 @@ class BCG_complete_markets:
985985
weights = self.weights
986986
integ = lambda πœ–: np.exp(πœ–) * fk * q(πœ–, k)
987987
988-
return -k + np.sum(weights * integ(self.points_integral)) / np.sqrt(np.pi)
988+
return -k + (weights @ integ(self.points_integral)) / np.sqrt(np.pi)
989989
990990
#=========== Optimal c ===========#
991991
# Function: Compute optimal consumption choices c
@@ -1007,10 +1007,10 @@ class BCG_complete_markets:
10071007
fk = self.f(k)
10081008
10091009
c1 = lambda πœ–: (w1(πœ–) + np.exp(πœ–)*fk)*q(πœ–,k)
1010-
denom = np.sum(weights * c1(self.points_integral)) / np.sqrt(np.pi) + (w0 - k)
1010+
denom = (weights @ c1(self.points_integral)) / np.sqrt(np.pi) + (w0 - k)
10111011
10121012
w11q = lambda πœ–: w11(πœ–)*q(πœ–,k)
1013-
num = w10 + πœƒ10 * V(k) + np.sum(weights * w11q(self.points_integral)) / np.sqrt(np.pi)
1013+
num = w10 + πœƒ10 * V(k) + (weights @ w11q(self.points_integral)) / np.sqrt(np.pi)
10141014
10151015
πœ‚ = num / denom
10161016
@@ -1048,7 +1048,7 @@ def k_foc_factory(model):
10481048
10491049
@njit
10501050
def k_foc(k, πœ’1, πœ’2):
1051-
int_k = np.sum(weights * integrand(points_integral, πœ’1, πœ’2, k=k)) / np.sqrt(np.pi)
1051+
int_k = (weights @ integrand(points_integral, πœ’1, πœ’2, k=k)) / np.sqrt(np.pi)
10521052
10531053
mul = 𝛽 * 𝛼 * A * k ** (𝛼 - 1) / ((w0 - k) ** (-πœ“))
10541054
val = mul * int_k - 1

0 commit comments

Comments
Β (0)