Пример #1
0
 def __new__(subtype,A,B):
     if isnumeric(A):
         A = OpMatrix(A)
     if isnumeric(B):
         B = OpMatrix(B)
         
     if not (isspot(A) and isspot(B)):
         raise Exception ('One of the operators is not a valid input.')
         return
     
     if not (A.m == B.m and A.n == B.n):
         raise Exception ('Operators are not compatible in size.')
         return
         
     m = A.m
     n = A.n
     op = OpSpot.__new__(subtype,'Sum',m,n,A.double()+B.double())
     op.cflag = A.cflag or B.cflag
     op.linear = A.linear or B.linear
     op.sweepflag = A.sweepflag and B.sweepflag
     op.children.append(A)
     op.children.append(B)
     op.precedence = 4
     op.disp()
     return op
Пример #2
0
 def __new__(subtype,A,B):
     if isnumeric(A):
         A = OpMatrix(A)
     if isnumeric(B):
         B = OpMatrix(B)
         
     if not (isspot(A) and isspot(B)):
         raise Exception ('One of the operators is not a valid input.')
         return
     
     if not (A.isscalar() or B.isscalar() or A.n == B.m):
         raise Exception ('Operators are not compatible in size.')
         return
         
     if A.isscalar() or B.isscalar():
         m = max(A.m,B.m)
         n = max(A.n,B.n)
     else:
         m = A.m
         n = B.n
         
     op = OpSpot.__new__(subtype,'FoG',m,n,np.dot(A,B))
     op.cflag = A.cflag or B.cflag
     op.linear = A.linear or B.linear
     op.sweepflag = A.sweepflag and B.sweepflag
     op.children.append(A)
     op.children.append(B)
     op.precedence = 3
     op.disp()
     return op
Пример #3
0
    def __new__(subtype, A, B):
        if isnumeric(A):
            A = OpMatrix(A)
        if isnumeric(B):
            B = OpMatrix(B)

        if not (isspot(A) and isspot(B)):
            raise Exception('One of the operators is not a valid input.')
            return

        if not (A.m == B.m and A.n == B.n):
            raise Exception('Operators are not compatible in size.')
            return

        m = A.m
        n = A.n
        op = OpSpot.__new__(subtype, 'Sum', m, n, A.double() + B.double())
        op.cflag = A.cflag or B.cflag
        op.linear = A.linear or B.linear
        op.sweepflag = A.sweepflag and B.sweepflag
        op.children.append(A)
        op.children.append(B)
        op.precedence = 4
        op.disp()
        return op
Пример #4
0
    def __new__(subtype, A, p):
        if np.round(p) != p:
            raise Exception('Second argument to opPower must be an integer.')
            return

        if isnumeric(A):
            A = OpMatrix(A)

        if not isspot(A):
            raise Exception('Input operator is not valid.')
            return

        if A.m != A.n:
            raise Exception('Warning: Operator is not a square matrix.')
            return

        op = OpSpot.__new__(subtype, 'Power', A.m, A.m,
                            np.linalg.matrix_power(A, p))
        op.cflag = A.cflag
        op.linear = A.linear
        op.children.append(A)
        op.exponent = p

        if p == 0:
            fun = lambda op, x, mode: x
        elif p > 0:
            fun = lambda op, x, mode: op.opPower_intrnl(x, mode)
        else:
            y = np.linalg.inv(np.linalg.matrix_power(A, np.abs(p)))
            fun = lambda op, x, mode: y.applyMultiply(x, mode)
        op.funHandle = fun

        op.disp()
        return op
Пример #5
0
 def __new__(subtype,A,p):
     if np.round(p) != p:
         raise Exception('Second argument to opPower must be an integer.')
         return
     
     if isnumeric(A):
         A = OpMatrix(A)
     
     if not isspot(A):
         raise Exception ('Input operator is not valid.')
         return
         
     if A.m != A.n:
         raise Exception ('Warning: Operator is not a square matrix.')
         return
         
     op = OpSpot.__new__(subtype,'Power',A.m,A.m,np.linalg.matrix_power(A,p))
     op.cflag = A.cflag
     op.linear = A.linear
     op.children.append(A)
     op.exponent = p
     
     if p == 0:
        fun = lambda op,x,mode: x
     elif p > 0:
         fun = lambda op,x,mode: op.opPower_intrnl(x,mode)
     else:
         y = np.linalg.inv(np.linalg.matrix_power(A,np.abs(p)))
         fun = lambda op,x,mode: y.applyMultiply(x,mode)
     op.funHandle = fun
        
     op.disp()
     return op
