matrix-multiplication

How to implement fast image filters on iOS platform

柔情痞子 提交于 2019-11-29 02:58:31
问题 I am working on iOS application where user can apply a certain set of photo filters. Each filter is basically set of Photoshop actions with a specific parameters. This actions are: Levels adjustment Brightness / Contrast Hue / Saturation Single and multiple overlay I've repeated all this actions in my code using arithmetic expressions looping through the all pixels in image. But when I run my app on iPhone 4, each filter takes about 3-4 sec to apply which is quite a few time for the user to

Matrix multiplication using hdf5

China☆狼群 提交于 2019-11-29 01:55:42
问题 I'm trying to multiplicate 2 big matrices with memory limit using hdf5 (pytables) but function numpy.dot seems to give me error: Valueerror: array is too big I need to do matrix multiplication by myself maybe blockwise or there is some another python function similar to numpy.dot? import numpy as np import time import tables import cProfile import numexpr as ne n_row=10000 n_col=100 n_batch=10 rows = n_row cols = n_col batches = n_batch atom = tables.UInt8Atom() #? filters = tables.Filters

Why is a naïve C++ matrix multiplication 100 times slower than BLAS?

谁说胖子不能爱 提交于 2019-11-29 01:21:13
问题 I am taking a look at large matrix multiplication and ran the following experiment to form a baseline test: Randomly generate two 4096x4096 matrixes X, Y from std normal (0 mean, 1 stddev). Z = X*Y Sum elements of Z (to make sure they are accessed) and output. Here is the naïve C++ implementatation: #include <iostream> #include <algorithm> using namespace std; int main() { constexpr size_t dim = 4096; float* x = new float[dim*dim]; float* y = new float[dim*dim]; float* z = new float[dim*dim];

Why is my Strassen's Matrix Multiplication slow?

ぐ巨炮叔叔 提交于 2019-11-29 01:16:45
问题 I wrote two Matrix Multiplications programs in C++: Regular MM (source), and Strassen's MM (source), both of which operate on square matrices of sizes 2^k x 2^k(in other words, square matrices of even size). Results are just terrible. For 1024 x 1024 matrix, Regular MM takes 46.381 sec , while Strassen's MM takes 1484.303 sec ( 25 minutes !!!!). I attempted to keep the code as simple as possible. Other Strassen's MM examples found on the web are not that much different from my code. One issue

How to optimize matrix multiplication operation [duplicate]

帅比萌擦擦* 提交于 2019-11-29 00:09:53
This question already has an answer here: Optimized matrix multiplication in C 13 answers I need to perform a lot of matrix operations in my application. The most time consuming is matrix multiplication. I implemented it this way template<typename T> Matrix<T> Matrix<T>::operator * (Matrix& matrix) { Matrix<T> multipliedMatrix = Matrix<T>(this->rows,matrix.GetColumns(),0); for (int i=0;i<this->rows;i++) { for (int j=0;j<matrix.GetColumns();j++) { multipliedMatrix.datavector.at(i).at(j) = 0; for (int k=0;k<this->columns ;k++) { multipliedMatrix.datavector.at(i).at(j) += datavector.at(i).at(k) *

What is R's multidimensional equivalent of rbind and cbind?

落花浮王杯 提交于 2019-11-28 23:34:23
问题 When working with matrices in R, one can put them side-by-side or stack them top of each other using cbind and rbind, respectively. What is the equivalent function for stacking matrices or arrays in other dimensions? For example, the following creates a pair of 2x2 matrices, each having 4 elements: x = cbind(1:2,3:4) y = cbind(5:6,7:8) What is the code to combine them into a 2x2x2 array with 8 elements? 回答1: See the abind package. If you want them to bind on a 3rd dimension, do this: library

Speed up matrix multiplication by SSE (C++)

送分小仙女□ 提交于 2019-11-28 21:32:51
I need to run a matrix-vector multiplication 240000 times per second. The matrix is 5x5 and is always the same, whereas the vector changes at each iteration. The data type is float. I was thinking of using some SSE (or similar) instructions. 1) I am concerned that the number of arithmetic operations is too small compared to the number of memory operations involved. Do you think I can get some tangible (e.g. > 20%) improvement? 2) Do I need the Intel compiler to do it? 3) Can you point out some references? Thanks everybody! The Eigen C++ template library for vectors, matrices, ... has both

Why is this naive matrix multiplication faster than base R's?

馋奶兔 提交于 2019-11-28 21:09:03
In R, matrix multiplication is very optimized, i.e. is really just a call to BLAS/LAPACK. However, I'm surprised this very naive C++ code for matrix-vector multiplication seems reliably 30% faster. library(Rcpp) # Simple C++ code for matrix multiplication mm_code = "NumericVector my_mm(NumericMatrix m, NumericVector v){ int nRow = m.rows(); int nCol = m.cols(); NumericVector ans(nRow); double v_j; for(int j = 0; j < nCol; j++){ v_j = v[j]; for(int i = 0; i < nRow; i++){ ans[i] += m(i,j) * v_j; } } return(ans); } " # Compiling my_mm = cppFunction(code = mm_code) # Simulating data to use nRow =

How to compute only the diagonal of a matrix product in Octave?

廉价感情. 提交于 2019-11-28 20:43:35
Is there a way in Octave to compute and store only the diagonal of a matrix product? Basically like doing: vector = diag(A*B); I don't care about any of the values of A*B except those on the diagonal. The matrix sizes are around 80k x 12 and 12 x 80k , so even if I didn't care about the speed/extra memory it simply wont fit in RAM. Strange, since Octave is a package for huge data sets and diagonals are very important, so it should be possible. The first element in the diagonal is the scalar product of the first row of A with the first column of B. The second element in the diagonal is the

Efficient SSE NxN matrix multiplication

送分小仙女□ 提交于 2019-11-28 10:35:15
I'm trying to implement SSE version of large matrix by matrix multiplication. I'm looking for an efficient algorithm based on SIMD implementations. My desired method looks like: A(n x m) * B(m x k) = C(n x k) And all matrices are considered to be 16-byte aligned float array. I searched the net and found some articles describing 8x8 multiplication and even smaller. I really need it as efficient as possible and I don't want to use Eigen library or similar libraries. (Only SSE3 to be more specific). So I'd appreciate if anyone can help me find some articles or resources on how to start