示例#1
0
    def __pow__(self, other):
        if self.shape[0] != self.shape[1]:
            raise TypeError('matrix is not square')

        if isintlike(other):
            other = int(other)
            if other < 0:
                raise ValueError('exponent must be >= 0')

            if other == 0:
                from construct import identity
                return identity( self.shape[0], dtype=self.dtype )
            elif other == 1:
                return self.copy()
            else:
                result = self
                for i in range(1,other):
                    result = result*self
                return result
        elif isscalarlike(other):
            raise ValueError('exponent must be an integer')
        elif isspmatrix(other):
            warn('Using ** for elementwise multiplication is deprecated.'\
                    'Use .multiply() instead', DeprecationWarning)
            return self.multiply(other)
        else:
            raise NotImplementedError
示例#2
0
    def __pow__(self, other):
        if self.shape[0] != self.shape[1]:
            raise TypeError('matrix is not square')

        if isintlike(other):
            other = int(other)
            if other < 0:
                raise ValueError('exponent must be >= 0')

            if other == 0:
                from construct import identity
                return identity( self.shape[0], dtype=self.dtype )
            elif other == 1:
                return self.copy()
            else:
                result = self
                for i in range(1,other):
                    result = result*self
                return result
        elif isscalarlike(other):
            raise ValueError('exponent must be an integer')
        elif isspmatrix(other):
            warn('Using ** for elementwise multiplication is deprecated.'\
                    'Use .multiply() instead', DeprecationWarning)
            return self.multiply(other)
        else:
            raise NotImplementedError
示例#3
0
    def __pow__(self, other):
        if self.shape[0] != self.shape[1]:
            raise TypeError('matrix is not square')

        if isintlike(other):
            other = int(other)
            if other < 0:
                raise ValueError('exponent must be >= 0')

            if other == 0:
                from construct import identity
                return identity( self.shape[0], dtype=self.dtype )
            elif other == 1:
                return self.copy()
            else:
                result = self
                for i in range(1,other):
                    result = result*self
                return result
        elif isscalarlike(other):
            raise ValueError('exponent must be an integer')
        else:
            raise NotImplementedError