Skip to content

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

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

[mccall_model] Replace np.sum(a * b) with a @ b#471
mmcky merged 1 commit intoQuantEcon:mainfrom
UdohNakamura:UdohNakamura-patch-1

Conversation

@UdohNakamura
Copy link
Contributor

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

@mmcky
Copy link
Contributor

mmcky commented Jul 1, 2025

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
# Consider action = accept or reject the current offer
accept = w[i] / (1 - β)
reject = c + β * np.sum(v * q)
reject = c + β * (v @ q)
Copy link
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
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
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
Copy link
Contributor

mmcky commented Jul 21, 2025

thanks so much of this PR @UdohNakamura

@mmcky mmcky merged commit 95cc107 into QuantEcon:main Jul 21, 2025
6 checks passed
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