linear-algebra

Very slow performance of cusparse csrsv_analysis

半腔热情 提交于 2020-01-11 03:34:06
问题 I wrote a Conjugate-gradient solver (for linear system of equations) with LU preconditioning, I used Dr. Maxim Naumov's papers on nvidia's research community as a guideline, the residuals update step, which requires solving a lower triangular matrix system and then solving an upper triangular matrix system is divided into two phases: analysis phase (which exploits the sparsity pattern and decides the parallelization level). the solution phase itself. according to all posts related to this

how to solve many overdetermined systems of linear equations using vectorized codes?

拥有回忆 提交于 2020-01-11 03:22:12
问题 I need to solve a system of linear equations Lx=b, where x is always a vector (3x1 array), L is an Nx3 array, and b is an Nx1 vector. N usually ranges from 4 to something like 10. I have no problems solving this using scipy.linalg.lstsq(L,b) However, I need to do this many times (something like 200x200=40000 times) as x is actually something associated with each pixel in an image. So x is actually stored in an PxQx3 array where P and Q is something like 200-300, and the last number '3' refers

Compute inverse of 2D arrays along the third axis in a 3D array without loops

末鹿安然 提交于 2020-01-11 02:11:43
问题 I have an array A whose shape is (N, N, K) and I would like to compute another array B with the same shape where B[:, :, i] = np.linalg.inv(A[:, :, i]) . As solutions, I see map and for loops but I am wondering if numpy provides a function to do this (I have tried np.apply_over_axes but it seems that it can only handle 1D array). with a for loop: B = np.zeros(shape=A.shape) for i in range(A.shape[2]): B[:, :, i] = np.linalg.inv(A[:, :, i]) with map : B = np.asarray(map(np.linalg.inv, np

Compute inverse of 2D arrays along the third axis in a 3D array without loops

こ雲淡風輕ζ 提交于 2020-01-11 02:10:54
问题 I have an array A whose shape is (N, N, K) and I would like to compute another array B with the same shape where B[:, :, i] = np.linalg.inv(A[:, :, i]) . As solutions, I see map and for loops but I am wondering if numpy provides a function to do this (I have tried np.apply_over_axes but it seems that it can only handle 1D array). with a for loop: B = np.zeros(shape=A.shape) for i in range(A.shape[2]): B[:, :, i] = np.linalg.inv(A[:, :, i]) with map : B = np.asarray(map(np.linalg.inv, np

Scipy-like functionality in Java / Scala? [closed]

北战南征 提交于 2020-01-10 18:25:32
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 2 years ago . I'm trying to port some Python code to Scala. It makes heavy use of Numpy and Scipy. While I've found a number of dense matrix / linear algebra libraries that will do as an adequate (but not superb) replacement for NumPy, I've not really found anything that provides the functionality I use in SciPy. In

Linear Algebra library for Javascript? [closed]

若如初见. 提交于 2020-01-10 12:14:19
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . I don't need anything fancy; basically, if it will let me do some basic Matrix*Matrix stuff I'll be happy. 回答1: You could use numericjs.com. It's a javascript numerical analysis library that I'm working on that has several standard matrix algorithms for arbitrary sized dense matrices. 回答2: Numericjs.com is good

Linear Algebra library for Javascript? [closed]

不想你离开。 提交于 2020-01-10 12:12:25
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . I don't need anything fancy; basically, if it will let me do some basic Matrix*Matrix stuff I'll be happy. 回答1: You could use numericjs.com. It's a javascript numerical analysis library that I'm working on that has several standard matrix algorithms for arbitrary sized dense matrices. 回答2: Numericjs.com is good

broadcasting linalg.pinv on a 3D theano tensor

空扰寡人 提交于 2020-01-06 19:38:24
问题 in the example below, there is a 3d numpy matrix of size (4, 3, 3)+ a solution about how to calculate pinv of each of 4 of those 3*3 matrices in numpy. I also tried to use the same function worked in numpy, in theano hoping that it is implemented the same, but it failed. Any idea how to do it in theano? dt = np.dtype(np.float32) a=[[[12,3,1], [2,4,1], [2,4,2],], [[12,3,3], [2,4,4], [2,4,5],], [[12,3,6], [2,4,5], [2,4,4],], [[12,3,3], [2,4,5], [2,4,6]]] a=np.asarray(a,dtype=dt) print(a.shape)

How does one test if a matrix in Python has only 1's and 0's?

旧时模样 提交于 2020-01-06 10:55:30
问题 Let's say I've got a matrix like this: mat1 = np.array([1,0,1], [1,1,0], [0,0,0]); And I've got another one like this: mat2 = np.array([0,1,0], [0,0,1], [1,1,1]); I want to detect if something like np.add(mat1, mat2); has only 1's or 0's, namely some 1's and some 0's, all 0's, or all 1's. n.b. - Comment your code. 回答1: How about this: >>> def check(matrix): ... # flatten up the matrix into one single list ... # and set on the list it should be [0,1] if it ... # contains only 0 and 1. Then do

How does one test if a matrix in Python has only 1's and 0's?

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-06 10:54:52
问题 Let's say I've got a matrix like this: mat1 = np.array([1,0,1], [1,1,0], [0,0,0]); And I've got another one like this: mat2 = np.array([0,1,0], [0,0,1], [1,1,1]); I want to detect if something like np.add(mat1, mat2); has only 1's or 0's, namely some 1's and some 0's, all 0's, or all 1's. n.b. - Comment your code. 回答1: How about this: >>> def check(matrix): ... # flatten up the matrix into one single list ... # and set on the list it should be [0,1] if it ... # contains only 0 and 1. Then do