Auto-converting one-dimensional AbstractArray to Matrix breaks type-checking logic in Python library
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 38/100
調査の方向性
src/matrix.jl の37行目付近を読み、2つの PyObject 変換を GAlgebra の Ga メトリック処理と比較してください。issue に示されている一次元入力のケースを再現し、そのうえで一次元および二次元の AbstractArray 値に対して動作をどのように検証すべきかを判断してください。意図された Python リストと Matrix の区別が維持されれば完了です。
索引モデルが issue の本文から書いたものです。
説明
In https://github.com/JuliaPy/SymPy.jl/blob/master/src/matrix.jl#L37:
## This allows abstract arrays of Sym Objects to slip through sympy.meth() calls
PyCall.PyObject(A::AbstractArray{Sym,2}) =
PyCall.pycall(sympy.Matrix, PyCall.PyObject, [PyCall.PyObject.(A[i,:]) for i in 1:size(A)[1]])
PyCall.PyObject(V::AbstractArray{Sym,1}) =
PyCall.pycall(sympy.Matrix, PyCall.PyObject,[[PyCall.PyObject(v)] for v in V])
This is fine for 2 dimensional AbstractArray and above, but it may break type-checking logic in Python library. And in GAlgebra and its Julia wrapper GAlgebra.jl, this is exactly the case.
The parameter g of galgebra.ga.Ga expects a metric which can be specified in many ways, as a string, as a Python list, or as a SymPy Matrix. The last two has a subtle difference:
- a Python list is treated as diagonal elements of the metric matrix
- a SymPy Matrix is treated as a complete matrix
For example, in the Python version of galgebra.ga.Ga, we can use:
#Define spherical coordinate system in 3-d
coords = (r, th, phi) = symbols('r,theta,phi', real=True)
s3d = Ga('e_r,e_th,e_ph', g=[1, r**2, r**2*sin(th)**2], coords=coords)
(er, eth, ephi) = s3d.mv()
Convert these to Julia syntax, it naturally becomes something like:
import SymPy: sympy
using GAlgebra
Ga = galgebra.ga.Ga
(r, th, phi) = coords = sympy.symbols("r theta phi", real=true)
s3d = Ga("e_r e_theta e_phi", g=[1, r^2, r^2 * sympy.sin(th)^2], coords=coords)
(er, eth, ephi) = s3d.mv()
But this won't work because SymPy automatically converted one-dimensional AbstractArray to Matrix, and GAlgebra will require a Matrix to be a complete metric Matrix instead of a list of diagonal elements of the metric matrix.
so I'll have to expand the Ga() call to
s3d = Ga("e_r e_theta e_phi", g=[1 0 0; 0 r^2 0; 0 0 r^2 * sympy.sin(th)^2], coords=coords, norm=true)
Of course, I can change GAlgebra to handle this scenario by treating one-dimensional sympy.Matrix as a list. But this might not work for other Python wrappers, and the core of the problem is one now can't pass a list of SymPy.jl objects to Python as a list of SymPy objects.
So I raised this issue to see if it could also cause problems for others and if it can be handled better.
- 主要言語
- Julia
- スター
- 282
- フォーク
- 59
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
JuliaPy/SymPy.jl のほかの issue
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 45/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 35/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 30/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
JuliaPy/SymPy.jl の issue をすべて見る
似ている issue
-
broken links in docsオープン
難易度 1/5 1時間未満 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
JuliaPhysics/BeamletOptics.jl#127 ·
メンテナーはふだん 1 日以内に返信
-
Chains resumed from `initial_state` take `num_warmup + 1` warm-up steps対応中かも @thevolatilebit が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 80/100
TuringLang/AbstractMCMC.jl#220 ·
-
found-by-agent
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
exanauts/SparseDirectSolver.jl#92 ·
メンテナーはふだん 1 日以内に返信
-
`inv` of a dense matrix fails for arrays whose `parent` is not an array of the same kind対応中かも @devmotion が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
JuliaLang/LinearAlgebra.jl#1740 ·
メンテナーはふだん 2 日以内に返信