# Problem with win32com and Numpy on NT based systems

PoulsenL at capecon.com PoulsenL at capecon.com
Fri May 4 15:30:16 CEST 2001

```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
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

```