New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add select
Operation
#207
Add select
Operation
#207
Conversation
Two ways of calling: 1. A.select(op, thunk) 2. gb.select.op(A, thunk) When calling `A.select(op)`, the op may be passed as a string. An additional set of "special" select functions take a comparator expression. An example: `gb.select.row(A <= 2)`. Row, column, and value are included, indicating what part of A is being compared in the select statement.
Aha, I see you found errors in the bizarro tests: https://github.com/metagraph-dev/grblas/blob/8e9acb9c1ac0e5689fc2f1066fd60020ea1c3ffe/.github/workflows/test_and_build.yml#L102-L109 This trick is kinda weird, but it's the best way I know to test both types of scalars (C and GrB) throughout the API. You may find it handy to switch to bizarro world locally with this command: #!/bin/bash
find grblas -type f -name "*.py" -print0 | xargs -0 sed -i -s \
-e '/# pragma: is_grbscalar/! s/is_cscalar=False/is_cscalar=True/g' \
-e '/# pragma: is_grbscalar/! s/is_cscalar = False/is_cscalar = True/g' \
-e '/# pragma: to_grb/ s/is_cscalar=True/is_cscalar=False/g' \
-e '/# pragma: to_grb/ s/is_cscalar = True/is_cscalar = False/g' Scalars are GrB by default, but there are a few places in the code where they must be a specific type of scalar.
Once you apply the above search-and-replace, you can't search-and-replace back the the original. Sometimes using patches is handy if you need to make changes. |
We added |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to change IndexUnaryOp to SelectOp. When we add apply with index unary, I will add that in as a different op class.
- Use correct dtype based on thunk - Handle Scalar thunk properly - Rename IndexUnaryOp to SelectOp
Please try to increase coverage: https://coveralls.io/builds/48230528 |
@eriknw I think this is ready. Please take one last look, and if you're happy with it, go ahead and merge. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It occurs to me that several of the SelectOps are awkward for Vectors. gb.select.row
needs to be used instead of gb.select.column
, but column-wise selectors are technically valid on Vectors, but they don't do much. Similarly, tril
is kind of useless. diag
and offdiag
can be use to select a specific index or all except a specific index, but the thunk to indicate which index needs to be negative.
Should we consider having type-specific (Vector, Matrix) SelectOps? There's definitely some awkwardness around UnaryOps/SelectOps, isn't there?
This is super-close to merging. I'll nag you about coverage on the next select PR ;)
Also, I tried select on a Matrix with a UDT, and it worked! Can you add a simple example to |
For warm-fuzzies, you may want to merge with main branch and update to |
This is in, thanks so much @jim22k 🎉 |
This implements item 1 in the proposal for adding select.