Пример #6
0
 def __new__(subtype,A):
     if isnumeric(A):
         A = OpMatrix(A)
     if not isspot(A):
         raise Exception ('Input operator is not valid.')
         return
         
     op = OpSpot.__new__(subtype,'PInverse',A.n,A.m,sci.pinv(A))
     op.cflag = A.cflag
     op.linear = A.linear
     op.sweepflag = A.sweepflag
     op.children.append(A)
     op.disp()
     return op
Пример #7
0
 def __new__(subtype,A):
     if isnumeric(A):
         A = OpMatrix(A)
     if not isspot(A):
         raise Exception ('Input operator is not valid.')
         return
     
     op = OpSpot.__new__(subtype,'Imag',A.m,A.n,A.double().imag)
     op.cflag = False
     op.linear = A.linear
     op.sweepflag = A.sweepflag
     op.children.append(A)
     op.disp()
     return op
Пример #8
0
    def __new__(subtype, A):
        if isnumeric(A):
            A = OpMatrix(A)
        if not isspot(A):
            raise Exception('Input operator is not valid.')
            return

        op = OpSpot.__new__(subtype, 'UnaryMinus', A.m, A.n, -A.double())
        op.cflag = A.cflag
        op.linear = A.linear
        op.children.append(A)
        op.precedence = 2
        op.disp()
        return op
Пример #9
0
    def __new__(subtype, A):
        if isnumeric(A):
            A = OpMatrix(A)
        if not isspot(A):
            raise Exception('Input operator is not valid.')
            return

        op = OpSpot.__new__(subtype, 'PInverse', A.n, A.m, sci.pinv(A))
        op.cflag = A.cflag
        op.linear = A.linear
        op.sweepflag = A.sweepflag
        op.children.append(A)
        op.disp()
        return op
Пример #10
0
 def __new__(subtype,A):
     if isnumeric(A):
         A = OpMatrix(A)
     if not isspot(A):
         raise Exception ('Input operator is not valid.')
         return
     
     op = OpSpot.__new__(subtype,'UnaryMinus',A.m,A.n,-A.double())
     op.cflag = A.cflag
     op.linear = A.linear
     op.children.append(A)
     op.precedence = 2
     op.disp()
     return op
Пример #11
0
    def __new__(subtype, A):
        if isnumeric(A):
            A = OpMatrix(A)

        if not isspot(A):
            raise Exception('Input operator is not valid.')
            return

        op = OpSpot.__new__(subtype, 'Transpose', A.n, A.m, A.T)
        op.cflag = A.cflag
        op.linear = A.linear
        op.sweepflag = A.sweepflag
        op.children.append(A)
        op.opIntrnl = OpCTranspose(OpConj(A))
        op.disp()
        return op
Пример #12
0
 def __new__(subtype,A):
     if isnumeric(A):
         A = OpMatrix(A)
     
     if not isspot(A):
         raise Exception ('Input operator is not valid.')
         return
     
     op = OpSpot.__new__(subtype,'Transpose',A.n,A.m,A.T)
     op.cflag = A.cflag
     op.linear = A.linear
     op.sweepflag = A.sweepflag
     op.children.append(A)
     op.opIntrnl = OpCTranspose(OpConj(A))
     op.disp()
     return op
Пример #13
0
 def __new__(subtype,A,description='Matrix'):
     if not isnumeric(A):
         raise Exception ('Input argument must be numeric.')
         return
     
     if np.isscalar(A):
         m = 1
         n = 1
     else:
         m = np.size(A,0)
         n = int(np.size(A)/m)
     op = OpSpot.__new__(subtype,description,m,n,A)
     op.cflag = not np.isreal(A).all()
     op.sweepflag = True
     op.matrix = A
     op.disp()
     return op