matrix-multiplication

Calculating column-wise dot product between two matrices

☆樱花仙子☆ 提交于 2019-12-08 04:37:25
问题 I would like to determine the dot product between the i th column in one matrix and the i th column in a second matrix. The end result will be an array containing i dot products. Here is a reproducible example of what I want to do: #Generate two matrices with 10 columns each with 5 rows (thus i in this case is 10) m1 <- replicate(10, rnorm(5)) m2 <- replicate(10, rnorm(5)) #Inefficiently calculate dot product of ith column in m1 with ith column in m2 d1 <- t(m1[,1]) %*% m2[,1] d2 <- t(m1[,2])

Implement the Fixed function Pipeline efficent in OpenGL ES 2.0?

我与影子孤独终老i 提交于 2019-12-08 03:45:12
问题 I want to use fixed function methods like glTranslate(), glRotate(), glScale() in my openGL 2.0 App. I know, that I need to implement an matrix class - and have done this. My question now is about efficiency. To be able to use something like: glLoadIdentity(); glRotatef(2.0f, 0.0f, 0.0f, 1.0f); glScalef(2.0f, 2.0f, 2.0f); I think, I need to do at least 3 matrix multiplications (assuming we have a projection and a modelview matrizes and this is for the modelview). First would be: Identity

From Matlab to C++ Eigen matrix operations - vector normalization

大憨熊 提交于 2019-12-08 02:16:44
问题 Converting some Matlab code to C++. Questions (how to in C++): Concatenate two vectors in a matrix. (already found the solution) Normalize each array ("pts" col) dividing it by its 3rd value Matlab code for 1 and 2: % 1. A 3x1 vector. d0, d1 double. B = [d0*A (d0+d1)*A]; % B is 3x2 % 2. Normalize a set of 3D points % Divide each col by its 3rd value % pts 3xN. C 3xN. % If N = 1 you can do: C = pts./pts(3); if not: C = bsxfun(@rdivide, pts, pts(3,:)); C++ code for 1 and 2: // 1. Found the

How do I rotate an arkit 4x4 matrix around Y using Apple's SIMD library?

左心房为你撑大大i 提交于 2019-12-08 02:01:12
问题 I am trying to implement some code based on an ARKit demo where someone used this helper function to place a waypoint let rotationMatrix = MatrixHelper.rotateAboutY( degrees: bearing * -1 ) How can I implement the .rotateAboutY function using the SIMD library and not using GLKit? To make it easier, I could start from the origin point. I'm not too handy with the matrix math so a more basic explanation would be helpful. 回答1: The rotation around Y matrix is: | cos(angle) 0 sin(angle)| | 0 1 0 |

MATLAB: Block matrix multiplying without loops

蹲街弑〆低调 提交于 2019-12-08 01:48:28
问题 I have a block matrix [A B C...] and a matrix D (all 2-dimensional). D has dimensions y-by-y, and A, B, C , etc are each z-by-y. Basically, what I want to compute is the matrix [D*(A'); D*(B'); D*(C');...] , where X ' refers to the transpose of X . However, I want to accomplish this without loops for speed considerations. I have been playing with the reshape command for several hours now, and I know how to use it in other cases, but this use case is different from the other ones and I cannot

Implement the Fixed function Pipeline efficent in OpenGL ES 2.0?

独自空忆成欢 提交于 2019-12-07 20:18:26
I want to use fixed function methods like glTranslate(), glRotate(), glScale() in my openGL 2.0 App. I know, that I need to implement an matrix class - and have done this. My question now is about efficiency. To be able to use something like: glLoadIdentity(); glRotatef(2.0f, 0.0f, 0.0f, 1.0f); glScalef(2.0f, 2.0f, 2.0f); I think, I need to do at least 3 matrix multiplications (assuming we have a projection and a modelview matrizes and this is for the modelview). First would be: Identity-Matrix*Rotation-Matrix - Second is: ActualMatrix*ScaleMatrix and the last would be: projectionMatrix

Multiplication of two arrays with dimension=5 in a vectorize way

99封情书 提交于 2019-12-07 18:28:07
问题 I have a three dimensional domain in MATLAB. For each point in the domain I have defined three arrays of size (NX,NY,NZ) at each point of the domain: A1; % size(A1) = [NX NY NZ] A2; % size(A2) = [NX NY NZ] A3; % size(A3) = [NX NY NZ] For each element, I am trying to construct an array which holds the value of A1 , A2 , and A3 . Would the following be a good candidate for having a 1×3 vector at each point? B = [A1(:) A2(:) A3(:)]; B = reshape(B, [size(A1) 1 3]); If the 1×3 array is named C , I

OpenCL matrix multiplication should be faster?

徘徊边缘 提交于 2019-12-07 12:03:31
问题 I'm trying to learn how to make GPU optimalized OpenCL kernells, I took example of matrix multiplication using square tiles in local memory. However I got at best case just ~10-times speedup ( ~50 Gflops ) in comparison to numpy.dot() ( 5 Gflops , it is using BLAS). I found studies where they got speedup >200x ( >1000 Gflops ) . ftp://ftp.u-aizu.ac.jp/u-aizu/doc/Tech-Report/2012/2012-002.pdf I don't know what I'm doing wrong, or if it is just because of my GPU ( nvidia GTX 275 ). Or if it is

bsxfun implementation in solving a min. optimization task

一笑奈何 提交于 2019-12-07 09:13:34
I really need help with this one. I have to matrices L1 and L2 , both are (500x3) of size. First of all, I compute the difference of every element of each column of L1 from L2 as follows: lib1 = bsxfun(@minus, L1(:,1)',L2(:,1)); lib1=lib1(:); lib2 = bsxfun(@minus, L1(:,2)',L2(:,2)); lib2=lib2(:); lib3 = bsxfun(@minus, L1(:,3)',L2(:,3)); lib3=lib3(:); LBR = [lib1 lib2 lib3]; The result is this matrix LBR . Then I have a min -problem to solve: [d,p] = min((LBR(:,1) - var1).^2 + (LBR(:,2) - var2).^2 + (LBR(:,3) - var3).^2); Which returns the point p where this min -problem is fulfied. Finally I

Scipy sparse matrices element wise multiplication

梦想的初衷 提交于 2019-12-07 07:55:12
问题 I am trying to do an element-wise multiplication for two large sparse matrices. Both are of size around (400K X 500K), with around 100M elements. However, they might not have non-zero elements in the same positions, and they might not have the same number of non-zero elements. In either situation, Im okay with multiplying the non-zero value of one matrix and the zero value in the other matrix to zero. I keep running out of memory (8GB) in every approach, which doesnt make much sense. I