Permalink
Browse files

Fixed autocasting tests to casting tests.. Inplace casting is not sup…

…ported.
  • Loading branch information...
1 parent 4f869af commit d9b385071c9b7ca71ef3b3da693770dd078c9fae @teoliphant teoliphant committed Nov 18, 2005
Showing with 14 additions and 8 deletions.
  1. +12 −6 scipy/base/matrix.py
  2. +2 −2 scipy/base/tests/test_matrix.py
View
@@ -1,5 +1,5 @@
-__all__ = ['matrix', 'bmat', 'mat']
+__all__ = ['matrix', 'bmat', 'mat', 'asmatrix']
import numeric as N
from numeric import ArrayType, concatenate, integer, multiply, power
@@ -44,6 +44,12 @@ def _convert_from_string(data):
newdata.append(newrow)
return newdata
+def asmatrix(data, dtype=None):
+ """ Returns 'data' as a matrix. Unlike matrix(), no copy is performed
+ if 'data' is already a matrix or array. Equivalent to:
+ matrix(data, copy=False)
+ """
+ return matrix(data, dtype=dtype, copy=False)
class matrix(N.ndarray):
__array_priority__ = 10.0
@@ -75,16 +81,16 @@ def __new__(self, data, dtype=None, copy=True):
elif ndim == 1:
shape = (1,shape[0])
- fortran = False;
- if (ndim == 2) and arr.flags['FORTRAN']:
+ fortran = False
+ if (ndim == 2) and arr.flags.fortran:
fortran = True
-
- if not (fortran or arr.flags['CONTIGUOUS']):
+
+ if not (fortran or arr.flags.contiguous):
arr = arr.copy()
ret = N.ndarray.__new__(matrix, shape, arr.dtype, buffer=arr,
fortran=fortran,
- swap=arr.flags['S'])
+ swap=arr.flags.swapped)
return ret
def __array_finalize__(self, obj):
@@ -83,14 +83,14 @@ def test_basic(self):
mB = mA.copy()
O = ones((10,10), float64) * 0.1
- mB += O
+ mB = mB + O
assert mB.dtype == float64
assert all(mA != mB)
assert all(mB == mA+0.1)
mC = mA.copy()
O = ones((10,10), complex128)
- mC *= O
+ mC = mC * O
assert mC.dtype == complex128
assert all(mA != mB)

0 comments on commit d9b3850

Please sign in to comment.