Skip to content

Commit

Permalink
test: ensure eigenvectors property not present with eigenvectors: fal…
Browse files Browse the repository at this point in the history
…se option
  • Loading branch information
gwhitney committed Oct 18, 2023
1 parent cf60b8c commit a5ebd0c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
7 changes: 3 additions & 4 deletions src/function/matrix/eigs/complexEigs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}

/**
Expand Down
10 changes: 6 additions & 4 deletions test/unit-tests/function/matrix/eigs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 () {
Expand All @@ -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)
Expand Down

0 comments on commit a5ebd0c

Please sign in to comment.