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>
* fix: use utility isNaN for consistent max and min results
* test: add NaN comparison cases for larger and smaller functions
* docs: update descriptions for larger, smaller, max, and min functions to clarify NaN behavior
* refactor: rename isNaN to mathIsNaN for extra clarity
---------
Co-authored-by: Glen Whitney <glen@studioinfinity.org>
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>
* fix: Accept bigints as matrix indices and range params, demoting to number
* feat: bigint support in range(), clarify demotion in Range()
* feat: range() support Fraction, better errors for single non-string argument
---------
Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
* fix: Don't override type-native floor/ceil when within tolerance of value
* refactor: extend bigint safety to round and fix
---------
Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
* fix: Handle bigints properly in more cases
* Allow a bigint to appear in a max/min of nonhomogeneous arguments
* If randomInt is called with a bigint or a pair of bigints, return
a bigint.
* Preserve uniformity of results if randomInt is called with a very large
range.
* Extend log, log2, and log10 to bigints
* Add tests for all of the above issues.
* Bonus: fix one JSDoc comment issue. If every PR fixes one, we will soon
get through the 150+
* fix: Refactors per comments and 1 bonus doc test (isInteger)
* chore: fix lint
---------
Co-authored-by: Jos de Jong <wjosdejong@gmail.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.
* Removed maxArgumentCount in favor of applyCallback
* Making a pure _recurse function
* Added cbrt tests, removed unnecesary changes in functions.
* Fixed main bottleneck
* Restored back function before unintended change
* Fix format
---------
Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
1 US gallon is defined as 231 cubic inches, which is exactly 3.785411784 L (since 1 inch is defined as 25.4 mm). Other units are defined against the gallon.
Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
* nearlyEqual with absolute and relative tolerances
* Format
* nearlyEqual for bigNumber
* Added skip for NaN
* Reduce diff a bit
* Issue with examples in jsdcos
* Updated all calls for nearlyEqual
* Fixed failing tests
* Changed epsilon to relTol, absTol
* Changed references to epsilon in docs and tests
* Added warning for config.epsilon
* Fix warning in zeta.test
* Added config test
* Added sinon to test console.warn
---------
Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
* Use referToSelf() to recursively check if various types are NaN in an array or matrix
* fix array test description from isNegative to isNaN
* Add test for units in a matrix
---------
Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
* Fixing rounding bug from issue 3100
* Corrected syntax and converted if...else to logic using ternary operator
* Removing nearlyEqual comparison because a false
return value was mathematically impossible by
user input.
Adding dynamic epsilon logic to cover cases when
a user requests to round a number to a higher
precision than epsilon in the config file.
Also adding tests to cover dynamic epsilon cases.
* Removing dynamic epsilon and adding test for changing config.epsilon during runtime
* Reintroducing nearly equal verification for
round function.
Adding test case for changing epsilon at runtime.
Both tests for changing epsilon at runtime also
verify the false nearlyEqual scenario.
---------
Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
* Add test for conversion to unitless quantity
* Avoid access to missing array index
* Also check that other.units is not empty
* Add test for abs of dimensionless unit
* Fix: avoid access to missing units array index
---------
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
* added subtractScaler
* added subtractScaler missing entries
* added test cases for 2 or more parameters, test for subtractScalar instead fo subtract
* replaced subtract with subtractScalar whereever possible
---------
Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
* 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.
* fixed matrix issue in correlation function + error handling
* fixed syntax error in correlation function documentation
* changed error to syntax error
* added test cases for error handling
* added test cases for error handling v2
* fixed issue in test cases for error handling v2
* fixed issue in test cases for error handling v2.1
* fixed issue in test cases for error handling v2.2
* removed math.matrix examples
* removed redundant code