[Matrix-SIG] Fix for UserArray.py

Yoon, Hoon (CICG - NY Program Trading) HYoon@exchange.ml.com
Tue, 25 May 1999 16:29:46 -0400


Charles,

>>> x  = Matrix.Matrix(M, 'f')
>>> x  = Matrix.Matrix(M, 'f')
>>> x
<Matrix.Matrix instance at 1310b20>
>>> x*x
Traceback (innermost last):
  File "<interactive input>", line 0, in ?
  File "C:\Python\LLNLDistribution\NUMERICAL\LIB\Matrix.py", line 12, in
__mul__
    return self._rc(matrixmultiply(self.array, asarray(other)))
AttributeError: _rc
>>> x
<Matrix.Matrix instance at 1310b20>
>>> dir(x)
['_typecode', 'array', 'name', 'shape']
>>> x.array
array([[ 0.94999999,  0.03      ],
       [ 0.05      ,  0.97000003]],'f')

May be the Matrix is broken as well???
While we are at it, let's go for variable typing as well. ; )

BTW: Do you have new NTXEmacs compiled? Last one is really NumPy unfriendly
as you can see from my earlier e-mail.
I cannot live without XEmacs on Py.

Thank you for everything,

**************************************************************
S. Hoon Yoon                   (Quant)                    Merrill Lynch
Equity Trading 
yelled@yahoo.com hoon@bigfoot.com(w)
"Miracle is always only few standard deviations away, but so is
catastrophe."
* Expressed opinions are often my own, but NOT my employer's.
"I feel like a fugitive from the law of averages."    Mauldin
**************************************************************

