import dask
import dask.array

import dask_distance._compat


def _bool_cmp_mtx_cnt(u, v):
    u = dask_distance._compat._asarray(u)
    v = dask_distance._compat._asarray(v)

    u_1 = u.astype(bool)
    v_1 = v.astype(bool)
    u_0 = ~u_1
    v_0 = ~v_1

    uv_11 = u_1 & v_1
    uv_10 = u_1 & v_0
    uv_01 = u_0 & v_1
    uv_00 = u_0 & v_0

    uv_11_sum = uv_11.sum(axis=0, dtype=float)
    uv_10_sum = uv_10.sum(axis=0, dtype=float)
    uv_01_sum = uv_01.sum(axis=0, dtype=float)
    uv_00_sum = uv_00.sum(axis=0, dtype=float)

    uv_cmp_mtx_cnts = dask.array.stack([
        dask.array.stack([uv_00_sum, uv_01_sum]),
        dask.array.stack([uv_10_sum, uv_11_sum]),
    ])

    return uv_cmp_mtx_cnts

Create a comparison matrix for 2 1-D bool arrays
Create a comparison matrix for 2 1-D bool arrays

Simply count the number of combinations of true and false between the
two 1-D arrays and sum them together. The result is then stacked into a
2-D array where the indices match the particular combination of true and
false seen in each 1-D bool array in order.
