def _mult_diag_matrix(D, mtx, on_right=False):
    """ Multiply diagonal matrix D to mtx
    Args:
      D (N ndarray) - diagonal matrix
      mtx (ndarray) - matrix to multiply
      on_right (bool) - whether to return D * mtx (False) or mtx * D (True)
    """
    if not on_right:
        return (D*mtx.T).T
    else:
        return D*mtx