def squareform(X, force="<STR_LIT>", checks=True):
X = _convert_to_double(np.asarray(X, order='<STR_LIT:c>'))<EOL>if not np.issubsctype(X, np.double):<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT>s = X.shape<EOL>if force.lower() == '<STR_LIT>':<EOL><INDENT>if len(s) != <NUM_LIT:1>:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT><DEDENT>elif force.lower() == '<STR_LIT>':<EOL><INDENT>if len(s) != <NUM_LIT:2>:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT><DEDENT>if len(s) == <NUM_LIT:1>:<EOL><INDENT>if X.shape[<NUM_LIT:0>] == <NUM_LIT:0>:<EOL><INDENT>return np.zeros((<NUM_LIT:1>, <NUM_LIT:1>), dtype=np.double)<EOL><DEDENT>d = int(np.ceil(np.sqrt(X.shape[<NUM_LIT:0>] * <NUM_LIT:2>)))<EOL>if d * (d - <NUM_LIT:1>) / <NUM_LIT:2> != int(s[<NUM_LIT:0>]):<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>M = np.zeros((d, d), dtype=np.double)<EOL>[X] = _copy_arrays_if_base_present([X])<EOL>_distance_wrap.to_squareform_from_vector_wrap(M, X)<EOL>M = M + M.transpose()<EOL>return M<EOL><DEDENT>elif len(s) == <NUM_LIT:2>:<EOL><INDENT>if s[<NUM_LIT:0>] != s[<NUM_LIT:1>]:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if checks:<EOL><INDENT>is_valid_dm(X, throw=True, name='<STR_LIT:X>')<EOL><DEDENT>d = s[<NUM_LIT:0>]<EOL>if d <= <NUM_LIT:1>:<EOL><INDENT>return np.array([], dtype=np.double)<EOL><DEDENT>v = np.zeros((d * (d - <NUM_LIT:1>)) // <NUM_LIT:2>, dtype=np.double)<EOL>[X] = _copy_arrays_if_base_present([X])<EOL>_distance_wrap.to_vector_from_squareform_wrap(X, v)<EOL>return v<EOL><DEDENT>else:<EOL><INDENT>raise ValueError(('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>') % len(s))<EOL><DEDENT>
Converts a vector-form distance vector to a square-form distance
matrix, and vice-versa.

Parameters
----------
X : ndarray
    Either a condensed or redundant distance matrix.
force : str, optional
    As with MATLAB(TM), if force is equal to 'tovector' or 'tomatrix',
    the input will be treated as a distance matrix or distance vector
    respectively.
checks : bool, optional
    If `checks` is set to False, no checks will be made for matrix
    symmetry nor zero diagonals. This is useful if it is known that
    ``X - X.T1`` is small and ``diag(X)`` is close to zero.
    These values are ignored any way so they do not disrupt the
    squareform transformation.

Returns
-------
Y : ndarray
    If a condensed distance matrix is passed, a redundant one is
    returned, or if a redundant one is passed, a condensed distance
    matrix is returned.

Notes
-----

1. v = squareform(X)

   Given a square d-by-d symmetric distance matrix X,
   ``v=squareform(X)`` returns a ``d * (d-1) / 2`` (or
   `${n \\choose 2}$`) sized vector v.

  v[{n \\choose 2}-{n-i \\choose 2} + (j-i-1)] is the distance
  between points i and j. If X is non-square or asymmetric, an error
  is returned.

2. X = squareform(v)

  Given a d*d(-1)/2 sized v for some integer d>=2 encoding distances
  as described, X=squareform(v) returns a d by d distance matrix X. The
  X[i, j] and X[j, i] values are set to
  v[{n \\choose 2}-{n-i \\choose 2} + (j-u-1)] and all
  diagonal elements are zero.