# Path: csc/divisi/tensor.py
# class View(Tensor):
#     """
#     A *view* is a wrapper around a tensor (always ``self.tensor``)
#     that performs some operations (usually ``__getitem__`` and/or
#     ``__setitem__``) differently.
# 
#     For almost all purposes, it acts like a ``Tensor`` itself. Unknown
#     methods are passed through to the underlying ``Tensor``.
# 
#     This is just the abstract base class. Some useful ``View``s
#     include :class:`csc.divisi.labeled_view.LabeledView` and
#     :class:`csc.divisi.labeled_view.NormalizedView`.
#     """
# 
#     def __init__(self, tensor):
#         """
#         Create a new View wrapping a Tensor.
#         """
#         self.tensor = tensor
#         self.ndim = tensor.ndim
# 
#     def __repr__(self):
#         return '<View of %s>' % repr(self.tensor)
# 
#     def __getattr__(self, name):
#         '''Fall back to the tensor operation.'''
#         if name in forward_to_tensor:
#             attr = getattr(self.tensor, name)
#             #setattr(self, name, attr)
#             return attr
#         else:
#             raise AttributeError(name)
# 
#     def __iter__(self):
#         return self.tensor.__iter__()
# 
#     def __len__(self):
#         return len(self.tensor)
# 
#     def add_layer(self, cls, *a, **kw):
#         """
#         Given a class of View, determine where it should go in the stack
#         and add it as a layer there.
#         """
#         try:
#             return cls(self, *a, **kw)
#         except InvalidLayeringException:
#             # Layer it below here.
#             return self.layer_on(self.tensor.add_layer(cls, *a, **kw))
# 
#     def layer_on(self, tensor):
#         # Just make a copy of the same class viewing the new tensor.
#         # Subclasses should override this.
#         return self.__class__(tensor)
# 
#     def unwrap(self):
#         """
#         Get the object being wrapped by this View. This may be a
#         :class:`Tensor`,
#         or another :class:`View`.
# 
#         Essentially, this removes the outermost View layer, so that you can
#         get at what's inside.
#         """
#         return self.tensor
# 
# def outer_tuple_iterator(shape):
#     return product(*map(xrange, shape))


from csc.divisi.tensor import View, outer_tuple_iterator
from math import ceil
import numpy
        offset = numpy.zeros(self._tensor_ndim)
        interval = numpy.zeros(self._tensor_ndim)
        dim_map = {}
        base_indices = numpy.zeros(self._tensor_ndim)
        for i in xrange(0, self._tensor_ndim):
            index = slice_indices[i]
            if hasattr(index, 'indices'):
                start, end, step = index.indices(tensor.shape[i])
                shape.append(int(ceil(float(end - start)/step)))
                offset[ndim] = start
                interval[ndim] = step
                dim_map[ndim] = i
                ndim += 1
            else:
                base_indices[i] = index

        self.ndim = ndim
        self.shape = tuple(shape)
        # These vars help perform the mapping from slice indices -> tensor indices
        self._offset = offset
        self._interval = interval
        self._dim_map = dim_map
        self._base_indices = base_indices

    def __repr__(self):
        return '<SlicedView of %r, slice=%r, shape=%r>' % (self.tensor, self._slice, self.shape)

    def _iter_all(self):
        # Iterates over all possible indices, instead of just the defined
        # indices

# Path: csc/divisi/tensor.py
# class View(Tensor):
#     """
#     A *view* is a wrapper around a tensor (always ``self.tensor``)
#     that performs some operations (usually ``__getitem__`` and/or
#     ``__setitem__``) differently.
# 
#     For almost all purposes, it acts like a ``Tensor`` itself. Unknown
#     methods are passed through to the underlying ``Tensor``.
# 
#     This is just the abstract base class. Some useful ``View``s
#     include :class:`csc.divisi.labeled_view.LabeledView` and
#     :class:`csc.divisi.labeled_view.NormalizedView`.
#     """
# 
#     def __init__(self, tensor):
#         """
#         Create a new View wrapping a Tensor.
#         """
#         self.tensor = tensor
#         self.ndim = tensor.ndim
# 
#     def __repr__(self):
#         return '<View of %s>' % repr(self.tensor)
# 
#     def __getattr__(self, name):
#         '''Fall back to the tensor operation.'''
#         if name in forward_to_tensor:
#             attr = getattr(self.tensor, name)
#             #setattr(self, name, attr)
#             return attr
#         else:
#             raise AttributeError(name)
# 
#     def __iter__(self):
#         return self.tensor.__iter__()
# 
#     def __len__(self):
#         return len(self.tensor)
# 
#     def add_layer(self, cls, *a, **kw):
#         """
#         Given a class of View, determine where it should go in the stack
#         and add it as a layer there.
#         """
#         try:
#             return cls(self, *a, **kw)
#         except InvalidLayeringException:
#             # Layer it below here.
#             return self.layer_on(self.tensor.add_layer(cls, *a, **kw))
# 
#     def layer_on(self, tensor):
#         # Just make a copy of the same class viewing the new tensor.
#         # Subclasses should override this.
#         return self.__class__(tensor)
# 
#     def unwrap(self):
#         """
#         Get the object being wrapped by this View. This may be a
#         :class:`Tensor`,
#         or another :class:`View`.
# 
#         Essentially, this removes the outermost View layer, so that you can
#         get at what's inside.
#         """
#         return self.tensor
# 
# def outer_tuple_iterator(shape):
#     return product(*map(xrange, shape))


# Path: csc/divisi/sliced_view.py
from csc.divisi.tensor import View, outer_tuple_iterator
from math import ceil
import numpy

        offset = numpy.zeros(self._tensor_ndim)
        interval = numpy.zeros(self._tensor_ndim)
        dim_map = {}
        base_indices = numpy.zeros(self._tensor_ndim)
        for i in xrange(0, self._tensor_ndim):
            index = slice_indices[i]
            if hasattr(index, 'indices'):
                start, end, step = index.indices(tensor.shape[i])
                shape.append(int(ceil(float(end - start)/step)))
                offset[ndim] = start
                interval[ndim] = step
                dim_map[ndim] = i
                ndim += 1
            else:
                base_indices[i] = index

        self.ndim = ndim
        self.shape = tuple(shape)
        # These vars help perform the mapping from slice indices -> tensor indices
        self._offset = offset
        self._interval = interval
        self._dim_map = dim_map
        self._base_indices = base_indices

    def __repr__(self):
        return '<SlicedView of %r, slice=%r, shape=%r>' % (self.tensor, self._slice, self.shape)

    def _iter_all(self):
        # Iterates over all possible indices, instead of just the defined
        # indices

        return outer_tuple_iterator(self.shape)