简体   繁体   中英

calculating the determinant of a matrix with cupy (python)

Im currently editing code for use with Cupy in python for GPU acceleration. Most of the edits have required a straight swap from numpy to cupy (eg cp.array instead of np.array) with a few minor exceptions. However, Im having trouble with this section of code, it works with numpy and im unsure of why I suddenly get this error. I have the following code

ab = (b - a)
ac = (c - a)
ap1 = (p1 - a)
ap2 = (p2 - a)

where a,b,c,p1 and p2 are all 1D Cupy arrays

From here I want to use the following to calculate the determinants.

testP1 = 1 if cp.linalg.det([ab,ac,ap1]) >0 else 0
testP2 = 1 if cp.linalg.det([ab,ac,ap2]) >0 else 0

This works fine in numpy (with the inputs being numpy rather than cupy arrays), however, I now get the following error

AttributeError: 'list' object has no attribute 'ndim'

As g2i commented, cupy doesnt implicitly convert to an array whilst numpy does, hence the conversion to a cupy array must be done explicitly

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM