From 684557d479f5201ffa105ca1ffe21661da007f59 Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Tue, 30 Jul 2024 22:42:49 -0700 Subject: [PATCH] use asarray() in place of array(copy=False) --- opencl_fdfd/csr.py | 2 +- opencl_fdfd/main.py | 17 +++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/opencl_fdfd/csr.py b/opencl_fdfd/csr.py index e2c5677..ec49c09 100644 --- a/opencl_fdfd/csr.py +++ b/opencl_fdfd/csr.py @@ -88,7 +88,7 @@ def cg( def load_field(v: NDArray[numpy.complexfloating], dtype: type = numpy.complex128) -> pyopencl.array.Array: return pyopencl.array.to_device(queue, v.astype(dtype)) - r = load_field(b) + r = load_field(numpy.asarray(b)) x = pyopencl.array.zeros_like(r) v = pyopencl.array.zeros_like(r) p = pyopencl.array.zeros_like(r) diff --git a/opencl_fdfd/main.py b/opencl_fdfd/main.py index f4bd139..769aee3 100644 --- a/opencl_fdfd/main.py +++ b/opencl_fdfd/main.py @@ -70,7 +70,7 @@ def cg_solver( shape = [dd.size for dd in dxes[0]] - b = -1j * omega * numpy.array(J, copy=False) + b = -1j * omega * numpy.asarray(J) ''' ** In this comment, I use the following notation: @@ -99,7 +99,8 @@ def cg_solver( We can accomplish all this simply by conjugating everything (except J) and reversing the order of L and R ''' - epsilon = numpy.array(epsilon, copy=False) + epsilon = numpy.asarray(epsilon) + if adjoint: # Conjugate everything dxes = [[numpy.conj(dd) for dd in dds] for dds in dxes] @@ -133,26 +134,26 @@ def cg_solver( rho = 1.0 + 0j errs = [] - inv_dxes = [[load_field(1 / numpy.array(dd, copy=False)) for dd in dds] for dds in dxes] - oeps = load_field(-omega ** 2 * epsilon) + inv_dxes = [[load_field(1 / numpy.asarray(dd)) for dd in dds] for dds in dxes] + oeps = load_field(-omega * omega * epsilon) Pl = load_field(L.diagonal()) Pr = load_field(R.diagonal()) if mu is None: invm = load_field(numpy.array([])) else: - invm = load_field(1 / numpy.array(mu, copy=False)) - mu = numpy.array(mu, copy=False) + invm = load_field(1 / numpy.asarray(mu)) + mu = numpy.asarray(mu) if pec is None: gpec = load_field(numpy.array([]), dtype=numpy.int8) else: - gpec = load_field(numpy.array(pec, dtype=bool, copy=False), dtype=numpy.int8) + gpec = load_field(numpy.asarray(pec, dtype=bool), dtype=numpy.int8) if pmc is None: gpmc = load_field(numpy.array([]), dtype=numpy.int8) else: - gpmc = load_field(numpy.array(pmc, dtype=bool, copy=False), dtype=numpy.int8) + gpmc = load_field(numpy.asarray(pmc, dtype=bool), dtype=numpy.int8) ''' Generate OpenCL kernels