Questions tagged [matrix-multiplication]

Questions related to matrix multiplication, especially implementation. Mathematical questions should consider the [linear-algebra] tag.

Filter by
Sorted by
Tagged with
1 vote
0 answers
15 views

How can I most efficiently multiply two matrixes together when I know it will produce a symmetric matrix?

I'm working with a number of matrix libraries (cuBLAS, OpenBLAS, and MKL BLAS) and am wondering if, in any of these matrix libraries, there exist optimized matrix multiplication functions for when the ...
meisel's user avatar
  • 2,215
0 votes
0 answers
17 views

How to estimate the complexity of a particular program

Problem: Assume that the coefficients of A and B take 𝒪(1) bits in memory, proving that, in the worst case, the coefficients of the result of the sequence of products problem use 𝛩(𝑛) bits. def ...
Tung Nguyen's user avatar
0 votes
2 answers
57 views

Multiplying without a for loop in R

I am working on a project and I need my function to be as fast as possible since I have millions of datapoints slowing down my calculations. I feel my problem is quite simple, but I haven't been able ...
Mr.Anugar's user avatar
-3 votes
0 answers
53 views

Write a Python function that takes two matrices as input and returns their product if the matrices can be multiplied [closed]

To multiply two matrices, the number of columns in the first matrix must be equal to the number of rows in the second matrix. If this condition is met, the resulting matrix will have dimensions equal ...
Mahendra Singh Barod's user avatar
0 votes
0 answers
7 views

cuSparse API cusparseSpGEMM to get row_offsets and column_indices

I want to calculate C = A.transpose()*A in cuda, A is sparse matrix,I know the API cusparseSpGEMM can do it and I test a simple demo successfully. But in my project,I need to get row_offsets and ...
lhy007's user avatar
  • 1
1 vote
1 answer
65 views

What does it mean that matrix multiplication is applied in reverse? [duplicate]

I don't understand this, this is from https://learnopengl.com/Getting-started/Transformations tutorial and it explains that while in the code we first translate and then rotate, rotate actually ...
Chris's user avatar
  • 35
-1 votes
0 answers
20 views

Numpy dot function failing even though dimensions align

I'm trying to build basic machine learning algorithms (the algorithm is not mine but class material, but I understand what this does). I require matrix multiplication in a function to do this. I'm ...
wuler_ninja's user avatar
0 votes
0 answers
8 views

How to improve the precision of matrix calculation in Matlab or Python?

Now, I have a matrix S, and it satisfies the recursion relation: S_{m,n}=(1+|α|^2)S_{m-1,n-1}+(m-1)(n-1)S_{m-2,n-2}+α(m-1)S_{m-2,n-1}+α*(n-1)S_{m-1,n-2} S_{0,n}=(α*)^n and S_{n,0}=α^n Obviously, when |...
Young Q's user avatar
  • 31
0 votes
1 answer
121 views

How to speed up dense matrix multiplication?

