-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAuxArrayOps.py
44 lines (37 loc) · 1.2 KB
/
AuxArrayOps.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#####################################################################
#
# AuxArrayOps:
# Contains functions to perform vectorized tensor-wise operations.
# Requires the list of tensors to be cast as a 3D array with the
# third dimension spanning the number of tensors in the list.
#
# Siddharth Maddali
# Argonne National Laboratory
# February 2020
#
#####################################################################
import numpy as np
import functools as ftools
def multimatmul( a, b ):
"""
multimatmul( a, b ):
Returns the elementwise matrix product of matrix lists `a` and `b`.
This is completely vectorized code that uses numpy's in-built
matmul and rollaxis functions.
Inputs:
`a`: 3D array of size ( D1, M, N ) representing a list of N
matrices, each of size D1xM.
`b`: 3D array of size ( M, D2, N ) representing a list of N
matrices, each of size MxD2
Outputs:
A 3D array of size (D1, D2, N ) representing a list of N
matrices of size D1xD2.
"""
return np.rollaxis(
np.matmul(
np.rollaxis( a, 2 ),
np.rollaxis( b, 2 )
),
0, 3
)