Auto-converting one-dimensional AbstractArray to Matrix breaks type-checking logic in Python library
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 38/100
Línea de trabajo
Lee src/matrix.jl alrededor de la línea 37 y compara las dos conversiones a PyObject con el manejo de la métrica Ga de GAlgebra. Reproduce el caso de entrada unidimensional mostrado en el issue y determina después cómo debería verificarse el comportamiento para valores de AbstractArray unidimensionales y bidimensionales; se considera terminado cuando se conserva la distinción prevista entre lista de Python y Matrix.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- Julia
- Estrellas
- 282
- Forks
- 59
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de JuliaPy/SymPy.jl
-
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 45/100
-
Not updated in registryAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 35/100
-
Dificultad 4/5 3-5 días Aptitud para principiantes 30/100
-
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
Todos los issues de JuliaPy/SymPy.jl
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 60/100
EnzymeAD/ReactantServer.jl#103 ·
Los mantenedores suelen responder en 1 día
-
debye_length: strong_zero drops the permittivity's composition dependence from κ derivativesAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
ClapeyronThermo/Clapeyron.jl#649 ·
-
Add DocStringExtensionsAbiertodocumentation
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
ohno/Antique.jl#165 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
JuliaLang/LinearAlgebra.jl#1749 ·
Los mantenedores suelen responder en 2 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100