def _call()

in core/maxframe/tensor/reduction/core.py [0:0]


    def _call(self, a, out):
        a = astensor(a)
        if out is not None and not isinstance(out, Tensor):
            raise TypeError(f"out should be Tensor object, got {type(out)} instead")

        axis = getattr(self, "axis", None)
        keepdims = getattr(self, "keepdims", None)
        order = self._calc_order(a, out)

        if self._is_cum():
            if axis is None:
                a, axis = a.ravel(), 0
                setattr(self, "axis", axis)
            shape = a.shape
        else:
            axis = list(range(len(a.shape))) if axis is None else axis
            if not isinstance(axis, Iterable):
                axis = (validate_axis(a.ndim, axis),)
            axis = set(axis)

            shape = tuple(
                s if i not in axis else 1
                for i, s in enumerate(a.shape)
                if keepdims or i not in axis
            )

        self.sparse = self._is_sparse(a.issparse(), shape)
        t = self.new_tensor([a], shape, order=order)

        if out is None:
            return t

        check_out_param(out, t, "same_kind")
        out_shape, out_dtype = out.shape, out.dtype
        # if `out` is specified, use out's dtype and shape
        if out_shape != t.shape:
            if out.ndim > t.ndim:
                raise ValueError("output has too many dimensions")
            raise ValueError(f"output shape should be {t.shape}, got {out_shape}")

        setattr(self, "dtype", out_dtype)

        out.data = t.data
        return out