I want to speed up the mutiplication blow: And here is the code that I need to improve: void multiply(int size, int **matA, int **matB, int ** matC) { for(int i=0;i<size;i++) { for(int ...
Z.Lun's user avatar
  • 265
1 vote
1 answer
54 views

Different results between Wolfram and Numpy when I multiply 3 matrices?

Firstly, I am sure that the Wolfram answer is the correct one because the two sandwich matrices is the eigen vecors matrices so the answer has to to be in the form of eigne bases. so, the question is, ...
Mostafa Atallah's user avatar
-1 votes
3 answers
174 views

How to calculate nth term of higher order GENERALIZED Fibonacci sequence using matrix exponentiation in C++? [duplicate]

I am interested in calculating the nth term of higher order Fibonacci sequence in C++, using matrix exponentiation, while allowing n to be reasonably large (in the range of hundreds). The sequences I ...
Ξένη Γήινος's user avatar
1 vote
1 answer
94 views

Dimension problem: Matrix multip. of ith entry in a vector multiplied as a scalar across part of matrix that is the ith entry in a list of matricies

I have a group of .csv files that contain matrices of identical size where the first row and first column are axis labels (they're fluorescence Excitation Emission Matrices, if anyone's familiar) that ...
carbonmire's user avatar
0 votes
0 answers
8 views

Correct data structure for simple Markov Decision Process

I want to implement a Markov Decision Process for the robot example. I used the numpy arrays to store the transition probabilities matrices per action: e.g. P[:,:,2] = np.array([ [0.9, 0, 0, 0, 0.1, 0,...
Apostolossr13's user avatar
1 vote
1 answer
73 views

Armadillo C++ matrix multiplication with in-place assignment to submatrix

Maybe it's a trivial question, but suppose I have two matrices A, B of dimension N x s: arma::mat A(N, s, arma::fill::randu) arma::mat B(N, s, arma::fill::randu) and I need to write a product of ...
Qant123's user avatar
  • 153
0 votes
2 answers
45 views

Why does computation on contiguous slices of tensors take less time than doing it directly on the tensor?

I have a test, which performs an element wise multiplication operation on a large tensor and stores the result back into it, on an identical sliced view of it and on a noncontiguous sliced chipped ...
Yes's user avatar
  • 331
1 vote
1 answer
44 views

Defining an infinite family of classes "MatrixMxN" in C#

Suppose I was writing a linear algebra library in C#, and I wanted to implement matrix multiplication. Of course, two matrices A and B can only be multiplied to form AB if A has as many columns as B ...
ummg's user avatar
  • 249
2 votes
1 answer
101 views

Masking individual rows for CSR SpMV in RISC-V RVV 0.7.1

EDIT: I have reformulated my question into something more productive, and will provide an answer below. The old version of this question is below still. I am implementing an optimized SpMV kernel for ...
Alex's user avatar
  • 163
0 votes
1 answer
96 views

Optimizing Matrix multiplication using Go routines without inbuilt functions

I have the below code for matrix multiplication using Go Routines func main() { var wg sync.WaitGroup var col = 100 var row = 150 var randMatrixA [][]int var randMatrixB [][]int ...
Subin Suthan's user avatar
0 votes
0 answers
34 views

Why this code that uses dynamically allocated shared memory in CUDA does not work? [duplicate]

The next kernel performs the multiplication of the matrices matA and matB and stores the result in the matrix matC (the size of all matrices is N) using a shared memory region with dimensions tiledim ...
Athanasios Margaris's user avatar
0 votes
1 answer
40 views

Attempt to parallelize despite the data dependencies

I am trying to parallelize matrix multiplication. I came across a Fox algorithm which can break the whole thing into 3 step. You can look up the algorithm. I have attached an image.enter image ...
pranavs1997's user avatar
0 votes
0 answers
39 views

How to convert coordinates from one camera space to another camera space

I'm developing render engine in WebGL and JavaScript. No ThreeJS or other libraries used. What I am trying to achieve: In a fragment shader, I have fragment XYZ coordinates in camera #1 space. I need ...
Siniša's user avatar
  • 3,028
0 votes
1 answer
89 views

Python Matrix Multiplication By Flattening Matrices

I have two matrices. One of them has size (128, 3, 32, 49) and the other one is (128, 3, 49, 32). In normal version, matrix multiplication of these matrices has size (128,3,32,32). I want to pack one ...
DOLFIN's user avatar
  • 1
0 votes
2 answers
147 views

How to perform matrix multiplication in R faster than %*%?

This problem occured in my R script. I want to multiply a 1000by1000 matrix by a 1000by1 matrix (vector), so that the output is a 1000by1 matrix. The 1000by1000 matrix has a unique property. Above the ...
matehorvath's user avatar
1 vote
1 answer
39 views

How to implement tensor multiplication of a sparse matrix with a 3D tensor in TensorFlow2.0?

I have a sparse matrix A of shape (60400, 32600) and a 3D tensor B of shape (32600, 60400, 64). What I want to do is to multiply A and B to get a tensor C of shape (60400, 60400, 64), then generate ...
LLLLLL's user avatar
  • 13
0 votes
0 answers
15 views

Does Loop tiling cause negative effects when the input dataset is small? If it does, why?

I'm currently learning about dnn and is working on a lab assignment where different optimization techniques of matrix multiplication are required to be implemented. I have generated the code of loop ...
cyj's user avatar
  • 1
0 votes
0 answers
65 views

Comparison of two methods that multiply two sparse matrices (C++)

I am studying the class "SparseMatrix" in the book "Fundamentals of Data Structures in C++" (Horowitz, Sahni, Mehta). While I analyze the Sparsematrix::Multiply() function, I made ...
goomseo's user avatar
2 votes
4 answers
88 views

Matrix multiplication of numpy ndarrays

I have a two numpy arrays a, B like this. >> a [1 2 3] >> type(a) <class 'numpy.ndarray'> >> B [[1 2 3] [2 2 7] [3 4 6]] >> type(B) <class 'numpy.ndarray'> I ...
Mike's user avatar
  • 33
0 votes
1 answer
77 views

Why do I get a segmentation fault problem in this program when the matrix dimension is too large (in ifort)?

I'm making basic linear algebra computations with matrices and vectors in Fortran. I have changed compiler from gfortran to ifort and I've found that when my matrices get too large (specifically when ...
Another User's user avatar
0 votes
0 answers
29 views

Matrix Representation of Convolution in Neural Networks: Challenges in Backpropagation and Parameter Updates

In neural networks, convolution operations are typically performed using a filter (or kernel) that slides over the input data and computes dot products at each location to produce the output feature ...
Blade's user avatar
  • 1,024
0 votes
1 answer
123 views

Is this possible to reduce O(N^3) time complexity of submatrix additions in N*N Matrix? [duplicate]

There is a N * N Matrix M. and It is initialized with random values. And there are input Row1, Row2, Col1, Col2, Value. and there is a pseudo code below. for start = 1 to N: input(Row1, Row2, ...
C and Python lover's user avatar
1 vote
2 answers
70 views

Product of arrays (einsum) of 3D arrays containing only -1 or +1

Let X be an array of shape (M, k, g) and Q be an array of shape (m, k, g), where m, M, k, and g can be "very large". Suppose the entries of X and Y are either -1 or plus +1. I'm interested ...
dohmatob's user avatar
  • 299
2 votes
2 answers
45 views

Creating a data frame by querying two other related data frames

I want to create a data frame that calculates abundances of traits from two other related data frames but don’t know what code would give me the desired output. The first data frame, species abundance,...
Sean's user avatar
  • 23
1 vote
1 answer
49 views

Calculating Variance over multiple axes simultaneously

I am trying to understand how varaince over multiple axes works and can it be acheived by using individual operations. Let us we have a input 3d matrix with shape (2,2,3) and we are interested in ...
Gouse73's user avatar
  • 35
-2 votes
3 answers
82 views

Why gives my matrix multiplication between 2d and 1d array this result?

Example: import numpy as np x = np.array([[1., 2., 3.], [4., 5., 6.]]) y = np.ones(3) np.dot(x , y) Result: array([ 6., 15.]) How is this possible when I have a matrix of (2x3) by (1x3)? It should ...
Mostafa Hosseini's user avatar
3 votes
1 answer
185 views

C++ OpenMP doesn't speed up matrix multiplication

I have written a simple matrix multiplication program in C++, and it works. I am just a beginner in C++ and I have managed to make it work. What baffled me was that it was much slower than NumPy. I ...
Ξένη Γήινος's user avatar
1 vote
0 answers
62 views

How to make matrix multiplication with cython + scipy.linalg.cython_blas as fast as numpy.dot?

import numpy as np I want to multiply two matrices a = np.random.randn(n_dim, n_dim) + 1j * np.random.randn(n_dim, n_dim) b = np.random.randn(n_dim, n_dim) + 1j * np.random.randn(n_dim, n_dim) My ...
Maryks's user avatar
  • 11
0 votes
0 answers
47 views

How to write a transfer matrix for N layers?

We have the matrices G_r and P_r, where r is an index (integer, from 0 to m) meaning one of the N layers of an experimental setup, while n and \delta are variables to be fixed (\delta=n\omega_r (x_(r+...
user22467059's user avatar
1 vote
1 answer
30 views

DataFrame's as matrices in matrix product

Suppose I have the following two DataFrame's in Pandas. import Pandas as pd data1 = {'col1': [1, 2, 3], 'col2': [4, 5, 6]} df1 = pd.DataFrame(data1) data2 = {'col3': [2,3]} df2 = pd.DataFrame(data2) ...
Hans's user avatar
  • 1,299
2 votes
1 answer
42 views

What is wrong with this matrix multiplication in python

In the below code (Jupiter notebook), output is given wrong, how to correct the code? import numpy as np A = [1,22,231,1540] B = [[-1,1,0],[1,-1,1],[0,6,0],[0,6,0]] C = [[113401201],[10649],[1]] ...
Pruthviraj's user avatar
0 votes
1 answer
48 views

Eigen3: Map MatrixXd to multiplication with Matrix4d

Using eigen3 to multiply multiple Vector3d, laid out consecutively, by a Matrix4d. Obviously, I have an issue with the differing size of the matrices. To solve this, I added the w part on disk to ...
Kroma's user avatar
  • 1,131
-6 votes
1 answer
71 views

Can anyone find the error in this code, the output file is not showing the contents [closed]

#include <stdio.h> int main() { int r1, r2, c1, c2; printf("Enter number of rows and colums for mat1-"); //matrix1// scanf("%d %d", &r1, &c1); int m1[r1][c1]; ...
Ritam26's user avatar
0 votes
0 answers
28 views

Matrix Multiplication in cvxpy

I want to include a constraint in cvxpy where 2 consecutive matrix multiplications need to be done. However it keeps saying I have a DCP error. There seems to be something wrong with the way I am ...
viethaihp291's user avatar
1 vote
2 answers
105 views

Parallely multiply N matrices in pytorch

I have a list of L matrices A_1, A_2, ... of size N x N. I would like to calculate the product A_1 @ A_2 @ ... A_L. I can calculate this value by iteratively calculating products using torch.matmul. ...
Zeeshan ahmed's user avatar
-1 votes
1 answer
82 views

Can you help me find the bug in the CUDA Kernel?

First I wrote the following listing which multiplies two matrices. A =B= [[1 2 3 4], [5 6 7 8], [9 10 11 12], [13 14 15 16]] A*B = [[90 100 110 120], [202 228 254 280], ...
user366312's user avatar
  • 16.8k
1 vote
0 answers
65 views

Different matrix multiplication result in MATLAB and Python leads different eigenvectors

I am trying to convert my MATLAB code to Python. I have to multiply two matrices and calculate the eigenvector and eigenvalues of the multiplication result. Here are the two matrices P = [0....
galib's user avatar
  • 93
0 votes
1 answer
15 views

which mode is better when optimize matrix mul vector with mpi? size>6000

normally when dealing with matrix a[size][size] mul vector b[size], nump = the number of processors. which way below is better? case 1: Divide matrix A into "nump" parts, each with "...
lazyyy's user avatar
  • 1
0 votes
0 answers
62 views

Batch matmul sparse matrices with a dense vector

I have a 3-dimensional tensor (n x p x m) which consists of m number of unique (n x p) sparse matrices I want to batch multiply to a single dense vector (n,). Prior to using sparse matrices, I had ...
Eppicurt's user avatar
  • 173
-2 votes
1 answer
119 views

How does the tiled multiplication of two matrices work?

My teacher wrote: Implement a CUDA kernel for matrix products as outer product vectors. In this version, each block of K threads counts a square piece of the result matrix of size KxK by implementing ...
user366312's user avatar
  • 16.8k
-3 votes
1 answer
62 views

Problem claiming my matrices are incompatible with each other for matrix multiplication but are both the same length

I am calling my function: function [h,y,e] = f_adap(x,d,h0,mu) h=h0; P=length(h); N=length(x); y=zeros(1,N);e=y; rP = 0:-1:-P+1; for k=P:N xx=x(k+rP); disp(length(h'...
A.wilson's user avatar
0 votes
0 answers
122 views

MVP matrix multiplication on WebGPU

About the order of MVP matrices multiplications for WebGPU/WGSL. (The issue may be the same for OpenGL/WebGL) In gl-matrix library mat4.muptiply is defined by the code in the section "gl-matrix ...
Omori's user avatar
  • 43

1
2 3 4 5
59