Questions tagged [matmul]

13 questions
2
votes
1 answer

issue with precision of numpy matmul ('at'/@ operator)

I traced a bug in a larger program back to this problem. I am getting larger than expected errors for changing the order of multiplicative operations using numpy. Here is a self-contained example (the actual code at the end is short, but I copy in…
1
vote
0 answers

Speeding up a large number of small matrix multiplications

I have a large number of 2x2 matrices that I need multiplied together. I can initiate the general shape of the problem as import numpy as np import time A_dim = 6*6 B_dim = 2**8 C_dim = B_dim A = np.random.rand(A_dim,A_dim,2,2) B =…
1
vote
0 answers

faster way of sparse to array multiplication

I m trying to multiply 300000 x 300000 sparse matrix with a single array of 300000, and its taking 7-8 seconds by matmul numpy. NumPy matmul is what I have used. Is there any other option?
1
vote
1 answer

How to prevent overflow in numpy matmul?

import numpy as np x1 = np.arange(0,63, dtype=np.int8).reshape(63,1) x2 = np.arange(0,63, dtype=np.int8).reshape(1,63) o = np.zeros((63,63), dtype=np.int16) o = np.matmul(x1,x2) print(o) Output: [[ 0 0 0 ... 0 0 0] [ 0 1 …
1
vote
1 answer

Einsum for shapes of different sizes or ranks

I have two PyTorch tensors. One is rank three and the other is rank four. Is there a way to get it so that it produce the rank and shape of the first tensor? For instance in this cross-attention bit: q = torch.linspace(1, 192, steps=192) q =…
MScottWaller
  • 3,321
  • 2
  • 24
  • 47
0
votes
1 answer

How to do matmul on 3D and 4D matrices?

I have an array a whose size is torch.Size([330, 330, 36]) The original data structure is [330, 6, 330, 6] The meaning is: I have 330 atoms in the system, each atom has 6 orbitals I want to know the interactions between all atoms and all orbitals. I…
0
votes
0 answers

tf.matmul vs tf.einsum for constructing density matrices from a set of Cholesky decomposed matrices

I am trying to construct a density matrix of shape 256x256 from a set of T matrices. These T matrices are all Cholesky-decomposed matrices. But I am not sure if the code is right or my approach is right; one of the reasons is that when I change from…
Dimitri
  • 109
  • 1
  • 14
0
votes
1 answer

CUDA error: CUBLAS_STATUS_INVALID_VALUE error when torch.matmul

I am working on text classification task using BERT model. I have fine-tuned my model and I want load and inference model in various machines. Most of the time it works just fine, but on one specific environment I am keep getting CUDA error:…
0
votes
2 answers

Why is the result of matrix multiply in torch so different when i roll the matrix?

Although there is a problem with the accuracy of floating-point multiplication, the gap is slightly larger. And it is also related to the roll step. x = torch.rand((1, 5)) y = torch.rand((5, 1)) print("%.10f"%torch.matmul(x,y)) >>>…
opflow
  • 3
  • 1
0
votes
2 answers

Matrix multiplication while subsetting elements from matrices and storing in a new matrix

I am attempting a numpy.matmul call using as variables Matrix A of dimensions (p, t, q) Matrix B of dimensions (r, t). A categories vector of shape r and p categories, used to take slices of B and define the index of A do use. The multiplications…
ilibarra
  • 57
  • 7
0
votes
0 answers

ValueError: matmul: Input operand 0 does not have enough dimensions (has 0, gufunc core with signature (n?,k),(k,m?)->(n?,m?) requires 1)

I am new to the box and the A.I program, and I don't know how to solve this problem: !rm -f winequality-red.csv winequality-white.csv !wget https://archive.ics.uci.edu/ml/machine-learning-databases/wine-quality/winequality-red.csv !wget…
-1
votes
1 answer

Matrix vector moltiplication: how to return np.shape (d,)

Here is an example code in Python: import numpy as np X = np.matrix([[0, 1], [1, 0]]) e1 = np.array([1, 1]) state = X @ e1 print(X @ state) The matmul operand when doing a matrix vector multiplication returns the vector in the shape (2,1) instead…
-1
votes
2 answers

How can I solve a system of x*y = c, where x and c are vectors, and y is a matrix in python?

I have a problem where I have a vector "c" which I know its values and it size is 100, and I want my code to find a vector "x" of size 30 and a matrix "y" of size (30,100), so that x*y= c and the norm of "x" and "y" are minimal. I want to know the…