How to use the larray.core.array.make_numpy_broadcastable function in larray

To help you get started, we’ve selected a few larray examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github liam2 / liam2 / liam2 / larray_monkey.py View on Github external
# 0, 2, 3, 4, 5    <- desired result
                    # 0, 1, 3, 4, 2    <- what I need to feed to transpose to get the correct result
                    adv_axes_indices = [i for i, axis_key in enumerate(key)
                                        # MONKEY PATCH CHANGED LINE
                                        if not isinstance(axis_key, (int, long, np.integer, slice))]
                    # not taking scalar axes since they will disappear
                    slice_axes_indices = [i for i, axis_key in enumerate(key)
                                          if isinstance(axis_key, slice)]
                    result_axes_indices = adv_axes_indices + slice_axes_indices
                    transpose_indices = tuple(np.array(result_axes_indices).argsort())
        else:
            # the advanced indexing subspace keep its position (insert at position of first concerned axis)
            adv_key_subspace_pos = adv_axes_indices[0]

        # scalar/slice keys are ignored by make_numpy_broadcastable, which is exactly what we need
        bcasted_adv_keys, adv_key_dest_axes = make_numpy_broadcastable(key)

        # insert advanced indexing subspace
        res_axes[adv_key_subspace_pos:adv_key_subspace_pos] = adv_key_dest_axes

    # transform to raw numpy arrays
    raw_broadcasted_key = tuple(k.data if isinstance(k, la.Array) else k
                                for k in bcasted_adv_keys)
    return raw_broadcasted_key, res_axes, transpose_indices