baharev/sdopt-tearing

Add support for NumPy arrays

EDWhyte opened this issue · 4 comments

The following error is encountered when running

  • rpc_api.fine_dulmage_mendelsohn
  • heap_md.hessenberg
  • bordered.to_bordered_form

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

The errors originate from the following lines:

  • dm_decomp.py line 148
  • order_util.py line 104 + 105

The current code is meant to be used with pure Python lists only, and has been tested accordingly. Most of sdopt-tearing works without NumPy, and it is an important a requirement for me.

In the future, I will add support for NumPy arrays too, however that will need more work and careful testing. Please do not forget that the code here is just a snapshot of my private repo, which has additional 7000 SLOC Python code that you do not see here. Implementing this enhancement will be time consuming, and has low priority.

A workaround would be to check in the top level API functions whether the caller actually passed in a pure Python list. If not, try to convert the arguments to lists on a best effort basis. This is fairly easy and straightforward to implement.

From a performance point of view, it is probably still a negligible overhead because the bottlenecks of the computations are in the min heap and in the networkx graphs. Using NumPy arrays won't help as these datastructures are pure Python datastructures anyway.

I converted the passed arguments to lists with no errors

Yes, probably that is the best workaround, and maybe the "solution" as well.

It is just so much easier to do this conversion upfront at the top-level, then chasing down all the possible cases where the list and the np.ndarray APIs differ. There is a cost too, an unnecessary copy, but it should not be noticeable as it is not the bottleneck.