def METHOD_NAME(window: Window):
    """
    Creates a cost matrix from a window.
    Depending on the density of the active cells in the window,
    will select either a dense or sparse storage representation.
    Parameters
    ----------
    window
        Takes a `Window` defining which cells are active and which are empty
    Returns
    -------
    CostMatrix
    """
    density = len(window) / ((window.n + 1) * (window.m + 1))
    # In the future it might be worth implementing
    # a sparse cost matrix based on column_index/column_length
    # that will work even for non-contiguous windows
    if isinstance(window, CRWindow) and density < 0.5:
        return SparseCostMatrix(window)
    else:
        return DenseCostMatrix(window.n, window.m)