Passed
Pull Request — master (#1)
by Konstantinos
01:11
created

artificial_artwork.nst_math   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 7
dl 0
loc 29
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A gram_matrix() 0 19 1
1
from typing import Union
2
from numpy.typing import NDArray
3
import tensorflow as tf
4
5
6
# Define type alias
7
VolumeType = Union[NDArray, tf.python.framework.ops.Tensor]
8
9
10
def gram_matrix(A: VolumeType) -> VolumeType:
11
    """Compute the Gram matrix of input 2D matrix A.
12
13
    In Linear Algebra the Gram matrix G of a set of vectors (u_1, u_2, .. , u_n)
14
    is the matrix of dot products, whose entries are:
15
    
16
    G_{ij} = u^T_i * u_j = numpy.dot(u_i, u_j)
17
    OR
18
    GA = A * A^T
19
20
    Uses tenforflow to compute the Gram matrix of the input 2D matrix.
21
22
    Args:
23
        A (type): matrix of shape (n_C, n_H * n_W)
24
    
25
    Returns:
26
        (tf.tensor): Gram matrix of A, of shape (n_C, n_C)
27
    """
28
    return tf.matmul(A, tf.transpose(A))
29