c9fd2c425cb873508ba16221819574400ad2443e,dask_image/ndmeasure/__init__.py,,extrema,#,75

Before Change


    out_dtype = numpy.dtype([
        ("min_val", input.dtype),
        ("min_pos", numpy.int),
        ("max_val", input.dtype),
        ("max_pos", numpy.int)
    ])
    default = numpy.zeros((), out_dtype)[()]

    extrema_lbl = labeled_comprehension(
        input, labels, index,
        _utils._extrema, out_dtype, default, pass_positions=True
    )

    extrema_lbl = {k: extrema_lbl[k] for k in extrema_lbl.dtype.names}

    for pos_key in ["min_pos", "max_pos"]:
        pos_1d = extrema_lbl[pos_key]
        if not pos_1d.ndim:
            pos_1d = pos_1d[None]

        pos_nd = _utils._unravel_index(pos_1d, input.shape)

        if index.ndim == 0:
            pos_nd = dask.array.squeeze(pos_nd)
        elif index.ndim > 1:
            pos_nd = pos_nd.reshape(
                (int(numpy.prod(pos_nd.shape[:-1])), pos_nd.shape[-1])
            )

        extrema_lbl[pos_key] = pos_nd

    result = (
        extrema_lbl["min_val"],

After Change



    type_mapping = collections.OrderedDict([
        ("min_val", input.dtype),
        ("max_val", input.dtype),
        ("min_pos", numpy.dtype(numpy.int)),
        ("max_pos", numpy.dtype(numpy.int))
    ])
    out_dtype = numpy.dtype(list(type_mapping.items()))

    default_1d = numpy.zeros((1,), dtype=out_dtype)

    func = functools.partial(_utils._extrema, dtype=out_dtype)
    extrema_lbl = labeled_comprehension(
        input, labels, index,
        func, out_dtype, default_1d[0], pass_positions=True
    )

    extrema_lbl = collections.OrderedDict([
        (k, extrema_lbl[k]) for k in type_mapping.keys()
    ])

    for pos_key in ["min_pos", "max_pos"]:
        pos_1d = extrema_lbl[pos_key]
        if not pos_1d.ndim:
            pos_1d = pos_1d[None]

        pos_nd = _utils._unravel_index(pos_1d, input.shape)

        if index.ndim == 0:
            pos_nd = dask.array.squeeze(pos_nd)
        elif index.ndim > 1:
            pos_nd = pos_nd.reshape(
                (int(numpy.prod(pos_nd.shape[:-1])), pos_nd.shape[-1])
            )

        extrema_lbl[pos_key] = pos_nd

    result = tuple(extrema_lbl.values())
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 4

Instances


Project Name: dask/dask-image
Commit Name: c9fd2c425cb873508ba16221819574400ad2443e
Time: 2018-09-30
Author: jakirkham@gmail.com
File Name: dask_image/ndmeasure/__init__.py
Class Name:
Method Name: extrema


Project Name: kymatio/kymatio
Commit Name: b5453ae0c6700e0d9e12de02876f6a07c58b45ec
Time: 2020-02-18
Author: epnevmatikakis@gmail.com
File Name: kymatio/scattering1d/frontend/tensorflow_frontend.py
Class Name: ScatteringTensorFlow1D
Method Name: scattering


Project Name: kymatio/kymatio
Commit Name: 094d40234092f583f55b1d025b9424d2a1b20b43
Time: 2020-02-18
Author: janden@flatironinstitute.org
File Name: kymatio/scattering2d/frontend/tensorflow_frontend.py
Class Name: ScatteringTensorFlow2D
Method Name: scattering