Skip to content
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

Edge case: diff([1]) #2412

Closed
gwhitney opened this issue Feb 8, 2022 · 1 comment
Closed

Edge case: diff([1]) #2412

gwhitney opened this issue Feb 8, 2022 · 1 comment
Labels

Comments

@gwhitney
Copy link
Collaborator

gwhitney commented Feb 8, 2022

Currently, math.evaluate('diff([1])') returns [1]. It seems to me that to be consistent with diff() called on any array of length > 1 (where it returns an array of length one less than the input), the value of diff([x]) ought to be [] no matter what x is. In other words , there are no consecutive differences of a list of length 1. (diff([]) would continue to produce [] as it currently does; there are also no consecutive differences of a list of length 0.)

If there's agreement that the current behavior is anomalous and should be corrected, I will be happy to supply the small PR needed to fix.

Incidentally, it seems to me that issue #1634 asking for diff in the first place can be closed.

@josdejong
Copy link
Owner

You're right, I would expect diff([1]) to return [], this is a bug, though I see from the unit tests that this behavior was implemented like this intentionally (see 1348d67).

I've put together a fix in #2422

Does this make sense @Veeloxfire ?

@josdejong josdejong added the bug label Feb 16, 2022
josdejong added a commit that referenced this issue Mar 18, 2022
…ntains only one element (#2422)

* Fix #2412: let function diff return an empty matrix when the input has only one element

* Undo changes in History in this fixme

* Add TypeScript definitions for src/utils/is.js (#2432)

This is a first step toward full publication of these functions,
that were already being exported by mathjs but had not yet
had the associated actions (documentation/available in 
parser/typed, etc.) Also, makes most of them into TypeScript
type guards, and adds Matrix as a constructor type. Resolved #2431.

Co-authored-by: Glen Whitney <glen@studioinfinity.org>

* test: add two-dimensional test cases for diff of length 1

Co-authored-by: Chris Chudzicki <christopher.chudzicki@gmail.com>
Co-authored-by: Glen Whitney <glen@studioinfinity.org>
gwhitney added a commit that referenced this issue Apr 13, 2022
…ntains only one element (#2422)

* Fix #2412: let function diff return an empty matrix when the input has only one element

* Undo changes in History in this fixme

* Add TypeScript definitions for src/utils/is.js (#2432)

This is a first step toward full publication of these functions,
that were already being exported by mathjs but had not yet
had the associated actions (documentation/available in 
parser/typed, etc.) Also, makes most of them into TypeScript
type guards, and adds Matrix as a constructor type. Resolved #2431.

Co-authored-by: Glen Whitney <glen@studioinfinity.org>

* test: add two-dimensional test cases for diff of length 1

Co-authored-by: Chris Chudzicki <christopher.chudzicki@gmail.com>
Co-authored-by: Glen Whitney <glen@studioinfinity.org>
gwhitney added a commit that referenced this issue Apr 30, 2022
…ntains only one element (#2422)

* Fix #2412: let function diff return an empty matrix when the input has only one element

* Undo changes in History in this fixme

* Add TypeScript definitions for src/utils/is.js (#2432)

This is a first step toward full publication of these functions,
that were already being exported by mathjs but had not yet
had the associated actions (documentation/available in 
parser/typed, etc.) Also, makes most of them into TypeScript
type guards, and adds Matrix as a constructor type. Resolved #2431.

Co-authored-by: Glen Whitney <glen@studioinfinity.org>

* test: add two-dimensional test cases for diff of length 1

Co-authored-by: Chris Chudzicki <christopher.chudzicki@gmail.com>
Co-authored-by: Glen Whitney <glen@studioinfinity.org>
gwhitney added a commit that referenced this issue May 12, 2022
…ntains only one element (#2422)

* Fix #2412: let function diff return an empty matrix when the input has only one element

* Undo changes in History in this fixme

* Add TypeScript definitions for src/utils/is.js (#2432)

This is a first step toward full publication of these functions,
that were already being exported by mathjs but had not yet
had the associated actions (documentation/available in 
parser/typed, etc.) Also, makes most of them into TypeScript
type guards, and adds Matrix as a constructor type. Resolved #2431.

Co-authored-by: Glen Whitney <glen@studioinfinity.org>

* test: add two-dimensional test cases for diff of length 1

Co-authored-by: Chris Chudzicki <christopher.chudzicki@gmail.com>
Co-authored-by: Glen Whitney <glen@studioinfinity.org>
gwhitney added a commit that referenced this issue May 31, 2022
…ntains only one element (#2422)

* Fix #2412: let function diff return an empty matrix when the input has only one element

* Undo changes in History in this fixme

* Add TypeScript definitions for src/utils/is.js (#2432)

This is a first step toward full publication of these functions,
that were already being exported by mathjs but had not yet
had the associated actions (documentation/available in 
parser/typed, etc.) Also, makes most of them into TypeScript
type guards, and adds Matrix as a constructor type. Resolved #2431.

Co-authored-by: Glen Whitney <glen@studioinfinity.org>

* test: add two-dimensional test cases for diff of length 1

Co-authored-by: Chris Chudzicki <christopher.chudzicki@gmail.com>
Co-authored-by: Glen Whitney <glen@studioinfinity.org>
gwhitney added a commit that referenced this issue May 31, 2022
…ntains only one element (#2422)

* Fix #2412: let function diff return an empty matrix when the input has only one element

* Undo changes in History in this fixme

* Add TypeScript definitions for src/utils/is.js (#2432)

This is a first step toward full publication of these functions,
that were already being exported by mathjs but had not yet
had the associated actions (documentation/available in 
parser/typed, etc.) Also, makes most of them into TypeScript
type guards, and adds Matrix as a constructor type. Resolved #2431.

Co-authored-by: Glen Whitney <glen@studioinfinity.org>

* test: add two-dimensional test cases for diff of length 1

Co-authored-by: Chris Chudzicki <christopher.chudzicki@gmail.com>
Co-authored-by: Glen Whitney <glen@studioinfinity.org>
gwhitney added a commit that referenced this issue Jul 13, 2022
…ntains only one element (#2422)

* Fix #2412: let function diff return an empty matrix when the input has only one element

* Undo changes in History in this fixme

* Add TypeScript definitions for src/utils/is.js (#2432)

This is a first step toward full publication of these functions,
that were already being exported by mathjs but had not yet
had the associated actions (documentation/available in 
parser/typed, etc.) Also, makes most of them into TypeScript
type guards, and adds Matrix as a constructor type. Resolved #2431.

Co-authored-by: Glen Whitney <glen@studioinfinity.org>

* test: add two-dimensional test cases for diff of length 1

Co-authored-by: Chris Chudzicki <christopher.chudzicki@gmail.com>
Co-authored-by: Glen Whitney <glen@studioinfinity.org>
gwhitney added a commit that referenced this issue Jul 15, 2022
…ntains only one element (#2422)

* Fix #2412: let function diff return an empty matrix when the input has only one element

* Undo changes in History in this fixme

* Add TypeScript definitions for src/utils/is.js (#2432)

This is a first step toward full publication of these functions,
that were already being exported by mathjs but had not yet
had the associated actions (documentation/available in 
parser/typed, etc.) Also, makes most of them into TypeScript
type guards, and adds Matrix as a constructor type. Resolved #2431.

Co-authored-by: Glen Whitney <glen@studioinfinity.org>

* test: add two-dimensional test cases for diff of length 1

Co-authored-by: Chris Chudzicki <christopher.chudzicki@gmail.com>
Co-authored-by: Glen Whitney <glen@studioinfinity.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants