def METHOD_NAME(d, validate_args, name=None):
  """Convert a vector size to a matrix size."""
  if isinstance(d, (float, int, np.generic, np.ndarray)):
    n = (-1 + np.sqrt(1 + 8 * d)) / 2.
    if float(int(n)) != n:
      raise ValueError("Vector length is not a triangular number.")
    return int(n)
  else:
    with ops.name_scope(name, "vector_size_to_square_matrix_size", [d]) as name:
      n = (-1. + math_ops.sqrt(1 + 8. * math_ops.cast(d, dtypes.float32))) / 2.
      if validate_args:
        with ops.control_dependencies([
            check_ops.assert_equal(
                math_ops.cast(math_ops.cast(n, dtypes.int32), dtypes.float32),
                n,
                message="Vector length is not a triangular number")
        ]):
          n = array_ops.identity(n)
      return math_ops.cast(n, d.dtype)