> -----Original Message-----
> From:	Charles G Waldman 
> Sent:	Tuesday, May 25, 1999 4:05 PM
> To:	matrix-sig@python.org
> Cc:	support@icf.llnl.gov
> Subject:	[Matrix-SIG] Fix for UserArray.py
> 
> 
> Looks like in Distribution 11, the indentation in UserArray.py got
> botched up.  Maybe the critics are right, and Python should have explicit
> block delimiters!! <**duck**>
> 
> --- UserArray.py	1999/05/25 19:58:20	1.1
> +++ UserArray.py	1999/05/25 19:59:33
> @@ -8,96 +8,96 @@
>          self._typecode = self.array.typecode()
>          self.name = string.split(str(self.__class__))[0]
>  
> -	def __repr__(self):
> -		return self.name+repr(self.array)[len("array"):]
> +    def __repr__(self):
> +       	return self.name+repr(self.array)[len("array"):]
>  
> -	def __array__(self,t=None):
> -		if t: return asarray(self.array,t)
> -		return asarray(self.array)
> +    def __array__(self,t=None):
> +       	if t: return asarray(self.array,t)
> +       	return asarray(self.array)
>  
> -	def __float__(self):
> -		return float(asarray(self.array))
> +    def __float__(self):
> +       	return float(asarray(self.array))
>  
> -	# Array as sequence
> -	def __len__(self): return len(self.array)
> +    # Array as sequence
> +    def __len__(self): return len(self.array)
>  
> -	def __getitem__(self, index): 
> -		return self._rc(self.array[index])
> +    def __getitem__(self, index): 
> +       	return self._rc(self.array[index])
>  
> -	def __getslice__(self, i, j): 
> -		return self._rc(self.array[i:j])
> +    def __getslice__(self, i, j): 
> +       	return self._rc(self.array[i:j])
>  
>  
> -	def __setitem__(self, index, value): self.array[index] =
> asarray(value,self._typecode)
> -	def __setslice__(self, i, j, value): self.array[i:j] =
> asarray(value,self._typecode)
> +    def __setitem__(self, index, value): self.array[index] =
> asarray(value,self._typecode)
> +    def __setslice__(self, i, j, value): self.array[i:j] =
> asarray(value,self._typecode)
>  
> -	def __del__(self):
> -		for att in dir(self):
> -			delattr(self,att)
> -			#del(self)
> +    def __del__(self):
> +       	for att in dir(self):
> +       		delattr(self,att)
> +       		#del(self)
>  
> -	def __abs__(self): return self._rc(absolute(self.array))
> -	def __neg__(self): return self._rc(-self.array)
> +    def __abs__(self): return self._rc(absolute(self.array))
> +    def __neg__(self): return self._rc(-self.array)
>  
> -	def __add__(self, other): 
> -		return self._rc(self.array+asarray(other))
> -	__radd__ = __add__
> +    def __add__(self, other): 
> +       	return self._rc(self.array+asarray(other))
> +    __radd__ = __add__
>  
> -	def __sub__(self, other): 
> -		return self._rc(self.array-asarray(other))
> -	def __rsub__(self, other): 
> -		return self._rc(asarray(other)-self.array)
> +    def __sub__(self, other): 
> +       	return self._rc(self.array-asarray(other))
> +    def __rsub__(self, other): 
> +       	return self._rc(asarray(other)-self.array)
>  
> -	def __mul__(self, other): 
> -		return self._rc(multiply(self.array,asarray(other)))
> -	__rmul__ = __mul__
> +    def __mul__(self, other): 
> +       	return self._rc(multiply(self.array,asarray(other)))
> +    __rmul__ = __mul__
>  
> -	def __div__(self, other): 
> -		return self._rc(divide(self.array,asarray(other)))
> -	def __rdiv__(self, other): 
> -		return self._rc(divide(asarray(other),self.array))
> +    def __div__(self, other): 
> +       	return self._rc(divide(self.array,asarray(other)))
> +    def __rdiv__(self, other): 
> +       	return self._rc(divide(asarray(other),self.array))
>  
> -	def __pow__(self,other): 
> -		return self._rc(power(self.array,asarray(other)))
> -	def __rpow__(self,other): 
> -		return self._rc(power(asarray(other),self.array))
> +    def __pow__(self,other): 
> +       	return self._rc(power(self.array,asarray(other)))
> +    def __rpow__(self,other): 
> +       	return self._rc(power(asarray(other),self.array))
>  
> -	def __sqrt__(self): 
> -		return self._rc(sqrt(self.array))
> +    def __sqrt__(self): 
> +       	return self._rc(sqrt(self.array))
>  
> -	def tostring(self): return self.array.tostring()
> +    def tostring(self): return self.array.tostring()
>  
> -	def byteswapped(self): return self._rc(self.array.byteswapped())
> -	def astype(self, typecode): return
> self._rc(self.array.asType(typecode))
> +    def byteswapped(self): return self._rc(self.array.byteswapped())
> +    def astype(self, typecode): return
> self._rc(self.array.asType(typecode))
>     
> -	def typecode(self): return self.array._typecode
> -	def itemsize(self): return self.array.itemsize()
> -	def iscontiguous(self): return self.array.iscontiguous()
> -
> -	def _rc(self, a):
> -		if len(shape(a)) == 0: return a
> -		else: return self.__class__(a)
> +    def typecode(self): return self.array._typecode
> +    def itemsize(self): return self.array.itemsize()
> +    def iscontiguous(self): return self.array.iscontiguous()
> +
> +    def _rc(self, a):
> +       	if len(shape(a)) == 0: return a
> +       	else: return self.__class__(a)
>  
>  
>  #############################################################
>  # Test of class UserArray
>  #############################################################
>  if __name__ == '__main__':
> -	import Numeric
> +    import Numeric
>  
> -	temp=reshape(arange(10000),(100,100))
> +    temp=reshape(arange(10000),(100,100))
>  
> -	ua=UserArray(temp)
> -	# new object created begin test
> -	print dir(ua)
> -	print shape(ua),ua.shape # I have changed Numeric.py
> -
> -	ua_small=ua[:3,:5]
> -	print ua_small
> -	ua_small[0,0]=10  # this did not change ua[0,0], wich is not normal
> behavior
> -	print ua_small[0,0],ua[0,0]
> -	print sin(ua_small)/3.*6.+sqrt(ua_small**2)
> -	print less(ua_small,103),type(less(ua_small,103))
> -	print type(ua_small*reshape(arange(15),shape(ua_small)))
> -	print reshape(ua_small,(5,3))
> -	print transpose(ua_small)
> +    ua=UserArray(temp)
> +    # new object created begin test
> +    print dir(ua)
> +    print shape(ua),ua.shape # I have changed Numeric.py
> +    
> +    ua_small=ua[:3,:5]
> +    print ua_small
> +    ua_small[0,0]=10  # this did not change ua[0,0], wich is not normal
> behavior
> +    print ua_small[0,0],ua[0,0]
> +    print sin(ua_small)/3.*6.+sqrt(ua_small**2)
> +    print less(ua_small,103),type(less(ua_small,103))
> +    print type(ua_small*reshape(arange(15),shape(ua_small)))
> +    print reshape(ua_small,(5,3))
> +    print transpose(ua_small)
> 
> _______________________________________________
> Matrix-SIG maillist  -  Matrix-SIG@python.org
> http://www.python.org/mailman/listinfo/matrix-sig