def mat_to(newtype, a):
    """
    Converts the elements of a matrix to a specified scalar type

    Parameters
    ----------
    newtype: class
        The new scalar type to which the elements of the matrix
        will be converted.
    a: list[list]
        A matrix of scalar values

    Returns
    -------
    list[list]
        A matrix whose elements are converted to the specified type.
        If the matrix is already of the given type, a copy is returned.

    """
    if type(a[0][0]) is not newtype:
        return [[newtype(e) for e in row] for row in a]
    else:
        return [[e for e in row] for row in a]