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 — Matrix subset according to type of input by dvd101x · Pull Request #3485 · josdejong/mathjs

Conversation

@dvd101x

@dvd101x dvd101x commented May 31, 2025

Copy link
Copy Markdown
Collaborator

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)

A = [1,2,3; 4,5,6]
A[2,3]  --> 6
A[[1,2],[2,3]] --> [2,3; 5,6]
A[[2],[2,3]] --> [[5, 6]]
A[2,[2,3]] --> [5,6]
A[[1,2],[2]] --> [2; 5]  // which is the same as [[2], [5]]
A[[1,2],2] --> [2,5]
A[[2], [2]] --> [[5]]
A[2, [2]] --> [5]
A[[2], 2] --> [5]
A[[],[]] --> []
A[1,[]] --> []
A[[],1] --> []

Sorry, something went wrong.

Uh oh!

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

All reactions
kiprobinsonknack and others added 14 commits April 16, 2025 16:26
@kiprobinsonknack
feat: give unary % operator (percentage) higher precedence than binar…
5a27c11
…y % operator (modulus) (#3432)
@kiprobinsonknack @gwhitney
feat: give unary % operator (percentage) higher precedence than binar…
4f748d2
…y % operator (modulus) (#3432)
@gwhitney
chore: update HISTORY, AUTHORS, and fix doc typo from last commit (#3460
75cd91b
)
@gwhitney @Delaney
Feat: Enhance Kronecker product to handle arbitrary dimension (#3461)
72a2442
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 <[email protected]>
@josdejong
Merge remote-tracking branch 'origin/v15' into v15
87651fe
# Conflicts:
#	docs/expressions/syntax.md
@dvd101x
Change index to maintain scalars
121c70a
@dvd101x
Changed function definitions, fixed format
0f50895
@dvd101x
Faster denseMatrix creation
cefff87
@dvd101x
Change subset
8c436c2
@dvd101x
Reduce try catch block
41dd563
@dvd101x
Merge branch 'develop' into matrix-subset-according-to-type-of-input
2c2e733
@dvd101x
Added a helper functions
d2fc265
@dvd101x
Return the use of anonymous functions
8f2d13a
@dvd101x
Return the use of the _isScalar flag
1fec634
@dvd101x

dvd101x commented May 31, 2025

Copy link
Copy Markdown
Collaborator Author

I think it's mostly ready for review.

Just wanted to review the following,

The elements of an index are called ranges like index(range1, range2) but the ranges are not always Range. Sometimes ranges are number, string, bigNumber, Array, Matrix, Array of Booleans, Matrix of Booleans or Range.

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 index(indexElement1, indexElement2).

As a reference in numpy it's more like you slice with indices and there is no index class. So you slice A[index1, index2]

https://mathjs.org/docs/reference/functions/index.html

All reactions

Sorry, something went wrong.

Uh oh!

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

josdejong added 2 commits June 4, 2025 10:41
@josdejong
Merge branch 'develop' into matrix-subset-according-to-type-of-input
c5051f5
@josdejong
Merge branch 'develop' into v15
8e76654
# Conflicts:
#	AUTHORS
#	HISTORY.md
@josdejong
josdejong changed the base branch from develop to v15 June 4, 2025 08:45
@josdejong josdejong added this to the v15 milestone Jun 4, 2025
@josdejong josdejong mentioned this pull request Jun 4, 2025
v15 breaking changes #3453
Closed
7 tasks done
@josdejong

josdejong commented Jun 4, 2025

Copy link
Copy Markdown
Owner

The code looks really neat, thanks David!

Some thoughts:

  1. This is a breaking change, therefore I've changed this PR to merge into the v15 branch, and listed it at #3453.

  2. 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 index(indexElement1, indexElement2).

    Maybe we can call the arguments index(dim1, dim2, ...)?

  3. Does this PR have impact on the performance of subset?

  4. I'm a bit concerned about how hugely breaking this change is. Existing code will probably still work but now return differently dimensioned matrices, which can give subtle and hard to debug errors. Can we somehow help people migrate, or detect "old" usage and warn the user? Or make it backward compatible with a config flag?

All reactions

Sorry, something went wrong.

Uh oh!

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

@dvd101x

dvd101x commented Jun 4, 2025 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Collaborator Author

Thanks for your review Jos,

  1. Ok.
  2. Good idea! that aligns better with the rest of the code base.
  3. Makes a few of the tests slightly faster within the margin of error, but the main speed benefit might be the Matrix creation during the creation of Index, which is outside the scope of the subset benchmark. I will add some tests including the Index creation.
  4. I agree it's a big change. I'm not sure how to proceed. I'll give it some thought.
josdejong reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

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

@dvd101x

dvd101x commented Jun 7, 2025

Copy link
Copy Markdown
Collaborator Author

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.

image

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 config.legacy ?

All reactions

Sorry, something went wrong.

Uh oh!

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

@josdejong

josdejong commented Jun 11, 2025

Copy link
Copy Markdown
Owner

Thanks for testing the performance David, most important is that there is not a sudden detoriation. Little performance improvements are of course always welcome :)

Regarding the new behavior, I think it's possible to do the config flag, what would be a good name for it? Like config.legacy ?

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 config.legacyIndex or config.backwardCompatibleIndex? I think I like config.legacyIndex more of these two but no strong feelings.

All reactions

Sorry, something went wrong.

Uh oh!

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

@dvd101x

dvd101x commented Jun 19, 2025

Copy link
Copy Markdown
Collaborator Author

Thanks Jos!

It might be too complicated to change the behavior of Index so I would like to try first to change subset with config.legacySubset flag. I will try this first and report back for your review.

josdejong reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

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

@dvd101x
Implement config.legacySubset
9074912
@dvd101x

dvd101x commented Jun 26, 2025 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Collaborator Author

Hi, this is still a work in progress but I think the overall implementation is working. Next steps are:

  • add tests for subset with config.legacySubset
  • sylvester, row and column depend on subset, thus they should save current config.legacySubset, change it to false and restore its original value at the end.
  • change documentation.
josdejong reacted with hooray emoji
All reactions
  • 🎉 1 reaction

Sorry, something went wrong.

Uh oh!

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

dvd101x added 3 commits June 26, 2025 14:13
@dvd101x
Fix comment
c460af6
@dvd101x
Merge branch 'v15' into matrix-subset-according-to-type-of-input
251c8ad
@dvd101x
Add tests for legacySubset
02c2c18
dvd101x added 2 commits July 1, 2025 20:51
@dvd101x
support for legacySubset in sylvester, row and column
c2daf58
@dvd101x
Formatting
c6fc802
@dvd101x

dvd101x commented Jul 2, 2025

Copy link
Copy Markdown
Collaborator Author

I think it's mostly done, the only thing left is changing the documentation.

josdejong reacted with hooray emoji
All reactions
  • 🎉 1 reaction

Sorry, something went wrong.

Uh oh!

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

dvd101x added 4 commits July 1, 2025 22:15
@dvd101x
added tests for sylvester, rowand column. Removed unnecesary ch…
47c1fe6
…anges.
@dvd101x
simplified config.test
2051b18
@dvd101x
Update documentation
3ca8899
@dvd101x
Update configuration.md
b92f742
@dvd101x

dvd101x commented Jul 3, 2025

Copy link
Copy Markdown
Collaborator Author

Hi, I included the changes in documentation and it's ready for review.

All reactions

Sorry, something went wrong.

Uh oh!

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

@gwhitney
gwhitney force-pushed the v15 branch from 8e76654 to 5655d71 Compare July 3, 2025 20:38
@dvd101x
Merge branch 'v15' into matrix-subset-according-to-type-of-input
660bf21
josdejong
josdejong reviewed Jul 4, 2025
View reviewed changes

@josdejong josdejong left a comment •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Owner

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?

Sorry, something went wrong.

Uh oh!

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

dvd101x reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread src/function/matrix/column.js Resolved

Uh oh!

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

Comment thread test/unit-tests/core/config.test.js Resolved

Uh oh!

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

Comment thread docs/datatypes/matrices.md Resolved

Uh oh!

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

@dvd101x

dvd101x commented Jul 4, 2025 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Collaborator Author

Thanks Jos, for your kind words and thorough review.

Will address these topics and report back in the following days.

josdejong reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

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

dvd101x added 4 commits July 4, 2025 19:27
@dvd101x
remove typo
9ae9bf8
@dvd101x
Instructions about config.legacySubset deperaction
774bc0d
@dvd101x
Moved config.legacySubset tests to their respective functions
0e55c7c
@dvd101x
Added migration section
b7213f0
@dvd101x

dvd101x commented Jul 7, 2025

Copy link
Copy Markdown
Collaborator Author

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.

All reactions

Sorry, something went wrong.

Uh oh!

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

dvd101x added 2 commits July 14, 2025 20:31
@dvd101x
Updated migration example
d1c135b
@dvd101x
More examples for migration to V15.
0edfb05
@josdejong
josdejong merged commit 10602fd into v15 Jul 16, 2025
@josdejong
josdejong deleted the matrix-subset-according-to-type-of-input branch July 16, 2025 08:40
@josdejong josdejong mentioned this pull request Jul 16, 2025
subset of matrix should always return the same type (matrix) #2344
Closed
josdejong added a commit that referenced this pull request Jul 16, 2025
@josdejong
docs: some updates in the description to migrate matrix index behavio…
a8ec24d
…r to v15 (see #3485)
@josdejong

josdejong commented Oct 10, 2025

Copy link
Copy Markdown
Owner

Published now in v15.0.0, thanks again David.

dvd101x reacted with hooray emoji
All reactions
  • 🎉 1 reaction

Sorry, something went wrong.

Uh oh!

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

@dvd101x dvd101x mentioned this pull request Mar 29, 2026
Fix rocket trajectory optimization example #3654
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@josdejong josdejong josdejong left review comments

Uh oh!

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

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

v15

Development

Successfully merging this pull request may close these issues.

Uh oh!

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

4 participants

@dvd101x @josdejong @kiprobinsonknack @gwhitney
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 01402792 — 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.