From a5ebd0c212cf875b03471fbdf89b048783915043 Mon Sep 17 00:00:00 2001 From: Glen Whitney Date: Wed, 18 Oct 2023 11:36:28 -0700 Subject: [PATCH] test: ensure eigenvectors property not present with eigenvectors: false option --- src/function/matrix/eigs/complexEigs.js | 7 +++---- test/unit-tests/function/matrix/eigs.test.js | 10 ++++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/function/matrix/eigs/complexEigs.js b/src/function/matrix/eigs/complexEigs.js index 17d053f887..26dcc0d38b 100644 --- a/src/function/matrix/eigs/complexEigs.js +++ b/src/function/matrix/eigs/complexEigs.js @@ -42,13 +42,12 @@ export function createComplexEigs ({ addScalar, subtract, flatten, multiply, mul // (So U = C^-1 arr C and the relationship between current arr // and original A is unchanged.) - let eigenvectors - if (findVectors) { - eigenvectors = findEigenvectors(arr, N, C, R, values, prec, type) + const eigenvectors = findEigenvectors(arr, N, C, R, values, prec, type) + return { values, eigenvectors } } - return { values, eigenvectors } + return { values } } /** diff --git a/test/unit-tests/function/matrix/eigs.test.js b/test/unit-tests/function/matrix/eigs.test.js index 7cbd250679..764a6d90b9 100644 --- a/test/unit-tests/function/matrix/eigs.test.js +++ b/test/unit-tests/function/matrix/eigs.test.js @@ -107,10 +107,9 @@ describe('eigs', function () { approx.deepEqual(fullValues, [-0.9135495807127523, 2.26552473288741, 5.6502090685149735, -8.687249803623432] ) - assert.deepStrictEqual( - fullValues, - eigs(sym4, { eigenvectors: false }).values - ) + const justEigs = eigs(sym4, { eigenvectors: false }) + assert.deepStrictEqual(fullValues, justEigs.values) + assert.ok(!('eigenvectors' in justEigs)) }) it('calculates eigenvalues and eigenvectors for 5x5 matrix', function () { @@ -162,6 +161,7 @@ describe('eigs', function () { testEigenvectors(ans, (v, j) => approx.deepEqual(multiply(E[j], v), multiply(H, v)) ) + assert.ok(!('eigenvectors' in justvalues)) const Vcols = ans.eigenvectors.map(obj => obj.vector) const V = matrixFromColumns(...Vcols) const VtHV = multiply(transpose(V), H, V) @@ -250,6 +250,7 @@ describe('eigs', function () { // Make sure the precision argument can go in the options object const stillbad = eigs(difficult, { precision: 1e-14, eigenvectors: false }) assert.deepStrictEqual(stillbad.values, poor.values) + assert.ok(!('eigenvectors' in stillbad)) }) it('diagonalizes matrix with bigNumber', function () { @@ -268,6 +269,7 @@ describe('eigs', function () { const ans = eigs(H) const justvalues = eigs(H, { eigenvectors: false }) assert.deepStrictEqual(ans.values, justvalues.values) + assert.ok(!('eigenvectors' in justvalues)) const E = ans.values const Vcols = ans.eigenvectors.map(obj => obj.vector) const V = matrixFromColumns(...Vcols)