def _convert_mem_units(from_val, from_units: str=None, to_units: str=None,
    sig_digits=None):
    """
    Convert memory units.

    Arguments:
        from_val {[type]} -- [description]

    Keyword Arguments:
        from_units {str} -- [description] (default: {None})
        to_units {str} -- [description] (default: {None})
        sig_digits {[type]} -- [description] (default: {None})

    Returns:
        [type] -- [description]
    """
    from_units = from_units or 'B'
    _mem_units_map = {'B': 1, 'K': 1024 ** 1, 'MB': 1024 ** 2, 'GB': 1024 **
        3, 'TB': 1024 ** 4}
    num_bytes = from_val * _mem_units_map[from_units]
    return_tuple = not to_units
    if not to_units:
        cutover_factor = 800
        if to_units not in _mem_units_map:
            if num_bytes < 100:
                to_units = 'B'
            if num_bytes < cutover_factor * _mem_units_map['K']:
                to_units = 'K'
            elif num_bytes < cutover_factor * _mem_units_map['MB']:
                to_units = 'MB'
            elif num_bytes < cutover_factor * _mem_units_map['GB']:
                to_units = 'GB'
            else:
                to_units = 'TB'
    result = num_bytes * 1.0 / _mem_units_map[to_units]
    if not sig_digits:
        sig_digits = 1 if result >= 10 else 2
    if return_tuple:
        return round(result, sig_digits), to_units
    return round(result, sig_digits)
