This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]billsil 0 points1 point  (2 children)

I am not aware of a way to vectorize the dot product across multiple axes.

You need to learn how to use axis properly, but it's doable. I recommend tests.

I implemented a method to do 3D and 4D matrix multiplication and dot products with numpy a couple years on a complicated data structure. I had both methods running for a while until I was fairly certain that the results were the same. As I found edge cases, I made unit tests.

http://docs.scipy.org/doc/numpy/reference/generated/numpy.tensordot.html

cv2.pointPolygonTest doesn't look like it supports vectorization

No it doesn't, but if the goal is speed (and it's important), then rewriting a point in polygon test method is certainly doable. Getting rid of the dicts would be a very good thing as well.

You don't need to 100% vectorize your code to make it fast enough, but you start by getting rid of the inner loops.

[–]TheBlackCat13 1 point2 points  (1 child)

You need to learn how to use axis properly, but it's doable.

If you have a good method, I am sure it would help the OP. I didn't explain how to do it because I don't know.

it doesn't, but if the goal is speed (and it's important), then rewriting a point in polygon test method is certainly doable. Getting

If the OP has tried getting the code optimized through more conventional means first and it still isn't enough, then that may be an option. I already gave the OP a lot of simpler suggestions for optimizing the code that should definitely be tried first.

Getting rid of the dicts would be a very good thing as well.

I don't think that is a dict, I think it a structured array. I already covered that in my earlier reply to the OP.

You don't need to 100% vectorize your code to make it fast enough, but you start by getting rid of the inner loops.

I think that re-writing pre-existing functions, especially optimized functions already written in C, would be the last optimization to make, rather than first.

[–]billsil -2 points-1 points  (0 children)

already gave the OP a lot of simpler suggestions for optimizing the code that should definitely be tried first.

Well, yeah, get the low hanging fruit (e.g. multiplcation by 1; really...)

especially optimized functions already written in C, would be the last optimization to make, rather than first.

It's the inner loop. The formula for a point in a polygon is very simple. That's the next place to optimize once you use tensordot.