(self, key)
Getitem function for mp matrix class with slice index enabled
            it allows the following assingments
            scalar to a slice of the matrix
         B = A[:,2:6]
Getitem function for mp matrix class with slice index enabled
            it allows the following assingments
            scalar to a slice of the matrix
         B = A[:,2:6]
Getitem function for mp matrix class with slice index enabled it allows the following assingments scalar to a slice of the matrix B = A [ : 2 : 6 ]
def __getitem__(self, key):
        '''
            Getitem function for mp matrix class with slice index enabled
            it allows the following assingments
            scalar to a slice of the matrix
         B = A[:,2:6]
        '''
        # Convert vector to matrix indexing
        if isinstance(key, int) or isinstance(key,slice):
            # only sufficent for vectors
            if self.__rows == 1:
                key = (0, key)
            elif self.__cols == 1:
                key = (key, 0)
            else:
                raise IndexError('insufficient indices for matrix')

        if isinstance(key[0],slice) or isinstance(key[1],slice):

            #Rows
            if isinstance(key[0],slice):
                #Check bounds
                if (key[0].start is None or key[0].start >= 0) and \
                    (key[0].stop is None or key[0].stop <= self.__rows+1):
                    # Generate indices
                    rows = xrange(*key[0].indices(self.__rows))
                else:
                    raise IndexError('Row index out of bounds')
            else:
                # Single row
                rows = [key[0]]

            # Columns
            if isinstance(key[1],slice):
                # Check bounds
                if (key[1].start is None or key[1].start >= 0) and \
                    (key[1].stop is None or key[1].stop <= self.__cols+1):
                    # Generate indices
                    columns = xrange(*key[1].indices(self.__cols))
                else:
                    raise IndexError('Column index out of bounds')

            else:
                # Single column
                columns = [key[1]]

            # Create matrix slice
            m = self.ctx.matrix(len(rows),len(columns))

            # Assign elements to the output matrix
            for i,x in enumerate(rows):
                for j,y in enumerate(columns):
                    m.__set_element((i,j),self.__get_element((x,y)))

            return m

        else:
            # single element extraction
            if key[0] >= self.__rows or key[1] >= self.__cols:
                raise IndexError('matrix index out of range')
            if key in self.__data:
                return self.__data[key]
            else:
                return self.ctx.zero
def __getitem__ ( self , key ) : # Convert vector to matrix indexing if isinstance ( key , int ) or isinstance ( key , slice ) : # only sufficent for vectors if self . __rows == 1 : key = ( 0 , key ) elif self . __cols == 1 : key = ( key , 0 ) else : raise IndexError ( 'insufficient indices for matrix' ) if isinstance ( key [ 0 ] , slice ) or isinstance ( key [ 1 ] , slice ) : #Rows if isinstance ( key [ 0 ] , slice ) : #Check bounds if ( key [ 0 ] . start is None or key [ 0 ] . start >= 0 ) and ( key [ 0 ] . stop is None or key [ 0 ] . stop <= self . __rows + 1 ) : # Generate indices rows = xrange ( * key [ 0 ] . indices ( self . __rows ) ) else : raise IndexError ( 'Row index out of bounds' ) else : # Single row rows = [ key [ 0 ] ] # Columns if isinstance ( key [ 1 ] , slice ) : # Check bounds if ( key [ 1 ] . start is None or key [ 1 ] . start >= 0 ) and ( key [ 1 ] . stop is None or key [ 1 ] . stop <= self . __cols + 1 ) : # Generate indices columns = xrange ( * key [ 1 ] . indices ( self . __cols ) ) else : raise IndexError ( 'Column index out of bounds' ) else : # Single column columns = [ key [ 1 ] ] # Create matrix slice m = self . ctx . matrix ( len ( rows ) , len ( columns ) ) # Assign elements to the output matrix for i , x in enumerate ( rows ) : for j , y in enumerate ( columns ) : m . __set_element ( ( i , j ) , self . __get_element ( ( x , y ) ) ) return m else : # single element extraction if key [ 0 ] >= self . __rows or key [ 1 ] >= self . __cols : raise IndexError ( 'matrix index out of range' ) if key in self . __data : return self . __data [ key ] else : return self . ctx . zero