<commit_before>import numpy as np


def complement_stain_matrix(w):
    """Generates a complemented stain matrix
    Used to fill out empty columns of a stain matrix for use with
    color_deconvolution. Replaces right-most column with normalized
    cross-product of first two columns.

    Parameters
    ----------
    w : array_like
        A 3x3 stain calibration matrix with stain color vectors in columns.

    Returns
    -------
    w_comp : array_like
        A 3x3 complemented stain calibration matrix with a third
        orthogonal column.

    See Also
    --------
    histomicstk.preprocessing.color_deconvolution.color_deconvolution
    """

    # copy input to output for initialization
    w_comp = w

    # calculate directed cross-product of first two columns
    if (w[0, 0]**2 + w[0, 1]**2) > 1:
        w_comp[0, 2] = 0
    else:
        w_comp[0, 2] = (1 - (w[0, 0] ** 2 + w[0, 1] ** 2)) ** 0.5

    if (w[1, 0]**2 + w[1, 1]**2) > 1:
        w_comp[1, 2] = 0
    else:
        w_comp[1, 2] = (1 - (w[1, 0] ** 2 + w[1, 1] ** 2)) ** 0.5

    if (w[2, 0]**2 + w[2, 1]**2) > 1:
        w_comp[2, 2] = 0
    else:
        w_comp[2, 2] = (1 - (w[2, 0] ** 2 + w[2, 1] ** 2)) ** 0.5

    # normalize new vector to unit-norm
    w_comp[:, 2] = w_comp[:, 2] / np.linalg.norm(w_comp[:, 2])

    return w_comp<commit_msg>Make complement_stain_matrix compute the cross-product.<commit_after>import numpy as np


def complement_stain_matrix(w):
    """Generates a complemented stain matrix
    Used to fill out empty columns of a stain matrix for use with
    color_deconvolution. Replaces right-most column with normalized
    cross-product of first two columns.

    Parameters
    ----------
    w : array_like
        A 3x3 stain calibration matrix with stain color vectors in columns.

    Returns
    -------
    w_comp : array_like
        A 3x3 complemented stain calibration matrix with a third
        orthogonal column.

    See Also
    --------
    histomicstk.preprocessing.color_deconvolution.color_deconvolution
    """

    stain0 = w[:, 0]
    stain1 = w[:, 1]
    stain2 = np.cross(stain0, stain1)
    # Normalize new vector to have unit norm
    return np.array([stain0, stain1, stain2 / np.linalg.norm(stain2)]).T
{'fraction_non_alphanumeric': 0.1246660730186999, 'fraction_numerical': 0.03784505788067676, 'mean_word_length': 2.333827893175074, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '831087', 'n_tokens_mistral': 802, 'n_tokens_neox': 739, 'n_words': 244}