* feat: toBest tests
* feat: toBest function initial
* fix: tests and function changes
* fix: dependencies
* new way to handle
* updated tests
* test updated
* tests fixed
* cleaned useless tests
* cleaned useless condition
* fix: missing comments
* fix: moved tests
* other fix and clean
* change test to work with npx mocha "path" -g "toBest"
* deleted check large and small value
* deleted precision test and fix options to bestprefix
* fix: moved toBest tests in correct file
* fix: math create
* fix: aligned files pre-mr
* fix: toBest docs test
* fix: lint issues
* fix: comments
* fix: added a helper function to simplify the test readability
* fix: unit.md and units.md docs updated
* fix: test on units.length
* added post process denormalize for tobest function to string returned value
* removed this.clone into format
* feat improve incompatible units test
* fix assign prefixes
* fixed examples
* changed order of params of assertUnit
* fixed comments and added toBest in knowProblems at doc.test
* refactor: update toBest functionality and adjust related tests for accuracy
* refactor: remove unnecessary offset initialization in prefix application
---------
Co-authored-by: Luca Quercetti <l.quercetti@wecodeyou.it>
Co-authored-by: Elia Alesiani <elia.alesiani@gmail.com>
Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
Co-authored-by: lucaQ <lucaquercetti@gmail.com>
Co-authored-by: EliaAlesiani <105418798+EliaAlesiani@users.noreply.github.com>
* fixes#3493 allowing math.unit(5), which would now fail because for values of MathNumericType and MathCollection, the second parameter wasn't optional
* Added tests, and as a result of that, fixed the definition of unit(value: MathCollection): Unit[] where no units seem to be allowed
* Changes as requested by josdejong
* math.add and math.multipl type fixes and added tests
* fixes#3494: math.unit(m).to(math.unit(cm)) is now ok for typescript
* fix: infer the correct type from two arrays defined as 2D
* chore: add check that 1D * 1D (number[]) arrays result in scalar
* chore: remove commented out line
* fix: update test so that 2D arrays can be multiplied correctly
---------
Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
* chore: Rename `apply` to `mapSlices`
This renaming conforms with the Julia name for the function formerly
called `apply`, and allows it to be called from the expression parser.
The previous name `apply` is kept as an alias for `mapSlices`, for
backward compatibility. This commit implements an `alias` metadata
property for function factories to facilitate the `apply` alias for
`mapSlices`.
As a separate bonus, this PR corrects several typos in function docs
and removes now-passing doc tests from the list of "known failing" doc
tests to get down to 45 known failures and 136 total issues in doc tests.
(Most of the excess of 136 as compared to 45 are just due to roundoff
error/slight inaccuracy of what the documentation claims the result will
be and the actual result returned by mathjs. When the 45 are eliminated,
a reasonable numeric tolerance can be decided on for doc testing and
then the doc tests can be made binding rather than advisory.
* refactor: changes per PR review
---------
Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
* Addressed silentmissile's comment in https://github.com/josdejong/mathjs/issues/3125
* Added method overload to index.d.ts, have to revert commit due to changes to package-lock.json with using npm install to run the unit tests & lint tests
* Type definition missing for matrixFrom* #3115
* fix: Update types and add tests as requested by review
* chore: lint fix
---------
Co-authored-by: Hudsxn <jhudson98new@gmail.com>
Co-authored-by: Hudsxn <143907857+Hudsxn@users.noreply.github.com>
BREAKING CHANGE:
The matrix types now support generics. For most practical cases, this doesn't cause a breaking change, but it is possible that it breaks typings in some specific edge cases.
* feat: export util functions `isMap`, `isPartitionedMap`, and `isObjectWrappingMap` and improve the documentation of `scope` (see #3150)
* chore: fix broken unit tests
* docs: refine the explanation about scopes
* fix: types static method for Unit class
Changes unit interface to declare class to enable the adding of static methods.
* refactor: change to not using declare class
* fix: adds more unit static methods and updates tests
* chore: moves test from wrong location
* fix: adds additional static methods and updates jsDocs
---------
Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
* fix: mode type signatures
* Add ts tests for mode
* Add assertions mode type tests
* Update author Rich in AUTHORS file
---------
Co-authored-by: Rich Martinez <richmartinez@Edinas-MacBook-Pro.local>
Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
* Prefer inferring types of nodes as tuples
* Implement for IndexNode
* Test for types
* Use tuple type for array node
---------
Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
* fix#2761: implement support for units in function `round` (WIP)
* fix#2761: extend function `round` with support for units
* docs: describe all signatures in the docs of function round
* chore: fix linting issue
* chore: remove less-useful signatures for round with units and matrices
* feat: Add option to eigs() to turn off eigenvector computation
For large matrices, the eigenvector computation can be noticeably expensive
and so it's worthwhile to have a way to turn it off if the eigenvectors
will not be used.
Resolves#2180.
* fix: Add test for precision in options arg of eigs
And also a fix for a small bug that the new test uncovered.
* test: check eigs with matrix and options
* refactor: remove dead code from complexEigs.js
* fix: add new signatures of eigs to typescript
* test: ensure eigenvectors property not present with eigenvectors: false option
* fix: correct balancing code in complexEigs
* fix: Find eigenvectors of defective matrices
Previously, attempting to take the `eigs` of any defective matrix
was doomed to fail in an attempt to solve a singular linear system.
This PR detects the situation (as best as it can given the
inherent numerical instability of the current methods used) and
handles it. Note that in such cases, it's not possible to return
a square matrix whose columns are the eigenvectors corresponding to
the returned eigenvalues. In light of that fact and issue #3014, this
PR also changes the return value of `eigs` so that the eigenvectors
are passed back in a property `eigenvectors` which is an array of
plain objects `{value: e, vector: v}`.
Note that this PR makes the ancillary changes of correcting the
spelling of the filename which was "realSymetric.js," and replacing
the now-unnecessary auxiliary function "createArray" therein with
`Array(size).fill(element)`. The rationale for performing these
changes not strictly related to the issues at hand is that this
file is rarely touched and with the level of maintenance hours we have
at hand, it's more efficient to do these small refactorings in parallel
with the actual bugfixes, which are orthogonal and so will not be
obfuscated by this refactor. Note `git diff` does properly track the
file name change.
However, it also makes a potentially more pervasive change: in order for
the numerically-sensitive algorithm to work, it changes the condition
on when two very close (double) numbers are "nearlyEqual" from differing by
less than DBL_EPSILON to differing by less than or equal to DBL_EPSILON.
Although this may change other behaviors than the ones primarily being
addressed, I believe it is an acceptable change because
(a) It preserves all tests.
(b) DBL_EPSILON is well below the standard config.epsilon anyway
(c) I believe there are extant issues noting the odd/inconsistent
behavior of nearlyEqual near 0 anyway, so I believe this will
be overhauled in the future in any case. If so, the eigenvector
computation will make a good test that a future nearlyEqual
algorithm is working well.
To be clear, the direct motivation for the change is that there are
multiple cases in the eigenvector computation in which a coefficient
that is "supposed" to be zero comes out to precisely DBL_EPSILON, which
is fairly unsurprising given that these coefficients are produced by
subtracting an eigenvalue from a diagonal entry of a matrix, which is
likely to be essentially equal to that eigenvalue.
As many tests of defective matrices as I could readily find by web
searching have been added as unit tests (and one more in the typescript
type testing). An additional case I found still fails, but in the
_eigenvalue_ computation rather than the _eigenvector_ search, so that
was deemed beyond the scope of this PR and has been filed as issue #3036.
Resolves#2879.
Resolves#2927.
Resolves#3014.
* refactor: remove comma that lint now doesn't like
* test: add a test for eigs with a precision argument
* feat: Use simple shifts in QR eigenvalue iterations that improve convergence
Although we might want to use better shifts in the future, we might just
use a library instead. But for now I think this:
Resolves#2178.
Also responds to the review feedback provided in PR #3037.
* feat: add polynomialRoot function
This is intended as a benchmark for general arithmetic/basic algebra
functionality of mathjs, but was chosen to be something of potential
independent utility as well, worth adding to mathjs in its own right.
Currently ol=nly computes the numerical roots for real or complex
polynomials of degree three or less.
As usual, adds documentation, embedded documentation, tests, TypeScript
declaration, and TypeScript tests.
Also updates doc.test.js to make it easier to specify an array of complex
numbers as the expected output, and comapres with the appropriate fuzz
in such cases.
Finally, adds a benchmark that computes the roots of all cubics with
nonnegative integer coefficients no larger than five.
* doc: fix typo in polynomialRoot embedded docs
Thanks, SamuelTLG
* style: avoid slightly cryptic Boolean flag stand-in