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

eigs throws TypeError for some BigNumber matrices #1789

Closed
pro7onmatrix opened this issue Mar 27, 2020 · 6 comments
Closed

eigs throws TypeError for some BigNumber matrices #1789

pro7onmatrix opened this issue Mar 27, 2020 · 6 comments
Labels

Comments

@pro7onmatrix
Copy link

The eigs function throws a TypeError for some (but not all) matrices using BigNumber.

This example from eigs.test.js works as expected:

var A = [
    [-4.78, -1.0, -2.59, -3.26, 4.24, 4.14],
    [-1.0, -2.45, -0.92, -2.33, -4.68, 4.27],
    [-2.59, -0.92, -2.45, 4.17, -3.33, 3.05],
    [-3.26, -2.33, 4.17, 2.51, 1.67, 2.24],
    [4.24, -4.68, -3.33, 1.67, 2.80, 2.73],
    [4.14, 4.27, 3.05, 2.24, 2.73, -4.47]
];
A = math.bignumber(A);
const ans = math.eigs(A);

However, the following example produces a TypeError:

var B = [
    [0.0, 1.0, 0.0, 0.0, 0.0, 1.0],
    [1.0, 0.0, 1.0, 0.0, 0.0, 0.0],
    [0.0, 1.0, 0.0, 1.0, 0.0, 0.0],
    [0.0, 0.0, 1.0, 0.0, 1.0, 0.0],
    [0.0, 0.0, 0.0, 1.0, 0.0, 1.0],
    [1.0, 0.0, 0.0, 0.0, 1.0, 0.0]
];
B = math.bignumber(B);
const ans2 = math.eigs(B);
TypeError: Cannot implicitly convert a number with >15 significant digits to BigNumber (value: 0.7071067811865476). Use function bignumber(x) to convert to BigNumber.
    at convert (/home/professorchaos/Dokumente/javascript/node_modules/mathjs/lib/core/function/typed.js:208:15)
    at Array.convertArg (/home/professorchaos/Dokumente/javascript/node_modules/typed-function/typed-function.js:819:22)
    at convertArgs (/home/professorchaos/Dokumente/javascript/node_modules/typed-function/typed-function.js:766:45)
    at generic (/home/professorchaos/Dokumente/javascript/node_modules/typed-function/typed-function.js:1073:27)
    at multiplyScalar (/home/professorchaos/Dokumente/javascript/node_modules/typed-function/typed-function.js:1092:24)
    at Sij1Big (/home/professorchaos/Dokumente/javascript/node_modules/mathjs/lib/function/matrix/eigs.js:274:25)
    at diagBig (/home/professorchaos/Dokumente/javascript/node_modules/mathjs/lib/function/matrix/eigs.js:202:13)
    at checkAndSubmit (/home/professorchaos/Dokumente/javascript/node_modules/mathjs/lib/function/matrix/eigs.js:143:14)
    at Array (/home/professorchaos/Dokumente/javascript/node_modules/mathjs/lib/function/matrix/eigs.js:73:17)
    at Object.eigs (/home/professorchaos/Dokumente/javascript/node_modules/typed-function/typed-function.js:1085:85)

I'm using math.js v6.6.1, the problem occurs both in node and in the browser using math.min.js. Let me know if you need any additional info.

@josdejong
Copy link
Owner

Thanks for reporting. It turned out the BigNumber implementation of eigs was calculated using a mix of numbers and BigNumbers, causing the output to have number precision only in some cases like your example.

Fix created, not yet published.

@josdejong
Copy link
Owner

Fixed now in v6.6.2

@pro7onmatrix
Copy link
Author

Thanks very much for the quick fix! On an unrelated note, seeing as you already have a precision parameter in the diag and diagBig functions in eigs.js, would it be possible to pass the precision from eigs? Should I open a new issue for this?

josdejong added a commit that referenced this issue Apr 4, 2020
@josdejong
Copy link
Owner

That's a very good point @professorchaos97 . I've addressed this in this commit: 7e8d128, so the function eigs consistently uses config.epsilon (not yet published).

Does that address your concern?

@pro7onmatrix
Copy link
Author

Yes, it does. Thanks again!

@josdejong
Copy link
Owner

👍

josdejong added a commit that referenced this issue May 6, 2020
* Update devDependencies

