GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Computation between scalars by eriknw · Pull Request #358 · python-graphblas/python-graphblas

Conversation

@eriknw

@eriknw eriknw commented Dec 31, 2022

Copy link
Copy Markdown
Member

Closes #199.

This is almost ready. It turns out we had most of the machinery already to support computation between scalars. I need to finish scalar.select and go over everything carefully one more time.

I discovered that expr.dup didn't match obj.dup, so I added tests to verify that signatures and docstrings match between expressions and objects.

A good wayto review this may be to check it out locally and try it out.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@eriknw
Computation between scalars
128ddd5
@eriknw
eriknw marked this pull request as draft December 31, 2022 19:17
eriknw added 2 commits December 31, 2022 14:57
@eriknw
Vanilla ewise_union between scalars
aec1973
@eriknw
Fix bizarro scalars
8a75e41
@coveralls

coveralls commented Dec 31, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Coverage Status

coverage: 99.468% (+0.9%) from 98.605%
when pulling 568cd86 on eriknw:scalar_compute
into ec2cad6 on python-graphblas:main.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

eriknw added 4 commits January 1, 2023 09:21
@eriknw
Merge branch 'main' into scalar_compute
069d78d
@eriknw
Coverage
70d600c
@eriknw
Handle select with scalars for suitesparse-vanilla backend
4add8fe
@eriknw
More coverage
d4b017c
@eriknw
eriknw marked this pull request as ready for review January 2, 2023 18:17
@eriknw
eriknw requested review from SultanOrazbayev and jim22k January 2, 2023 18:18
@eriknw

eriknw commented Jan 2, 2023

Copy link
Copy Markdown
Member Author

This is ready for review if anybody wants to take a look. I plan to merge this PR in a week or so if there's no feedback.

I think a useful way to review this would be to try it out and compare to how you expect computation between scalars to behave.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

eriknw added 2 commits January 2, 2023 12:22
@eriknw
Missed a docstring for dup
34121be
@eriknw
Add ruff ISC (flake8-implicit-str-concat), T20 (flake8-print), and …
61b9d20
…PIE (flake8-pie)
jim22k
jim22k approved these changes Jan 4, 2023
View reviewed changes
@eriknw

eriknw commented Jan 4, 2023

Copy link
Copy Markdown
Member Author

Thanks for looking @jim22k!

There's one thing I almost forgot: docstrings! I will add docstrings to the new methods on Scalar before I merge.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

