MatX icon indicating copy to clipboard operation
MatX copied to clipboard

[FEA] Add cross product operator

Open cliffburdick opened this issue 2 years ago • 8 comments

Should support 3D points with an arbitrary rank (Nx3)

cliffburdick avatar Aug 25 '23 15:08 cliffburdick

I use cross products quite a bit and would be interested in implementing this. Anything I should be aware of regarding intended implementation or anything?

mfzmullen avatar Jul 19 '24 21:07 mfzmullen

Great! I think I would do the following:

  1. Copy the operator source from something like polyval.h into a new file called cross.h with the namings inside changed
  2. Take two operators as input. Have a runtime check that the last dimension has length 3 (Or 2 for bonus points if you want z=0). The other dimensions are batching. The dimensions are a bit awkward because of the 3D nature not fitting in a warp size, but it doesn't need to be optimal right now.
  3. Add unit tests for batching and non-batching cases
  4. Update docs pointing to the tests and any extra notes

cliffburdick avatar Jul 19 '24 22:07 cliffburdick

Great thanks! I'll start on this sometime this week.

mfzmullen avatar Jul 22 '24 14:07 mfzmullen

As a matter of convention in MatX, are assertions best defined in the constructor for a class template specialization (e.g. like in polyval.h) or in the Exec method, like in corr.h?

mfzmullen avatar Jul 25 '24 19:07 mfzmullen

In general if they're template parameters of the class they should go at the top of the class (doesn't even have to be in the ctor). In the corr.h case those are template parameters to the function so they must be in the function itself.

cliffburdick avatar Jul 25 '24 19:07 cliffburdick

This hasn't dropped off my radar, just haven't had a chance to look at it since implementing the runtime checks.

mfzmullen avatar Aug 20 '24 21:08 mfzmullen

Finally got around to this! Have some unit tests put together locally but unsure where to put the documentation. Would it make sense to place it in docs_input/api/linalg/other? Logic being that Numpy has a cross function in np.linalg (which just seems to reference the core version of np.cross).

mfzmullen avatar Jan 07 '25 21:01 mfzmullen

Hi @mfzmullen , thanks! Yes, that location sounds good.

cliffburdick avatar Jan 07 '25 21:01 cliffburdick

Cross was added: https://nvidia.github.io/MatX/api/linalg/other/cross.html

cliffburdick avatar Aug 07 '25 23:08 cliffburdick