use new numpy.random.Generator approach

This commit is contained in:
Jan Petykiewicz 2024-07-28 23:23:11 -07:00
parent 6f3ae5a64f
commit b16b35d84a
2 changed files with 5 additions and 3 deletions

View File

@ -25,8 +25,9 @@ def power_iteration(
Returns:
(Largest-magnitude eigenvalue, Corresponding eigenvector estimate)
"""
rng = numpy.random.default_rng()
if guess_vector is None:
v = numpy.random.rand(operator.shape[0]) + 1j * numpy.random.rand(operator.shape[0])
v = rng.random(operator.shape[0]) + 1j * rng.random(operator.shape[0])
else:
v = guess_vector

View File

@ -561,9 +561,10 @@ def eigsolve(
prev_theta = 0.5
D = numpy.zeros(shape=y_shape, dtype=complex)
rng = numpy.random.default_rng()
Z: NDArray[numpy.complex128]
if y0 is None:
Z = numpy.random.rand(*y_shape) + 1j * numpy.random.rand(*y_shape)
Z = rng.random(y_shape) + 1j * rng.random(y_shape)
else:
Z = numpy.array(y0, copy=False).T
@ -573,7 +574,7 @@ def eigsolve(
try:
U = numpy.linalg.inv(ZtZ)
except numpy.linalg.LinAlgError:
Z = numpy.random.rand(*y_shape) + 1j * numpy.random.rand(*y_shape)
Z = rng.random(y_shape) + 1j * rng.random(y_shape)
continue
trace_U = real(trace(U))