Auto-converting one-dimensional AbstractArray to Matrix breaks type-checking logic in Python library
还没有人认领这个 Issue。
评估
调研方向
阅读 src/matrix.jl 第 37 行附近的内容,并将两个 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 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 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
相似的 Issue
-
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 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 90/100
NumericalEarth/Breeze.jl#1051 ·
维护者通常 1 天内回复
-
lu_instance/qr_instance run a full factorization for FixedSizeArrays可能已有人在做 @devmotion 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
JuliaArrays/ArrayInterface.jl#510 ·