Problem with win32com and Numpy on NT based systems

PoulsenL at capecon.com PoulsenL at capecon.com
Fri May 4 12:29:33 EDT 2001


Please ignore the second post I am an idiot, however, the first post is
still a problem.

-----Original Message-----
From: PoulsenL at capecon.com [mailto:PoulsenL at capecon.com]
Sent: Friday, May 04, 2001 12:21 PM
To: python-list at python.org
Subject: RE: Problem with win32com and Numpy on NT based systems


With no response I would like to add a bit more to the puzzle. I set the
return value of LinearAlgebra.eigenvalues to 1.  Theis returns a variant to
Excel with a single element for the following code:Function test()

Dim MatrixIn(1, 1)
MatrixIn(0, 0) = -1
MatrixIn(0, 1) = 3
MatrixIn(1, 0) = -1
MatrixIn(1, 1) = 2

Set numpy = CreateObject("PythonNumeric.Utilities")
test = numpy.Eigenvalues(MatrixIn)
temp = test(0)
Set numpy = Nothing

End Function

I can stop the code at temp = test(0) and verify that it is a Variant with
one element whose value is 1 according to the Locals window.  One the next
line when I try to assign the value to another variable I get an "Out of
Stack Space" error from Excel.  What is the COM Server returning? Again this
is on a W2K machine.

-----Original Message-----
From: PoulsenL at capecon.com [mailto:PoulsenL at capecon.com]
Sent: Friday, May 04, 2001 9:30 AM
To: python-list at python.org
Subject: Problem with win32com and Numpy on NT based systems


I have tried the following simple com server on win95, win98, NT4, and
win2K:

# PythonNumeric.py 

class PythonNumeric:
    _public_methods_ = [ 'InvertMatrix', 'NegSemiDefTest', 'Eigenvalues' ]
    _reg_progid_ = "PythonNumeric.Utilities"
    # NEVER copy the following ID 
    # Use "print pythoncom.CreateGuid()" to make a new one.
    _reg_clsid_ = "{3B262C80-01BA-11D5-A9ED-0010A4C3B041}"
    
    def InvertMatrix(self, val):
        import Numeric
        import LinearAlgebra
        return ((LinearAlgebra.inverse(Numeric.array(val))),)

    def NegSemiDefTest(self, MatrixIn):
        import Numeric
        import LinearAlgebra
        NegSemiDef = 1
        TestMatrix = LinearAlgebra.eigenvalues(Numeric.array(MatrixIn))
        for i in range(0,len(TestMatrix)):
            if TestMatrix[i] > 0:
                NegSemiDef = 0
                break
        return (NegSemiDef,) #(((1,0),(0,0)),)


    def Eigenvalues(self, val):
        import Numeric
        import LinearAlgebra
        initialArray = Numeric.array(val)
        return ((LinearAlgebra.eigenvalues(initialArray)),)

# Add code so that when this script is run by
# Python.exe, it self-registers.
if __name__=='__main__':
    print "Registering COM server..."
    import win32com.server.register
    win32com.server.register.UseCommandLine(PythonNumeric)

The following works on all systems:

import win32com.client
numpy = win32com.client.Dispatch("PythonNumeric.Utilities")

myVal = ((-1,2),(2,-2))
print numpy.InvertMatrix(myVal)
print numpy.NegSemiDefTest(myVal)
print numpy.Eigenvalues(myVal)

However, Excel "freezes" (excel.exe consumes 100% of resources) on just the
2000 and NT box for the following code:

Function Eigenvalues(MatrixIn)
On Error GoTo ErrorOut
    If IsObject(MatrixIn) Then
        MatrixIn = ActiveSheet.Range(MatrixIn.Address).Value
    Else
        MatrixIn = MatrixIn
    End If
    Set numpy = CreateObject("PythonNumeric.Utilities")
    Eigenvalues = numpy.Eigenvalues(MatrixIn)
    Set numpy = Nothing

    Exit Function
ErrorOut:
    Debug.Print "Non-symmetric"
    Dim TempEigenvalue
    ReDim TempEigenvalue(0 To UBound(MatrixIn) - 1)
    For i = 0 To UBound(MatrixIn) - 1
        TempEigenvalue(i) = 1
    Next i
    Eigenvalues = TempEigenvalue
    Resume Next
End Function

And just to be explicit about what I am trying to pass (this "freezes" excel
also):
Function test()
Dim MatrixIn(1, 1)
MatrixIn(0, 0) = -1
MatrixIn(0, 1) = 2
MatrixIn(1, 0) = -1
MatrixIn(1, 1) = 2

Set numpy = CreateObject("PythonNumeric.Utilities")
Debug.Print numpy.NegSemiDefTest(MatrixIn)
Set numpy = Nothing

End Function

Thanks

Loren

-- 
http://mail.python.org/mailman/listinfo/python-list

-- 
http://mail.python.org/mailman/listinfo/python-list




More information about the Python-list mailing list