Returns a shape based on `self` with the given rank.

        This method promotes a completely unknown shape to one with a
        known rank.

        Args:
          rank: An integer.

        Returns:
          A shape that is at least as specific as `self` with the given rank.

        Raises:
          ValueError: If `self` does not represent a shape with the given `rank`.

def with_rank(self, rank):
        """Returns a shape based on `self` with the given rank.

        This method promotes a completely unknown shape to one with a
        known rank.

        Args:
          rank: An integer.

        Returns:
          A shape that is at least as specific as `self` with the given rank.

        Raises:
          ValueError: If `self` does not represent a shape with the given `rank`.
        """
        try:
            return self.merge_with(unknown_shape(ndims=rank))
        except ValueError:
            raise ValueError("Shape %s must have rank %d" % (self, rank))