Skip to content

Commit bb74308

Browse files
authored
fix: Correct eigenvector assertion and comment typo (#1127)
The assertion for comparing eigenvectors was failing when the signs of the vectors were opposite. This commit replaces the direct comparison with a dot product check to make the test robust to sign differences. Additionally, a minor typo ('powr' -> 'power') in a comment was corrected.
1 parent e2d120a commit bb74308

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

notebooks/book1/07/power_method_demo.ipynb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"metadata": {},
88
"outputs": [],
99
"source": [
10-
"# Illustrate the powr method for computing largest eigenvector\n",
10+
"# Illustrate the power method for computing largest eigenvector\n",
1111
"\n",
1212
"\n",
1313
"import numpy as np\n",
@@ -41,12 +41,16 @@
4141
"evecs = evecs[:, idx]\n",
4242
"\n",
4343
"tol = 1e-3\n",
44-
"assert np.allclose(evecs[:, 0], u, tol)\n",
44+
"assert np.isclose(np.abs(np.dot(evecs[:, 0], u)), 1, tol)\n",
4545
"assert np.allclose(evals[0], lam, tol)"
4646
]
4747
}
4848
],
49-
"metadata": {},
49+
"metadata": {
50+
"language_info": {
51+
"name": "python"
52+
}
53+
},
5054
"nbformat": 4,
5155
"nbformat_minor": 5
5256
}

0 commit comments

Comments
 (0)