# [SciPy-user] Inverting Complex64 array fails on OS X

Sat Jan 14 17:33:55 CST 2006

```I'm new to SciPy and as my first project, I chose to port some linear
algebra code over from MatLab. I ran into some unexpected results
while inverting an array of type Complex64. Here's a simple test case:

jannu:~ andre\$ /usr/local/bin/python
ActivePython 2.4.2 Build 248 (ActiveState Corp.) based on
Python 2.4.2 (#1, Oct  3 2005, 09:39:46)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1666)] on darwin
>>>  from scipy import *
>>>  a = array([[1, 1], [-1, -1j]], dtype=Complex64)
>>>  a_inv = linalg.inv(a)
>>>  a
array([[ 1.+0.j,  1.+0.j],
[-1.+0.j,  0.-1.j]], dtype=complex128)
>>>  a_inv
array([[ 0., -1.],
[ 1.,  1.]])
>>>  dot (a, a_inv)
array([[ 1.+0.j,  0.+0.j],
[ 0.-1.j,  1.-1.j]], dtype=complex128)

Inverting this Complex64 matrix surprisingly returns a real matrix.
The dot product of the matrix and its supposed inverse does not yield
the unit matrix, but rather a complex matrix whose real part happens
to be the unit matrix.

It seems like linalg.inv() completely ignored the imaginary part of
the input matrix.

Switching the data type of the array to Complex32 and repeating the
calculations yields the correct results:

>>>  b = array([[1, 1], [-1, -1j]], dtype=Complex32)
>>>  b_inv = linalg.inv(b)
>>>  b
array([[ 1.+0.j,  1.+0.j],
[-1.+0.j,  0.-1.j]], dtype=complex64)
>>>  b_inv
array([[ 0.5-0.5j, -0.5-0.5j],
[ 0.5+0.5j,  0.5+0.5j]], dtype=complex64)
>>>  dot(b, b_inv)
array([[ 1.+0.j,  0.+0.j],
[ 0.+0.j,  1.+0.j]], dtype=complex64)

Am I right in assuming that linalg.inv() is supposed to be able to
deal with Complex64 arrays?

If so, can anybody reproduce the results I got?

This is on an Apple PowerBook G3 (pre-Altivec) running Mac OS X
10.3.9 with NumPy and SciPy compiled from current svn source
(0.9.3.1903 and 0.4.4.1550) per Chris' latest instructions on
new.scipy.org.

I also tried to obtain the ATLAS version and path info as per step 5
of the troubleshooting hints in the INSTALL.txt file, but ran into
the following warning and error while running setup_atlas_version.py:

/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/numpy/distutils/misc_util.py:886:
deprecated default_config_dict('linalg','',None)
Traceback (most recent call last):
File "setup_atlas_version.py", line 29, in ?
setup(**configuration())
File "setup_atlas_version.py", line 13, in configuration
del config['fortran_libraries']
KeyError: 'fortran_libraries'

When I comment out the offending line in setup_atlas_version.py and
run it again, the script raises the AtlasNotFoundError exception. I
haven't figured out yet whether this means that the build process
indeed failed to locate the Atlas libraries on my system and if so,
what replacement (if any) it used instead. Any hints on how to do
this would be appreciated.