vector-multiplication

Matrix-Vector and Matrix-Matrix multiplication using SSE

懵懂的女人 提交于 2021-02-07 04:28:19
问题 I need to write matrix-vector and matrix-matrix multiplication functions but I cannot wrap my head around SSE commands. The dimensions of matrices and vectors are always multiples of 4. I managed to write the vector-vector multiplication function that looks like this: void vector_multiplication_SSE(float* m, float* n, float* result, unsigned const int size) { int i; __declspec(align(16))__m128 *p_m = (__m128*)m; __declspec(align(16))__m128 *p_n = (__m128*)n; __declspec(align(16))__m128 *p

matmul function for vector with tensor multiplication in tensorflow

丶灬走出姿态 提交于 2019-12-25 00:05:21
问题 In general when we multiply a vector v of dimension 1*n with a tensor T of dimension m*n*k , we expect to get a matrix/tensor of dimension m*k / m*1*k . This means that our tensor has m slices of matrices with dimension n*k , and v is multiplied to each matrix and the resulting vectors are stacked together. In order to do this multiplication in tensorflow , I came up with the following formulation. I am just wondering if there is any built-in function that does this standard multiplication

MATLAB: element-wise multiplication of two matrices over one index?

假如想象 提交于 2019-12-10 19:49:37
问题 I'm trying to figure out if there's a native way of obtaining a certain kind of element-wise product of two matrices in Matlab. The product that I'm looking for takes two matrices, A and B say, and returns there product C , whose elements are given by C(i,j,k) = A(i,j)*B(j,k) Naturally, the number of columns of A is assumed be the same as the number of rows of B . Right now, I'm using the following for-loop (assuming size(A,2)==size(B,1) is true). First, I initialize C : C = zeros(size(A,1),

element by element matrix multiplication in Matlab

自古美人都是妖i 提交于 2019-12-01 14:00:28
So I have the following matrices: A = [1 2 3; 4 5 6]; B = [0.5 2 3]; I'm writing a function in MATLAB that will allow me to multiply a vector and a matrix by element as long as the number of elements in the vector matches the number of columns. In A there are 3 columns: 1 2 3 4 5 6 B also has 3 elements so this should work. I'm trying to produce the following output based on A and B : 0.5 4 9 2 10 18 My code is below. Does anyone know what I'm doing wrong? function C = lab11(mat, vec) C = zeros(2,3); [a, b] = size(mat); [c, d] = size(vec); for i = 1:a for k = 1:b for j = 1 C(i,k) = C(i,k) + A

element by element matrix multiplication in Matlab

谁说我不能喝 提交于 2019-12-01 13:01:09
问题 So I have the following matrices: A = [1 2 3; 4 5 6]; B = [0.5 2 3]; I'm writing a function in MATLAB that will allow me to multiply a vector and a matrix by element as long as the number of elements in the vector matches the number of columns. In A there are 3 columns: 1 2 3 4 5 6 B also has 3 elements so this should work. I'm trying to produce the following output based on A and B : 0.5 4 9 2 10 18 My code is below. Does anyone know what I'm doing wrong? function C = lab11(mat, vec) C =

Multiply permutations of two vectors in R

吃可爱长大的小学妹 提交于 2019-11-28 14:37:35
I've got two vectors of the length 4 and want a multiplication of the permutations of the vector: A=(a1,a2,a3,a4) B=(b1,b2,b3,b4) I want: a1*b1;a1*b2;a1*b3...a4*b4 as a list with known order or data.frame with row.names=A and colnames=B Use outer(A,B,'*') which will return a matrix x<-c(1:4) y<-c(10:14) outer(x,y,'*') returns [,1] [,2] [,3] [,4] [,5] [1,] 10 11 12 13 14 [2,] 20 22 24 26 28 [3,] 30 33 36 39 42 [4,] 40 44 48 52 56 and if you want the result in a list you then can do z<-outer(x,y,'*') z.list<-as.list(t(z)) head(z.list) returns [[1]] [1] 10 [[2]] [1] 11 [[3]] [1] 12 [[4]] [1] 13 [

Multiply permutations of two vectors in R

故事扮演 提交于 2019-11-27 19:39:15
问题 I've got two vectors of the length 4 and want a multiplication of the permutations of the vector: A=(a1,a2,a3,a4) B=(b1,b2,b3,b4) I want: a1*b1;a1*b2;a1*b3...a4*b4 as a list with known order or data.frame with row.names=A and colnames=B 回答1: Use outer(A,B,'*') which will return a matrix x<-c(1:4) y<-c(10:14) outer(x,y,'*') returns [,1] [,2] [,3] [,4] [,5] [1,] 10 11 12 13 14 [2,] 20 22 24 26 28 [3,] 30 33 36 39 42 [4,] 40 44 48 52 56 and if you want the result in a list you then can do z<