Skip to content

Commit fd38025

Browse files
committed
Error example
1 parent 2d9efb8 commit fd38025

4 files changed

Lines changed: 121 additions & 7 deletions

File tree

docs/en/releases/unreleased.ipynb

Lines changed: 42 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/ja/releases/unreleased.ipynb

Lines changed: 45 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

markdowns/en/releases/unreleased.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,22 @@ Comprehensions used with `jm.genarray` MUST satisfy the following conditions:
6060
2. The `for` clause must be a single loop of the form `for i_1, .., i_k in (N_1, .., N_k)` for natural-number expressions `N_i`.
6161
If the arity and types match, the variable names may be arbitrary, and the expression itself may be complex.
6262

63+
The following is an example that raises an error because it uses multiple `for` clauses:
64+
65+
```{code-cell} ipython3
66+
try:
67+
68+
@jm.Problem.define("genarray example")
69+
def problem(problem):
70+
N = problem.Natural()
71+
M = problem.Natural()
72+
a = problem.Float(shape=(N, M))
73+
x = problem.BinaryVar(shape=N)
74+
Sums = problem.NamedExpr(jm.genarray(a[i, j] * x[i] for i in N for j in M))
75+
except SyntaxError as e:
76+
print(str(e))
77+
```
78+
6379
### Support for `min` / `max` along axes
6480

6581
Previously, {py:func}`jm.sum <jijmodeling.sum>` and {py:meth}`Expression.sum <jijmodeling.Expression.sum>` supported taking sums along a specific axis of a multidimensional array via the `axis` keyword argument.
@@ -191,3 +207,4 @@ Starting with this release, data is generated successfully in cases like the exa
191207
## Other Changes
192208

193209
- Relaxed version bounds to allow installation on any Python 3 version from Python 3.11 onwards.
210+
- Error messages for invalid comprehensions used with the Decorator API in `sum` and similar constructs now report the specific location in the source code.

markdowns/ja/releases/unreleased.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,22 @@ problem
6060
2. `for` 部は自然数式 `N_i` に対し、 `for i_1, .., i_k in (N_1, .., N_k)` の形の単一のループであること。
6161
+ 個数と型が合っていれば、変数名は何でも構いませんし、複雑な式を書くこともできます。
6262

63+
以下は、複数の `for`-節を使ってしまい、エラーになっている例です:
64+
65+
```{code-cell} ipython3
66+
try:
67+
68+
@jm.Problem.define("genarray example")
69+
def problem(problem):
70+
N = problem.Natural()
71+
M = problem.Natural()
72+
a = problem.Float(shape=(N, M))
73+
x = problem.BinaryVar(shape=N)
74+
Sums = problem.NamedExpr(jm.genarray(a[i, j] * x[i] for i in N for j in M))
75+
except SyntaxError as e:
76+
print(str(e))
77+
```
78+
6379
## 軸に沿った `min` / `max` のサポート
6480

6581
旧来は {py:func}`jm.sum <jijmodeling.sum>` や {py:meth}`Expression.sum <jijmodeling.Expression.sum>` では `axis` キーワード引数により、多次元配列の特定の軸に沿った和を取ることができましたが、今回のバージョンからは {py:func}`jm.min <jijmodeling.min>` と {py:func}`jm.max <jijmodeling.max>`(そしてその対応する `Expression` メソッド)にも同様の機能が追加されました。
@@ -186,3 +202,4 @@ problem.generate_random_dataset(seed=17)
186202
## その他の変更
187203

188204
- バージョン条件を緩和し、Python 3.11 以降の任意の Python 3 でのインストールを許容しました。
205+
- Decorator API の `sum` などで不正な内包表記を使った際のエラーメッセージが、具体的なコード上の位置を報告するようになりました。

0 commit comments

Comments
 (0)