You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I had a student today who had some code running very slowly. It turned out he was accessing M.v[i, t] for i and t in a loop, and M a StateMonitor. Turning this into a single v=M.v and then v[i,t] made it run almost instantly. I'm wondering if we can catch this sort of thing and warn about it because it might be tripping up a few people. Perhaps something like if you access M.v more than 100 times as often as you run M it gives you the warning? Not sure of the best way here, or if there's some general way to catch these sorts of issues or not.
The text was updated successfully, but these errors were encountered:
Hmm, not sure about a warning, I'd prefer if it would be fast in the first place :) Of course there's almost never a reason to loop over a 2D array instead of treating it like a matrix, but many users will still do it, and there is no reason to make this slow if we don't have to.
I just had a quick look into StateMonitor.__getattr__ and there's a weird thing: if you access M.v (i.e. with units), it will make a copy of the data, whereas it gives you a direct reference without a copy if you access M.v_ (i.e. without units). So the latter should already be reasonably fast even in looped access.
I could come up with reasons for a copy – e.g. related to problems when the underlying data gets resized in a second run – but I don't quite see why it should only apply to values with units... I'll try to dig into history at some point to see whether this was intentional.
I had a student today who had some code running very slowly. It turned out he was accessing
M.v[i, t]
fori
andt
in a loop, andM
aStateMonitor
. Turning this into a singlev=M.v
and thenv[i,t]
made it run almost instantly. I'm wondering if we can catch this sort of thing and warn about it because it might be tripping up a few people. Perhaps something like if you accessM.v
more than 100 times as often as you runM
it gives you the warning? Not sure of the best way here, or if there's some general way to catch these sorts of issues or not.The text was updated successfully, but these errors were encountered: