Skip to content

Closes 4124, align ak.dot to np.dot. - #4224

Merged
ajpotts merged 2 commits into
Bears-R-Us:masterfrom
drculhane:Closes-4124
Apr 22, 2025
Merged

ajpotts merged 2 commits into
Bears-R-Us:masterfrom
drculhane:Closes-4124

Conversation

@drculhane

@drculhane drculhane commented Apr 7, 2025 •

Copy link
Copy Markdown
Contributor

Closes #4124

Summary of work:

There was a lot here, hence these comments so that you won't have to start from scratch when you review this.

Aligning ak.dot to np.dot has been time-consuming, as np.dot does much more than the conventional 1-D vector dot product. Hopefully the comments in def dot, in pdarrayclass.py, make it clear what's going on.

In addition to the executable python code, there's a new docstring that gives examples of all use cases of ak.dot.

It's worth noting that in order to prevent mypy from freaking out, ak.dot requires several # type: ignore statements, as is typical with functions whose inputs accept a Union of types. There's also an unreachable return None (also with a # type: ignore) which prevents mypy from claiming there's a missing return. I considered just having mypy bypass this function.

There were test_dot functions in both pdarrayclass_test.py and numeric_test.py. The one in numeric_test.py has been removed. The one in pdarrayclass_test.py has been changed to cover all the possible use cases and data types of ak.dot.

A possible TODO: move dot out of pdarrayclass.py and into _numeric.py. Similarly with test_dot.

A dotProd function was added to LinalgMsg.chpl to perform the computation (thank you, Ryan). I modified Ryan's code to allow for the case where the two pdarrays aren't of the same type.

In LinalgMsg.chpl, both dotProd and matmul need to compute the return type based on the input types. Both call a function named np_ret_type (which is meant to stand for "numpy return type"). There is a similar function called by vecdot (it's currently called compute_result_type_vecdot). In a future alignment of ak.vecdot to np.vecdot, that function may also be rolled into np_ret_type.

Additional changes were needed in LinalgMsg.chpl, OperatorMsg.chpl and BinOp.chpl to enable all of the appropriate combinations of data types.

Another possible TODO: make a 1D case for dotProd, rather than piggyback onto the ND case.

A very likely TODON'T: make test cases for > 3D. So far, I've found that making arkouda with max_dim > 3 isn't feasible.

Ryan: I'd love if you could add some comments to the dotProd proc in LinalgMsg.chpl.

@drculhane drculhane changed the title Initial Draft PR Closes 4124, align ak.dot to np.dot. Apr 8, 2025
@drculhane
drculhane marked this pull request as ready for review April 9, 2025 12:05
@drculhane
drculhane force-pushed the Closes-4124 branch 4 times, most recently from aa2ca26 to e982c3e Compare April 14, 2025 12:29

@1RyanK 1RyanK left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

Comment thread arkouda/numpy/pdarrayclass.py Resolved
Comment thread src/LinalgMsg.chpl Resolved
Comment thread src/LinalgMsg.chpl Resolved

@jaketrookman jaketrookman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

@ajpotts
ajpotts added this pull request to the merge queue Apr 21, 2025
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to no response for status checks Apr 21, 2025
@ajpotts
ajpotts added this pull request to the merge queue Apr 21, 2025
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to no response for status checks Apr 21, 2025
@ajpotts
ajpotts added this pull request to the merge queue Apr 22, 2025
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to no response for status checks Apr 22, 2025
@ajpotts
ajpotts added this pull request to the merge queue Apr 22, 2025
Merged via the queue into Bears-R-Us:master with commit a0324fa Apr 22, 2025
@drculhane
drculhane deleted the Closes-4124 branch June 3, 2025 13:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Align ak.dot to numpy dot

5 participants