From b16b35d84a2ab8b7ece797f738daec58061d15b3 Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Sun, 28 Jul 2024 23:23:11 -0700 Subject: [PATCH] use new numpy.random.Generator approach --- meanas/eigensolvers.py | 3 ++- meanas/fdfd/bloch.py | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/meanas/eigensolvers.py b/meanas/eigensolvers.py index ac64f5c..032f921 100644 --- a/meanas/eigensolvers.py +++ b/meanas/eigensolvers.py @@ -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 diff --git a/meanas/fdfd/bloch.py b/meanas/fdfd/bloch.py index 0d0ac1a..e5754a1 100644 --- a/meanas/fdfd/bloch.py +++ b/meanas/fdfd/bloch.py @@ -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))