Auto-converting one-dimensional AbstractArray to Matrix breaks type-checking logic in Python library
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 38/100
Hướng nghiên cứu
Đọc src/matrix.jl quanh dòng 37 và so sánh hai chuyển đổi PyObject với cách GAlgebra xử lý metric Ga. Tái hiện trường hợp đầu vào một chiều được nêu trong issue, sau đó xác định cách cần kiểm tra hành vi đối với các giá trị AbstractArray một chiều và hai chiều; hoàn tất có nghĩa là vẫn giữ được sự phân biệt dự kiến giữa danh sách Python và Matrix.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Julia
- Star
- 282
- Fork
- 59
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của JuliaPy/SymPy.jl
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 45/100
-
Not updated in registryĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 35/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 30/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
Tất cả issue của JuliaPy/SymPy.jl
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Sienna-Platform/PowerSystemCaseBuilder.jl#239 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
JuliaPluto/Malt.jl#114 ·
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
QuantumSavory/QuantumSavory.jl#592 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
JuliaQUBO/QUBOTools.jl#136 ·