matrix-multiplication

Does scipy support multithreading for sparse matrix multiplication when using MKL BLAS?

不问归期 提交于 2019-12-04 22:58:17
问题 According to MKL BLAS documentation "All matrix-matrix operations (level 3) are threaded for both dense and sparse BLAS." http://software.intel.com/en-us/articles/parallelism-in-the-intel-math-kernel-library I have built Scipy with MKL BLAS. Using the test code below, I see the expected multithreaded speedup for dense, but not sparse, matrix multiplication. Are there any changes to Scipy to enable multithreaded sparse operations? # test dense matrix multiplication from numpy import * import

Matrix multiplication using 1d arrays

南楼画角 提交于 2019-12-04 22:53:05
问题 I'm trying to multiply two matrices stored inside 1d arrays. I'm using this function, but my program crashes, I assume due to an out of bounds error. However, I have no (easy) ability to debug, so I have to decide if my code is correct, and to me it seems it is... void SampleUtils::multiplyMatrices(float* matA, int rA, int cA, float* matB, int rB, int cB, float* matC, int rC, int cC) { for (int i = 0; i <= rA; i++) { for (int j = 0; j <= cB; j++) { float sum = 0.0; for (int k = 0; k <= rB; k+

Numpy matrix multiplication of 2d matrix to give 3d matrix

蹲街弑〆低调 提交于 2019-12-04 17:41:20
I have two numpy arrays, like A: = array([[0, 1], [2, 3], [4, 5]]) B = array([[ 6, 7], [ 8, 9], [10, 11]]) For each row of A and B, say Ra and Rb respectively, I want to calculate transpose(Ra)*Rb. So for given value of A and B, i want following answer: array([[[ 0, 0], [ 6, 7]], [[ 16, 18], [ 24, 27]], [[ 40, 44], [ 50, 55]]]) I have written the following code to do so: x = np.outer(np.transpose(A[0]), B[0]) for i in range(1,len(A)): x = np.append(x,np.outer(np.transpose(A[i]), B[i]),axis=0) Is there any better way to do this task. You can use extend dimensions of A and B with np.newaxis/None

Unproject results for object picking

最后都变了- 提交于 2019-12-04 16:17:34
There are several references to this around the web, including from stackoverflow. I have an unproject method which returns x,y coordinates which are returning in range of -1 and 1. Im wondering if these values are correct. If so, then what do i do with these values, multiply b the cameras position? Reference: How to convert mouse coordinate on screen to 3D coordinate Updated I found a bug in my matrix library, where I was missing some matrix components, I think it was in the multiplication method. After fixing this, I am no longer getting the -1 to 1 range. Now my data (freshly returned from

Google Interview : Find the maximum sum of a polygon [closed]

痴心易碎 提交于 2019-12-04 14:19:07
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 6 years ago . Given a polygon with N vertexes and N edges. There is an int number(could be negative) on every vertex and an operation in set (*,+) on every edge. Every

How to perform Vector-Matrix Multiplication with BLAS ?

眉间皱痕 提交于 2019-12-04 12:21:17
问题 BLAS defines the GEMV (Matrix-Vector Multiplication) level-2 operation. How to use a BLAS Library to perform Vector-Matrix Multiplication ? It's probably obvious, but I don't see how to use BLAS operation for this multiplication. I would have expected a GEVM operation. 回答1: The Matrix-Vector multiplication of a (M x N) Matrix with a (N x 1) Vector will result an (M x 1) Vector. In short a*A(MxN)*X(Nx1) + b*Y(Mx1) -> Y(Mx1) . Of course you can use INCX and INCY when your vector is included in

Row major vs Column Major Matrix Multiplication

夙愿已清 提交于 2019-12-04 11:42:43
I am currently working on a C program trying to compute Matrix Multiplication.. I have approached this task by looping through each column of the second matrix as seen below. I have set size to 1000. for(i=0;i<size;i++) { for(j=0;j<size;j++) { for(k=0;k<size;k++) { matC[i][j]+=matA[i][k]*matB[k][j]; } } } I wanted to know what problematic access pattern is in this implementation.. What makes row/column access more efficient than the other? I am trying to understand this in terms of logic from the use of Caches.. Please help me understand this. Your help is much appreciated :) If you are

Tetranacci Numbers in Log(n)

旧城冷巷雨未停 提交于 2019-12-04 10:14:39
I have stumbled upon a problem, which requires me to calculate the nth Tetranacci Number in O(log n). I have seen several solutions for doing this for Fibonacci Numbers I was looking to follow a similar procedure (Matrix Multiplication/Fast Doubling) to achieve this, but I am not sure how to do it exactly (take a 4 by 4 matrix and 1 by 4 in a similar fashion doesn't seem to work). With dynamic programming/general loops/any other basic idea, I am not able to achieve sub-linear runtime. Any help appreciated! From the OEIS , this is the (1,4) entry of the nth power of 1 1 0 0 1 0 1 0 1 0 0 1 1 0

LWJGL - Problems implementing 'roll' in a 6DOF Camera using quaternions and a translation matrix

限于喜欢 提交于 2019-12-04 08:39:25
I've spent a couple weeks on this issue and can't seem to find a proper solution and need some advice. I'm working on creating a Camera class using LWJGL/Java, and am using Quaternions to handle bearing (yaw), pitch and roll rotations. I'd like this camera to handle all 6 degrees of movement in 3D space, and roll. Bearing, Pitch and Roll are all quaternions. I multiply them into a 'change' quaternion, and create a translation matrix from that. I put that in a float buffer, and multiply the modelview matrix by my buffer containing the rotation matrix. I can get the bearing and pitch rotations

Where is strassen's matrix multiplication useful?

≯℡__Kan透↙ 提交于 2019-12-04 08:26:21
Strassen's algorithm for matrix multiplication just gives a marginal improvement over the conventional O(N^3) algorithm. It has higher constant factors and is much harder to implement. Given these shortcomings, is strassens algorithm actually useful and is it implemented in any library for matrix multiplication? Moreover, how is matrix multiplication implemented in libraries? Generally Strassen’s Method is not preferred for practical applications for following reasons. The constants used in Strassen’s method are high and for a typical application Naive method works better. For Sparse matrices,