-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Matrix subset according to type of input #3485
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
base: v15
Are you sure you want to change the base?
Conversation
…y % operator (modulus) (#3432)
…y % operator (modulus) (#3432)
Previously `math.kron()` always returned a 2D matrix, and could not handle 3D or greater arrays. Now it always returns an array of the max dimension of its arguments. Resolves #1753. --------- Co-authored-by: Delaney Sylvans <delaneysylvans@gmail.com>
# Conflicts: # docs/expressions/syntax.md
I think it's mostly ready for review. Just wanted to review the following, The elements of an index are called ranges like So I was thinking if in the documentation and maybe in the code to find a more general name for the elements of an index like As a reference in numpy it's more like you slice with indices and there is no index class. So you slice |
# Conflicts: # AUTHORS # HISTORY.md
The code looks really neat, thanks David! Some thoughts:
|
Thanks for your review Jos,
|
Regarding the benchmarks, I said something wrong. The current benchmarks already take into account the index creation. The main benefit is the index creation, if tested on its own it's about twice as fast. But if tested on slicing as I said it's slightly faster. So this task was already done. Regarding the new behavior, I think it's possible to do the config flag, what would be a good name for it? Like |
Thanks for testing the performance David, most important is that there is not a sudden detoriation. Little performance improvements are of course always welcome :)
Great to hear a config flag is most likely possible. I think we should give it a name specific for this very subset/index refactoring. Something like |
Thanks Jos! It might be too complicated to change the behavior of |
Hi, this is still a work in progress but I think the overall implementation is working. Next steps are:
|
I think it's mostly done, the only thing left is changing the documentation. |
Hi, I included the changes in documentation and it's ready for review. |
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.
Thanks David, this is an impressive piece of work! I'm really happy you managed to implement the legacySubset
config option, without it it will be a really painful upgrade for many users I think.
I made a few minor inline comments, can you have a look at those?
docs/datatypes/matrices.md
Outdated
@@ -274,9 +274,30 @@ created using the function `index`. When getting a single value from a matrix, | |||
`subset` will return the value itself instead of a matrix containing just this | |||
value. | |||
|
|||
The function `subset` normally returns a subset, but when getting or setting a | |||
single value in a matrix, the value itself is returned. | |||
**New behavior:** |
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 think people upgrading to this breaking change will have the following question: "I upgrade to v15 and now my existing code is broken. How do I migrate"?
Can you write a bit more about how to update existing code? I think it should be a separate section with a title like "Migrate to v15". I think a small table showing some examples of old notation and new notation side by side (to get the same result) would help. What do you think?
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's a good idea, I included that in the latest commit.
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.
Nice! I would like to try to simplify the table a bit, it's showing quite a lot at the same time. How about this:
const m = math.matrix([[1, 2, 3], [4, 5, 6]])
v14 code | v15 equivalent code | Result |
---|---|---|
math.subset(m, math.index([0, 1], [1, 2])) |
No change needed | [[2, 3], [5, 6]] |
math.subset(m, math.index(1, [1, 2])) |
math.subset(m, math.index([1], [1, 2])) |
[[5, 6]] |
math.subset(m, math.index([0, 1], 2)) |
math.subset(m, math.index([0, 1], [2])) |
[[3], [6]] |
math.subset(m, math.index(1, 2)) |
No change needed | 6 |
I would also love to add a similar "Migration section" to the Matrix section on the Syntax page: https://mathjs.org/docs/expressions/syntax.html#matrices. To help people migrate that only use the expression parser and not the JS API. Can you please add that too?
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.
Hi, yes, it makes sense, I will work on it and report back soon.
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.
Hi, the comments are addressed and it's ready for review.
Thanks Jos, for your kind words and thorough review. Will address these topics and report back in the following days. |
Hi, the topics are addressed in general, please let me know if the chapter of migration with this new behavior should be more in detail or with a different focus. |
Hi Jos,
This addresses #2344
It changes the behavior of index to accommodate for scalar indices and the size of the output depends on the input.
I'm still doing some tests and reviewing what documentation needs to change, but it all seems to work according to:
#2344 (comment)