Compute cross product between list of 3D vectors. Much faster than np.cross() when the number of cross products becomes large (>= 500). This is because np.cross() methods become less memory efficient at this stage. Parameters ---------- x : array Input array 1, shap
(x, y)
| 333 | |
| 334 | |
| 335 | def fast_cross_3d(x, y): |
| 336 | """Compute cross product between list of 3D vectors. |
| 337 | |
| 338 | Much faster than np.cross() when the number of cross products |
| 339 | becomes large (>= 500). This is because np.cross() methods become |
| 340 | less memory efficient at this stage. |
| 341 | |
| 342 | Parameters |
| 343 | ---------- |
| 344 | x : array |
| 345 | Input array 1, shape (..., 3). |
| 346 | y : array |
| 347 | Input array 2, shape (..., 3). |
| 348 | |
| 349 | Returns |
| 350 | ------- |
| 351 | z : array, shape (..., 3) |
| 352 | Cross product of x and y along the last dimension. |
| 353 | |
| 354 | Notes |
| 355 | ----- |
| 356 | x and y must broadcast against each other. |
| 357 | """ |
| 358 | assert x.ndim >= 1 |
| 359 | assert y.ndim >= 1 |
| 360 | assert x.shape[-1] == 3 |
| 361 | assert y.shape[-1] == 3 |
| 362 | if max(x.size, y.size) >= 500: |
| 363 | out = np.empty(np.broadcast(x, y).shape) |
| 364 | _jit_cross(out, x, y) |
| 365 | return out |
| 366 | else: |
| 367 | return np.cross(x, y) |
| 368 | |
| 369 | |
| 370 | @jit() |