rfho/utils.py
def dot(v1, v2, name='dot'):
    """
    Dot product (No idea why there isn't already in tensorflow...) and some partial extensions for matrix vector
    multiplication. Should ideally copy `np.dot` method.

    :param v1: first vector
    :param v2: second vector
    :return:
    """
    v1_shape = v1.get_shape().ndims
    v2_shape = v2.get_shape().ndims
    # print(v1_shape, v2_shape)
    if v1_shape > 1 and v2_shape > 1:
        return tf.matmul(v1, v2, name=name)
    elif v1_shape == 2 and v2_shape == 1:
        if v1.get_shape().as_list()[1] != 1:  # it is a true matrix
            return tf.reduce_sum(v1 * v2, reduction_indices=[1], name=name)
        else:
            raise NotImplementedError('This would be a multiplication column vector times row vector.. TODO')
    elif v1_shape == 1 and v2_shape == 2:  # fine for mat
        # this is a thing that is useful in DirectDoh
        res = tf.reduce_sum(v1 * tf.transpose(v2), reduction_indices=[1])
        if v2.get_shape().as_list()[1] == 1:
            return tf.identity(res[0], name=name)
        else:
            return tf.identity(res[0], name=name)
    elif v1_shape == 1 and v2_shape == 1:
        return tf.reduce_sum(v1 * v2, name=name)
    else:
        raise NotImplementedError()

    Dot product (No idea why there isn't already in tensorflow...) and some partial extensions for matrix vector
    multiplication. Should ideally copy `np.dot` method.

    :param v1: first vector
    :param v2: second vector
    :return:
    
Dot product (No idea why there isn't already in tensorflow...) and some partial extensions for matrix vector
multiplication. Should ideally copy `np.dot` method.
Dot product ( No idea why there isn ' t already in tensorflow ... ) and some partial extensions for matrix vector multiplication . Should ideally copy ` np . dot ` method .
def dot(v1, v2, name='dot'):
    v1_shape = v1.get_shape().ndims
    v2_shape = v2.get_shape().ndims
    if v1_shape > 1 and v2_shape > 1:
        return tf.matmul(v1, v2, name=name)
    elif v1_shape == 2 and v2_shape == 1:
        if v1.get_shape().as_list()[1] != 1:  
            return tf.reduce_sum(v1 * v2, reduction_indices=[1], name=name)
        else:
            raise NotImplementedError('This would be a multiplication column vector times row vector.. TODO')
    elif v1_shape == 1 and v2_shape == 2:  
        res = tf.reduce_sum(v1 * tf.transpose(v2), reduction_indices=[1])
        if v2.get_shape().as_list()[1] == 1:
            return tf.identity(res[0], name=name)
        else:
            return tf.identity(res[0], name=name)
    elif v1_shape == 1 and v2_shape == 1:
        return tf.reduce_sum(v1 * v2, name=name)
    else:
        raise NotImplementedError()
def dot ( v1 , v2 , name = 'dot' ) : v1_shape = v1 . get_shape ( ) . ndims v2_shape = v2 . get_shape ( ) . ndims if v1_shape > 1 and v2_shape > 1 : return tf . matmul ( v1 , v2 , name = name ) elif v1_shape == 2 and v2_shape == 1 : if v1 . get_shape ( ) . as_list ( ) [ 1 ] != 1 : return tf . reduce_sum ( v1 * v2 , reduction_indices = [ 1 ] , name = name ) else : raise NotImplementedError ( 'This would be a multiplication column vector times row vector.. TODO' ) elif v1_shape == 1 and v2_shape == 2 : res = tf . reduce_sum ( v1 * tf . transpose ( v2 ) , reduction_indices = [ 1 ] ) if v2 . get_shape ( ) . as_list ( ) [ 1 ] == 1 : return tf . identity ( res [ 0 ] , name = name ) else : return tf . identity ( res [ 0 ] , name = name ) elif v1_shape == 1 and v2_shape == 1 : return tf . reduce_sum ( v1 * v2 , name = name ) else : raise NotImplementedError ( )
Dot product (No idea why there isn't already in tensorflow...) and some partial extensions for matrix vector
multiplication.
Dot product ( No idea why there isn ' t already in tensorflow ... ) and some partial extensions for matrix vector multiplication .
"""
    Dot product (No idea why there isn't already in tensorflow...) and some partial extensions for matrix vector
    multiplication. Should ideally copy `np.dot` method.

    :param v1: first vector
    :param v2: second vector
    :return:
    """ # print(v1_shape, v2_shape) # it is a true matrix # fine for mat # this is a thing that is useful in DirectDoh
None
v1
None
v2
None
name