import tensorflow as tf

    weights = np.random.normal(scale=np.sqrt(1.0/shape[0]), size=shape).astype('f')
    return safe_get(name, list(shape), initializer=tf.constant_initializer(weights), dtype=tf.float32)

def init_conv_weights_snn(shape, name=None):
    weights = np.random.normal(scale=np.sqrt(1.0/(shape[0]*shape[1]*shape[2])), size=shape).astype('f')
    return safe_get(name, list(shape), initializer=tf.constant_initializer(weights), dtype=tf.float32)

def batched_matrix_vector_multiply(vector, matrix):
    """ computes x^T A in mini-batches. """
    vector_batch_as_matricies = tf.expand_dims(vector, [1])
    mult_result = tf.matmul(vector_batch_as_matricies, matrix)
    squeezed_result = tf.squeeze(mult_result, [1])
    return squeezed_result

def euclidean_loss_layer(a, b, multiplier=100.0, use_l1=False, eps=0.01):
    """ Math:  out = (action - mlp_out)'*precision*(action-mlp_out)
                    = (u-uhat)'*A*(u-uhat)"""
    multiplier = tf.constant(multiplier, dtype='float') #for bc #10000
    uP =a*multiplier-b*multiplier
    if use_l1:
        return tf.reduce_mean(eps*tf.square(uP) + tf.abs(uP))
    return tf.reduce_mean(tf.square(uP))
