In cases where not all of a pairwise distance matrix needs to be stored at
once, this is used to calculate pairwise distances in
working_memory-sized chunks. If reduce_func is given, it is run
on each chunk and its return values are concatenated into lists, arrays
or sparse matrices.

Parameters:

X:array [n_samples_a, n_samples_a] if metric == “precomputed”, or,

[n_samples_a, n_features] otherwise
Array of pairwise distances between samples, or a feature array.

Y:array [n_samples_b, n_features], optional

An optional second feature array. Only allowed if
metric != “precomputed”.

reduce_func:callable, optional

The function which is applied on each chunk of the distance matrix,
reducing it to needed values. reduce_func(D_chunk,start)
is called repeatedly, where D_chunk is a contiguous vertical
slice of the pairwise distance matrix, starting at row start.
It should return an array, a list, or a sparse matrix of length
D_chunk.shape[0], or a tuple of such objects.

If None, pairwise_distances_chunked returns a generator of vertical
chunks of the distance matrix.

metric:string, or callable

The metric to use when calculating distance between instances in a
feature array. If metric is a string, it must be one of the options
allowed by scipy.spatial.distance.pdist for its metric parameter, or
a metric listed in pairwise.PAIRWISE_DISTANCE_FUNCTIONS.
If metric is “precomputed”, X is assumed to be a distance matrix.
Alternatively, if metric is a callable function, it is called on each
pair of instances (rows) and the resulting value recorded. The callable
should take two arrays from X as input and return a value indicating
the distance between them.

n_jobs:int or None, optional (default=None)

The number of jobs to use for the computation. This works by breaking
down the pairwise matrix into n_jobs even slices and computing them in
parallel.