use new numpy.random.Generator approach
This commit is contained in:
parent
6f3ae5a64f
commit
b16b35d84a
@ -25,8 +25,9 @@ def power_iteration(
|
|||||||
Returns:
|
Returns:
|
||||||
(Largest-magnitude eigenvalue, Corresponding eigenvector estimate)
|
(Largest-magnitude eigenvalue, Corresponding eigenvector estimate)
|
||||||
"""
|
"""
|
||||||
|
rng = numpy.random.default_rng()
|
||||||
if guess_vector is None:
|
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:
|
else:
|
||||||
v = guess_vector
|
v = guess_vector
|
||||||
|
|
||||||
|
@ -561,9 +561,10 @@ def eigsolve(
|
|||||||
prev_theta = 0.5
|
prev_theta = 0.5
|
||||||
D = numpy.zeros(shape=y_shape, dtype=complex)
|
D = numpy.zeros(shape=y_shape, dtype=complex)
|
||||||
|
|
||||||
|
rng = numpy.random.default_rng()
|
||||||
Z: NDArray[numpy.complex128]
|
Z: NDArray[numpy.complex128]
|
||||||
if y0 is None:
|
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:
|
else:
|
||||||
Z = numpy.array(y0, copy=False).T
|
Z = numpy.array(y0, copy=False).T
|
||||||
|
|
||||||
@ -573,7 +574,7 @@ def eigsolve(
|
|||||||
try:
|
try:
|
||||||
U = numpy.linalg.inv(ZtZ)
|
U = numpy.linalg.inv(ZtZ)
|
||||||
except numpy.linalg.LinAlgError:
|
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
|
continue
|
||||||
|
|
||||||
trace_U = real(trace(U))
|
trace_U = real(trace(U))
|
||||||
|
Loading…
Reference in New Issue
Block a user