Skip to content

Commit 5cdc2fe

Browse files
ilayntylerjereddy
authored andcommitted
MAINT:linalg:Remove memcpy from lu
1 parent d9ac3f3 commit 5cdc2fe

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

scipy/linalg/_decomp_lu_cython.pyx

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import cython
44
from cpython.mem cimport PyMem_Malloc, PyMem_Free
5-
from libc.string cimport memcpy
6-
75
from scipy.linalg.cython_lapack cimport sgetrf, dgetrf, cgetrf, zgetrf
86
from scipy.linalg._cythonized_array_utils cimport lapack_t, swap_c_and_f_layout
97

@@ -103,7 +101,9 @@ cdef void lu_decompose(cnp.ndarray[lapack_t, ndim=2] a,
103101
# as final. Solution without argsort : ipiv[perm] = np.arange(m)
104102
for ind1 in range(m):
105103
ipiv[perm[ind1]] = ind1
106-
memcpy(&perm[0], ipiv, m*sizeof(int))
104+
for ind1 in range(m):
105+
perm[ind1] = ipiv[ind1]
106+
107107
finally:
108108
PyMem_Free(ipiv)
109109

@@ -135,24 +135,22 @@ cdef void lu_decompose(cnp.ndarray[lapack_t, ndim=2] a,
135135
# rows from b as dictated by perm
136136

137137
if m > n:
138-
memcpy(bb, &a[0, 0], m*mn*sizeof(lapack_t))
138+
b[:, :] = a[:, :]
139+
# memcpy(bb, &a[0, 0], m*mn*sizeof(lapack_t))
139140
for ind1 in range(m):
140141
if perm[ind1] == ind1:
141142
continue
142143
else:
143-
memcpy(&a[ind1, 0],
144-
bb + (perm[ind1]*mn), # row stride
145-
mn*sizeof(lapack_t)) # copy one row of memory
144+
a[ind1, :] = b[perm[ind1], :]
146145

147146
else: # same but for lu array
148-
memcpy(bb, &lu[0, 0], mn*n*sizeof(lapack_t))
147+
b[:mn, :mn] = lu[:, :]
148+
# memcpy(bb, &lu[0, 0], mn*n*sizeof(lapack_t))
149149
for ind1 in range(mn):
150150
if perm[ind1] == ind1:
151151
continue
152152
else:
153-
memcpy(&lu[ind1, 0],
154-
bb + (perm[ind1]*mn),
155-
mn*sizeof(lapack_t))
153+
lu[ind1, :] = b[perm[ind1], :mn]
156154

157155

158156
@cython.nonecheck(False)

0 commit comments

Comments
 (0)