import tensorflow as tf

       do not have a Euclidean norm greater than maxnorm. Rows that exceed 
       it are scaled to length.
    
    Args:
        var_matrix: 2D mutable tensor (Variable) to operate on
        indices: 1D tensor with the row indices to constrain
        maxnorm: the maximum Euclidean norm

    Returns:
        An operation that will update var_matrix when run in a Session
    '''
    selected_rows = tf.nn.embedding_lookup(var_matrix, indices)
    row_norms = tf.sqrt(tf.reduce_sum(tf.square(selected_rows), 1))
    scaling = maxnorm / tf.maximum(row_norms, maxnorm)
    scaled = selected_rows * tf.expand_dims(scaling, 1)
    return tf.scatter_update(var_matrix, indices, scaled)


def dense_maxnorm_update(var_matrix, maxnorm=1.0):
    '''Dense update operation that ensures all rows in var_matrix 
       do not have a Euclidean norm greater than maxnorm. Rows that exceed 
       it are scaled to length.
    
    Args:
        var_matrix: 2D mutable tensor (Variable) to operate on
        maxnorm: the maximum Euclidean norm
