Can't pass cell array with shape of [N, 1] to matlab from Python

Aperta
#61 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
38/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
python
Ambito
tooling

Direzione di ricerca

Start with the Python MWE using start_instance, loadcase, workspace, and the MATLAB engine, then compare the native and round-trip bus_name sizes. Done means a nested [N, 1] cell array remains [N, 1] when passed from Python back to MATLAB and the runpf round trip succeeds.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Nested list of shape [N, 1] is passed as [1, 1], causing error array cell dimension. From matlab, cell array [N,1] is passed to Python as list [N], but send it back will make it into [1, N]. Nested [N, 1] from Python will be treated as [1, 1]

Python MWE:

from matpower import start_instance
m = start_instance(engine="matlab")

CASE_NAME = "case_RTS_GMLC.m"

m.eval(f"mpc_native = loadcase('{CASE_NAME}');", nargout=0)
print("MATLAB native class:", m.eval("class(mpc_native.bus_name)", nargout=1))
print("MATLAB native size :", m.eval("size(mpc_native.bus_name)", nargout=1))

mpc = m.loadcase(CASE_NAME)

bus_name = mpc["bus_name"]
print("Python type      :", type(bus_name))
print("First entry      :", bus_name[0])
print("First entry type :", type(bus_name[0]))
mpc["bus_name"] = np.atleast_2d(mpc["bus_name"]).tolist()

m.workspace["mpc_rt"] = mpc
print("Round-trip class   :", m.eval("class(mpc_rt.bus_name)", nargout=1))
print("Round-trip size    :", m.eval("size(mpc_rt.bus_name)", nargout=1))

m.eval("runpf(mpc_native);", nargout=0)  # success due to correct cell shape
m.eval("runpf(mpc_rt);", nargout=0)  # fail due to [[1.0,1.0]] array for bus_name

m.exit()
MATLAB native class: cell
MATLAB native size : [[73.0,1.0]]
Python type      : <class 'list'>
First entry      : ABEL
First entry type : <class 'str'>
Round-trip class   : cell
Round-trip size    : [[1.0,1.0]]
Lingua principale
Python
Stelle
97
Fork
13
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di mathworks/matlab-engine-for-python

Tutte le issue di mathworks/matlab-engine-for-python

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.