Do matmul between lists

Hi, I am looking for a function could do this:

a=torch.rand(1)
b=torch.rand(1)
c=torch.rand(2,3)
d=torch.rand(3,4)

Func( [a,c], [b,d]) = [matmul(a,b), matmul(c,d)]

It could be done by iteration, but takes a lot time for long list :frowning: .
Is there some func can handle this ?

You can use list comprehension and a zip statement

import torch
 
a=torch.rand(1)
b=torch.rand(1)
c=torch.rand(2,3)
d=torch.rand(3,4)
 
def func(list1, list2):
  return [a@b for a, b in zip(list1, list2)]

list1=[a,c]
list2=[b,d]
 
func(list1, list2)
"""
returns [tensor(0.0130), tensor([[0.6270, 1.0470, 0.2362, 0.7666],
        [0.9061, 1.3999, 0.2975, 1.0312]])]
"""