Arrays of structs should be returned as a list of the struct objects

Abierto
#10 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
32/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
matlab, python
Área
api, tooling

Línea de trabajo

No source file or test is named. Start by reproducing the MATLAB Engine cases with a = whos and a Simulink.BusElement array, then trace the conversion and ml.get/indexing entry points. Done means struct arrays become usable Python lists of struct objects and BusElement access no longer fails.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Currently, using Matlab 2019a and the associated Matlab Engine.

The engine fails to convert arrays of structs, which is a known limitation. However, the equivalent of a vector in Matlab is simply a list in Python, or, for a matrix, a list of lists. Other non-struct items correctly translate this way. The struct arrays should simply pass a list of struct objects to Python (which may need further conversion to be usable).

I worked around this by checking if it is a struct with max(size) greater than 1, and if so, I convert the variable to a cell with the struct2cell property, then pull the object into Python, which pulls it in as a list of the struct objects (or list of lists). The engine should be able to do this directly, rather than having to figure out whether to do a conversion first in the Matlab workspace.

An example of such an object is the output of whos: a = whos in Matlab.

Simulink.BusElement example and different error

Also, the Simulink.BusElement object of a Simulink.Bus will be a vector (though could be size 1). It will pull the multi-dimensional struct array into an object in Python, but the .get property fails, even if accessing the keys. i.e. ml.get(BusElement[0]) fails when BusElement is the matlab object given for the Elements property of a Simulink.Bus after translation into Python. The odd thing here is this fails with a different error. There seems to be a problem with the array indexing either in the struct array object, or the get function, or both.

Note

I just happened across the get and struct2cell properties by chance after a lot of digging from a stray answer for something else. I was pulling my hair out on getting this to work. Better documentation or examples for different types would be very helpful.

Lenguaje dominante
Python
Estrellas
97
Forks
13
Métricas de merge de PR
Sin PR fusionados en 30 d

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de mathworks/matlab-engine-for-python

Todos los issues de mathworks/matlab-engine-for-python

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.