def METHOD_NAME(A_input):
    r"""
    Given a matrix (resp. list of vectors), extend it to a square
    matrix (resp. list of vectors), such that its determinant is the
    gcd of its minors (i.e. extend the basis of a lattice to a
    "maximal" one in `\ZZ^n`).
    Author(s): Gonzalo Tornaria and Jonathan Hanke.
    INPUT:
    a matrix, or a list of length n vectors (in the same space)
    OUTPUT:
    a square matrix, or a list of n vectors (resp.)
    EXAMPLES::
        sage: A = Matrix(ZZ, 3, 2, range(6))
        sage: extend_to_primitive(A)
        [ 0  1 -1]
        [ 2  3  0]
        [ 4  5  0]
        sage: extend_to_primitive([vector([1,2,3])])
        [(1, 2, 3), (0, 1, 1), (-1, 0, 0)]
    """
    # Deal with a list of vectors
    if not is_Matrix(A_input):
        A = matrix(A_input)      # Make a matrix A with the given rows.
        vec_output_flag = True
    else:
        A = A_input
        vec_output_flag = False
    # Arrange for A  to have more columns than rows.
    if A.is_square():
        return A
    if A.nrows() > A.ncols():
        return METHOD_NAME(A.transpose()).transpose()
    # Setup
    k = A.nrows()
    n = A.ncols()
    R = A.base_ring()
    # Smith normal form transformation, assuming more columns than rows
    V = A.smith_form()[2]
    # Extend the matrix in new coordinates, then switch back.
    B = A * V
    B_new = matrix(R, n - k, n)
    for i in range(n - k):
        B_new[i, n - i - 1] = 1
    C = B.stack(B_new)
    D = C * V**(-1)
    # Normalize for a positive determinant
    if D.det() < 0:
        D.rescale_row(n - 1, -1)
    # Return the current information
    if vec_output_flag:
        return D.rows()
    else:
        return D