* Fixed `eigs` not using `config.epsilon` (see #1789)

* Should be able to take NAMED_DELIMITER as object keys (#1798)

Co-authored-by: Jos de Jong <[email protected]>

* Update history

* Clarify the documentation on `scope` when using `rawArgs`, see #1055

* Bump @babel/preset-env from 7.9.0 to 7.9.5 (#1810)

Bumps [@babel/preset-env](https://github.com/babel/babel) from 7.9.0 to 7.9.5.
- [Release notes](https://github.com/babel/babel/releases)
- [Changelog](https://github.com/babel/babel/blob/master/CHANGELOG.md)
- [Commits](babel/babel@v7.9.0...v7.9.5)

Signed-off-by: dependabot-preview[bot] <[email protected]>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>

* Prefix the cli test with 'node' so it works on windows (#1807)

* Prefix the cli test with 'node' so it works on windows

Shouldnt provide any issues for other systems I hope

* Revert "Prefix the cli test with 'node' so it works on windows"

This reverts commit 4cd2704.

* Revert "Revert "Prefix the cli test with 'node' so it works on windows""

This reverts commit 268b594.

Co-authored-by: Jos de Jong <[email protected]>

* Fix #1808: `toNumber()` not working on a unitless unit (#1811)

* Update history

* Fix #1813: bug in engineering notation for numbers of function `format`, sometimes resulting in needless trailing zeros

* Improve explanation of engineering notation in function format

* Publish v6.6.3

* Bump uglify-js from 3.8.1 to 3.9.0 (#1816)

Bumps [uglify-js](https://github.com/mishoo/UglifyJS2) from 3.8.1 to 3.9.0.
- [Release notes](https://github.com/mishoo/UglifyJS2/releases)
- [Commits](mishoo/UglifyJS@v3.8.1...v3.9.0)

Signed-off-by: dependabot-preview[bot] <[email protected]>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>

* Publish v6.6.4

* Bump uglify-js from 3.9.0 to 3.9.1 (#1818)

Bumps [uglify-js](https://github.com/mishoo/UglifyJS2) from 3.9.0 to 3.9.1.
- [Release notes](https://github.com/mishoo/UglifyJS2/releases)
- [Commits](mishoo/UglifyJS@v3.9.0...v3.9.1)

Signed-off-by: dependabot-preview[bot] <[email protected]>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>

* Bump karma from 4.4.1 to 5.0.3 (#1830)

Bumps [karma](https://github.com/karma-runner/karma) from 4.4.1 to 5.0.3.
- [Release notes](https://github.com/karma-runner/karma/releases)
- [Changelog](https://github.com/karma-runner/karma/blob/master/CHANGELOG.md)
- [Commits](karma-runner/karma@v4.4.1...v5.0.3)

Signed-off-by: dependabot-preview[bot] <[email protected]>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>

* Bump karma-mocha from 1.3.0 to 2.0.1 (#1832)

* Bump karma from 5.0.3 to 5.0.4 (#1839)

Bumps [karma](https://github.com/karma-runner/karma) from 5.0.3 to 5.0.4.
- [Release notes](https://github.com/karma-runner/karma/releases)
- [Changelog](https://github.com/karma-runner/karma/blob/master/CHANGELOG.md)
- [Commits](karma-runner/karma@v5.0.3...v5.0.4)

Signed-off-by: dependabot-preview[bot] <[email protected]>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>

* Bump mocha from 7.1.1 to 7.1.2 (#1827)

* Update devDependencies

* Fix #1834: value `Infinity` cannot be serialized and deserialized

* Fix broken bundle tests and linting issues

* Fix unit test on node 8 (yeah, I know)

* Fix #1842: value `Infinity` not turned into the latex symbol `\\infty`

* Publish v6.6.5

* Fix fixer.io example, the free plan doesn't support SSL

* Change node versions

Co-authored-by: jos <[email protected]>
Co-authored-by: Veeloxfire <[email protected]>
Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
cshaa added a commit to cshaa/mathjs that referenced this issue Sep 26, 2020
josdejong added a commit that referenced this issue Apr 18, 2021
* split the eigs function into multiple algorithms

* moved checks and coersions to eigs.js, made them more robust

* fix little bugs, make im and re more robust

* Implemented matrix balancing algorithm

* fix typos

* a draft of reduction to Hessenberg matrix

* finished implementation of reduction to Hessenberg

* fix Hessenberg elimination for complex numbers

* implemented non-shifted explicit QR algorithm for real matrices

* implemented vector computation, won't work untill usolve is fixed

* refactored to match yarn lint

* some minor changes

* solve merge conflicts

* refactored and re-fixed #1789

* some old uncommited changes

* fix small problems introduced by merging

* done some polishing

* improved jsdoc description of eigs

* little changes in jsdoc

Co-authored-by: Jos de Jong <[email protected]>
joshhansen pushed a commit to LearnSomethingTeam/mathjs that referenced this issue Sep 16, 2021
* split the eigs function into multiple algorithms

* moved checks and coersions to eigs.js, made them more robust

* fix little bugs, make im and re more robust

* Implemented matrix balancing algorithm

* fix typos

* a draft of reduction to Hessenberg matrix

* finished implementation of reduction to Hessenberg

* fix Hessenberg elimination for complex numbers

* implemented non-shifted explicit QR algorithm for real matrices

* implemented vector computation, won't work untill usolve is fixed

* refactored to match yarn lint

* some minor changes

* solve merge conflicts

* refactored and re-fixed josdejong#1789

* some old uncommited changes

* fix small problems introduced by merging

* done some polishing

* improved jsdoc description of eigs

* little changes in jsdoc

Co-authored-by: Jos de Jong <[email protected]>
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