Skip to content

🌐 [translation-sync] Modernize Numba lecture#17

Open
mmcky wants to merge 2 commits intomainfrom
translation-sync-2026-04-08T08-16-48-pr-512
Open

🌐 [translation-sync] Modernize Numba lecture#17
mmcky wants to merge 2 commits intomainfrom
translation-sync-2026-04-08T08-16-48-pr-512

Conversation

@mmcky
Copy link
Copy Markdown
Contributor

@mmcky mmcky commented Apr 8, 2026

Automated Translation Sync

This PR contains automated translations from QuantEcon/lecture-python-programming.

Source PR

#512 - Modernize Numba lecture

Files Updated

  • ✏️ lectures/numba.md
  • ✏️ .translate/state/numba.md.yml

Details

  • Source Language: en
  • Target Language: zh-cn
  • Model: claude-sonnet-4-6

This PR was created automatically by the translation action.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 8, 2026

✅ Translation Quality Review

Verdict: PASS | Model: claude-sonnet-4-6 | Date: 2026-04-08


📝 Translation Quality

Criterion Score
Accuracy 9/10
Fluency 9/10
Terminology 9/10
Formatting 9/10
Overall 9/10

Summary: The translation is of high quality overall. All modified and newly added sections are accurately translated with natural Chinese phrasing and consistent technical terminology. The new 'Caching Compiled Code' section is well handled. Minor improvements could be made to a few word choices for naturalness, but these are non-critical. Formatting and mathematical content are fully preserved with no syntax errors detected. Technical terminology is consistently and correctly applied throughout, including 'JIT编译', '即时编译器', '类型推断', '多线程', '并行化' etc. The newly added '### 缓存编译代码' section is accurately and fluently translated, clearly conveying both the concept and the practical usage Mathematical expressions and LaTeX formatting are fully preserved with no errors Code comments within code blocks are appropriately translated into Chinese (e.g., '# 抽取冲击', '# 更新财富', '# 对每条样本路径'), improving accessibility for Chinese readers The glossary term 'stochastic volatility' → '随机波动率' is correctly applied in the numba_ex4 exercise section

Suggestions:

  • Decorator Notation section: '要将函数定向为 JIT 编译' → '要将函数标记为 JIT 编译目标' - 'targeted for JIT compilation' is better rendered as '标记为 JIT 编译目标' rather than '定向为 JIT 编译', which sounds slightly unnatural in Chinese

  • How and When it Works section: '动态推断类型信息' → '即时推断类型信息' - 'on the fly' is more precisely translated as '即时' rather than '动态' (which could be confused with 'dynamic' in the technical sense)

  • Caching Compiled Code section (new): '为了避免这种开销' → '为了避免这一额外开销' - adding '额外' better conveys the meaning of 'overhead' as extra/additional cost in this context


🔍 Diff Quality

Check Status
Scope Correct
Position Correct
Structure Preserved
Heading-map Correct
Overall 10/10

Summary: The translation target document is correctly updated to mirror all structural and content changes from the English source, with the heading map accurately reflecting added, removed, and renamed headings.


This review was generated automatically by action-translation review mode.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Automated zh-cn translation sync to align the Numba lecture with upstream “Modernize Numba lecture” changes from QuantEcon/lecture-python-programming.

Changes:

  • Updated lectures/numba.md content/structure (reworded intro, revised sections, removed “编译类”, added “缓存编译代码”).
  • Refreshed code examples and surrounding explanations to match the modernized source (e.g., updated random-number usage, decorator usage, and headings).
  • Updated translation sync state metadata in .translate/state/numba.md.yml.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
lectures/numba.md Updates the zh-cn Numba lecture translation to match upstream modernized content and examples.
.translate/state/numba.md.yml Updates translation-sync bookkeeping (source SHA, sync date, mode, section count).
Comments suppressed due to low confidence (1)

lectures/numba.md:263

  • 这里用 @jit 装饰并在注释中说明“这段代码会抛出错误”,但如果 @jit 未强制 nopython=True,某些 Numba 版本/设置可能会回退到对象模式而不抛错,从而与讲解目的不一致。建议将该示例改为 @njit(或 @jit(nopython=True)),以确保无法推断类型时确实触发编译错误。
```{code-cell} ipython3
@jit
def bootstrap(data, statistics, n_resamples):
    bootstrap_stat = np.empty(n_resamples)
    n = len(data)
    for i in range(n_resamples):
        resample = np.random.choice(data, size=n, replace=True)
        bootstrap_stat[i] = statistics(resample)
    return bootstrap_stat

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +249 to +251
```{note}
在旧版本的 Numba 中,当 `@jit` 装饰器无法推断所有类型时,会静默回退到"对象模式",这几乎不能带来速度提升。当前版本的 Numba 默认使用 `nopython` 模式,这意味着编译器坚持进行完整的类型推断,如果失败则引发错误。您在其他代码中经常会看到 `@njit`,它只是 `@jit(nopython=True)` 的别名。由于 nopython 模式现在是默认模式,`@jit` 和 `@njit` 是等价的。
```
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

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

{note} 块里写到“当前版本的 Numba 默认使用 nopython 模式,因此 @jit@njit 等价”。这会让文中后续多个示例(例如期待编译失败抛错、以及并行化加速)变得依赖 Numba 版本/配置,且在不少环境下 @jit 仍可能回退到对象模式而不报错。建议改为显式使用 @njit(或 @jit(nopython=True))并相应更新这段说明,避免读者得到不一致的结果。

Copilot uses AI. Check for mistakes.
Comment on lines 459 to 463
from numba import prange

@njit(parallel=True)
@jit(parallel=True)
def compute_long_run_median_parallel(w0=1, T=1000, num_reps=50_000):

Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

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

此处使用 @jit(parallel=True) + prange 来演示并行化,但 Numba 的并行化优化通常要求处于 nopython 编译路径;如果 @jit 发生对象模式回退,parallel=True 可能不会生效(或行为与讲解不一致)。建议改为 @njit(parallel=True)(或 @jit(nopython=True, parallel=True))以确保示例确实并行执行。

Copilot uses AI. Check for mistakes.
return x
```

这会将编译后的代码存储在磁盘上,以便后续会话可以跳过编译步骤。
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

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

cache=True 的说明写成“后续会话可以跳过编译步骤”。在 Jupyter / Jupyter Book 这类交互式环境中,Numba 的磁盘缓存通常要求函数定义在可定位的模块文件中;在笔记本代码单元里启用缓存可能不会生效,甚至可能直接报错。建议在文字里注明该限制(或将示例调整为更适用于本讲义构建环境的写法)。

Suggested change
这会将编译后的代码存储在磁盘上,以便后续会话可以跳过编译步骤
这通常会将编译后的代码存储在磁盘上,从而在后续会话中避免重复编译
但需要注意的是,Numba 的磁盘缓存通常要求函数定义在可定位的模块文件中;在 Jupyter / Jupyter Book 这类交互式环境的代码单元里,`cache=True` 可能不会生效,甚至可能直接报错。

Copilot uses AI. Check for mistakes.

```{code-cell} ipython3
time1 / time3 # 计算速度提升倍数
time1 / time3 # Calculate speed gain
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

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

这一行代码注释仍是英文(“Calculate speed gain”),与其余中文讲义不一致。建议将注释翻译为中文以保持语言一致性。

Suggested change
time1 / time3 # Calculate speed gain
time1 / time3 # 计算加速比

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants