use asarray() in place of array(copy=False)

This commit is contained in:
Jan Petykiewicz 2024-07-30 22:42:49 -07:00
parent 6193a9c256
commit 684557d479
2 changed files with 10 additions and 9 deletions

View File

@ -88,7 +88,7 @@ def cg(
def load_field(v: NDArray[numpy.complexfloating], dtype: type = numpy.complex128) -> pyopencl.array.Array: def load_field(v: NDArray[numpy.complexfloating], dtype: type = numpy.complex128) -> pyopencl.array.Array:
return pyopencl.array.to_device(queue, v.astype(dtype)) 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) x = pyopencl.array.zeros_like(r)
v = pyopencl.array.zeros_like(r) v = pyopencl.array.zeros_like(r)
p = pyopencl.array.zeros_like(r) p = pyopencl.array.zeros_like(r)

View File

@ -70,7 +70,7 @@ def cg_solver(
shape = [dd.size for dd in dxes[0]] 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: ** 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 We can accomplish all this simply by conjugating everything (except J) and
reversing the order of L and R reversing the order of L and R
''' '''
epsilon = numpy.array(epsilon, copy=False) epsilon = numpy.asarray(epsilon)
if adjoint: if adjoint:
# Conjugate everything # Conjugate everything
dxes = [[numpy.conj(dd) for dd in dds] for dds in dxes] dxes = [[numpy.conj(dd) for dd in dds] for dds in dxes]
@ -133,26 +134,26 @@ def cg_solver(
rho = 1.0 + 0j rho = 1.0 + 0j
errs = [] errs = []
inv_dxes = [[load_field(1 / numpy.array(dd, copy=False)) for dd in dds] for dds in dxes] inv_dxes = [[load_field(1 / numpy.asarray(dd)) for dd in dds] for dds in dxes]
oeps = load_field(-omega ** 2 * epsilon) oeps = load_field(-omega * omega * epsilon)
Pl = load_field(L.diagonal()) Pl = load_field(L.diagonal())
Pr = load_field(R.diagonal()) Pr = load_field(R.diagonal())
if mu is None: if mu is None:
invm = load_field(numpy.array([])) invm = load_field(numpy.array([]))
else: else:
invm = load_field(1 / numpy.array(mu, copy=False)) invm = load_field(1 / numpy.asarray(mu))
mu = numpy.array(mu, copy=False) mu = numpy.asarray(mu)
if pec is None: if pec is None:
gpec = load_field(numpy.array([]), dtype=numpy.int8) gpec = load_field(numpy.array([]), dtype=numpy.int8)
else: 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: if pmc is None:
gpmc = load_field(numpy.array([]), dtype=numpy.int8) gpmc = load_field(numpy.array([]), dtype=numpy.int8)
else: 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 Generate OpenCL kernels