matrix-multiplication

Matrix Multiplication of size 100*100 using SSE Intrinsics

狂风中的少年 提交于 2020-01-06 06:51:45
问题 int MAX_DIM = 100; float a[MAX_DIM][MAX_DIM]__attribute__ ((aligned(16))); float b[MAX_DIM][MAX_DIM]__attribute__ ((aligned(16))); float d[MAX_DIM][MAX_DIM]__attribute__ ((aligned(16))); /* * I fill these arrays with some values */ for(int i=0;i<MAX_DIM;i+=1){ for(int j=0;j<MAX_DIM;j+=4){ for(int k=0;k<MAX_DIM;k+=4){ __m128 result = _mm_load_ps(&d[i][j]); __m128 a_line = _mm_load_ps(&a[i][k]); __m128 b_line0 = _mm_load_ps(&b[k][j+0]); __m128 b_line1 = _mm_loadu_ps(&b[k][j+1]); __m128 b_line2

Matrix - return and pass as parameter c++

最后都变了- 提交于 2020-01-05 05:48:08
问题 I'm trying to use clear functions to do a matrix multiplication with random generated values. Therefore I'm hoping to use a function( mat_def ) to generate the matrices and another function( mat_mul ) to multiply them when the matrices are sent as parameters. #include <iostream> #include <stdio.h> #include <stdlib.h> #include <time.h> using namespace std; double mat_def(int n) //how to return the matrix { double a[n][n]; double f; for(int i=0; i<n; i++) { for(int j=0; j<n; j++) { f= rand();

Fortran function to overload multiplication between derived types with allocatable components

╄→尐↘猪︶ㄣ 提交于 2020-01-05 03:46:07
问题 Foreword In order to store banded matrices whose full counterparts can have both rows and columns indexed from indices other than 1 , I defined a derived data type as TYPE CDS REAL, DIMENSION(:,:), ALLOCATABLE :: matrix INTEGER, DIMENSION(2) :: lb, ub INTEGER :: ld, ud END TYPE CDS where CDS stands for compressed diagonal storage. Given the declaration TYPE(CDS) :: A , The rank-2 component matrix is supposed to contain, as columns, the diagonals of the actual full matrix (like here, except

How to work with a 2D array with unknown dimensions?

早过忘川 提交于 2020-01-04 15:56:09
问题 I'm writing a C function for matrix multiplication. It takes two 2D arrays of ints. I could do this if I knew the dimensions of the input arrays, but I'd like to make a more general function. How to find their dimensions, and how to return an array when I don't know the product's dimensions on compile-time? 回答1: You can't find out the dimensions of an array if all you have is a pointer to the beginning of the array. You will need to pass the dimensions of the array to the functions. 回答2: This

numpy elementwise outer product with sparse matrices

孤街醉人 提交于 2020-01-03 20:22:08
问题 I want to do the element-wise outer product of three (or four) large 2D arrays in python (values are float32 rounded to 2 decimals). They all have the same number of rows "n", but different number of columns "i", "j", "k". The resulting array should be of shape (n, i*j*k). Then, I want to sum each column of the result to end up with a 1D array of shape (i*j*k). np.shape(a) = (75466, 10) np.shape(b) = (75466, 28) np.shape(c) = (75466, 66) np.shape(intermediate_result) = (75466, 18480) np.shape

Receiving transformed mouse event data from DOM objects with a CSS 3D transform

痞子三分冷 提交于 2020-01-03 10:18:11
问题 Is there currently any data in a javascript mouse event that would allow me to easily find or calculate a mouse position relative to the 3D space of a transformed element? To illustrate visually, At left is the div without a 3d matrix, at right is the div after 3d transformation. o is the origin of the mouse event + /| / | +-----+ + | | | | | | o| => | o| | | | | +-----+ + | \ | \| + In the script below, clicking the same pixels in the div will report an event.layerX which is in the 2d

Recursive matrix multiplication

China☆狼群 提交于 2020-01-02 19:57:10
问题 I am reading Introduction to Algorithms by CLRS. Book shows pseudocode for simple divide and conquer matrix multiplication: n = A.rows let c be a new n x n matrix if n == 1 c11 = a11 * b11 else partition A, B, and C C11 = SquareMatrixMultiplyRecursive(A11, B11) + SquareMatrixMultiplyRecursive(A12, B21) //... return C Where for example, A11 is submatrix of A of size n/2 x n/2. Author also hints that I should use index calculations instead of creating new matrices to represent submatrices, so I

Matrix multiplication using multiple threads?

南笙酒味 提交于 2020-01-02 06:07:36
问题 I am supposed to multiply 2 matrices using threads. Two things: I keep getting 0's when I run the program. I also get message errors(for each, it says "warning: passing argument 1 of 'printMatrix' from incompatible pointer type" on the bolded lines(where I try to print the output). Also to note, the first block that is bolded, I that was my attempt at solving the problem. I think I am close, but I may not be. Can anyone help? Thanks :) Output looks like this: A= 1 4 2 5 3 6 B= 8 7 6 5 4 3 A*B

Generalized Matrix Product

时光总嘲笑我的痴心妄想 提交于 2020-01-02 02:24:22
问题 I'm fairly new to MATLAB. Normal matrix multiplication of a M x K matrix by an K x N matrix -- C = A * B -- has c_ij = sum(a_ik * b_kj, k = 1:K) . What if I want this to be instead c_ij = sum(op(a_ik, b_kj), k = 1:K) for some simple binary operation op ? Is there any nice way to vectorize this in MATLAB (or maybe even a built-in function)? EDIT: This is currently the best I can do. % A is M x K, B is K x N % op is min C = zeros(M, N); for i = 1:M: C(i, :) = sum(bsxfun(@min, A(i, :)', B)); end

CSR Matrix - Matrix multiplication

我是研究僧i 提交于 2020-01-01 10:38:50
问题 I have two square matrices A and B I must convert B to CSR Format and determine the product C A * B_csr = C I have found a lot of information online regarding CSR Matrix - Vector multiplication. The algorithm is: for (k = 0; k < N; k = k + 1) result[i] = 0; for (i = 0; i < N; i = i + 1) { for (k = RowPtr[i]; k < RowPtr[i+1]; k = k + 1) { result[i] = result[i] + Val[k]*d[Col[k]]; } } However, I require Matrix - Matrix multiplication. Further, it seems that most algorithms apply A_csr - vector