matrix-multiplication

Solve the linear equations system AX = B in Python, np.linalg.solve not working

痴心易碎 提交于 2021-01-29 11:29:42
问题 I'm trying to solve the linear equation AX=B where A,X,B are Matrices. I've tried using the np.linalg.solve function of numpy but the result seems to be wrong. Example: Matrix A [9 1 8] [3 2 5] [1 6 5] Matrix B [7 0 5] [7 8 4] [5 6 7] So to solve X, i've used: X = np.linalg.solve(A,B) The result is: X [ 1.17521368 -0.17948718 0.40598291] [ 0.20512821 -0.30769231 0.74358974] [-0.56410256 -0.15384615 1.20512821] But if i try to verify the result by multiplying A by X, the result is anything but

Multiplying matrices using pointers

半腔热情 提交于 2021-01-28 00:41:46
问题 Hey guys I am trying practice learning pointers in c++. So I am trying to multiply these arrays and am getting all 0's in my resulting matrix. if anybody could just hint to me what to look at or some advice on what is causing this that would be amazing. Here is the code: #include <stdio.h> #include<conio.h> #include <stdlib.h> #include <iostream> /* Routines called. */ int loadMatrixFromFile(char *filename, int *data); void showMatrix(int *data, int len); int makeIdent(int matrixB[5][5], int

Multiplying real matrix with a complex vector using BLAS

那年仲夏 提交于 2021-01-26 19:08:32
问题 How can I use Blas to multiply a real matrix with a complex vector ? When I use functions like ccsrgemv() I get type mismatch errors? error: argument of type "float *" is incompatible with parameter of type "std::complex<float> *" 回答1: Use two matrix-vector multiplications (A * (x + iy) = A * x + i A * y). More precisely, consider your complex vector as two entangled real vectors with stride 2. BLAS lets you do this. UPDATE : actually, I did not notice that you were doing Sparse BLAS. For

Multiplying real matrix with a complex vector using BLAS

时光总嘲笑我的痴心妄想 提交于 2021-01-26 19:07:40
问题 How can I use Blas to multiply a real matrix with a complex vector ? When I use functions like ccsrgemv() I get type mismatch errors? error: argument of type "float *" is incompatible with parameter of type "std::complex<float> *" 回答1: Use two matrix-vector multiplications (A * (x + iy) = A * x + i A * y). More precisely, consider your complex vector as two entangled real vectors with stride 2. BLAS lets you do this. UPDATE : actually, I did not notice that you were doing Sparse BLAS. For

Multiplying real matrix with a complex vector using BLAS

懵懂的女人 提交于 2021-01-26 19:07:26
问题 How can I use Blas to multiply a real matrix with a complex vector ? When I use functions like ccsrgemv() I get type mismatch errors? error: argument of type "float *" is incompatible with parameter of type "std::complex<float> *" 回答1: Use two matrix-vector multiplications (A * (x + iy) = A * x + i A * y). More precisely, consider your complex vector as two entangled real vectors with stride 2. BLAS lets you do this. UPDATE : actually, I did not notice that you were doing Sparse BLAS. For

Calculate covariance matrix for complex data in two channels (no complex data type)

两盒软妹~` 提交于 2021-01-20 20:32:08
问题 I have complex-valued data given in 2 channels of a matrix (one is the real, one the imaginary part, so the matrix dimensions are (height, width, 2) , since Pytorch does not have native complex data types. I now want to calculate the covariance matrix. The stripped-down numpy calculation adapted for Pytorch is this: def cov(m, y=None): if m.ndimension() > 2: raise ValueError("m has more than 2 dimensions") if y.ndimension() > 2: raise ValueError('y has more than 2 dimensions') X = m if X

Calculate covariance matrix for complex data in two channels (no complex data type)

好久不见. 提交于 2021-01-20 20:31:23
问题 I have complex-valued data given in 2 channels of a matrix (one is the real, one the imaginary part, so the matrix dimensions are (height, width, 2) , since Pytorch does not have native complex data types. I now want to calculate the covariance matrix. The stripped-down numpy calculation adapted for Pytorch is this: def cov(m, y=None): if m.ndimension() > 2: raise ValueError("m has more than 2 dimensions") if y.ndimension() > 2: raise ValueError('y has more than 2 dimensions') X = m if X

Matrix-Multiplication: Why non-blocked outperforms blocked?

本秂侑毒 提交于 2020-12-30 02:22:19
问题 I'm trying to speed up a matrix multiplication algorithm by blocking the loops to improve cache performance, yet the non-blocked version remains significantly faster regardless of matrix size, block size (I've tried lots of values between 2 and 200, potenses of 2 and others) and optimization level. Non-blocked version: for(size_t i = 0; i < n; ++i) { for(size_t k = 0; k < n; ++k) { int r = a[i][k]; for(size_t j = 0; j < n; ++j) { c[i][j] += r * b[k][j]; } } } Blocked version: for(size_t kk =

Best block size value for block matrix matrix multiplication

为君一笑 提交于 2020-12-30 01:38:32
问题 I want to do block matrix-matrix multiplication with the following C code.In this approach, blocks of size BLOCK_SIZE is loaded into the fastest cache in order to reduce memory traffic during calculation. void bMMikj(double **A , double **B , double ** C , int m, int n , int p , int BLOCK_SIZE){ int i, j , jj, k , kk ; register double jjTempMin = 0.0 , kkTempMin = 0.0; for (jj=0; jj<n; jj+= BLOCK_SIZE) { jjTempMin = min(jj+ BLOCK_SIZE,n); for (kk=0; kk<n; kk+= BLOCK_SIZE) { kkTempMin = min(kk

Best block size value for block matrix matrix multiplication

痴心易碎 提交于 2020-12-30 01:33:03
问题 I want to do block matrix-matrix multiplication with the following C code.In this approach, blocks of size BLOCK_SIZE is loaded into the fastest cache in order to reduce memory traffic during calculation. void bMMikj(double **A , double **B , double ** C , int m, int n , int p , int BLOCK_SIZE){ int i, j , jj, k , kk ; register double jjTempMin = 0.0 , kkTempMin = 0.0; for (jj=0; jj<n; jj+= BLOCK_SIZE) { jjTempMin = min(jj+ BLOCK_SIZE,n); for (kk=0; kk<n; kk+= BLOCK_SIZE) { kkTempMin = min(kk