Skip to content

[mccall_model] Replace np.sum(a * b) with a @ b - #471

Merged
mmcky merged 1 commit into
QuantEcon:mainfrom
UdohNakamura:UdohNakamura-patch-1
Jul 21, 2025
Merged

mmcky merged 1 commit into
QuantEcon:mainfrom
UdohNakamura:UdohNakamura-patch-1

Conversation

@UdohNakamura

Copy link
Copy Markdown
Contributor

Replace np.sum(a * b) with a @ b
#463

@mmcky

mmcky commented Jul 1, 2025

Copy link
Copy Markdown
Contributor

thank you @UdohNakamura for this FIX - I have enabled the tests to run.

@mmcky
mmcky requested a review from HumphreyYang July 1, 2025 02:14
Comment thread lectures/mccall_model.md
# Consider action = accept or reject the current offer
accept = w[i] / (1 - β)
reject = c + β * np.sum(v * q)
reject = c + β * (v @ q)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many thanks @UdohNakamura and @mmcky,

When building on my side I got

<string>:3: NumbaPerformanceWarning: '@' is faster on contiguous arrays, called on (Array(float64, 1, 'C', False, aligned=True), Array(float64, 1, 'A', False, aligned=True))

Upon checking, I found we annotate the type

    ('w', float64[:]),   # array of wage values, w[i] = wage at state i
    ('q', float64[:])    # array of probabilities

The following type will help (see more here:

    ('w', float64[::1]),   # array of wage values, w[i] = wage at state i
    ('q', float64[::1])    # array of probabilities

Please let me know what you think.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@HumphreyYang Thanks, I didn't know that. Maybe write float64[::1] in place of float64[:] and explain that it is needed to have @ work inside a jitclass?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @HumphreyYang and @oyamad

@HumphreyYang I will merge these great PRs and then you can do a pass to fix this.

@mmcky

mmcky commented Jul 21, 2025

Copy link
Copy Markdown
Contributor

thanks so much of this PR @UdohNakamura

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants