fix(solve): random_walk 的 start 校验恢复后收尾(文案/空格/测试)
两条口径由用户第二轮改定,Codex 顺手补工程侧。 - 用户:恢复 start 的入口类型校验;n_steps/n_paths 注解放宽为 int | np.integer - Codex:start 报错文案"必须是整数" -> "必须是数值"(这条校验本来就收 float,原文案自相矛盾), 类型名统一 type(x).__name__;n_paths 默认值补空格;docstring 的 start 说明与 Raises 同步 - tests:start="a" 恢复断言 TypeError;补回 np.int64 的 n_steps/n_paths;solve 段 42 条 - 验证:209 收集 / 178 passed / 31 skipped / 0 xfail,ruff 0,pyright 0 - docs:STATUS 决策 55(方阵歧义两条路)+ 验证计数;CHANGELOG
This commit is contained in:
1 parent
6fca82e3fc
commit
cd6f613568
4 files changed
+54
-21
No files matched your search
@@ -335,8 +335,8 @@ def monte_carlo_integral(
|
||||
|
||||
|
||||
def random_walk(
|
||||
n_steps: int,
|
||||
n_paths: int = 1,
|
||||
n_steps: int | np.integer,
|
||||
n_paths: int | np.integer = 1,
|
||||
step_sampler: Callable[..., Any] | None = None,
|
||||
start: float = 0.0,
|
||||
random_state: int | None = None,
|
||||
@@ -354,7 +354,7 @@ def random_walk(
|
||||
必须返回形状 `(n_paths, n_steps)` 的数组(契约同 `monte_carlo` 的 `sampler`,只是这里是二维)。
|
||||
默认 ±1 等概率(对称随机游走)。
|
||||
start:
|
||||
起点,写进每条路径的第 0 列(**入口不校验类型**,传非数值会落到失败分支)。
|
||||
起点,写进每条路径的第 0 列。
|
||||
random_state:
|
||||
随机种子。`None` 时跟随 `core.set_seed` 的全局流,见 `core.random.get_rng`。
|
||||
|
||||
@@ -367,6 +367,7 @@ def random_walk(
|
||||
------
|
||||
TypeError:
|
||||
`n_steps` / `n_paths` 不是整数。
|
||||
`start` 不是数值。
|
||||
ValueError:
|
||||
`n_steps` / `n_paths` 不是正整数。
|
||||
|
||||
@@ -397,6 +398,9 @@ def random_walk(
|
||||
if n_paths <= 0:
|
||||
raise ValueError(f"n_paths 必须是正整数,你传入了 {n_paths}")
|
||||
|
||||
if not isinstance(start, (int, float, np.number)):
|
||||
raise TypeError(f"start 必须是数值,你传入了 {type(start).__name__}")
|
||||
|
||||
rng = get_rng(random_state)
|
||||
|
||||
if step_sampler is None:
|
||||
@@ -425,7 +429,7 @@ def random_walk(
|
||||
paths[:, 0] = start
|
||||
paths[:, 1:] = start + cumsum
|
||||
|
||||
terminal_positions = paths[:, -1] # 取最后一列,得到 n_paths 个终点位置
|
||||
terminal_positions = paths[:, -1]
|
||||
metrics = {
|
||||
"mean_terminal": float(np.mean(terminal_positions)),
|
||||
"std_terminal": float(np.std(terminal_positions))
|
||||
|
||||
Reference in new issue
Block a user