eriknw added 13 commits January 4, 2023 12:36
@eriknw
Merge branch 'main' into scalar_compute
9e7d8c1
@eriknw
Support awkward version 2; also support 11 more pylint checks
f8018b8
@eriknw
Revert: ignore pylint not-an-iterable
57d5e67
@eriknw
Move more config to pyproject.toml; fix awkward tests
93d1afd
@eriknw
coverage
51bde4b
@eriknw
CI: break test section into multiple sections for easier review
d136fff
@eriknw
Only test one slow task per CI job
22b175c
@eriknw
Better; I knew I would like randomization :)
c43ac8a
@eriknw
Update ruff: one cleanup
1c5ea24
@eriknw
Move more config to pyproject.toml (see python-graphblas#356)
568cd86
@eriknw
flake8-simplify actually seems nice
5f659cc
@eriknw
Simplify ScalarMatMulExpr
e7aa1a0
@eriknw
Fix and catch using single back-tic instead of two in RST files
5983a42
@eriknw

eriknw commented Jan 5, 2023

Copy link
Copy Markdown
Member Author

@jim22k, there's one more edge case for Scalar computation that I want to bring attention to.

__eq__, __ne__, __neg__, and __invert__ are all greedy and return results, not expressions. __eq__ and __ne__ return Python bool, and __neg__ and __invert__ return gb.Scalar. This matches existing behavior of scalars. However, these return expressions for vectors and matrices.

All other scalar dunder methods (such as s + t) return expressions. This includes comparators such as s < t.

What should we do for infix and prefix operators for scalars? Should they always return gb.Scalar? Note that with SuiteSparse:GraphBLAS, s("+") << t + u is able to be done with a single GraphBLAS operation:

GrB_Vector_eWiseAdd_BinaryOp((GrB_Vector)s, NULL, GrB_PLUS_FP64, GrB_PLUS_FP64, (GrB_Vector)t, (GrB_Vector)u, NULL);

Also note that empty_s == empty_t currently returns True. Would returning an empty bool scalar make more sense?

In summary, this PR currently matches old behavior to be backwards compatible, and otherwise infix methods return expressions to match with Vector and Matrix. This may be surprising at times, so we should consider being backwards incompatible.

I want to come to consensus on this before merging.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@eriknw
Support accum for scalars
612c48a
@eriknw

eriknw commented Jan 5, 2023

Copy link
Copy Markdown
Member Author

Here's my current position regarding the previous comment:

  • Changing behavior of __eq__ and __ne__ would be too disruptive; keep as is and return bools
    • The behavior is also reasonable-ish and probably easy to get used to
    • But I hope we won't regret empty == empty someday
  • Other dunder methods should return expressions as is done with vectors and matrices
    • Expressions are value-y enough that things should still "just work" most of the time
    • Allowing other comparators such as s < t to be true, false, or empty is useful
  • Change __neg__ and __invert__ to return expressions
    • These aren't special enough to be different
    • It's probably safe to change these behaviors, as they're probably not used that often 🤞
    • I think it would be best to compute the result of these in GraphBLAS instead of in Python
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

eriknw added 2 commits January 5, 2023 18:28
@eriknw
__neg__ and __invert__ return expressions for scalars too
318b540
@eriknw
fix
5ab686c
@jim22k

jim22k commented Jan 6, 2023

Copy link
Copy Markdown
Member

The changes (__neg__, __invert__) sound reasonable, and I agree with keeping current behavior for __eq__ and __ne__. Even the empty == empty makes sense to me. That is the same behavior as calling s1.isequal(s2).

If for some reason we wanted to change the behavior of __eq__ in the future, we have to consider that non-empty == empty would yield an empty Scalar -- at least, that is what happens for Vector and Matrix. Maybe that behavior is useful, but I agree that most times people are actually reaching for .isequal, not element-wise equality.

They also aren't locked out of doing element-wise equality. They would just have to use the non-infix notation, which makes it explicitly clear what is being asked for (i.e. binary.eq(s1 & s2))

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@eriknw

eriknw commented Jan 6, 2023

Copy link
Copy Markdown
Member Author

Perfect, thanks so much @jim22k for the careful consideration. I agree with everything you said, so sounds like we're in agreement!

Now I just need to add those docstrings...

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@eriknw
Add docstrings to new Scalar methods; add pylint task to CI
789059a
@eriknw
eriknw merged commit 501fe6f into python-graphblas:main Jan 6, 2023
@eriknw

eriknw commented Jan 6, 2023

Copy link
Copy Markdown
Member Author

This is in 🎉 🚀 🎉 !

This ended up being a bigger PR than I expected, but it makes a lot of improvements, and operations with scalars seems pretty nice.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@eriknw

eriknw commented Jan 6, 2023

Copy link
Copy Markdown
Member Author

btw, one of the misc things added in this PR is running Pylint sometimes in CI. It is only informational--it doesn't fail the CI job.

Pylint is actually how I learned awkward 2 is out and we needed to update (another misc update done in this PR), so I think it can actually be a useful check. I'm tempted to allow it to fail PRs, but let's do a "dry run" for now to see how it goes.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@eriknw eriknw mentioned this pull request Oct 28, 2026
Fix Scalar infix expressions with a literal operand #654
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@jim22k jim22k jim22k approved these changes
@SultanOrazbayev SultanOrazbayev Awaiting requested review from SultanOrazbayev

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Computation between scalars

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@eriknw @coveralls @jim22k
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.