# -*- coding: utf-8 -*-
"""
Created on Wed Jul 22 14:36:48 2020

@author: matth
"""

import autograd.numpy as np
#%% Kernel operations

# Returns the norm of the pairwise difference
def norm_matrix(matrix_1, matrix_2):
    norm_square_1 = np.sum(np.square(matrix_1), axis = 1)
    norm_square_1 = np.reshape(norm_square_1, (-1,1))
    
    norm_square_2 = np.sum(np.square(matrix_2), axis = 1)
    norm_square_2 = np.reshape(norm_square_2, (-1,1))
    
    d1=matrix_1.shape
    d2=matrix_2.shape

    if d1[1]!=d2[1]:
        matrix_1=np.transpose(matrix_1)
    
    inner_matrix = np.matmul(matrix_1, np.transpose(matrix_2))
    
    norm_diff = -2 * inner_matrix + norm_square_1 + np.transpose(norm_square_2)
    
    return norm_diff

# Returns the pairwise inner product
def inner_matrix(matrix_1, matrix_2):
    d1=matrix_1.shape
    d2=matrix_2.shape

    if d1[1]!=d2[1]:
        matrix_1=np.transpose(matrix_1)
    return np.matmul(matrix_1, np.transpose(matrix_2))


if __name__ == '__main__':
    print('This is the matrix operations file')
[((14, 20, 14, 53), 'autograd.numpy.reshape', 'np.reshape', ({(14, 31, 14, 44): 'norm_square_1', (14, 46, 14, 52): '(-1, 1)'}, {}), '(norm_square_1, (-1, 1))', True, 'import autograd.numpy as np\n'), ((17, 20, 17, 53), 'autograd.numpy.reshape', 'np.reshape', ({(17, 31, 17, 44): 'norm_square_2', (17, 46, 17, 52): '(-1, 1)'}, {}), '(norm_square_2, (-1, 1))', True, 'import autograd.numpy as np\n'), ((13, 27, 13, 46), 'autograd.numpy.square', 'np.square', ({(13, 37, 13, 45): 'matrix_1'}, {}), '(matrix_1)', True, 'import autograd.numpy as np\n'), ((16, 27, 16, 46), 'autograd.numpy.square', 'np.square', ({(16, 37, 16, 45): 'matrix_2'}, {}), '(matrix_2)', True, 'import autograd.numpy as np\n'), ((23, 17, 23, 39), 'autograd.numpy.transpose', 'np.transpose', ({(23, 30, 23, 38): 'matrix_1'}, {}), '(matrix_1)', True, 'import autograd.numpy as np\n'), ((25, 39, 25, 61), 'autograd.numpy.transpose', 'np.transpose', ({(25, 52, 25, 60): 'matrix_2'}, {}), '(matrix_2)', True, 'import autograd.numpy as np\n'), ((27, 52, 27, 79), 'autograd.numpy.transpose', 'np.transpose', ({(27, 65, 27, 78): 'norm_square_2'}, {}), '(norm_square_2)', True, 'import autograd.numpy as np\n'), ((37, 17, 37, 39), 'autograd.numpy.transpose', 'np.transpose', ({(37, 30, 37, 38): 'matrix_1'}, {}), '(matrix_1)', True, 'import autograd.numpy as np\n'), ((38, 31, 38, 53), 'autograd.numpy.transpose', 'np.transpose', ({(38, 44, 38, 52): 'matrix_2'}, {}), '(matrix_2)', True, 'import autograd.numpy as np\n')]