matrix-multiplication

Multithreaded sparse matrix multiplication in Matlab

左心房为你撑大大i 提交于 2019-11-30 23:53:01
问题 I am performing several matrix multiplications of an NxN sparse (~1-2%) matrix, let's call it B, with an NxM dense matrix, let's call it A (where M < N). N is large, as is M; on the order of several thousands. I am running Matlab 2013a. Now, usually, matrix multiplications and most other matrix operations are implicitly parallelized in Matlab, i.e. they make use of multiple threads automatically. This appears NOT to be the case if either of the matrices are sparse (see e.g. this StackOverflow

Google Cloud: matrix multiplication with Bigquery or some other service?

人盡茶涼 提交于 2019-11-30 20:37:36
问题 I am using Google Analytics and processing the data with Bigquery, I need to do a matrix multiplication. What is the most feasible way of implementing matrix multiplication in Google Cloud? Can it be done directly in Bigquery? 回答1: Assuming MatrixA is a table with below columns: i, k, value and MatrixB - has schema as k, j, value and also assuming that range of k-values is the same in both tables: This would mimic below matrices : Matrix A 2 -3 4 -1 0 2 Matrix B -1 2 3 0 1 7 1 1 -2 Below code

Matlab matrix multiplication speed

做~自己de王妃 提交于 2019-11-30 20:15:20
I was wondering how can matlab multiply two matrices so fast. When multiplying two NxN matrices, N^3 multiplications are performed. Even with the Strassen Algorithm it takes N^2.8 multiplications, which is still a large number. I was running the following test program: a = rand(2160); b = rand(2160); tic;a*b;toc 2160 was used because 2160^3=~10^10 ( a*b should be about 10^10 multiplications) I got: Elapsed time is 1.164289 seconds. (I'm running on 2.4Ghz notebook and no threading occurs) which mean my computer made ~10^10 operation in a little more than 1 second. How this could be?? It's a

Element-wise matrix multiplication in NumPy

戏子无情 提交于 2019-11-30 19:45:22
I'm making my first real foray into Python and NumPy to do some image processing. I have an image loaded as a 3 dimensional NumPy Array, where axis 0 represents image bands, while axes 1 and 2 represent columns and rows of pixels. From this, I need to take the 3x1 matrix representing each pixel and perform a few operations which result in another 3x1 matrix, which will be used to build a results image. My first approach (simplified and with random data) looks like this: import numpy as np import random factor = np.random.rand(3,3) input = np.random.rand(3,100,100) results = np.zeros((3,100,100

Matrix/Tensor Triple Product?

狂风中的少年 提交于 2019-11-30 18:46:02
An algorithm I'm working on requires computing, in a couple places, a type of matrix triple product. The operation takes three square matrices with identical dimensions, and produces a 3-index tensor. Labeling the operands A , B and C , the (i,j,k) -th element of the result is X[i,j,k] = \sum_a A[i,a] B[a,j] C[k,a] In numpy, you can compute this with einsum('ia,aj,ka->ijk', A, B, C) . Questions: Does this operation have a standard name? Can I compute this with a single BLAS call? Are there any other heavy-optimized numerical C/Fortran libraries that can compute expressions of this type?

Matrix multiplication, solve Ax = b solve for x

爱⌒轻易说出口 提交于 2019-11-30 17:52:25
So I was given a homework assignment that requires solving the coefficients of cubic splines. Now I clearly understand how to do the math on paper as well as with MatLab, I want to solve the problem with Python. Given an equation Ax = b where I know the values of A and b, I want to be able to solve for x with Python and I am having trouble finding a good resource to do such a thing. Ex. A = |1 0 0| |1 4 1| |0 0 1| x = Unknown 3x1 matrix b = |0 | |24| |0 | Solve for x ev-br In a general case, use solve : >>> import numpy as np >>> from scipy.linalg import solve >>> >>> A = np.random.random((3,

numpy matrix multiplication shapes [duplicate]

旧街凉风 提交于 2019-11-30 17:09:50
问题 This question already has answers here : how does multiplication differ for NumPy Matrix vs Array classes? (8 answers) Closed 6 years ago . In matrix multiplication, assume that the A is a 3 x 2 matrix (3 rows, 2 columns ) and B is a 2 x 4 matrix (2 rows, 4 columns ), then if a matrix C = A * B , then C should have 3 rows and 4 columns. Why does numpy not do this multiplication? When I try the following code I get an error : ValueError: operands could not be broadcast together with shapes (3

Tensorflow, how to multiply a 2D tensor (matrix) by corresponding elements in a 1D vector

霸气de小男生 提交于 2019-11-30 16:16:45
I have a 2D matrix M of shape [batch x dim] , I have a vector V of shape [batch] . How can I multiply each of the columns in the matrix by the corresponding element in the V? That is: I know an inefficient numpy implementation would look like this: import numpy as np M = np.random.uniform(size=(4, 10)) V = np.random.randint(4) def tst(M, V): rows = [] for i in range(len(M)): col = [] for j in range(len(M[i])): col.append(M[i][j] * V[i]) rows.append(col) return np.array(rows) In tensorflow, given two tensors, what is the most efficient way to achieve this? import tensorflow as tf sess = tf

Equivalent of cudaGetErrorString for cuBLAS?

二次信任 提交于 2019-11-30 14:21:45
CUDA runtime has a convenience function cudaGetErrorString(cudaError_t error) that translates an error enum into a readable string. cudaGetErrorString is used in the CUDA_SAFE_CALL(someCudaFunction()) macro that many people use for CUDA error handling. I'm familiarizing myself with cuBLAS now, and I'd like to create a macro similar to CUDA_SAFE_CALL for cuBLAS. To make my macro's printouts useful, I'd like to have something analogous to cudaGetErrorString in cuBLAS. Is there an equivalent of cudaGetErrorString() in cuBLAS? Or, have any cuBLAS users written a function like this? In CUDA 5.0,

Efficient element-wise multiplication of a matrix and a vector in TensorFlow

时光毁灭记忆、已成空白 提交于 2019-11-30 11:48:59
问题 What would be the most efficient way to multiply (element-wise) a 2D tensor (matrix): x11 x12 .. x1N ... xM1 xM2 .. xMN by a vertical vector: w1 ... wN to obtain a new matrix: x11*w1 x12*w2 ... x1N*wN ... xM1*w1 xM2*w2 ... xMN*wN To give some context, we have M data samples in a batch that can be processed in parallel, and each N -element sample must be multiplied by weights w stored in a variable to eventually pick the largest Xij*wj for each row i . 回答1: The simplest code to do this relies