How to use the larray.Array 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
def get_axes(value):
        return value.axes if isinstance(value, la.Array) else la.AxisCollection([])
github liam2 / liam2 / liam2 / larray_monkey.py View on Github external
def to_la_ikey(axis, axis_key):
        # MONKEY PATCH CHANGED LINE
        if isinstance(axis_key, (int, long, np.integer, slice, la.Array)):
            return axis_key
        else:
            # MONKEY PATCH CHANGED LINE
            assert isinstance(axis_key, (list, np.ndarray)), \
                "unsupported key type: {} ({})".format(axis_key, type(axis_key))
            res_axis = axis.subaxis(axis_key)
            # TODO: for perf reasons, we should bypass creating an actual Array by returning axes and key_data
            # but then we will need to implement a function similar to make_numpy_broadcastable which works on axes
            # and rawdata instead of arrays
            return la.Array(axis_key, res_axis)
github liam2 / liam2 / liam2 / larray_monkey.py View on Github external
key = tuple(self[axis][axis_key] for axis, axis_key in key.items())
    elif not isinstance(key, tuple):
        # convert scalar keys to 1D keys
        key = (key,)

    # handle ExprNode
    key = tuple(axis_key.evaluate(self) if isinstance(axis_key, ExprNode) else axis_key
                for axis_key in key)

    nonboolkey = []
    for axis_key in key:
        if isinstance(axis_key, np.ndarray) and np.issubdtype(axis_key.dtype, np.bool_):
            if axis_key.shape != self.shape:
                raise ValueError("boolean key with a different shape ({}) than array ({})"
                                 .format(axis_key.shape, self.shape))
            axis_key = la.Array(axis_key, self)

        if isinstance(axis_key, la.Array) and np.issubdtype(axis_key.dtype, np.bool_):
            bool_axes_names = [axis.name for axis in self if np.issubdtype(axis.dtype, np.bool_)]
            if bool_axes_names:
                # a "filter" key has always somme axes in common with the array (it should be a subset of the array
                # axes), so if there is no common axis, it is not a filter key.

                # TOCHECK: we might want to check for extra_key_axes too?
                common_axes = axis_key.axes & self
                could_be_a_filter = len(common_axes) >= 1
                if could_be_a_filter:
                    raise ValueError("boolean subset key ({}) is ambiguous because it can be interpreted "
                                     "either as a filter on the array or as a key on a boolean axis ({})"
                                     .format(axis_key, ', '.join(bool_axes_names)))
                nonboolkey.append(axis_key)
            else:
github liam2 / liam2 / liam2 / larray_monkey.py View on Github external
def to_la_ikey(axis, axis_key):
        # MONKEY PATCH CHANGED LINE
        if isinstance(axis_key, (int, long, np.integer, slice, la.Array)):
            return axis_key
        else:
            # MONKEY PATCH CHANGED LINE
            assert isinstance(axis_key, (list, np.ndarray)), \
                "unsupported key type: {} ({})".format(axis_key, type(axis_key))
            res_axis = axis.subaxis(axis_key)
            # TODO: for perf reasons, we should bypass creating an actual Array by returning axes and key_data
            # but then we will need to implement a function similar to make_numpy_broadcastable which works on axes
            # and rawdata instead of arrays
            return la.Array(axis_key, res_axis)