0

I am writing a unit test. The thing it tests involves numpy memmaps, which, like numpy ndarrays, can be "views" that reference an other memmap's data (and take no time to create) or copies (which take a long time to create).

I want to test how many copy-type memmaps are created inside my function and ensure it is minimized given certain inputs. Is this possible?

Pavel Komarov
  • 1,153
  • 12
  • 26
  • If you can identify the copy constructor for the memmaps you can write a wrapper around that function that counts the number of invocations and then substitute that wrapper function for the copy constructor. What I don't know is if the copy constructor is implemented in python or in C. – Nick Chapman Oct 04 '17 at 20:32
  • I don't really want to write a wrapper and then call that instead of the native constructor in my underlying function. I want some kind of access to the heap so I can see what was put on it. – Pavel Komarov Oct 04 '17 at 20:45
  • Another option is to statically analyze your code to see how many objects of type it creates. But that can get very tricky very quickly – inspectorG4dget Oct 04 '17 at 20:56
  • @pvlkmrv writing the wrapper would be really easy, it's essentially adding a decorator for the constructor – Nick Chapman Oct 04 '17 at 21:09
  • NickChapman, yeah still don't want to do that. Want to use native numpy. @inspectorG4dget, is there any way to put such analysis in a unit test? – Pavel Komarov Oct 04 '17 at 21:44

0 Answers0