<commit_before>import numpy as np
from ..utils import safe_isinstance

def invariants(masker, *args):
    invariants = None
    if isinstance(masker, "shap.maskers.FixedComposite"):
        if callable(getattr(masker, "invariants", None)):
            return masker.invariants(*args)
        else:
            raise AttributeError("FixedComposite masker must define 'invariants' attribute.")
    if callable(getattr(masker, "invariants", None)):
        invariants = masker.invariants(*args)
    return invariants

def variants(masker, *args):
    variants, variants_column_sums, variants_row_inds = None, None, None
    # if the masker supports it, save what positions vary from the background
    _invariants = invariants(masker, *args)
    if _invariants is not None:
        variants = ~_invariants
        variants_column_sums = variants.sum(0)
        variants_row_inds = [
            variants[:,i] for i in range(variants.shape[1])
        ]
    else:
        variants = None

    return variants, variants_column_sums, variants_row_inds

def shape(masker, *args):
    masker_rows, masker_cols = None, None
    if isinstance(masker, "shap.maskers.FixedComposite"):
        if callable(getattr(masker, "shape", None)):
            return masker.shape(*args)
        else:
            raise AttributeError("FixedComposite masker must define 'shape' attribute.")
    # compute the length of the mask (and hence our length)<commit_msg>Modified isinstance to safe_isinstance in _maskers.py utility<commit_after>import numpy as np
from ..utils import safe_isinstance

def invariants(masker, *args):
    invariants = None
    if safe_isinstance(masker, "shap.maskers.FixedComposite"):
        if callable(getattr(masker, "invariants", None)):
            return masker.invariants(*args)
        else:
            raise AttributeError("FixedComposite masker must define 'invariants' attribute.")
    if callable(getattr(masker, "invariants", None)):
        invariants = masker.invariants(*args)
    return invariants

def variants(masker, *args):
    variants, variants_column_sums, variants_row_inds = None, None, None
    # if the masker supports it, save what positions vary from the background
    _invariants = invariants(masker, *args)
    if _invariants is not None:
        variants = ~_invariants
        variants_column_sums = variants.sum(0)
        variants_row_inds = [
            variants[:,i] for i in range(variants.shape[1])
        ]
    else:
        variants = None

    return variants, variants_column_sums, variants_row_inds

def shape(masker, *args):
    masker_rows, masker_cols = None, None
    if safe_isinstance(masker, "shap.maskers.FixedComposite"):
        if callable(getattr(masker, "shape", None)):
            return masker.shape(*args)
        else:
            raise AttributeError("FixedComposite masker must define 'shape' attribute.")
    # compute the length of the mask (and hence our length)
{'fraction_non_alphanumeric': 0.09162125340599456, 'fraction_numerical': 0.0013623978201634877, 'mean_word_length': 3.2813411078717203, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4786570', 'n_tokens_mistral': 898, 'n_tokens_neox': 874, 'n_words': 241}