diff --git a/docs/en/releases/unreleased.ipynb b/docs/en/releases/unreleased.ipynb index ee5f2d9..a34e6f9 100644 --- a/docs/en/releases/unreleased.ipynb +++ b/docs/en/releases/unreleased.ipynb @@ -18,7 +18,55 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### Feature 1" + "### Generating arrays with a shape and generator function\n", + "\n", + "Starting with this version, the {py:func}`~jijmodeling.genarray` function can be used to generate arrays by specifying a shape and a generator function.\n", + "This is similar to {py:func}`~numpy.fromfunction` in NumPy." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "38785527", + "metadata": { + "execution": { + "iopub.execute_input": "2026-04-14T02:56:24.225462Z", + "iopub.status.busy": "2026-04-14T02:56:24.225369Z", + "iopub.status.idle": "2026-04-14T02:56:25.559880Z", + "shell.execute_reply": "2026-04-14T02:56:25.559497Z" + } + }, + "outputs": [ + { + "data": { + "text/latex": [ + "$$\\begin{array}{rl}\n", + "\\text{Problem}\\colon &\\text{genarray example}\\\\\\displaystyle \\min &\\displaystyle 0\\\\&\\\\\\text{where}&\\\\&\\text{Decision Variables:}\\\\&\\qquad \\begin{alignedat}{2}x&\\in \\mathop{\\mathrm{Array}}\\left[N;\\left\\{0, 1\\right\\}\\right]&\\quad &1\\text{-dim binary variable}\\\\\\end{alignedat}\\\\&\\\\&\\text{Placeholders:}\\\\&\\qquad \\begin{alignedat}{2}a&\\in \\mathop{\\mathrm{Array}}\\left[N\\times M;\\mathbb{R}\\right]&\\quad &2\\text{-dimensional array of placeholders with elements in }\\mathbb{R}\\\\M&\\in \\mathbb{N}&\\quad &\\text{A scalar placeholder in }\\mathbb{N}\\\\N&\\in \\mathbb{N}&\\quad &\\text{A scalar placeholder in }\\mathbb{N}\\\\\\end{alignedat}\\\\&\\\\&\\text{Named Expressions:}\\\\&\\qquad \\begin{alignedat}{2}Sums&={\\left( {a}_{i,j}\\cdot {x}_{i}\\right) }_{\\substack{i\\in \\left\\{0,\\ldots ,N-1\\right\\}\\\\j\\in \\left\\{0,\\ldots ,M-1\\right\\}}}&\\quad &\\in \\mathop{\\mathrm{Array}}\\left[N\\times M;\\mathbb{R}\\right]\\\\\\end{alignedat}\\end{array}\n", + "$$" + ], + "text/plain": [ + "Problem(name=\"genarray example\", sense=MINIMIZE, objective=0, constraints=[])" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import jijmodeling as jm\n", + "\n", + "\n", + "@jm.Problem.define(\"genarray example\")\n", + "def problem(problem):\n", + " N = problem.Natural()\n", + " M = problem.Natural()\n", + " a = problem.Float(shape=(N, M))\n", + " x = problem.BinaryVar(shape=N)\n", + " Sums = problem.NamedExpr(jm.genarray(lambda i, j: a[i, j] * x[i], (N, M)))\n", + "\n", + "\n", + "problem" ] }, { @@ -44,14 +92,14 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 2, "id": "3a442924", "metadata": { "execution": { - "iopub.execute_input": "2026-04-13T06:58:16.006255Z", - "iopub.status.busy": "2026-04-13T06:58:16.006136Z", - "iopub.status.idle": "2026-04-13T06:58:16.466116Z", - "shell.execute_reply": "2026-04-13T06:58:16.465739Z" + "iopub.execute_input": "2026-04-14T02:56:25.560974Z", + "iopub.status.busy": "2026-04-14T02:56:25.560909Z", + "iopub.status.idle": "2026-04-14T02:56:25.907338Z", + "shell.execute_reply": "2026-04-14T02:56:25.906912Z" } }, "outputs": [ @@ -66,7 +114,7 @@ "Problem(name=\"My Problem\", sense=MINIMIZE, objective=sum(N.flat_map(lambda (i: natural): M.map(lambda (j: natural): (i, j))).map(lambda ((i, j): Tuple[natural, natural]): a[i] * b[i, j])), constraints=[])" ] }, - "execution_count": 1, + "execution_count": 2, "metadata": {}, "output_type": "execute_result" } @@ -97,14 +145,14 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 3, "id": "cda9cce0", "metadata": { "execution": { - "iopub.execute_input": "2026-04-13T06:58:16.467341Z", - "iopub.status.busy": "2026-04-13T06:58:16.467272Z", - "iopub.status.idle": "2026-04-13T06:58:16.509069Z", - "shell.execute_reply": "2026-04-13T06:58:16.508690Z" + "iopub.execute_input": "2026-04-14T02:56:25.908416Z", + "iopub.status.busy": "2026-04-14T02:56:25.908362Z", + "iopub.status.idle": "2026-04-14T02:56:25.968107Z", + "shell.execute_reply": "2026-04-14T02:56:25.967772Z" } }, "outputs": [ @@ -119,7 +167,7 @@ " 1.6632417823227748], dtype=object)}" ] }, - "execution_count": 2, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } @@ -141,14 +189,14 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 4, "id": "b743aa56", "metadata": { "execution": { - "iopub.execute_input": "2026-04-13T06:58:16.510011Z", - "iopub.status.busy": "2026-04-13T06:58:16.509941Z", - "iopub.status.idle": "2026-04-13T06:58:16.518618Z", - "shell.execute_reply": "2026-04-13T06:58:16.518300Z" + "iopub.execute_input": "2026-04-14T02:56:25.969236Z", + "iopub.status.busy": "2026-04-14T02:56:25.969159Z", + "iopub.status.idle": "2026-04-14T02:56:25.979036Z", + "shell.execute_reply": "2026-04-14T02:56:25.978633Z" } }, "outputs": [ @@ -158,7 +206,7 @@ "{'N': 3}" ] }, - "execution_count": 3, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } diff --git a/docs/ja/releases/unreleased.ipynb b/docs/ja/releases/unreleased.ipynb index 9bc7745..f5d567b 100644 --- a/docs/ja/releases/unreleased.ipynb +++ b/docs/ja/releases/unreleased.ipynb @@ -18,7 +18,55 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### 機能1" + "### シェイプと生成関数による配列の生成\n", + "\n", + "本バージョンから、{py:func}`~jijmodeling.genarray` 関数により、シェイプと生成関数を指定して配列を生成できるようになりました。\n", + "これは numpy の {py:func}`~numpy.fromfunction` と類似の機能です。" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "454e2d9a", + "metadata": { + "execution": { + "iopub.execute_input": "2026-04-14T02:56:26.849353Z", + "iopub.status.busy": "2026-04-14T02:56:26.849298Z", + "iopub.status.idle": "2026-04-14T02:56:27.219237Z", + "shell.execute_reply": "2026-04-14T02:56:27.218867Z" + } + }, + "outputs": [ + { + "data": { + "text/latex": [ + "$$\\begin{array}{rl}\n", + "\\text{Problem}\\colon &\\text{genarray example}\\\\\\displaystyle \\min &\\displaystyle 0\\\\&\\\\\\text{where}&\\\\&\\text{Decision Variables:}\\\\&\\qquad \\begin{alignedat}{2}x&\\in \\mathop{\\mathrm{Array}}\\left[N;\\left\\{0, 1\\right\\}\\right]&\\quad &1\\text{-dim binary variable}\\\\\\end{alignedat}\\\\&\\\\&\\text{Placeholders:}\\\\&\\qquad \\begin{alignedat}{2}a&\\in \\mathop{\\mathrm{Array}}\\left[N\\times M;\\mathbb{R}\\right]&\\quad &2\\text{-dimensional array of placeholders with elements in }\\mathbb{R}\\\\M&\\in \\mathbb{N}&\\quad &\\text{A scalar placeholder in }\\mathbb{N}\\\\N&\\in \\mathbb{N}&\\quad &\\text{A scalar placeholder in }\\mathbb{N}\\\\\\end{alignedat}\\\\&\\\\&\\text{Named Expressions:}\\\\&\\qquad \\begin{alignedat}{2}Sums&={\\left( {a}_{i,j}\\cdot {x}_{i}\\right) }_{\\substack{i\\in \\left\\{0,\\ldots ,N-1\\right\\}\\\\j\\in \\left\\{0,\\ldots ,M-1\\right\\}}}&\\quad &\\in \\mathop{\\mathrm{Array}}\\left[N\\times M;\\mathbb{R}\\right]\\\\\\end{alignedat}\\end{array}\n", + "$$" + ], + "text/plain": [ + "Problem(name=\"genarray example\", sense=MINIMIZE, objective=0, constraints=[])" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import jijmodeling as jm\n", + "\n", + "\n", + "@jm.Problem.define(\"genarray example\")\n", + "def problem(problem):\n", + " N = problem.Natural()\n", + " M = problem.Natural()\n", + " a = problem.Float(shape=(N, M))\n", + " x = problem.BinaryVar(shape=N)\n", + " Sums = problem.NamedExpr(jm.genarray(lambda i, j: a[i, j] * x[i], (N, M)))\n", + "\n", + "\n", + "problem" ] }, { @@ -45,14 +93,14 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 2, "id": "503193f3", "metadata": { "execution": { - "iopub.execute_input": "2026-04-13T06:58:17.214029Z", - "iopub.status.busy": "2026-04-13T06:58:17.213975Z", - "iopub.status.idle": "2026-04-13T06:58:17.539639Z", - "shell.execute_reply": "2026-04-13T06:58:17.539309Z" + "iopub.execute_input": "2026-04-14T02:56:27.220364Z", + "iopub.status.busy": "2026-04-14T02:56:27.220300Z", + "iopub.status.idle": "2026-04-14T02:56:27.562415Z", + "shell.execute_reply": "2026-04-14T02:56:27.561917Z" } }, "outputs": [ @@ -67,7 +115,7 @@ "Problem(name=\"My Problem\", sense=MINIMIZE, objective=sum(N.flat_map(lambda (i: natural): M.map(lambda (j: natural): (i, j))).map(lambda ((i, j): Tuple[natural, natural]): a[i] * b[i, j])), constraints=[])" ] }, - "execution_count": 1, + "execution_count": 2, "metadata": {}, "output_type": "execute_result" } @@ -98,29 +146,29 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 3, "id": "9efb052a", "metadata": { "execution": { - "iopub.execute_input": "2026-04-13T06:58:17.540874Z", - "iopub.status.busy": "2026-04-13T06:58:17.540807Z", - "iopub.status.idle": "2026-04-13T06:58:17.562065Z", - "shell.execute_reply": "2026-04-13T06:58:17.561746Z" + "iopub.execute_input": "2026-04-14T02:56:27.563998Z", + "iopub.status.busy": "2026-04-14T02:56:27.563886Z", + "iopub.status.idle": "2026-04-14T02:56:27.587625Z", + "shell.execute_reply": "2026-04-14T02:56:27.587282Z" } }, "outputs": [ { "data": { "text/plain": [ - "{'a': array([1.9051444149700796, 4.388381466224443, 4.6746291952632575,\n", - " 1.6632417823227748], dtype=object),\n", - " 'b': array([[5, 5, 3, 3, 0],\n", + "{'b': array([[5, 5, 3, 3, 0],\n", " [5, 2, 1, 2, 0],\n", " [0, 1, 5, 3, 5],\n", - " [0, 2, 3, 0, 2]], dtype=object)}" + " [0, 2, 3, 0, 2]], dtype=object),\n", + " 'a': array([1.9051444149700796, 4.388381466224443, 4.6746291952632575,\n", + " 1.6632417823227748], dtype=object)}" ] }, - "execution_count": 2, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } @@ -142,14 +190,14 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 4, "id": "3076f3b8", "metadata": { "execution": { - "iopub.execute_input": "2026-04-13T06:58:17.563228Z", - "iopub.status.busy": "2026-04-13T06:58:17.563157Z", - "iopub.status.idle": "2026-04-13T06:58:17.572127Z", - "shell.execute_reply": "2026-04-13T06:58:17.571809Z" + "iopub.execute_input": "2026-04-14T02:56:27.588786Z", + "iopub.status.busy": "2026-04-14T02:56:27.588712Z", + "iopub.status.idle": "2026-04-14T02:56:27.598577Z", + "shell.execute_reply": "2026-04-14T02:56:27.598318Z" } }, "outputs": [ @@ -159,7 +207,7 @@ "{'N': 3}" ] }, - "execution_count": 3, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } diff --git a/markdowns/en/releases/unreleased.md b/markdowns/en/releases/unreleased.md index 26367b7..ee8b348 100644 --- a/markdowns/en/releases/unreleased.md +++ b/markdowns/en/releases/unreleased.md @@ -19,9 +19,26 @@ kernelspec: +++ -### Feature 1 +### Generating arrays with a shape and generator function -+++ +Starting with this version, the {py:func}`~jijmodeling.genarray` function can be used to generate arrays by specifying a shape and a generator function. +This is similar to {py:func}`~numpy.fromfunction` in NumPy. + +```{code-cell} ipython3 +import jijmodeling as jm + + +@jm.Problem.define("genarray example") +def problem(problem): + N = problem.Natural() + M = problem.Natural() + a = problem.Float(shape=(N, M)) + x = problem.BinaryVar(shape=N) + Sums = problem.NamedExpr(jm.genarray(lambda i, j: a[i, j] * x[i], (N, M))) + + +problem +``` ## Bugfixes diff --git a/markdowns/ja/releases/unreleased.md b/markdowns/ja/releases/unreleased.md index 7f014cc..3425457 100644 --- a/markdowns/ja/releases/unreleased.md +++ b/markdowns/ja/releases/unreleased.md @@ -19,9 +19,26 @@ kernelspec: +++ -### 機能1 +### シェイプと生成関数による配列の生成 -+++ +本バージョンから、{py:func}`~jijmodeling.genarray` 関数により、シェイプと生成関数を指定して配列を生成できるようになりました。 +これは numpy の {py:func}`~numpy.fromfunction` と類似の機能です。 + +```{code-cell} ipython3 +import jijmodeling as jm + + +@jm.Problem.define("genarray example") +def problem(problem): + N = problem.Natural() + M = problem.Natural() + a = problem.Float(shape=(N, M)) + x = problem.BinaryVar(shape=N) + Sums = problem.NamedExpr(jm.genarray(lambda i, j: a[i, j] * x[i], (N, M))) + + +problem +``` ## バグ修正